From 40622aa97d31837254996b718b0a6feca2bcd0ce Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 8 Feb 2012 14:41:10 -0800 Subject: Styles Controller - added methods to get keyframe animation rules --- js/controllers/styles-controller.js | 44 +++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 011caec5..ff59c8f8 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -179,10 +179,14 @@ var stylesController = exports.StylesController = Montage.create(Component, { this.styleSheetModified(stylesheet); rule = stylesheet.rules[index]; - + ///// attach specificity to rule object + ///// if rule is css keyframes, return rule and don't attach specificity + if (rule instanceof WebKitCSSKeyframesRule) { + return rule; + } rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); - + ///// return the rule we just inserted return rule; } @@ -840,6 +844,27 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + ///// Get Animation Rule With Name + ///// Returns the CSSKeyframesRule with given name + + getAnimationRuleWithName : { + value: function(name) { + var sheets = this._activeDocument._document.styleSheets, + rules, i, j, rule; + + for(i = 0; i < sheets.length; i++) { + rules = sheets[i].rules; + for(j = 0; j < rules.length; j++) { + rule = rules[j]; + if(rule instanceof WebKitCSSKeyframesRule && rule.name === name) { + return rule; + } + } + } + + return; + } + }, ///// Delete style ///// Removes the property from the style declaration/rule @@ -1045,6 +1070,21 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + ///// Get Element Animation Rule + ///// Returns the CSSKeyframesRule applied to an element + + getElementAnimationRule : { + value: function(element) { + var animationName = this.getElementStyle(element, '-webkit-animation-name'); + + if(!animationName) { + return null; + } + + return this.getAnimationRuleWithName(animationName); + } + }, + ///// Create Rule From Inline Style ///// Creates a rule for an inline style with a specified, or partially random selector. -- cgit v1.2.3 From a30d76ff641ce89686cf5fbd9f04ac9ab4e9c830 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 10 Feb 2012 17:21:28 -0800 Subject: initial color chip for the stage Signed-off-by: Valerio Virgillito --- js/components/ui/color-chip.reel/color-chip.js | 80 +++++++++++++++++++--- js/controllers/elements/stage-controller.js | 5 +- js/data/pi/pi-data.js | 16 ++++- js/io/document/html-document.js | 3 + js/panels/properties/content.reel/content.js | 37 ++++++++++ .../properties/sections/custom.reel/custom.js | 46 +++++++++++-- 6 files changed, 172 insertions(+), 15 deletions(-) (limited to 'js') diff --git a/js/components/ui/color-chip.reel/color-chip.js b/js/components/ui/color-chip.reel/color-chip.js index 5bef7020..4c288084 100644 --- a/js/components/ui/color-chip.reel/color-chip.js +++ b/js/components/ui/color-chip.reel/color-chip.js @@ -9,32 +9,96 @@ var Montage = require("montage/core/core").Montage, var ColorChip = exports.ColorChip = Montage.create(Component, { + chip: { + value: false + }, + hasIcon: { value: true }, + iconType: { + value: null + }, + mode: { value: "stroke" }, - prepareForDraw: { - value: function() { -// this.colorButton.props = {side: 'right', align: 'bottom', wheel: true, palette: true, gradient: true, image: true, offset: 20}; -// this.application.ninja.colorController.addButton('chip', this.colorButton); + offset: { + value: 20 + }, + initialColor: { + value: false + }, + + changeDelegate: { + value: null + }, + prepareForDraw: { + value: function() { this.addEventListener("firstDraw", this, false); } }, draw: { value: function() { + if(this.hasIcon) { + var icon = this.iconType || this.mode + "Icon"; + this.application.ninja.colorController.addButton(icon, this.icon); + } - if(this.hasIcon) this.application.ninja.colorController.addButton(this.mode + 'Icon', this.icon); - -// this.application.ninja.colorController.addButton(this.mode, this.chipBtn); - this.chipBtn.props = {side: 'right', align: 'top', wheel: true, palette: true, gradient: true, image: true, offset: 20}; + this.chipBtn.props = {side: 'right', align: 'top', wheel: true, palette: true, gradient: true, image: true, offset: this.offset}; this.application.ninja.colorController.addButton(this.mode, this.chipBtn); + + /* + if(this.chip) { + //this.application.ninja.colorController.addButton('fillIcon', this.icon); + this.chipBtn.props = {side: 'right', align: 'top', wheel: true, palette: true, gradient: true, image: true, offset: 0}; + this.application.ninja.colorController.addButton(this.mode, this.chipBtn); + } else { + //if(this.hasIcon) this.application.ninja.colorController.addButton(this.mode + 'Icon', this.icon); + this.chipBtn.props = {side: 'right', align: 'top', wheel: true, palette: true, gradient: true, image: true, offset: 20}; + this.application.ninja.colorController.addButton(this.mode, this.chipBtn); + } + */ + + + } + }, + + handleFirstDraw: { + value: function(evt) { + if(this.chip) { + // This is a single chip - Not related to the color panel -- Set the initial color if found + var mode = "rgb", r = 0, g = 0, b = 0, a = 1, css = "rgb(255,0,0)"; + + if(this.initialColor) { + console.log(this.initialColor); + var colorObj = this.application.ninja.colorController.getColorObjFromCss(this.initialColor); + mode = colorObj.mode; + r = colorObj.value.r; + g = colorObj.value.g; + b = colorObj.value.b; + a = colorObj.value.a; + css = colorObj.css; + } + + this.chipBtn.color(mode, {wasSetByCode: true, type: 'change', color: {r: r, g: g, b: b}, css: css}); + //this.chipBtn.color('rgb', {wasSetByCode: true, type: 'change', color: {r: 255, g: 0, b: 0}, css: 'rgb(255,0,0)'}); + + this.chipBtn.addEventListener("change", this, false); + } + } + }, + + handleChange: { + value: function(evt) { + if(this.changeDelegate && typeof(this.changeDelegate === "function")) { + this.changeDelegate(evt); + } } } diff --git a/js/controllers/elements/stage-controller.js b/js/controllers/elements/stage-controller.js index b8170826..e9fc6bce 100644 --- a/js/controllers/elements/stage-controller.js +++ b/js/controllers/elements/stage-controller.js @@ -75,6 +75,8 @@ exports.StageController = Montage.create(ElementController, { getProperty: { value: function(el, p) { switch(p) { + case "background" : + return el.elementModel.stageBackground.style.getProperty(p); case "border": return el.elementModel.stageView.style.getProperty(p); case "height": @@ -92,7 +94,8 @@ exports.StageController = Montage.create(ElementController, { value: function(el, p, value) { switch(p) { case "background": - el.elementModel.body.style.setProperty(p, value); + console.log(value); + el.elementModel.stageBackground.style.setProperty(p, value); break; case "overflow": el.elementModel.viewPort.style.setProperty(p, value); diff --git a/js/data/pi/pi-data.js b/js/data/pi/pi-data.js index 10b33a0e..a6811a20 100644 --- a/js/data/pi/pi-data.js +++ b/js/data/pi/pi-data.js @@ -10,7 +10,21 @@ var Montage = require("montage/core/core").Montage, exports.PiData = Montage.create( Montage, { stagePi: { - value: [] + value: [ + { + label: "Style", + + Section: [ + [ + { + type : "chip", + id : "background", + prop: "background" + } + ] + ] + } + ] }, blockPi: { diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index c44dfe75..dd3507c2 100644 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -398,6 +398,9 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base this.documentRoot.elementModel.stageView = this.documentRoot.elementModel.defaultRule.cssRules[j]; + } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "#stageBG") { + + this.documentRoot.elementModel.stageBackground = this.documentRoot.elementModel.defaultRule.cssRules[j]; } } diff --git a/js/panels/properties/content.reel/content.js b/js/panels/properties/content.reel/content.js index 0088447a..b15f2d71 100644 --- a/js/panels/properties/content.reel/content.js +++ b/js/panels/properties/content.reel/content.js @@ -150,6 +150,43 @@ exports.Content = Montage.create(Component, { this.customPi = stage.elementModel.pi; this.displayCustomProperties(stage, stage.elementModel.pi); } + + // For now hardcode the background since it is the only custom property + // No need to loop through all the properties. + var backgroundChip = this.customSections[0].content.controls["background"]; + backgroundChip.initialColor = ElementsMediator.getProperty(stage, "background"); + + // Get stage color + //var backgroundColor = + //console.log(backgroundColor); + + /* + var customPI = PiData[this.customPi]; + // Get all the custom section for the custom PI + for(var i = 0, customSec; customSec = customPI[i]; i++) { + + // Now set the Fields for the custom PI + for(var j = 0, fields; fields = customSec.Section[j]; j++) { + for(var k = 0, control; control = fields[k]; k++) { + + var colorChipEl = this.customSections[i].content.controls[control.id]; + this.foo = colorChipEl; + colorChipEl.addEventListener("firstDraw", this, false); + + } + } + } + */ + } + }, + + foo: { + value: null + }, + + handleFirstDraw: { + value: function() { + this.foo.chipBtn.color('rgb', {wasSetByCode: true, type: 'change', color: {r: 255, g: 0, b: 0}, css: 'rgb(255,0,0)'}); } }, diff --git a/js/panels/properties/sections/custom.reel/custom.js b/js/panels/properties/sections/custom.reel/custom.js index 992db8e6..5315defc 100644 --- a/js/panels/properties/sections/custom.reel/custom.js +++ b/js/panels/properties/sections/custom.reel/custom.js @@ -6,6 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage; var Component = require("montage/ui/component").Component; +var ElementsMediator = require("js/mediators/element-mediator").ElementMediator; //Custom Rows var SingleRow = require("js/panels/properties/sections/custom-rows/single-row.reel").SingleRow; @@ -18,7 +19,7 @@ var Dropdown = require("js/components/combobox.reel").Combobox; var TextField = require("js/components/textfield.reel").TextField; var FileInput = require("js/components/ui/file-input.reel").FileInput; var Checkbox = require("js/components/checkbox.reel").Checkbox; - +var ColorChip = require("js/components/ui/color-chip.reel").ColorChip; exports.CustomSection = Montage.create(Component, { @@ -88,10 +89,8 @@ exports.CustomSection = Montage.create(Component, { value:{} }, - handleChanging: - { - value:function(event) - { + handleChanging: { + value:function(event) { var obj = event.currentTarget; this._dispatchPropEvent({"type": "changing", "id": obj.id, "prop": obj.prop, "value": obj.value, "control": obj}); } @@ -106,6 +105,26 @@ exports.CustomSection = Montage.create(Component, { } }, + handleColorChange: { + value: function(event) { + // Change the stage color for now + console.log(this); + console.log(event); + console.log(event._event.color.css); + ElementsMediator.setProperty([this.application.ninja.currentDocument.documentRoot], "background", [event._event.color.css], "Change", "pi", 'foo'); + /* + var propEvent = document.createEvent("CustomEvent"); + propEvent.initEvent("propertyChange", true, true); + propEvent.type = "propertyChange"; + + propEvent.prop = "background";//event.prop; + propEvent.value = event._event.color.css; + + this.dispatchEvent(propEvent); + */ + } + }, + _dispatchPropEvent: { value: function(event) { // console.log(event); @@ -140,6 +159,7 @@ exports.CustomSection = Montage.create(Component, { case "textbox" : return this.createTextField(fields); case "file" : return this.createFileInput(fields); case "checkbox" : return this.createCheckbox(fields); + case "chip" : return this.createColorChip(fields); } } }, @@ -303,6 +323,22 @@ exports.CustomSection = Montage.create(Component, { boundObjectPropertyPath: "checked" }); + return obj; + } + }, + + createColorChip: { + value: function(aField) { + var obj = ColorChip.create(); + obj.chip = true; + obj.iconType = "fillIcon"; + obj.mode = "chip"; + obj.offset = 0; + + obj.changeDelegate = this.handleColorChange; + + this.controls[aField.id] = obj; + return obj; } } -- cgit v1.2.3 From 0d7d6d4d98437a93f31ededa14ca6eb5382c9e58 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Mon, 13 Feb 2012 14:05:10 -0800 Subject: Cleaning up the stage background color chip. Signed-off-by: Valerio Virgillito --- js/components/ui/color-chip.reel/color-chip.js | 16 ---------------- js/controllers/elements/stage-controller.js | 1 - js/panels/properties/content.reel/content.js | 8 -------- js/panels/properties/sections/custom.reel/custom.js | 13 +++++++++---- 4 files changed, 9 insertions(+), 29 deletions(-) (limited to 'js') diff --git a/js/components/ui/color-chip.reel/color-chip.js b/js/components/ui/color-chip.reel/color-chip.js index 4c288084..e51bdd8a 100644 --- a/js/components/ui/color-chip.reel/color-chip.js +++ b/js/components/ui/color-chip.reel/color-chip.js @@ -53,19 +53,6 @@ var ColorChip = exports.ColorChip = Montage.create(Component, { this.chipBtn.props = {side: 'right', align: 'top', wheel: true, palette: true, gradient: true, image: true, offset: this.offset}; this.application.ninja.colorController.addButton(this.mode, this.chipBtn); - /* - if(this.chip) { - //this.application.ninja.colorController.addButton('fillIcon', this.icon); - this.chipBtn.props = {side: 'right', align: 'top', wheel: true, palette: true, gradient: true, image: true, offset: 0}; - this.application.ninja.colorController.addButton(this.mode, this.chipBtn); - } else { - //if(this.hasIcon) this.application.ninja.colorController.addButton(this.mode + 'Icon', this.icon); - this.chipBtn.props = {side: 'right', align: 'top', wheel: true, palette: true, gradient: true, image: true, offset: 20}; - this.application.ninja.colorController.addButton(this.mode, this.chipBtn); - } - */ - - } }, @@ -76,7 +63,6 @@ var ColorChip = exports.ColorChip = Montage.create(Component, { var mode = "rgb", r = 0, g = 0, b = 0, a = 1, css = "rgb(255,0,0)"; if(this.initialColor) { - console.log(this.initialColor); var colorObj = this.application.ninja.colorController.getColorObjFromCss(this.initialColor); mode = colorObj.mode; r = colorObj.value.r; @@ -87,8 +73,6 @@ var ColorChip = exports.ColorChip = Montage.create(Component, { } this.chipBtn.color(mode, {wasSetByCode: true, type: 'change', color: {r: r, g: g, b: b}, css: css}); - //this.chipBtn.color('rgb', {wasSetByCode: true, type: 'change', color: {r: 255, g: 0, b: 0}, css: 'rgb(255,0,0)'}); - this.chipBtn.addEventListener("change", this, false); } } diff --git a/js/controllers/elements/stage-controller.js b/js/controllers/elements/stage-controller.js index e9fc6bce..af7c4858 100644 --- a/js/controllers/elements/stage-controller.js +++ b/js/controllers/elements/stage-controller.js @@ -94,7 +94,6 @@ exports.StageController = Montage.create(ElementController, { value: function(el, p, value) { switch(p) { case "background": - console.log(value); el.elementModel.stageBackground.style.setProperty(p, value); break; case "overflow": diff --git a/js/panels/properties/content.reel/content.js b/js/panels/properties/content.reel/content.js index b15f2d71..1ec6d769 100644 --- a/js/panels/properties/content.reel/content.js +++ b/js/panels/properties/content.reel/content.js @@ -156,10 +156,6 @@ exports.Content = Montage.create(Component, { var backgroundChip = this.customSections[0].content.controls["background"]; backgroundChip.initialColor = ElementsMediator.getProperty(stage, "background"); - // Get stage color - //var backgroundColor = - //console.log(backgroundColor); - /* var customPI = PiData[this.customPi]; // Get all the custom section for the custom PI @@ -180,10 +176,6 @@ exports.Content = Montage.create(Component, { } }, - foo: { - value: null - }, - handleFirstDraw: { value: function() { this.foo.chipBtn.color('rgb', {wasSetByCode: true, type: 'change', color: {r: 255, g: 0, b: 0}, css: 'rgb(255,0,0)'}); diff --git a/js/panels/properties/sections/custom.reel/custom.js b/js/panels/properties/sections/custom.reel/custom.js index 5315defc..a2b9b9fa 100644 --- a/js/panels/properties/sections/custom.reel/custom.js +++ b/js/panels/properties/sections/custom.reel/custom.js @@ -105,13 +105,14 @@ exports.CustomSection = Montage.create(Component, { } }, + /** + * Color change handler. Hard coding the stage for now since only the stage PI uses this color chip + */ handleColorChange: { value: function(event) { // Change the stage color for now - console.log(this); - console.log(event); - console.log(event._event.color.css); - ElementsMediator.setProperty([this.application.ninja.currentDocument.documentRoot], "background", [event._event.color.css], "Change", "pi", 'foo'); + //console.log(this, event); + ElementsMediator.setProperty([this.application.ninja.currentDocument.documentRoot], this.id, [event._event.color.css], "Change", "pi", ''); /* var propEvent = document.createEvent("CustomEvent"); propEvent.initEvent("propertyChange", true, true); @@ -330,11 +331,15 @@ exports.CustomSection = Montage.create(Component, { createColorChip: { value: function(aField) { var obj = ColorChip.create(); + obj.chip = true; obj.iconType = "fillIcon"; obj.mode = "chip"; obj.offset = 0; + if (aField.id) obj.id = aField.id; + if (aField.prop) obj.prop = aField.prop; + obj.changeDelegate = this.handleColorChange; this.controls[aField.id] = obj; -- cgit v1.2.3 From a738121a921e4c721b280434952b415b9ab3b1a8 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 13 Feb 2012 15:18:55 -0800 Subject: Styles Controller - Separate css animation rule getters To add document- and sheet-specific getters. --- js/controllers/styles-controller.js | 58 +++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index ff59c8f8..44ca50e1 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -128,7 +128,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { } else { this._defaultStylesheet = sheets[lastIndex]; } - + } } }, @@ -848,17 +848,15 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Returns the CSSKeyframesRule with given name getAnimationRuleWithName : { - value: function(name) { - var sheets = this._activeDocument._document.styleSheets, - rules, i, j, rule; - - for(i = 0; i < sheets.length; i++) { - rules = sheets[i].rules; - for(j = 0; j < rules.length; j++) { - rule = rules[j]; - if(rule instanceof WebKitCSSKeyframesRule && rule.name === name) { - return rule; - } + value: function(name, document) { + var doc = document || this._activeDocument._document, + animRules = this.getDocumentAnimationRules(doc), + rule, i; + + for(i = 0; i < animRules.length; i++) { + rule = animRules[i]; + if(rule.name === name) { + return rule; } } @@ -866,6 +864,42 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + ///// Get Document Animation Rules + ///// Returns all CSSKeyframesRules in active document, or in + ///// optionally passed-in document + ///// If none are found, returns an empty array + + getDocumentAnimationRules : { + value: function(document) { + var sheets = (document) ? document.styleSheets : this._activeDocument._document.styleSheets, + rules = []; + + nj.toArray(sheets).forEach(function(sheet) { + rules = rules.concat(this.getStyleSheetAnimationRules(sheet)); + }, this); + + return rules; + } + }, + + ///// Get Style Sheet Animation Rules + ///// Returns all CSSKeyframesRules from the given stylesheet + ///// If none are found, returns an empty array + + getStyleSheetAnimationRules : { + value: function(sheet) { + var rules = []; + + if(sheet.rules) { + rules = rules.concat(nj.toArray(sheet.rules).filter(function(rule) { + return rule instanceof WebKitCSSKeyframesRule; + })); + } + + return rules; + } + }, + ///// Delete style ///// Removes the property from the style declaration/rule ///// Returns the rule -- cgit v1.2.3