Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cookie-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Cookie_Notice {
),
'script_placement' => 'header',
'translate' => true,
'deactivation_delete' => 'no'
'deactivation_delete' => 'no',
'iframe_disable' => true
),
'version' => '1.2.37'
);
Expand Down Expand Up @@ -299,6 +300,7 @@ public function register_settings() {
add_settings_field( 'cn_time', __( 'Cookie expiry', 'cookie-notice' ), array( $this, 'cn_time' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_script_placement', __( 'Script placement', 'cookie-notice' ), array( $this, 'cn_script_placement' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_deactivation_delete', __( 'Deactivation', 'cookie-notice' ), array( $this, 'cn_deactivation_delete' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_iframe_disable', __( 'Iframes', 'cookie-notice' ), array( $this, 'cn_iframe_disable' ), 'cookie_notice_options', 'cookie_notice_configuration' );

// design
add_settings_section( 'cookie_notice_design', __( 'Design', 'cookie-notice' ), array( $this, 'cn_section_design' ), 'cookie_notice_options' );
Expand All @@ -322,6 +324,15 @@ public function cn_deactivation_delete() {
<label><input id="cn_deactivation_delete" type="checkbox" name="cookie_notice_options[deactivation_delete]" value="1" ' . checked( 'yes', $this->options['general']['deactivation_delete'], false ) . '/>' . __( 'Enable if you want all plugin data to be deleted on deactivation.', 'cookie-notice' ) . '</label>';
}

/**
* Disable in iframes.
*/
public function cn_iframe_disable() {
echo '

<label><input id="cn_iframe_disable" type="checkbox" name="cookie_notice_options[iframe_disable]" value="1" ' . checked( 'yes', $this->options['general']['iframe_disable'], false ) . '/>' . __( 'Show cookie notice in iframes.', 'cookie-notice' ) . '</label>';
}

/**
* Cookie message option.
*/
Expand Down Expand Up @@ -628,6 +639,9 @@ public function validate_options( $input ) {
// deactivation
$input['deactivation_delete'] = (bool) isset( $input['deactivation_delete'] ) ? 'yes' : 'no';

// iframe
$input['iframe_disable'] = (bool) isset( $input['iframe_disable'] ) ? 'yes' : 'no';

// read more
$input['see_more'] = (bool) isset( $input['see_more'] ) ? 'yes' : 'no';
$input['see_more_opt']['text'] = sanitize_text_field( isset( $input['see_more_opt']['text'] ) && $input['see_more_opt']['text'] !== '' ? $input['see_more_opt']['text'] : $this->defaults['general']['see_more_opt']['text'] );
Expand Down Expand Up @@ -831,6 +845,7 @@ public function front_load_scripts_styles() {
'hideEffect' => $this->options['general']['hide_effect'],
'onScroll' => $this->options['general']['on_scroll'],
'onScrollOffset' => $this->options['general']['on_scroll_offset'],
'onIframe' => $this->options['general']['iframe_disable'],
'cookieName' => self::$cookie['name'],
'cookieValue' => self::$cookie['value'],
'cookieTime' => $this->times[$this->options['general']['time']][1],
Expand Down
31 changes: 20 additions & 11 deletions js/front.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
(function ($) {
$.fn.isCrossOriginFrame = function () {
try {
return (!window.top.location.hostname);
} catch (e) {
return true;
}
}

// set Cookie Notice
$.fn.setCookieNotice = function (cookie_value) {
Expand Down Expand Up @@ -67,19 +74,21 @@
$(window).on('scroll', cnHandleScroll);
}

// display cookie notice
if (document.cookie.indexOf('cookie_notice_accepted') === -1) {
if (cnArgs.hideEffect === 'fade') {
cnDomNode.fadeIn(300);
} else if (cnArgs.hideEffect === 'slide') {
cnDomNode.slideDown(300);
// check if we're in an iframe
if (!($(this).isCrossOriginFrame() && cnArgs.onIframe == 'no')) {
// display cookie notice
if (document.cookie.indexOf('cookie_notice_accepted') === -1) {
if (cnArgs.hideEffect === 'fade') {
cnDomNode.fadeIn(300);
} else if (cnArgs.hideEffect === 'slide') {
cnDomNode.slideDown(300);
} else {
cnDomNode.show();
}
$('body').addClass('cookies-not-accepted');
} else {
cnDomNode.show();
cnDomNode.removeCookieNotice();
}
$('body').addClass('cookies-not-accepted');
} else {
cnDomNode.removeCookieNotice();
}

})
})(jQuery);
Loading