aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.js
diff options
context:
space:
mode:
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.js133
1 files changed, 133 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..d2c81b93
--- /dev/null
+++ b/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.js
@@ -0,0 +1,133 @@
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
7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component;
9
10exports.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) { 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
89 update: {
90 value: function() {
91 if(this.cssText !== this.rule.cssText) {
92 // TODO: add update for selector and stylesheet name
93 this.declarationComponent.update();
94 }
95 }
96 },
97
98 templateDidLoad : {
99 value: function() {
100 //console.log("css style rule : template did load");
101 }
102 },
103 prepareForDraw : {
104 value: function() {
105 if(this.rule.type === 'inline') {
106 this.selectorField.readOnly = true;
107 } else {
108 this.selectorField.addEventListener('change', this, false);
109 }
110 //console.log("css style rule : prepare for draw");
111
112 }
113 },
114 willDraw : {
115 value: function() {
116 if(this.applied) {
117 this.element.removeAttribute('title');
118 } else {
119 this.element.title = "Rule does not apply to selection";
120 }
121 }
122 },
123 draw : {
124 value: function() {
125 //console.log("css style rule : draw");
126 if(this.applied) {
127 this.element.classList.remove(this.unappliedClass);
128 } else {
129 this.element.classList.add(this.unappliedClass);
130 }
131 }
132 }
133});