aboutsummaryrefslogtreecommitdiff
path: root/js/components/toolbar.reel/toolbar.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-05-23 13:37:15 -0700
committerJose Antonio Marquez2012-05-23 13:37:15 -0700
commit16decc5726eafbb25675c61be6df85a378ac1fac (patch)
tree5590c4a20a5d9297d3e66a1d290db32f028047eb /js/components/toolbar.reel/toolbar.js
parent27e6e1238ec1adb34aa396074e2559801c7e4314 (diff)
parent108764dbdaa0c040de9146c2d722b6e53830cd54 (diff)
downloadninja-16decc5726eafbb25675c61be6df85a378ac1fac.tar.gz
Merge branch 'refs/heads/Ninja-DOM-Architecture' into Document
Diffstat (limited to 'js/components/toolbar.reel/toolbar.js')
-rw-r--r--js/components/toolbar.reel/toolbar.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/js/components/toolbar.reel/toolbar.js b/js/components/toolbar.reel/toolbar.js
new file mode 100644
index 00000000..2ccdb2c5
--- /dev/null
+++ b/js/components/toolbar.reel/toolbar.js
@@ -0,0 +1,123 @@
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
7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component;
9
10exports.Toolbar = Montage.create(Component, {
11 _needsButtonProperties : {
12 value: null
13 },
14 _sourceObject : {
15 value: null
16 },
17 sourceObject : {
18 get: function() {
19 return this._sourceObject;
20 },
21 set: function(value) {
22 if(value === this._sourceObject) { return; }
23 this._sourceObject = value;
24 },
25 serializable: true
26 },
27 leftAlignClass : { value: "left-button" },
28 hideButtonClass : { value: "hide-button" },
29 _buttons : { value: [], distinct: true },
30 buttons : {
31 get: function() {
32 return this._buttons;
33 },
34 set: function(btns) {
35 this._buttons = btns;
36 this._needsButtonProperties = this.needsDraw = true;
37 },
38 serializable: true
39 },
40
41 _buttonToHide : {
42 value: null
43 },
44 _buttonToShow : {
45 value: null
46 },
47 getButton : {
48 value: function(identifier) {
49 var buttons = this.repetition.childComponents,
50 buttonIds = buttons.map(function(component) {
51 return component.sourceObject.identifier;
52 });
53
54 return buttons[buttonIds.indexOf(identifier)];
55 }
56 },
57 hideButton : {
58 value: function(identifier) {
59 var button = this.getButton(identifier);
60
61 if(button) {
62 this._buttonToHide = button;
63 this.needsDraw = true;
64 }
65 }
66 },
67 showButton : {
68 value: function(identifier) {
69 var button = this.getButton(identifier);
70
71 if(button) {
72 this._buttonToShow = button;
73 this.needsDraw = true;
74 }
75 }
76 },
77
78 prepareForDraw : {
79 value: function() {
80 if(this._needsButtonProperties) {
81 this.repetition.childComponents.forEach(function(button) {
82 button.identifier = button.sourceObject.identifier;
83 button.addEventListener('action', this.delegate, false);
84 }, this);
85 }
86 }
87 },
88 draw : {
89 value: function() {
90 if(this._needsClass) {
91
92 this.repetition.childComponents.forEach(function(button) {
93 button.element.classList.add('toolbar-' + button.sourceObject.identifier + '-button');
94
95 ///// add left align class if specified in serialization
96 if(button.sourceObject.leftAlign) {
97 button.element.parentElement.classList.add(this.leftAlignClass);
98 }
99 }, this);
100
101 this._needsClass = false;
102 }
103
104 if(this._needsButtonProperties) {
105 this._needsClass = this.needsDraw = true;
106 this._needsButtonProperties = false;
107 }
108
109 if(this._buttonToHide) {
110 this._buttonToHide.element.classList.add(this.hideButtonClass);
111 this._buttonToHide = null;
112 }
113 if(this._buttonToShow) {
114 this._buttonToShow.element.classList.remove(this.hideButtonClass);
115 this._buttonToShow = null;
116 }
117
118 }
119 },
120 _needsClass : {
121 value: null
122 }
123}); \ No newline at end of file