general.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* jshint multistr:true */
  2. (function( $, undefined ) {
  3. "use strict";
  4. window.VAMTAM = window.VAMTAM || {}; // Namespace
  5. $(function () {
  6. window.VAMTAM.admin_bar_fix = document.body.classList.contains( 'admin-bar' ) ? 32 : 0;
  7. if ( /iPad|iPhone|iPod/.test( navigator.userAgent ) && ! window.MSStream) {
  8. requestAnimationFrame( function() {
  9. document.documentElement.classList.add( 'ios-safari' );
  10. } );
  11. }
  12. // trigger resize after publishing a layout in order to deal with the disappearance of Beaver's UI
  13. if ( 'FLBuilder' in window ) {
  14. FLBuilder.addHook( 'didPublishLayout', function() {
  15. window.dispatchEvent( new Event( 'resize' ) );
  16. } );
  17. }
  18. // prevent hover when scrolling
  19. (function() {
  20. var box = document.querySelector( '.boxed-layout' ),
  21. timer;
  22. window.addEventListener( 'scroll', function() {
  23. clearTimeout(timer);
  24. requestAnimationFrame( function() {
  25. box.style.pointerEvents = 'none';
  26. timer = setTimeout( function() {
  27. box.style.pointerEvents = '';
  28. }, 300 );
  29. } );
  30. }, { passive: true } );
  31. })();
  32. // Code which depends on the window width
  33. // =====================================================================
  34. window.VAMTAM.resizeElements = function() {
  35. // video size
  36. $('.portfolio-image-wrapper,\
  37. .boxed-layout .media-inner,\
  38. .boxed-layout .loop-wrapper.news .thumbnail,\
  39. .boxed-layout .portfolio-image .thumbnail,\
  40. .vamtam-video-frame').find('iframe, object, embed, video').each(function() {
  41. setTimeout( function() {
  42. requestAnimationFrame( function() {
  43. var v_width = this.offsetWidth;
  44. this.style.width = '100%';
  45. if ( this.width === '0' && this.height === '0' ) {
  46. this.style.height = ( v_width * 9/16 ) + 'px';
  47. } else {
  48. this.style.height = ( this.height * v_width / this.width ) + 'px';
  49. }
  50. $( this ).trigger('vamtam-video-resized');
  51. }.bind( this ) );
  52. }.bind( this ), 50 );
  53. });
  54. setTimeout( function() {
  55. requestAnimationFrame( function() {
  56. $('.mejs-time-rail').css('width', '-=1px');
  57. } );
  58. }, 100 );
  59. };
  60. window.addEventListener( 'resize', window.VAMTAM.debounce( window.VAMTAM.resizeElements, 100 ), false );
  61. window.VAMTAM.resizeElements();
  62. } );
  63. // Low priority scripts are loaded later
  64. document.addEventListener('DOMContentLoaded', function () {
  65. window.VAMTAM.load_script( VAMTAM_FRONT.jspath + 'build/low-priority.min.js' );
  66. if ( ! ( window.CSS && window.CSS.supports && window.CSS.supports( '(--foo: red)' ) ) ) {
  67. window.VAMTAM.load_script( VAMTAM_FRONT.jspath + 'plugins/thirdparty/css-variables-polyfill.js' );
  68. var ie11styles = document.createElement('link');
  69. ie11styles.type = 'text/css';
  70. ie11styles.rel = 'stylesheet';
  71. ie11styles.href = VAMTAM_FRONT.jspath + '../css/dist/ie11.css';
  72. document.body.appendChild( ie11styles );
  73. }
  74. }, { passive: true } );
  75. })(jQuery);