1(function ($) { 2 $.fn.collapsible = function(options, methodParam) { 3 var defaults = { 4 accordion: undefined, 5 onOpen: undefined, 6 onClose: undefined 7 }; 8 9 var methodName = options; 10 options = $.extend(defaults, options); 11 12 13 return this.each(function() { 14 15 var $this = $(this); 16 17 var $panel_headers = $(this).find('> li > .collapsible-header'); 18 19 var collapsible_type = $this.data("collapsible"); 20 21 /**************** 22 Helper Functions 23 ****************/ 24 25 // Accordion Open 26 function accordionOpen(object) { 27 $panel_headers = $this.find('> li > .collapsible-header'); 28 if (object.hasClass('active')) { 29 object.parent().addClass('active'); 30 } 31 else { 32 object.parent().removeClass('active'); 33 } 34 if (object.parent().hasClass('active')){ 35 object.siblings('.collapsible-body').stop(true,false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}}); 36 } 37 else{ 38 object.siblings('.collapsible-body').stop(true,false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}}); 39 } 40 41 $panel_headers.not(object).removeClass('active').parent().removeClass('active'); 42 43 // Close previously open accordion elements. 44 $panel_headers.not(object).parent().children('.collapsible-body').stop(true,false).each(function() { 45 if ($(this).is(':visible')) { 46 $(this).slideUp({ 47 duration: 350, 48 easing: "easeOutQuart", 49 queue: false, 50 complete: 51 function() { 52 $(this).css('height', ''); 53 execCallbacks($(this).siblings('.collapsible-header')); 54 } 55 }); 56 } 57 }); 58 } 59 60 // Expandable Open 61 function expandableOpen(object) { 62 if (object.hasClass('active')) { 63 object.parent().addClass('active'); 64 } 65 else { 66 object.parent().removeClass('active'); 67 } 68 if (object.parent().hasClass('active')){ 69 object.siblings('.collapsible-body').stop(true,false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}}); 70 } 71 else { 72 object.siblings('.collapsible-body').stop(true,false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}}); 73 } 74 } 75 76 // Open collapsible. object: .collapsible-header 77 function collapsibleOpen(object, noToggle) { 78 if (!noToggle) { 79 object.toggleClass('active'); 80 } 81 82 if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { // Handle Accordion 83 accordionOpen(object); 84 } else { // Handle Expandables 85 expandableOpen(object); 86 } 87 88 execCallbacks(object); 89 } 90 91 // Handle callbacks 92 function execCallbacks(object) { 93 if (object.hasClass('active')) { 94 if (typeof(options.onOpen) === "function") { 95 options.onOpen.call(this, object.parent()); 96 } 97 } else { 98 if (typeof(options.onClose) === "function") { 99 options.onClose.call(this, object.parent()); 100 } 101 } 102 } 103 104 /** 105 * Check if object is children of panel header 106 * @param {Object} object Jquery object 107 * @return {Boolean} true if it is children 108 */ 109 function isChildrenOfPanelHeader(object) { 110 111 var panelHeader = getPanelHeader(object); 112 113 return panelHeader.length > 0; 114 } 115 116 /** 117 * Get panel header from a children element 118 * @param {Object} object Jquery object 119 * @return {Object} panel header object 120 */ 121 function getPanelHeader(object) { 122 123 return object.closest('li > .collapsible-header'); 124 } 125 126 127 // Turn off any existing event handlers 128 function removeEventHandlers() { 129 $this.off('click.collapse', '> li > .collapsible-header'); 130 } 131 132 /***** End Helper Functions *****/ 133 134 135 // Methods 136 if (methodName === 'destroy') { 137 removeEventHandlers(); 138 return; 139 } else if (methodParam >= 0 && 140 methodParam < $panel_headers.length) { 141 var $curr_header = $panel_headers.eq(methodParam); 142 if ($curr_header.length && 143 (methodName === 'open' || 144 (methodName === 'close' && 145 $curr_header.hasClass('active')))) { 146 collapsibleOpen($curr_header); 147 } 148 return; 149 } 150 151 152 removeEventHandlers(); 153 154 155 // Add click handler to only direct collapsible header children 156 $this.on('click.collapse', '> li > .collapsible-header', function(e) { 157 var element = $(e.target); 158 159 if (isChildrenOfPanelHeader(element)) { 160 element = getPanelHeader(element); 161 } 162 163 collapsibleOpen(element); 164 }); 165 166 167 // Open first active 168 if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { // Handle Accordion 169 collapsibleOpen($panel_headers.filter('.active').first(), true); 170 171 } else { // Handle Expandables 172 $panel_headers.filter('.active').each(function() { 173 collapsibleOpen($(this), true); 174 }); 175 } 176 177 }); 178 }; 179 180 $(document).ready(function(){ 181 $('.collapsible').collapsible(); 182 }); 183}( jQuery ));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.