Skip to content

Commit

Permalink
debugging, ES3, new features
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoMamerow committed Apr 18, 2017
1 parent 9eadfc7 commit 4e643f2
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 167 deletions.
15 changes: 8 additions & 7 deletions admin/partials/exit-pop-up-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@
<label class="ex3p-label"
for="ex3p-probability"><?php _e( 'Probability', $this->plugin_name ); ?>
:</label>
<input id="ex3p-probability" class="ex3p-input ex3p-input-numbers
small-text"
type="number"
name="<?php echo $this->plugin_name; ?>[probability]" min="0"
max="100" step="1" size="3"
value="<?php echo $options['probability'];
?>"> <?php _e( 'in %', $this->plugin_name ); ?>
<input id="ex3p-probability" class="ex3p-input ex3p-input-numbers small-text" type="number" name="<?php echo $this->plugin_name; ?>[probability]" min="0" max="100" step="1" size="3" value="<?php echo $options['probability']; ?>"> <?php _e( 'in %', $this->plugin_name ); ?>
<br>
<label class="ex3p-label"
for="ex3p-delay"><?php _e( 'Delay', $this->plugin_name ); ?>
Expand Down Expand Up @@ -85,6 +79,13 @@ class="ex3p-image">
name="<?php echo $this->plugin_name; ?>[text]"><?php
echo $options['text']; ?></textarea>
<br>
<label class="ex3p-label ex3p-label-textarea"
for="ex3p-txt"><?php _e( 'Text after submit', $this->plugin_name ); ?>
:</label>
<textarea id="ex3p-txt" class="ex3p-input ex3p-textarea"
name="<?php echo $this->plugin_name; ?>[text-submit]"><?php
echo $options['text-submit']; ?></textarea>
<br>
<label class="ex3p-label"
for="ex3p-btn-y"><?php _e( 'Yes Button', $this->plugin_name ); ?>
:</label>
Expand Down
31 changes: 16 additions & 15 deletions public/class-exit-pop-up-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function localize_script() {
$options = get_option( $this->plugin_name );

$public_dir_path = plugin_dir_path( __FILE__ ) . 'css/variants';
$public_dir_url = plugin_dir_url( __FILE__ ) . 'css/variants/';
$public_dir_url = plugin_dir_url( __FILE__ ) . 'css/variants/';
$public_scandir = scandir( $public_dir_path );
$public_scandir_sliced = array_slice( $public_scandir, 2 );

Expand All @@ -93,20 +93,21 @@ public function localize_script() {
$public_email = __( 'E-Mail', 'exit-pop-up' );

$localize_array = array(
'ex3pProbability' => $options['probability'],
'ex3pDelay' => $options['delay'],
'ex3pPublicJs' => $public_js,
'ex3pPublicCss' => $public_css,
'ex3pClose' => $options['close'],
'ex3p_text' => $options['text'],
'public_url' => $public_url,
'ex3p_action' => $options['action'],
'public_email' => $public_email,
'ex3p_btn_y' => $options['btn-y'],
'ex3p_btn_n' => $options['btn-n'],
'public_img' => $options['image'],
'public_scandir' => $public_scandir_sliced,
'publicDirUrl' => $public_dir_url,
'ex3pProbability' => $options['probability'],
'ex3pDelay' => $options['delay'],
'ex3pPublicJs' => $public_js,
'ex3pPublicCss' => $public_css,
'ex3pClose' => $options['close'],
'ex3p_text' => $options['text'],
'ex3p_text_submit' => $options['text-submit'],
'public_url' => $public_url,
'ex3p_action' => $options['action'],
'public_email' => $public_email,
'ex3p_btn_y' => $options['btn-y'],
'ex3p_btn_n' => $options['btn-n'],
'public_img' => $options['image'],
'public_scandir' => $public_scandir_sliced,
'publicDirUrl' => $public_dir_url,
);
wp_localize_script( $this->plugin_name, 'ex3pObject', $localize_array );
}
Expand Down
1 change: 0 additions & 1 deletion public/css/exit-pop-up-public.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ Exit Pop-up CSS
font-size: 100%;
padding: 10px;
}

130 changes: 83 additions & 47 deletions public/js/exit-pop-up-loader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef,valid-jsdoc */
/**
* Loader script
*
Expand All @@ -19,70 +20,105 @@ var scanDir;
var randFile;
var publicDirUrl;

// Check local store if not empty
if ( 'xxxxxxxxxx' !== localStorage.getItem( 'exit-pop-up-' + window.location.hostname ) ) {
// Load options via object from wp_localize_script.
ex3pProbability = parseInt( ex3pObject.ex3pProbability, 10 );
ex3pPublicJs = ex3pObject.ex3pPublicJs;
ex3pPublicCss = ex3pObject.ex3pPublicCss;
// Load options via object from wp_localize_script.
ex3pProbability = parseInt( ex3pObject.ex3pProbability, 10 );
ex3pPublicJs = ex3pObject.ex3pPublicJs;
ex3pPublicCss = ex3pObject.ex3pPublicCss;

// Get random number between 1 and 100.
ex3pRand = Math.floor( Math.random() * 100 );
/**
* Calculate delay for pop-up loading.
*/
function ex3pDelayFn() {
// Load option via object from wp_localize_script.
ex3pDelay = parseInt( ex3pObject.ex3pDelay, 10 );

/**
* Load the js and css files.
*/
function loadFiles() {
// Load js file
fileref = document.createElement( 'script' );
// value to milliseconds
ex3pDelay *= 1000;

fileref.setAttribute( 'src', ex3pPublicJs );
fileref.setAttribute( 'defer', 'defer' );
// Add more delay randomly
min = 0;
randomDelay = Math.floor( Math.random() * ( ex3pDelay + 1 ) ) + min;
ex3pDelay += randomDelay;

document.getElementsByTagName( 'head' )[ 0 ].appendChild( fileref );
return ex3pDelay;
}

// Load basic css file
fileref = document.createElement( 'link' );
/**
* Load the js file.
*
* @returns {string}
*/
function loadJs() {
// Load js file
fileref = document.createElement( 'script' );

fileref.setAttribute( 'href', ex3pPublicCss );
fileref.setAttribute( 'rel', 'stylesheet' );
fileref.setAttribute( 'type', 'text/css' );
fileref.setAttribute( 'media', 'screen' );
fileref.setAttribute( 'src', ex3pPublicJs );
fileref.setAttribute( 'defer', 'defer' );

document.getElementsByTagName( 'head' )[ 0 ].appendChild( fileref );
return document.getElementsByTagName( 'body' )[ 0 ].appendChild( fileref );
}

// Shuffle a css variant file and load
publicDirUrl = ex3pObject.publicDirUrl;
scanDir = ex3pObject.public_scandir;
randFile = scanDir[ Math.floor( Math.random() * scanDir.length ) ];
/**
* Load the basic css files.
*
* @returns {string}
*/
function loadCssBasic() {
// Load basic css file
fileref = document.createElement( 'link' );

fileref = document.createElement( 'link' );
fileref.setAttribute( 'href', ex3pPublicCss );
fileref.setAttribute( 'rel', 'stylesheet' );
fileref.setAttribute( 'type', 'text/css' );
fileref.setAttribute( 'media', 'screen' );

fileref.setAttribute( 'href', publicDirUrl + randFile );
fileref.setAttribute( 'id', 'ex3p-css-variant' );
fileref.setAttribute( 'rel', 'stylesheet' );
fileref.setAttribute( 'type', 'text/css' );
fileref.setAttribute( 'media', 'screen' );
return document.getElementsByTagName( 'head' )[ 0 ].appendChild( fileref );
}

document.getElementsByTagName( 'head' )[ 0 ].appendChild( fileref );
}
/**
* Load the css variant.
*
* @returns {string}
*/
function loadCssVariant() {
// Shuffle and load a css variant file
publicDirUrl = ex3pObject.publicDirUrl;
scanDir = ex3pObject.public_scandir;
randFile = scanDir[ Math.floor( Math.random() * scanDir.length ) ];

// Load main script for pop-up
if ( ex3pProbability >= ex3pRand ) {
// Load option via object from wp_localize_script.
ex3pDelay = parseInt( ex3pObject.ex3pDelay, 10 );
fileref = document.createElement( 'link' );

fileref.setAttribute( 'href', publicDirUrl + randFile );
fileref.setAttribute( 'id', 'ex3p-css-variant' );
fileref.setAttribute( 'rel', 'stylesheet' );
fileref.setAttribute( 'type', 'text/css' );
fileref.setAttribute( 'media', 'screen' );

// value to milliseconds
ex3pDelay *= 1000;
return document.getElementsByTagName( 'head' )[ 0 ].appendChild( fileref );
}

/**
* Bundle all files functions.
*/
function loadFiles() {
loadJs();
loadCssBasic();
loadCssVariant();
}

// Add more delay randomly
min = 0;
randomDelay = Math.floor( Math.random() * ( ex3pDelay + 1 ) ) + min;
ex3pDelay += randomDelay;
/**
* Load all files with delay.
*/
// Check local store if not empty
if ( 'x' !== localStorage.getItem( 'exit-pop-up-' + window.location.hostname ) ) {
// Get random number between 1 and 100.
ex3pRand = Math.floor( Math.random() * 100 );

// Load main script for pop-up
if ( ex3pProbability >= ex3pRand ) {
// Load files after amount of time.
window.addEventListener( 'load', function () {
setTimeout( loadFiles, ex3pDelay );
setTimeout( loadFiles, ex3pDelayFn() );
} );
}
}
Loading

0 comments on commit 4e643f2

Please sign in to comment.