diff options
author | Pushkar Joshi | 2012-04-04 15:55:48 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-04-04 15:55:48 -0700 |
commit | 0681b34b506767b6caf2816b9096bc1a57a17a2d (patch) | |
tree | 20f10c767efe8d9c5c38fbc2cdb713d093bb279d /js/controllers | |
parent | f4eccf3e7cb76a14a3546a646575162dbd831538 (diff) | |
parent | 8482e23cd9b8c4700b5130f2588e5eb24d376536 (diff) | |
download | ninja-0681b34b506767b6caf2816b9096bc1a57a17a2d.tar.gz |
Merge branch 'master' into pentool
Conflicts:
js/tools/PenTool.js
Diffstat (limited to 'js/controllers')
-rwxr-xr-x | js/controllers/elements/element-controller.js | 15 | ||||
-rwxr-xr-x | js/controllers/elements/shapes-controller.js | 5 | ||||
-rw-r--r-- | js/controllers/presets-controller.js | 77 | ||||
-rwxr-xr-x | js/controllers/selection-controller.js | 147 |
4 files changed, 99 insertions, 145 deletions
diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index b35251ad..efb33292 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js | |||
@@ -5,22 +5,27 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | NJComponent = require("js/lib/nj-base").NJComponent; | 8 | Component = require("montage/ui/component").Component; |
9 | 9 | ||
10 | var ElementController = exports.ElementController = Montage.create(NJComponent, { | 10 | exports.ElementController = Montage.create(Component, { |
11 | 11 | ||
12 | addElement: { | 12 | addElement: { |
13 | value: function(el, styles) { | 13 | value: function(el, styles) { |
14 | this.application.ninja.currentDocument.documentRoot.appendChild(el); | 14 | this.application.ninja.currentDocument.documentRoot.appendChild(el); |
15 | // Nested elements - | 15 | // Nested elements - TODO make sure the CSS is correct before nesting elements |
16 | // TODO make sure the CSS is correct before nesting elements | ||
17 | // this.application.ninja.currentSelectedContainer.appendChild(el); | 16 | // this.application.ninja.currentSelectedContainer.appendChild(el); |
18 | this.application.ninja.stylesController.setElementStyles(el, styles); | 17 | if(styles) { |
18 | this.application.ninja.stylesController.setElementStyles(el, styles); | ||
19 | } | ||
19 | } | 20 | } |
20 | }, | 21 | }, |
21 | 22 | ||
23 | // Remove the element from the DOM and clear the GLWord. | ||
22 | removeElement: { | 24 | removeElement: { |
23 | value: function(el) { | 25 | value: function(el) { |
26 | if(el.elementModel && el.elementModel.shapeModel && el.elementModel.shapeModel.GLWorld) { | ||
27 | el.elementModel.shapeModel.GLWorld.clearTree(); | ||
28 | } | ||
24 | el.parentNode.removeChild(el); | 29 | el.parentNode.removeChild(el); |
25 | } | 30 | } |
26 | }, | 31 | }, |
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index ef453bea..c9164e3e 100755 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js | |||
@@ -72,8 +72,9 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
72 | canvas.setAttribute("data-RDGE-id", njModule.NJUtils.generateRandom()); | 72 | canvas.setAttribute("data-RDGE-id", njModule.NJUtils.generateRandom()); |
73 | canvas.width = el.width; | 73 | canvas.width = el.width; |
74 | canvas.height = el.height; | 74 | canvas.height = el.height; |
75 | this.application.ninja.elementMediator.replaceElement(el, canvas); | 75 | canvas.elementModel = el.elementModel; |
76 | NJevent("elementDeleted", el); | 76 | this.application.ninja.currentDocument.documentRoot.replaceChild(canvas, el); |
77 | NJevent("elementsRemoved", el); | ||
77 | el = canvas; | 78 | el = canvas; |
78 | this.toggleWebGlMode(el, value); | 79 | this.toggleWebGlMode(el, value); |
79 | el.elementModel.shapeModel.GLWorld.render(); | 80 | el.elementModel.shapeModel.GLWorld.render(); |
diff --git a/js/controllers/presets-controller.js b/js/controllers/presets-controller.js index 7152ba93..975f9f7a 100644 --- a/js/controllers/presets-controller.js +++ b/js/controllers/presets-controller.js | |||
@@ -20,14 +20,39 @@ exports.PresetsController = Montage.create(Component, { | |||
20 | 20 | ||
21 | addTransition: { | 21 | addTransition: { |
22 | value: function(element) { | 22 | value: function(element) { |
23 | var transitionDuration; | ||
24 | |||
23 | element.classList.add(this.transitionClass); | 25 | element.classList.add(this.transitionClass); |
24 | element.addEventListener("webkitTransitionEnd", this, true); | 26 | element.addEventListener("webkitTransitionEnd", this, true); |
27 | |||
28 | |||
29 | //// TODO: replace this hack when webkit supports transitionStart event | ||
30 | transitionDuration = this.application.ninja.stylesController.getElementStyle(element, '-webkit-transition-duration', true); | ||
31 | element.njTimeout = window.setTimeout(function() { | ||
32 | this.captureWebkitTransitionEnd({ | ||
33 | 'target': element | ||
34 | }); | ||
35 | }.bind(this), this._getMilliseconds(transitionDuration) + 100); | ||
36 | } | ||
37 | }, | ||
38 | |||
39 | _getMilliseconds : { | ||
40 | value: function(duration) { | ||
41 | if(duration.indexOf('ms') !== -1) { | ||
42 | return parseInt(duration); | ||
43 | } else { | ||
44 | return parseFloat(duration)*1000; | ||
45 | } | ||
25 | } | 46 | } |
26 | }, | 47 | }, |
27 | 48 | ||
28 | captureWebkitTransitionEnd : { | 49 | captureWebkitTransitionEnd : { |
29 | value : function(e) { | 50 | value : function(e) { |
30 | var el = e.target; | 51 | var el = e.target; |
52 | |||
53 | //// TODO: replace this hack when webkit supports transitionStart event (see above) | ||
54 | window.clearTimeout(el.njTimeout); | ||
55 | |||
31 | el.classList.remove(this.transitionClass); | 56 | el.classList.remove(this.transitionClass); |
32 | el.removeEventListener("webkitTransitionEnd", this, true); | 57 | el.removeEventListener("webkitTransitionEnd", this, true); |
33 | } | 58 | } |
@@ -41,10 +66,29 @@ exports.PresetsController = Montage.create(Component, { | |||
41 | 66 | ||
42 | var stylesController = this.application.ninja.stylesController, | 67 | var stylesController = this.application.ninja.stylesController, |
43 | selectorBase = presetData.selectorBase, | 68 | selectorBase = presetData.selectorBase, |
44 | rules = []; | 69 | rules = [], |
70 | animationNames = []; | ||
45 | 71 | ||
46 | selectorBase = stylesController.generateClassName(selectorBase); | 72 | selectorBase = stylesController.generateClassName(selectorBase); |
47 | 73 | ||
74 | selection.forEach(function(element) { | ||
75 | var el = element._element, | ||
76 | animationName; | ||
77 | |||
78 | if(useTransition) { | ||
79 | this.addTransition(el); | ||
80 | } | ||
81 | |||
82 | ///// TODO: remove when we find out what to do with competing animations | ||
83 | animationName = stylesController.getElementStyle(el, '-webkit-animation-name'); | ||
84 | if(animationName) { | ||
85 | animationNames.push(animationName); | ||
86 | } | ||
87 | |||
88 | el.classList.add(selectorBase); | ||
89 | |||
90 | }, this); | ||
91 | |||
48 | presetData.rules.forEach(function(rule, i) { | 92 | presetData.rules.forEach(function(rule, i) { |
49 | ///// Treat keyframed rules differently | 93 | ///// Treat keyframed rules differently |
50 | if(rule.isKeyFrameRule) { | 94 | if(rule.isKeyFrameRule) { |
@@ -54,40 +98,19 @@ exports.PresetsController = Montage.create(Component, { | |||
54 | ); | 98 | ); |
55 | } else { | 99 | } else { |
56 | var suffix = rule.selectorSuffix || ''; | 100 | var suffix = rule.selectorSuffix || ''; |
57 | rules.push(stylesController.addRule('.'+selectorBase + suffix, rule.styles)); | ||
58 | } | ||
59 | }, this); | ||
60 | 101 | ||
61 | selection.forEach(function(element) { | 102 | ///// TODO: remove when we find out what to do with competing animations |
62 | var el = element._element; | 103 | if(rule.styles['-webkit-animation-name'] && animationNames.length) { |
104 | rule.styles['-webkit-animation-name'] += ',' + animationNames.join(','); | ||
105 | } | ||
63 | 106 | ||
64 | if(useTransition) { | 107 | rules.push(stylesController.addRule('.'+selectorBase + suffix, rule.styles)); |
65 | this.addTransition(el); | ||
66 | } | 108 | } |
67 | |||
68 | el.classList.add(selectorBase); | ||
69 | |||
70 | //// Keep track of elements with presets and don't add duplicates | ||
71 | this.setCachedPreset(el, presetData.id, rules); | ||
72 | |||
73 | }, this); | 109 | }, this); |
74 | 110 | ||
75 | } | 111 | } |
76 | }, | 112 | }, |
77 | 113 | ||
78 | setCachedPreset : { | ||
79 | value: function(el, presetId, rules) { | ||
80 | |||
81 | } | ||
82 | }, | ||
83 | |||
84 | getPresets : { | ||
85 | value: function(element) { | ||
86 | |||
87 | } | ||
88 | |||
89 | }, | ||
90 | |||
91 | stringifyKeys : { | 114 | stringifyKeys : { |
92 | value: function(keysArray) { | 115 | value: function(keysArray) { |
93 | var keysString = ''; | 116 | var keysString = ''; |
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 53cca029..dbb3f30d 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js | |||
@@ -6,8 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | 7 | ||
8 | var Montage = require("montage/core/core").Montage, | 8 | var Montage = require("montage/core/core").Montage, |
9 | Component = require("montage/ui/component").Component, | 9 | Component = require("montage/ui/component").Component; |
10 | NJUtils = require("js/lib/NJUtils").NJUtils; | ||
11 | 10 | ||
12 | exports.SelectionController = Montage.create(Component, { | 11 | exports.SelectionController = Montage.create(Component, { |
13 | 12 | ||
@@ -45,13 +44,10 @@ exports.SelectionController = Montage.create(Component, { | |||
45 | value: function() { | 44 | value: function() { |
46 | this.eventManager.addEventListener("openDocument", this, false); | 45 | this.eventManager.addEventListener("openDocument", this, false); |
47 | this.eventManager.addEventListener("elementAdded", this, false); | 46 | this.eventManager.addEventListener("elementAdded", this, false); |
48 | this.eventManager.addEventListener("elementDeleted", this, false); | 47 | this.eventManager.addEventListener("elementsRemoved", this, false); |
49 | this.eventManager.addEventListener("selectAll", this, false); | 48 | this.eventManager.addEventListener("selectAll", this, false); |
50 | this.eventManager.addEventListener("delete |