aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/presets-controller.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-04 17:24:27 -0700
committerNivesh Rajbhandari2012-04-04 17:24:27 -0700
commit01cf259da7aaa7d70789d9a7c32111d88b477463 (patch)
tree0bff3395ac681e5f685d2267f7dbc03a8e32bc4a /js/controllers/presets-controller.js
parent331ea08655245e3532e48bf160d5f68a04d8723f (diff)
parent13368ca6ebbc13adeafccd898dfffd7ce37cb28a (diff)
downloadninja-01cf259da7aaa7d70789d9a7c32111d88b477463.tar.gz
Merge branch 'refs/heads/ToolFixes' into WebGLMaterials
Conflicts: js/document/templates/montage-html/default_html.css js/mediators/element-mediator.js js/panels/properties.reel/properties.js js/tools/BrushTool.js js/tools/LineTool.js js/tools/PenTool.js js/tools/SelectionTool.js js/tools/ShapeTool.js js/tools/TranslateObject3DTool.js Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/controllers/presets-controller.js')
-rw-r--r--js/controllers/presets-controller.js131
1 files changed, 131 insertions, 0 deletions
diff --git a/js/controllers/presets-controller.js b/js/controllers/presets-controller.js
new file mode 100644
index 00000000..975f9f7a
--- /dev/null
+++ b/js/controllers/presets-controller.js
@@ -0,0 +1,131 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
7
8var Montage = require("montage/core/core").Montage,
9 Component = require("montage/ui/component").Component;
10
11exports.PresetsController = Montage.create(Component, {
12
13 hasTemplate : {
14 value: false
15 },
16
17 transitionClass : {
18 value : "nj-preset-transition"
19 },
20
21 addTransition: {
22 value: function(element) {
23 var transitionDuration;
24
25 element.classList.add(this.transitionClass);
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 }
46 }
47 },
48
49 captureWebkitTransitionEnd : {
50 value : function(e) {
51 var el = e.target;
52
53 //// TODO: replace this hack when webkit supports transitionStart event (see above)
54 window.clearTimeout(el.njTimeout);
55
56 el.classList.remove(this.transitionClass);
57 el.removeEventListener("webkitTransitionEnd", this, true);
58 }
59 },
60
61 applyPreset : {
62 value: function(presetData, useTransition) {
63 var selection = this.application.ninja.selectedElements;
64
65 if(!selection || !selection.length || selection.length === 0) { return false; }
66
67 var stylesController = this.application.ninja.stylesController,
68 selectorBase = presetData.selectorBase,
69 rules = [],
70 animationNames = [];
71
72 selectorBase = stylesController.generateClassName(selectorBase);
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
92 presetData.rules.forEach(function(rule, i) {
93 ///// Treat keyframed rules differently
94 if(rule.isKeyFrameRule) {
95 this.application.ninja.stylesController.addRule(
96 '@-webkit-keyframes ' + presetData.selectorBase,
97 this.stringifyKeys(rule.keys)
98 );
99 } else {
100 var suffix = rule.selectorSuffix || '';
101
102 ///// TODO: remove when we find out what to do with competing animations
103 if(rule.styles['-webkit-animation-name'] && animationNames.length) {
104 rule.styles['-webkit-animation-name'] += ',' + animationNames.join(',');
105 }
106
107 rules.push(stylesController.addRule('.'+selectorBase + suffix, rule.styles));
108 }
109 }, this);
110
111 }
112 },
113
114 stringifyKeys : {
115 value: function(keysArray) {
116 var keysString = '';
117
118 keysArray.forEach(function(key) {
119 var styles = '', style;
120
121 for(style in key.styles) {
122 styles += style + ':' + key.styles[style] + '; ';
123 }
124
125 keysString += key.keyText + ' {' + styles + ' }';
126 });
127
128 return keysString;
129 }
130 }
131}); \ No newline at end of file