scripts.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. Bones Scripts File
  3. Author: Eddie Machado
  4. This file should contain any js scripts you want to add to the site.
  5. Instead of calling it in the header or throwing it inside wp_head()
  6. this file will be called automatically in the footer so as not to
  7. slow the page load.
  8. */
  9. // IE8 ployfill for GetComputed Style (for Responsive Script below)
  10. if (!window.getComputedStyle) {
  11. window.getComputedStyle = function(el, pseudo) {
  12. this.el = el;
  13. this.getPropertyValue = function(prop) {
  14. var re = /(\-([a-z]){1})/g;
  15. if (prop == 'float') prop = 'styleFloat';
  16. if (re.test(prop)) {
  17. prop = prop.replace(re, function () {
  18. return arguments[2].toUpperCase();
  19. });
  20. }
  21. return el.currentStyle[prop] ? el.currentStyle[prop] : null;
  22. }
  23. return this;
  24. }
  25. }
  26. // as the page loads, call these scripts
  27. jQuery(document).ready(function($) {
  28. /*
  29. Responsive jQuery is a tricky thing.
  30. There's a bunch of different ways to handle
  31. it, so be sure to research and find the one
  32. that works for you best.
  33. */
  34. /* getting viewport width */
  35. var responsive_viewport = $(window).width();
  36. /* if is below 481px */
  37. if (responsive_viewport < 481) {
  38. } /* end smallest screen */
  39. /* if is larger than 481px */
  40. if (responsive_viewport > 481) {
  41. } /* end larger than 481px */
  42. /* if is above or equal to 768px */
  43. if (responsive_viewport >= 768) {
  44. /* load gravatars */
  45. $('.comment img[data-gravatar]').each(function(){
  46. $(this).attr('src',$(this).attr('data-gravatar'));
  47. });
  48. }
  49. /* off the bat large screen actions */
  50. if (responsive_viewport > 1030) {
  51. }
  52. // add all your scripts here
  53. }); /* end of as page load scripts */
  54. /*! A fix for the iOS orientationchange zoom bug.
  55. Script by @scottjehl, rebound by @wilto.
  56. MIT License.
  57. */
  58. (function(w){
  59. // This fix addresses an iOS bug, so return early if the UA claims it's something else.
  60. if( !( /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1 ) ){ return; }
  61. var doc = w.document;
  62. if( !doc.querySelector ){ return; }
  63. var meta = doc.querySelector( "meta[name=viewport]" ),
  64. initialContent = meta && meta.getAttribute( "content" ),
  65. disabledZoom = initialContent + ",maximum-scale=1",
  66. enabledZoom = initialContent + ",maximum-scale=10",
  67. enabled = true,
  68. x, y, z, aig;
  69. if( !meta ){ return; }
  70. function restoreZoom(){
  71. meta.setAttribute( "content", enabledZoom );
  72. enabled = true; }
  73. function disableZoom(){
  74. meta.setAttribute( "content", disabledZoom );
  75. enabled = false; }
  76. function checkTilt( e ){
  77. aig = e.accelerationIncludingGravity;
  78. x = Math.abs( aig.x );
  79. y = Math.abs( aig.y );
  80. z = Math.abs( aig.z );
  81. // If portrait orientation and in one of the danger zones
  82. if( !w.orientation && ( x > 7 || ( ( z > 6 && y < 8 || z < 8 && y > 6 ) && x > 5 ) ) ){
  83. if( enabled ){ disableZoom(); } }
  84. else if( !enabled ){ restoreZoom(); } }
  85. w.addEventListener( "orientationchange", restoreZoom, false );
  86. w.addEventListener( "devicemotion", checkTilt, false );
  87. })( this );