src/js/layout.js
branchpopcorn-port
changeset 539 3ba5b82aebb6
parent 525 af5248f4d37e
child 542 b33516ab03e8
equal deleted inserted replaced
538:b778b2f93ef4 539:3ba5b82aebb6
    47 IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) {
    47 IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) {
    48     this._Popcorn = popcorn;
    48     this._Popcorn = popcorn;
    49 }
    49 }
    50 
    50 
    51 /** create a subdiv with an unique id, and a spacer div as well.
    51 /** create a subdiv with an unique id, and a spacer div as well.
    52     @param stem stem is a string to append to the id of the widget
    52     @param widgetName the name of the widget.
    53     @return an array of the form [createdivId, spacerdivId].
    53     @return an array of the form [createdivId, spacerdivId].
    54 */
    54 */
    55 IriSP.LayoutManager.prototype.createDiv = function(stem) {
    55 IriSP.LayoutManager.prototype.createDiv = function(widgetName) {
    56     if (typeof(stem) === "undefined")
    56     if (typeof(widgetName) === "undefined")
    57        stem = "";
    57        widgetName = "";
    58 
    58 
    59     var newDiv = IriSP.guid(this._div + "_widget_" + stem + "_");
    59     var newDiv = IriSP.guid(this._div + "_widget_" + widgetName + "_");
    60     var spacerDiv = IriSP.guid("LdtPlayer_spacer_");
    60     var spacerDiv = IriSP.guid("LdtPlayer_spacer_");
    61     this._widgets.push(newDiv);
    61     this._widgets.push([widgetName, newDiv]);    
    62 
    62 
    63     var divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative;'></div";
    63     var divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative;'></div";
    64     var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}};'></div";
    64     var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}};'></div";
    65     
    65     
    66     var divCode = Mustache.to_html(divTempl, {id: newDiv, width: this._width});
    66     var divCode = Mustache.to_html(divTempl, {id: newDiv, width: this._width});
    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 };