client/js/main.js
changeset 26 2fad193bae98
parent 24 121a24be9da4
child 28 805d85b3f390
equal deleted inserted replaced
25:b5ada3bb8e53 26:2fad193bae98
    46             .addClass("Rk-Bin-Title")
    46             .addClass("Rk-Bin-Title")
    47             .appendTo(this.$);
    47             .appendTo(this.$);
    48         this.main_$ = Rkns.$('<div>')
    48         this.main_$ = Rkns.$('<div>')
    49             .addClass("Rk-Bin-Main")
    49             .addClass("Rk-Bin-Main")
    50             .appendTo(this.$);
    50             .appendTo(this.$);
       
    51         this.title_$.html(_opts.title || '(new bin)');
    51         this.renkan.resizeBins();
    52         this.renkan.resizeBins();
    52     }
    53     }
    53 }
    54 }
    54 /* Point of entry */
    55 /* Point of entry */
    55 
    56 
    74     this.$ = Rkns.$("#" + _opts.container);
    75     this.$ = Rkns.$("#" + _opts.container);
    75     this.$.html(this.template());
    76     this.$.html(this.template());
    76     this.renderer = new Rkns.Renderer.Scene(this);
    77     this.renderer = new Rkns.Renderer.Scene(this);
    77     this.tabs = [];
    78     this.tabs = [];
    78     this.selected_bin_item = undefined;
    79     this.selected_bin_item = undefined;
    79     this.mousedown = false;
       
    80     var _this = this;
    80     var _this = this;
    81     this.$.mouseup(function() {
    81     this.$.mouseup(function() {
    82         _this.selected_bin_item = undefined;
    82         _this.selected_bin_item = undefined;
       
    83         _this.$.find(".Rk-Bin-Item.dragging").removeClass("dragging");
    83     });
    84     });
    84     if (!_opts.search.length) {
    85     if (!_opts.search.length) {
    85         this.$.find(".Rk-Search-Form").detach();
    86         this.$.find(".Rk-Search-Form").detach();
    86     } else {
    87     } else {
    87         var _tmpl = Rkns._.template('<option value="<%= key %>"><%= value.title %></option>'),
    88         var _tmpl = Rkns._.template('<option value="<%= key %>"><%= value.title %></option>'),
   110             }
   111             }
   111             return false;
   112             return false;
   112             
   113             
   113         });
   114         });
   114     }
   115     }
       
   116     Rkns._(_opts.bins).each(function(_bin) {
       
   117         _this.tabs.push(new _bin.bin(_this, _bin));
       
   118     })
       
   119     
       
   120     /* The bins are not yet populated, but we want to bind dragging functions
       
   121      * here, as it will be easier than in the bins. Therefore, we bind to Rk-Bins
       
   122      * and look where the click was. */
       
   123     function findItem(_event) {
       
   124         var _t = Rkns.$(_event.target);
       
   125         while (!_t.is(".Rk-Bins,.Rk-Bin-Item")) {
       
   126             _t = _t.parent();
       
   127         }
       
   128         if (_t.is(".Rk-Bin-Item")) {
       
   129             return _t
       
   130         } else {
       
   131             return null;
       
   132         }
       
   133     }
   115     
   134     
   116     this.$.find(".Rk-Bins")
   135     this.$.find(".Rk-Bins")
   117         .click(function(_e) {
   136         .click(function(_e) {
   118             if (_e.target.className == "Rk-Bin-Title") {
   137             if (_e.target.className == "Rk-Bin-Title") {
   119                 var _mainDiv = Rkns.$(_e.target).siblings(".Rk-Bin-Main");
   138                 var _mainDiv = Rkns.$(_e.target).siblings(".Rk-Bin-Main");
   121                     _this.$.find(".Rk-Bin-Main").slideUp();
   140                     _this.$.find(".Rk-Bin-Main").slideUp();
   122                     _mainDiv.slideDown();
   141                     _mainDiv.slideDown();
   123                 }
   142                 }
   124             }
   143             }
   125         }).mousedown(function(_e) {
   144         }).mousedown(function(_e) {
   126             var _t = Rkns.$(_e.target);
   145             var _t = findItem(_e);
   127             while (!_t.is(".Rk-Bins,.Rk-Bin-Item")) {
   146             if (_t) {
   128                 _t = _t.parent();
   147                 _t.addClass("dragging");
   129             }
       
   130             if (_t.is(".Rk-Bin-Item")) {
       
   131                 _this.selected_bin_item = {
   148                 _this.selected_bin_item = {
   132                     uri : $(_t).attr("data-uri"),
   149                     uri : $(_t).attr("data-uri"),
   133                     title : $(_t).attr("data-title"),
   150                     title : $(_t).attr("data-title"),
   134                     description : $(_t).attr("data-description")
   151                     description : $(_t).attr("data-description")
   135                 }
   152                 }
   136                 return false;
   153                 return false;
   137             }
   154             }
       
   155         }).mouseover(function(_e) {
       
   156             var _t = findItem(_e);
       
   157             if (_t && $(_t).attr("data-uri")) {
       
   158                 var _models = _this.project.get("nodes").where({
       
   159                     uri: $(_t).attr("data-uri")
       
   160                 });
       
   161                 Rkns._(_models).each(function(_model) {
       
   162                     _this.renderer.highlightModel(_model);
       
   163                 });
       
   164             }
       
   165         }).mouseout(function() {
       
   166             _this.renderer.unhighlightAll();
   138         });
   167         });
   139     Rkns.$(window).resize(function() {
   168     Rkns.$(window).resize(function() {
   140         _this.resizeBins();
   169         _this.resizeBins();
   141     });
   170     });
   142 }
   171 }
   147     + '<ul class="Rk-Bin-List"></ul></div><div class="Rk-Render"></div>'
   176     + '<ul class="Rk-Bin-List"></ul></div><div class="Rk-Render"></div>'
   148 );
   177 );
   149 
   178 
   150 
   179 
   151 Rkns.Renkan.prototype.resizeBins = function() {
   180 Rkns.Renkan.prototype.resizeBins = function() {
   152     var _titles = this.$.find(".Rk-Bin-Title"),
   181     var _d = + this.$.find(".Rk-Search-Form").outerHeight();
   153         _d = _titles.length * _titles.outerHeight() + this.$.find(".Rk-Search-Form").outerHeight();
   182     this.$.find(".Rk-Bin-Title").each(function() {
       
   183         _d += Rkns.$(this).outerHeight();
       
   184     });
   154     this.$.find(".Rk-Bin-Main").css({
   185     this.$.find(".Rk-Bin-Main").css({
   155         height: this.$.find(".Rk-Bins").height() - _d
   186         height: this.$.find(".Rk-Bins").height() - _d
   156     });
   187     });
   157 }
   188 }
   158 
   189