From 143105a0b9c7765898b22d53489b4bd8df3dff2e Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Thu, 26 Apr 2012 03:15:49 -0700 Subject: CSS Panel - add handlers for css panel actions --- .../css-panel/declaration.reel/declaration.html | 7 +- .../css-panel/declaration.reel/declaration.js | 10 ++ .../css-style-rule.reel/css-style-rule.js | 8 ++ .../rule-list-container.js | 8 ++ js/panels/css-panel/rule-list.reel/rule-list.js | 9 +- .../style-shorthand.reel/style-shorthand.html | 4 +- js/panels/css-panel/style.reel/style.css | 22 +++- js/panels/css-panel/style.reel/style.html | 22 +++- js/panels/css-panel/style.reel/style.js | 126 ++++++++++++++++++++- .../styles-view-container.html | 5 +- js/panels/css-panel/styles-view-mediator.js | 77 ++++++++++++- 11 files changed, 277 insertions(+), 21 deletions(-) (limited to 'js') diff --git a/js/panels/css-panel/declaration.reel/declaration.html b/js/panels/css-panel/declaration.reel/declaration.html index 79865fed..3a513871 100644 --- a/js/panels/css-panel/declaration.reel/declaration.html +++ b/js/panels/css-panel/declaration.reel/declaration.html @@ -14,7 +14,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "module" : "js/panels/css-panel/declaration.reel", "name" : "Declaration", "properties" : { - "element" : {"#" : "container"} + "element" : {"#" : "container"}, + "treeController": {"@": "treeController"} } }, "styleShorthand": { @@ -26,9 +27,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "name": "TreeController", "properties" : { "branchKey" : "properties", - "labelKey" : "name", - - "delegate": {"@": "owner" } + "labelKey" : "name" }, "bindings": { "content": { diff --git a/js/panels/css-panel/declaration.reel/declaration.js b/js/panels/css-panel/declaration.reel/declaration.js index 55fe0e18..9685510b 100644 --- a/js/panels/css-panel/declaration.reel/declaration.js +++ b/js/panels/css-panel/declaration.reel/declaration.js @@ -9,12 +9,16 @@ var Montage = require("montage/core/core").Montage, ShorthandProps = require("js/panels/CSSPanel/css-shorthand-map"); exports.Declaration = Montage.create(Component, { + focusDelegate : { + value: null + }, includeEmptyStyle : { value: true }, templateDidLoad : { value: function() { console.log("declaration - template did load"); + this.treeController.delegate = this.focusDelegate || this; } }, prepareForDraw : { @@ -115,6 +119,12 @@ exports.Declaration = Montage.create(Component, { distinct: true }, + addNewStyle : { + value: function() { + debugger; + } + }, + /* drag/drop events */ handleDrop : { value: function(e) { 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 index dd51565a..d85b5797 100644 --- 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 @@ -14,6 +14,10 @@ exports.CssStyleRule = Montage.create(Component, { hasTemplate: { value: true }, + focusDelegate : { + value: null + }, + _rule : { value : null }, @@ -67,6 +71,10 @@ exports.CssStyleRule = Montage.create(Component, { if(this._declaration) { this.declarationComponent.declaration = this._declaration; } + + if(this.focusDelegate) { + this.declarationComponent.focusDelegate = this.focusDelegate; + } } }, prepareForDraw : { 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 index 4bad8350..a059af12 100644 --- 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 @@ -116,6 +116,14 @@ exports.RuleListContainer = Montage.create(Component, { distinct: true }, + templateDidLoad : { + value: function() { + if(this.focusDelegate) { + this.ruleListComponent.focusDelegate = this.focusDelegate; + } + } + }, + draw : { value: function() { if(this._appendElement) { diff --git a/js/panels/css-panel/rule-list.reel/rule-list.js b/js/panels/css-panel/rule-list.reel/rule-list.js index ebd7428b..0faff07e 100644 --- a/js/panels/css-panel/rule-list.reel/rule-list.js +++ b/js/panels/css-panel/rule-list.reel/rule-list.js @@ -8,7 +8,9 @@ var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; exports.RuleList = Montage.create(Component, { - + focusDelegate : { + value: null + }, ruleNodeName : { value: 'li' }, _rules: { value: null }, @@ -59,6 +61,11 @@ exports.RuleList = Montage.create(Component, { if(componentBase) { instance = Montage.create(componentBase); instance.rule = rule; + + if(this.focusDelegate) { + instance.focusDelegate = this.focusDelegate; + } + this.rulesToDraw.push(instance); this.needsDraw = true; } diff --git a/js/panels/css-panel/style-shorthand.reel/style-shorthand.html b/js/panels/css-panel/style-shorthand.reel/style-shorthand.html index 243d9cc7..0311798b 100644 --- a/js/panels/css-panel/style-shorthand.reel/style-shorthand.html +++ b/js/panels/css-panel/style-shorthand.reel/style-shorthand.html @@ -19,8 +19,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "branchList": {"#" : "branchList"}, "arrayController": {"@": "arrayController" }, "repetition": {"@": "repetition"}, - "leafComponent": {"@": "leaf"}, - "branchComponent": {"@": "branch"}, + "leafComponent": {"@": "style"}, + "branchComponent": {"@": "shorthand"}, "branchCollapser": {"#": "collapser" } } }, diff --git a/js/panels/css-panel/style.reel/style.css b/js/panels/css-panel/style.reel/style.css index f8750eea..ff410951 100644 --- a/js/panels/css-panel/style.reel/style.css +++ b/js/panels/css-panel/style.reel/style.css @@ -11,7 +11,7 @@ border-bottom: 1px solid rgba(0,0,0,0); cursor: url(/js/../images/tools/hand_down.png), default; display: block; - /*overflow: hidden;*/ + overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } @@ -20,6 +20,21 @@ margin-right: 3px; } +/* ------------------------ + Invalid Style +------------------------ */ +.style-item-invalid { + background-repeat: no-repeat; + background-position: 6px 2px; + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAALCAYAAABGbhwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWR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36%2Bz5GFgWZr75fjPDhBD4C%2BucjWgaphjQdTgK%2FfPi5a%2FGpPDtjEVjERyqKlag%2FlY8gHPsfzSwPbQgbDyfIs6vURa3EKK8Jf6jmhUy51yiWDlBUDED2NF0JKGQS3IPVn4ATXqIL0EYJgwD42YQG4quE45EggOtCwbWrUM1Ej%2F0jkXDAYaOtOa6iIH2YSQOBugPj4KN3aFdnIThkprynoeUYjtwIRO0hCLxiU3wp12odgl0AXhUa3VQ0xoWCqEApiNhEpFzt7Tm%2F4Tzo9kGvtq4UjNzqJB1mswURvNoqayP57V7KcB7HfZnE8v%2BHYtZtmiGcBzqQ1TSZUPP85HVlo1MfCaX94WPpSO83qwO6wbWCTtBQocoD70eDgZncw3Z%2BC3AAFMzlxlnnpevAAAAAElFTkSuQmCC); + opacity: 0.5; +} +.style-item.style-item-invalid:hover input { + visibility: hidden; +} +.style-item-invalid.edit-style-item { + opacity: 1; +} /* ------------------------ Checkbox ------------------------ */ @@ -52,6 +67,10 @@ .css-property:hover, .css-value:hover { background-color: #FFDECC; } +.css-property:focus, .css-value:focus { + border: 1px solid rgba(0,0,0,0); + box-shadow: none; +} .css-property:after { color: #333; content: ":"; @@ -102,6 +121,7 @@ cursor: default; -webkit-transition: -webkit-transform .2s cubic-bezier(0.44, 0.19, 0, 0.99); -webkit-transform: translate3d(-120px, 0, 0); + overflow: visible; } .empty-css-style:hover { border-right-style: none; diff --git a/js/panels/css-panel/style.reel/style.html b/js/panels/css-panel/style.reel/style.html index 0d438ead..469c7268 100644 --- a/js/panels/css-panel/style.reel/style.html +++ b/js/panels/css-panel/style.reel/style.html @@ -40,7 +40,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "name": "Hintable", "properties": { "startOnEvent": "click", - "element": {"#": "property"} + "element": {"#": "property"}, + "identifier": "property" }, "bindings": { "value" : { @@ -48,14 +49,21 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "boundObjectPropertyPath": "propertyText", "oneway": true } - } + }, + "listeners": [ + { + "type": "change", + "listener": {"@": "owner"} + } + ] }, "value": { "module": "js/components/hintable.reel", "name": "Hintable", "properties": { "startOnEvent": "click", - "element": {"#": "value"} + "element": {"#": "value"}, + "identifier": "value" }, "bindings": { "value" : { @@ -63,7 +71,13 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "boundObjectPropertyPath": "valueText", "oneway": true } - } + }, + "listeners": [ + { + "type": "change", + "listener": {"@": "owner"} + } + ] } } diff --git a/js/panels/css-panel/style.reel/style.js b/js/panels/css-panel/style.reel/style.js index adf17a84..517d1012 100644 --- a/js/panels/css-panel/style.reel/style.js +++ b/js/panels/css-panel/style.reel/style.js @@ -8,18 +8,47 @@ var Montage = require("montage/core/core").Montage, TreeNode = require("js/components/treeview/tree-node").TreeNode; exports.Style = Montage.create(TreeNode, { + delegate : { + value: null + }, disabledClass : { value: 'style-item-disabled' }, + editingStyleClass : { + value: 'edit-style-item' + }, editNewEmptyClass : { value: 'edit-empty-style' }, + invalidStyleClass : { + value: "style-item-invalid" + }, propertyText : { value: "property" }, - valueText : { + _valueText : { value: "value" }, + valueText : { + get: function() { + return this._valueText; + }, + set: function(text) { + this._valueText = text; + this.units = this.getUnits(text); + } + }, + + getUnits : { + value: function(val) { + if(val.split(/\s/).length > 1) { + return false; + } else if(/(px|em|pt|in|cm|mm|ex|pc|%)$/.test(val)) { + return val.replace(/^.*(px|em|pt|in|cm|mm|ex|pc|%).*/, '$1'); + } + return null; + } + }, _enabled : { value: true, distinct: true }, enabled : { @@ -42,6 +71,28 @@ exports.Style = Montage.create(TreeNode, { } }, + _invalid: { value: null }, + invalid : { + get: function() { + return this._invalid; + }, + set: function(value) { + this._invalid = value; + this.needsDraw = true; + } + }, + + _editing : { value : null }, + editing : { + get: function() { + return this._editing; + }, + set: function(value) { + this._editing = value; + this.needsDraw = true; + } + }, + _editingNewStyle : { value: null }, @@ -100,7 +151,13 @@ exports.Style = Montage.create(TreeNode, { handleClick : { value: function(e) { console.log("handleAction"); - this.editingNewStyle = true; + this.editingNewStyle = this.editing = true; + } + }, + + handleStart : { + value: function(e) { + this.editing = true; } }, @@ -116,15 +173,42 @@ exports.Style = Montage.create(TreeNode, { clicked = e._event.detail.originalEvent.target; return clicked !== this.propertyField.element && clicked !== this.valueField.element; } - return + return; } if(this.sourceObject.isEmpty && !this.dirty && shouldStopEditing.bind(this)()) { this.editingNewStyle = false; } + + this.treeView.contentController.delegate.handleStyleStop(e); + //this.editing = false; + } }, + + handlePropertyChange : { + value: function(e) { + var property = this.propertyField.value, + oldProperty = this.propertyField._preEditValue, + value = this.valueField.value, + rule = this.treeView.parentComponent.declaration.parentRule, + delegate = this.treeView.contentController.delegate; + + delegate.handlePropertyChange(rule, property, value, oldProperty, this); + } + }, + handleValueChange : { + value: function(e) { + var property = this.propertyField.value, + value = this.valueField.value, + rule = this.treeView.parentComponent.declaration.parentRule, + delegate = this.treeView.contentController.delegate; + + delegate.handleValueChange(rule, property, value, this); + } + }, + prepareForDraw : { value: function() { console.log("style's prepare for draw"); @@ -134,11 +218,17 @@ exports.Style = Montage.create(TreeNode, { this.element.addEventListener('drop', this, false); this.element.addEventListener('webkitTransitionEnd', this, false); + ///// Add listeners to the value/property fields + this.propertyField.addEventListener('start', this, false); + this.valueField.addEventListener('start', this, false); + this.propertyField.addEventListener('stop', this, false); + this.valueField.addEventListener('stop', this, false); +// this.propertyField.addEventListener('change', this, false); +// this.valueField.addEventListener('change', this, false); + if(this.sourceObject.isEmpty) { this.element.draggable = false; this.addStyleButton.addEventListener('click', this, false); - this.propertyField.addEventListener('stop', this, false); - this.valueField.addEventListener('stop', this, false); } else { this.element.removeChild(this.addStyleButton); delete this.addStyleButton; @@ -146,6 +236,16 @@ exports.Style = Montage.create(TreeNode, { } }, + willDraw : { + value: function() { + if(this.invalid) { + this._element.title = "Unrecognized Style"; + } else { + this._element.removeAttribute('title'); + } + } + }, + draw : { value : function() { //debugger; @@ -168,11 +268,25 @@ exports.Style = Montage.create(TreeNode, { } if(this._editingNewStyle) { - this.propertyField.start(); + if(!this.propertyField.isEditable) { + this.propertyField.start(); + } this.element.classList.add(this.editNewEmptyClass); } else { this.element.classList.remove(this.editNewEmptyClass); } + + if(this._invalid) { + this._element.classList.add(this.invalidStyleClass); + } else { + this._element.classList.remove(this.invalidStyleClass); + } + + if(this.editing) { + this._element.classList.add(this.editingStyleClass); + } else { + this._element.classList.remove(this.editingStyleClass); + } } } }); \ No newline at end of file diff --git a/js/panels/css-panel/styles-view-container.reel/styles-view-container.html b/js/panels/css-panel/styles-view-container.reel/styles-view-container.html index 56e965c2..10b63087 100644 --- a/js/panels/css-panel/styles-view-container.reel/styles-view-container.html +++ b/js/panels/css-panel/styles-view-container.reel/styles-view-container.html @@ -46,7 +46,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot }, "ruleListContainer": { "module": "js/panels/css-panel/rule-list-container.reel", - "name": "RuleListContainer" + "name": "RuleListContainer", + "properties": { + "focusDelegate": {"@": "stylesViewDelegate"} + } }, "computedStyleView": { "module": "js/panels/CSSPanel/ComputedStyleSubPanel.reel", diff --git a/js/panels/css-panel/styles-view-mediator.js b/js/panels/css-panel/styles-view-mediator.js index 38b61220..c93a5e73 100644 --- a/js/panels/css-panel/styles-view-mediator.js +++ b/js/panels/css-panel/styles-view-mediator.js @@ -5,7 +5,8 @@ */ var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component; + Component = require("montage/ui/component").Component, + Keyboard = require("js/mediators/keyboard-mediator").Keyboard; exports.StylesViewMediator = Montage.create(Component, { stylesController : { @@ -29,10 +30,82 @@ exports.StylesViewMediator = Montage.create(Component, { selector = this.stylesController.generateClassName(this.ruleListContainer.displayedList.selection[0].nodeName); } - newRule = this.application.ninja.stylesController.addRule("."+selector, ' { }'); + newRule = this.application.ninja.stylesController.addRule('.'+selector, ' { }'); this.ruleListContainer.displayedList.component.addRule(newRule); } + }, + handleStyleStop: { + value: function(e) { + console.log("Handle Style Stop"); + //debugger; + if(e._event.detail.type === 'keydown') { + + } + } + }, + handlePropertyChange : { + value: function(rule, property, value, oldProperty, style) { + var browserValue; + + if(style.editingNewStyle) { + return false; + } + + ///// Remove old property and add new one + this.stylesController.deleteStyle(rule, oldProperty); + browserValue = this.stylesController.setStyle(rule, property, value); + + ///// Mark style as invalid if the browser doesn't accept it + style.invalid = (browserValue === null); + + console.log("BrowserValue: ", browserValue, rule); + + this._dispatchChange(property, browserValue); + } + }, + handleValueChange : { + value: function(rule, property, value, style) { + var browserValue, units; + + ///// Auto-fill units if not provided and units + ///// not previously stored + units = style.getUnits(value); + if(style.units && units === null && parseInt(value)) { + value += style.units; + style.valueField.value = value; + } else if (value !== '0') { + style.units = units; + } + + ///// update value + browserValue = this.stylesController.setStyle(rule, property, value); + + ///// Mark style as invalid if the browser doesn't accept it + style.invalid = (browserValue === null); + + console.log("BrowserValue: ", browserValue, rule); + + this._dispatchChange(property, browserValue); + + if(style.editingNewStyle) { + style.treeView.parentComponent.addNewStyle(); + } + } + }, + + _dispatchChange : { + value: function(property, value) { + this.application.ninja.stage.updatedStage = true; + NJevent('elementChange', { + type : 'cssChange', + data: { + "prop": property, + "value": value + }, + redraw: null + }); + } } }); \ No newline at end of file -- cgit v1.2.3