src/js/layout.js
author hamidouk
Mon, 19 Dec 2011 15:25:22 +0100
branchpopcorn-port
changeset 481 a46cfeee6d77
parent 468 651528a4f795
child 499 0a09ff3db7c2
permissions -rw-r--r--
using jquery ui draggable changes the state of an element from absolute to relative positioning, which breaks the way our seek button expands itself, so we need to force absolute positioning, quite uglily, using jquery.
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
468
651528a4f795 fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents: 356
diff changeset
    58
    var divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative;'></div";
651528a4f795 fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents: 356
diff changeset
    59
    var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}};'></div";
113
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    60
    
468
651528a4f795 fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents: 356
diff changeset
    61
    var divCode = Mustache.to_html(divTempl, {id: newDiv, width: this._width});
651528a4f795 fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents: 356
diff changeset
    62
    var spacerCode = Mustache.to_html(spacerTempl, {spacer_id: spacerDiv, width: this._width,
651528a4f795 fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents: 356
diff changeset
    63
                                                    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
    64
356
1a84cdc88d9f spacer are now inserted after the div instead of before. It makes more sense
hamidouk
parents: 315
diff changeset
    65
    this.selector.append(divCode);
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    66
    this.selector.append(spacerCode);
356
1a84cdc88d9f spacer are now inserted after the div instead of before. It makes more sense
hamidouk
parents: 315
diff changeset
    67
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 217
diff changeset
    68
    return [newDiv, spacerDiv];
113
ebfd0d17e427 small changes to the layout manager.
hamidouk
parents: 111
diff changeset
    69
};