PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/build/history-hash-ie/history-hash-ie-coverage.js

https://bitbucket.org/Quartermain/yui3
JavaScript | 204 lines | 124 code | 22 blank | 58 comment | 20 complexity | 5b85ad515b9c3f2dd8730471b17c8be4 MD5 | raw file
  1. if (typeof _yuitest_coverage == "undefined"){
  2. _yuitest_coverage = {};
  3. _yuitest_coverline = function(src, line){
  4. var coverage = _yuitest_coverage[src];
  5. if (!coverage.lines[line]){
  6. coverage.calledLines++;
  7. }
  8. coverage.lines[line]++;
  9. };
  10. _yuitest_coverfunc = function(src, name, line){
  11. var coverage = _yuitest_coverage[src],
  12. funcId = name + ":" + line;
  13. if (!coverage.functions[funcId]){
  14. coverage.calledFunctions++;
  15. }
  16. coverage.functions[funcId]++;
  17. };
  18. }
  19. _yuitest_coverage["build/history-hash-ie/history-hash-ie.js"] = {
  20. lines: {},
  21. functions: {},
  22. coveredLines: 0,
  23. calledLines: 0,
  24. coveredFunctions: 0,
  25. calledFunctions: 0,
  26. path: "build/history-hash-ie/history-hash-ie.js",
  27. code: []
  28. };
  29. _yuitest_coverage["build/history-hash-ie/history-hash-ie.js"].code=["YUI.add('history-hash-ie', function (Y, NAME) {","","/**"," * Improves IE6/7 support in history-hash by using a hidden iframe to create"," * entries in IE's browser history. This module is only needed if IE6/7 support"," * is necessary; it's not needed for any other browser."," *"," * @module history"," * @submodule history-hash-ie"," * @since 3.2.0"," */","","// Combination of a UA sniff to ensure this is IE (or a browser that wants us to","// treat it like IE) and feature detection for native hashchange support (false","// for IE < 8 or IE8/9 in IE7 mode).","if (Y.UA.ie && !Y.HistoryBase.nativeHashChange) {"," var Do = Y.Do,"," GlobalEnv = YUI.namespace('Env.HistoryHash'),"," HistoryHash = Y.HistoryHash,",""," iframe = GlobalEnv._iframe,"," win = Y.config.win;",""," /**"," * Gets the raw (not decoded) current location hash from the IE iframe,"," * minus the preceding '#' character and the hashPrefix (if one is set)."," *"," * @method getIframeHash"," * @return {String} current iframe hash"," * @static"," */"," HistoryHash.getIframeHash = function () {"," if (!iframe || !iframe.contentWindow) {"," return '';"," }",""," var prefix = HistoryHash.hashPrefix,"," hash = iframe.contentWindow.location.hash.substr(1);",""," return prefix && hash.indexOf(prefix) === 0 ?"," hash.replace(prefix, '') : hash;"," };",""," /**"," * Updates the history iframe with the specified hash."," *"," * @method _updateIframe"," * @param {String} hash location hash"," * @param {Boolean} replace (optional) if <code>true</code>, the current"," * history state will be replaced without adding a new history entry"," * @protected"," * @static"," * @for HistoryHash"," */"," HistoryHash._updateIframe = function (hash, replace) {"," var iframeDoc = iframe && iframe.contentWindow && iframe.contentWindow.document,"," iframeLocation = iframeDoc && iframeDoc.location;",""," if (!iframeDoc || !iframeLocation) {"," return;"," }","",""," if (replace) {"," iframeLocation.replace(hash.charAt(0) === '#' ? hash : '#' + hash);"," } else {"," iframeDoc.open().close();"," iframeLocation.hash = hash;"," }"," };",""," Do.before(HistoryHash._updateIframe, HistoryHash, 'replaceHash', HistoryHash, true);",""," if (!iframe) {"," Y.on('domready', function () {"," var lastUrlHash = HistoryHash.getHash();",""," // Create a hidden iframe to store history state, following the"," // iframe-hiding recommendations from"," // http://www.paciellogroup.com/blog/?p=604."," //"," // This iframe will allow history navigation within the current page"," // context. After navigating to another page, all but the most"," // recent history state will be lost."," //"," // Earlier versions of the YUI History Utility attempted to work"," // around this limitation by having the iframe load a static"," // resource. This workaround was extremely fragile and tended to"," // break frequently (and silently) since it was entirely dependent"," // on IE's inconsistent handling of iframe history."," //"," // Since this workaround didn't work much of the time anyway and"," // added significant complexity, it has been removed, and IE6 and 7"," // now get slightly degraded history support.",""," iframe = GlobalEnv._iframe = Y.Node.getDOMNode(Y.Node.create("," '<iframe src=\"javascript:0\" style=\"display:none\" height=\"0\" width=\"0\" tabindex=\"-1\" title=\"empty\"/>'"," ));",""," // Append the iframe to the documentElement rather than the body."," // Keeping it outside the body prevents scrolling on the initial"," // page load (hat tip to Ben Alman and jQuery BBQ for this"," // technique)."," Y.config.doc.documentElement.appendChild(iframe);",""," // Update the iframe with the initial location hash, if any. This"," // will create an initial history entry that the user can return to"," // after the state has changed."," HistoryHash._updateIframe(lastUrlHash || '#');",""," // Listen for hashchange events and keep the iframe's hash in sync"," // with the parent frame's hash."," Y.on('hashchange', function (e) {"," lastUrlHash = e.newHash;",""," if (HistoryHash.getIframeHash() !== lastUrlHash) {"," HistoryHash._updateIframe(lastUrlHash);"," }"," }, win);",""," // Watch the iframe hash in order to detect back/forward navigation."," Y.later(50, null, function () {"," var iframeHash = HistoryHash.getIframeHash();",""," if (iframeHash !== lastUrlHash) {"," HistoryHash.setHash(iframeHash);"," }"," }, null, true);"," });"," }","}","","","}, '@VERSION@', {\"requires\": [\"history-hash\", \"node-base\"]});"];
  30. _yuitest_coverage["build/history-hash-ie/history-hash-ie.js"].lines = {"1":0,"16":0,"17":0,"32":0,"33":0,"34":0,"37":0,"40":0,"55":0,"56":0,"59":0,"60":0,"64":0,"65":0,"67":0,"68":0,"72":0,"74":0,"75":0,"76":0,"96":0,"104":0,"109":0,"113":0,"114":0,"116":0,"117":0,"122":0,"123":0,"125":0,"126":0};
  31. _yuitest_coverage["build/history-hash-ie/history-hash-ie.js"].functions = {"getIframeHash:32":0,"_updateIframe:55":0,"(anonymous 3):113":0,"(anonymous 4):122":0,"(anonymous 2):75":0,"(anonymous 1):1":0};
  32. _yuitest_coverage["build/history-hash-ie/history-hash-ie.js"].coveredLines = 31;
  33. _yuitest_coverage["build/history-hash-ie/history-hash-ie.js"].coveredFunctions = 6;
  34. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 1);
  35. YUI.add('history-hash-ie', function (Y, NAME) {
  36. /**
  37. * Improves IE6/7 support in history-hash by using a hidden iframe to create
  38. * entries in IE's browser history. This module is only needed if IE6/7 support
  39. * is necessary; it's not needed for any other browser.
  40. *
  41. * @module history
  42. * @submodule history-hash-ie
  43. * @since 3.2.0
  44. */
  45. // Combination of a UA sniff to ensure this is IE (or a browser that wants us to
  46. // treat it like IE) and feature detection for native hashchange support (false
  47. // for IE < 8 or IE8/9 in IE7 mode).
  48. _yuitest_coverfunc("build/history-hash-ie/history-hash-ie.js", "(anonymous 1)", 1);
  49. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 16);
  50. if (Y.UA.ie && !Y.HistoryBase.nativeHashChange) {
  51. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 17);
  52. var Do = Y.Do,
  53. GlobalEnv = YUI.namespace('Env.HistoryHash'),
  54. HistoryHash = Y.HistoryHash,
  55. iframe = GlobalEnv._iframe,
  56. win = Y.config.win;
  57. /**
  58. * Gets the raw (not decoded) current location hash from the IE iframe,
  59. * minus the preceding '#' character and the hashPrefix (if one is set).
  60. *
  61. * @method getIframeHash
  62. * @return {String} current iframe hash
  63. * @static
  64. */
  65. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 32);
  66. HistoryHash.getIframeHash = function () {
  67. _yuitest_coverfunc("build/history-hash-ie/history-hash-ie.js", "getIframeHash", 32);
  68. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 33);
  69. if (!iframe || !iframe.contentWindow) {
  70. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 34);
  71. return '';
  72. }
  73. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 37);
  74. var prefix = HistoryHash.hashPrefix,
  75. hash = iframe.contentWindow.location.hash.substr(1);
  76. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 40);
  77. return prefix && hash.indexOf(prefix) === 0 ?
  78. hash.replace(prefix, '') : hash;
  79. };
  80. /**
  81. * Updates the history iframe with the specified hash.
  82. *
  83. * @method _updateIframe
  84. * @param {String} hash location hash
  85. * @param {Boolean} replace (optional) if <code>true</code>, the current
  86. * history state will be replaced without adding a new history entry
  87. * @protected
  88. * @static
  89. * @for HistoryHash
  90. */
  91. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 55);
  92. HistoryHash._updateIframe = function (hash, replace) {
  93. _yuitest_coverfunc("build/history-hash-ie/history-hash-ie.js", "_updateIframe", 55);
  94. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 56);
  95. var iframeDoc = iframe && iframe.contentWindow && iframe.contentWindow.document,
  96. iframeLocation = iframeDoc && iframeDoc.location;
  97. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 59);
  98. if (!iframeDoc || !iframeLocation) {
  99. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 60);
  100. return;
  101. }
  102. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 64);
  103. if (replace) {
  104. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 65);
  105. iframeLocation.replace(hash.charAt(0) === '#' ? hash : '#' + hash);
  106. } else {
  107. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 67);
  108. iframeDoc.open().close();
  109. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 68);
  110. iframeLocation.hash = hash;
  111. }
  112. };
  113. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 72);
  114. Do.before(HistoryHash._updateIframe, HistoryHash, 'replaceHash', HistoryHash, true);
  115. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 74);
  116. if (!iframe) {
  117. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 75);
  118. Y.on('domready', function () {
  119. _yuitest_coverfunc("build/history-hash-ie/history-hash-ie.js", "(anonymous 2)", 75);
  120. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 76);
  121. var lastUrlHash = HistoryHash.getHash();
  122. // Create a hidden iframe to store history state, following the
  123. // iframe-hiding recommendations from
  124. // http://www.paciellogroup.com/blog/?p=604.
  125. //
  126. // This iframe will allow history navigation within the current page
  127. // context. After navigating to another page, all but the most
  128. // recent history state will be lost.
  129. //
  130. // Earlier versions of the YUI History Utility attempted to work
  131. // around this limitation by having the iframe load a static
  132. // resource. This workaround was extremely fragile and tended to
  133. // break frequently (and silently) since it was entirely dependent
  134. // on IE's inconsistent handling of iframe history.
  135. //
  136. // Since this workaround didn't work much of the time anyway and
  137. // added significant complexity, it has been removed, and IE6 and 7
  138. // now get slightly degraded history support.
  139. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 96);
  140. iframe = GlobalEnv._iframe = Y.Node.getDOMNode(Y.Node.create(
  141. '<iframe src="javascript:0" style="display:none" height="0" width="0" tabindex="-1" title="empty"/>'
  142. ));
  143. // Append the iframe to the documentElement rather than the body.
  144. // Keeping it outside the body prevents scrolling on the initial
  145. // page load (hat tip to Ben Alman and jQuery BBQ for this
  146. // technique).
  147. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 104);
  148. Y.config.doc.documentElement.appendChild(iframe);
  149. // Update the iframe with the initial location hash, if any. This
  150. // will create an initial history entry that the user can return to
  151. // after the state has changed.
  152. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 109);
  153. HistoryHash._updateIframe(lastUrlHash || '#');
  154. // Listen for hashchange events and keep the iframe's hash in sync
  155. // with the parent frame's hash.
  156. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 113);
  157. Y.on('hashchange', function (e) {
  158. _yuitest_coverfunc("build/history-hash-ie/history-hash-ie.js", "(anonymous 3)", 113);
  159. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 114);
  160. lastUrlHash = e.newHash;
  161. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 116);
  162. if (HistoryHash.getIframeHash() !== lastUrlHash) {
  163. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 117);
  164. HistoryHash._updateIframe(lastUrlHash);
  165. }
  166. }, win);
  167. // Watch the iframe hash in order to detect back/forward navigation.
  168. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 122);
  169. Y.later(50, null, function () {
  170. _yuitest_coverfunc("build/history-hash-ie/history-hash-ie.js", "(anonymous 4)", 122);
  171. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 123);
  172. var iframeHash = HistoryHash.getIframeHash();
  173. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 125);
  174. if (iframeHash !== lastUrlHash) {
  175. _yuitest_coverline("build/history-hash-ie/history-hash-ie.js", 126);
  176. HistoryHash.setHash(iframeHash);
  177. }
  178. }, null, true);
  179. });
  180. }
  181. }
  182. }, '@VERSION@', {"requires": ["history-hash", "node-base"]});