forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccordion.js
91 lines (84 loc) · 2.94 KB
/
accordion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
"jquery",
"mage/tabs"
], function($, tabs){
"use strict";
$.widget("mage.accordion", tabs, {
options: {
active : [0],
multipleCollapsible: false,
openOnFocus: false
},
_callCollapsible: function() {
if((typeof this.options.active) === "string") {
this.options.active = this.options.active.split(" ").map(function(item) {
return parseInt(item, 10);
});
}
var self = this,
disabled = false,
active = false;
$.each(this.collapsibles, function(i) {
disabled = active = false;
if($.inArray(i,self.options.disabled) !== -1) {
disabled = true;
}
if($.inArray(i,self.options.active) !== -1) {
active = true;
}
self._instantiateCollapsible(this,i,active,disabled);
});
},
/**
* Overwrites default functionality to provide the option to activate/deactivate multiple sections simultaneous
* @param action
* @param index
* @private
*/
_toggleActivate: function(action,index) {
if($.isArray( index && this.options.multipleCollapsible)) {
var self = this;
$.each(index, function() {
self.collapsibles.eq(this).collapsible(action);
});
} else if( (index === undefined) && this.options.multipleCollapsible) {
this.collapsibles.collapsible(action);
} else {
this._super(action,index);
}
},
/**
* If the Accordion allows multiple section to be active at the same time, if deep linking is used
* sections that don't contain the id from anchor shouldn't be closed, otherwise the accordion uses the
* tabs behavior
* @private
*/
_handleDeepLinking: function() {
if(!this.options.multipleCollapsible) {
this._super();
}
},
/**
* Prevent default behavior that closes the other sections when one gets activated if the Accordion allows
* multiple sections simultaneous
* @private
*/
_closeOthers: function() {
if(!this.options.multipleCollapsible) {
this._super();
}
$.each(this.collapsibles, function() {
$(this).on("beforeOpen", function() {
var section = $(this);
section.addClass('allow').prevAll().addClass('allow');
section.nextAll().removeClass('allow');
});
});
}
});
return $.mage.accordion;
});