Almost finished with js cookie logic
This commit is contained in:
@ -22,11 +22,13 @@ class CWV3 {
|
|||||||
wp_enqueue_style( 'cwv3_css' );
|
wp_enqueue_style( 'cwv3_css' );
|
||||||
wp_enqueue_script( 'cwv3_js' );
|
wp_enqueue_script( 'cwv3_js' );
|
||||||
|
|
||||||
|
$cookie_death = get_option( 'cwv3_death', 1 );
|
||||||
|
|
||||||
wp_localize_script( 'cwv3_js', 'cwv3_params', array(
|
wp_localize_script( 'cwv3_js', 'cwv3_params', array(
|
||||||
'opacity' => get_option( 'cwv3_bg_opacity', 0.85 ),
|
'opacity' => get_option( 'cwv3_bg_opacity', 0.85 ),
|
||||||
'cookie_path' => SITECOOKIEPATH,
|
'cookie_path' => SITECOOKIEPATH,
|
||||||
'cookie_name' => $this->get_cookie_name(),
|
'cookie_name' => $this->get_cookie_name(),
|
||||||
'cookie_time' => $cookie_death,
|
'cookie_time' => intval( $cookie_death ) > 365 ? 365 : intval( $cookie_death ),
|
||||||
'denial_enabled' => get_option( 'cwv3_denial', 'enabled' ),
|
'denial_enabled' => get_option( 'cwv3_denial', 'enabled' ),
|
||||||
'denial_method' => get_option( 'cwv3_method_show', 'redirect' ),
|
'denial_method' => get_option( 'cwv3_method_show', 'redirect' ),
|
||||||
'redirect_url' => esc_js( get_option( 'cwv3_exit_link', '#' ) ),
|
'redirect_url' => esc_js( get_option( 'cwv3_exit_link', '#' ) ),
|
||||||
|
@ -63,8 +63,8 @@ function cwv3_get_js_dialog(){
|
|||||||
ob_start();
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<!-- CWV3 JS Dialog -->
|
<!-- CWV3 JS Dialog -->
|
||||||
<div class="cwv3 dialog-overlay"> </div>
|
<div class="cwv3 dialog-overlay" style="display:none;"> </div>
|
||||||
<div id="cwv3_dialog" class="cwv3_dialog js">
|
<div id="cwv3_dialog" class="cwv3_dialog js" style="display:none;">
|
||||||
<div class="cwv3 auth">
|
<div class="cwv3 auth">
|
||||||
<div class="cwv3_title"><?php echo esc_attr( $cwv3_title ); ?></div>
|
<div class="cwv3_title"><?php echo esc_attr( $cwv3_title ); ?></div>
|
||||||
<div class="cwv3_content"><?php echo wp_kses_post( $cwv3_message ); ?></div>
|
<div class="cwv3_content"><?php echo wp_kses_post( $cwv3_message ); ?></div>
|
||||||
|
65
js/cwv3.js
65
js/cwv3.js
@ -1,15 +1,18 @@
|
|||||||
/* global cwv3_params */
|
/* global cwv3_params*/
|
||||||
|
|
||||||
|
|
||||||
window.cwv3 = ( function( window, document, $ ){
|
window.cwv3 = ( function( window, document, $ ){
|
||||||
|
|
||||||
var app = {};
|
var app = {};
|
||||||
|
|
||||||
app.cache = function(){
|
app.cache = function(){
|
||||||
app.$dialog = $('.cwv3_dialog');
|
app.$dialog = $('.cwv3_dialog');
|
||||||
app.$auth = app.$dialog.find( '.cwv3.auth' );
|
app.$auth = app.$dialog.find( '.cwv3.auth' );
|
||||||
app.$denial = app.$dialog.find( '.cwv3.denied' );
|
app.$denial = app.$dialog.find( '.cwv3.denied' );
|
||||||
app.$exit = app.$dialog.find( '.cwv3_exit' );
|
app.$exit = app.$dialog.find( '.cwv3_exit' );
|
||||||
app.$enter = app.$dialog.find( '.cwv3_enter' );
|
app.$enter = app.$dialog.find( '.cwv3_enter' );
|
||||||
app.cookie_name = ( '' !== cwv3_params.cookie_name ) ? 'cwv3_cookie_' + cwv3_params.cookie_name : false;
|
app.$overlay = $( '.cwv3.dialog-overlay' );
|
||||||
|
app.cookie_name = ( '' !== cwv3_params.cookie_name ) ? 'cwv3_cookie_' + cwv3_params.cookie_name : false;
|
||||||
app.redirect_url = ( '' === cwv3_params.redirect_url || '#' === cwv3_params.redirect_url ) ? 'http://google.com' : cwv3_params.redirect_url;
|
app.redirect_url = ( '' === cwv3_params.redirect_url || '#' === cwv3_params.redirect_url ) ? 'http://google.com' : cwv3_params.redirect_url;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,44 +23,74 @@ window.cwv3 = ( function( window, document, $ ){
|
|||||||
$( 'body' ).on( 'click', '.cwv3_enter', app.enter_handler );
|
$( 'body' ).on( 'click', '.cwv3_enter', app.enter_handler );
|
||||||
$( 'body' ).on( 'click', '.cwv3_exit', app.exit_handler );
|
$( 'body' ).on( 'click', '.cwv3_exit', app.exit_handler );
|
||||||
|
|
||||||
|
|
||||||
if( app.cookie_name ){
|
if( app.cookie_name ){
|
||||||
// We need to set a cookie, so show the dialog.
|
// We need to set a cookie, so show the dialog.
|
||||||
app.show_popup();
|
app.dialog_switch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app.enter_handler = function( evt ){
|
app.enter_handler = function( evt ){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
// Have to set the cookie first.
|
||||||
|
app.set_cookie( 'enter' );
|
||||||
|
var $enter_url = app.$enter.find( 'a' ).attr( 'href' );
|
||||||
|
if( '#' === $enter_url || '' === $enter_url ){
|
||||||
|
app.close_handler();
|
||||||
|
} else {
|
||||||
|
window.location.replace( $enter_url );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// opacity cookie_path cookie_name cookie_time denial_enabled denial_method redirect_url
|
||||||
app.exit_handler = function( evt ){
|
app.exit_handler = function( evt ){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
app.set_cookie( 'exit' );
|
||||||
|
var $exit_url = app.$exit.find( 'a' ).attr( 'href' );
|
||||||
|
if( '#' === $exit_url || '' === $exit_url ){
|
||||||
|
window.location.replace( 'http://google.com' );
|
||||||
|
} else {
|
||||||
|
window.location.replace( $exit_url );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
app.set_cookie = function(){
|
app.set_cookie = function( method ){
|
||||||
// Set the cookie
|
// Set the cookie
|
||||||
|
method = method === 'exit' ? 'denied' : true;
|
||||||
|
$.cookie( app.cookie_name, method, {
|
||||||
|
expires : parseInt( cwv3_params.cookie_time ),
|
||||||
|
path : cwv3_params.cookie_path,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.show_popup = function(){
|
app.close_handler = function(){
|
||||||
|
app.$dialog.fadeOut( 100, function(){
|
||||||
|
app.$overlay.fadeOut( 100 );
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.dialog_switch = function(){
|
app.dialog_switch = function(){
|
||||||
var cookie_data = $.cookie( app.cookie_name );
|
var cookie_data = $.cookie( app.cookie_name );
|
||||||
|
console.log( app.cookie_name );
|
||||||
if( 'denied' === cookie_data ){
|
if( 'denied' === cookie_data ){
|
||||||
//app.$auth.remove(); // Remove the main dialog
|
app.$auth.remove(); // Remove the main dialog
|
||||||
if( 'redirect' === cwv3_params.denial_method ){
|
if( 'redirect' === cwv3_params.denial_method ){
|
||||||
window.location.replace( app.redirect_url );
|
window.location.replace( app.redirect_url );
|
||||||
|
} else {
|
||||||
|
app.show_popup();
|
||||||
}
|
}
|
||||||
} else if( undefined === cookie_data ){
|
} else if( undefined === cookie_data ){
|
||||||
app.$denial.remove(); // Remove the denied box instead.
|
app.$denial.remove(); // Remove the denied box instead.
|
||||||
|
app.show_popup();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.show_popup = function(){
|
||||||
|
app.$overlay.fadeIn( 200, function(){
|
||||||
|
app.$dialog.fadeIn( 100 );
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$( document ).ready( app.init );
|
$( document ).ready( app.init );
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
2
js/cwv3.min.js
vendored
2
js/cwv3.min.js
vendored
@ -1 +1 @@
|
|||||||
window.cwv3=function(window,document,$){var app={};return app.cache=function(){app.$dialog=$(".cwv3_dialog"),app.$auth=app.$dialog.find(".cwv3.auth"),app.$denial=app.$dialog.find(".cwv3.denied"),app.$exit=app.$dialog.find(".cwv3_exit"),app.$enter=app.$dialog.find(".cwv3_enter"),app.cookie_name=""!==cwv3_params.cookie_name?"cwv3_cookie_"+cwv3_params.cookie_name:!1,app.redirect_url=""===cwv3_params.redirect_url||"#"===cwv3_params.redirect_url?"http://google.com":cwv3_params.redirect_url},app.init=function(){app.cache(),$("body").on("click",".cwv3_enter",app.enter_handler),$("body").on("click",".cwv3_exit",app.exit_handler),app.cookie_name&&app.show_popup()},app.enter_handler=function(evt){evt.preventDefault()},app.exit_handler=function(evt){evt.preventDefault()},app.set_cookie=function(){},app.show_popup=function(){},app.dialog_switch=function(){var cookie_data=$.cookie(app.cookie_name);"denied"===cookie_data?"redirect"===cwv3_params.denial_method&&window.location.replace(app.redirect_url):void 0===cookie_data&&app.$denial.remove()},$(document).ready(app.init),app}(window,document,jQuery);
|
window.cwv3=function(window,document,$){var app={};return app.cache=function(){app.$dialog=$(".cwv3_dialog"),app.$auth=app.$dialog.find(".cwv3.auth"),app.$denial=app.$dialog.find(".cwv3.denied"),app.$exit=app.$dialog.find(".cwv3_exit"),app.$enter=app.$dialog.find(".cwv3_enter"),app.$overlay=$(".cwv3.dialog-overlay"),app.cookie_name=""!==cwv3_params.cookie_name?"cwv3_cookie_"+cwv3_params.cookie_name:!1,app.redirect_url=""===cwv3_params.redirect_url||"#"===cwv3_params.redirect_url?"http://google.com":cwv3_params.redirect_url},app.init=function(){app.cache(),$("body").on("click",".cwv3_enter",app.enter_handler),$("body").on("click",".cwv3_exit",app.exit_handler),app.cookie_name&&app.dialog_switch()},app.enter_handler=function(evt){evt.preventDefault(),app.set_cookie("enter");var $enter_url=app.$enter.find("a").attr("href");"#"===$enter_url||""===$enter_url?app.close_handler():window.location.replace($enter_url)},app.exit_handler=function(evt){evt.preventDefault(),app.set_cookie("exit");var $exit_url=app.$exit.find("a").attr("href");window.location.replace("#"===$exit_url||""===$exit_url?"http://google.com":$exit_url)},app.set_cookie=function(method){method="exit"===method?"denied":!0,$.cookie(app.cookie_name,method,{expires:parseInt(cwv3_params.cookie_time),path:cwv3_params.cookie_path})},app.close_handler=function(){app.$dialog.fadeOut(100,function(){app.$overlay.fadeOut(100)})},app.dialog_switch=function(){var cookie_data=$.cookie(app.cookie_name);console.log(app.cookie_name),"denied"===cookie_data?(app.$auth.remove(),"redirect"===cwv3_params.denial_method?window.location.replace(app.redirect_url):app.show_popup()):void 0===cookie_data&&(app.$denial.remove(),app.show_popup())},app.show_popup=function(){app.$overlay.fadeIn(200,function(){app.$dialog.fadeIn(100)})},$(document).ready(app.init),app}(window,document,jQuery);
|
Reference in New Issue
Block a user