| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895 |
- /*******************************************************************************
- * Copyright (c) 2020, Code Atlantic LLC
- ******************************************************************************/
- ( function( $ ) {
- 'use strict';
- window.PUM_Admin = window.PUM_Admin || {};
- window.pum_popup_settings_editor = window.pum_popup_settings_editor || {
- form_args: {},
- current_values: {},
- };
- $( document )
- .on( 'keydown', '#popup-title', function( event ) {
- var keyCode = event.keyCode || event.which;
- if ( 9 === keyCode ) {
- event.preventDefault();
- $( '#title' ).focus();
- }
- } )
- .on( 'keydown', '#title, #popup-title', function( event ) {
- var keyCode = event.keyCode || event.which,
- target;
- if ( ! event.shiftKey && 9 === keyCode ) {
- event.preventDefault();
- target =
- $( this ).attr( 'id' ) === 'title'
- ? '#popup-title'
- : '#insert-media-button';
- $( target ).focus();
- }
- } )
- .on( 'keydown', '#popup-title, #insert-media-button', function(
- event
- ) {
- var keyCode = event.keyCode || event.which,
- target;
- if ( event.shiftKey && 9 === keyCode ) {
- event.preventDefault();
- target =
- $( this ).attr( 'id' ) === 'popup-title'
- ? '#title'
- : '#popup-title';
- $( target ).focus();
- }
- } );
- // Initiate when ready.
- $( function() {
- $( this ).trigger( 'pum_init' );
- $( '#title' ).prop( 'required', true );
- var $container = $( '#pum-popup-settings-container' ),
- args = pum_popup_settings_editor.form_args || {},
- values = pum_popup_settings_editor.current_values || {};
- if ( $container.length ) {
- $container.find( '.pum-no-js' ).hide();
- PUM_Admin.forms.render( args, values, $container );
- }
- $( 'a.page-title-action' )
- .clone()
- .attr( 'target', '_blank' )
- .attr(
- 'href',
- pum_admin_vars.homeurl +
- '?popup_preview=true&popup=' +
- $( '#post_ID' ).val()
- )
- .text( pum_admin_vars.I10n.preview_popup )
- .insertAfter( 'a.page-title-action' );
- // TODO Can't figure out why this is needed, but it looks stupid otherwise when the first condition field defaults to something other than the placeholder.
- $( '#pum-first-condition, #pum-first-trigger, #pum-first-cookie' )
- .val( null )
- .trigger( 'change' );
- // Add event handler to detect when opening sound is change and play the sound to allow admin to preview it.
- document
- .querySelector( '#pum-popup-settings-container' )
- .addEventListener( 'change', function( e ) {
- if ( 'open_sound' === e.target.id ) {
- // Only play if the sound selected is not None or Custom.
- var notThese = [ 'none', 'custom' ];
- if ( notThese.indexOf( e.target.value ) === -1 ) {
- var audio = new Audio(
- pum_admin_vars.pm_dir_url +
- '/assets/sounds/' +
- e.target.value
- );
- audio.addEventListener(
- 'canplaythrough',
- function() {
- this.play().catch( function( reason ) {
- console.warn(
- 'Sound was not able to play when selected. Reason: ' +
- reason
- );
- } );
- }
- );
- audio.addEventListener( 'error', function() {
- console.warn(
- 'Error occurred when trying to load popup opening sound.'
- );
- } );
- }
- }
- } );
- // Dynamically switches example click trigger from popup-{popup-id} to using real ID.
- $( document ).on( 'pum_init', function() {
- $(
- '#pum-default-click-trigger-class:not(.pum-click-trigger-initialized)'
- ).each( function() {
- $( this )
- .addClass( 'pum-click-trigger-initialized' )
- .text( $( '#popup-id' ).data( 'popup-id' ) );
- } );
- } );
- document
- .querySelector( '#pum-popup-settings-container' )
- .addEventListener( 'click', function( e ) {
- if (
- Array.from( e.target.classList ).includes(
- 'popup-type'
- ) ||
- Array.from( e.target.parentElement.classList ).includes(
- 'popup-type'
- )
- ) {
- var $container = jQuery(
- '#pum-popup-settings-container'
- );
- if ( 1 === $container.length ) {
- // Our initial presets. As we add more, consider creating JSON import system and moving to there.
- var popupTypes = {
- 'center-popup': {
- size: 'medium',
- responsive_min_width: '0%',
- responsive_max_width: '100%',
- animation_type: 'fade',
- animation_speed: 350,
- location: 'center',
- position_fixed: false,
- position_from_trigger: false,
- overlay_disabled: false,
- stackable: false,
- disable_reposition: false,
- },
- 'left-bottom-notice': {
- size: 'tiny',
- responsive_min_width: '0%',
- responsive_max_width: '100%',
- animation_type: 'fade',
- animation_speed: 350,
- animation_origin: 'left bottom',
- location: 'left bottom',
- position_bottom: 10,
- position_left: 10,
- position_from_trigger: false,
- position_fixed: true,
- overlay_disabled: true,
- stackable: true,
- disable_reposition: false,
- },
- 'top-bar': {
- size: 'custom',
- custom_width: '100%',
- custom_height_auto: true,
- animation_type: 'fadeAndSlide',
- animation_speed: 300,
- animation_origin: 'top',
- location: 'center top',
- position_top: 0,
- position_from_trigger: false,
- position_fixed: true,
- overlay_disabled: true,
- stackable: true,
- disable_reposition: false,
- },
- 'right-bottom-slidein': {
- size: 'custom',
- custom_width: '300px',
- custom_height_auto: true,
- animation_type: 'slide',
- animation_speed: 350,
- animation_origin: 'bottom',
- location: 'right bottom',
- position_bottom: 10,
- position_right: 10,
- position_from_trigger: false,
- position_fixed: true,
- overlay_disabled: true,
- stackable: true,
- disable_reposition: false,
- },
- };
- var popupType =
- e.target.dataset.popupType ||
- e.target.parentElement.dataset.popupType ||
- '';
- // Gather our values needed for creating new settings object.
- var presetValues = popupTypes.hasOwnProperty(
- popupType
- )
- ? popupTypes[ popupType ]
- : {};
- var args =
- pum_popup_settings_editor.form_args || {};
- var originalValues =
- pum_popup_settings_editor.current_values || {};
- var currentValues = $container.pumSerializeObject();
- // pumSerializeObject returns the trigger/cookie settings as strings instead of objects.
- // Cycle through each trigger and cookie and convert to objects.
- if ( currentValues.popup_settings.triggers ) {
- for (
- var i = 0;
- i <
- currentValues.popup_settings.triggers
- .length;
- i++
- ) {
- currentValues.popup_settings.triggers[
- i
- ].settings = JSON.parse(
- currentValues.popup_settings.triggers[
- i
- ].settings
- );
- }
- }
- if ( currentValues.popup_settings.cookies ) {
- for (
- var j = 0;
- j <
- currentValues.popup_settings.cookies.length;
- j++
- ) {
- currentValues.popup_settings.cookies[
- j
- ].settings = JSON.parse(
- currentValues.popup_settings.cookies[
- j
- ].settings
- );
- }
- }
- var newValues = Object.assign(
- {},
- originalValues,
- currentValues.popup_settings,
- presetValues
- );
- // Re-render form using updated settings.
- PUM_Admin.forms.render(
- args,
- newValues,
- $container
- );
- // Click to 'Display' so they don't jump to 'Targeting' tab upon render.
- document
- .querySelector(
- 'a[href="#pum-popup-settings_display"]'
- )
- .click();
- // Adds a notice into 'Display Presets' tab telling admin the settings have been applied.
- var notice = document.createElement( 'div' );
- notice.classList.add( 'notice', 'updated' );
- notice.insertBefore(
- document.createElement( 'p' ),
- notice.firstChild
- );
- notice.firstChild.innerText =
- 'Display settings have been updated with the ' +
- popupType +
- ' preset';
- var parent = document.querySelector(
- '#pum-popup-settings-display-subtabs_preset'
- );
- parent.insertBefore( notice, parent.firstChild );
- }
- }
- } );
- } );
- } )( jQuery );
- ( function( $, document, undefined ) {
- 'use strict';
- $( document ).on( 'click', '#popup_reset_open_count', function() {
- var $this = $( this );
- if (
- $this.is( ':checked' ) &&
- ! confirm( pum_admin_vars.I10n.confirm_count_reset )
- ) {
- $this.prop( 'checked', false );
- }
- } );
- } )( jQuery, document );
- ( function( $ ) {
- 'use strict';
- var conditions = {
- get_conditions: function() {
- return window.pum_popup_settings_editor.conditions_selectlist;
- },
- not_operand_checkbox: function( $element ) {
- $element = $element || $( '.pum-not-operand' );
- return $element.each( function() {
- var $this = $( this ),
- $input = $this.find( 'input' );
- $input.prop( 'checked', ! $input.is( ':checked' ) );
- conditions.toggle_not_operand( $this );
- } );
- },
- toggle_not_operand: function( $element ) {
- $element = $element || $( '.pum-not-operand' );
- return $element.each( function() {
- var $this = $( this ),
- $input = $this.find( 'input' ),
- // $is = $this.find('.is'),
- // $not = $this.find('.not'),
- $container = $this.parents( '.facet-target' );
- if ( $input.is( ':checked' ) ) {
- // $is.hide();
- // $not.show();
- $container.addClass( 'not-operand-checked' );
- } else {
- // $is.show();
- // $not.hide();
- $container.removeClass( 'not-operand-checked' );
- }
- } );
- },
- template: {
- editor: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- groups: [],
- },
- args
- );
- data.groups = PUM_Admin.utils.object_to_array( data.groups );
- return PUM_Admin.templates.render(
- 'pum-condition-editor',
- data
- );
- },
- group: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- index: '',
- facets: [],
- },
- args
- ),
- i;
- data.facets = PUM_Admin.utils.object_to_array( data.facets );
- for ( i = 0; data.facets.length > i; i++ ) {
- data.facets[ i ].index = i;
- data.facets[ i ].group = data.index;
- }
- return PUM_Admin.templates.render(
- 'pum-condition-group',
- data
- );
- },
- facet: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- group: '',
- index: '',
- target: '',
- not_operand: false,
- settings: {},
- },
- args
- );
- return PUM_Admin.templates.render(
- 'pum-condition-facet',
- data
- );
- },
- settings: function( args, values ) {
- var fields = [],
- data = $.extend(
- true,
- {},
- {
- index: '',
- group: '',
- target: null,
- fields: [],
- },
- args
- );
- if (
- ! data.fields.length &&
- pum_popup_settings_editor.conditions[ args.target ] !==
- undefined
- ) {
- data.fields =
- pum_popup_settings_editor.conditions[
- args.target
- ].fields;
- }
- if ( undefined === values ) {
- values = {};
- }
- // Replace the array with rendered fields.
- _.each( data.fields, function( field, fieldID ) {
- field = PUM_Admin.models.field( field );
- if ( typeof field.meta !== 'object' ) {
- field.meta = {};
- }
- if ( undefined !== values[ fieldID ] ) {
- field.value = values[ fieldID ];
- }
- field.name =
- 'popup_settings[conditions][' +
- data.group +
- '][' +
- data.index +
- '][settings][' +
- fieldID +
- ']';
- if ( field.id === '' ) {
- field.id =
- 'popup_settings_conditions_' +
- data.group +
- '_' +
- data.index +
- '_settings_' +
- fieldID;
- }
- fields.push( PUM_Admin.templates.field( field ) );
- } );
- // Render the section.
- return PUM_Admin.templates.section( {
- fields: fields,
- } );
- },
- selectbox: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- id: null,
- name: null,
- type: 'select',
- group: '',
- index: '',
- value: null,
- select2: true,
- classes: [],
- options: conditions.get_conditions(),
- },
- args
- );
- if ( data.id === null ) {
- data.id =
- 'popup_settings_conditions_' +
- data.group +
- '_' +
- data.index +
- '_target';
- }
- if ( data.name === null ) {
- data.name =
- 'popup_settings[conditions][' +
- data.group +
- '][' +
- data.index +
- '][target]';
- }
- return PUM_Admin.templates.field( data );
- },
- },
- groups: {
- add: function( editor, target, not_operand ) {
- var $editor = $( editor ),
- data = {
- index: $editor.find( '.facet-group-wrap' ).length,
- facets: [
- {
- target: target || null,
- not_operand: not_operand || false,
- settings: {},
- },
- ],
- };
- $editor
- .find( '.facet-groups' )
- .append( conditions.template.group( data ) );
- $editor.addClass( 'has-conditions' );
- },
- remove: function( $group ) {
- var $editor = $group.parents( '.facet-builder' );
- $group
- .prev( '.facet-group-wrap' )
- .find( '.and .add-facet' )
- .removeClass( 'disabled' );
- $group.remove();
- conditions.renumber();
- if ( $editor.find( '.facet-group-wrap' ).length === 0 ) {
- $editor.removeClass( 'has-conditions' );
- $( '#pum-first-condition' )
- .val( null )
- .trigger( 'change' );
- }
- },
- },
- facets: {
- add: function( $group, target, not_operand ) {
- var data = {
- group: $group.data( 'index' ),
- index: $group.find( '.facet' ).length,
- target: target || null,
- not_operand: not_operand || false,
- settings: {},
- };
- $group
- .find( '.facet-list' )
- .append( conditions.template.facet( data ) );
- },
- remove: function( $facet ) {
- var $group = $facet.parents( '.facet-group-wrap' );
- $facet.remove();
- if ( $group.find( '.facet' ).length === 0 ) {
- conditions.groups.remove( $group );
- } else {
- conditions.renumber();
- }
- },
- },
- renumber: function() {
- $( '.facet-builder .facet-group-wrap' ).each( function() {
- var $group = $( this ),
- groupIndex = $group
- .parent()
- .children()
- .index( $group );
- $group
- .data( 'index', groupIndex )
- .find( '.facet' )
- .each( function() {
- var $facet = $( this ),
- facetIndex = $facet
- .parent()
- .children()
- .index( $facet );
- $facet
- .data( 'index', facetIndex )
- .find( '[name]' )
- .each( function() {
- this.name = this.name.replace(
- /popup_settings\[conditions\]\[\d*?\]\[\d*?\]/,
- 'popup_settings[conditions][' +
- groupIndex +
- '][' +
- facetIndex +
- ']'
- );
- this.id = this.id.replace(
- /popup_settings_conditions_\d*?_\d*?_/,
- 'popup_settings_conditions_' +
- groupIndex +
- '_' +
- facetIndex +
- '_'
- );
- } );
- } );
- } );
- },
- };
- // Import this module.
- window.PUM_Admin = window.PUM_Admin || {};
- window.PUM_Admin.conditions = conditions;
- $( document )
- .on( 'pum_init', function() {
- conditions.renumber();
- conditions.toggle_not_operand();
- } )
- .on(
- 'select2:select pumselect2:select',
- '#pum-first-condition',
- function( event ) {
- var $field = $( this ),
- $editor = $field.parents( '.facet-builder' ).eq( 0 ),
- target = $field.val(),
- $operand = $editor.find( '#pum-first-facet-operand' ),
- not_operand = $operand.is( ':checked' );
- conditions.groups.add( $editor, target, not_operand );
- $field.val( null ).trigger( 'change' );
- $operand
- .prop( 'checked', false )
- .parents( '.facet-target' )
- .removeClass( 'not-operand-checked' );
- $( document ).trigger( 'pum_init' );
- }
- )
- .on( 'click', '.facet-builder .pum-not-operand', function() {
- conditions.not_operand_checkbox( $( this ) );
- } )
- .on( 'change', '.facet-builder .facet-target select', function(
- event
- ) {
- var $this = $( this ),
- $facet = $this.parents( '.facet' ),
- target = $this.val(),
- data = {
- target: target,
- };
- if ( target === '' || target === $facet.data( 'target' ) ) {
- return;
- }
- $facet
- .data( 'target', target )
- .find( '.facet-settings' )
- .html( conditions.template.settings( data ) );
- $( document ).trigger( 'pum_init' );
- } )
- .on(
- 'click',
- '.facet-builder .facet-group-wrap:last-child .and .add-facet',
- function() {
- conditions.groups.add(
- $( this )
- .parents( '.facet-builder' )
- .eq( 0 )
- );
- $( document ).trigger( 'pum_init' );
- }
- )
- .on(
- 'click',
- '.facet-builder .add-or .add-facet:not(.disabled)',
- function() {
- conditions.facets.add(
- $( this )
- .parents( '.facet-group-wrap' )
- .eq( 0 )
- );
- $( document ).trigger( 'pum_init' );
- }
- )
- .on( 'click', '.facet-builder .remove-facet', function() {
- conditions.facets.remove(
- $( this )
- .parents( '.facet' )
- .eq( 0 )
- );
- $( document ).trigger( 'pum_init' );
- } );
- } )( jQuery );
- var cookies;
- ( function( $, document, undefined ) {
- 'use strict';
- var I10n = pum_admin_vars.I10n,
- current_editor,
- cookies = {
- get_cookies: function() {
- return window.pum_popup_settings_editor.cookies;
- },
- get_cookie: function( event ) {
- var cookies = this.get_cookies(),
- cookie =
- cookies[ event ] !== 'undefined'
- ? cookies[ event ]
- : false;
- if ( ! cookie ) {
- return false;
- }
- if (
- cookie &&
- typeof cookie === 'object' &&
- typeof cookie.fields === 'object' &&
- Object.keys( cookie.fields ).length
- ) {
- cookie = this.parseFields( cookie );
- }
- return cookie;
- },
- getCookieDefaults: function( event ) {
- var cookie = cookies.get_cookie( event );
- var defaultSettings = {};
- for ( var tab in cookie.fields ) {
- if ( cookie.fields.hasOwnProperty( tab ) ) {
- for ( var setting in cookie.fields[ tab ] ) {
- if (
- cookie.fields[ tab ].hasOwnProperty( setting )
- ) {
- defaultSettings[ setting ] =
- cookie.fields[ tab ][ setting ].std;
- }
- }
- }
- }
- defaultSettings.name = 'pum-' + $( '#post_ID' ).val();
- return defaultSettings;
- },
- parseFields: function( cookie ) {
- _.each( cookie.fields, function( fields, tabID ) {
- _.each( fields, function( field, fieldID ) {
- cookie.fields[ tabID ][ fieldID ].name =
- 'cookie_settings[' + fieldID + ']';
- if ( cookie.fields[ tabID ][ fieldID ].id === '' ) {
- cookie.fields[ tabID ][ fieldID ].id =
- 'cookie_settings_' + fieldID;
- }
- } );
- } );
- return cookie;
- },
- parseValues: function( values, type ) {
- return values;
- },
- select_list: function() {
- var i,
- _cookies = PUM_Admin.utils.object_to_array(
- cookies.get_cookies()
- ),
- options = {};
- for ( i = 0; i < _cookies.length; i++ ) {
- options[ _cookies[ i ].id ] = _cookies[ i ].name;
- }
- return options;
- },
- /**
- * @deprecated
- *
- * @param event
- */
- getLabel: function( event ) {
- var cookie = cookies.get_cookie( event );
- if ( ! cookie ) {
- return false;
- }
- return cookie.name;
- },
- /**
- * @param event
- * @param values
- */
- getSettingsDesc: function( event, values ) {
- var cookie = cookies.get_cookie( event );
- if ( ! cookie ) {
- return false;
- }
- return PUM_Admin.templates.renderInline(
- cookie.settings_column,
- values
- );
- },
- /**
- * Refresh all cookie row descriptions.
- */
- refreshDescriptions: function() {
- $( '.pum-popup-cookie-editor table.list-table tbody tr' ).each(
- function() {
- var $row = $( this ),
- event = $row
- .find( '.popup_cookies_field_event' )
- .val(),
- values = JSON.parse(
- $row
- .find(
- '.popup_cookies_field_settings:first'
- )
- .val()
- );
- $row.find( 'td.settings-column' ).html(
- cookies.getSettingsDesc( event, values )
- );
- }
- );
- },
- /**
- * Insert a new cookie when needed.
- *
- * @param $editor
- * @param args
- */
- insertCookie: function( $editor, args ) {
- var defaultSettings = cookies.getCookieDefaults( args.event );
- args = $.extend(
- true,
- {},
- {
- event: 'on_popup_close',
- settings: defaultSettings,
- },
- args
- );
- cookies.rows.add( $editor, args );
- },
- template: {
- form: function( event, values, callback ) {
- var cookie = cookies.get_cookie( event ),
- modalID = 'pum_cookie_settings',
- firstTab = Object.keys( cookie.fields )[ 0 ];
- values = values || {};
- values.event = event;
- values.index = values.index >= 0 ? values.index : null;
- // Add hidden index & event fields.
- cookie.fields[ firstTab ] = $.extend(
- true,
- cookie.fields[ firstTab ],
- {
- index: {
- type: 'hidden',
- name: 'index',
- },
- event: {
- type: 'hidden',
- name: 'event',
- },
- }
- );
- if ( typeof values.key !== 'string' || values.key === '' ) {
- delete cookie.fields.advanced.key;
- }
- PUM_Admin.modals.reload(
- '#' + modalID,
- PUM_Admin.templates.modal( {
- id: modalID,
- title: cookie.modal_title || cookie.name,
- classes: 'tabbed-content',
- save_button:
- values.index !== null ? I10n.update : I10n.add,
- content: PUM_Admin.forms.render(
- {
- id: 'pum_cookie_settings_form',
- tabs: cookie.tabs || {},
- fields: cookie.fields || {},
- },
- values || {}
- ),
- } )
- );
- $( '#' + modalID + ' form' ).on(
- 'submit',
- callback ||
- function( e ) {
- e.preventDefault();
- PUM_Admin.modals.closeAll();
- }
- );
- },
- editor: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- cookies: [],
- name: '',
- },
- args
- );
- data.cookies = PUM_Admin.utils.object_to_array(
- data.cookies
- );
- return PUM_Admin.templates.render(
- 'pum-cookie-editor',
- data
- );
- },
- row: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- index: '',
- event: '',
- name: '',
- settings: {
- name: '',
- key: '',
- session: null,
- path: null,
- time: '30 days',
- },
- },
- args
- );
- return PUM_Admin.templates.render( 'pum-cookie-row', data );
- },
- selectbox: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- id: null,
- name: null,
- type: 'select',
- group: '',
- index: '',
- value: null,
- select2: true,
- classes: [],
- options: cookies.select_list(),
- },
- args
- );
- if ( data.id === null ) {
- data.id =
- 'popup_settings_cookies_' + data.index + '_event';
- }
- if ( data.name === null ) {
- data.name =
- 'popup_settings[cookies][' +
- data.index +
- '][event]';
- }
- return PUM_Admin.templates.field( data );
- },
- },
- rows: {
- add: function( editor, cookie ) {
- var $editor = $( editor ),
- data = {
- index:
- cookie.index !== null && cookie.index >= 0
- ? cookie.index
- : $editor.find(
- 'table.list-table tbody tr'
- ).length,
- event: cookie.event,
- name: $editor.data( 'field_name' ),
- settings: cookie.settings || {},
- },
- $row = $editor.find( 'tbody tr' ).eq( data.index ),
- $new_row = PUM_Admin.templates.render(
- 'pum-cookie-row',
- data
- );
- if ( $row.length ) {
- $row.replaceWith( $new_row );
- } else {
- $editor.find( 'tbody' ).append( $new_row );
- }
- $editor.addClass( 'has-list-items' );
- cookies.rows.renumber();
- cookies.refreshDescriptions();
- },
- /**
- * Remove a cookie editor table row.
- *
- * @param $cookie
- */
- remove: function( $cookie ) {
- var $editor = $cookie.parents( '.pum-popup-cookie-editor' );
- $cookie.remove();
- cookies.rows.renumber();
- if (
- $editor.find( 'table.list-table tbody tr' ).length === 0
- ) {
- $editor.removeClass( 'has-list-items' );
- $( '#pum-first-cookie' )
- .val( null )
- .trigger( 'change' );
- }
- },
- /**
- * Renumber all rows for all editors.
- */
- renumber: function() {
- $(
- '.pum-popup-cookie-editor table.list-table tbody tr'
- ).each( function() {
- var $this = $( this ),
- index = $this
- .parent()
- .children()
- .index( $this );
- $this
- .attr( 'data-index', index )
- .data( 'index', index );
- $this.find( ':input, [name]' ).each( function() {
- if ( this.name && this.name !== '' ) {
- this.name = this.name.replace(
- /\[\d*?\]/,
- '[' + index + ']'
- );
- }
- } );
- } );
- },
- },
- };
- // Import this module.
- window.PUM_Admin = window.PUM_Admin || {};
- window.PUM_Admin.cookies = cookies;
- $( document )
- .on( 'pum_init', function() {
- cookies.refreshDescriptions();
- } )
- .on(
- 'select2:select pumselect2:select',
- '#pum-first-cookie',
- function() {
- var $this = $( this ),
- $editor = $this.parents( '.pum-popup-cookie-editor' ),
- event = $this.val(),
- values = {
- indes: $editor.find( 'table.list-table tbody tr' )
- .length,
- name: 'pum-' + $( '#post_ID' ).val(),
- };
- $this.val( null ).trigger( 'change' );
- cookies.template.form( event, values, function( e ) {
- var $form = $( this ),
- event = $form.find( 'input#event' ).val(),
- index = $form.find( 'input#index' ).val(),
- values = $form.pumSerializeObject();
- e.preventDefault();
- if ( ! index || index < 0 ) {
- index = $editor.find( 'tbody tr' ).length;
- }
- cookies.rows.add( $editor, {
- index: index,
- event: event,
- settings: values.cookie_settings,
- } );
- PUM_Admin.modals.closeAll();
- } );
- }
- )
- .on( 'click', '.pum-popup-cookie-editor .pum-add-new', function() {
- current_editor = $( this ).parents( '.pum-popup-cookie-editor' );
- var template = wp.template( 'pum-cookie-add-event' );
- PUM_Admin.modals.reload(
- '#pum_cookie_add_event_modal',
- template( { I10n: I10n } )
- );
- } )
- .on( 'click', '.pum-popup-cookie-editor .edit', function( e ) {
- var $this = $( this ),
- $editor = $this.parents( '.pum-popup-cookie-editor' ),
- $row = $this.parents( 'tr:first' ),
- event = $row.find( '.popup_cookies_field_event' ).val(),
- values = _.extend(
- {},
- JSON.parse(
- $row.find( '.popup_cookies_field_settings:first' ).val()
- ),
- {
- index: $row
- .parent()
- .children()
- .index( $row ),
- event: event,
- }
- );
- e.preventDefault();
- cookies.template.form( event, values, function( e ) {
- var $form = $( this ),
- event = $form.find( 'input#event' ).val(),
- index = $form.find( 'input#index' ).val(),
- values = $form.pumSerializeObject();
- e.preventDefault();
- if ( index === false || index < 0 ) {
- index = $editor.find( 'tbody tr' ).length;
- }
- cookies.rows.add( $editor, {
- index: index,
- event: event,
- settings: values.cookie_settings,
- } );
- PUM_Admin.modals.closeAll();
- } );
- } )
- .on( 'click', '.pum-popup-cookie-editor .remove', function( e ) {
- var $this = $( this ),
- $row = $this.parents( 'tr:first' );
- e.preventDefault();
- if ( window.confirm( I10n.confirm_delete_cookie ) ) {
- cookies.rows.remove( $row );
- }
- } )
- .on( 'click', '.pum-field-cookie_key button.reset', function( e ) {
- var $this = $( this ),
- newKey = new Date().getTime().toString( 16 );
- $this.siblings( 'input[type="text"]:first' ).val( newKey );
- } )
- .on( 'submit', '#pum_cookie_add_event_modal .pum-form', function( e ) {
- var $editor = current_editor,
- event = $( '#popup_cookie_add_event' ).val(),
- values = {
- index: $editor.find( 'table.list-table tbody tr' ).length,
- name: 'pum-' + $( '#post_ID' ).val(),
- path: '1',
- };
- e.preventDefault();
- cookies.template.form( event, values, function( e ) {
- var $form = $( this ),
- event = $form.find( 'input#event' ).val(),
- index = $form.find( 'input#index' ).val(),
- values = $form.pumSerializeObject();
- e.preventDefault();
- if ( index === false || index < 0 ) {
- index = $editor.find( 'tbody tr' ).length;
- }
- cookies.rows.add( $editor, {
- index: index,
- event: event,
- settings: values.cookie_settings,
- } );
- PUM_Admin.modals.closeAll();
- if (
- typeof PUM_Admin.triggers !== 'undefined' &&
- PUM_Admin.triggers.new_cookie !== false &&
- PUM_Admin.triggers.new_cookie >= 0
- ) {
- var $trigger = PUM_Admin.triggers.current_editor
- .find( 'tbody tr' )
- .eq( PUM_Admin.triggers.new_cookie )
- .find( '.popup_triggers_field_settings:first' ),
- trigger_settings = JSON.parse( $trigger.val() );
- if ( typeof trigger_settings.cookie_name === 'string' ) {
- trigger_settings.cookie_name = trigger_settings.cookie_name.replace(
- 'add_new',
- values.cookie_settings.name
- );
- } else {
- trigger_settings.cookie_name[
- trigger_settings.cookie_name.indexOf( 'add_new' )
- ] = values.cookie_settings.name;
- trigger_settings.cookie_name = trigger_settings.cookie_name.filter(
- function( element, index, array ) {
- return element in this
- ? false
- : ( this[ element ] = true );
- },
- {}
- );
- }
- $trigger.val( JSON.stringify( trigger_settings ) );
- PUM_Admin.triggers.new_cookie = false;
- PUM_Admin.triggers.refreshDescriptions();
- }
- } );
- } );
- } )( jQuery, document );
- ( function( $, document, undefined ) {
- 'use strict';
- var I10n = pum_admin_vars.I10n;
- var triggers = {
- current_editor: null,
- new_cookie: false,
- get_triggers: function() {
- return window.pum_popup_settings_editor.triggers;
- },
- get_trigger: function( type ) {
- var triggers = this.get_triggers(),
- trigger =
- triggers[ type ] !== 'undefined' ? triggers[ type ] : false;
- if ( ! trigger ) {
- return false;
- }
- if (
- trigger &&
- typeof trigger === 'object' &&
- typeof trigger.fields === 'object' &&
- Object.keys( trigger.fields ).length
- ) {
- trigger = this.parseFields( trigger );
- }
- return trigger;
- },
- parseFields: function( trigger ) {
- _.each( trigger.fields, function( fields, tabID ) {
- _.each( fields, function( field, fieldID ) {
- trigger.fields[ tabID ][ fieldID ].name =
- 'trigger_settings[' + fieldID + ']';
- if ( trigger.fields[ tabID ][ fieldID ].id === '' ) {
- trigger.fields[ tabID ][ fieldID ].id =
- 'trigger_settings_' + fieldID;
- }
- } );
- } );
- return trigger;
- },
- parseValues: function( values, type ) {
- for ( var key in values ) {
- if ( ! values.hasOwnProperty( key ) ) {
- continue;
- }
- // Clean measurement fields.
- if ( values.hasOwnProperty( key + '_unit' ) ) {
- values[ key ] += values[ key + '_unit' ];
- delete values[ key + '_unit' ];
- }
- }
- return values;
- },
- select_list: function() {
- var i,
- _triggers = PUM_Admin.utils.object_to_array(
- triggers.get_triggers()
- ),
- options = {};
- for ( i = 0; i < _triggers.length; i++ ) {
- options[ _triggers[ i ].id ] = _triggers[ i ].name;
- }
- return options;
- },
- rows: {
- add: function( editor, trigger ) {
- var $editor = $( editor ),
- data = {
- index:
- trigger.index !== null && trigger.index >= 0
- ? trigger.index
- : $editor.find( 'table.list-table tbody tr' )
- .length,
- type: trigger.type,
- name: $editor.data( 'field_name' ),
- settings: trigger.settings || {},
- },
- $row = $editor.find( 'tbody tr' ).eq( data.index ),
- $new_row = PUM_Admin.templates.render(
- 'pum-trigger-row',
- data
- );
- if ( $row.length ) {
- $row.replaceWith( $new_row );
- } else {
- $editor.find( 'tbody' ).append( $new_row );
- }
- $editor.addClass( 'has-list-items' );
- triggers.renumber();
- triggers.refreshDescriptions();
- },
- remove: function( $trigger ) {
- var $editor = $trigger.parents( '.pum-popup-trigger-editor' );
- $trigger.remove();
- triggers.renumber();
- if (
- $editor.find( 'table.list-table tbody tr' ).length === 0
- ) {
- $editor.removeClass( 'has-list-items' );
- $( '#pum-first-trigger' )
- .val( null )
- .trigger( 'change' );
- }
- },
- },
- template: {
- form: function( type, values, callback ) {
- var trigger = triggers.get_trigger( type ),
- modalID = 'pum_trigger_settings',
- firstTab = Object.keys( trigger.fields )[ 0 ],
- $cookies = $( '.pum-field-cookies .list-table tbody tr' );
- values = values || {};
- values.type = type;
- values.index = values.index >= 0 ? values.index : null;
- // Add hidden index & type fields.
- trigger.fields[ firstTab ] = $.extend(
- true,
- trigger.fields[ firstTab ],
- {
- index: {
- type: 'hidden',
- name: 'index',
- },
- type: {
- type: 'hidden',
- name: 'type',
- },
- }
- );
- $cookies.each( function() {
- var settings = JSON.parse(
- $( this )
- .find( '.popup_cookies_field_settings:first' )
- .val()
- );
- if (
- typeof trigger.fields[ firstTab ].cookie_name.options[
- settings.name
- ] === 'undefined'
- ) {
- trigger.fields[ firstTab ].cookie_name.options[
- settings.name
- ] = settings.name;
- }
- } );
- PUM_Admin.modals.reload(
- '#' + modalID,
- PUM_Admin.templates.modal( {
- id: modalID,
- title: trigger.modal_title || trigger.name,
- classes: 'tabbed-content',
- save_button:
- values.index !== null ? I10n.update : I10n.add,
- content: PUM_Admin.forms.render(
- {
- id: 'pum_trigger_settings_form',
- tabs: trigger.tabs || {},
- fields: trigger.fields || {},
- },
- values || {}
- ),
- } )
- );
- $( '#' + modalID + ' form' ).on(
- 'submit',
- callback ||
- function( event ) {
- event.preventDefault();
- PUM_Admin.modals.closeAll();
- }
- );
- },
- editor: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- triggers: [],
- name: '',
- },
- args
- );
- data.triggers = PUM_Admin.utils.object_to_array(
- data.triggers
- );
- return PUM_Admin.templates.render( 'pum-trigger-editor', data );
- },
- row: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- index: '',
- type: '',
- name: '',
- settings: {
- cookie_name: '',
- },
- },
- args
- );
- return PUM_Admin.templates.render( 'pum-trigger-row', data );
- },
- selectbox: function( args ) {
- var data = $.extend(
- true,
- {},
- {
- id: null,
- name: null,
- type: 'select',
- group: '',
- index: '',
- value: null,
- select2: true,
- classes: [],
- options: triggers.select_list(),
- },
- args
- );
- if ( data.id === null ) {
- data.id = 'popup_settings_triggers_' + data.index + '_type';
- }
- if ( data.name === null ) {
- data.name =
- 'popup_settings[triggers][' + data.index + '][type]';
- }
- return PUM_Admin.templates.field( data );
- },
- },
- /* @deprecated */
- getLabel: function( type ) {
- var trigger = triggers.get_trigger( type );
- if ( ! trigger ) {
- return false;
- }
- return trigger.name;
- },
- getSettingsDesc: function( type, values ) {
- var trigger = triggers.get_trigger( type );
- if ( ! trigger ) {
- return false;
- }
- return PUM_Admin.templates.renderInline(
- trigger.settings_column,
- values
- );
- },
- renumber: function() {
- $( '.pum-popup-trigger-editor table.list-table tbody tr' ).each(
- function() {
- var $this = $( this ),
- index = $this
- .parent()
- .children()
- .index( $this );
- $this.attr( 'data-index', index ).data( 'index', index );
- $this.find( ':input, [name]' ).each( function() {
- if ( this.name && this.name !== '' ) {
- this.name = this.name.replace(
- /\[\d*?\]/,
- '[' + index + ']'
- );
- }
- } );
- }
- );
- },
- refreshDescriptions: function() {
- $( '.pum-popup-trigger-editor table.list-table tbody tr' ).each(
- function() {
- var $row = $( this ),
- type = $row.find( '.popup_triggers_field_type' ).val(),
- values = JSON.parse(
- $row
- .find( '.popup_triggers_field_settings:first' )
- .val()
- ),
- cookie_text = PUM_Admin.triggers.cookie_column_value(
- values.cookie_name
- );
- $row.find( 'td.settings-column' ).html(
- PUM_Admin.triggers.getSettingsDesc( type, values )
- );
- $row.find( 'td.cookie-column code' ).text( cookie_text );
- }
- );
- },
- cookie_column_value: function( cookie_name ) {
- var cookie_text = I10n.no_cookie;
- if ( cookie_name instanceof Array ) {
- cookie_text = cookie_name.join( ', ' );
- } else if (
- cookie_name !== null &&
- cookie_name !== undefined &&
- cookie_name !== ''
- ) {
- cookie_text = cookie_name;
- }
- return cookie_text;
- },
- append_click_selector_presets: function() {
- var $field = $( '#extra_selectors' ),
- template,
- $presets;
- if (
- ! $field.length ||
- $field.hasClass( 'pum-click-selector-presets-initialized' )
- ) {
- return;
- }
- template = PUM_Admin.templates.render(
- 'pum-click-selector-presets'
- );
- $presets = $field
- .parents( '.pum-field' )
- .find( '.pum-click-selector-presets' );
- if ( ! $presets.length ) {
- $field.before( template );
- $field.addClass( 'pum-click-selector-presets-initialized' );
- $presets = $field
- .parents( '.pum-field' )
- .find( '.pum-click-selector-presets' );
- }
- $presets.position( {
- my: 'right center',
- at: 'right center',
- of: $field,
- } );
- },
- toggle_click_selector_presets: function() {
- $( this )
- .parent()
- .toggleClass( 'open' );
- },
- reset_click_selector_presets: function( e ) {
- if (
- e !== undefined &&
- $( e.target ).parents( '.pum-click-selector-presets' ).length
- ) {
- return;
- }
- $( '.pum-click-selector-presets' ).removeClass( 'open' );
- },
- insert_click_selector_preset: function() {
- var $this = $( this ),
- $input = $( '#extra_selectors' ),
- val = $input.val();
- if ( val !== '' ) {
- val = val + ', ';
- }
- $input.val( val + $this.data( 'preset' ) );
- PUM_Admin.triggers.reset_click_selector_presets();
- },
- };
- // Import this module.
- window.PUM_Admin = window.PUM_Admin || {};
- window.PUM_Admin.triggers = triggers;
- $( document )
- .on( 'pum_init', function() {
- PUM_Admin.triggers.append_click_selector_presets();
- PUM_Admin.triggers.refreshDescriptions();
- } )
- .on(
- 'click',
- '.pum-click-selector-presets > span',
- PUM_Admin.triggers.toggle_click_selector_presets
- )
- .on(
- 'click',
- '.pum-click-selector-presets li',
- PUM_Admin.triggers.insert_click_selector_preset
- )
- .on( 'click', PUM_Admin.triggers.reset_click_selector_presets )
- /**
- * @deprecated 1.7.0
- */
- .on(
- 'select2:select pumselect2:select',
- '#pum-first-trigger',
- function() {
- var $this = $( this ),
- $editor = $this.parents( '.pum-popup-trigger-editor' ),
- type = $this.val(),
- values = {};
- // Set Current Editor.
- PUM_Admin.triggers.current_editor = $editor;
- if ( type !== 'click_open' ) {
- values.cookie_name = 'pum-' + $( '#post_ID' ).val();
- }
- triggers.template.form( type, values, function( event ) {
- var $form = $( this ),
- type = $form.find( 'input#type' ).val(),
- values = $form.pumSerializeObject(),
- trigger_settings = triggers.parseValues(
- values.trigger_settings || {}
- ),
- index = parseInt( values.index );
- event.preventDefault();
- if ( index === false || index < 0 ) {
- index = $editor.find( 'tbody tr' ).length;
- }
- triggers.rows.add( $editor, {
- index: index,
- type: type,
- settings: trigger_settings,
- } );
- PUM_Admin.modals.closeAll();
- if (
- trigger_settings.cookie_name !== undefined &&
- trigger_settings.cookie_name !== null &&
- ( trigger_settings.cookie_name === 'add_new' ||
- trigger_settings.cookie_name.indexOf( 'add_new' ) >=
- 0 )
- ) {
- PUM_Admin.triggers.new_cookie = values.index;
- $(
- '#pum-popup-settings-container .pum-popup-cookie-editor button.pum-add-new'
- ).trigger( 'click' );
- }
- } );
- $this.val( null ).trigger( 'change' );
- }
- )
- // Add New Triggers
- .on( 'click', '.pum-popup-trigger-editor .pum-add-new', function() {
- PUM_Admin.triggers.current_editor = $( this ).parents(
- '.pum-popup-trigger-editor'
- );
- var template = wp.template( 'pum-trigger-add-type' );
- PUM_Admin.modals.reload(
- '#pum_trigger_add_type_modal',
- template( { I10n: I10n } )
- );
- } )
- .on( 'click', '.pum-popup-trigger-editor .edit', function( event ) {
- var $this = $( this ),
- $editor = $this.parents( '.pum-popup-trigger-editor' ),
- $row = $this.parents( 'tr:first' ),
- type = $row.find( '.popup_triggers_field_type' ).val(),
- values = _.extend(
- {},
- JSON.parse(
- $row
- .find( '.popup_triggers_field_settings:first' )
- .val()
- ),
- {
- index: $row
- .parent()
- .children()
- .index( $row ),
- type: type,
- }
- );
- event.preventDefault();
- triggers.template.form( type, values, function( event ) {
- var $form = $( this ),
- type = $form.find( 'input#type' ).val(),
- index = $form.find( 'input#index' ).val(),
- values = $form.pumSerializeObject(),
- trigger_settings = triggers.parseValues(
- values.trigger_settings || {}
- );
- // Set Current Editor.
- PUM_Admin.triggers.current_editor = $editor;
- event.preventDefault();
- if ( index === false || index < 0 ) {
- index = $editor.find( 'tbody tr' ).length;
- }
- triggers.rows.add( $editor, {
- index: index,
- type: type,
- settings: trigger_settings,
- } );
- PUM_Admin.modals.closeAll();
- if (
- trigger_settings.cookie_name !== undefined &&
- trigger_settings.cookie_name !== null &&
- ( trigger_settings.cookie_name === 'add_new' ||
- trigger_settings.cookie_name.indexOf( 'add_new' ) >= 0 )
- ) {
- PUM_Admin.triggers.new_cookie = values.index;
- $(
- '#pum-popup-settings-container .pum-popup-cookie-editor button.pum-add-new'
- ).trigger( 'click' );
- }
- } );
- } )
- .on( 'click', '.pum-popup-trigger-editor .remove', function( event ) {
- var $this = $( this ),
- $editor = $this.parents( '.pum-popup-trigger-editor' ),
- $row = $this.parents( 'tr:first' );
- // Set Current Editor.
- PUM_Admin.triggers.current_editor = $editor;
- event.preventDefault();
- if ( window.confirm( I10n.confirm_delete_trigger ) ) {
- triggers.rows.remove( $row );
- }
- } )
- .on( 'submit', '#pum_trigger_add_type_modal .pum-form', function(
- event
- ) {
- var $editor = PUM_Admin.triggers.current_editor,
- $cookie_editor = $editor
- .parents( '#pum-popup-settings-triggers-subtabs_main' )
- .find( '.pum-field-cookies .pum-popup-cookie-editor' ),
- type = $( '#popup_trigger_add_type' ).val(),
- add_cookie = $( '#popup_trigger_add_cookie' ).is( ':checked' ),
- add_cookie_event = $( '#popup_trigger_add_cookie_event' ).val(),
- values = {};
- event.preventDefault();
- if ( add_cookie ) {
- values.cookie_name = 'pum-' + $( '#post_ID' ).val();
- PUM_Admin.cookies.insertCookie( $cookie_editor, {
- event: add_cookie_event,
- settings: {
- time: '1 month',
- path: '1',
- name: values.cookie_name,
- },
- } );
- }
- triggers.template.form( type, values, function( event ) {
- var $form = $( this ),
- type = $form.find( 'input#type' ).val(),
- values = $form.pumSerializeObject(),
- trigger_settings = triggers.parseValues(
- values.trigger_settings || {}
- ),
- index = parseInt( values.index );
- // Set Current Editor.
- PUM_Admin.triggers.current_editor = $editor;
- event.preventDefault();
- if ( ! index || index < 0 ) {
- index = $editor.find( 'tbody tr' ).length;
- }
- triggers.rows.add( $editor, {
- index: index,
- type: type,
- settings: trigger_settings,
- } );
- PUM_Admin.modals.closeAll();
- if (
- trigger_settings.cookie_name !== undefined &&
- trigger_settings.cookie_name !== null &&
- ( trigger_settings.cookie_name === 'add_new' ||
- trigger_settings.cookie_name.indexOf( 'add_new' ) >= 0 )
- ) {
- PUM_Admin.triggers.new_cookie = values.index;
- $(
- '#pum-popup-settings-container .pum-popup-cookie-editor button.pum-add-new'
- ).trigger( 'click' );
- }
- } );
- } );
- } )( jQuery, document );
|