bootstrap.breadcrumb.js
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* 显示一个路劲导航
* 作者:黄平
* 日期:2016-04-13
*/
(function($) {
$.fn.breadcrumb = function(options, param) {
var self = this;
if (typeof (options) == "string") {
var method = $.fn.breadcrumb.methods[options];
if (method){
return method.call(this, param);
}
}
return this.each(function() {
var opt = $.extend({}, $.fn.breadcrumb.defaults, options);
self.data("breadcrumb", opt);
_createBreadcrumb.call(self, opt);
});
};
function _createBreadcrumb(opt) {
var jq = this;
jq.empty();
jq.addClass("breadcrumb");
if (!opt.data || opt.data.length == 0) {
return;
}
var li;
$(opt.data).each(function(index, item) {
li = $("<li>").appendTo(jq);
if (index === opt.data.length - 1) {
li.addClass("active");
}
if (item[opt.hrefField]) {
li.append($("<a>").attr({
href : item[opt.hrefField]
}).html(item[opt.textField]));
} else {
li.html(item[opt.textField]);
}
});
}
$.fn.breadcrumb.methods = {
};
$.fn.breadcrumb.event = {
};
$.fn.breadcrumb.defaults = $.extend({}, $.fn.breadcrumb.event, {
textField : "text",
hrefField : "href",
data : []
});
})(jQuery);