mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-28 15:28:15 +00:00
Fix hashchange event on IE8 compatibility mode
Stupid IE8 in compatibility mode or in IE7 mode returns true for `('onhashchange' in window)`, but does not support hashchange event.
Closes #353
This commit is contained in:
parent
aa64d37a23
commit
50076b571d
3 changed files with 46 additions and 3 deletions
18
regression/issue-353.html
Normal file
18
regression/issue-353.html
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns:ng="http://angularjs.org">
|
||||||
|
<script type="text/javascript" src="../build/angular.js" ng:autobind></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function Cntl($route) {
|
||||||
|
$route.when('/item1', {});
|
||||||
|
$route.when('/item2', {});
|
||||||
|
$route.onChange(function() {
|
||||||
|
alert('change');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Cntl.$inject = ['$route'];
|
||||||
|
</script>
|
||||||
|
<body ng:controller="Cntl">
|
||||||
|
<a href="#/item1">test</a>
|
||||||
|
<a href="#/item2">test</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -249,7 +249,9 @@ function Browser(window, document, body, XHR, $log) {
|
||||||
* @return {function()} Returns the registered listener fn - handy if the fn is anonymous.
|
* @return {function()} Returns the registered listener fn - handy if the fn is anonymous.
|
||||||
*/
|
*/
|
||||||
self.onHashChange = function(listener) {
|
self.onHashChange = function(listener) {
|
||||||
if ('onhashchange' in window) {
|
// IE8 comp mode returns true, but doesn't support hashchange event
|
||||||
|
var dm = window.document.documentMode;
|
||||||
|
if ('onhashchange' in window && (isUndefined(dm) || dm >= 8)) {
|
||||||
jqLite(window).bind('hashchange', listener);
|
jqLite(window).bind('hashchange', listener);
|
||||||
} else {
|
} else {
|
||||||
var lastBrowserUrl = self.getUrl();
|
var lastBrowserUrl = self.getUrl();
|
||||||
|
|
|
||||||
|
|
@ -418,7 +418,10 @@ describe('browser', function(){
|
||||||
it('should use $browser poller to detect url changes when onhashchange event is unsupported',
|
it('should use $browser poller to detect url changes when onhashchange event is unsupported',
|
||||||
function() {
|
function() {
|
||||||
|
|
||||||
fakeWindow = {location: {href:"http://server"}};
|
fakeWindow = {
|
||||||
|
location: {href:"http://server"},
|
||||||
|
document: {}
|
||||||
|
};
|
||||||
|
|
||||||
browser = new Browser(fakeWindow, {}, {});
|
browser = new Browser(fakeWindow, {}, {});
|
||||||
|
|
||||||
|
|
@ -455,7 +458,8 @@ describe('browser', function(){
|
||||||
onHashChngListener = listener;
|
onHashChngListener = listener;
|
||||||
},
|
},
|
||||||
removeEventListener: angular.noop,
|
removeEventListener: angular.noop,
|
||||||
detachEvent: angular.noop
|
detachEvent: angular.noop,
|
||||||
|
document: {}
|
||||||
};
|
};
|
||||||
fakeWindow.onhashchange = true;
|
fakeWindow.onhashchange = true;
|
||||||
|
|
||||||
|
|
@ -479,5 +483,24 @@ describe('browser', function(){
|
||||||
jqLite(fakeWindow).dealoc();
|
jqLite(fakeWindow).dealoc();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// asynchronous test
|
||||||
|
it('should fire onHashChange when location.hash change', function() {
|
||||||
|
var callback = jasmine.createSpy('onHashChange');
|
||||||
|
browser = new Browser(window, {}, {});
|
||||||
|
browser.onHashChange(callback);
|
||||||
|
|
||||||
|
window.location.hash = 'new-hash';
|
||||||
|
browser.startPoller(100, setTimeout);
|
||||||
|
|
||||||
|
waitsFor(function() {
|
||||||
|
return callback.callCount;
|
||||||
|
}, 'onHashChange callback to be called', 1000);
|
||||||
|
|
||||||
|
runs(function() {
|
||||||
|
if (!jQuery) jqLite(window).dealoc();
|
||||||
|
window.location.hash = '';
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue