src/js/layout.js
branchnew-model
changeset 868 a525cc2214e7
parent 842 4ae2247a59f4
equal deleted inserted replaced
866:3bf7aa8216e5 868:a525cc2214e7
     1 /* layout.js - very basic layout management */
     1 /* layout.js - very basic layout management */
     2 
     2 
     3 /**
     3 /* Has been integrated to init.js */
     4   @class a layout manager manages a div and the layout of objects
       
     5   inside it.
       
     6 */
       
     7 IriSP.LayoutManager = function(options) {
       
     8     this._Popcorn = null;
       
     9     this._widgets = [];
       
    10     
       
    11     this._div = "LdtPlayer";
       
    12     this._width = 640;
       
    13     
       
    14     if (options === undefined) {
       
    15       options = {};
       
    16     };
       
    17     
       
    18     if (options.hasOwnProperty('container')) {
       
    19       this._div = options.container;
       
    20     }
       
    21 
       
    22     if (options.hasOwnProperty('width')) {
       
    23       this._width = options.width;
       
    24     }    
       
    25     
       
    26     if (options.hasOwnProperty('height')) {
       
    27       this._height = options.height;
       
    28     } 
       
    29     
       
    30     /* this is a shortcut */
       
    31     this.selector = IriSP.jQuery("#" + this._div);
       
    32     
       
    33     this.selector.css({
       
    34         "width": this._width,
       
    35         "clear": "both"
       
    36     });
       
    37     
       
    38     if (this._height !== undefined)
       
    39       this.selector.css("height", this._height);
       
    40 };
       
    41 
       
    42 /** 
       
    43    Set the popcorn instance used by the manager.
       
    44    
       
    45    we need this special setter because of a chicken and egg problem :
       
    46    we want the manager to use popcorn but the popcorn div will be managed
       
    47    by the manager. So we need a way to set the instance the manager uses
       
    48 */
       
    49    
       
    50 IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) {
       
    51     this._Popcorn = popcorn;
       
    52 }
       
    53 
       
    54 /** create a subdiv with an unique id, and a spacer div as well.
       
    55     @param widgetName the name of the widget.
       
    56     @return an array of the form [createdivId, spacerdivId].
       
    57 */
       
    58 IriSP.LayoutManager.prototype.createDiv = function(widgetName) {
       
    59     if (typeof(widgetName) === "undefined")
       
    60        widgetName = "";
       
    61 
       
    62     var newDiv = IriSP.guid(this._div + "_widget_" + widgetName + "_");
       
    63     var spacerDiv = IriSP.guid("LdtPlayer_spacer_");
       
    64     this._widgets.push([widgetName, newDiv]);    
       
    65 
       
    66     var divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative; clear: both;'></div";
       
    67     var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}}px;'></div";
       
    68     
       
    69     var divCode = Mustache.to_html(divTempl, {id: newDiv, width: this._width});
       
    70     var spacerCode = Mustache.to_html(spacerTempl, {spacer_id: spacerDiv, width: this._width,
       
    71                                                     spacer_div_height: IriSP.widgetsDefaults.LayoutManager.spacer_div_height });
       
    72 
       
    73     this.selector.append(divCode);
       
    74     this.selector.append(spacerCode);
       
    75 
       
    76     return [newDiv, spacerDiv];
       
    77 };