diff options
Diffstat (limited to 'js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.js')
-rw-r--r-- | js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.js | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.js b/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.js new file mode 100644 index 00000000..ac714bfa --- /dev/null +++ b/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.js | |||
@@ -0,0 +1,148 @@ | |||
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.CssStyleRule = Montage.create(Component, { | ||
11 | unappliedClass : { | ||
12 | value: 'unapplied-css-rule' | ||
13 | }, | ||
14 | cssText: { | ||
15 | value: null | ||
16 | }, | ||
17 | hasTemplate: { | ||
18 | value: true | ||
19 | }, | ||
20 | focusDelegate : { | ||
21 | value: null | ||
22 | }, | ||
23 | _applied : { | ||
24 | value: true, | ||
25 | distinct: true | ||
26 | }, | ||
27 | applied : { | ||
28 | get: function() { | ||
29 | return this._applied; | ||
30 | }, | ||
31 | set: function(value) { | ||
32 | if(this._applied === value || value === undefined || value === null) { return false; } | ||
33 | |||
34 | this._applied = value; | ||
35 | this.needsDraw = true; | ||
36 | } | ||
37 | }, | ||
38 | |||
39 | _rule : { | ||
40 | value : null | ||
41 | }, | ||
42 | rule : { | ||
43 | get: function() { | ||
44 | return this._rule; | ||
45 | }, | ||
46 | set: function(rule) { | ||
47 | this.cssText = rule.cssText; | ||
48 | |||
49 | if(rule.type === 'inline') { | ||
50 | this.sheetName = 'Inline Style'; | ||
51 | } else { | ||
52 | this.sheetName = rule.href || 'Style Tag'; | ||
53 | } | ||
54 | |||
55 | this.selector = rule.selectorText; | ||
56 | this.declaration = rule.style; | ||
57 | |||
58 | console.log('Rule with selector "' +rule.selectorText+ '" is set on componenet.'); | ||
59 | |||
60 | this._rule = rule; | ||
61 | } | ||
62 | }, | ||
63 | declarationComponent: { | ||
64 | value: null | ||
65 | }, | ||
66 | _declaration: { | ||
67 | value: null | ||
68 | }, | ||
69 | declaration: { | ||
70 | get: function() { | ||
71 | return this._declaration; | ||
72 | }, | ||
73 | set: function(dec) { | ||
74 | this._declaration = dec; | ||
75 | } | ||
76 | }, | ||
77 | condition: { | ||
78 | value: false | ||
79 | }, | ||
80 | |||
81 | handleChange : { | ||
82 | value: function(e) { | ||
83 | if(this.focusDelegate) { | ||
84 | this.focusDelegate.handleSelectorChange(this.rule, this.selectorField.value, this); | ||
85 | } | ||
86 | } | ||
87 | }, | ||
88 | handleMouseover: { | ||
89 | value: function(e) { | ||
90 | if(this.focusDelegate) { | ||
91 | this.focusDelegate.handleSelectorHover(this.selectorField.value, 'over'); | ||
92 | } | ||
93 | } | ||
94 | }, | ||
95 | handleMouseout: { | ||
96 | value: function(e) { | ||
97 | if(this.focusDelegate) { | ||
98 | this.focusDelegate.handleSelectorHover(this.selectorField.value, 'out'); | ||
99 | } | ||
100 | } | ||
101 | }, | ||
102 | update: { | ||
103 | value: function() { | ||
104 | if(this.cssText !== this.rule.cssText) { | ||
105 | // TODO: add update for selector and stylesheet name | ||
106 | this.declarationComponent.update(); | ||
107 | } | ||
108 | } | ||
109 | }, | ||
110 | |||
111 | templateDidLoad : { | ||
112 | value: function() { | ||
113 | //console.log("css style rule : template did load"); | ||
114 | } | ||
115 | }, | ||
116 | prepareForDraw : { | ||
117 | value: function() { | ||
118 | if(this.rule.type === 'inline') { | ||
119 | this.selectorField.readOnly = true; | ||
120 | this.declarationComponent.type = 'inline'; | ||
121 | } else { | ||
122 | this.selectorField.addEventListener('change', this, false); | ||
123 | this.selectorField.element.addEventListener('mouseover', this, false); | ||
124 | this.selectorField.element.addEventListener('mouseout', this, false); | ||
125 | } | ||
126 | } | ||
127 | }, | ||
128 | |||
129 | willDraw : { | ||
130 | value: function() { | ||
131 | if(this.applied) { | ||
132 | this.element.removeAttribute('title'); | ||
133 | } else { | ||
134 | this.element.title = "Rule does not apply to selection"; | ||
135 | } | ||
136 | } | ||
137 | }, | ||
138 | draw : { | ||
139 | value: function() { | ||
140 | //console.log("css style rule : draw"); | ||
141 | if(this.applied) { | ||
142 | this.element.classList.remove(this.unappliedClass); | ||
143 | } else { | ||
144 | this.element.classList.add(this.unappliedClass); | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | }); | ||