diff options
Diffstat (limited to 'node_modules/montage/ui/bluemoon/tabs.reel/tabs.js')
-rwxr-xr-x | node_modules/montage/ui/bluemoon/tabs.reel/tabs.js | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/node_modules/montage/ui/bluemoon/tabs.reel/tabs.js b/node_modules/montage/ui/bluemoon/tabs.reel/tabs.js new file mode 100755 index 00000000..4836e455 --- /dev/null +++ b/node_modules/montage/ui/bluemoon/tabs.reel/tabs.js | |||
@@ -0,0 +1,180 @@ | |||
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 | @module "montage/ui/tabs.reel" | ||
8 | @requires montage/core/core | ||
9 | @requires montage/ui/component | ||
10 | @requires "montage/ui/repetition.reel" | ||
11 | @requires "montage/ui/substitution.reel" | ||
12 | @requires "montage/ui/dynamic-text.reel" | ||
13 | @requires "montage/ui/image.reel" | ||
14 | @requires montage/core/uuid | ||
15 | */ | ||
16 | var Montage = require("montage").Montage, | ||
17 | Component = require("ui/component").Component, | ||
18 | Repetition = require("ui/repetition.reel").Repetition, | ||
19 | Substitution = require("ui/substitution.reel").Substitution, | ||
20 | DynamicText = require("ui/dynamic-text.reel").DynamicText, | ||
21 | Image = require("ui/image.reel").Image, | ||
22 | Uuid = require("core/uuid").Uuid; | ||
23 | |||
24 | /** | ||
25 | @class module:"montage/ui/tabs.reel".Tabs | ||
26 | */ | ||
27 | |||
28 | var Tabs = exports.Tabs = Montage.create(Component, /** @lends module:"montage/ui/tabs.reel".Tabs# */ { | ||
29 | |||
30 | _repetition: { | ||
31 | value: null, | ||
32 | serializable: true | ||
33 | }, | ||
34 | |||
35 | _indicator: { | ||
36 | value: null, | ||
37 | serializable: true | ||
38 | }, | ||
39 | /** | ||
40 | Description TODO | ||
41 | @type {Property} | ||
42 | @default {Array} [] | ||
43 | */ | ||
44 | tabs: { | ||
45 | distinct: true, | ||
46 | serializable: true, | ||
47 | value: [] | ||
48 | }, | ||
49 | |||
50 | navController: { | ||
51 | value: null, | ||
52 | serializable: true | ||
53 | }, | ||
54 | // optional property. If provided, this will result in wiring tab clicks to switching components in content | ||
55 | /** | ||
56 | Description TODO | ||
57 | @type {Property} | ||
58 | @default null | ||
59 | */ | ||
60 | content: { | ||
61 | enumerable: false, | ||
62 | serializable: true, | ||
63 | value: null | ||
64 | }, | ||
65 | |||
66 | // @private - | ||
67 | _selectedTabs: {value: null}, | ||
68 | selectedTabs: { | ||
69 | get: function() { | ||
70 | return this._selectedTabs; | ||
71 | }, | ||
72 | set: function(arr) { | ||
73 | if(arr && arr.length > 0) { | ||
74 | this._selectedTabs = arr; | ||
75 | this.selectedTab = arr[0]; | ||
76 | } | ||
77 | } | ||
78 | }, | ||
79 | |||
80 | // selectedTabValue is the value of the Tab, selectedTab returns the object representing the tab | ||
81 | |||
82 | _selectedTabValue: {value: null}, | ||
83 | selectedTabValue: { | ||
84 | get: function() { | ||
85 | return this._selectedTabValue; | ||
86 | }, | ||
87 | set: function(value) { | ||
88 | this._selectedTabValue = value; | ||
89 | if(this.navController) { | ||
90 | var index = this._indexOf(value); | ||
91 | this.navController.selectedIndexes = [index]; | ||
92 | } | ||
93 | }, | ||
94 | serializable: true | ||
95 | }, | ||
96 | |||
97 | |||
98 | _selectedTab: {value: null}, | ||
99 | selectedTab: { | ||
100 | enumerable: false, | ||
101 | get: function() { | ||
102 | return this._selectedTab; | ||
103 | }, | ||
104 | set: function(value) { | ||
105 | if(value && value !== this._selectedTab) { | ||
106 | this._selectedTab = value; | ||
107 | this.needsDraw = true; | ||
108 | } | ||
109 | } | ||
110 | }, | ||
111 | |||
112 | _indexOf: { | ||
113 | value: function(value) { | ||
114 | var index = 0; | ||
115 | // get the index of the this value element in the tabs array | ||
116 | var i = 0, len = this.tabs.length; | ||
117 | for (; i < len; i++) { | ||
118 | if (this.tabs[i].value === value) { | ||
119 | index = i; | ||
120 | } | ||
121 | } | ||
122 | return index; | ||
123 | |||
124 | } | ||
125 | }, | ||
126 | |||
127 | propertyChangeBindingListener: { | ||
128 | value: function(type, listener, useCapture, atSignIndex, bindingOrigin, bindingPropertyPath, bindingDescriptor) { | ||
129 | // kishore: same as in list.js | ||
130 | if (bindingDescriptor.boundObjectPropertyPath.match(/objectAtCurrentIteration/)) { | ||
131 | if (this._repetition) { | ||
132 | bindingDescriptor.boundObject = this._repetition; | ||
133 | return this._repetition.propertyChangeBindingListener.apply(this._repetition, arguments); | ||
134 | } else { | ||
135 | return null; | ||
136 | } | ||
137 | } else { | ||
138 | return Object.prototype.propertyChangeBindingListener.apply(this, arguments); | ||
139 | } | ||
140 | } | ||
141 | }, | ||
142 | |||
143 | deserializedFromTemplate: { | ||
144 | value: function() { | ||
145 | this._orphanedChildren = this.childComponents; | ||
146 | this.childComponents = null; | ||
147 | } | ||
148 | }, | ||
149 | |||
150 | templateDidLoad: { | ||
151 | value: function() { | ||
152 | var orphanedFragment, | ||
153 | currentContentRange = this.element.ownerDocument.createRange(); | ||
154 | currentContentRange.selectNodeContents(this.element); | ||
155 | orphanedFragment = currentContentRange.extractContents(); | ||
156 | |||
157 | this._repetition.element.querySelector('li').appendChild(orphanedFragment); | ||
158 | this._repetition.childComponents = this._orphanedChildren; | ||
159 | this._repetition.needsDraw = true; | ||
160 | |||
161 | if(this.content) { | ||
162 | // substitution | ||
163 | Object.defineBinding(this.content, "switchValue", { | ||
164 | boundObject: this, | ||
165 | boundObjectPropertyPath: 'selectedTab.value' | ||
166 | }); | ||
167 | } | ||
168 | var index = (this.selectedTabValue ? this._indexOf(this.selectedTabValue) : 0); | ||
169 | this.navController.selectedIndexes = [index]; | ||
170 | |||
171 | } | ||
172 | }, | ||
173 | |||
174 | draw: { | ||
175 | value: function() { | ||
176 | //console.log("draw current tab = " + value); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | }); | ||