mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
History API not working properly on Boxee box browser (old Webkit) problem similar to the one on Android < 4
85 lines
3.2 KiB
JavaScript
85 lines
3.2 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* !!! This is an undocumented "private" service !!!
|
|
*
|
|
* @name ng.$sniffer
|
|
* @requires $window
|
|
* @requires $document
|
|
*
|
|
* @property {boolean} history Does the browser support html5 history api ?
|
|
* @property {boolean} hashchange Does the browser support hashchange event ?
|
|
* @property {boolean} transitions Does the browser support CSS transition events ?
|
|
* @property {boolean} animations Does the browser support CSS animation events ?
|
|
*
|
|
* @description
|
|
* This is very simple implementation of testing browser's features.
|
|
*/
|
|
function $SnifferProvider() {
|
|
this.$get = ['$window', '$document', function($window, $document) {
|
|
var eventSupport = {},
|
|
android = int((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]),
|
|
boxee = /Boxee/i.test(($window.navigator || {}).userAgent),
|
|
document = $document[0] || {},
|
|
vendorPrefix,
|
|
vendorRegex = /^(Moz|webkit|O|ms)(?=[A-Z])/,
|
|
bodyStyle = document.body && document.body.style,
|
|
transitions = false,
|
|
animations = false,
|
|
match;
|
|
|
|
if (bodyStyle) {
|
|
for(var prop in bodyStyle) {
|
|
if(match = vendorRegex.exec(prop)) {
|
|
vendorPrefix = match[0];
|
|
vendorPrefix = vendorPrefix.substr(0, 1).toUpperCase() + vendorPrefix.substr(1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(!vendorPrefix) {
|
|
vendorPrefix = ('WebkitOpacity' in bodyStyle) && 'webkit';
|
|
}
|
|
|
|
transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle));
|
|
animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle));
|
|
|
|
if (android && (!transitions||!animations)) {
|
|
transitions = isString(document.body.style.webkitTransition);
|
|
animations = isString(document.body.style.webkitAnimation);
|
|
}
|
|
}
|
|
|
|
|
|
return {
|
|
// Android has history.pushState, but it does not update location correctly
|
|
// so let's not use the history API at all.
|
|
// http://code.google.com/p/android/issues/detail?id=17471
|
|
// https://github.com/angular/angular.js/issues/904
|
|
|
|
// older webit browser (533.9) on Boxee box has exactly the same problem as Android has
|
|
// so let's not use the history API also
|
|
history: !!($window.history && $window.history.pushState && !(android < 4) && !boxee),
|
|
hashchange: 'onhashchange' in $window &&
|
|
// IE8 compatible mode lies
|
|
(!document.documentMode || document.documentMode > 7),
|
|
hasEvent: function(event) {
|
|
// IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have
|
|
// it. In particular the event is not fired when backspace or delete key are pressed or
|
|
// when cut operation is performed.
|
|
if (event == 'input' && msie == 9) return false;
|
|
|
|
if (isUndefined(eventSupport[event])) {
|
|
var divElm = document.createElement('div');
|
|
eventSupport[event] = 'on' + event in divElm;
|
|
}
|
|
|
|
return eventSupport[event];
|
|
},
|
|
csp: document.securityPolicy ? document.securityPolicy.isActive : false,
|
|
vendorPrefix: vendorPrefix,
|
|
transitions : transitions,
|
|
animations : animations
|
|
};
|
|
}];
|
|
}
|