|
1 |
| -/*! jQuery asAccordion - v0.1.0 - 2014-10-23 |
| 1 | +/*! jQuery asAccordion - v0.1.0 - 2014-11-06 |
2 | 2 | * https://github.com/amazingSurge/jquery-asAccordion
|
3 | 3 | * Copyright (c) 2014 amazingSurge; Licensed GPL */
|
4 | 4 | (function(window, document, $, undefined) {
|
|
49 | 49 | this.initialIndex = this.options.initialIndex;
|
50 | 50 | this.initialized = false;
|
51 | 51 | this.disabled = false;
|
52 |
| - this.actived = false; |
53 | 52 | this.current = null;
|
54 | 53 |
|
55 | 54 | this.classes = {
|
|
112 | 111 | this.set(this.initialIndex);
|
113 | 112 | this.current = this.initialIndex;
|
114 | 113 |
|
| 114 | + this.initialized = true; |
| 115 | + |
115 | 116 | this.responsive.init(this);
|
116 | 117 | $(window).on('resize', this._throttle(function(){
|
117 | 118 | self.responsive.init(self);
|
118 | 119 | }, 250));
|
119 | 120 |
|
120 |
| - |
121 |
| - this.initialized = true; |
122 |
| - |
123 | 121 | this._trigger('ready');
|
124 | 122 | },
|
125 | 123 |
|
|
142 | 140 |
|
143 | 141 | responsive: {
|
144 | 142 | init: function(self) {
|
145 |
| - if ($('html, body').outerWidth() <= self.options.mobile_breakpoint) { |
| 143 | + if ($('html, body').outerWidth() <= self.options.mobile_breakpoint && !this.responsive) { |
146 | 144 | if (self.options.direction === 'vertical') {
|
147 | 145 | return false;
|
148 | 146 | }
|
| 147 | + this.responsive = true; |
149 | 148 |
|
150 | 149 | this.resize(self);
|
151 | 150 | }else {
|
152 | 151 | if (typeof self.default_direction === 'undefined' || self.default_direction === 'vertical') {
|
153 | 152 | return false;
|
154 | 153 | }
|
| 154 | + this.responsive = false; |
155 | 155 |
|
156 | 156 | this.resize(self);
|
157 | 157 | }
|
|
174 | 174 | self.$element.addClass(self.classes.direction);
|
175 | 175 |
|
176 | 176 | style[self.animateProperty] = self.distance;
|
177 |
| - self.$panel.css(style); |
| 177 | + self.$panel.css(style).removeClass(self.classes.active); |
178 | 178 |
|
179 |
| - if (typeof self.current !== 'undefined') { |
| 179 | + if (self.current.length >= 0 || self.current >= 0) { |
180 | 180 | var index = self.current;
|
181 |
| - self.current = null; |
| 181 | + self.current = self.current.length >= 0 ? [] : null; |
182 | 182 | self.set(index);
|
183 | 183 | }
|
184 | 184 | }
|
185 | 185 | },
|
186 | 186 |
|
187 | 187 | set: function(index) {
|
| 188 | + if ($.isArray(index)) { |
| 189 | + for(var key in index) { |
| 190 | + this.set(index[key]); |
| 191 | + } |
| 192 | + return; |
| 193 | + } |
| 194 | + |
| 195 | + if (index >= this.size || index < 0) { |
| 196 | + return; |
| 197 | + } |
| 198 | + |
188 | 199 | var self = this,
|
189 | 200 | $panel = this.$panel.eq(index),
|
190 | 201 | $oldPanel = this.$element.find('.' + this.classes.active),
|
191 | 202 | distance,
|
192 | 203 | duration,
|
| 204 | + current = false, |
193 | 205 | style = {},
|
194 | 206 | old_style = {};
|
195 | 207 |
|
|
206 | 218 | }
|
207 | 219 | duration = Math.ceil(duration);
|
208 | 220 |
|
209 |
| - if (index === this.current) { |
210 |
| - this.current = null; |
| 221 | + if ($panel.hasClass(this.classes.active)) { |
211 | 222 | distance = this.distance;
|
212 | 223 | $panel.removeClass(this.classes.active);
|
213 |
| - }else { |
214 |
| - if (index >= this.size) { |
215 |
| - index = this.size - 1; |
216 |
| - }else if (index < 0) { |
217 |
| - index = 0; |
218 |
| - } |
219 | 224 |
|
| 225 | + if (this.options.multiple) { |
| 226 | + var number; |
| 227 | + for (var key in this.current) { |
| 228 | + if (this.current[key] == index) { |
| 229 | + number = key; |
| 230 | + }else { |
| 231 | + continue; |
| 232 | + } |
| 233 | + this.current.splice(key, 1); |
| 234 | + } |
| 235 | + } else { |
| 236 | + this.current = null; |
| 237 | + } |
| 238 | + }else { |
220 | 239 | if (this.options.direction === 'vertical') {
|
221 | 240 | distance = $panel.find('.' + this.namespace + '__expander').outerHeight() + this.distance;
|
222 | 241 | } else {
|
223 | 242 | distance = $panel.find('.' + this.namespace + '__expander').outerWidth() + this.distance;
|
224 | 243 | }
|
225 | 244 |
|
226 |
| - this.current = index; |
| 245 | + if (this.options.multiple && $.isArray(this.current)) { |
| 246 | + this.current.push(index); |
| 247 | + } else { |
| 248 | + this.current = index; |
| 249 | + } |
227 | 250 |
|
228 |
| - old_style[this.animateProperty] = this.distance; // used to remove the original distance |
229 |
| - this.animate($oldPanel, old_style, duration, this.options.easing, moveEnd); |
| 251 | + if (this.options.multiple) { |
| 252 | + $panel.addClass(this.classes.active); |
| 253 | + } else { |
| 254 | + old_style[this.animateProperty] = this.distance; // used to remove the original distance |
| 255 | + this.animate($oldPanel, old_style, duration, this.options.easing, moveEnd); |
230 | 256 |
|
231 |
| - $panel.addClass(this.classes.active).siblings().removeClass(this.classes.active); |
| 257 | + $panel.addClass(this.classes.active).siblings().removeClass(this.classes.active); |
| 258 | + } |
232 | 259 | }
|
233 | 260 |
|
234 | 261 | style[this.animateProperty] = distance;
|
|
336 | 363 | easing: 'ease-in-out',
|
337 | 364 | speed: 500,
|
338 | 365 | direction: 'vertical',
|
339 |
| - event: 'click' |
| 366 | + event: 'click', |
| 367 | + multiple: false |
340 | 368 | };
|
341 | 369 |
|
342 | 370 | $.fn[pluginName] = function(options) {
|
|
0 commit comments