-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.compactors-0.0.1.min.js
13 lines (11 loc) · 2.53 KB
/
jquery.compactors-0.0.1.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
jQuery compactors plugin
Copyright (c) 2010 Boomworks <http://boomworks.com.au/>
Author: Lindsay Evans
Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
(function(d){d.fn.compactors=function(i){var b=d.extend({},d.fn.compactors.defaults,i),c=this.selector;return this.each(function(h){var f=d(this),g=f.parent(b.parent_container_selector);g.attr("role","tablist").attr("aria-multiselectable","true");f.addClass(b.enabled_class_name).bind({open:function(e){e.stopPropagation();f.removeClass(b.closed_class_name).addClass(b.opened_class_name).find(b.content_selector).show(b.animation_speed).attr("aria-expanded","true")},close:function(e){e.stopPropagation();
f.removeClass(b.opened_class_name).addClass(b.closed_class_name).find(b.content_selector).hide(b.animation_speed).attr("aria-expanded","false")}}).filter(b.initially_open_selector).trigger("open").end().not(b.initially_open_selector).trigger("close").end().find(b.trigger_selector).attr("tabindex",0).attr("role","tab").attr("aria-controls","jq-compactor-content-"+h).bind({"click keypress":function(a){if(a.type==="click")f.trigger(f.hasClass(b.opened_class_name)?"close":"open");else if(a.type==="keypress"&&
(a.keyCode===39||a.keyCode===40)){a=f.next(c);a.length||(a=g.find(c).first());a.find(b.trigger_selector).focus()}else if(a.type==="keypress"&&(a.keyCode===37||a.keyCode===38)){a=f.prev(c);a.length||(a=g.find(c).last());a.find(b.trigger_selector).focus()}else if(a.type==="keypress"&&(a.keyCode===10||a.keyCode===13||a.charCode===32))f.trigger(f.hasClass(b.opened_class_name)?"close":"open")},mouseenter:function(){d(this).addClass(b.hover_class_name)},mouseleave:function(){d(this).removeClass(b.hover_class_name)}}).end().find(b.content_selector).bind({keypress:function(a){if(a.type===
"keypress"&&a.ctrlKey&&(a.keyCode===37||a.keyCode===38))d(this).parents(c).find(b.trigger_selector).focus();else if(a.type==="keypress"&&a.ctrlKey&&a.keyCode===33){a=d(this).parents(c).prev(c);a.length||(a=g.find(c).last());a.find(b.trigger_selector).focus();return false}else if(a.type==="keypress"&&a.ctrlKey&&a.keyCode===34){a=d(this).parents(c).next(c);a.length||(a=g.find(c).first());a.find(b.trigger_selector).focus();return false}}}).attr("role","tabpanel").attr("id","jq-compactor-content-"+h)})};
d.fn.compactors.defaults={parent_container_selector:"",trigger_selector:".trigger",content_selector:".content",initially_open_selector:"",enabled_class_name:"enabled",opened_class_name:"opened",closed_class_name:"closed",hover_class_name:"hover",animation_speed:null}})(jQuery);