PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/dojo/1.7.0/has.js.uncompressed.js

https://gitlab.com/alidz1982/cdnjs
JavaScript | 179 lines | 69 code | 14 blank | 96 comment | 29 complexity | 422c8744c9f60cf5ac5e99aaf945e2d7 MD5 | raw file
  1. //>>built
  2. define("dojo/has", ["require"], function(require) {
  3. // module:
  4. // dojo/has
  5. // summary:
  6. // Defines the has.js API and several feature tests used by dojo.
  7. // description:
  8. // This module defines the has API as described by the project has.js with the following additional features:
  9. //
  10. // * the has test cache is exposed at has.cache.
  11. // * the method has.add includes a forth parameter that controls whether or not existing tests are replaced
  12. // * the loader's has cache may be optionally copied into this module's has cahce.
  13. //
  14. // This module adopted from https://github.com/phiggins42/has.js; thanks has.js team!
  15. // try to pull the has implementation from the loader; both the dojo loader and bdLoad provide one
  16. // WARNING: if a foreign loader defines require.has to be something other than the has.js API, then this implementation fail
  17. var has = require.has || function(){};
  18. if(!1){
  19. // notice the condition is written so that if 1 is transformed to 1 during a build
  20. // the conditional will be (!1 && typeof has=="function") which is statically false and the closure
  21. // compiler will discard the block.
  22. var
  23. isBrowser =
  24. // the most fundamental decision: are we in the browser?
  25. typeof window != "undefined" &&
  26. typeof location != "undefined" &&
  27. typeof document != "undefined" &&
  28. window.location == location && window.document == document,
  29. // has API variables
  30. global = this,
  31. doc = isBrowser && document,
  32. element = doc && doc.createElement("DiV"),
  33. cache = {};
  34. has = /*===== dojo.has= =====*/ function(name){
  35. // summary:
  36. // Return the current value of the named feature.
  37. //
  38. // name: String|Integer
  39. // The name (if a string) or identifier (if an integer) of the feature to test.
  40. //
  41. // description:
  42. // Returns the value of the feature named by name. The feature must have been
  43. // previously added to the cache by has.add.
  44. return cache[name] = typeof cache[name] == "function" ? cache[name](global, doc, element) : cache[name]; // Boolean
  45. };
  46. has.cache = cache;
  47. has.add = /*====== dojo.has.add= ======*/ function(name, test, now, force){
  48. // summary:
  49. // Register a new feature test for some named feature.
  50. //
  51. // name: String|Integer
  52. // The name (if a string) or identifier (if an integer) of the feature to test.
  53. //
  54. // test: Function
  55. // A test function to register. If a function, queued for testing until actually
  56. // needed. The test function should return a boolean indicating
  57. // the presence of a feature or bug.
  58. //
  59. // now: Boolean?
  60. // Optional. Omit if `test` is not a function. Provides a way to immediately
  61. // run the test and cache the result.
  62. //
  63. // force: Boolean?
  64. // Optional. If the test already exists and force is truthy, then the existing
  65. // test will be replaced; otherwise, add does not replace an existing test (that
  66. // is, by default, the first test advice wins).
  67. //
  68. // example:
  69. // A redundant test, testFn with immediate execution:
  70. // | has.add("javascript", function(){ return true; }, true);
  71. //
  72. // example:
  73. // Again with the redundantness. You can do this in your tests, but we should
  74. // not be doing this in any internal has.js tests
  75. // | has.add("javascript", true);
  76. //
  77. // example:
  78. // Three things are passed to the testFunction. `global`, `document`, and a generic element
  79. // from which to work your test should the need arise.
  80. // | has.add("bug-byid", function(g, d, el){
  81. // | // g == global, typically window, yadda yadda
  82. // | // d == document object
  83. // | // el == the generic element. a `has` element.
  84. // | return false; // fake test, byid-when-form-has-name-matching-an-id is slightly longer
  85. // | });
  86. (typeof cache[name]=="undefined" || force) && (cache[name]= test);
  87. return now && has(name);
  88. };
  89. // since we're operating under a loader that doesn't provide a has API, we must explicitly initialize
  90. // has as it would have otherwise been initialized by the dojo loader; use has.add to the builder
  91. // can optimize these away iff desired
  92. true || has.add("host-browser", isBrowser);
  93. true || has.add("dom", isBrowser);
  94. true || has.add("dojo-dom-ready-api", 1);
  95. true || has.add("dojo-sniff", 1);
  96. }
  97. if(1){
  98. var agent = navigator.userAgent;
  99. // Common application level tests
  100. has.add("dom-addeventlistener", !!document.addEventListener);
  101. has.add("touch", "ontouchstart" in document);
  102. // I don't know if any of these tests are really correct, just a rough guess
  103. has.add("device-width", screen.availWidth || innerWidth);
  104. has.add("agent-ios", !!agent.match(/iPhone|iP[ao]d/));
  105. has.add("agent-android", agent.indexOf("android") > 1);
  106. }
  107. has.clearElement = /*===== dojo.has.clearElement= ======*/ function(element) {
  108. // summary:
  109. // Deletes the contents of the element passed to test functions.
  110. element.innerHTML= "";
  111. return element;
  112. };
  113. has.normalize = /*===== dojo.has.normalize= ======*/ function(id, toAbsMid){
  114. // summary:
  115. // Resolves id into a module id based on possibly-nested tenary expression that branches on has feature test value(s).
  116. //
  117. // toAbsMid: Function
  118. // Resolves a relative module id into an absolute module id
  119. var
  120. tokens = id.match(/[\?:]|[^:\?]*/g), i = 0,
  121. get = function(skip){
  122. var term = tokens[i++];
  123. if(term == ":"){
  124. // empty string module name, resolves to 0
  125. return 0;
  126. }else{
  127. // postfixed with a ? means it is a feature to branch on, the term is the name of the feature
  128. if(tokens[i++] == "?"){
  129. if(!skip && has(term)){
  130. // matched the feature, get the first value from the options
  131. return get();
  132. }else{
  133. // did not match, get the second value, passing over the first
  134. get(true);
  135. return get(skip);
  136. }
  137. }
  138. // a module
  139. return term || 0;
  140. }
  141. };
  142. id = get();
  143. return id && toAbsMid(id);
  144. };
  145. has.load = /*===== dojo.has.load= ======*/ function(id, parentRequire, loaded){
  146. // summary:
  147. // Conditional loading of AMD modules based on a has feature test value.
  148. //
  149. // id: String
  150. // Gives the resolved module id to load.
  151. //
  152. // parentRequire: Function
  153. // The loader require function with respect to the module that contained the plugin resource in it's
  154. // dependency list.
  155. //
  156. // loaded: Function
  157. // Callback to loader that consumes result of plugin demand.
  158. if(id){
  159. parentRequire([id], loaded);
  160. }else{
  161. loaded();
  162. }
  163. };
  164. return has;
  165. });