author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/YUI-extensions/layout/LayoutStateManager.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/YUI-extensions/layout/LayoutStateManager.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/YUI-extensions/layout/LayoutStateManager.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/layout/LayoutStateManager.js b/frontend/beta/js/YUI-extensions/layout/LayoutStateManager.js new file mode 100644 index 0000000..ea22235 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/layout/LayoutStateManager.js | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * Private internal class for reading and applying state | ||
3 | */ | ||
4 | YAHOO.ext.LayoutStateManager = function(layout){ | ||
5 | // default empty state | ||
6 | this.state = { | ||
7 | north: {}, | ||
8 | south: {}, | ||
9 | east: {}, | ||
10 | west: {} | ||
11 | }; | ||
12 | }; | ||
13 | |||
14 | YAHOO.ext.LayoutStateManager.prototype = { | ||
15 | init : function(layout, provider){ | ||
16 | this.provider = provider; | ||
17 | var state = provider.get(layout.id+'-layout-state'); | ||
18 | if(state){ | ||
19 | var wasUpdating = layout.isUpdating(); | ||
20 | if(!wasUpdating){ | ||
21 | layout.beginUpdate(); | ||
22 | } | ||
23 | for(var key in state){ | ||
24 | if(typeof state[key] != 'function'){ | ||
25 | var rstate = state[key]; | ||
26 | var r = layout.getRegion(key); | ||
27 | if(r && rstate){ | ||
28 | if(rstate.size){ | ||
29 | r.resizeTo(rstate.size); | ||
30 | } | ||
31 | if(rstate.collapsed == true){ | ||
32 | r.collapse(true); | ||
33 | }else{ | ||
34 | r.expand(null, true); | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | if(!wasUpdating){ | ||
40 | layout.endUpdate(); | ||
41 | } | ||
42 | this.state = state; | ||
43 | } | ||
44 | this.layout = layout; | ||
45 | layout.on('regionresized', this.onRegionResized, this, true); | ||
46 | layout.on('regioncollapsed', this.onRegionCollapsed, this, true); | ||
47 | layout.on('regionexpanded', this.onRegionExpanded, this, true); | ||
48 | }, | ||
49 | |||
50 | storeState : function(){ | ||
51 | this.provider.set(this.layout.id+'-layout-state', this.state); | ||
52 | }, | ||
53 | |||
54 | onRegionResized : function(region, newSize){ | ||
55 | this.state[region.getPosition()].size = newSize; | ||
56 | this.storeState(); | ||
57 | }, | ||
58 | |||
59 | onRegionCollapsed : function(region){ | ||
60 | this.state[region.getPosition()].collapsed = true; | ||
61 | this.storeState(); | ||
62 | }, | ||
63 | |||
64 | onRegionExpanded : function(region){ | ||
65 | this.state[region.getPosition()].collapsed = false; | ||
66 | this.storeState(); | ||
67 | } | ||
68 | }; | ||