PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/webroot/static/bower_components/jquery-hashchange/examples/document_domain/index.php

https://gitlab.com/tangsengjiu/Talk
PHP | 172 lines | 95 code | 40 blank | 37 comment | 0 complexity | 4b9f31c3f62e8bd36c5d6acc1ccb006f MD5 | raw file
  1. <?PHP
  2. include "../index.php";
  3. $shell['title3'] = "document.domain";
  4. $shell['h2'] = 'The hash, it\'s a-changin\'...';
  5. // ========================================================================== //
  6. // SCRIPT
  7. // ========================================================================== //
  8. ob_start();
  9. ?>
  10. $(function(){
  11. // These two properties, set after jQuery and the hashchange event plugin are
  12. // loaded, only need to be used when document.domain is set (to fix the "access
  13. // denied" error in IE6/7).
  14. $.fn.hashchange.src = '../../document-domain.html';
  15. $.fn.hashchange.domain = document.domain;
  16. // Bind an event to window.onhashchange that, when the hash changes, gets the
  17. // hash and adds the class "selected" to any matching nav link.
  18. $(window).hashchange( function(){
  19. var hash = location.hash;
  20. // Set the page title based on the hash.
  21. document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
  22. // Iterate over all nav links, setting the "selected" class as-appropriate.
  23. $('#nav a').each(function(){
  24. var that = $(this);
  25. that[ that.attr( 'href' ) === hash ? 'addClass' : 'removeClass' ]( 'selected' );
  26. });
  27. })
  28. // Since the event is only triggered when the hash changes, we need to trigger
  29. // the event now, to handle the hash the page may have loaded with.
  30. $(window).hashchange();
  31. });
  32. <?
  33. $shell['script'] = ob_get_contents();
  34. ob_end_clean();
  35. // ========================================================================== //
  36. // HTML HEAD ADDITIONAL
  37. // ========================================================================== //
  38. ob_start();
  39. ?>
  40. <script type="text/javascript">
  41. // If setting document.domain, be sure to do it *before* jQuery is loaded!
  42. document.domain = document.domain.split('.').slice(-2).join('.');
  43. </script>
  44. <?
  45. $shell['html_head_pre'] = ob_get_contents();
  46. ob_end_clean();
  47. ob_start();
  48. ?>
  49. <script type="text/javascript" src="../../jquery.ba-hashchange.js"></script>
  50. <script type="text/javascript" language="javascript">
  51. <?= $shell['script']; ?>
  52. $(function(){
  53. // Syntax highlighter.
  54. SyntaxHighlighter.highlight();
  55. });
  56. </script>
  57. <style type="text/css" title="text/css">
  58. /*
  59. bg: #FDEBDC
  60. bg1: #FFD6AF
  61. bg2: #FFAB59
  62. orange: #FF7F00
  63. brown: #913D00
  64. lt. brown: #C4884F
  65. */
  66. #page {
  67. width: 700px;
  68. }
  69. #nav {
  70. font-size: 200%;
  71. }
  72. #nav a {
  73. color: #777;
  74. border: 2px solid #777;
  75. background-color: #ccc;
  76. padding: 0.2em 0.6em;
  77. text-decoration: none;
  78. float: left;
  79. margin-right: 0.3em;
  80. }
  81. #nav a:hover {
  82. color: #999;
  83. border-color: #999;
  84. background: #eee;
  85. }
  86. #nav a.selected,
  87. #nav a.selected:hover {
  88. color: #0a0;
  89. border-color: #0a0;
  90. background: #afa;
  91. }
  92. </style>
  93. <?
  94. $shell['html_head'] = ob_get_contents();
  95. ob_end_clean();
  96. // ========================================================================== //
  97. // HTML BODY
  98. // ========================================================================== //
  99. ob_start();
  100. ?>
  101. <?= $shell['donate'] ?>
  102. <p>
  103. <a href="http://benalman.com/projects/jquery-hashchange-plugin/">jQuery hashchange event</a> enables very basic bookmarkable #hash history via a cross-browser window.onhashchange event. <em>This example is exactly like the basic <a href="../hashchange/">hashchange event example</a> except that document.domain is set, and the example code has been modifed accordingly.</em>
  104. </p>
  105. <h3>Click, and watch as the magic happens!</h3>
  106. <p id="nav">
  107. <a href="#test1">test 1</a>
  108. <a href="#test2">test 2</a>
  109. <a href="#test3">test 3</a>
  110. <a href="#test4">test 4</a>
  111. </p>
  112. <div class="clear" style="padding-top:1em;"></div>
  113. <p>
  114. Note that there is absolutely no JavaScript attached to the click event of these links. All they do is set the <code>location.hash</code> via href, and the callback bound to the window.onhashchange event does the rest. Once you've clicked one or more of these links, fool around with your browser's back and next buttons.
  115. </p>
  116. <h3>The code</h3>
  117. <pre class="brush:js">
  118. <?= htmlspecialchars( $shell['script'] ); ?>
  119. </pre>
  120. <h3>That's it!</h3>
  121. <p>
  122. This plugin is, by design, very basic. If you want to add lot of extra utility around getting and setting the hash as a state, and parsing and merging fragment params, check out the <a href="http://benalman.com/projects/jquery-bbq-plugin/">jQuery BBQ</a> plugin. It includes this plugin at its core, plus a whole lot more, and has thorough documentation and examples as well. You can't have too much of a good thing!
  123. </p>
  124. <?
  125. $shell['html_body'] = ob_get_contents();
  126. ob_end_clean();
  127. // ========================================================================== //
  128. // DRAW SHELL
  129. // ========================================================================== //
  130. draw_shell();
  131. ?>