1/*----------------------------------------------------------------------*/ 2/* wl_Breadcrumb v 1.0 by revaxarts.com 3/* description: Makes and handles a Breadcrumb navigation 4/* dependency: 5/*----------------------------------------------------------------------*/ 6 7 8$.fn.wl_Breadcrumb = function (method) { 9 10 var args = arguments; 11 return this.each(function () { 12 13 var $this = $(this), 14 $li = $this.find('li'); 15 $a = $this.find('a'); 16 17 18 if ($.fn.wl_Breadcrumb.methods[method]) { 19 return $.fn.wl_Breadcrumb.methods[method].apply(this, Array.prototype.slice.call(args, 1)); 20 } else if (typeof method === 'object' || !method) { 21 if ($this.data('wl_Breadcrumb')) { 22 var opts = $.extend({}, $this.data('wl_Breadcrumb'), method); 23 } else { 24 var opts = $.extend({}, $.fn.wl_Breadcrumb.defaults, method, $this.data()); 25 } 26 } else { 27 $.error('Method "' + method + '" does not exist'); 28 } 29 30 //get the current field or use the first if not set 31 var $current = $this.find('a.active').eq(0); 32 if (!$current.length) $current = $a.eq(opts.start); 33 34 35 if (!$this.data('wl_Breadcrumb')) { 36 37 $this.data('wl_Breadcrumb', {}); 38 39 //each anchor 40 $a.each(function (i) { 41 var _this = $(this); 42 //save the id 43 _this.data('id', i); 44 45 //prepend numbers if set 46 if (opts.numbers) _this.text((i + 1) + '. ' + _this.text()); 47 }); 48 49 //each listelement 50 $li.each(function (i) { 51 var _this = $(this); 52 53 //if has a class (must be an icon) 54 if (_this.attr('class')) { 55 //innerwrap the anchor to attach the icon 56 $a.eq(i).wrapInner('<span class="' + _this.attr('class') + '"/>'); 57 //remove the class from the list element 58 _this.removeAttr('class'); 59 } 60 }); 61 62 //add a 'last' class to the last element for IE :( 63 if($.browser.msie)$li.filter(':last').addClass('last'); 64 65 //Bind the click handler 66 $this.delegate('a', 'click.wl_Breadcrumb', function () { 67 var opts = $this.data('wl_Breadcrumb') || opts; 68 69 //if disabled stop 70 if (opts.disabled) return false; 71 var _this = $(this); 72 73 //if not allownextonly or data is current+1 or current-x 74 if (!opts.allownextonly || _this.data('id') - $this.find('a.active').data('id') <= 1) { 75 76 //activate and trigger callback 77 $.fn.wl_Breadcrumb.methods.activate.call($this[0], _this); 78 opts.onChange.call($this[0], _this, _this.data('id')); 79 } 80 return false; 81 }); 82 83 //connected breadcrumb 84 if (opts.connect) { 85 var $connect = $('#' + opts.connect), 86 $pages = $connect.children(); 87 88 //bind event to all 'next' class elements 89 $connect.find('.next').bind('click.wl_Breadcrumb', function () { 90 $this.wl_Breadcrumb('next'); 91 return false; 92 }); 93 //bind event to all 'prev' class elements 94 $connect.find('.prev').bind('click.wl_Breadcrumb', function () { 95 $this.wl_Breadcrumb('prev'); 96 return false; 97 }); 98 99 //hide all and show the starting one 100 $pages.hide().eq(opts.start).show(); 101 102 } 103 104 //disable if set 105 if (opts.disabled) { 106 $this.wl_Breadcrumb('disable'); 107 } 108 } else { 109 110 } 111 112 if (opts) $.extend($this.data('wl_Breadcrumb'), opts); 113 114 //activate the current part 115 $.fn.wl_Breadcrumb.methods.activate.call(this, $current); 116 }); 117 118}; 119 120$.fn.wl_Breadcrumb.defaults = { 121 start: 0, 122 numbers: false, 123 allownextonly: false, 124 disabled: false, 125 connect: null, 126 onChange: function () {} 127}; 128$.fn.wl_Breadcrumb.version = '1.0'; 129 130 131$.fn.wl_Breadcrumb.methods = { 132 activate: function (element) { 133 var $this = $(this); 134 135 //element is a number so we mean the id 136 if (typeof element === 'number') { 137 element = $this.find('li').eq(element).find('a'); 138 element.trigger('click.wl_Breadcrumb'); 139 return false; 140 } 141 var _opts = $this.data('wl_Breadcrumb'); 142 //remove classes 143 $this.find('a').removeClass('active previous'); 144 //find all previous tabs and add a class 145 element.parent().prevAll().find('a').addClass('previous'); 146 //add and active class to the current tab 147 element.addClass('active'); 148 //connected breadcrumb 149 if (_opts.connect) { 150 var $connect = $('#' + _opts.connect), 151 $pages = $connect.children(); 152 //hide all and show selected 153 $pages.hide().eq(element.data('id')).show(); 154 } 155 }, 156 disable: function () { 157 var $this = $(this); 158 //disable and add class disable 159 $this.wl_Breadcrumb('set', 'disabled', true); 160 $this.addClass('disabled'); 161 }, 162 enable: function () { 163 var $this = $(this); 164 //enable and remove class disable 165 $this.wl_Breadcrumb('set', 'disabled', false); 166 $this.removeClass('disabled'); 167 }, 168 next: function () { 169 var $this = $(this); 170 //click next tab 171 $this.find('a.active').parent().next().find('a').trigger('click.wl_Breadcrumb'); 172 }, 173 prev: function () { 174 var $this = $(this); 175 //click prev tab 176 $this.find('a.active').parent().prev().find('a').trigger('click.wl_Breadcrumb'); 177 }, 178 set: function () { 179 var $this = $(this), 180 options = {}; 181 if (typeof arguments[0] === 'object') { 182 options = arguments[0]; 183 } else if (arguments[0] && arguments[1] !== undefined) { 184 options[arguments[0]] = arguments[1]; 185 } 186 $.each(options, function (key, value) { 187 if ($.fn.wl_Breadcrumb.defaults[key] !== undefined || $.fn.wl_Breadcrumb.defaults[key] == null) { 188 $this.data('wl_Breadcrumb')[key] = value; 189 } else { 190 $.error('Key "' + key + '" is not defined'); 191 } 192 }); 193 194 } 195};
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.