mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 04:24:45 -04:00
Refactor location module.
This commit is contained in:
parent
2525ad8393
commit
6500b624f5
2 changed files with 11 additions and 11 deletions
|
@ -178,17 +178,17 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/event', 'core/notify',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onPopState(ev) {
|
||||||
if (history) {
|
|
||||||
window.onpopstate = function (ev) {
|
|
||||||
|
|
||||||
if (ev.state && ev.state.absHref) {
|
if (ev.state && ev.state.absHref) {
|
||||||
setLocation(ev.state.absHref, true);
|
setLocation(ev.state.absHref, true);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.onpopstate = history ? onPopState : null;
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
forceEncoding: forceEncoding,
|
forceEncoding: forceEncoding,
|
||||||
getDomain: getDomain,
|
getDomain: getDomain,
|
||||||
|
|
|
@ -86,7 +86,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
assert.lengthOfKeys(instance, 7);
|
assert.lengthOfKeys(instance, 7);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets window.onpopstate when history and fastBrowsing', function () {
|
it('sets window.onpopstate function when history and fastBrowsing', function () {
|
||||||
|
|
||||||
this.xModernizr.history = true;
|
this.xModernizr.history = true;
|
||||||
this.xSettings.view.fastBrowsing = true;
|
this.xSettings.view.fastBrowsing = true;
|
||||||
|
@ -96,7 +96,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
assert.isFunction(window.onpopstate);
|
assert.isFunction(window.onpopstate);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not set window.onpopstate when not history and fastBrowsing', function () {
|
it('sets window.onpopstate to null when not history and fastBrowsing', function () {
|
||||||
|
|
||||||
this.xModernizr.history = false;
|
this.xModernizr.history = false;
|
||||||
this.xSettings.view.fastBrowsing = true;
|
this.xSettings.view.fastBrowsing = true;
|
||||||
|
@ -106,7 +106,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
assert.isNull(window.onpopstate);
|
assert.isNull(window.onpopstate);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not set window.onpopstate when history and not fastBrowsing', function () {
|
it('sets window.onpopstate to null when history and not fastBrowsing', function () {
|
||||||
|
|
||||||
this.xModernizr.history = true;
|
this.xModernizr.history = true;
|
||||||
this.xSettings.view.fastBrowsing = false;
|
this.xSettings.view.fastBrowsing = false;
|
||||||
|
@ -116,7 +116,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
assert.isNull(window.onpopstate);
|
assert.isNull(window.onpopstate);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not set window.onpopstate when not history and not fastBrowsing', function () {
|
it('sets window.onpopstate to null when not history and not fastBrowsing', function () {
|
||||||
|
|
||||||
this.xModernizr.history = false;
|
this.xModernizr.history = false;
|
||||||
this.xSettings.view.fastBrowsing = false;
|
this.xSettings.view.fastBrowsing = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue