This repository has been archived by the owner on Dec 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.wizard.breadcrumb.js
70 lines (54 loc) · 1.92 KB
/
jquery.wizard.breadcrumb.js
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
59
60
61
62
63
64
65
66
67
68
69
70
// Breadcrumb support for jQuery wizard Plugin. Should be included
// after the main plugin file.
// Authors: Tero Teelahti (http://teelahti.fi)
//
// http://github.com/teelahti/jquery.wizard
//
// Licensed under the MIT licenses:
// http://www.opensource.org/licenses/mit-license.php
(function( $ ){
var settings,
root,
targetData,
doc = $(document);
function pageCreated(event, data) {
var li = $("<li>").data(targetData, data.index).html(data.title);
if(!root.find("li").size()) {
li.addClass(ns("-active"));
}
root.append(li);
// Navigate when breadcrumb is clicked
li.click(function(e) {
// Create navigating context
var cssClass = ns("-active"),
ctx = {
currentPage: root.find("li." + cssClass).data(targetData),
targetPage : li.data(targetData)
};
doc.trigger(ns("/navigate"), ctx);
});
}
function navigating(event, data) {
var cssClass = ns("-active");
root.find("li").removeClass(cssClass).each(function(){
var page = $(this);
if(page.data(targetData) === data.targetPage) {
page.addClass(cssClass);
}
});
}
function ns(name) {
/// Prepend configured namespace to given name.
return settings.namespace + name;
}
$.fn.wizard.initializeBreadcrumb = function(options) {
settings = options;
root = $("<ul>");
$(settings.breadcrumb).append(root);
targetData = ns("-targetpage");
// subscribe to wizard page created event
doc.on(ns("/pagecreated"), pageCreated);
// subscribe to wizard navigating event
doc.on(ns("/navigated"), navigating);
};
})( jQuery );