xooie 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,167 +14,170 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- define('xooie/addons/carousel_pagination', ['jquery', 'xooie/addons/base'], function($, Base){
17
+ define('xooie/addons/carousel_pagination', ['jquery', 'xooie/addons/base', 'xooie/helpers'], function ($, Base, helpers) {
18
+ 'use strict';
19
+ var Pagination = new Base('pagination', function () {
20
+ var self = this;
21
+
22
+ this._breaks = [];
23
+
24
+ this.module.positionUpdaters = $.extend({}, this.module.positionUpdaters, {
25
+ "page": function (quantity, direction) {
26
+ var items, bias, offset, position, i;
27
+
28
+ items = self.module.content.children();
29
+ bias = 1;
30
+ offset = 0;
31
+ position = self.module.wrapper.scrollLeft();
32
+
33
+ if (helpers.isUndefined(direction)) {
34
+ if (quantity > 0 && quantity <= self._breaks.length) {
35
+ offset = Math.round(items.eq(self._breaks[quantity - 1]).position().left);
36
+ }
37
+ } else {
38
+ direction = direction === -1 ? -1 : 1;
18
39
 
19
- var Pagination = Base('pagination', function() {
20
- var self = this;
40
+ bias = -direction;
21
41
 
22
- this._breaks = [];
42
+ if (!quantity || typeof quantity !== 'number') {
43
+ quantity = 1;
44
+ }
23
45
 
24
- this.module.positionUpdaters = $.extend({}, this.module.positionUpdaters, {
25
- "page": function(quantity, direction) {
26
- var items = self.module.content.children(),
27
- bias = 1,
28
- offset = 0,
29
- position = self.module.wrapper.scrollLeft(),
30
- i;
46
+ i = self.currentPage(bias) + direction * quantity;
47
+ i = Math.max(0, Math.min(self._breaks.length - 1, i));
48
+ offset = Math.round(items.eq(self._breaks[i]).position().left);
49
+ }
31
50
 
32
- if (typeof direction === 'undefined') {
33
- if (quantity > 0 && quantity <= self._breaks.length) {
34
- offset = Math.round(items.eq(self._breaks[quantity - 1]).position().left);
35
- }
36
- } else {
37
- direction = direction === -1 ? -1 : 1;
51
+ return position + offset;
52
+ }
53
+ });
38
54
 
39
- bias = -direction;
55
+ this.module.snapMethods = $.extend({}, this.module.snapMethods, {
56
+ "page": function () {
57
+ var items, offset, p1, p2, i;
40
58
 
41
- if (!quantity || typeof quantity !== 'number') {
42
- quantity = 1;
43
- }
59
+ items = self.module.content.children();
60
+ i = self.currentPage();
44
61
 
45
- i = self.currentPage(bias) + direction * quantity;
46
- i = Math.max(0, Math.min(self._breaks.length - 1, i));
47
- offset = Math.round(items.eq(self._breaks[i]).position().left);
48
- }
62
+ p1 = items.eq(self._breaks[i]).position().left;
49
63
 
50
- return position + offset;
51
- }
52
- });
64
+ if (Math.abs(p1) < 1) {
65
+ p1 = p1 < 0 ? Math.ceil(p1) : Math.floor(p1);
66
+ } else {
67
+ p1 = Math.round(p1);
68
+ }
53
69
 
54
- this.module.snapMethods = $.extend({}, this.module.snapMethods, {
55
- "page": function() {
56
- var items = self.module.content.children(),
57
- offset, p1, p2,
58
- i = self.currentPage();
59
-
60
- p1 = items.eq(self._breaks[i]).position().left;
61
- if (Math.abs(p1) < 1) {
62
- p1 = p1 < 0 ? Math.ceil(p1) : Math.floor(p1);
63
- } else {
64
- p1 = Math.round(p1);
65
- }
66
-
67
- if (p1 !== 0 && i > 0) {
68
- p2 = items.eq(self._breaks[i - 1]).position().left;
69
-
70
- if (Math.abs(p2) < 1) {
71
- p2 = p2 < 0 ? Math.ceil(p2) : Math.floor(p2);
72
- } else {
73
- p2 = Math.round(p2);
74
- }
75
-
76
- if (Math.abs(p1) < Math.abs(p2)) {
77
- offset = p1 + self.module.wrapper.scrollLeft();
78
- } else {
79
- offset = p2 + self.module.wrapper.scrollLeft();
80
- }
81
-
82
- self.module.wrapper.animate({ scrollLeft: offset });
83
- }
84
- }
85
- });
70
+ if (p1 !== 0 && i > 0) {
71
+ p2 = items.eq(self._breaks[i - 1]).position().left;
86
72
 
87
- this.module.displayMethods = $.extend({}, this.module.displayMethods, {
88
- "page": function(container, template){
73
+ if (Math.abs(p2) < 1) {
74
+ p2 = p2 < 0 ? Math.ceil(p2) : Math.floor(p2);
75
+ } else {
76
+ p2 = Math.round(p2);
77
+ }
89
78
 
90
- var element = self.module.render(template, {
91
- current_page: self.currentPage() + 1,
92
- total_pages: self._breaks.length
93
- });
79
+ if (Math.abs(p1) < Math.abs(p2)) {
80
+ offset = p1 + self.module.wrapper.scrollLeft();
81
+ } else {
82
+ offset = p2 + self.module.wrapper.scrollLeft();
83
+ }
94
84
 
95
- container.append(element);
96
- }
97
- });
85
+ self.module.wrapper.animate({ scrollLeft: offset });
86
+ }
87
+ }
88
+ });
98
89
 
99
- this.module.root.on('carouselUpdated', function(){
100
- self.updateBreaks();
90
+ this.module.displayMethods = $.extend({}, this.module.displayMethods, {
91
+ "page": function (container, template) {
92
+ var element = self.module.render(template, {
93
+ current_page: self.currentPage() + 1,
94
+ total_pages: self._breaks.length
101
95
  });
102
96
 
103
- this.updateBreaks();
97
+ container.append(element);
98
+ }
104
99
  });
105
100
 
106
- Pagination.prototype.currentPage = function(bias) {
107
- var i, k, items = this.module.content.children(),
108
- position, itemWidth, lastItem;
101
+ this.module.root.on('carouselUpdated', function () {
102
+ self.updateBreaks();
103
+ });
109
104
 
110
- if (typeof bias === 'undefined') {
111
- bias = 1;
112
- }
105
+ this.updateBreaks();
106
+ });
113
107
 
114
- if (bias === 1) {
115
- position = this.module.content.position().left;
108
+ Pagination.prototype.currentPage = function (bias) {
109
+ var i, k, items, position, itemWidth, lastItem;
116
110
 
117
- for (i = 0; i < this._breaks.length; i += 1) {
118
- itemWidth = 0;
119
- lastItem = (i === this._breaks.length - 1) ? items.length : this._breaks[i + 1];
111
+ items = this.module.content.children();
120
112
 
121
- for (k = this._breaks[i]; k < lastItem; k += 1) {
122
- itemWidth += items.eq(k).outerWidth(true);
123
- }
113
+ if (helpers.isUndefined(bias)) {
114
+ bias = 1;
115
+ }
124
116
 
125
- if (position + (this.module.options.visibleThreshold * itemWidth) >= 0){
126
- return i;
127
- } else {
128
- position += itemWidth;
129
- }
130
- }
131
- return items.length - 1;
132
- } else {
133
- position = this.module.content.outerWidth(true) + this.module.content.position().left;
134
-
135
- for (i = this._breaks.length - 1; i >= 0; i--) {
136
- itemWidth = 0;
137
- lastItem = (i === this._breaks.length - 1) ? items.length : this._breaks[i + 1];
138
-
139
- for (k = this._breaks[i]; k < lastItem; k += 1) {
140
- itemWidth += items.eq(k).outerWidth(true);
141
- }
142
- position -= itemWidth;
143
-
144
- if (position <= this.module.options.visibleThreshold * itemWidth) {
145
- return i;
146
- }
147
- }
148
- return 0;
117
+ if (bias === 1) {
118
+ position = this.module.content.position().left;
119
+
120
+ for (i = 0; i < this._breaks.length; i += 1) {
121
+ itemWidth = 0;
122
+ lastItem = (i === this._breaks.length - 1) ? items.length : this._breaks[i + 1];
123
+
124
+ for (k = this._breaks[i]; k < lastItem; k += 1) {
125
+ itemWidth += items.eq(k).outerWidth(true);
149
126
  }
150
- };
151
-
152
- Pagination.prototype.updateBreaks = function() {
153
- var items = this.module.content.children(),
154
- width = 0,
155
- breakPoint = this.module.wrapper.innerWidth(),
156
- breaks = [0];
157
-
158
- items.each(function(i) {
159
- var node = $(this),
160
- w = node.outerWidth(true);
161
-
162
- width += w;
163
-
164
- if (width > breakPoint) {
165
- if (width - (w - node.innerWidth()) > breakPoint) {
166
- width = w;
167
- breaks.push(i);
168
- }
169
- }
170
- });
171
127
 
172
- this.module.root.toggleClass('is-carousel-paginated', breaks.length > 1);
128
+ if (position + (this.module.options.visibleThreshold * itemWidth) >= 0) {
129
+ return i;
130
+ }
131
+ position += itemWidth;
132
+ }
133
+ return items.length - 1;
134
+ }
135
+ position = this.module.content.outerWidth(true) + this.module.content.position().left;
136
+
137
+ for (i = this._breaks.length - 1; i >= 0; i -= 1) {
138
+ itemWidth = 0;
139
+ lastItem = (i === this._breaks.length - 1) ? items.length : this._breaks[i + 1];
140
+
141
+ for (k = this._breaks[i]; k < lastItem; k += 1) {
142
+ itemWidth += items.eq(k).outerWidth(true);
143
+ }
144
+ position -= itemWidth;
145
+
146
+ if (position <= this.module.options.visibleThreshold * itemWidth) {
147
+ return i;
148
+ }
149
+ }
150
+ return 0;
151
+ };
152
+
153
+ Pagination.prototype.updateBreaks = function () {
154
+ var items, width, breakPoint, breaks;
155
+
156
+ items = this.module.content.children();
157
+ width = 0;
158
+ breakPoint = this.module.wrapper.innerWidth();
159
+ breaks = [0];
160
+
161
+ items.each(function (i) {
162
+ var node, w;
163
+
164
+ node = $(this);
165
+ w = node.outerWidth(true);
166
+
167
+ width += w;
168
+
169
+ if (width > breakPoint && (width - (w - node.innerWidth()) > breakPoint)) {
170
+ width = w;
171
+ breaks.push(i);
172
+ }
173
+ });
174
+
175
+ this.module.root.toggleClass('is-carousel-paginated', breaks.length > 1);
173
176
 
174
- this._breaks = breaks;
177
+ this._breaks = breaks;
175
178
 
176
- this.module.updateDisplay();
177
- };
179
+ this.module.updateDisplay();
180
+ };
178
181
 
179
- return Pagination;
180
- });
182
+ return Pagination;
183
+ });
@@ -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
+ });