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.history.js
59 lines (48 loc) · 1.8 KB
/
jquery.wizard.history.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
// History navigation (back/forward) support for jQuery wizard Plugin.
// Should be included after the main plugin file.
//
// Takes a dependency to history.js plugin found at:
// https://github.com/balupton/history.js
//
//
// 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 History,
settings,
doc = $(document);
function navigating(event, data) {
var page = data.targetPage + 1;
// TODO: Find real title
History.pushState(data, "Page " + page, "?page=" + page);
}
function historyPop() {
console.log("HistoryPop");
// Note: We are using History.getState() instead of event.state
var state = History.getState();
// History.log(State.data, State.title, State.url);
doc.trigger(ns("/navigate"), state.data);
}
function ns(name) {
/// Prepend configured namespace to given name.
return settings.namespace + name;
}
$.fn.wizard.initializeHistory = function(options) {
settings = options;
// Capital H on purpose
History = window.History;
if(!History) {
throw new Error("History.js is not included. jquery.wizard.history.js takes a dependency to jquery.history.js");
}
// Bind to StateChange Event.
// Note: We are using statechange instead of popstate.
History.Adapter.bind(window, 'statechange', historyPop);
// subscribe to wizard navigating event to be able to
// store navigation to history stack.
doc.on(ns("/navigated"), navigating);
};
})( jQuery );