aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVojta Jina2011-06-23 20:01:25 +0200
committerVojta Jina2011-09-08 20:37:28 +0200
commitd0f459c56fdb3dae692c359a2915acb2fd063c79 (patch)
tree302a6a0aea894a9b496c950d106214af01e4e58a /src
parentcbedf556416522a0a4b08abd3101e856e59c6a6a (diff)
downloadangular.js-d0f459c56fdb3dae692c359a2915acb2fd063c79.tar.bz2
feat($sniffer): basic implementation of browser feature testing
This only extracts our 'hashchange' event and html5 history api detection from $browser. Closes #400
Diffstat (limited to 'src')
-rw-r--r--src/AngularPublic.js7
-rw-r--r--src/angular-bootstrap.js1
-rw-r--r--src/service/sniffer.js24
3 files changed, 28 insertions, 4 deletions
diff --git a/src/AngularPublic.js b/src/AngularPublic.js
index f63948d8..8683b379 100644
--- a/src/AngularPublic.js
+++ b/src/AngularPublic.js
@@ -2,15 +2,14 @@
var browserSingleton;
-angularService('$browser', function($log){
+angularService('$browser', function($log, $sniffer) {
if (!browserSingleton) {
- // TODO(vojta): inject $sniffer service when implemented
browserSingleton = new Browser(window, jqLite(window.document), jqLite(window.document.body),
- XHR, $log, {});
+ XHR, $log, $sniffer);
browserSingleton.bind();
}
return browserSingleton;
-}, {$inject:['$log']});
+}, {$inject: ['$log', '$sniffer']});
extend(angular, {
diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js
index f88973e0..9f08ff94 100644
--- a/src/angular-bootstrap.js
+++ b/src/angular-bootstrap.js
@@ -115,6 +115,7 @@
'service/resource.js',
'service/route.js',
'service/routeParams.js',
+ 'service/sniffer.js',
'service/window.js',
'service/xhr.bulk.js',
'service/xhr.cache.js',
diff --git a/src/service/sniffer.js b/src/service/sniffer.js
new file mode 100644
index 00000000..c71a9bde
--- /dev/null
+++ b/src/service/sniffer.js
@@ -0,0 +1,24 @@
+'use strict';
+
+/**
+ * @workInProgress
+ * @ngdoc service
+ * @name angular.service.$sniffer
+ * @requires $window
+ *
+ * @property {boolean} history Does the browser support html5 history api ?
+ * @property {boolean} hashchange Does the browser support hashchange event ?
+ *
+ * @description
+ * This is very simple implementation of testing browser's features.
+ */
+angularServiceInject('$sniffer', function($window) {
+ if ($window.Modernizr) return $window.Modernizr;
+
+ return {
+ history: !!($window.history && $window.history.pushState),
+ hashchange: 'onhashchange' in $window &&
+ // IE8 compatible mode lies
+ (!$window.document.documentMode || $window.document.documentMode > 7)
+ };
+}, ['$window']);