Mercurial > web-octave
annotate js/foundation/foundation.accordion.js @ 0:7abe02bf29ec
initial commit
author | Alex Krolick <whokilledtheelectricmonk@gmail.com> |
---|---|
date | Sat, 07 Nov 2015 18:04:42 -0800 |
parents | |
children |
rev | line source |
---|---|
0
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
1 ;(function ($, window, document, undefined) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
2 'use strict'; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
3 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
4 Foundation.libs.accordion = { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
5 name : 'accordion', |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
6 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
7 version : '5.5.3', |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
8 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
9 settings : { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
10 content_class : 'content', |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
11 active_class : 'active', |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
12 multi_expand : false, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
13 toggleable : true, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
14 callback : function () {} |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
15 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
16 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
17 init : function (scope, method, options) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
18 this.bindings(method, options); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
19 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
20 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
21 events : function (instance) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
22 var self = this; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
23 var S = this.S; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
24 self.create(this.S(instance)); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
25 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
26 S(this.scope) |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
27 .off('.fndtn.accordion') |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
28 .on('click.fndtn.accordion', '[' + this.attr_name() + '] > dd > a, [' + this.attr_name() + '] > li > a', function (e) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
29 var accordion = S(this).closest('[' + self.attr_name() + ']'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
30 groupSelector = self.attr_name() + '=' + accordion.attr(self.attr_name()), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
31 settings = accordion.data(self.attr_name(true) + '-init') || self.settings, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
32 target = S('#' + this.href.split('#')[1]), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
33 aunts = $('> dd, > li', accordion), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
34 siblings = aunts.children('.' + settings.content_class), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
35 active_content = siblings.filter('.' + settings.active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
36 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
37 e.preventDefault(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
38 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
39 if (accordion.attr(self.attr_name())) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
40 siblings = siblings.add('[' + groupSelector + '] dd > ' + '.' + settings.content_class + ', [' + groupSelector + '] li > ' + '.' + settings.content_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
41 aunts = aunts.add('[' + groupSelector + '] dd, [' + groupSelector + '] li'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
42 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
43 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
44 if (settings.toggleable && target.is(active_content)) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
45 target.parent('dd, li').toggleClass(settings.active_class, false); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
46 target.toggleClass(settings.active_class, false); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
47 S(this).attr('aria-expanded', function(i, attr){ |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
48 return attr === 'true' ? 'false' : 'true'; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
49 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
50 settings.callback(target); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
51 target.triggerHandler('toggled', [accordion]); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
52 accordion.triggerHandler('toggled', [target]); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
53 return; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
54 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
55 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
56 if (!settings.multi_expand) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
57 siblings.removeClass(settings.active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
58 aunts.removeClass(settings.active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
59 aunts.children('a').attr('aria-expanded','false'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
60 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
61 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
62 target.addClass(settings.active_class).parent().addClass(settings.active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
63 settings.callback(target); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
64 target.triggerHandler('toggled', [accordion]); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
65 accordion.triggerHandler('toggled', [target]); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
66 S(this).attr('aria-expanded','true'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
67 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
68 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
69 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
70 create: function($instance) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
71 var self = this, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
72 accordion = $instance, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
73 aunts = $('> .accordion-navigation', accordion), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
74 settings = accordion.data(self.attr_name(true) + '-init') || self.settings; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
75 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
76 aunts.children('a').attr('aria-expanded','false'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
77 aunts.has('.' + settings.content_class + '.' + settings.active_class).addClass(settings.active_class).children('a').attr('aria-expanded','true'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
78 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
79 if (settings.multi_expand) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
80 $instance.attr('aria-multiselectable','true'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
81 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
82 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
83 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
84 toggle : function(options) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
85 var options = typeof options !== 'undefined' ? options : {}; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
86 var selector = typeof options.selector !== 'undefined' ? options.selector : ''; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
87 var toggle_state = typeof options.toggle_state !== 'undefined' ? options.toggle_state : ''; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
88 var $accordion = typeof options.$accordion !== 'undefined' ? options.$accordion : this.S(this.scope).closest('[' + this.attr_name() + ']'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
89 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
90 var $items = $accordion.find('> dd' + selector + ', > li' + selector); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
91 if ( $items.length < 1 ) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
92 if ( window.console ) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
93 console.error('Selection not found.', selector); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
94 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
95 return false; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
96 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
97 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
98 var S = this.S; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
99 var active_class = this.settings.active_class; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
100 $items.each(function() { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
101 var $item = S(this); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
102 var is_active = $item.hasClass(active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
103 if ( ( is_active && toggle_state === 'close' ) || ( !is_active && toggle_state === 'open' ) || toggle_state === '' ) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
104 $item.find('> a').trigger('click.fndtn.accordion'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
105 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
106 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
107 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
108 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
109 open : function(options) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
110 var options = typeof options !== 'undefined' ? options : {}; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
111 options.toggle_state = 'open'; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
112 this.toggle(options); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
113 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
114 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
115 close : function(options) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
116 var options = typeof options !== 'undefined' ? options : {}; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
117 options.toggle_state = 'close'; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
118 this.toggle(options); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
119 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
120 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
121 off : function () {}, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
122 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
123 reflow : function () {} |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
124 }; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
125 }(jQuery, window, window.document)); |