var spu = { // module rules : null }; SPU_ADMIN = (function ( $ ) { var spu_editor = ''; $(document).ready(function(){ spu.rules.init(); var color_field = $('#spu-appearance input.spu-color-field'), spu_optin = $('#spu_optin'); // Only run if there is no optin being used in premium version if( color_field.length && ( ! spu_optin.length || spu_optin.val() == '' ) ){ color_field.wpColorPicker({ change: applyStyles, clear: applyStyles }); } $("#spu-appearance input,#spu-appearance select").not(".spu-color-field").change(applyStyles); //Toogle trigger boxes on init checkTriggerMethod( $("#spu_trigger").val() ); //Toogle trigger boxes on change $("#spu_trigger").change(function(){ checkTriggerMethod( $(this).val() ); }) /** * Updates on position change */ $('#spu_position').on('change', function(){ var $editor = SPU_ADMIN.spu_editor, val = $(this).val(); //update editor $editor.alterClass('spu-position-*', 'spu-position-'+ val ) if( val == 'top-bar' || val == 'bottom-bar') { $editor.find('.spu-box-container *:not("p, .spu-fields-container, .spu-fields-container *")').remove(); } }); }); /** * When tinyMcr loads */ function TinyMceOptin() { SPU_ADMIN.spu_editor = $("#content_ifr").contents().find('html #tinymce'); // add position class SPU_ADMIN.spu_editor.addClass(' spu-position-' + spu_js.opts.css.position).removeClass('wp-autoresize'); applyStyles(); } function checkTriggerMethod( val ) { if( val == 'pixels' || val == 'percentage' || val == 'visible') { $('tr.auto_hide').fadeIn('fast'); } else { $('tr.auto_hide').fadeOut('fast'); }/*TODO I should fix premium so these values are not even considered here*/ if( val == 'manual' || val == 'trigger-click' || val == 'visible' || val == 'exit-intent') { $('.spu-trigger-number').fadeOut('fast'); } else { $('.spu-trigger-number').fadeIn('fast'); } } // functions function getPxValue($el, retval) { if($el.val()) { return parseInt($el.val()); } else { return (retval !== undefined) ? retval + "px" : 0; } } function getColor($el, retval) { if($el.val().length > 0) { return $el.wpColorPicker('color'); } else { return (retval !== undefined) ? retval : ''; } } function applyStyles() { var $editor = $("#content_ifr").contents().find('html'); $editor.trigger('spu_tinymce_init'); $editor.css({ 'background': spu_hexToRgb(getColor($("#spu_bgcolor")),$("#spu_bgopacity").val()) }); // if there is no optin mode load defaults if (typeof spup_js == "undefined" || $('#spu_optin').val() == '') { // remove any field that could be there after deactivating premium version $editor.find(".spu-fields-container").remove(); $editor.find("#tinymce").attr('style', 'padding: ' + getPxValue($("#spu-padding")) + 'px !important'); $editor.find("#tinymce").css({ 'background-color': spu_hexToRgb(getColor($("#spu-background-color")),$("#spu_background_opacity").val()), 'border-color': getColor($("#spu-border-color")), 'border-width': getPxValue($("#spu-border-width")), 'border-style': $("#spu-border-type").val(), 'width': $("#spu-width").val(), 'color': getColor($("#spu-color")), 'height': 'auto', 'min-width': '200px', 'max-width': '100%', 'margin': '8px auto 0;', 'box-shadow': ($("#spu-shadow-type").val() == 'inset' ? 'inset' : '') +' '+ $("#spu-shadow-x").val() + 'px ' + $("#spu-shadow-y").val() + 'px ' + $("#spu-shadow-blur").val() + 'px ' + $("#spu-shadow-spread").val() + 'px ' + getColor($("#spu-shadow-color")) }); var img_src = $('#spu_bgimage').val(); $editor.find("#tinymce").css({ 'background-image': 'url("'+img_src+'")', 'background-size' : 'cover' }); } } /* * Rules * * Js for needed for rules * * @since: 1.0.0 * Thanks to advanced custom fields plugin for part of this code */ spu.rules = { $el : null, init : function(){ // vars var _this = this; // $el _this.$el = $('#spu-rules'); // add rule _this.$el.on('click', '.rules-add-rule', function(){ _this.add_rule( $(this).closest('tr') ); return false; }); // remove rule _this.$el.on('click', '.rules-remove-rule', function(){ _this.remove_rule( $(this).closest('tr') ); return false; }); // add rule _this.$el.on('click', '.rules-add-group', function(){ _this.add_group(); return false; }); // change rule _this.$el.on('change', '.param select', function(){ // vars var $tr = $(this).closest('tr'), rule_id = $tr.attr('data-id'), $group = $tr.closest('.rules-group'), group_id = $group.attr('data-id'), val_td = $tr.find('td.value'), ajax_data = { 'action' : "spu/field_group/render_rules", 'nonce' : spu_js.nonce, 'rule_id' : rule_id, 'group_id' : group_id, 'value' : '', 'param' : $(this).val() }; // add loading gif var div = $('