From 8802043dc2acab5f669a68c02464a6b7792af1bb Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 1 Feb 2012 16:50:59 -0800 Subject: Styles Controller - First stab at group styling Split "createOverrideRule" into two methods --> now has createOverrideSelector. Also took first stab at creating a group style. --- js/controllers/styles-controller.js | 102 ++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 16 deletions(-) (limited to 'js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index afd298c9..8fc90e7d 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -171,7 +171,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { if(argType === 'string') { ruleText += '{' + declaration + '}'; } else if(argType === 'object') { - ruleText += '{' + nj.cssFromObject(declaration) + '}'; + ruleText += '{' + this.cssFromObject(declaration) + '}'; } stylesheet.insertRule(ruleText, index); @@ -199,25 +199,42 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Locally-scoped function to de-clutter variable declarations function getSelector(el, rule) { - return this._getMostSpecificSelectorForElement(el, rule[this.CONST.SPECIFICITY_KEY]).selector; } var selectorToOverride = getSelector.bind(this)(element, ruleToOverride), - tokens = selectorToOverride.split(/\s/), - newClass = this.generateClassName(element.nodeName), - lastToken, pseudoSplit, base, pseudo, newToken, newSelector, rule; + overrideData, rule; + + ///// Get the overriding selector and className + overrideData = this.createOverrideSelector(selectorToOverride, element.nodeName); + + ///// Create new rule with selector and insert it after the rule we're overriding + rule = this.addRule(overrideData.selector + ' { }', this.getRuleIndex(ruleToOverride)+1); + + return { + className : overrideData.className, + rule : rule + }; + + } + }, + + createOverrideSelector : { + value: function(selectorToOverride, classPrefix, className) { + var tokens = selectorToOverride.split(/\s/), + newClass = className || this.generateClassName(classPrefix, true), + lastToken, pseudoSplit, base, pseudo, newToken, newSelector; ///// Creating an overriding selector by replacing the last ///// class, attribute or type selector in passed-in rule's selector - + ///// Grab the last token lastToken = tokens[tokens.length-1]; pseudoSplit = lastToken.split(':'); ///// The last token can have pseudo class. Let's preserve it base = pseudoSplit[0]; pseudo = (pseudoSplit[1]) ? ':'+pseudoSplit[1] : ''; - + ///// Now, all we want to do is replace the last token with a ///// generated class name, except if the last token is an ID selector, ///// in which case we append the generated class name to the ID selector @@ -231,18 +248,15 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Append the generated class newToken += '.' + newClass + pseudo; } - + ///// Now we can build the new selector by replacing the last token tokens[tokens.length-1] = newToken; newSelector = tokens.join(' '); - - rule = this.addRule(newSelector + ' { }', this.getRuleIndex(ruleToOverride)+1); - + return { className : newClass, - rule : rule + selector : newSelector }; - } }, @@ -370,7 +384,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// from which an overriding rule can be created. getDominantRuleForGroup : { - value : function(elements, property) { + value : function(elements, property, forceOverride) { var selectorsToOverride = [], commonRules, dominantRules, useImportant; @@ -639,7 +653,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { }, ///// Get Most Specific Selector For Element - ///// Given a selector+specificty array, find the most specific + ///// Given a selector+specificity array, find the most specific ///// selector for the passed-in element _getMostSpecificSelectorForElement : { @@ -721,7 +735,11 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Calculate specificity ///// Returns the specificity value of passed-in selector ///// WARNING: Do not pass in grouped selectors! - ///// Helpful for determining precedence of style rules + ///// Helpful for determining precedence of style rules + ///// Calculation javascript code courtesy of David Owens: + ///// http://gbradley.com/2009/10/02/css-specificity-in-javascript + ///// Used with author's permission + calculateSpecificity : { value : function(selector) { var s = selector.replace(/\([^\)]+\)/,''), @@ -922,6 +940,43 @@ var stylesController = exports.StylesController = Montage.create(Component, { } } }, + + setGroupStyles : { + value : function(elements, styles) { + var properties = Object.keys(styles), + newClass = this.generateClassName(null, true), + selectors; + + ///// TODO: move this: Locally-scoped function to de-clutter variable declarations + function getSelector(el, rule) { + return this._getMostSpecificSelectorForElement(el, rule[this.CONST.SPECIFICITY_KEY]).selector; + } + + selectors = elements.map(function(el) { + ///// for each element, we want to find the most specific selector + var matchingRules = this.getMatchingRules(el, true); + + this.addClass(el, newClass); + + if(matchingRules.length === 0) { + return null; + } + + var mostSpecificRule = matchingRules[0], // TODO: iterate over properties to find most specific + selectorToOverride = getSelector.bind(this)(el, mostSpecificRule), + override = this.createOverrideSelector(selectorToOverride, null, newClass); + + return override.selector; + + }, this); + + selectors.filter(function(item) { + return item !== null; + }); + + this.addRule(selectors.join(', '), styles); + } + }, ///// Get Element Style ///// Gets the style value that is currently applied to the element @@ -1058,6 +1113,21 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + ///// CSS From Object + ///// Returns css text from object with key/value pairs + ///// representing css styles + + cssFromObject : { + value : function(obj) { + var cssText = ''; + ///// For each key/value pair, create css text + for(var prop in obj) { + cssText += prop + ':' + obj[prop] + ';'; + } + return cssText; + } + }, + /* ----------------- Element model (rule cache) related methods ----------------- */ ///// Get Cached Rule For Property -- cgit v1.2.3 From 82579a7aa6fc75e4a8cebde6628fc43275740079 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 6 Feb 2012 16:55:34 -0800 Subject: Styles Controller - Add code to remove cache items from history (not just nullifying them) --- js/controllers/styles-controller.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 8fc90e7d..6ba24aa6 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -736,7 +736,6 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Returns the specificity value of passed-in selector ///// WARNING: Do not pass in grouped selectors! ///// Helpful for determining precedence of style rules - ///// Calculation javascript code courtesy of David Owens: ///// http://gbradley.com/2009/10/02/css-specificity-in-javascript ///// Used with author's permission @@ -1177,15 +1176,24 @@ var stylesController = exports.StylesController = Montage.create(Component, { _clearCache: { value: function(element) { - var itemsToClear = this._cacheHistory; + var itemsToNullify = this._cacheHistory, + itemsToRemove = [], + i; + + ///// If clearing the cache for an element, filter by element + ///// and keep track of indices to remove from cache if(element) { - itemsToClear = itemsToClear.filter(function(item) { - return item.element === element; + itemsToNullify = itemsToNullify.filter(function(item, index) { + if(item.element === element) { + itemsToRemove.push(index); + return true; + } + return false; }); } - itemsToClear.forEach(function(item) { + itemsToNullify.forEach(function(item) { //var identifier = item.element.nodeName; //identifier += '#'+item.element.id || '.'+item.element.className; //console.log("clearing cache for \"" + item.property +"\" and element \"" + identifier+ ""); @@ -1194,6 +1202,17 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }); + ///// Remove the nullified items from the cache + ///// Start at the end to not mess up index references + for(i = itemsToRemove.length-1; i >= 0; i--) { + this._cacheHistory.splice(itemsToRemove[i], 1); + } + + if(!element) { + this._cacheHistory = null; + this._cacheHistory = []; + } + } }, _removeCachedRuleForProperty : { -- cgit v1.2.3 From 34bb4763344f14c8055bc45ea01e5307c424c1c0 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 6 Feb 2012 16:56:57 -0800 Subject: Styles Controller - Correct author attribution for specificity calculation --- js/controllers/styles-controller.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 6ba24aa6..1dd91c8d 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -736,6 +736,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Returns the specificity value of passed-in selector ///// WARNING: Do not pass in grouped selectors! ///// Helpful for determining precedence of style rules + ///// Calculation javascript code courtesy of Graham Bradley: ///// http://gbradley.com/2009/10/02/css-specificity-in-javascript ///// Used with author's permission -- cgit v1.2.3 From c8c78a82aa4ec8ad8b53c6240f3b144ca113cf05 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 6 Feb 2012 16:57:33 -0800 Subject: Styles Controller - Add some methods for modifying css keyframe rules --- js/controllers/styles-controller.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 1dd91c8d..21024125 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -804,7 +804,34 @@ var stylesController = exports.StylesController = Montage.create(Component, { return browserValues; } }, - + + ///// Set Keyframe Style + ///// For a given CSSKeyframesRule, we may add a style to the keyframe at + ///// given index. + + setKeyframeStyle : { + value : function(rule, keyframeIndex, property, value, useImportant) { + return this.setStyle(rule.cssRules[keyframeIndex], property, value, useImportant); + } + }, + + ///// Set Keyframe Styles + ///// For a given CSSKeyframesRule, we may add styles to the keyframe at + ///// given index. + + setKeyframeStyle : { + value : function(rule, keyframeIndex, property, value, useImportant) { + return this.setStyles(rule.cssRules[keyframeIndex], property, value, useImportant); + } + }, + + insertKeyframe : { + value : function() { + + } + }, + + ///// Delete style ///// Removes the property from the style declaration/rule ///// Returns the rule -- cgit v1.2.3 From 18f687974273b5ed7374ca5ae440c797064c5d0f Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Tue, 7 Feb 2012 13:35:27 -0800 Subject: Presets Panel - Initial commit with panel content --- .../PanelContainer.reel/PanelContainer.js | 4 +- js/panels/presets/content.reel/content.css | 55 ++++++++++ js/panels/presets/content.reel/content.html | 66 ++++++++++++ js/panels/presets/content.reel/content.js | 106 ++++++++++++++++++ js/panels/presets/presets-panel.js | 15 +++ .../presets/style-presets.reel/style-presets.css | 0 .../presets/style-presets.reel/style-presets.html | 58 ++++++++++ .../presets/style-presets.reel/style-presets.js | 119 +++++++++++++++++++++ .../transitions-presets.css | 0 .../transitions-presets.html | 58 ++++++++++ .../transitions-presets.js | 67 ++++++++++++ 11 files changed, 547 insertions(+), 1 deletion(-) create mode 100644 js/panels/presets/content.reel/content.css create mode 100644 js/panels/presets/content.reel/content.html create mode 100644 js/panels/presets/content.reel/content.js create mode 100644 js/panels/presets/presets-panel.js create mode 100644 js/panels/presets/style-presets.reel/style-presets.css create mode 100644 js/panels/presets/style-presets.reel/style-presets.html create mode 100644 js/panels/presets/style-presets.reel/style-presets.js create mode 100644 js/panels/presets/transitions-presets.reel/transitions-presets.css create mode 100644 js/panels/presets/transitions-presets.reel/transitions-presets.html create mode 100644 js/panels/presets/transitions-presets.reel/transitions-presets.js (limited to 'js') diff --git a/js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js b/js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js index 66333cc0..0569cc51 100644 --- a/js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js +++ b/js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js @@ -15,6 +15,7 @@ var CSSPanel = require("js/panels/CSSPanel/CSSPanel").CSSPanel; var ComponentsPanel = require("js/panels/Components/ComponentsPanel").ComponentsPanel; var ProjectPanel = require("js/panels/Project/ProjectPanel").ProjectPanel; var MaterialsPanel = require("js/panels/Materials/MaterialsPanel").MaterialsPanel; +var PresetsPanel = require("js/panels/presets/presets-panel").PresetsPanel; exports.PanelContainer = Montage.create(Component, { lastOffset: { @@ -44,7 +45,7 @@ exports.PanelContainer = Montage.create(Component, { }, initPanelOrder: { - value: ['PropertiesPanel','ColorPanel','ComponentsPanel','ProjectPanel','CSSPanel','MaterialsPanel'] + value: ['PresetsPanel','PropertiesPanel','ColorPanel','ComponentsPanel','ProjectPanel','CSSPanel','MaterialsPanel'] }, panelOrder: { @@ -93,6 +94,7 @@ exports.PanelContainer = Montage.create(Component, { // this.needsDraw = true; + this.addEventListener("change@appModel.PresetsPanel", this, false); this.addEventListener("change@appModel.PropertiesPanel", this, false); this.addEventListener("change@appModel.ProjectPanel", this, false); this.addEventListener("change@appModel.ColorPanel", this, false); diff --git a/js/panels/presets/content.reel/content.css b/js/panels/presets/content.reel/content.css new file mode 100644 index 00000000..a6a1545f --- /dev/null +++ b/js/panels/presets/content.reel/content.css @@ -0,0 +1,55 @@ +.presetsPanel { + display: -webkit-box; + text-shadow: 1px 1px 0 #000; + -webkit-box-orient: vertical; + -webkit-box-flex: 1; +} +.presetsPanel .treeRoot { + margin: 0 8px; +} +.tab-bar { + -webkit-box-flex: 0; + background-color: #282828; + color: #FFF; + display: -webkit-box; + font-size: 12px; + -webkit-box-orient: horizontal; +} + +.tab-bar div { + -webkit-box-flex: 0; + border-top-right-radius: 2px; + border-top-left-radius: 2px; + background-color: #474747; + background-image: -webkit-linear-gradient(bottom, rgba(0,0,0,0.2) 0,rgba(0,0,0,0) 3px); + border-top: 1px solid rgb(100, 100, 100); + border-left: 1px solid rgba(100, 100, 100, 0.3); + border-right: 1px solid rgba(100, 100, 100, 0.3); + padding: 4px 9px; + cursor: pointer; + opacity: 0.6; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + position: relative; + z-index: 999; +} +.tab-bar div.active-tab { + background-image: none; + box-shadow: 0 -5px 2px 3px rgba(0,0,0,0.2); + position: relative; + opacity: 1; + text-overflow: clip; + z-index: 1001; +} + +.librarySlot { + -webkit-box-flex: 1; + overflow: auto; + background-color: #474747; + + color: #FFF; + + position: relative; + z-index: 1000; +} \ No newline at end of file diff --git a/js/panels/presets/content.reel/content.html b/js/panels/presets/content.reel/content.html new file mode 100644 index 00000000..38de2a6d --- /dev/null +++ b/js/panels/presets/content.reel/content.html @@ -0,0 +1,66 @@ + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/js/panels/presets/content.reel/content.js b/js/panels/presets/content.reel/content.js new file mode 100644 index 00000000..8ddb3757 --- /dev/null +++ b/js/panels/presets/content.reel/content.js @@ -0,0 +1,106 @@ +/* +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.content = Montage.create(Component, { + hasTemplate: { + value: true + }, + contentPanel : { + value: "presets" // get from local storage + }, + templateDidLoad : { + value: function() { + console.log('deserialized'); + } + }, + prepareForDraw : { + value: function() { + this.activeTab = this.tabs[this.activeTabIndex]; + + this.tabBar.addEventListener('click', this, false); + } + }, + handleClick : { + value: function(e) { + var tabObject = this.tabs.filter(function(item) { + return item.tab === e._event.target; + }); + + if(tabObject[0]) { + this.activeTab = tabObject[0]; + } + + } + }, + _activeTab : { + value: null, + enumerable: false + }, + activeTab : { + get: function() { + return this._activeTab; + }, + set: function(tabObject) { + this.contentPanel = tabObject.key; + + if(this.activeTab) { + this._activeTab.tab.classList.remove('active-tab'); + } + + tabObject.tab.classList.add('active-tab'); + this._activeTab = tabObject; + } + }, + treeList : { + value : null + }, + data2: { + value: { + "meta": "Blah", + "status": "OK", + "text" : "Root", + "data" : { + "date": "1.1.01", + "text": "Root", + "children": [{ + "date": "3.3.01", + "text": "Child 1" + }, + { + "date": "3.3.01", + "text": "Child 2", + "children": [{ + "date": "3.4.01", + "text": "Grand Child 1", + "children": [{ + "date": "4.4.01", + "text": "Great Grand Child 1" + }] + }] + + },{ + "date": "5.5.01", + "text": "Child 3" + }] + } + } + }, + + didDraw: { + value : function() { + console.log('Presets Panel prepare for draw.'); +// this.treeList.items.push({ +// label : "Box Style", +// type : 'leaf' +// }); + } + } + + +}); diff --git a/js/panels/presets/presets-panel.js b/js/panels/presets/presets-panel.js new file mode 100644 index 00000000..091c5cb9 --- /dev/null +++ b/js/panels/presets/presets-panel.js @@ -0,0 +1,15 @@ +/* +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; +var PanelBase = require("js/panels/PanelBase").PanelBase; +var Content = require("js/panels/presets/content.reel").content; + +exports.PresetsPanel = Montage.create(PanelBase, { + panelName : { value: "Presets" }, + minHeight : { value: 200 }, + content : { value: Content } +}); \ No newline at end of file diff --git a/js/panels/presets/style-presets.reel/style-presets.css b/js/panels/presets/style-presets.reel/style-presets.css new file mode 100644 index 00000000..e69de29b diff --git a/js/panels/presets/style-presets.reel/style-presets.html b/js/panels/presets/style-presets.reel/style-presets.html new file mode 100644 index 00000000..5bc83ffa --- /dev/null +++ b/js/panels/presets/style-presets.reel/style-presets.html @@ -0,0 +1,58 @@ + + + + + + + + + +
+
+
+ + \ No newline at end of file diff --git a/js/panels/presets/style-presets.reel/style-presets.js b/js/panels/presets/style-presets.reel/style-presets.js new file mode 100644 index 00000000..3a71c344 --- /dev/null +++ b/js/panels/presets/style-presets.reel/style-presets.js @@ -0,0 +1,119 @@ +/* + 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.StylesLibrary = Montage.create(Component, { + hasTemplate: { + value: true + }, + contentPanel : { + value: "presets" // get from local storage + }, + templateDidLoad : { + value: function() { + console.log('deserialized'); + } + }, + treeList : { + value : null + }, + data2: { + value: { + "text": "styles", + "children": [{ + "text": "Box Styles", + "children": [ + { + "text": "Border-Radius", + "classNameBase" : "border-radius", + "styles" : { + "border-radius": "100px", + "border" : "1px solid #333" + } + }, + { + "text": "Drop Shadow", + "classNameBase" : "drop-shadow", + "styles" : { + "box-shadow": "2px 2px 50px rgba(0,0,0,0.5)", + "border" : "1px solid #CCC" + } + }, + { + "text": "Fancy Box", + "classNameBase" : "fancy-box", + "styles" : { + "box-shadow": "inset 0 0 0 1px #666, inset 0 0 0 2px rgba(225, 225, 225, 0.4), 0 0 20px -10px #333", + "border" : "1px solid #FFF", + "border-radius": "30px", + "background-color": "#7db9e8", + "background-image": "-webkit-linear-gradient(top, rgba(255,255,255,0.74) 0%,rgba(255,255,255,0) 100%)" + } + }] + }, { + "text": "Text Styles", + "children": [ + { "text": "Italic" }, + { "text": "Text Shadow" }, + { "text": "Text Color" } ] + }, { + "text": "Color Styles", + "children": [ + { "text": "Background Gradient" }, + { "text": "Background Color" }, + { "text": "Text Highlight" } ] + }] + } + }, + didDraw: { + value : function() { + console.log('Presets Panel prepare for draw.'); +// this.treeList.items.push({ +// label : "Box Style", +// type : 'leaf' +// }); + } + }, + applyPresetSelection : { + value: function(presetData) { + var selection = this.application.ninja.selectedElements, + self = this; + + function setStopRuleSelector(selector) { + self.application.ninja + .currentDocument.documentRoot + .elementModel.controller + .changeSelector(self.application.ninja.currentDocument.documentRoot, null, selector); + } + + selection.forEach(function(el) { + el._element.style.webkitTransition = "all 450ms linear"; + + el._element.addEventListener("webkitTransitionEnd", function(e) { + console.log("calling transition end"); + setStopRuleSelector("*"); + }); + + setStopRuleSelector("transitionStopRule"); + + this.application.ninja.stylesController.setElementStyles(el._element, presetData.styles); + }, this); + + } + }, + shouldChangeSelection : { + value : function(controller, newSelection, oldSelection) { + // + //debugger; + console.log('1Handle should change selection'); + return false; + } + } + + +}); diff --git a/js/panels/presets/transitions-presets.reel/transitions-presets.css b/js/panels/presets/transitions-presets.reel/transitions-presets.css new file mode 100644 index 00000000..e69de29b diff --git a/js/panels/presets/transitions-presets.reel/transitions-presets.html b/js/panels/presets/transitions-presets.reel/transitions-presets.html new file mode 100644 index 00000000..e3bf0aba --- /dev/null +++ b/js/panels/presets/transitions-presets.reel/transitions-presets.html @@ -0,0 +1,58 @@ + + + + + + + + + +
+
+
+ + \ No newline at end of file diff --git a/js/panels/presets/transitions-presets.reel/transitions-presets.js b/js/panels/presets/transitions-presets.reel/transitions-presets.js new file mode 100644 index 00000000..bc91b3ad --- /dev/null +++ b/js/panels/presets/transitions-presets.reel/transitions-presets.js @@ -0,0 +1,67 @@ +/* + 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.TransitionsLibrary = Montage.create(Component, { + hasTemplate: { + value: true + }, + contentPanel : { + value: "presets" // get from local storage + }, + templateDidLoad : { + value: function() { + console.log('deserialized'); + } + }, + treeList : { + value : null + }, + data2: { + value: { + "meta": "Blah", + "status": "OK", + "text" : "Root", + "data" : { + "date": "1.1.01", + "text": "Transitions", + "children": [{ + "date": "3.3.01", + "text": "Kid 1" + }, + { + "date": "3.3.01", + "text": "Kid 2", + "children": [{ + "date": "3.4.01", + "text": "Grand Kid 1", + "children": [{ + "date": "4.4.01", + "text": "Great Grand Kid 1" + }] + }] + + },{ + "date": "5.5.01", + "text": "Kid 3" + }] + } + } + }, + didDraw: { + value : function() { + console.log('Presets Panel prepare for draw.'); +// this.treeList.items.push({ +// label : "Box Style", +// type : 'leaf' +// }); + } + } + + +}); -- cgit v1.2.3 From 600dc32b7fbf406443e067eb661758e478049170 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 8 Feb 2012 16:53:46 -0800 Subject: Presets - fixed some object naming and css for presets tree --- js/panels/presets/content.reel/content.css | 3 --- js/panels/presets/style-presets.reel/style-presets.html | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/panels/presets/content.reel/content.css b/js/panels/presets/content.reel/content.css index a6a1545f..d0c8a08a 100644 --- a/js/panels/presets/content.reel/content.css +++ b/js/panels/presets/content.reel/content.css @@ -47,9 +47,6 @@ -webkit-box-flex: 1; overflow: auto; background-color: #474747; - - color: #FFF; - position: relative; z-index: 1000; } \ No newline at end of file diff --git a/js/panels/presets/style-presets.reel/style-presets.html b/js/panels/presets/style-presets.reel/style-presets.html index 5bc83ffa..58af617f 100644 --- a/js/panels/presets/style-presets.reel/style-presets.html +++ b/js/panels/presets/style-presets.reel/style-presets.html @@ -38,14 +38,14 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "name" : "Treeview", "properties" : { "element" : {"#": "libraryContainer"}, - "branchComponent" : {"@": "njbranch" }, + "branchComponent" : {"@": "branch" }, "contentController": {"@": "presetsController"}, "showRoot" : false } }, - "njbranch" : { + "branch" : { "module" : "js/components/treeview/ninja-branch.reel", - "name" : "NinjaBranch" + "name" : "Branch" } } -- cgit v1.2.3 From 586c3f7bbea04e62638e5ed8cdce9933e88c0b67 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 13 Feb 2012 10:27:27 -0800 Subject: Presets - Committing half-baked drag and drop --- js/panels/presets/style-presets.reel/style-presets.html | 1 + js/panels/presets/style-presets.reel/style-presets.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/panels/presets/style-presets.reel/style-presets.html b/js/panels/presets/style-presets.reel/style-presets.html index 58af617f..b5c40d9c 100644 --- a/js/panels/presets/style-presets.reel/style-presets.html +++ b/js/panels/presets/style-presets.reel/style-presets.html @@ -40,6 +40,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "element" : {"#": "libraryContainer"}, "branchComponent" : {"@": "branch" }, "contentController": {"@": "presetsController"}, + "activationEvent" : "dblclick", "showRoot" : false } }, diff --git a/js/panels/presets/style-presets.reel/style-presets.js b/js/panels/presets/style-presets.reel/style-presets.js index 3a71c344..f25c8067 100644 --- a/js/panels/presets/style-presets.reel/style-presets.js +++ b/js/panels/presets/style-presets.reel/style-presets.js @@ -79,11 +79,15 @@ exports.StylesLibrary = Montage.create(Component, { // }); } }, - applyPresetSelection : { + handleNodeActivation: { value: function(presetData) { var selection = this.application.ninja.selectedElements, self = this; + if(!selection || !selection.length || selection.length === 0) { + return false; + } + function setStopRuleSelector(selector) { self.application.ninja .currentDocument.documentRoot @@ -106,6 +110,11 @@ exports.StylesLibrary = Montage.create(Component, { } }, + handleDragEnd : { + value: function(sourceObject) { + console.log(sourceObject); + } + }, shouldChangeSelection : { value : function(controller, newSelection, oldSelection) { // -- cgit v1.2.3 From 6dc5d31b201d3578bf17b4f1fa7b1b9865d46153 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 13 Feb 2012 13:38:16 -0800 Subject: Style Presets - Separate out the style preset data to new file --- js/panels/presets/default-style-presets.js | 52 ++++++++++++++++++ .../presets/style-presets.reel/style-presets.html | 2 +- .../presets/style-presets.reel/style-presets.js | 61 +++------------------- 3 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 js/panels/presets/default-style-presets.js (limited to 'js') diff --git a/js/panels/presets/default-style-presets.js b/js/panels/presets/default-style-presets.js new file mode 100644 index 00000000..7455ac9f --- /dev/null +++ b/js/panels/presets/default-style-presets.js @@ -0,0 +1,52 @@ +/* + 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. +
*/ + +exports.stylePresets = { + "text": "Style Presets Library", + "children": [{ + "text": "Box Styles", + "children": [ + { + "text": "Border-Radius", + "classNameBase" : "border-radius", + "styles" : { + "border-radius": "100px", + "border" : "1px solid #333" + } + }, + { + "text": "Drop Shadow", + "classNameBase" : "drop-shadow", + "styles" : { + "box-shadow": "2px 2px 50px rgba(0,0,0,0.5)", + "border" : "1px solid #CCC" + } + }, + { + "text": "Fancy Box", + "classNameBase" : "fancy-box", + "styles" : { + "box-shadow": "inset 0 0 0 1px #666, inset 0 0 0 2px rgba(225, 225, 225, 0.4), 0 0 20px -10px #333", + "border" : "1px solid #FFF", + "border-radius": "30px", + "background-color": "#7db9e8", + "background-image": "-webkit-linear-gradient(top, rgba(255,255,255,0.74) 0%,rgba(255,255,255,0) 100%)" + } + }] + }, { + "text": "Text Styles", + "children": [ + { "text": "Italic" }, + { "text": "Text Shadow" }, + { "text": "Text Color" } ] + }, { + "text": "Color Styles", + "children": [ + { "text": "Background Gradient" }, + { "text": "Background Color" }, + { "text": "Text Highlight" } ] + }] +}; \ No newline at end of file diff --git a/js/panels/presets/style-presets.reel/style-presets.html b/js/panels/presets/style-presets.reel/style-presets.html index b5c40d9c..0db4d3c0 100644 --- a/js/panels/presets/style-presets.reel/style-presets.html +++ b/js/panels/presets/style-presets.reel/style-presets.html @@ -29,7 +29,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "bindings": { "content": { "boundObject": {"@": "owner"}, - "boundObjectPropertyPath": "data2" + "boundObjectPropertyPath": "presetData" } } }, diff --git a/js/panels/presets/style-presets.reel/style-presets.js b/js/panels/presets/style-presets.reel/style-presets.js index f25c8067..0c44e20c 100644 --- a/js/panels/presets/style-presets.reel/style-presets.js +++ b/js/panels/presets/style-presets.reel/style-presets.js @@ -5,78 +5,29 @@ */ var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component; + Component = require("montage/ui/component").Component, + DefaultPresets = require("js/panels/presets/default-style-presets").stylePresets; exports.StylesLibrary = Montage.create(Component, { hasTemplate: { value: true }, + presetData : { + value : null + }, contentPanel : { value: "presets" // get from local storage }, templateDidLoad : { value: function() { - console.log('deserialized'); + this.presetData = DefaultPresets; } }, treeList : { value : null }, - data2: { - value: { - "text": "styles", - "children": [{ - "text": "Box Styles", - "children": [ - { - "text": "Border-Radius", - "classNameBase" : "border-radius", - "styles" : { - "border-radius": "100px", - "border" : "1px solid #333" - } - }, - { - "text": "Drop Shadow", - "classNameBase" : "drop-shadow", - "styles" : { - "box-shadow": "2px 2px 50px rgba(0,0,0,0.5)", - "border" : "1px solid #CCC" - } - }, - { - "text": "Fancy Box", - "classNameBase" : "fancy-box", - "styles" : { - "box-shadow": "inset 0 0 0 1px #666, inset 0 0 0 2px rgba(225, 225, 225, 0.4), 0 0 20px -10px #333", - "border" : "1px solid #FFF", - "border-radius": "30px", - "background-color": "#7db9e8", - "background-image": "-webkit-linear-gradient(top, rgba(255,255,255,0.74) 0%,rgba(255,255,255,0) 100%)" - } - }] - }, { - "text": "Text Styles", - "children": [ - { "text": "Italic" }, - { "text": "Text Shadow" }, - { "text": "Text Color" } ] - }, { - "text": "Color Styles", - "children": [ - { "text": "Background Gradient" }, - { "text": "Background Color" }, - { "text": "Text Highlight" } ] - }] - } - }, didDraw: { value : function() { - console.log('Presets Panel prepare for draw.'); -// this.treeList.items.push({ -// label : "Box Style", -// type : 'leaf' -// }); } }, handleNodeActivation: { -- cgit v1.2.3 From 646b269da2387582531258d14a3f2ff550617323 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 14 Feb 2012 11:45:57 -0800 Subject: Cleaning up mediator --- js/controllers/document-controller.js | 16 +++++++++++++--- js/mediators/io-mediator.js | 13 ++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 84b994ce..7d38c600 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -104,16 +104,26 @@ DocumentController = exports.DocumentController = Montage.create(Component, { handleExecuteSave: { value: function(event) { //Text and HTML document classes should return the same save object for fileSave - this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.clearDocumentDirtyFlag.bind(this)); + this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); } }, - + //////////////////////////////////////////////////////////////////// + // + fileSaveResult: { + value: function (result) { + if(result.status === 204){ + this.clearDocumentDirtyFlag(); + } + } + }, + //////////////////////////////////////////////////////////////////// + + clearDocumentDirtyFlag:{ value: function(){ this.activeDocument.dirtyFlag = false; } }, - //////////////////////////////////////////////////////////////////// createNewFile:{ diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 95e775a0..599b7d84 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -155,9 +155,8 @@ exports.IoMediator = Montage.create(Component, { } // save = this.fio.saveFile({uri: file.document.uri, contents: contents}); - if(save.status === 204){ - callback(); - } + // + if (callback) callback(save); } }, //////////////////////////////////////////////////////////////////// @@ -170,6 +169,14 @@ exports.IoMediator = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// // + fileDelete: { + enumerable: false, + value: function (file, callback) { + // + } + }, + //////////////////////////////////////////////////////////////////// + // parseHtmlToNinjaTemplate: { enumerable: false, value: function (html) { -- cgit v1.2.3 From a7952c5a16e2cae3fd1a459b03b9f16bba1004da Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 14 Feb 2012 13:23:20 -0800 Subject: Cleaning up Setting up a 'document' folder to handle all document related classes that in relation to IO --- js/controllers/document-controller.js | 4 +- js/document/models/base-document.js | 93 +++++++ js/document/models/html-document.js | 492 ++++++++++++++++++++++++++++++++++ js/document/models/text-document.js | 156 +++++++++++ js/io/document/base-document.js | 93 ------- js/io/document/html-document.js | 492 ---------------------------------- js/io/document/text-document.js | 156 ----------- 7 files changed, 743 insertions(+), 743 deletions(-) create mode 100755 js/document/models/base-document.js create mode 100755 js/document/models/html-document.js create mode 100755 js/document/models/text-document.js delete mode 100755 js/io/document/base-document.js delete mode 100755 js/io/document/html-document.js delete mode 100755 js/io/document/text-document.js (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 7d38c600..9b412576 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -9,8 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, Uuid = require("montage/core/uuid").Uuid, - HTMLDocument = require("js/io/document/html-document").HTMLDocument, - TextDocument = require("js/io/document/text-document").TextDocument, + HTMLDocument = require("js/document/models/html-document").HTMLDocument, + TextDocument = require("js/document/models/text-document").TextDocument, DocumentController; //////////////////////////////////////////////////////////////////////// // diff --git a/js/document/models/base-document.js b/js/document/models/base-document.js new file mode 100755 index 00000000..918b51ad --- /dev/null +++ b/js/document/models/base-document.js @@ -0,0 +1,93 @@ +/* +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. +
*/ + +//BaseDocument Object for all files types and base class for HTML documents. + +var Montage = require("montage/core/core").Montage; + +var BaseDocument = exports.BaseDocument = Montage.create(Montage, { + /** Private Members **/ + _name: { value: null, enumerable: false }, + _uri: { value: null, enumerable: false }, + _documentType: { value: null, enumerable: false }, + _container: {value: null, enumerable: false }, + _uuid: { value: null, enumerable: false }, + _isActive: { value: true, enumerable: false }, + _dirtyFlag: { value: false, enumerable: false }, + _callback: { value: null, enumerable: false }, + _currentView: { value: null, enumerable: false}, + + /** Getters/Setters **/ + name: { + get: function() { return this._name; }, + set: function(value) { this._name = value; } + }, + + uri: { + get: function() { return this._uri; }, + set: function(value) { this._uri = value; } + }, + + documentType: { + get: function() { return this._documentType; }, + set: function(value) { this._documentType = value; } + }, + + container: { + get: function() { return this._container; }, + set: function(value) { this._container = value; } + }, + + uuid: { + get: function() { return this._uuid; }, + set: function(value) { this._uuid = value; } + }, + + isActive: { + get: function() { return this._isActive; }, + set: function(value) { this._isActive = value; } + }, + + dirtyFlag: { + get: function() { return this._dirtyFlag; }, + set: function(value) { this._dirtyFlag = value; } + }, + + callback: { + get: function() { return this._callback; }, + set: function(value) { this._callback = value; } + }, + + currentView: { + get: function() { return this._currentView; }, + set: function(value) { this._currentView = value } + }, + + /** Base Methods **/ + init: { + value: function(name, uri, type, container, uuid, callback) { + this.name = name; + this.uri = uri; + this.documentType = type; + this.container = container; + this.uuid = uuid; + this.callback = callback; + } + }, + + loadDocument: { + value: function() { + // Have the XHR here? + } + }, + + save:{ + value:function(){ + //base function - to be overridden + } + } + +}); \ No newline at end of file diff --git a/js/document/models/html-document.js b/js/document/models/html-document.js new file mode 100755 index 00000000..cb399f04 --- /dev/null +++ b/js/document/models/html-document.js @@ -0,0 +1,492 @@ +/* +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, + BaseDocument = require("js/document/models/base-document").BaseDocument, + NJUtils = require("js/lib/NJUtils").NJUtils; +//////////////////////////////////////////////////////////////////////// +// +exports.HTMLDocument = Montage.create(BaseDocument, { + // PRIVATE MEMBERS + _selectionExclude: { value: null, enumerable: false }, + _htmlTemplateUrl: { value: "user-document-templates/montage-application-cloud/index.html", enumerable: false}, + _iframe: { value: null, enumerable: false }, + _server: { value: null, enumerable: false }, + _templateDocument: { value: null, enumerable: false }, + _selectionModel: { value: [], enumerable: false }, + _undoModel: { value: { "queue" : [], "position" : 0 }, enumerable: false}, + + _document: { value: null, enumerable: false }, + _documentRoot: { value: null, enumerable: false }, + _stageBG: { value: null, enumerable: false }, + _window: { value: null, enumerable: false }, + _styles: { value: null, enumerable: false }, + _stylesheets: { value: null, enumerable: false }, + _stageStyleSheetId : { value: 'nj-stage-stylesheet', enumerable: false }, + _userDocument: { value: null, enumerable: false }, + _htmlSource: {value: "", enumerable: false}, + _glData: {value: null, enumerable: false }, + + _elementCounter: { value: 1, enumerable: false }, + _snapping : { value: true, enumerable: false }, + _layoutMode: { value: "all", enumerable: false }, + _draw3DGrid: { value: false, writable: true }, + _swfObject: { value: false, enumerable: false }, + + _zoomFactor: { value: 100, enumerable: false }, + + // PUBLIC MEMBERS + cssLoadInterval: { value: null, enumerable: false }, + + _savedLeftScroll: {value:null}, + _savedTopScroll: {value:null}, + + _codeViewDocument:{ + writable: true, + enumerable: true, + value:null + }, + + /* + * PUBLIC API + */ + + // GETTERS / SETTERS + + codeViewDocument:{ + get: function() { return this._codeViewDocument; }, + set: function(value) { this._codeViewDocument = value} + }, + + savedLeftScroll:{ + get: function() { return this._savedLeftScroll; }, + set: function(value) { this._savedLeftScroll = value} + }, + + savedTopScroll:{ + get: function() { return this._savedTopScroll; }, + set: function(value) { this._savedTopScroll = value} + }, + + selectionExclude: { + get: function() { return this._selectionExclude; }, + set: function(value) { this._selectionExclude = value; } + }, + + iframe: { + get: function() { return this._iframe; }, + set: function(value) { this._iframe = value; } + }, + + server: { + get: function() { return this._server; }, + set: function(value) { this._server = value; } + }, + + selectionModel: { + get: function() { return this._selectionModel; }, + set: function(value) { this._selectionModel = value; } + }, + + undoModel: { + get: function() { return this._undoModel; }, + set: function(value) { this._undoModel.queue = value.queue; this._undoModel.position = value.position; } + }, + + documentRoot: { + get: function() { return this._documentRoot; }, + set: function(value) { this._documentRoot = value; } + }, + + stageBG: { + get: function() { return this._stageBG; }, + set: function(value) { this._stageBG = value; } + }, + + elementCounter: { + set: function(value) { this._elementCounter = value; }, + get: function() { return this._elementCounter; } + }, + + snapping: { + get: function() { return this._snapping; }, + set: function(value) { + if(this._snapping !== value) { + this._snapping = value; + } + } + }, + + // TODO SEND THE EVENT --> Redraw the desired layout + layoutMode: { + get: function() { return this._layoutMode; }, + set: function(mode) { this._layoutMode = mode; } + }, + + draw3DGrid: { + get: function() { return this._draw3DGrid; }, + set: function(value) { + if(this._draw3DGrid !== value) { + this._draw3DGrid = value; + } + } + }, + + _userComponentSet: { + value: {}, + writable: true, + enumerable:true + }, + +// userComponentSet:{ +// enumerable: true, +// get: function() { +// return this._userComponentSet; +// }, +// set: function(value) { +// this._userComponentSet = value; +// this._drawUserComponentsOnOpen(); +// } +// }, +// +// _drawUserComponentsOnOpen:{ +// value:function(){ +// for(var i in this._userComponentSet){ +// console.log(this._userComponentSet[i].control) +// this._userComponentSet[i].control.needsDraw = true; +// } +// } +// }, + + glData: { + get: function() + { + var elt = this.iframe; + var elt = this.iframe.contentWindow.document.getElementById("UserContent"); + this._glData = null; + if (elt) + { + this._glData = new Array(); + this.collectGLData( elt, this._glData ); + } + + return this._glData + }, + + set: function(value) + { + var nWorlds = value.length; + for (var i=0; i= 0) + { + var endIndex = importStr.indexOf( "\n", startIndex ); + if (endIndex > 0) + { + var id = importStr.substring( startIndex+4, endIndex ); + var canvas = this.iframe.contentWindow.document.getElementById( id ); + if (canvas) + { + if (!canvas.elementModel) + { + NJUtils.makeElementModel(canvas, "Canvas", "shape", true); + } + + if (canvas.elementModel) + { + if (canvas.elementModel.shapeModel.GLWorld) + canvas.elementModel.shapeModel.GLWorld.clearTree(); + + var world = new GLWorld( canvas ); + canvas.elementModel.shapeModel.GLWorld = world; + world.import( importStr ); + } + } + } + } + } + } + }, + + zoomFactor: { + get: function() { return this._zoomFactor; }, + set: function(value) { this._zoomFactor = value; } + }, + + //****************************************// + // PUBLIC METHODS + + + //////////////////////////////////////////////////////////////////// + // + initialize: { + value: function(file, uuid, iframe, callback) { + // + this._userDocument = file; + // + this.init(file.name, file.uri, file.extension, iframe, uuid, callback); + // + this.iframe = iframe; + this.selectionExclude = ["HTML", "BODY", "Viewport", "UserContent", "stageBG"]; + this.currentView = "design"; + // + this.iframe.src = this._htmlTemplateUrl; + this.iframe.addEventListener("load", this, true); + } + }, + //////////////////////////////////////////////////////////////////// + + + collectGLData: { + value: function( elt, dataArray ) + { + if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) + { + var data = elt.elementModel.shapeModel.GLWorld.export(); + dataArray.push( data ); + } + + if (elt.children) + { + var nKids = elt.children.length; + for (var i=0; i