diff options
Diffstat (limited to 'js/panels/CSSPanel/CSSPanelBase.reel/CSSPanelBase.js')
-rw-r--r-- | js/panels/CSSPanel/CSSPanelBase.reel/CSSPanelBase.js | 2885 |
1 files changed, 2885 insertions, 0 deletions
diff --git a/js/panels/CSSPanel/CSSPanelBase.reel/CSSPanelBase.js b/js/panels/CSSPanel/CSSPanelBase.reel/CSSPanelBase.js new file mode 100644 index 00000000..ae7e5c14 --- /dev/null +++ b/js/panels/CSSPanel/CSSPanelBase.reel/CSSPanelBase.js | |||
@@ -0,0 +1,2885 @@ | |||
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 cssPropertyNameList = require("js/panels/CSSPanel/css-property-name-list").cssPropertyNameList, | ||
8 | cssCompletionMap = require("js/panels/CSSPanel/css-value-completion-map").cssValueCompletionMap, | ||
9 | CSS_SHORTHAND_MAP = require("js/panels/CSSPanel/css-shorthand-map").CSS_SHORTHAND_MAP, | ||
10 | keyboardModule = require("js/mediators/keyboard-mediator").Keyboard, | ||
11 | nj = require("js/lib/NJUtils.js").NJUtils; | ||
12 | |||
13 | |||
14 | |||
15 | var CSSPanel = exports.CSSPanelBase = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, { | ||
16 | prepareForDraw: { | ||
17 | value: function() { | ||
18 | var self = this; | ||
19 | |||
20 | this.sections = { | ||
21 | sheets : { | ||
22 | container : nj.$('nj-section-stylesheets'), | ||
23 | heading : nj.$('nj-css-sheets-header'), | ||
24 | arrow : nj.$('nj-css-sheets-arrow'), | ||
25 | doc : null, | ||
26 | listEl : nj.$('nj-sheet-list'), | ||
27 | docNameEl : nj.$('nj-current-doc-name'), | ||
28 | collapsed : false, | ||
29 | toolbar : nj.$('nj-css-stylesheet-toolbar'), | ||
30 | addSheetEl: nj.$('nj-css-add-stylesheet') | ||
31 | }, | ||
32 | styles : { | ||
33 | container : nj.$('nj-section-styles'), | ||
34 | heading : nj.$('nj-css-styles-header'), | ||
35 | statusMsg : nj.$('nj-status-heading'), | ||
36 | arrow : nj.$('nj-css-styles-arrow'), | ||
37 | listEl : nj.$('nj-css-rule-list'), | ||
38 | elNameEl : nj.$('nj-current-element-name'), | ||
39 | collapsed : false, | ||
40 | currentEl : null, | ||
41 | toolbar : nj.$('nj-css-styles-toolbar'), | ||
42 | addRuleEl : nj.$('nj-css-add-rule'), | ||
43 | showComputedEl : nj.$('nj-css-show-computed'), | ||
44 | numItemsEl : nj.$('nj-num-items') | ||
45 | } | ||
46 | }; | ||
47 | |||
48 | ///// Set up collapsible sub sections | ||
49 | ['sheets', 'styles'].forEach(function(section) { | ||
50 | var s = section; | ||
51 | self.sections[s].heading.addEventListener('click', function(e) { | ||
52 | self.toggleSectionCollapse(s); | ||
53 | }, false); | ||
54 | }); | ||
55 | |||
56 | //// Hook into selection manager | ||
57 | |||
58 | this.eventManager.addEventListener("selectionChange", this, true); | ||
59 | this.eventManager.addEventListener("elementChange", this, true); | ||
60 | this.eventManager.addEventListener("openDocument", this, true); | ||
61 | |||
62 | if(this.application.ninja.currentDocument) { | ||
63 | this.captureOpenDocument(); | ||
64 | } | ||
65 | |||
66 | this.addEventListener('webkitTransitionEnd', this, false); | ||
67 | ['sheets', 'styles'].forEach(function(section) { | ||
68 | this.sections[section].container.style.height = 'auto'; | ||
69 | // //console.log('setting height to auto for section "' + section + '".'); | ||
70 | }.bind(this)); | ||
71 | |||
72 | this._setUpStyleEditMode(); | ||
73 | this._setUpToolbars(); | ||
74 | } | ||
75 | }, | ||
76 | captureOpenDocument : { | ||
77 | value : function(e) { | ||
78 | this.populateStyleSheetList(); | ||
79 | } | ||
80 | }, | ||
81 | handleWebkitTransitionEnd : { | ||
82 | value: function(e) { | ||
83 | //console.log('transition end at panel base'); | ||
84 | e.stopPropagation(); | ||
85 | } | ||
86 | }, | ||
87 | |||
88 | populateStyleSheetList: { | ||
89 | value: function() { | ||
90 | this.sections.sheets.doc = this.application.ninja.currentDocument._document; | ||
91 | var styleTagCount = 0, | ||
92 | sect = this.sections.sheets, | ||
93 | sheetsArray = nj.toArray(sect.doc.styleSheets), | ||
94 | listEl = sect.listEl, | ||
95 | contEl = sect.container, | ||
96 | userDocName = nj.getFileNameFromPath(sect.doc.defaultView.location.href), | ||
97 | self = this; | ||
98 | |||
99 | ///// Set current document name in Stylesheets section header | ||
100 | nj.empty(sect.docNameEl).appendChild(nj.textNode(' - ' + userDocName)); | ||
101 | |||
102 | ///// LOOP through stylesheet list | ||
103 | ///// ------------------------------------------------------- | ||
104 | sheetsArray.forEach(function(sheet, index) { | ||
105 | var isStageStyleSheet = (sheet.ownerNode.id === this._stageStyleSheetId), | ||
106 | isDefaultStyleSheet = (sheet.ownerNode.id === this._defaultStyleSheetId), | ||
107 | sheetObj; | ||
108 | |||
109 | if(!isStageStyleSheet) { | ||
110 | sheetObj = new NJStyleSheet(sheet, index); | ||
111 | if(isDefaultStyleSheet) { | ||
112 | sheetObj.isProtected = sheetObj.isCurrent = true; | ||
113 | this.currentStyleSheet = this.defaultStyleSheet = sheetObj; | ||
114 | } | ||
115 | |||
116 | //// Add Default stylesheet selection | ||
117 | sheetObj.sheetNameEl.addEventListener('click', function(e) { | ||
118 | //console.log('clicking sheet'); | ||
119 | e.preventDefault(); | ||
120 | //e.stopPropagation(); | ||
121 | self.currentStyleSheet = sheetObj; | ||
122 | }, false); | ||
123 | |||
124 | sheetObj.deleteEl.addEventListener('click', function(e) { | ||
125 | if(sheetObj.isCurrent) { | ||
126 | self.defaultStyleSheet.makeCurrent(); | ||
127 | } | ||
128 | }, false); | ||
129 | |||
130 | sheetObj.render(listEl); | ||
131 | } | ||
132 | |||
133 | |||
134 | }, this); | ||
135 | ///// ________________________________________________________ | ||
136 | |||
137 | ///// save height of content, and convert height from "auto" to pixels | ||
138 | //sect.height = contEl.style.height = nj.height(contEl); | ||
139 | |||
140 | |||
141 | |||
142 | //contEl.style.webkitTransition = 'all 0.15s ease-out'; | ||
143 | |||
144 | } | ||
145 | }, | ||
146 | clearStyleSheetList : { | ||
147 | value: function() { | ||
148 | nj.empty(this.sections.sheets.listEl); | ||
149 | } | ||
150 | }, | ||
151 | _preventAdvanceToNext : { // don't advance if there's an error on stop edit | ||
152 | value: false | ||
153 | }, | ||
154 | _setUpStyleEditMode: { | ||
155 | value: function() { | ||
156 | var self = this; | ||
157 | ///// Add onchange event to NJCSSStyle | ||
158 | NJCSSStyle.prototype.onStyleChange.push(function() { | ||
159 | self._stageUpdate(); | ||
160 | }); | ||
161 | |||
162 | ///// Add some NJEditable functionality | ||
163 | NJEditable.prototype.onStartEdit.push(function(e) { | ||
164 | if(this.isSelector && this.el.nodeContent === 'element.style') { | ||
165 | return; | ||
166 | } | ||
167 | var njStyle = this.el.parentNode.njcssstyle; | ||
168 | // //console.log('added start edit'); | ||
169 | this.el.parentNode.classList.add('nj-editing'); | ||
170 | if(this.el.nodeName === "DD") { | ||
171 | this.el.parentNode.classList.add('nj-editing-val'); // controls wrapping of text | ||
172 | if(cssCompletionMap[njStyle.property]) { | ||
173 | this.suggestions = cssCompletionMap[njStyle.property]; | ||
174 | } | ||
175 | } | ||
176 | }); | ||
177 | NJEditable.prototype.onStopEdit.push(function(e) { | ||
178 | var nextEl = this.el, | ||
179 | isAddButton = false, | ||
180 | autoSuggestArray = null, | ||
181 | nextEditable, sibling, njStyle, isAddBtn; | ||
182 | |||
183 | this.el.parentNode.classList.remove('nj-editing'); | ||
184 | this.el.parentNode.classList.remove('nj-editing-val'); | ||
185 | |||
186 | if(this.isSelector) { | ||
187 | if(e && [9,13].indexOf(e._event.keyCode) !== -1) { | ||
188 | // console.log('selector onStopEdit function'); | ||
189 | var propertyEl = nj.children(this.el.nextSibling.firstChild, function(item){ | ||
190 | return item.nodeName === 'DT'; | ||
191 | })[0]; | ||
192 | if(propertyEl.parentNode.njcssstyle.activate) { | ||
193 | ///// still the Add button | ||
194 | propertyEl.parentNode.njcssstyle.activate.bind(propertyEl)(); | ||
195 | delete propertyEl.parentNode.njcssstyle.activate; | ||
196 | } else { | ||
197 | nextEditable = propertyEl.njedit || new NJEditable(propertyEl, null, self.CSS_PROPERTY_NAMES); | ||
198 | nextEditable.startEditable(); | ||
199 | } | ||
200 | |||
201 | } | ||
202 | return false; | ||
203 | } | ||
204 | |||
205 | ////console.log('NJEditable onStopEdit callback'); | ||
206 | |||
207 | if(e && [9,13,186].indexOf(e._event.keyCode) !== -1) { // if the user is tabbing between styles | ||
208 | e.preventDefault(); | ||
209 | sibling = (e._event.keyCode === 9 && e._event.shiftKey) ? ['previousSibling', 'lastChild'] : ['nextSibling', 'firstChild']; | ||
210 | // //console.log('enter pressed - skip to next editable.'); | ||
211 | // move to the next editable dt/dd elements | ||