main.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. Paradigm Shift by HTML5 UP
  3. html5up.net | @ajlkn
  4. Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
  5. */
  6. (function($) {
  7. var $window = $(window),
  8. $body = $('body');
  9. // Breakpoints.
  10. breakpoints({
  11. default: ['1681px', null ],
  12. xlarge: ['1281px', '1680px' ],
  13. large: ['981px', '1280px' ],
  14. medium: ['737px', '980px' ],
  15. small: ['481px', '736px' ],
  16. xsmall: ['361px', '480px' ],
  17. xxsmall: [null, '360px' ]
  18. });
  19. // Play initial animations on page load.
  20. $window.on('load', function() {
  21. window.setTimeout(function() {
  22. $body.removeClass('is-preload');
  23. }, 100);
  24. });
  25. // Hack: Enable IE workarounds.
  26. if (browser.name == 'ie')
  27. $body.addClass('is-ie');
  28. // Mobile?
  29. if (browser.mobile)
  30. $body.addClass('is-mobile');
  31. // Scrolly.
  32. $('.scrolly')
  33. .scrolly({
  34. offset: 100
  35. });
  36. // Polyfill: Object fit.
  37. if (!browser.canUse('object-fit')) {
  38. $('.image[data-position]').each(function() {
  39. var $this = $(this),
  40. $img = $this.children('img');
  41. // Apply img as background.
  42. $this
  43. .css('background-image', 'url("' + $img.attr('src') + '")')
  44. .css('background-position', $this.data('position'))
  45. .css('background-size', 'cover')
  46. .css('background-repeat', 'no-repeat');
  47. // Hide img.
  48. $img
  49. .css('opacity', '0');
  50. });
  51. $('.gallery > a').each(function() {
  52. var $this = $(this),
  53. $img = $this.children('img');
  54. // Apply img as background.
  55. $this
  56. .css('background-image', 'url("' + $img.attr('src') + '")')
  57. .css('background-position', 'center')
  58. .css('background-size', 'cover')
  59. .css('background-repeat', 'no-repeat');
  60. // Hide img.
  61. $img
  62. .css('opacity', '0');
  63. });
  64. }
  65. // Gallery.
  66. $('.gallery')
  67. .on('click', 'a', function(event) {
  68. var $a = $(this),
  69. $gallery = $a.parents('.gallery'),
  70. $modal = $gallery.children('.modal'),
  71. $modalImg = $modal.find('img'),
  72. href = $a.attr('href');
  73. // Not an image? Bail.
  74. if (!href.match(/\.(jpg|gif|png|mp4)$/))
  75. return;
  76. // Prevent default.
  77. event.preventDefault();
  78. event.stopPropagation();
  79. // Locked? Bail.
  80. if ($modal[0]._locked)
  81. return;
  82. // Lock.
  83. $modal[0]._locked = true;
  84. // Set src.
  85. $modalImg.attr('src', href);
  86. // Set visible.
  87. $modal.addClass('visible');
  88. // Focus.
  89. $modal.focus();
  90. // Delay.
  91. setTimeout(function() {
  92. // Unlock.
  93. $modal[0]._locked = false;
  94. }, 600);
  95. })
  96. .on('click', '.modal', function(event) {
  97. var $modal = $(this),
  98. $modalImg = $modal.find('img');
  99. // Locked? Bail.
  100. if ($modal[0]._locked)
  101. return;
  102. // Already hidden? Bail.
  103. if (!$modal.hasClass('visible'))
  104. return;
  105. // Stop propagation.
  106. event.stopPropagation();
  107. // Lock.
  108. $modal[0]._locked = true;
  109. // Clear visible, loaded.
  110. $modal
  111. .removeClass('loaded')
  112. // Delay.
  113. setTimeout(function() {
  114. $modal
  115. .removeClass('visible')
  116. setTimeout(function() {
  117. // Clear src.
  118. $modalImg.attr('src', '');
  119. // Unlock.
  120. $modal[0]._locked = false;
  121. // Focus.
  122. $body.focus();
  123. }, 475);
  124. }, 125);
  125. })
  126. .on('keypress', '.modal', function(event) {
  127. var $modal = $(this);
  128. // Escape? Hide modal.
  129. if (event.keyCode == 27)
  130. $modal.trigger('click');
  131. })
  132. .on('mouseup mousedown mousemove', '.modal', function(event) {
  133. // Stop propagation.
  134. event.stopPropagation();
  135. })
  136. .prepend('<div class="modal" tabIndex="-1"><div class="inner"><img src="" /></div></div>')
  137. .find('img')
  138. .on('load', function(event) {
  139. var $modalImg = $(this),
  140. $modal = $modalImg.parents('.modal');
  141. setTimeout(function() {
  142. // No longer visible? Bail.
  143. if (!$modal.hasClass('visible'))
  144. return;
  145. // Set loaded.
  146. $modal.addClass('loaded');
  147. }, 275);
  148. });
  149. })(jQuery);