| author | hamidouk |
| Fri, 23 Dec 2011 15:44:34 +0100 | |
| branch | popcorn-port |
| changeset 525 | af5248f4d37e |
| parent 499 | 0a09ff3db7c2 |
| child 539 | 3ba5b82aebb6 |
| 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 |
|
|
33 |
this.selector.css("width", this._width); |
|
| 159 | 34 |
|
35 |
if (this._height !== undefined) |
|
36 |
this.selector.css("height", this._height); |
|
| 111 | 37 |
}; |
38 |
||
| 525 | 39 |
/** |
40 |
Set the popcorn instance used by the manager. |
|
41 |
|
|
42 |
we need this special setter because of a chicken and egg problem : |
|
| 111 | 43 |
we want the manager to use popcorn but the popcorn div will be managed |
44 |
by the manager. So we need a way to set the instance the manager uses |
|
45 |
*/ |
|
46 |
|
|
47 |
IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) { |
|
48 |
this._Popcorn = popcorn; |
|
49 |
} |
|
50 |
||
| 525 | 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 |
|
53 |
@return an array of the form [createdivId, spacerdivId]. |
|
54 |
*/ |
|
|
315
4466bf448426
updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents:
288
diff
changeset
|
55 |
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
|
56 |
if (typeof(stem) === "undefined") |
|
4466bf448426
updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents:
288
diff
changeset
|
57 |
stem = ""; |
|
4466bf448426
updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents:
288
diff
changeset
|
58 |
|
|
499
0a09ff3db7c2
made the layout manager use our own guid generation routine.
hamidouk
parents:
468
diff
changeset
|
59 |
var newDiv = IriSP.guid(this._div + "_widget_" + stem + "_"); |
|
0a09ff3db7c2
made the layout manager use our own guid generation routine.
hamidouk
parents:
468
diff
changeset
|
60 |
var spacerDiv = IriSP.guid("LdtPlayer_spacer_"); |
| 217 | 61 |
this._widgets.push(newDiv); |
62 |
||
|
468
651528a4f795
fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents:
356
diff
changeset
|
63 |
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
|
64 |
var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}};'></div"; |
| 113 | 65 |
|
|
468
651528a4f795
fixed a couple layout bugs that didn't appear in integration testing.
hamidouk
parents:
356
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
|
|
356
1a84cdc88d9f
spacer are now inserted after the div instead of before. It makes more sense
hamidouk
parents:
315
diff
changeset
|
70 |
this.selector.append(divCode); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
217
diff
changeset
|
71 |
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
|
72 |
|
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
217
diff
changeset
|
73 |
return [newDiv, spacerDiv]; |
| 113 | 74 |
}; |