1(function ($) { 2 3 $.fn.mgaccordion = function (options) { 4 5 var defaults = { 6 theme: "flat", 7 leaveOpen: false 8 }; 9 10 var settings = $.extend({}, defaults, options); 11 12 var openIcon, closeIcon; 13 14 this.initialize = function () { 15 /** 16 * silently exit if passed element is not a list 17 */ 18 if (!this.is('ul') && !this.is('ol')) { 19 console.log('Element is not a list'); 20 return; 21 } 22 this.addClass('mg-accordion'); 23 var theme = settings.theme; 24 var leaveOpen = settings.leaveOpen; 25 if (theme === 'tree') { 26 this.addClass('mg-tree'); 27 } else { 28 this.addClass('mg-flat'); 29 } 30 $.each(this.find('li'), function () { 31 var $this = $(this); 32 if ($this.children('ul').length) { 33 $this.addClass('dropdown') 34 .children('a') 35 .bind('click', function (e) { 36 e.preventDefault(); 37 if (leaveOpen === false) { 38 closeOther($(this)); 39 } 40 $(this).siblings('ul.submenu').slideToggle(function () { 41 $(this).toggleClass('closed', $(this).is(':visible')); 42 }); 43 updateIcons($(this)); 44 } 45 ); 46 $this.find('ul').addClass('submenu'); 47 48 } 49 }); 50 51 return this; 52 53 }; 54 55 var setIcons = function () { 56 if (settings.theme === 'tree') { 57 openIcon = '<span class="toggler"><i class="fa fa-plus-circle"></i> </span>'; 58 closeIcon = '<span class="toggler"><i class="fa fa-minus-circle"></i> </span>'; 59 } else if (settings.theme === 'flat') { 60 openIcon = '<span class="toggler"><i class="fa fa-arrow-circle-down"></i> </span>'; 61 closeIcon = '<span class="toggler"> <i class="fa fa-arrow-circle-up"></i></span>'; 62 } 63 } 64 65 var closeOther = function (obj) { 66 setIcons(); 67 var items = obj.parent().siblings().find('ul.submenu'); 68 if (settings.theme === 'flat') { 69 items.each(function () { 70 if ($(this).hasClass('closed')) { 71 $(this).slideUp('slow') 72 .parent() 73 .find('a') 74 .removeClass('openItem'); 75 } 76 }); 77 } else { 78 items.each(function () { 79 if ($(this).hasClass('closed')) { 80 $(this).slideUp('slow') 81 .parent() 82 .find('span.toggler') 83 .replaceWith(openIcon); 84 } 85 }); 86 } 87 } 88 89 var updateIcons = function (obj) { 90 if (settings.theme === 'flat') { 91 if (obj.siblings('.submenu').hasClass('closed')) { 92 obj.removeClass('openItem'); 93 } else { 94 obj.addClass('openItem'); 95 } 96 } else { 97 if (obj.siblings('.submenu').hasClass('closed')) { 98 obj.find('span.toggler').replaceWith(openIcon); 99 } else { 100 obj.find('span.toggler').replaceWith(closeIcon); 101 } 102 } 103 } 104 105 return this.initialize(); 106 107 }; 108 109}(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.