| author | veltr |
| Fri, 30 Mar 2012 18:00:26 +0200 | |
| branch | popcorn-port |
| changeset 840 | ac66e2240e1e |
| parent 542 | b33516ab03e8 |
| child 842 | 4ae2247a59f4 |
| permissions | -rw-r--r-- |
| 111 | 1 |
/* layout.js - very basic layout management */ |
2 |
||
| 525 | 3 |
/** |
4 |
@class a layout manager manages a div and the layout of objects |
|
| 111 | 5 |
inside it. |
6 |
*/ |
|
7 |
IriSP.LayoutManager = function(options) { |
|
8 |
this._Popcorn = null; |
|
9 |
this._widgets = []; |
|
10 |
|
|
| 113 | 11 |
this._div = "LdtPlayer"; |
| 111 | 12 |
this._width = 640; |
13 |
|
|
14 |
if (options === undefined) { |
|
15 |
options = {}; |
|
16 |
}; |
|
17 |
|
|
| 117 | 18 |
if (options.hasOwnProperty('container')) { |
19 |
this._div = options.container; |
|
| 111 | 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 |
|
|
| 113 | 30 |
/* this is a shortcut */ |
31 |
this.selector = IriSP.jQuery("#" + this._div); |
|
32 |
|
|
| 840 | 33 |
this.selector.css({ |
34 |
"width": this._width, |
|
35 |
"clear": "both" |
|
36 |
}); |
|
| 159 | 37 |
|
38 |
if (this._height !== undefined) |
|
39 |
this.selector.css("height", this._height); |
|
| 111 | 40 |
}; |
41 |
||
| 525 | 42 |
/** |
43 |
Set the popcorn instance used by the manager. |
|
44 |
|
|
45 |
we need this special setter because of a chicken and egg problem : |
|
| 111 | 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 |
||
| 525 | 54 |
/** create a subdiv with an unique id, and a spacer div as well. |
|
539
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
525
diff
changeset
|
55 |
@param widgetName the name of the widget. |
| 525 | 56 |
@return an array of the form [createdivId, spacerdivId]. |
57 |
*/ |
|
|
539
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
525
diff
changeset
|
58 |
IriSP.LayoutManager.prototype.createDiv = function(widgetName) { |
|
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
525
diff
changeset
|
59 |
if (typeof(widgetName) === "undefined") |
|
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
525
diff
changeset
|
60 |
widgetName = ""; |
|
315
4466bf448426
updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents:
288
diff
changeset
|
61 |
|
|
539
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
525
diff
changeset
|
62 |
var newDiv = IriSP.guid(this._div + "_widget_" + widgetName + "_"); |
|
499
0a09ff3db7c2
made the layout manager use our own guid generation routine.
hamidouk
parents:
468
diff
changeset
|
63 |
var spacerDiv = IriSP.guid("LdtPlayer_spacer_"); |
|
539
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
525
diff
changeset
|
64 |
this._widgets.push([widgetName, newDiv]); |
| 217 | 65 |
|
| 840 | 66 |
var divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative; clear: both;'></div"; |
|
468
651528a4f795
fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents:
356
diff
changeset
|
67 |
var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}};'></div"; |
| 113 | 68 |
|
|
468
651528a4f795
fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents:
356
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
|
|
356
1a84cdc88d9f
spacer are now inserted after the div instead of before. It makes more sense
hamidouk
parents:
315
diff
changeset
|
73 |
this.selector.append(divCode); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
217
diff
changeset
|
74 |
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
|
75 |
|
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
217
diff
changeset
|
76 |
return [newDiv, spacerDiv]; |
|
539
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
525
diff
changeset
|
77 |
}; |