Skip to content

add ability to disable html history functionality in the browser service #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function Browser(window, document, $log, $sniffer) {
history = window.history,
setTimeout = window.setTimeout,
clearTimeout = window.clearTimeout,
pendingDeferIds = {};
pendingDeferIds = {},
useHtml5HistoryMode = false;

self.isMock = false;

Expand Down Expand Up @@ -151,7 +152,7 @@ function Browser(window, document, $log, $sniffer) {
if (url) {
if (lastBrowserUrl == url) return;
lastBrowserUrl = url;
if ($sniffer.history) {
if ($sniffer.history && useHtml5HistoryMode) {
if (replace) history.replaceState(null, '', url);
else {
history.pushState(null, '', url);
Expand Down Expand Up @@ -212,7 +213,7 @@ function Browser(window, document, $log, $sniffer) {
// changed by push/replaceState

// html5 history api - popstate event
if ($sniffer.history) jqLite(window).bind('popstate', fireUrlChange);
if ($sniffer.history && useHtml5HistoryMode) jqLite(window).bind('popstate', fireUrlChange);
// hashchange event
if ($sniffer.hashchange) jqLite(window).bind('hashchange', fireUrlChange);
// polling
Expand Down Expand Up @@ -352,6 +353,15 @@ function Browser(window, document, $log, $sniffer) {
return false;
};

self.html5HistoryMode = function(mode) {
if (isDefined(mode)) {
useHtml5HistoryMode = mode;
return this;
} else {
return useHtml5HistoryMode;
}
};

}

function $BrowserProvider(){
Expand Down
3 changes: 3 additions & 0 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ function $LocationProvider(){
initUrlParts = matchUrl(initUrl),
appBaseUrl;

// Apply the html5Mode setting to the $browser service
$browser.html5HistoryMode(html5Mode);

if (html5Mode) {
basePath = $browser.baseHref() || '/';
pathPrefix = pathPrefixFromBase(basePath);
Expand Down