xooie 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright 2012 Comcast
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ define('xooie/addons/dropdown_accordion', ['jquery', 'xooie/addons/base'], function($, Base){
18
+
19
+ var Accordion = Base('accordion', function() {
20
+ var self = this;
21
+
22
+ this.module.getHandle().on('dropdownExpand', function(event){
23
+ var activeHandles = self.module.getHandle().not($(this)).filter('.' + self.module.options.activeDropdownClass),
24
+ i = 0,
25
+ index;
26
+
27
+ for (; i < activeHandles.length; i += 1) {
28
+ index = parseInt($(activeHandles[i]).attr('data-dropdown-index'), 10);
29
+
30
+ self.module.collapse(index, 0);
31
+ }
32
+
33
+ });
34
+ });
35
+
36
+ return Accordion;
37
+
38
+ });
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Copyright 2012 Comcast
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ define('xooie/addons/tab_automation', ['jquery', 'xooie/addons/base'], function($, Base) {
18
+ var outOfRange = function(lower, upper, point, normalize) {
19
+ var n = ( Math.min(lower, point) - lower ) || ( Math.max(upper, point) - upper );
20
+ var denominator = (normalize) ? Math.max(Math.abs(n),1) : 1;
21
+ return n/denominator;
22
+ };
23
+
24
+
25
+ var Automation = Base('automation', function(){
26
+ var self = this,
27
+ focusTable = {},
28
+ setFocus;
29
+
30
+ this._tabChangeTimer = 0;
31
+
32
+ this._canRotate = true;
33
+
34
+ //automationInstances.push(this);
35
+
36
+ setFocus = function(method, state) {
37
+ var prop;
38
+
39
+ focusTable[method] = state;
40
+
41
+ if (state) {
42
+ for (prop in focusTable) {
43
+ state = state && focusTable[prop];
44
+ }
45
+ }
46
+
47
+ self._canRotate = state;
48
+ };
49
+
50
+ this.module.root.on({
51
+ 'mouseenter': function(){
52
+ setFocus('mouse', false);
53
+ self.stop();
54
+ },
55
+ 'focus': function(){
56
+ setFocus('keyboard', false);
57
+ self.stop();
58
+ },
59
+ 'mouseleave': function(){
60
+ setFocus('mouse', true);
61
+ self.start();
62
+ },
63
+ 'blur': function(){
64
+ setFocus('mouse', true);
65
+ self.start();
66
+ },
67
+ 'tabChange': function(){
68
+ self.start();
69
+ }
70
+ });
71
+
72
+ this.module.root.find('*').on({
73
+ 'focus': function(){
74
+ setFocus('keyboard', false);
75
+ self.stop();
76
+ },
77
+ 'blur': function(){
78
+ setFocus('keyboard', true);
79
+ self.start();
80
+ }
81
+ });
82
+
83
+ this.start();
84
+ });
85
+
86
+ Automation.setDefaultOptions({
87
+ direction: 1,
88
+ delay: 10000
89
+ });
90
+
91
+ $.extend(Automation.prototype, {
92
+ start: function(){
93
+ var self = this;
94
+
95
+ if (this._tabChangeTimer) {
96
+ this.stop();
97
+ }
98
+
99
+ this._tabChangeTimer = setTimeout(function(){
100
+ self.stop();
101
+
102
+ if (!self._canRotate){
103
+ return;
104
+ }
105
+
106
+ if (self.outOfRange()) {
107
+ $(window).on('scroll', function(event){
108
+ if (!self.outOfRange()) {
109
+ self.start();
110
+ $(window).off(event);
111
+ }
112
+ //TODO: add logic to remove scroll event if the elementis no longer in the DOM
113
+ });
114
+ return;
115
+ }
116
+
117
+ var newTab;
118
+
119
+ if (self.module._currentTab + self.options.direction >= self.module.getPanel().length) {
120
+ newTab = 0;
121
+ } else if (self.module._currentTab + self.options.direction < 0) {
122
+ newTab = self.module.getPanel().length - 1;
123
+ } else {
124
+ newTab = self.module._currentTab + self.options.direction;
125
+ }
126
+
127
+ self.module.switchToTab(newTab);
128
+ }, this.options.delay);
129
+
130
+ },
131
+
132
+ stop: function() {
133
+ this._tabChangeTimer = clearTimeout(this._tabChangeTimer);
134
+ },
135
+
136
+ //Will return true if the tab module is out of range (ie, both the top and bottom are out of range)
137
+ outOfRange: function(){
138
+ var lower, upper, top, bottom;
139
+
140
+ lower = $(window).scrollTop();
141
+ upper = lower + $(window).height();
142
+ top = this.module.root.offset().top;
143
+ bottom = top + this.module.root.outerHeight(true);
144
+
145
+ return !!(outOfRange(lower, upper, top, true) && outOfRange(lower, upper, bottom, true));
146
+ }
147
+ });
148
+
149
+ return Automation;
150
+ });
@@ -0,0 +1,217 @@
1
+ /*
2
+ * Copyright 2012 Comcast
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ define('xooie/base', ['jquery', 'xooie', 'xooie/stylesheet'], function($, $X, Stylesheet) {
18
+ $.event.special['xooie-init'] = {
19
+ add: function(handleObj) {
20
+ var control = $(this).data(handleObj.namespace + '-instance');
21
+ if (control) {
22
+ var event = $.Event('xooie-init');
23
+ event.namespace = handleObj.namespace;
24
+ event.data = handleObj.data;
25
+
26
+ handleObj.handler.call(this, event);
27
+ }
28
+ }
29
+ };
30
+
31
+ var Base = function(name, constructor) {
32
+ var instances, defaultOptions, instanceCounter,
33
+ initEvent, refreshEvent,
34
+ instanceName, cssRules,
35
+ stylesInstance, className, Xooie;
36
+
37
+ instances = [];
38
+
39
+ defaultOptions = {};
40
+
41
+ name = name.toLowerCase();
42
+ initEvent = 'xooie-init.' + name;
43
+ refreshEvent = 'xooie-refresh.' + name;
44
+ instanceName = name + '-instance';
45
+ instanceCounter = 0;
46
+ className = 'is-' + name + '-instantiated';
47
+
48
+ cssRules = {};
49
+ stylesInstance = new Stylesheet('Xooie');
50
+
51
+ Xooie = function(root) {
52
+ this.root = $(root);
53
+ this._name = name;
54
+
55
+ if (this.root.data(instanceName)) {
56
+ this.root.trigger(refreshEvent);
57
+ return instances[this.root.data(instanceName)];
58
+ }
59
+ instanceCounter+=1;
60
+ instances[instanceCounter] = this;
61
+ this.root.data(instanceName, instanceCounter);
62
+
63
+ this.instanceClass = this._name + '-' + instanceCounter;
64
+ this.root.addClass(this.instanceClass);
65
+
66
+ this.options = $.extend({}, Xooie.getDefaultOptions(), this.root.data());
67
+
68
+ //expose the stylesheet for this widget to each instance
69
+ this.stylesheet = stylesInstance;
70
+
71
+ //expose the common css rules
72
+ this.cssRules = $.extend({}, cssRules);
73
+
74
+ var addons, i, self = this;
75
+
76
+ constructor.apply(this, arguments);
77
+
78
+ this.root.addClass(className);
79
+
80
+ if(this.options.addons) {
81
+ addons = this.options.addons.split(' ');
82
+
83
+ for (i = 0; i < addons.length; i += 1) {
84
+ this.loadAddon(addons[i]);
85
+ }
86
+ }
87
+
88
+ this.root.trigger(initEvent);
89
+ };
90
+
91
+ Xooie.prototype = {
92
+ loadAddon: function(addon){
93
+ var self = this,
94
+ addon_name = $X.mapName(addon, 'addons', 'xooie/addons/');
95
+
96
+ if (typeof this.addons === 'undefined') {
97
+ this.addons = {};
98
+ }
99
+
100
+ try {
101
+ $X._requireShim(addon_name, function(Addon){
102
+ if (typeof Addon === 'function') {
103
+ new Addon(self);
104
+ }
105
+ });
106
+ } catch (e) {
107
+ //need to determine how to handle missing addons
108
+ }
109
+ },
110
+
111
+ render: function(template, view) {
112
+ var language = template.data('templateLanguage') || Base.default_template_language,
113
+ result = Base.render[language](template, view);
114
+
115
+ if (result === false) {
116
+ return $('<span>Error rendering template</span>');
117
+ } else {
118
+ return result;
119
+ }
120
+ },
121
+
122
+ cleanup: function() {
123
+ var name;
124
+
125
+ for (name in this.addons) {
126
+ if (this.addons.hasOwnProperty(name)) {
127
+ this.addons[name].cleanup();
128
+ }
129
+ }
130
+
131
+ this.root.removeClass(className);
132
+ this.root.removeClass(this.instanceClass);
133
+ this.root.data(instanceName, false);
134
+ }
135
+
136
+ };
137
+
138
+ Xooie.setCSSRules = function(rules){
139
+ var rule;
140
+
141
+ if(typeof stylesInstance.addRule === 'undefined'){
142
+ return;
143
+ }
144
+
145
+ for (rule in rules){
146
+ cssRules[rule] = stylesInstance.addRule(rule, rules[rule]);
147
+ }
148
+ };
149
+
150
+ Xooie.getDefaultOptions = function(){
151
+ return defaultOptions || {};
152
+ };
153
+
154
+ Xooie.setDefaultOptions = function(options) {
155
+ if (typeof options !== 'undefined') {
156
+ $.extend(defaultOptions, options);
157
+ }
158
+ };
159
+
160
+ Xooie.garbageCollect = function() {
161
+ var id, instance;
162
+
163
+ for (id in instances) {
164
+ if (instances.hasOwnProperty(id)) {
165
+ instance = instances[id];
166
+
167
+ if (instance.root.parents('body').length === 0) {
168
+ instance.cleanup();
169
+ delete instances[id];
170
+ }
171
+ }
172
+ }
173
+ };
174
+
175
+ $X.registeredClasses.push(Xooie);
176
+
177
+ return Xooie;
178
+ };
179
+
180
+ Base.default_template_language = 'micro_template';
181
+
182
+ Base.render = {
183
+ 'micro_template': function(template, view) {
184
+ if (typeof template.micro_render !== 'undefined') {
185
+ return $(template.micro_render(view));
186
+ } else {
187
+ return false;
188
+ }
189
+ },
190
+
191
+ 'mustache': function(template, view) {
192
+ if (typeof Mustache !== 'undefined' && typeof Mustache.render !== 'undefined') {
193
+ return $(Mustache.render(template.html(), view));
194
+ } else {
195
+ return false;
196
+ }
197
+ },
198
+
199
+ 'jsrender': function(template, view) {
200
+ if (typeof template.render !== 'undefined') {
201
+ return $(template.render(view));
202
+ } else {
203
+ return false;
204
+ }
205
+ },
206
+
207
+ 'underscore': function(template, view) {
208
+ if (typeof _ !== 'undefined' && typeof _.template !== 'undefined') {
209
+ return $(_.template(template.html())(view).trim());
210
+ } else {
211
+ return false;
212
+ }
213
+ }
214
+ };
215
+
216
+ return Base;
217
+ });