From a447eaf48ffbaea89cbb229f06e8b5a7e199f77f Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 2 May 2012 17:00:09 -0700 Subject: CSS Panel - Added element highlight on selector field hover --- .../css-style-rule.reel/css-style-rule.js | 20 +++++++++++++++++--- js/panels/css-panel/styles-view-delegate.js | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'js/panels/css-panel') 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 cfa3e605..7a6a3957 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 @@ -85,7 +85,20 @@ exports.CssStyleRule = Montage.create(Component, { } } }, - + handleMouseover: { + value: function(e) { + if(this.focusDelegate) { + this.focusDelegate.handleSelectorHover(this.selectorField.value, 'over'); + } + } + }, + handleMouseout: { + value: function(e) { + if(this.focusDelegate) { + this.focusDelegate.handleSelectorHover(this.selectorField.value, 'out'); + } + } + }, update: { value: function() { if(this.cssText !== this.rule.cssText) { @@ -107,11 +120,12 @@ exports.CssStyleRule = Montage.create(Component, { this.declarationComponent.type = 'inline'; } else { this.selectorField.addEventListener('change', this, false); + this.selectorField.element.addEventListener('mouseover', this, false); + this.selectorField.element.addEventListener('mouseout', this, false); } - //console.log("css style rule : prepare for draw"); - } }, + willDraw : { value: function() { if(this.applied) { diff --git a/js/panels/css-panel/styles-view-delegate.js b/js/panels/css-panel/styles-view-delegate.js index a76d25ad..7e0987eb 100644 --- a/js/panels/css-panel/styles-view-delegate.js +++ b/js/panels/css-panel/styles-view-delegate.js @@ -9,9 +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" - }, + newClassPrefix : { value: "new-class" }, + elementOutlineClass : { value: "nj-element-highlight" }, + stylesController : { get: function() { return this.application.ninja.stylesController; @@ -21,6 +21,17 @@ exports.StylesViewMediator = Montage.create(Component, { } }, + handleSelectorHover : { + value: function(selector, direction) { + var elements = this.stylesController._activeDocument._document.querySelectorAll(selector), + method = (direction === "out") ? "remove" : "add"; + + Array.prototype.slice.call(elements).forEach(function(el) { + el.classList[method](this.elementOutlineClass); + }, this); + } + }, + handleSelectorChange : { value: function(rule, newSelector, ruleComponent) { if(newSelector === "") { -- cgit v1.2.3