Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

initialize_shuffle.html 2.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  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>
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...