/* This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
*/ 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 }, hasTemplate: { value: true }, 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 }, rule : { get: function() { return this._rule; }, set: function(rule) { this.cssText = rule.cssText; if(rule.type === 'inline') { this.sheetName = 'Inline Style'; } else { this.sheetName = rule.href || 'Style Tag'; } this.selector = rule.selectorText; this.declaration = rule.style; console.log('Rule with selector "' +rule.selectorText+ '" is set on componenet.'); this._rule = rule; } }, declarationComponent: { value: null }, _declaration: { value: null }, declaration: { get: function() { return this._declaration; }, set: function(dec) { this._declaration = dec; } }, condition: { value: false }, handleChange : { value: function(e) { if(this.focusDelegate) { this.focusDelegate.handleSelectorChange(this.rule, this.selectorField.value, this); } } }, 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) { // TODO: add update for selector and stylesheet name //this.declarationComponent.update(); } } }, templateDidLoad : { value: function() { //console.log("css style rule : template did load"); } }, prepareForDraw : { value: function() { if(this.rule.type === 'inline') { this.selectorField.readOnly = true; 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); } } }, 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"); if(this.applied) { this.element.classList.remove(this.unappliedClass); } else { this.element.classList.add(this.unappliedClass); } } } });