github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/vue-1.0.24/src/util/env.js (about)

     1  /* global MutationObserver */
     2  
     3  // can we use __proto__?
     4  export const hasProto = '__proto__' in {}
     5  
     6  // Browser environment sniffing
     7  export const inBrowser =
     8    typeof window !== 'undefined' &&
     9    Object.prototype.toString.call(window) !== '[object Object]'
    10  
    11  // detect devtools
    12  export const devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
    13  
    14  // UA sniffing for working around browser-specific quirks
    15  const UA = inBrowser && window.navigator.userAgent.toLowerCase()
    16  export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
    17  export const isAndroid = UA && UA.indexOf('android') > 0
    18  export const isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA)
    19  export const isWechat = UA && UA.indexOf('micromessenger') > 0
    20  
    21  let transitionProp
    22  let transitionEndEvent
    23  let animationProp
    24  let animationEndEvent
    25  
    26  // Transition property/event sniffing
    27  if (inBrowser && !isIE9) {
    28    const isWebkitTrans =
    29      window.ontransitionend === undefined &&
    30      window.onwebkittransitionend !== undefined
    31    const isWebkitAnim =
    32      window.onanimationend === undefined &&
    33      window.onwebkitanimationend !== undefined
    34    transitionProp = isWebkitTrans
    35      ? 'WebkitTransition'
    36      : 'transition'
    37    transitionEndEvent = isWebkitTrans
    38      ? 'webkitTransitionEnd'
    39      : 'transitionend'
    40    animationProp = isWebkitAnim
    41      ? 'WebkitAnimation'
    42      : 'animation'
    43    animationEndEvent = isWebkitAnim
    44      ? 'webkitAnimationEnd'
    45      : 'animationend'
    46  }
    47  
    48  export {
    49    transitionProp,
    50    transitionEndEvent,
    51    animationProp,
    52    animationEndEvent
    53  }
    54  
    55  /**
    56   * Defer a task to execute it asynchronously. Ideally this
    57   * should be executed as a microtask, so we leverage
    58   * MutationObserver if it's available, and fallback to
    59   * setTimeout(0).
    60   *
    61   * @param {Function} cb
    62   * @param {Object} ctx
    63   */
    64  
    65  export const nextTick = (function () {
    66    var callbacks = []
    67    var pending = false
    68    var timerFunc
    69    function nextTickHandler () {
    70      pending = false
    71      var copies = callbacks.slice(0)
    72      callbacks = []
    73      for (var i = 0; i < copies.length; i++) {
    74        copies[i]()
    75      }
    76    }
    77  
    78    /* istanbul ignore if */
    79    if (typeof MutationObserver !== 'undefined' && !(isWechat && isIos)) {
    80      var counter = 1
    81      var observer = new MutationObserver(nextTickHandler)
    82      var textNode = document.createTextNode(counter)
    83      observer.observe(textNode, {
    84        characterData: true
    85      })
    86      timerFunc = function () {
    87        counter = (counter + 1) % 2
    88        textNode.data = counter
    89      }
    90    } else {
    91      // webpack attempts to inject a shim for setImmediate
    92      // if it is used as a global, so we have to work around that to
    93      // avoid bundling unnecessary code.
    94      const context = inBrowser
    95        ? window
    96        : typeof global !== 'undefined' ? global : {}
    97      timerFunc = context.setImmediate || setTimeout
    98    }
    99    return function (cb, ctx) {
   100      var func = ctx
   101        ? function () { cb.call(ctx) }
   102        : cb
   103      callbacks.push(func)
   104      if (pending) return
   105      pending = true
   106      timerFunc(nextTickHandler, 0)
   107    }
   108  })()
   109  
   110  let _Set
   111  /* istanbul ignore if */
   112  if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
   113    // use native Set when available.
   114    _Set = Set
   115  } else {
   116    // a non-standard Set polyfill that only works with primitive keys.
   117    _Set = function () {
   118      this.set = Object.create(null)
   119    }
   120    _Set.prototype.has = function (key) {
   121      return this.set[key] !== undefined
   122    }
   123    _Set.prototype.add = function (key) {
   124      this.set[key] = 1
   125    }
   126    _Set.prototype.clear = function () {
   127      this.set = Object.create(null)
   128    }
   129  }
   130  
   131  export { _Set }