Permalink
Browse files

BUGFIX Making HTML5 History support optional, so we can disable HTML4…

… hash change fallback
  • Loading branch information...
1 parent 1b7c335 commit 9c6cbf7012d2bec186dca0080216ae7925bda1f2 @chillu chillu committed Dec 14, 2011
@@ -31,7 +31,12 @@
var url = $(node).find('a:first').attr('href');
if(url && url != '#') {
- window.History.pushState({}, '', url);
+ if($(node).find('a:first').is(':internal')) url = $('base').attr('href') + url;
+ if(window.History.enabled) {
+ window.History.pushState({}, '', url);
+ } else {
+ window.location = url;
+ }
} else {
self.removeForm();
}
@@ -97,20 +97,25 @@
// Expand this, and collapse all other items
var item = this.getMenuItem();
item.select();
+
+ var url = this.attr('href');
+ if(this.is(':internal')) url = $('base').attr('href') + url;
var children = item.find('li');
if(children.length) {
children.first().find('a').click();
- } else {
+ } else if(window.History.enabled) {
// Active menu item is set based on X-Controller ajax header,
// which matches one class on the menu
- window.History.pushState({}, '', this.attr('href'));
+ window.History.pushState({}, '', url);
+ } else {
+ window.location = url;
}
}
});
});
-
+
// Internal Helper
$.expr[':'].internal = function(obj){return obj.href.match(/^mailto\:/) || (obj.hostname == location.hostname);};
$.expr[':'].external = function(obj){return !$(obj).is(':internal')};
@@ -99,9 +99,9 @@
var id = $(doc).find('meta[name=x-page-id]').attr('content'),
editLink = $(doc).find('meta[name=x-cms-edit-link]').attr('content'),
contentPanel = $('.cms-content');
- // TODO Remove hardcoding
if(id && contentPanel.find(':input[name=ID]').val() != id) {
- window.History.pushState({}, '', editLink);
+ // Ignore behaviour without history support (as we need ajax loading for the new form to load in the background)
+ if(window.History.enabled) window.History.pushState({}, '', editLink);
}
},
@@ -137,8 +137,10 @@
var firstLink = this.find('a[href]');
if(!firstLink) return;
- window.History.pushState({selector: '.cms-content-fields form:first'}, '', firstLink.attr('href'));
- return false;
+ if(window.History.enabled) {
+ window.History.pushState({selector: '.cms-content-fields form:first'}, '', firstLink.attr('href'));
+ return false;
+ }
}
});

0 comments on commit 9c6cbf7

Please sign in to comment.