From 830b6577ee25a6955bd4e275f216e1cadeff168c Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Thu, 10 May 2012 13:20:19 -0700 Subject: CSS Panel - Rule List refactor Improved adding, updating, and sorting of rules in rule list. --- js/panels/css-panel/styles-view-delegate.js | 109 ++++++++++++++-------------- 1 file changed, 54 insertions(+), 55 deletions(-) (limited to 'js/panels/css-panel/styles-view-delegate.js') diff --git a/js/panels/css-panel/styles-view-delegate.js b/js/panels/css-panel/styles-view-delegate.js index 71b4a8dd..3f29ba27 100644 --- a/js/panels/css-panel/styles-view-delegate.js +++ b/js/panels/css-panel/styles-view-delegate.js @@ -72,61 +72,6 @@ exports.StylesViewMediator = Montage.create(Component, { } }, - - /// Toolbar Button Actions - /// ----------------------- - - ///// Add rule button action - handleAddAction : { - value: function(e) { - 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.newClassPrefix); - } - - ///// Create the rule with generated selector - newRule = this.application.ninja.stylesController.addRule('.'+selector, ' { }'); - - ///// 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; - - } - }, - - ///// Show/hide computed style sub panel - handleComputedAction : { - value: function(e) { - var container = this.ownerComponent, - panelToShow = (container.contentPanel === "computed") ? "rules" : "computed"; - - ///// Handle showing and hiding of the add button - if(panelToShow === "computed") { - container.toolbar.hideButton('add'); - } else { - container.toolbar.showButton('add'); - } - - container.contentPanel = panelToShow; - this.ownerComponent.handleSelectionChange(); - } - }, - ///// Style event handlers //// ------------------------------------- @@ -270,6 +215,60 @@ exports.StylesViewMediator = Montage.create(Component, { } }, + /// Toolbar Button Actions + /// ----------------------- + + ///// Add rule button action + handleAddAction : { + value: function(e) { + 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.newClassPrefix); + } + + ///// Create the rule with generated selector + newRule = this.application.ninja.stylesController.addRule('.'+selector, ' { }'); + + ///// 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; + + } + }, + + ///// Show/hide computed style sub panel + handleComputedAction : { + value: function(e) { + var container = this.ownerComponent, + panelToShow = (container.contentPanel === "computed") ? "rules" : "computed"; + + ///// Handle showing and hiding of the add button + if(panelToShow === "computed") { + container.toolbar.hideButton('add'); + } else { + container.toolbar.showButton('add'); + } + + container.contentPanel = panelToShow; + this.ownerComponent.handleSelectionChange(); + } + }, + ///// Utilities //// ------------------------------------- -- cgit v1.2.3