initialize_shuffle.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2,h3,h4' });
  4. });
  5. </script>
  6. <!-- shuffle -->
  7. <script>
  8. var shuffleme = (function( $ ) {
  9. 'use strict';
  10. var $grid = $('#grid'),
  11. $filterOptions = $('.filter-options'),
  12. $sizer = $grid.find('.shuffle_sizer'),
  13. init = function() {
  14. // None of these need to be executed synchronously
  15. setTimeout(function() {
  16. listen();
  17. setupFilters();
  18. }, 100);
  19. // instantiate the plugin
  20. $grid.shuffle({
  21. itemSelector: '[class*="col-"]',
  22. sizer: $sizer
  23. });
  24. },
  25. // Set up button clicks
  26. setupFilters = function() {
  27. var $btns = $filterOptions.children();
  28. $btns.on('click', function() {
  29. var $this = $(this),
  30. isActive = $this.hasClass( 'active' ),
  31. group = isActive ? 'all' : $this.data('group');
  32. // Hide current label, show current label in title
  33. if ( !isActive ) {
  34. $('.filter-options .active').removeClass('active');
  35. }
  36. $this.toggleClass('active');
  37. // Filter elements
  38. $grid.shuffle( 'shuffle', group );
  39. });
  40. $btns = null;
  41. },
  42. // Re layout shuffle when images load. This is only needed
  43. // below 768 pixels because the .picture-item height is auto and therefore
  44. // the height of the picture-item is dependent on the image
  45. // I recommend using imagesloaded to determine when an image is loaded
  46. // but that doesn't support IE7
  47. listen = function() {
  48. var debouncedLayout = $.throttle( 300, function() {
  49. $grid.shuffle('update');
  50. });
  51. // Get all images inside shuffle
  52. $grid.find('img').each(function() {
  53. var proxyImage;
  54. // Image already loaded
  55. if ( this.complete && this.naturalWidth !== undefined ) {
  56. return;
  57. }
  58. // If none of the checks above matched, simulate loading on detached element.
  59. proxyImage = new Image();
  60. $( proxyImage ).on('load', function() {
  61. $(this).off('load');
  62. debouncedLayout();
  63. });
  64. proxyImage.src = this.src;
  65. });
  66. // Because this method doesn't seem to be perfect.
  67. setTimeout(function() {
  68. debouncedLayout();
  69. }, 500);
  70. };
  71. return {
  72. init: init
  73. };
  74. }( jQuery ));
  75. $(document).ready(function() {
  76. shuffleme.init();
  77. });
  78. </script>
  79. <!-- new attempt-->
  80. <script>
  81. $(document).ready(function() {
  82. /* initialize shuffle plugin */
  83. var $grid = $('#grid');
  84. $grid.shuffle({
  85. itemSelector: '.item' // the selector for the items in the grid
  86. });
  87. });</script>
  88. <script>
  89. $('#filter a').click(function (e) {
  90. e.preventDefault();
  91. // set active class
  92. $('#filter a').removeClass('active');
  93. $(this).addClass('active');
  94. // get group name from clicked item
  95. var groupName = $(this).attr('data-group');
  96. // reshuffle grid
  97. $grid.shuffle('shuffle', groupName );
  98. });</script>