diff options
Diffstat (limited to 'js/panels/css-panel/rule-list-container.reel/rule-list-container.js')
-rw-r--r-- | js/panels/css-panel/rule-list-container.reel/rule-list-container.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/js/panels/css-panel/rule-list-container.reel/rule-list-container.js b/js/panels/css-panel/rule-list-container.reel/rule-list-container.js new file mode 100644 index 00000000..17bdc2a4 --- /dev/null +++ b/js/panels/css-panel/rule-list-container.reel/rule-list-container.js | |||
@@ -0,0 +1,128 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component; | ||
9 | |||
10 | exports.RuleListContainer = Montage.create(Component, { | ||
11 | _instanceToAdd : { value: null }, | ||
12 | _appendElement : { value: null }, | ||
13 | _lastDisplayedList : { value: null }, | ||
14 | _displayedList : { value: null }, | ||
15 | |||
16 | displayedList : { | ||
17 | get: function() { | ||
18 | return this._displayedList; | ||
19 | }, | ||
20 | set: function(list) { | ||
21 | this._lastDisplayedList = this._displayedList; | ||
22 | this._displayedList = list; | ||
23 | this.needsDraw = true; | ||
24 | } | ||
25 | }, | ||
26 | |||
27 | displayListForSelection : { | ||
28 | value: function(selection) { | ||
29 | var list = this._getListForSelection(selection); | ||
30 | |||
31 | if(!list) { | ||
32 | list = this.add(selection); | ||
33 | } else { | ||
34 | console.log("rule list found!"); | ||
35 | } | ||
36 | |||
37 | this.displayedList = list; | ||
38 | } | ||
39 | }, | ||
40 | |||
41 | //// Get the element containing list based on selection | ||
42 | _getListForSelection : { | ||
43 | value: function(selection) { | ||
44 | var i, list, matchesAll; | ||
45 | |||
46 | for(i = 0; i<this.ruleLists.length; i++) { | ||
47 | list = this.ruleLists[i]; | ||
48 | |||
49 | if(selection.length > 1) { | ||
50 | matchesAll = list.selection.every(function(element, index, array) { | ||
51 | return array.indexOf(element) !== 0; | ||
52 | }); | ||
53 | |||
54 | if(matchesAll) { | ||
55 | break; | ||
56 | } | ||
57 | } else { | ||
58 | ///// Selection (single element or stylesheet) is the same, | ||
59 | ///// Use the existing rule list | ||
60 | if(list.selection[0] === selection[0]) { | ||
61 | break; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | list = null; | ||
66 | } | ||
67 | |||
68 | return list; | ||
69 | |||
70 | } | ||
71 | }, | ||
72 | |||
73 | //// Creates a new rule list to be added to the container | ||
74 | add : { | ||
75 | value: function(selection) { | ||
76 | var stylesController = this.application.ninja.stylesController, | ||
77 | listInstance = Montage.create(this.ruleListComponent), | ||
78 | container = document.createElement('div'), | ||
79 | rules, ruleListLog; | ||
80 | |||
81 | if(selection.length === 1) { | ||
82 | rules = stylesController.getMatchingRules(selection[0]); | ||
83 | } //// TODO: support more selection types | ||
84 | |||
85 | this._instanceToAdd = listInstance; | ||
86 | listInstance.rules = rules; | ||
87 | |||
88 | ruleListLog = { | ||
89 | selection: selection, | ||
90 | component : listInstance | ||
91 | }; | ||
92 | |||
93 | this.ruleLists.push(ruleListLog); | ||
94 | |||
95 | this._appendElement = container; | ||
96 | this.needsDraw = true; | ||
97 | |||
98 | return ruleListLog; | ||
99 | } | ||
100 | }, | ||
101 | |||
102 | //// Array of lists that have been added to the container | ||
103 | //// Lists include selection type (element/stylesheet), and | ||
104 | //// the selection itself | ||
105 | ruleLists : { | ||
106 | value: [], | ||
107 | distinct: true | ||
108 | }, | ||
109 | |||
110 | draw : { | ||
111 | value: function() { | ||
112 | if(this._appendElement) { | ||
113 | this.element.appendChild(this._appendElement); | ||
114 | this._instanceToAdd.element = this._appendElement; | ||
115 | this._appendElement = null; | ||
116 | this.needsDraw = true; | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | if(this._lastDisplayedList) { | ||
121 | this._lastDisplayedList.component.element.style.display = 'none'; | ||
122 | if(this._displayedList.component.element) { | ||
123 | this._displayedList.component.element.style.display = null; | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | }); \ No newline at end of file | ||