From 4332599afffae987a18bb197fcfdd09bc2e94d2b Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 30 Apr 2012 13:45:52 -0700 Subject: CSS Style Rule - Add code for changing selectors and showing unapplied rules --- .../css-style-rule.reel/css-style-rule.css | 19 ++++++ .../css-style-rule.reel/css-style-rule.html | 13 ++++ .../css-style-rule.reel/css-style-rule.js | 66 ++++++++++++------- js/panels/css-panel/styles-view-mediator.js | 73 ++++++++++++++++++++-- 4 files changed, 143 insertions(+), 28 deletions(-) (limited to 'js') diff --git a/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.css b/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.css index 7cde3fd8..03d43ebf 100644 --- a/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.css +++ b/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.css @@ -4,6 +4,7 @@ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ .css-style-rule-item { + min-height: 69px; position: relative; } .css-style-rule-item:after { @@ -14,7 +15,9 @@ } .style-rule-heading { background-color: #f3f3f3; + /*background-color: #DDDDDD;*/ border: 1px #e7e7e7; + /*border: 1px #CCC;*/ border-style: solid none; box-shadow: inset 0 0 1px #FFF; padding: 4px; @@ -47,4 +50,20 @@ right: -10px; +} + +/* ------------------- + Unapplied Rule +------------------ */ +.unapplied-css-rule { + opacity: .8; + background-color: #f3f3f3; +} +.unapplied-css-rule .style-rule-heading { + background-repeat: no-repeat; + background-position: 6px 6px; + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAALCAYAAABGbhwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0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XDZ36%2Bz5GFgWZr75fjPDhBD4C%2BucjWgaphjQdTgK%2FfPi5a%2FGpPDtjEVjERyqKlag%2FlY8gHPsfzSwPbQgbDyfIs6vURa3EKK8Jf6jmhUy51yiWDlBUDED2NF0JKGQS3IPVn4ATXqIL0EYJgwD42YQG4quE45EggOtCwbWrUM1Ej%2F0jkXDAYaOtOa6iIH2YSQOBugPj4KN3aFdnIThkprynoeUYjtwIRO0hCLxiU3wp12odgl0AXhUa3VQ0xoWCqEApiNhEpFzt7Tm%2F4Tzo9kGvtq4UjNzqJB1mswURvNoqayP57V7KcB7HfZnE8v%2BHYtZtmiGcBzqQ1TSZUPP85HVlo1MfCaX94WPpSO83qwO6wbWCTtBQocoD70eDgZncw3Z%2BC3AAFMzlxlnnpevAAAAAElFTkSuQmCC); +} +.unapplied-css-rule .nj-css-selector { + margin-left: 16px; } \ No newline at end of file diff --git a/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.html b/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.html index 1042d29e..bf101719 100644 --- a/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.html +++ b/js/panels/css-panel/rule-components/css-style-rule.reel/css-style-rule.html @@ -15,6 +15,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "name" : "CssStyleRule", "properties" : { "element" : {"#" : "rule-item"}, + "selectorField": {"@": "selector"}, "declarationComponent": {"@": "declaration"} } }, @@ -52,6 +53,18 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "name": "Declaration", "properties": { "element": {"#": "declaration-list"} + }, + "bindings": { + "focusDelegate" : { + "boundObject": {"@": "owner"}, + "boundObjectPropertyPath": "focusDelegate", + "oneway": true + }, + "declaration" : { + "boundObject": {"@": "owner"}, + "boundObjectPropertyPath": "_declaration", + "oneway": true + } } }, "sheetLink": { 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 d85b5797..ac22878e 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 @@ -8,6 +8,9 @@ var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; exports.CssStyleRule = Montage.create(Component, { + unappliedClass : { + value: 'unapplied-css-rule' + }, cssText: { value: null }, @@ -17,6 +20,21 @@ exports.CssStyleRule = Montage.create(Component, { focusDelegate : { value: null }, + _applied : { + value: true, + distinct: true + }, + applied : { + get: function() { + return this._applied; + }, + set: function(value) { + if(this._applied === value) { return false; } + + this._applied = value; + this.needsDraw = true; + } + }, _rule : { value : null @@ -44,13 +62,7 @@ exports.CssStyleRule = Montage.create(Component, { }, declarationComponent: { value: null - } , -// declarationNodeName: { -// value: "dl" -// }, -// declarationElement: { -// value: null -// }, + }, _declaration: { value: null }, @@ -65,35 +77,45 @@ exports.CssStyleRule = Montage.create(Component, { condition: { value: false }, - templateDidLoad : { - value: function() { - console.log("css style rule : template did load"); - if(this._declaration) { - this.declarationComponent.declaration = this._declaration; - } + handleChange : { + value: function(e) { if(this.focusDelegate) { - this.declarationComponent.focusDelegate = this.focusDelegate; + this.focusDelegate.handleSelectorChange(this.rule, this.selectorField.value, this); } } }, + + templateDidLoad : { + value: function() { + //console.log("css style rule : template did load"); + } + }, prepareForDraw : { value: function() { - console.log("css style rule : prepare for draw"); - - if(!this.declarationElement) { - ///// Create element to contain declaration - this.declarationElement = document.createElement(this.declarationNodeName); - } + this.selectorField.addEventListener('change', this, false); - if(!this._declaration && this._rule) { + //console.log("css style rule : prepare for draw"); + } + }, + willDraw : { + value: function() { + if(this.applied) { + this.element.removeAttribute('title'); + } else { + this.element.title = "Rule does not apply to selection"; } } }, draw : { value: function() { - console.log("css style rule : draw"); + //console.log("css style rule : draw"); + if(this.applied) { + this.element.classList.remove(this.unappliedClass); + } else { + this.element.classList.add(this.unappliedClass); + } } } }); diff --git a/js/panels/css-panel/styles-view-mediator.js b/js/panels/css-panel/styles-view-mediator.js index c93a5e73..8a0e4137 100644 --- a/js/panels/css-panel/styles-view-mediator.js +++ b/js/panels/css-panel/styles-view-mediator.js @@ -9,6 +9,9 @@ var Montage = require("montage/core/core").Montage, Keyboard = require("js/mediators/keyboard-mediator").Keyboard; exports.StylesViewMediator = Montage.create(Component, { + newClassPrefix : { + value: "new-class" + }, stylesController : { get: function() { return this.application.ninja.stylesController; @@ -17,25 +20,72 @@ exports.StylesViewMediator = Montage.create(Component, { return; } }, + + handleSelectorChange : { + value: function(rule, newSelector, ruleComponent) { + rule.selectorText = newSelector; + + ruleComponent.applied = this.ruleListContainer.displayedList.selection.every(function(el) { + return this._doesSelectorTargetElement(newSelector, el); + }, this); + + } + }, + + ///// Add rule button action handleAddAction : { value: function(e) { - var selector, newRule; - - ///// Add rule to the container + var selector, + newRule, + applies = true; ///// Get selection prefix if(this.ruleListContainer.displayedList.selection.length > 1) { selector = this.stylesController.generateClassName(null, true); } else { - selector = this.stylesController.generateClassName(this.ruleListContainer.displayedList.selection[0].nodeName); + selector = this.stylesController.generateClassName(this.newClassPrefix); } + ///// Create the rule with generated selector newRule = this.application.ninja.stylesController.addRule('.'+selector, ' { }'); - this.ruleListContainer.displayedList.component.addRule(newRule); + ///// Add the generated class to each element in selection + ///// and check whether it applies to the element + this.ruleListContainer.displayedList.selection.forEach(function(el) { + this.stylesController.addClass(el, selector); + + if(applies) { + applies = (this._doesSelectorTargetElement('.'+selector, el)); + } + },this); + + ///// Add rule directly to the rule list + this.ruleListContainer.displayedList.component.addRule(newRule).applied = applies; + + } + }, + + _doesSelectorTargetElement : { + value: function doesSelectorTargetElement(selector, element) { + var doc = element.ownerDocument, + matchingEls = Array.prototype.slice.call(doc.querySelectorAll(selector)); + return matchingEls.indexOf(element) !== -1; + } + }, + ///// Enable/Disable Style when checkbox is clicked + handleStyleToggle : { + value: function(rule, enable, style) { + if(enable) { + this.stylesController.setStyle(rule, style.propertyText, style.valueText, style.priority); + } else { + this.stylesController.deleteStyle(rule, style.propertyText); + } + + this._dispatchChange(); } }, + handleStyleStop: { value: function(e) { console.log("Handle Style Stop"); @@ -90,7 +140,18 @@ exports.StylesViewMediator = Montage.create(Component, { this._dispatchChange(property, browserValue); if(style.editingNewStyle) { - style.treeView.parentComponent.addNewStyle(); + style.treeView.parentComponent.addNewStyleAfter(style); + style.editingNewStyle = false; + } + } + }, + + handlePaste : { + value: function(e) { + var text = document.execCommand('insertHTML', null, e._event.clipboardData.getData("Text")).trim(); + + if(text.matches(/([a-zA-Z-]+:[a-zA-Z-]+){,1}/)) { + } } }, -- cgit v1.2.3