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 --- 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 ++++++++++++++++++++++++++++-- 3 files changed, 159 insertions(+), 11 deletions(-) (limited to 'js/panels/css-panel/style.reel') 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%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9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XhUa3VQ0xoWCqEApiNhEpFzt7Tm%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 -- cgit v1.2.3