first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,471 @@
/* global wpforms_education, WPFormsBuilder */
/**
* WPForms Education Core.
*
* @since 1.6.6
*/
'use strict';
var WPFormsEducation = window.WPFormsEducation || {};
WPFormsEducation.core = window.WPFormsEducation.core || ( function( document, window, $ ) {
/**
* Spinner markup.
*
* @since 1.7.0
*
* @type {string}
*/
var spinner = '<i class="wpforms-loading-spinner wpforms-loading-white wpforms-loading-inline"></i>';
/**
* Public functions and properties.
*
* @since 1.6.6
*
* @type {object}
*/
var app = {
/**
* Start the engine.
*
* @since 1.6.6
*/
init: function() {
$( app.ready );
},
/**
* Document ready.
*
* @since 1.6.6
*/
ready: function() {
app.events();
},
/**
* Register JS events.
*
* @since 1.6.6
*/
events: function() {
app.dismissEvents();
app.openModalButtonClick();
},
/**
* Open education modal.
*
* @since 1.7.0
*/
openModalButtonClick: function() {
$( document ).on(
'click',
'.education-modal',
function( event ) {
var $this = $( this );
event.preventDefault();
switch ( $this.data( 'action' ) ) {
case 'activate':
app.activateModal( $this );
break;
case 'install':
app.installModal( $this );
break;
}
}
);
},
/**
* Dismiss button events.
*
* @since 1.6.6
*/
dismissEvents: function() {
$( '.wpforms-dismiss-container' ).on( 'click', '.wpforms-dismiss-button', function( e ) {
var $this = $( this ),
$cont = $this.closest( '.wpforms-dismiss-container' ),
$out = $cont.find( '.wpforms-dismiss-out' ),
data = {
action: 'wpforms_education_dismiss',
nonce: wpforms_education.nonce,
section: $this.data( 'section' ),
};
if ( $cont.hasClass( 'wpforms-dismiss-out' ) ) {
$out = $cont;
}
if ( $out.length > 0 ) {
$out.addClass( 'out' );
setTimeout(
function() {
$cont.remove();
},
300
);
} else {
$cont.remove();
}
$.post( wpforms_education.ajax_url, data );
} );
},
/**
* Get UTM content for different elements.
*
* @since 1.6.9
*
* @param {jQuery} $el Element.
*
* @returns {string} UTM content string.
*/
getUTMContentValue: function( $el ) {
// UTM content for Fields.
if ( $el.hasClass( 'wpforms-add-fields-button' ) ) {
return $el.data( 'utm-content' ) + ' Field';
}
// UTM content for Templates.
if ( $el.hasClass( 'wpforms-template-select' ) ) {
return app.slugToUTMcontent( $el.data( 'slug' ) );
}
// UTM content for Addons (sidebar).
if ( $el.hasClass( 'wpforms-panel-sidebar-section' ) ) {
return app.slugToUTMcontent( $el.data( 'slug' ) ) + ' Addon';
}
// UTM content by default with fallback `data-name`.
return $el.data( 'utm-content' ) || $el.data( 'name' );
},
/**
* Convert slug to UTM content.
*
* @since 1.6.9
*
* @param {string} slug Slug.
*
* @returns {string} UTM content string.
*/
slugToUTMcontent: function( slug ) {
if ( ! slug ) {
return '';
}
return slug.toString()
// Replace all non-alphanumeric characters with space.
.replace( /[^a-z\d ]/gi, ' ' )
// Uppercase each word.
.replace( /\b[a-z]/g, function( char ) {
return char.toUpperCase();
} );
},
/**
* Get upgrade URL according to the UTM content and license type.
*
* @since 1.6.9
*
* @param {string} utmContent UTM content.
* @param {string} type Feature license type: pro or elite.
*
* @returns {string} Upgrade URL.
*/
getUpgradeURL: function( utmContent, type ) {
var baseURL = wpforms_education.upgrade[ type ].url;
if ( utmContent.toLowerCase().indexOf( 'template' ) > -1 ) {
baseURL = wpforms_education.upgrade[ type ].url_template;
}
// Test if the base URL already contains `?`.
var appendChar = /(\?)/.test( baseURL ) ? '&' : '?';
return baseURL + appendChar + 'utm_content=' + encodeURIComponent( utmContent.trim() );
},
/**
* Addon activate modal.
*
* @since 1.7.0
*
* @param {jQuery} $button jQuery button element.
*/
activateModal: function( $button ) {
var feature = $button.data( 'name' );
$.alert( {
title : false,
content: wpforms_education.activate_prompt.replace( /%name%/g, feature ),
icon : 'fa fa-info-circle',
type : 'blue',
buttons: {
confirm: {
text : wpforms_education.activate_confirm,
btnClass: 'btn-confirm',
keys : [ 'enter' ],
action : function() {
this.$$confirm
.prop( 'disabled', true )
.html( spinner + wpforms_education.activating );
this.$$cancel
.prop( 'disabled', true );
app.activateAddon( $button, this );
return false;
},
},
cancel : {
text: wpforms_education.cancel,
},
},
} );
},
/**
* Activate addon via AJAX.
*
* @since 1.7.0
*
* @param {jQuery} $button jQuery button element.
* @param {object} previousModal Previous modal instance.
*/
activateAddon: function( $button, previousModal ) {
var path = $button.data( 'path' ),
pluginType = $button.data( 'type' ),
nonce = $button.data( 'nonce' ),
hideOnSuccess = $button.data( 'hide-on-success' );
$.post(
wpforms_education.ajax_url,
{
action: 'wpforms_activate_addon',
nonce : nonce,
plugin: path,
type : pluginType,
},
function( res ) {
previousModal.close();
if ( res.success ) {
if ( hideOnSuccess ) {
$button.hide();
}
app.saveModal( pluginType === 'plugin' ? wpforms_education.plugin_activated : wpforms_education.addon_activated );
} else {
$.alert( {
title : false,
content: res.data,
icon : 'fa fa-exclamation-circle',
type : 'orange',
buttons: {
confirm: {
text : wpforms_education.close,
btnClass: 'btn-confirm',
keys : [ 'enter' ],
},
},
} );
}
}
);
},
/**
* Ask user if they would like to save form and refresh form builder.
*
* @since 1.7.0
*
* @param {string} title Modal title.
*/
saveModal: function( title ) {
title = title || wpforms_education.addon_activated;
$.alert( {
title : title.replace( /\.$/, '' ), // Remove a dot in the title end.
content: wpforms_education.save_prompt,
icon : 'fa fa-check-circle',
type : 'green',
buttons: {
confirm: {
text : wpforms_education.save_confirm,
btnClass: 'btn-confirm',
keys : [ 'enter' ],
action : function() {
if ( 'undefined' === typeof WPFormsBuilder ) {
location.reload();
return;
}
this.$$confirm
.prop( 'disabled', true )
.html( spinner + wpforms_education.saving );
this.$$cancel
.prop( 'disabled', true );
if ( WPFormsBuilder.formIsSaved() ) {
location.reload();
}
WPFormsBuilder.formSave().done( function() {
location.reload();
} );
return false;
},
},
cancel : {
text: wpforms_education.close,
},
},
} );
},
/**
* Addon install modal.
*
* @since 1.7.0
*
* @param {jQuery} $button jQuery button element.
*/
installModal: function( $button ) {
var feature = $button.data( 'name' ),
url = $button.data( 'url' ),
licenseType = $button.data( 'license' );
if ( ! url || '' === url ) {
app.upgradeModal( feature, '', 'Empty install URL', licenseType, '' );
return;
}
$.alert( {
title : false,
content : wpforms_education.install_prompt.replace( /%name%/g, feature ),
icon : 'fa fa-info-circle',
type : 'blue',
boxWidth: '425px',
buttons : {
confirm: {
text : wpforms_education.install_confirm,
btnClass: 'btn-confirm',
keys : [ 'enter' ],
isHidden: ! wpforms_education.can_install_addons,
action : function() {
this.$$confirm.prop( 'disabled', true )
.html( spinner + wpforms_education.installing );
this.$$cancel
.prop( 'disabled', true );
app.installAddon( $button, this );
return false;
},
},
cancel : {
text: wpforms_education.cancel,
},
},
} );
},
/**
* Install addon via AJAX.
*
* @since 1.7.0
*
* @param {jQuery} $button jQuery button element.
* @param {object} previousModal Previous modal instance.
*/
installAddon: function( $button, previousModal ) {
var url = $button.data( 'url' ),
pluginType = $button.data( 'type' ),
nonce = $button.data( 'nonce' ),
hideOnSuccess = $button.data( 'hide-on-success' );
$.post(
wpforms_education.ajax_url,
{
action: 'wpforms_install_addon',
nonce : nonce,
plugin: url,
type : pluginType,
},
function( res ) {
previousModal.close();
if ( res.success ) {
if ( hideOnSuccess ) {
$button.hide();
}
app.saveModal( res.data.msg );
} else {
var message = res.data;
if ( 'object' === typeof res.data ) {
message = wpforms_education.addon_error;
}
$.alert( {
title : false,
content: message,
icon : 'fa fa-exclamation-circle',
type : 'orange',
buttons: {
confirm: {
text : wpforms_education.close,
btnClass: 'btn-confirm',
keys : [ 'enter' ],
},
},
} );
}
}
);
},
};
// Provide access to public functions/properties.
return app;
}( document, window, jQuery ) );
WPFormsEducation.core.init();

View File

@@ -0,0 +1 @@
"use strict";var WPFormsEducation=window.WPFormsEducation||{};WPFormsEducation.core=window.WPFormsEducation.core||function(t,s){var e='<i class="wpforms-loading-spinner wpforms-loading-white wpforms-loading-inline"></i>',c={init:function(){s(c.ready)},ready:function(){c.events()},events:function(){c.dismissEvents(),c.openModalButtonClick()},openModalButtonClick:function(){s(t).on("click",".education-modal",function(t){var n=s(this);switch(t.preventDefault(),n.data("action")){case"activate":c.activateModal(n);break;case"install":c.installModal(n)}})},dismissEvents:function(){s(".wpforms-dismiss-container").on("click",".wpforms-dismiss-button",function(t){var n=s(this),o=n.closest(".wpforms-dismiss-container"),a=o.find(".wpforms-dismiss-out"),n={action:"wpforms_education_dismiss",nonce:wpforms_education.nonce,section:n.data("section")};0<(a=o.hasClass("wpforms-dismiss-out")?o:a).length?(a.addClass("out"),setTimeout(function(){o.remove()},300)):o.remove(),s.post(wpforms_education.ajax_url,n)})},getUTMContentValue:function(t){return t.hasClass("wpforms-add-fields-button")?t.data("utm-content")+" Field":t.hasClass("wpforms-template-select")?c.slugToUTMcontent(t.data("slug")):t.hasClass("wpforms-panel-sidebar-section")?c.slugToUTMcontent(t.data("slug"))+" Addon":t.data("utm-content")||t.data("name")},slugToUTMcontent:function(t){return t?t.toString().replace(/[^a-z\d ]/gi," ").replace(/\b[a-z]/g,function(t){return t.toUpperCase()}):""},getUpgradeURL:function(t,n){var o=wpforms_education.upgrade[n].url;return(o=-1<t.toLowerCase().indexOf("template")?wpforms_education.upgrade[n].url_template:o)+(/(\?)/.test(o)?"&":"?")+"utm_content="+encodeURIComponent(t.trim())},activateModal:function(t){var n=t.data("name");s.alert({title:!1,content:wpforms_education.activate_prompt.replace(/%name%/g,n),icon:"fa fa-info-circle",type:"blue",buttons:{confirm:{text:wpforms_education.activate_confirm,btnClass:"btn-confirm",keys:["enter"],action:function(){return this.$$confirm.prop("disabled",!0).html(e+wpforms_education.activating),this.$$cancel.prop("disabled",!0),c.activateAddon(t,this),!1}},cancel:{text:wpforms_education.cancel}}})},activateAddon:function(n,o){var t=n.data("path"),a=n.data("type"),e=n.data("nonce"),i=n.data("hide-on-success");s.post(wpforms_education.ajax_url,{action:"wpforms_activate_addon",nonce:e,plugin:t,type:a},function(t){o.close(),t.success?(i&&n.hide(),c.saveModal("plugin"===a?wpforms_education.plugin_activated:wpforms_education.addon_activated)):s.alert({title:!1,content:t.data,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_education.close,btnClass:"btn-confirm",keys:["enter"]}}})})},saveModal:function(t){t=t||wpforms_education.addon_activated,s.alert({title:t.replace(/\.$/,""),content:wpforms_education.save_prompt,icon:"fa fa-check-circle",type:"green",buttons:{confirm:{text:wpforms_education.save_confirm,btnClass:"btn-confirm",keys:["enter"],action:function(){if("undefined"!=typeof WPFormsBuilder)return this.$$confirm.prop("disabled",!0).html(e+wpforms_education.saving),this.$$cancel.prop("disabled",!0),WPFormsBuilder.formIsSaved()&&location.reload(),WPFormsBuilder.formSave().done(function(){location.reload()}),!1;location.reload()}},cancel:{text:wpforms_education.close}}})},installModal:function(t){var n=t.data("name"),o=t.data("url"),a=t.data("license");o&&""!==o?s.alert({title:!1,content:wpforms_education.install_prompt.replace(/%name%/g,n),icon:"fa fa-info-circle",type:"blue",boxWidth:"425px",buttons:{confirm:{text:wpforms_education.install_confirm,btnClass:"btn-confirm",keys:["enter"],isHidden:!wpforms_education.can_install_addons,action:function(){return this.$$confirm.prop("disabled",!0).html(e+wpforms_education.installing),this.$$cancel.prop("disabled",!0),c.installAddon(t,this),!1}},cancel:{text:wpforms_education.cancel}}}):c.upgradeModal(n,"","Empty install URL",a,"")},installAddon:function(o,a){var t=o.data("url"),n=o.data("type"),e=o.data("nonce"),i=o.data("hide-on-success");s.post(wpforms_education.ajax_url,{action:"wpforms_install_addon",nonce:e,plugin:t,type:n},function(t){var n;a.close(),t.success?(i&&o.hide(),c.saveModal(t.data.msg)):(n=t.data,"object"==typeof t.data&&(n=wpforms_education.addon_error),s.alert({title:!1,content:n,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_education.close,btnClass:"btn-confirm",keys:["enter"]}}}))})}};return c}(document,(window,jQuery)),WPFormsEducation.core.init();