(function ($) { 'use strict'; /** * All of the code for your public-facing JavaScript source * should reside in this file. * * Note: It has been assumed you will write jQuery code here, so the * $ function reference has been prepared for usage within the scope * of this function. * * This enables you to define handlers, for when the DOM is ready: * * $(function() { * * }); * * When the window is loaded: * * $( window ).load(function() { * * }); * * ...and/or other possibilities. * * Ideally, it is not considered best practise to attach more than a * single DOM-ready or window-load handler for a particular page. * Although scripts in the WordPress core, Plugins and Themes may be * practising this, we should strive to set a better example in our own work. */ var nextBanner = function (adzone) { var active = adzone.getElementsByClassName('active'), a = adzone.querySelectorAll('[data-adfoxly-banner-id]'), z = 0, x = 0, y, bannerId, intervalTime = 5, dataInterval = adzone.getAttribute('data-adfoxly-interval'); if (null != dataInterval && 0 != dataInterval) { intervalTime = dataInterval; } var interval = setInterval(function () { y = z + 1; if (y > a.length - 1) { y = 0; } a[z].setAttribute('class', 'hide'); a[y].setAttribute('class', 'active'); if (x < a.length) { bannerId = a[y].getAttribute('data-adfoxly-banner-id'); saveView(bannerId); // saveView(); x++; } z++; if (z > a.length - 1) { z = 0; } }, intervalTime * 1000); }; // alert(adfoxlyAjax.ajaxurl); var saveView = function (bannerId) { // var saveView = function () { jQuery.ajax({ type: "post", dataType: "json", url: "/wp-admin/admin-ajax.php", data: { action: "adfoxlySaveBannerView", post_id: bannerId }, success: function (response) { // alert('ok'); // console.log(response); }, error: function (response) { // alert("nope"); // console.log('nope'); } // success: function (adzoneBanners) { // } }); }; // function isVisible( $obj ) { // var top = $(window).scrollTop(); // var bottom = top + $(window).height(); // var objTop = $obj.offset().top; // var objBottom = objTop + $obj.height(); // // if(objTop < bottom && objBottom > top) { // console.log('test'); // } // }; document.addEventListener("DOMContentLoaded", function (event) { var adzones; adzones = document.querySelectorAll('[data-adfoxly-interval]'); for (var j = 0; j < adzones.length; j++) { if (adzones[j].hasChildNodes()) { nextBanner(adzones[j]); } } // if (typeof ga !== "function") { // window["GoogleAnalyticsObject"] = "ga"; // window["GoogleAnalyticsObject"] = "ga"; // window["ga"] = window["ga"] || function () { // (window["ga"].q = window["ga"].q || []).push(arguments) // }; // } // if () { // jQuery(".adfoxly-wrapper").click(function (e) { // var $href = jQuery(this).find("a").attr("data-target"); // ga("send", "pageview", $href); // }); // } }); // setInterval(function () { // isVisible($("#adfoxly-adzone-15")); // }, 1000); // check is ga })(jQuery);