src/js/layout.js
branchpopcorn-port
changeset 542 b33516ab03e8
parent 539 3ba5b82aebb6
child 840 ac66e2240e1e
equal deleted inserted replaced
541:f7667a1dde8e 542:b33516ab03e8
    70     this.selector.append(divCode);
    70     this.selector.append(divCode);
    71     this.selector.append(spacerCode);
    71     this.selector.append(spacerCode);
    72 
    72 
    73     return [newDiv, spacerDiv];
    73     return [newDiv, spacerDiv];
    74 };
    74 };
    75 
       
    76 /** return a new slice    
       
    77     @return an IriSP.LayoutManager.sliceObject
       
    78 */
       
    79 IriSP.LayoutManager.prototype.slice = function(widget) {
       
    80   var end = (this._widgets.length > 0) ? this._widgets.length - 1 : 0;
       
    81   var s = new IriSP.LayoutManager.sliceObject(0, end, this)
       
    82   return s;
       
    83 };
       
    84 
       
    85 /** sliceObjects represent a group of widget managed by a layout manager.
       
    86     They expose convenient methods for selecting portions of widgets
       
    87     They can be chained in this way :
       
    88     layoutManager.slice().before("ArrowWidget").after("PolemicWidget");
       
    89 */
       
    90 IriSP.LayoutManager.sliceObject = function(start, end, layoutManager) {
       
    91   this.start = start;
       
    92   this.end = end;
       
    93   this._layoutManager = layoutManager;
       
    94 };
       
    95 
       
    96 /** returns a slice of the array corresponding to the objects after widget
       
    97     @param widget the widget to filter with */
       
    98 IriSP.LayoutManager.sliceObject.prototype.after = function(widget) {
       
    99   var i;
       
   100   for(i = this.start; i < this.end; i++)
       
   101     if (this._layoutManager._widgets[i][0] === widget)
       
   102       break;
       
   103       
       
   104   this.start = i;
       
   105   console.log(this.start);
       
   106   return this;
       
   107 }
       
   108 
       
   109 /** returns a slice of the array corresponding to the objects before widget
       
   110     @param widget the widget to filter with */
       
   111 IriSP.LayoutManager.sliceObject.prototype.before = function(widget) {
       
   112   var i;
       
   113   for(i = this.start; i < this.end; i++)
       
   114     if (this._layoutManager._widgets[i][0] === widget)
       
   115       break;
       
   116       
       
   117   this.end = i;
       
   118   
       
   119   return this;
       
   120 }
       
   121 
       
   122 /** return a jquery selector corresponding to the defined slice */
       
   123 IriSP.LayoutManager.sliceObject.prototype.jQuerySelector = function() {
       
   124   return this._layoutManager.selector.children("").slice(this.start, this.end);  
       
   125 };