Skip to content

Commit badfc40

Browse files
committed
Merge branch 'project/architizer' of https://github.com/typecode/typecode-js into project/architizer
2 parents e28af7e + ac6e448 commit badfc40

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

lib/Merlin2.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ define(['jquery', 'NIseed'], function($) {
278278
get_n_step_renders: function(){
279279
return internal.n_step_renders;
280280
},
281+
get_step: function(name){
282+
if(internal.steps[name]){
283+
return internal.steps[name];
284+
}
285+
return null;
286+
},
281287
destroy: function() {
282288
$.each(internal.controls, function(k, control) {
283289
if (handlers[k]) {
@@ -327,6 +333,7 @@ define(['jquery', 'NIseed'], function($) {
327333
this.get_val = fn.get_val;
328334
this.get_dom = fn.get_dom;
329335
this.get_name = fn.get_name;
336+
this.get_step = fn.get_step;
330337
this.get_n_step_renders = fn.get_n_step_renders;
331338
this.destroy = fn.destroy;
332339

lib/PushstateHelper.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ define(['jquery'], function($) {
3535

3636
fn = {
3737
init: function() {
38-
$(document).on('click', '.js-use-pushstate', handlers.doc_click);
39-
$(window).on('popstate', handlers.popstate).on('pushstate', handlers.pushstate);
38+
$(document).on('click', '.js-use-pushstate, .js-simulate-pushstate', handlers.doc_click);
39+
$(window).on('popstate', handlers.popstate).on('pushstate', handlers.pushstate).on('simulate-pushstate', handlers.simulate_pushstate);
4040
o.app.events.on('app.featuresInitialized', handlers.features_initialized);
41-
fn.statechange(window.location);
41+
if(o.use_hash){
42+
fn.statechange(window.location.hash);
43+
} else {
44+
fn.statechange(window.location.pathname);
45+
}
4246
},
43-
statechange: function(href){
47+
statechange: function(pathname){
4448
var i, path_components, position;
4549

46-
if(o.use_hash && href.hash){
47-
path_components = PushstateHelper.get_path_components(href.hash);
48-
} else {
49-
path_components = PushstateHelper.get_path_components(href.pathname);
50-
}
50+
path_components = PushstateHelper.get_path_components(pathname);
5151

5252
// push the state change to Google Analytics
5353
if(window._gaq){
54-
_gaq.push(['_trackPageview', href]);
54+
_gaq.push(['_trackPageview', pathname]);
5555
}
5656

5757
o.app.events.trigger('navigationEvent:Pushstate', {
58-
location: href,
58+
path: pathname,
5959
components: path_components
6060
});
6161
},
@@ -70,31 +70,42 @@ define(['jquery'], function($) {
7070
//fn.statechange(window.location);
7171
},
7272
doc_click: function(e, d) {
73+
var _href;
7374
e.preventDefault();
74-
if(o.use_hash){
75-
window.location.hash = $(this).attr('HREF');
75+
_href = $(this).attr('HREF');
76+
if(!$(this).hasClass('js-simulate-pushstate')){
77+
if(o.use_hash){
78+
window.location.hash = _href;
79+
fn.statechange(window.location.hash);
80+
} else {
81+
history.pushState(null, null, _href);
82+
fn.statechange(window.location.pathname);
83+
}
84+
7685
} else {
77-
history.pushState(null, null, $(this).attr('HREF'));
86+
fn.statechange(_href);
7887
}
79-
fn.statechange(window.location);
8088
},
8189
popstate: function(e, d) {
8290
fn.statechange(window.location);
8391
},
8492
pushstate: function(e, d) {
8593
if(o.use_hash){
86-
if(window.location.hash == d.pathname){
87-
return;
94+
if(window.location.hash != d.pathname){
95+
window.location.hash = d.pathname;
8896
}
89-
window.location.hash = d.pathname;
9097
} else {
91-
if(window.location.pathname == d.pathname){
92-
return;
98+
if(window.location.pathname != d.pathname){
99+
history.pushState(null, null, d.pathname);
93100
}
94-
history.pushState(null, null, d.pathname);
95101
}
96102
if(!d.prevent_propagation){
97-
fn.statechange(d);
103+
fn.statechange(d.pathname);
104+
}
105+
},
106+
simulate_pushstate: function(e, d) {
107+
if(!d.prevent_propagation){
108+
fn.statechange(d.pathname);
98109
}
99110
}
100111
};

0 commit comments

Comments
 (0)