UNPKG

javascript-magic

Version:

Include Ray's JS Library

1,032 lines (860 loc) 28.8 kB
/*! * jQuery.Raymond * Copyright (c) 2015 Raymond Lewis Jones - me<a>raymondlewisjones<d>com | https://www.raymondlewisjones.com * Licensed under MIT * @projectDescription Ray's Jquery Plugins. * @author Raymond Jones * @version 1.0.0 */ ;(function(plugin) { // AMD Support if (typeof define === 'function' && define.amd) { define(['jquery'], plugin); } else { plugin(jQuery); } }(function($) { var $ray = $.ray = function() { return $(window).ray(); }; if ($('meta[name="debug"]').get (0) !== undefined && $('meta[name="debug"]').attr ('content') == 'true') { window.shouldDebug = true; } $window = $(window); $html = $('html'); $body = $('body'); $windowHeight = $window.height (); $windowWidth = $window.width (); $.fn.addClassesIfNotExists = function (cns) { var classNames = cns; $(this).each (function (i) { for (var ii=0;ii<classNames.length;ii++) { var className = classNames [ii]; $(this).addClassIfNotExists (className); } }); return $(this); }; $.fn.addClassIfNotExists = function (cn) { if ($.isArray(cn)) return $(this).addClassesIfNotExists (cn); var className = cn; $(this).each (function (i) { if (!$(this).is ("." + className)) $(this).addClass (className); }); return $(this); }; $.fn.removeClassesIfExists = function (cns) { var classNames = cns; $(this).each (function (i) { for (var ii=0;ii<classNames.length;ii++) { var className = classNames [ii]; $(this).removeClassIfExists (className); } }); return $(this); }; $.fn.removeClassIfExists = function (cn) { if ($.isArray(cn)) return $(this).removeClassesIfExists (cn); var className = cn; $(this).each (function (i) { if ($(this).is ("." + className)) $(this).removeClass (className); }); return $(this); }; $.fn.isNot = function (s) { return !$(this).is (s); }; $.fn.isMobile = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .mobile").is (":visible"); }; $.fn.isXsmall = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .xsmall").is (":visible"); }; $.fn.isSmall = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .small").is (":visible"); }; $.fn.isMedium = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .medium").is (":visible"); }; $.fn.isLarge = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .large").is (":visible"); }; $.fn.isXlarge = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .xlarge").is (":visible"); }; $.fn.isMax = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .max").is (":visible"); }; $.fn.isRetina = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .retina").is (":visible"); }; $.fn.isIE9 = function () { if (!window.isDetecting) $(window).detectionFx (); return $(".detectors .ie-9").is (":visible"); }; $.fn.isIE = function () { if (!window.isDetecting) $(window).detectionFx (); if ($(window).isIE9 () || $(".detectors .ie").is (":visible")) return true; return false; }; $.fn.isTouch = function () { if (!window.isDetecting) $(window).detectionFx (); return (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0)); }; $.fn.isiOS = function () { if (!window.isDetecting) $(window).detectionFx (); var iOS = parseFloat( ('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1]) .replace('undefined', '3_2').replace('_', '.').replace('_', '') ) || false; if (iOS) return true; else return false; }; $.fn.lessThan8 = function () { if (!window.isDetecting) $(window).detectionFx (); var iOS = parseFloat( ('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1]) .replace('undefined', '3_2').replace('_', '.').replace('_', '') ) || false; if (iOS) return iOS < 8; else return false; }; $.fn.isHandheld = function () { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobi/i.test(navigator.userAgent); }; $.fn.isMobileDevice = function () { if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) { window.debug.warn ('This is a mobile device.'); return true; } return false; }; $.fn.isPortrait = function () { if ($html.is ('.portrait')) { return true; } return false; }; $.fn.isLandscape = function () { if ($html.is ('.portrait')) { return false; } return true; }; $.fn.isMobileBrowser = function () { if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) { $html.addClassIfNotExists ('mobile-browser'); return true; } $html.removeClassIfExists ('mobile-browser'); return false; }; $.fn.hasNotch = function () { $proceed = false; $div = document.createElement ('div'); if (CSS.supports ('padding-bottom: env(safe-area-inset-bottom)')) { $div.style.paddingBottom = 'env(safe-area-inset-bottom)'; $proceed = true; } else if (CSS.supports ('padding-bottom: constant(safe-area-inset-bottom)')) { $div.style.paddingBottom = 'constant(safe-area-inset-bottom)'; $proceed = true; } if ($proceed) { document.body.appendChild ($div); $calculatedPadding = parseInt (window.getComputedStyle ($div).paddingBottom); document.body.removeChild ($div); if ($calculatedPadding > 0) { return true; } } return false; }; $.fn.isMobileSafari = function () { $isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/); $iOS = /iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; if ($isSafari && $iOS) { if ($.fn.hasNotch ()) { $html.addClassIfNotExists ('notch'); } $html.addClassIfNotExists ('ios'); return true; } $html.removeClassIfExists ('notch').removeClassIfExists ('ios'); return false; }; $.fn.isEdge = function () { if (document.documentMode || /Edge/.test(navigator.userAgent)) { $html.addClassIfNotExists ('edge'); return true; } $html.removeClassIfExists ('edge'); return false; }; if ($(".ray-main").length < 1) $("html").addClassIfNotExists ("ray-main"); if ($(".ray-container").length < 1) $("html").addClassIfNotExists ("ray-container"); $.fn.hash = function () { return (location.hash).replace ('#', ''); }; ///// /*window.addEventListener ('mousemove', function (e) { var html = $("html"); html.addClassesIfNotExists (["mouse", "no-touch"]).removeClassIfExists("touch"); }); window.addEventListener ('touchstart', function (e){ var html = $("html"); html.removeClassesIfExists (["mouse", "no-touch"]).addClassIfNotExists("touch"); }, false);*/ ////// $.fn.detectTouch = function () { var theWindow = $(this); var html = $("html"); if (theWindow.isTouch ()) { html.removeClassesIfExists (["mouse", "no-touch"]).addClassIfNotExists("touch"); } else { html.addClassesIfNotExists (["mouse", "no-touch"]).removeClassIfExists("touch"); } } $.fn.flashyButton = function () { $(this).each (function () { if (!$(this).is ("[data-flash]")) { $(this).html ("<span class='text'>" + $(this).html () + "</span><span class='top'></span><span class='right'></span><span class='bottom'></span><span class='left'></span>"); $(this).attr ("data-flash", 1); } }); }; $.fn.underlineLinks = function () { $(this).each (function (i) { if (!$(this).is ("[data-underline]")) { $(this).append ('<span class="underline"></span>'); $(this).attr ("data-underline", "1"); } }); }; $.fn.wholeTarget = function () { $(this).each (function () { if (!$(this).is ("[data-whole-target]")) { $(this).click (function (e) { window.location = $(this).find('a[href]').attr ('href'); e.preventDefault (); e.stopPropagation(); }); $(this).attr ("data-whole-target", 1); } }); }; $.fn.swipeRight = function (action, yThreshold, xThreshold, time) { $target = $(this); $target.get (0).swipeRight = action; if (!yThreshold) { yThreshold = 10; } if (!xThreshold) { xThreshold = 20; } if (!time) { time = 500; } $target.get (0).swipeRightYThreshold = yThreshold; $target.get (0).swipeRightXThreshold = xThreshold; $target.get (0).swipeRightTime = time; $target.get (0).addEventListener ( 'touchstart', function (e) { $target = $(this).get (0); $target.isSwipingRight = true; $target.origRightTouchX = e.targetTouches[0].clientX; $target.origRightTouchY = e.targetTouches[0].clientY; $target.rightStart = new Date (); }, {passive: true} ); $target.get (0).addEventListener ( 'touchmove', function (e) { if (!$target.isSwipingRight) { return; } $target = $(this).get (0); $target.rightTouchX = e.targetTouches[0].clientX; $target.rightTouchY = e.targetTouches[0].clientY; $now = new Date (); if ($now.getTime () - $target.rightStart.getTime () > $target.swipeRightTime) { $target.isSwipingRight = false; } if ($target.isSwipingRight && Math.abs($target.origRightTouchY - $target.rightTouchY) >= $target.swipeRightYThreshold) { $target.isSwipingRight = false; } if ($target.isSwipingRight && $target.rightTouchX - $target.origRightTouchX > $target.swipeRightXThreshold) { //console.log ('broke the barrier'); $target.isSwipingRight = false; $target.swipeRight (); } //console.log ($target); //console.log ('touch move ' + ($target.rightTouchX - $target.origRightTouchX)); }, {passive: true} ); $target.get (0).addEventListener ( 'touchend', function (e) { $target = $(this).get (0); $target.isSwipingRight = false; //console.log ($target); //console.log ('touch end'); }, {passive: true} ); }; $.fn.swipeLeft = function (action, yThreshold, xThreshold, time) { $target = $(this); $target.get (0).swipeLeft = action; if (!yThreshold) { yThreshold = 10; } if (!xThreshold) { xThreshold = 20; } if (!time) { time = 500; } $target.get (0).swipeLeftYThreshold = yThreshold; $target.get (0).swipeLeftXThreshold = xThreshold; $target.get (0).swipeLeftTime = time; $target.get (0).addEventListener ( 'touchstart', function (e) { $target = $(this).get (0); $target.isSwipingLeft = true; $target.origLeftTouchX = e.targetTouches[0].clientX; $target.origLeftTouchY = e.targetTouches[0].clientY; $target.leftStart = new Date (); //console.log ($target.swipeRight); //console.log ('touch start'); }, {passive: true} ); $target.get (0).addEventListener ( 'touchmove', function (e) { if (!$target.isSwipingLeft) { return; } $target = $(this).get (0); $target.leftTouchX = e.targetTouches[0].clientX; $target.leftTouchY = e.targetTouches[0].clientY; $now = new Date (); if ($now.getTime () - $target.leftStart.getTime () > $target.swipeLeftTime) { $target.isSwipingRight = false; } if ($target.isSwipingLeft && Math.abs($target.origLeftTouchY - $target.leftTouchY) >= $target.swipeLeftYThreshold) { $target.isSwipingLeft = false; } if ($target.isSwipingLeft && $target.origLeftTouchX - $target.leftTouchX > $target.swipeLeftXThreshold) { //console.log ('broke the barrier'); $target.isSwipingLeft = false; $target.swipeLeft (); } //console.log ($target); //console.log ('touch move ' + ($target.rightTouchX - $target.origRightTouchX)); }, {passive: true} ); $target.get (0).addEventListener ( 'touchend', function (e) { $target = $(this).get (0); $target.isSwipingLeft = false; //console.log ($target); //console.log ('touch end'); }, {passive: true} ); }; $.fn.relativeOffset = function () { var offset = { left : 0, top : 0 }; offset.left = $(this).get (0).getBoundingClientRect ().left; offset.top = $(this).get (0).getBoundingClientRect ().top; return offset; }; $.fn.hashFx = function (fn) { if (!fn) { if (!window.isHashingFx) { window.isHashingFx = true; if (window.hashFunction) window.hashFunction (); window.isHashingFx = false; } } else { var oldHashFunction = window.hashFunction; if (oldHashFunction) { window.hashFunction = function () { oldHashFunction (); fn (); }; } else { window.hashFunction = function () { fn (); }; } $(window).bind ('hashchange', function (e) { $.fn.hashFx (); }); } }; $.fn.scrollFx = function (fn) { if (!fn) { if (!window.isScrollingFx) { window.isScrollingFx = true; if (window.scrollingFunction) window.scrollingFunction (); window.isScrollingFx = false; } } else { var oldScrollingFunction = window.scrollingFunction; if (oldScrollingFunction) { window.scrollingFunction = function () { oldScrollingFunction (); fn (); }; } else { window.scrollingFunction = function () { fn (); }; } $(window).scroll (function () { $.fn.scrollFx (); }); } }; $.fn.loadFx = function (fn) { if (fn) { if (!window.isLoadingFx) { window.isLoadingFx = true; if (document.readyState !== 'loading') { fn (); } else { window.addEventListener ( 'load', function (e) { fn (); }, {passive: true} ); } window.isLoadingFx = false; } } }; /*window.addEventListener('scroll', function(){ $('body').animate ({ scrollTop: '0px' }, 500, function () { // }); }, false);*/ $.fn.resizeFx = function (fn) { if (!fn) { if (!window.isResizingFx) { window.isResizingFx = true; if (window.resizeFunction) window.resizeFunction (); window.isResizingFx = false; } } else { var oldResizeFunction = window.resizeFunction; if (oldResizeFunction) { window.resizeFunction = function () { oldResizeFunction (); fn (); }; } else { window.resizeFunction = function () { fn (); }; } $(window).resize (function () { $.fn.resizeFx (); window.width = $(window).width (); }); } }; /*end window events*/ $.fn.focusFx = function (fn) { if (!fn) { if (!window.isFocusingFx) { window.isFocusingFx = true; if (window.focusFunction) window.focusFunction (); window.isFocusingFx = false; } } else { var oldFocusFunction = window.focusFunction; if (oldFocusFunction) { window.focusFunction = function () { oldFocusFunction (); fn (); }; } else { window.focusFunction = function () { fn (); }; } } }; $.fn.processMasks = function (config) { if (config) { window.maskConfig = config; } $maskedImages = $('picture[data-mask]'); $maskedImages.each ( function (i) { $maskedImage = $(this); if (!$maskedImage.get (0).masked) { $maskType = $maskedImage.attr ('data-mask'); $maskBg = '#542e89'; if ($maskedImage.attr ('data-background')) $maskBg = $maskedImage.attr ('data-background'); $maskColor = '#00FFFFFF'; if ($maskedImage.attr ('data-color')) $maskColor = $maskedImage.attr ('data-color'); $maskDirection = 'right'; if ($maskedImage.attr ('data-direction')) $maskDirection = $maskedImage.attr ('data-direction'); $image = $maskedImage.find ('img'); $maskSrc = ''; if (window.maskConfig.masks[$maskType]) { $maskSrc = window.maskConfig.masks[$maskType]; } $width = $maskedImage.width (); $height = $maskedImage.height (); $imageSrc = $maskSrc; $imageOpacity = 0; if ($image.get (0) !== undefined) { $imageSrc = $image.attr ('src'); $imageOpacity = 1; } if ($imageSrc == '#') { $image.attr ('src', $maskSrc); $imageSrc = $maskSrc; $imageOpacity = 0; } $ID = i; $start = '.9'; $end = '.1'; $extra = ''; if ($maskDirection == 'left') { $start = '0'; $end = '.75'; } else if ($maskDirection == 'up') { $extra = ' x1="0%" y1="0%" x2="0%" y2="100%"'; $start = '.1'; $end = '.9'; } else if ($maskDirection == 'down') { $extra = ' x1="0%" y1="0%" x2="0%" y2="100%"'; $start = '.9'; $end = '.1'; } else if ($maskDirection == 'cover') { $extra = ' x1="0%" y1="0%" x2="0%" y2="100%"'; $start = '.8'; $end = '.8'; } $gradient = '<linearGradient id="gradient{ID}"{extra}><stop offset="0%" stop-color="{color}" stop-opacity="{start}" /><stop offset="100%" stop-color="{color}" stop-opacity="{end}" /></linearGradient>'; $svg = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" class="mask" width="100%" height="100%" viewBox="0 0 {width} {height}"><defs>{gradient}</defs><mask id="mask{ID}"><image width="100%" height="100%" preserveAspectRatio="none" xlink:href="{maskSrc}" /></mask><rect width="100%" height="100%" mask="url(#mask{ID})" fill="' + $maskBg + '" /><image class="image" mask="url(#mask{ID})" style="opacity:' + $imageOpacity + ';" width="100%" height="100%" preserveAspectRatio="none" xlink:href="{imageSrc}" /><rect width="100%" height="100%" mask="url(#mask{ID})" fill="url(#gradient{ID})" class="gradient" /></svg>'; //$svg = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" class="svgMask" width="100%" height="100%" viewBox="0 0 {width} {height}"><mask id="maskID{maskID}"><image width="100%" height="100%" preserveAspectRatio="xMinYMin slice" xlink:href="{maskSrc}" /></mask><image mask="url(#maskID{maskID})" width="100%" height="100%" preserveAspectRatio="xMinYMin slice" xlink:href="{imageSrc}" /></svg>'; $svg = $svg.replace (/{gradient}/g, $gradient); $svg = $svg.replace (/{extra}/g, $extra); $svg = $svg.replace (/{color}/g, $maskColor); $svg = $svg.replace (/{start}/g, $start); $svg = $svg.replace (/{end}/g, $end); $svg = $svg.replace (/{width}/g, $width); $svg = $svg.replace (/{height}/g, $height); $svg = $svg.replace (/{ID}/g, $ID); $svg = $svg.replace (/{maskSrc}/g, $maskSrc); $svg = $svg.replace (/{imageSrc}/g, $imageSrc); $svg = $($svg); //swap original IMG with SVG $maskedImage.append ($svg); //clean up // delete $maskPath, $maskSrc, $uniqueID, $svg; $maskedImage.get (0).masked = true; } else { $svg = $maskedImage.find ('svg'); $svg.attr ('viewBox', '0 0 ' + $maskedImage.width () + ' ' + $maskedImage.height ()); } } ); if (!window.shouldProcess) { $.fn.resizeFx ( function () { $.fn.processMasks (); } ); window.shouldProcess = true; } }; /*body events*/ $("body").click (function (e) { var html = $("html"); if (html.is (".locked")) html.removeClassIfExists ("locked"); }); $("body").hover (function () { if (window.hasLeft == true) { window.hasLeft = false; $.fn.focusFx (); } }, function () { window.hasLeft = true; }); /*body events*/ $("body").click (function (e) { var html = $("html"); if (html.is (".locked")) html.removeClassIfExists ("locked"); }); $("body").hover (function () { if (window.hasLeft == true) { window.hasLeft = false; $.fn.focusFx (); } }, function () { window.hasLeft = true; }); $.fn.detectionFx = function () { if (!window.isDetecting) { window.isDetecting = true; window.addEventListener ('mousemove', function (e) { if (!window.isTouching) { //console.log("mouse",e); var html = $("html"); html.addClassesIfNotExists (["mouse", "no-touch"]).removeClassIfExists("touch"); } }, {passive: true}); window.addEventListener ('touchstart', function (e){ //console.log("touch",e); window.isTouching = true; var html = $("html"); html.removeClassesIfExists (["mouse", "no-touch"]).addClassIfNotExists("touch"); }, {passive: true}); window.addEventListener ('touchend', function (e){ setTimeout (function () { window.isTouching = false; }, 100); }, {passive: true}); if ($("body > .detectors").length < 1) { $("body").append ('<div class="detectors"><div class="mobile"></div><div class="retina"></div><div class="ie"></div><div class="ie-9"></div><div class="xsmall"></div><div class="small"></div><div class="medium"></div><div class="large"></div><div class="xlarge"></div><div class="max"></div></div>'); } $.fn.isMobileBrowser (); $.fn.isMobileSafari (); $.fn.isEdge (); $('a[href]').each (function (i) { $a = $(this); if ($a.attr ('href') != "#") { var link = $a.get (0); var compare = window.location.href.replace ('#', ''); link = link.protocol + "//" + link.host + link.pathname; // console.log (compare, link, link.indexOf (compare)); if (compare.indexOf (link) > -1) { $a.addClassIfNotExists ('active'); } if (link == compare) { $a.addClassIfNotExists ('current'); } } }); $.fn.scrollFx (function () { if (!window.isScrolling || window.isScrolling == null) { window.isScrolling = true; var theWindow = $(window); var html = $("html"); if (theWindow.scrollTop() != 0) { html.addClassIfNotExists ("scrolled"); } else html.removeClassIfExists ("scrolled"); window.isScrolling = false; } }); $.fn.resizeFx (function () { $windowHeight = $window.height (); $width = $window.width (); if ($width != $windowWidth) { $windowWidth = $width; window.dispatchEvent ( new CustomEvent ( 'magic-width-change', { detail: "The width of the window has changed." } ) ); } }); $.fn.resizeFx (function () { if (!window.isResizing || window.isResizing == null) { window.isResizing = true; var theWindow = $(this); var html = $("html"); if ((theWindow.width () / theWindow.height ()) > 1) html.removeClassIfExists ("portrait").addClassIfNotExists ("landscape"); else html.removeClassIfExists ("landscape").addClassIfNotExists ("portrait"); if (theWindow.isIE9 ()) html.addClassIfNotExists (["ie","ie-9"]); if (theWindow.isIE ()) html.addClassIfNotExists ("ie"); theWindow.detectTouch (); if (theWindow.isXsmall ()) { html.removeClassIfExists (["xsmall","small","medium","large","xlarge","max"]).addClass ("xsmall"); } if (theWindow.isSmall ()) { html.removeClassIfExists (["xsmall", "small","medium","large","xlarge","max"]).addClass ("small"); } else if (theWindow.isMedium ()) { html.removeClassIfExists (["xsmall","small","medium","large","xlarge","max"]).addClassIfNotExists ("medium"); } else if (theWindow.isLarge ()) { html.removeClassIfExists (["xsmall","small","medium","large","xlarge","max"]).addClassIfNotExists ("large"); } else if (theWindow.isXlarge ()) { html.removeClassIfExists (["xsmall","small","medium","large","xlarge","max"]).addClassIfNotExists ("xlarge"); } else if (theWindow.isMax ()) { html.removeClassIfExists (["xsmall","small","medium","large","xlarge","max"]).addClassIfNotExists ("max"); } if (theWindow.isMobile ()) html.removeClassIfExists ("desktop").addClassIfNotExists ("mobile"); else html.removeClassIfExists ("locked").removeClass ("mobile").addClassIfNotExists ("desktop"); if (theWindow.isRetina ()) html.addClassIfNotExists ("retina"); else html.removeClassIfExists ("retina"); if (theWindow.isiOS () || theWindow.isHandheld ()) html.addClassIfNotExists ("handheld"); else html.removeClassIfExists ("handheld"); theWindow.scroll (); window.isResizing = false; } }); } }; $.fn.analytics = function (params) { if (params.category) { ga ( 'send', 'event', params.category, params.action, params.label, { nonInteraction: params.nonInteraction } ); } else if (params.page) { if (params.page && params.page != "") { ga ( 'send', 'pageview', params.page ); } else { ga ( 'send', 'pageview' ); } } else { return; } }; $('body').on ('focusout change', 'form[data-form-analytics] input, form[data-form-analytics] select, form[data-form-analytics] textarea', function (event) { var field = $(this); var element = field.get (0); var label = field.attr ("name"); var parent = field.parents ("form").first (); var category = "Form Completion"; if (parent.is ("[data-category]")) category = parent.attr ("data-category"); var identifier = (Math.random () * (9999999999 - 99999) + 99999); if (parent.is ("[id]")) identifier = parent.attr ("id"); if (parent.is ("[data-identifier]")) identifier = parent.attr ("data-identifier"); var action = identifier + '-' + label; var tmp = parent.attr ("data-form-analytics"); var multiFire = false; if (tmp == "multi") multiFire = true; if (field.val ().length !== 0) { if (element.prev && element.prev != field.val ()) element.evented = false; if (multiFire || (!multiFire && !element.evented)) { ga ('send', { hitType: 'event', eventCategory: category, eventAction: action, eventLabel: '' }); /*console.log ('Category: Form Completion, Action: ' + identifier + '-' + label);*/ element.evented = true; element.prev = field.val (); } } }); $.fn.stopFx = function (event) { event.preventDefault (); event.stopPropagation (); event.stopImmediatePropagation (); }; if (navigator.userAgent.match(/Trident\/7\./)) { $body.on ( 'mousewheel', function (e) { e.preventDefault(); var wheelDelta = event.wheelDelta; var currentScrollPosition = window.pageYOffset; window.scrollTo(0, currentScrollPosition - wheelDelta); } ); } // AMD requirement return $ray; }));