/*
an_scripts.js
AdBlock Notify
Copyright: (c) 2014 Brice CAPOBIANCO, b-website.com
*/
jQuery(document).ready(function($) {
//define global testing var
var $an_state = null;
/* Detection
/* ------------------------------------ */
$(window).load(function() {
setTimeout(function() {
//launch FIRST test (js file) - check if advertisement is blocked or not
if ($.adblockJsFile === undefined){
$an_state=true;
}
//launch SECOND test (jQuery) - check adsense element height
if( $an_state !== true && $('#adsense.an-sponsored').length > 0 ){
if ($('#adsense.an-sponsored').outerHeight() == 0){
$an_state=true;
$('#adsense.an-sponsored').remove();
}
}
//do action
an_message_display($an_state);
}, 100);
});
/* Do action
/* ------------------------------------ */
function an_message_display($an_state){
if($an_state === true ){
//IF MODAL BOX IS ACTIVATED
if ( ( anOptions.anOptionChoice == 2 && anOptions.anOptionCookie == 1 && getCookie('anCookie') !== 'true' ) || ( anOptions.anOptionChoice == 2 && anOptions.anOptionCookie == 2 ) ) {
if(anOptions.anOptionModalBxtitle != ''){
var headingColor = 'style="color:'+ anOptions.anOptionModalBxtitle +'"';
} else {
var headingColor = '';
}
$('#an-Modal').prepend('
' + anOptions.anModalTitle + '
' + anOptions.anModalText +'×');
$('#an-Modal').bind('reveal:open', function () { //on modale box open
$('.reveal-modal-bg').css({ //apply custom style
'background': anOptions.anOptionModalOverlay
});
//fixed for IE8
if(jQuery.browser.version.substring(0, 2) <= "10.") {
$('#an-Modal').css("left", Math.max(0, (($(window).width() - $('#an-Modal').outerWidth()) / 2) + $(window).scrollLeft()) + "px");
}
});
$('#an-Modal').reveal({
animation: anOptions.anOptionModalEffect, //fade, fadeAndPop, none
animationspeed: anOptions.anOptionModalspeed, //how fast animtions are
closeonbackgroundclick: anOptions.anOptionModalclose, //if you click background will modal close?
dismissmodalclass: 'close-reveal-modal' //the class of a button or element that will close an open modal
}).trigger('reveal:open');
$('#an-Modal').bind('reveal:close', function () { //on modale box close
$('#an-Modal p, #an-Modal a').fadeOut(150); //fix for visual elements
setCookie('anCookie', 'true', anOptions.anOptionCookieLife); //set cookie to true
setTimeout(function() {
$('#an-Modal, .reveal-modal-bg').remove();
}, anOptions.anOptionModalspeed);
});
//IF PAGE REDIRECT IS ACTIVATED
} else if (anOptions.anOptionChoice == 3 && anOptions.anPermalink !== 'undefined' && getCookie('anCookie') !== 'true'){
setCookie('anCookie', 'true', anOptions.anOptionCookieLife); //set cookie to true
window.location.replace(anOptions.anPermalink); //redirect to user page
}
//IF AD PLACEHOLDER IS ACTIVATED
if ( anOptions.anAlternativeActivation == true && anOptions.anAlternativeElement != '') {
$(anOptions.anAlternativeElement).each(function(i, obj) {
var $element = $(this);
if (($element.outerHeight() == 0) || ($element.size() <= 2)){
if ( anOptions.anAlternativeClone < 4){
var elementType = $element[0].tagName;
var newElement = document.createElement(elementType),
newElement = $(newElement);
} else {
var newElement = document.createElement('DIV'),
newElement = $(newElement);
}
if ( anOptions.anAlternativeClone == 1 && anOptions.anAlternativeProperties != '' ) {
var copiedStyles = getStyleObjectCss($element);
if(typeof (copiedStyles) == 'undefined'){
var copiedStyles = $element.getStyleObject();
}
newElement.css(copiedStyles);
var anAskedCSS = anOptions.anAlternativeProperties.split(' ').join('');
console.log(anAskedCSS);
var arrayProperties = new Array();
arrayProperties = anAskedCSS.split(',');
var anKeepCSS = [];
$.each( arrayProperties, function(item, value) {
var elProperty = newElement.css(value);
if (typeof elProperty !== 'undefined'){
if(elProperty !== ''){
anKeepCSS.push(value + ':' + elProperty +';');
}
}
});
anKeepCSS = anKeepCSS.join('');
newElement.removeAttr('style').attr("style",anKeepCSS);
} else if ( anOptions.anAlternativeClone == 2 ) {
var copiedStyles = getStyleObjectCss($element);
if(typeof (copiedStyles) == 'undefined'){
var copiedStyles = $element.getStyleObject();
}
newElement.css(copiedStyles).css(anExcludeRules);
} else if ( anOptions.anAlternativeClone == 3 ) {
var copiedStyles = $element.getStyleObject();
newElement.css(copiedStyles).css(anExcludeRules);
}
newElement.html(anOptions.anAlternativeText);
$element.before(newElement);
newElement.addClass('an-alternative').fadeIn(300);
};
});
};
an_blocker_counter(['total','blocked']); //adblocker detected
} else {
//IF AD BLOCKER IS DEACTIVATED
if ( getCookie('anCookie') == 'true') {
an_blocker_counter(['total','deactivated']); //adblocker deactivated
setCookie('anCookie', '', anOptions.anOptionCookieLife); //set cookie to true
} else {
an_blocker_counter(['total']); //no adblocker
}
}
}
//COUNT PAGE VIEWS WITH ADBLOCKER
function an_blocker_counter(value){
if(anOptions.anOptionStats != 2){
$.post(ajax_object.ajaxurl, {
action: 'call_an_adblock_counter',
an_state: value
});
return false;
}
};
/* Fetch all DEFINED Element CSS Properties
/* Source: http://stackoverflow.com/a/5830517
/* ------------------------------------ */
function getStyleObjectCss(element) {
var sheets = document.styleSheets, o = {};
for (var i in sheets) {
try {
if(typeof (sheets[i].cssRules) != 'undefined'){
var rules = sheets[i].rules || sheets[i].cssRules;
for (var r in rules) {
if (element.is(rules[r].selectorText)) {
o = $.extend(o, css2json(rules[r].style), css2json(element.attr('style')));
}
}
}
} catch(e){
return;
}
}
return o;
}
function css2json(css) {
var s = {};
if (!css) return s;
if (css instanceof CSSStyleDeclaration) {
for (var i in css) {
if ((css[i]).toLowerCase) {
s[(css[i]).toLowerCase()] = (css[css[i]]);
}
}
} else if (typeof css == "string") {
css = css.split("; ");
for (var i in css) {
var l = css[i].split(": ");
s[l[0].toLowerCase()] = (l[1]);
}
}
return s;
}
/* Fetch ALL Element CSS Properties
/* Source: http://stackoverflow.com/a/5830517
/* ------------------------------------ */
$.fn.getStyleObject = function(){
var dom = this.get(0);
var style;
var returns = {};
if(window.getComputedStyle){
var camelize = function(a,b){
return b.toUpperCase();
};
style = window.getComputedStyle(dom, null);
for(var i = 0, l = style.length; i < l; i++){
var prop = style[i];
var camel = prop.replace(/\-([a-z])/, camelize);
var val = style.getPropertyValue(prop);
returns[camel] = val;
};
return returns;
};
if(style = dom.currentStyle){
for(var prop in style){
returns[prop] = style[prop];
};
return returns;
};
if(style = dom.style){
for(var prop in style){
if(typeof style[prop] != 'function'){
returns[prop] = style[prop];
}
}
return returns;
}
return returns;
}
/* Initiate cookies functions
/* ------------------------------------ */
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i').insertAfter(modal);
}
/*---------------------------
Open & Close Animations
----------------------------*/
//Entrance Animations
modal.bind('reveal:open', function () {
modalBG.unbind('click.modalEvent');
$('.' + options.dismissmodalclass).unbind('click.modalEvent');
if(!locked) {
lockModal();
if(options.animation == "fadeAndPop") {
modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'});
modalBG.fadeIn(options.animationspeed/2);
modal.delay(options.animationspeed/2).animate({
"top": $(document).scrollTop()+topMeasure + 'px',
"opacity" : 1
}, options.animationspeed,unlockModal());
}
if(options.animation == "fade") {
modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure});
modalBG.fadeIn(options.animationspeed/2);
modal.delay(options.animationspeed/2).animate({
"opacity" : 1
}, options.animationspeed,unlockModal());
}
if(options.animation == "none") {
modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
modalBG.css({"display":"block"});
unlockModal()
}
}
modal.unbind('reveal:open');
});
//Closing Animation
modal.bind('reveal:close', function () {
if(!locked) {
lockModal();
if(options.animation == "fadeAndPop") {
modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
modal.animate({
"top": $(document).scrollTop()-topOffset + 'px',
"opacity" : 0
}, options.animationspeed/2, function() {
modal.css({'top':topMeasure, 'opacity' : 1, 'visibility' : 'hidden'});
unlockModal();
});
}
if(options.animation == "fade") {
modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
modal.animate({
"opacity" : 0
}, options.animationspeed, function() {
modal.css({'opacity' : 1, 'visibility' : 'hidden', 'top' : topMeasure});
unlockModal();
});
}
if(options.animation == "none") {
modal.css({'visibility' : 'hidden', 'top' : topMeasure});
modalBG.css({'display' : 'none'});
}
}
modal.unbind('reveal:close');
});
/*---------------------------
Open and add Closing Listeners
----------------------------*/
//Open Modal Immediately
modal.trigger('reveal:open')
//Close Modal Listeners
var closeButton = $('.' + options.dismissmodalclass).bind('click.modalEvent', function () {
modal.trigger('reveal:close')
});
if(options.closeonbackgroundclick) {
modalBG.css({"cursor":"pointer"})
modalBG.bind('click.modalEvent', function () {
modal.trigger('reveal:close')
});
}
$('body').keyup(function(e) {
if(e.which===27){ modal.trigger('reveal:close'); } // 27 is the keycode for the Escape key
});
/*---------------------------
Animations Locks
----------------------------*/
function unlockModal() {
locked = false;
}
function lockModal() {
locked = true;
}
});//each call
}//orbit plugin call
})(jQuery);