src/js/layout.js
author hamidouk
Tue, 29 Nov 2011 11:09:08 +0100
branchpopcorn-port
changeset 345 8a088f7daa66
parent 315 4466bf448426
child 356 1a84cdc88d9f
permissions -rw-r--r--
rollover over the interface buttons now works as expected. Also changed the width of the buttons to the correct size. Resized the width and height of the sprites to be the same as the boxes we display them in.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
111
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     1
/* layout.js - very basic layout management */
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     2
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     3
/*
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     4
  a layout manager manages a div and the layout of objects
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     5
  inside it.
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     6
*/
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     7
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     8
IriSP.LayoutManager = function(options) {
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
     9
    this._Popcorn = null;
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    10
    this._widgets = [];
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    11
    
113
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    12
    this._div = "LdtPlayer";
111
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    13
    this._width = 640;
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    14
    
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    15
    if (options === undefined) {
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    16
      options = {};
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    17
    };
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    18
    
117
b0a699baf3f1 some renames to the layout internal structures.
hamidouk
parents: 113
diff changeset
    19
    if (options.hasOwnProperty('container')) {
b0a699baf3f1 some renames to the layout internal structures.
hamidouk
parents: 113
diff changeset
    20
      this._div = options.container;
111
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    21
    }
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    22
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    23
    if (options.hasOwnProperty('width')) {
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    24
      this._width = options.width;
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    25
    }    
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    26
    
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    27
    if (options.hasOwnProperty('height')) {
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    28
      this._height = options.height;
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    29
    } 
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    30
    
113
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    31
    /* this is a shortcut */
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    32
    this.selector = IriSP.jQuery("#" + this._div);
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    33
    
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    34
    this.selector.css("width", this._width);
159
de92bfdcbe4c removed default height from layout.js.
hamidouk
parents: 138
diff changeset
    35
    
de92bfdcbe4c removed default height from layout.js.
hamidouk
parents: 138
diff changeset
    36
    if (this._height !== undefined)
de92bfdcbe4c removed default height from layout.js.
hamidouk
parents: 138
diff changeset
    37
      this.selector.css("height", this._height);
111
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    38
};
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    39
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    40
/* we need this special setter because of a chicken and egg problem :
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    41
   we want the manager to use popcorn but the popcorn div will be managed
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    42
   by the manager. So we need a way to set the instance the manager uses
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    43
*/
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    44
   
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    45
IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) {
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    46
    this._Popcorn = popcorn;
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    47
}
df08c7f9535c added a basic layout manager.
hamidouk
parents:
diff changeset
    48
315
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 288
diff changeset
    49
/* stem is a string to append to the id of the widget */
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 288
diff changeset
    50
IriSP.LayoutManager.prototype.createDiv = function(stem) {
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 288
diff changeset
    51
    if (typeof(stem) === "undefined")
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 288
diff changeset
    52
       stem = "";
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 288
diff changeset
    53
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 288
diff changeset
    54
    var newDiv = Popcorn.guid(this._div + "_widget_" + stem + "_");
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 288
diff changeset
    55
    var spacerDiv = Popcorn.guid("LdtPlayer_spacer_");
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 159
diff changeset
    56
    this._widgets.push(newDiv);
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 159
diff changeset
    57
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    58
    var divTempl = "<div id='{{id}}' style='width: 100%; position: relative;'></div";
288
25fe0c8831de made the spacer height configurable. set to 0 by default.
hamidouk
parents: 287
diff changeset
    59
    var spacerTempl = "<div id='{{spacer_id}}' style='width: 100%; position: relative; height: {{spacer_div_height}};'></div";
113
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    60
    
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    61
    var divCode = Mustache.to_html(divTempl, {id: newDiv});
288
25fe0c8831de made the spacer height configurable. set to 0 by default.
hamidouk
parents: 287
diff changeset
    62
    var spacerCode = Mustache.to_html(spacerTempl, {spacer_id: spacerDiv, spacer_div_height: IriSP.widgetsDefaults.LayoutManager.spacer_div_height });
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    63
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    64
    this.selector.append(spacerCode);
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    65
    this.selector.append(divCode);
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    66
    
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    67
    return [newDiv, spacerDiv];
113
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    68
};