what does the $sniffer do?

3,436 views
Skip to first unread message

z...@caudate.me

unread,
Nov 3, 2012, 8:50:00 PM11/3/12
to ang...@googlegroups.com
I was looking at the angular source code and found a sniffer service.

eg.

function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {

  var listener = function() {
    var value = trim(element.val());

    if (ctrl.$viewValue !== value) {
      scope.$apply(function() {
        ctrl.$setViewValue(value);
      });
    }
  };

what does it do and is it documented anywhere?

Peter Bacon Darwin

unread,
Nov 4, 2012, 3:58:53 PM11/4/12
to ang...@googlegroups.com
If you can't find $sniffer then search the src for $SnifferProvider.  You'll find it under src/ng/sniffer.js!!

You can see it only provides a handful of members: history, hashchange, hasEvent and csp.

Pete

function $SnifferProvider() {
  this.$get = ['$window', '$document', function($window, $document) {
    var eventSupport = {},
        android = int((/android (\d+)/.exec(lowercase($window.navigator.userAgent)) || [])[1]),
        document = $document[0];

    return {
      // Android has history.pushState, but it does not update location correctly
      // so let's not use the history API at all.
      history: !!($window.history && $window.history.pushState && !(android < 4)),
      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
    };
  }];
}

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Reply all
Reply to author
Forward
0 new messages