1 /* layout.js - very basic layout management */ |
1 /* layout.js - very basic layout management */ |
2 |
2 |
3 /* |
3 define(["IriSP"], function() { |
4 a layout manager manages a div and the layout of objects |
4 /* |
5 inside it. |
5 a layout manager manages a div and the layout of objects |
6 */ |
6 inside it. |
|
7 */ |
7 |
8 |
8 IriSP.LayoutManager = function(options) { |
9 IriSP.LayoutManager = function(options) { |
9 this._Popcorn = null; |
10 this._Popcorn = null; |
10 this._widgets = []; |
11 this._widgets = []; |
11 |
12 |
12 this._div = "LdtPlayer"; |
13 this._div = "LdtPlayer"; |
13 this._width = 640; |
14 this._width = 640; |
14 |
15 |
15 if (options === undefined) { |
16 if (options === undefined) { |
16 options = {}; |
17 options = {}; |
17 }; |
18 }; |
18 |
19 |
19 if (options.hasOwnProperty('container')) { |
20 if (options.hasOwnProperty('container')) { |
20 this._div = options.container; |
21 this._div = options.container; |
21 } |
22 } |
22 |
23 |
23 if (options.hasOwnProperty('width')) { |
24 if (options.hasOwnProperty('width')) { |
24 this._width = options.width; |
25 this._width = options.width; |
25 } |
26 } |
26 |
27 |
27 if (options.hasOwnProperty('height')) { |
28 if (options.hasOwnProperty('height')) { |
28 this._height = options.height; |
29 this._height = options.height; |
29 } |
30 } |
30 |
31 |
31 /* this is a shortcut */ |
32 /* this is a shortcut */ |
32 this.selector = IriSP.jQuery("#" + this._div); |
33 this.selector = IriSP.jQuery("#" + this._div); |
33 |
34 |
34 this.selector.css("width", this._width); |
35 this.selector.css("width", this._width); |
35 |
36 |
36 if (this._height !== undefined) |
37 if (this._height !== undefined) |
37 this.selector.css("height", this._height); |
38 this.selector.css("height", this._height); |
38 }; |
39 }; |
39 |
40 |
40 /* we need this special setter because of a chicken and egg problem : |
41 /* we need this special setter because of a chicken and egg problem : |
41 we want the manager to use popcorn but the popcorn div will be managed |
42 we want the manager to use popcorn but the popcorn div will be managed |
42 by the manager. So we need a way to set the instance the manager uses |
43 by the manager. So we need a way to set the instance the manager uses |
43 */ |
44 */ |
44 |
45 |
45 IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) { |
46 IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) { |
46 this._Popcorn = popcorn; |
47 this._Popcorn = popcorn; |
47 /* FIXME - don't forget to add the popcorn messages handlers there */ |
48 /* FIXME - don't forget to add the popcorn messages handlers there */ |
48 } |
49 } |
49 |
50 |
50 IriSP.LayoutManager.prototype.createDiv = function() { |
51 IriSP.LayoutManager.prototype.createDiv = function() { |
51 var newDiv = Popcorn.guid(this._div + "_widget_"); |
52 var newDiv = Popcorn.guid(this._div + "_widget_"); |
52 this._widgets.push(newDiv); |
53 this._widgets.push(newDiv); |
53 |
54 |
54 var templ = "<div id='{{id}}' style='width: 100%; position: relative;'></div"; |
55 var templ = "<div id='{{id}}' style='width: 100%; position: relative;'></div"; |
55 var txt = Mustache.to_html(templ, {id: newDiv}); |
56 var txt = Mustache.to_html(templ, {id: newDiv}); |
56 this.selector.append(txt); |
57 this.selector.append(txt); |
57 |
58 |
58 return newDiv; |
59 return newDiv; |
59 }; |
60 }; |
|
61 }); |