diff options
author | Ananya Sen | 2012-05-31 10:13:40 -0700 |
---|---|---|
committer | Ananya Sen | 2012-05-31 10:13:40 -0700 |
commit | 286457b4f23974277274ba388afd283e8aa085cb (patch) | |
tree | c21bf791e7c4f572d12f97987ea6b89e74da67fe /js/components/toolbar.reel/toolbar.js | |
parent | 4d9b481c58090e8f1fc7b0e9d73a81b0f49cccc8 (diff) | |
parent | d49c909cff7f0c5e5d0b127ad84a2fefc6677dc6 (diff) | |
download | ninja-286457b4f23974277274ba388afd283e8aa085cb.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into cut-copy-paste
Conflicts:
js/controllers/styles-controller.js
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/components/toolbar.reel/toolbar.js')
-rw-r--r-- | js/components/toolbar.reel/toolbar.js | 123 |
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 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component; | ||
9 | |||
10 | exports.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 | ||