first commit
This commit is contained in:
@@ -0,0 +1,544 @@
|
||||
/* global wpforms_builder_help, wpf */
|
||||
|
||||
/**
|
||||
* WPForms Builder Help screen module.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPForms = window.WPForms || {};
|
||||
|
||||
WPForms.Admin = WPForms.Admin || {};
|
||||
WPForms.Admin.Builder = WPForms.Admin.Builder || {};
|
||||
|
||||
WPForms.Admin.Builder.Help = WPForms.Admin.Builder.Help || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Elements holder.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var el;
|
||||
|
||||
/**
|
||||
* UI functions.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var ui;
|
||||
|
||||
/**
|
||||
* Event handlers.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var event;
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine. DOM is not ready yet, use only to init something.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* DOM is fully loaded.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.setup();
|
||||
app.initCategories();
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup. Prepare some variables.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
setup: function() {
|
||||
|
||||
// Cache DOM elements.
|
||||
el = {
|
||||
$builder: $( '#wpforms-builder' ),
|
||||
$builderForm: $( '#wpforms-builder-form' ),
|
||||
$helpBtn: $( '#wpforms-help' ),
|
||||
$help: $( '#wpforms-builder-help' ),
|
||||
$closeBtn: $( '#wpforms-builder-help-close' ),
|
||||
$search: $( '#wpforms-builder-help-search' ),
|
||||
$result: $( '#wpforms-builder-help-result' ),
|
||||
$noResult: $( '#wpforms-builder-help-no-result' ),
|
||||
$categories: $( '#wpforms-builder-help-categories' ),
|
||||
$footer: $( '#wpforms-builder-help-footer' ),
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind events.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
// Open/close help modal.
|
||||
el.$helpBtn.on( 'click', event.openHelp );
|
||||
el.$closeBtn.on( 'click', event.closeHelp );
|
||||
|
||||
// Expand/collapce category.
|
||||
el.$categories.on( 'click', '.wpforms-builder-help-category header', event.toggleCategory );
|
||||
|
||||
// View all Category Docs button click.
|
||||
el.$categories.on( 'click', '.wpforms-builder-help-category button.viewall', event.viewAllCategoryDocs );
|
||||
|
||||
// Input into search field.
|
||||
el.$search.on( 'keyup', 'input', _.debounce( event.inputSearch, 250 ) );
|
||||
|
||||
// Clear search field.
|
||||
el.$search.on( 'click', '#wpforms-builder-help-search-clear', event.clearSearch );
|
||||
},
|
||||
|
||||
/**
|
||||
* Init (generate) categories list.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
initCategories: function() {
|
||||
|
||||
// Display error if docs data is not available.
|
||||
if ( wpf.empty( wpforms_builder_help.docs ) ) {
|
||||
el.$categories.html( wp.template( 'wpforms-builder-help-categories-error' ) );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var tmpl = wp.template( 'wpforms-builder-help-categories' ),
|
||||
data = {
|
||||
categories: wpforms_builder_help.categories,
|
||||
docs: app.getDocsByCategories(),
|
||||
};
|
||||
|
||||
el.$categories.html( tmpl( data ) );
|
||||
},
|
||||
|
||||
/**
|
||||
* Init categories list.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @returns {object} Docs arranged by category.
|
||||
*/
|
||||
getDocsByCategories: function() {
|
||||
|
||||
var categories = wpforms_builder_help.categories,
|
||||
docs = wpforms_builder_help.docs || [],
|
||||
docsByCategories = {};
|
||||
|
||||
_.each( categories, function( categoryTitle, categorySlug ) {
|
||||
var docsByCategory = [];
|
||||
_.each( docs, function( doc ) {
|
||||
if ( doc.categories && doc.categories.indexOf( categorySlug ) > -1 ) {
|
||||
docsByCategory.push( doc );
|
||||
}
|
||||
} );
|
||||
docsByCategories[ categorySlug ] = docsByCategory;
|
||||
} );
|
||||
|
||||
return docsByCategories;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get docs recommended by search term.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {string} term Search term.
|
||||
*
|
||||
* @returns {Array} Recommended docs.
|
||||
*/
|
||||
getRecommendedDocs: function( term ) {
|
||||
|
||||
if ( wpf.empty( term ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
term = term.toLowerCase();
|
||||
|
||||
var docs = wpforms_builder_help.docs,
|
||||
recommendedDocs = [];
|
||||
|
||||
if ( wpf.empty( wpforms_builder_help.context.docs[ term ] ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
_.each( wpforms_builder_help.context.docs[ term ], function( docId ) {
|
||||
if ( ! wpf.empty( docs[ docId ] ) ) {
|
||||
recommendedDocs.push( docs[ docId ] );
|
||||
}
|
||||
} );
|
||||
|
||||
return recommendedDocs;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get docs filtered by search term.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {string} term Search term.
|
||||
*
|
||||
* @returns {Array} Filtered docs.
|
||||
*/
|
||||
getFilteredDocs: function( term ) {
|
||||
|
||||
if ( wpf.empty( term ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var docs = wpforms_builder_help.docs,
|
||||
filteredDocs = [];
|
||||
|
||||
term = term.toLowerCase();
|
||||
|
||||
_.each( docs, function( doc ) {
|
||||
if ( doc.title && doc.title.toLowerCase().indexOf( term ) > -1 ) {
|
||||
filteredDocs.push( doc );
|
||||
}
|
||||
} );
|
||||
|
||||
return filteredDocs;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the current context (state) of the form builder.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @returns {string} Builder context string. For example 'fields/add_field' or 'settings/notifications'.
|
||||
*/
|
||||
getBuilderContext: function() {
|
||||
|
||||
// New (not saved) form.
|
||||
if ( wpf.empty( el.$builderForm.data( 'id' ) ) ) {
|
||||
return 'new_form';
|
||||
}
|
||||
|
||||
// Determine builder panel and section.
|
||||
var panel = el.$builder.find( '#wpforms-panels-toggle button.active' ).data( 'panel' ),
|
||||
$panel = el.$builder.find( '#wpforms-panel-' + panel ),
|
||||
section = '',
|
||||
subsection = '',
|
||||
context;
|
||||
|
||||
switch ( panel ) {
|
||||
case 'fields':
|
||||
section = $panel.find( '.wpforms-panel-sidebar .wpforms-tab a.active' ).parent().attr( 'id' );
|
||||
break;
|
||||
case 'setup':
|
||||
section = '';
|
||||
break;
|
||||
default:
|
||||
section = $panel.find( '.wpforms-panel-sidebar a.active' ).data( 'section' );
|
||||
}
|
||||
|
||||
section = ! wpf.empty( section ) ? section.replace( /-/g, '_' ) : '';
|
||||
|
||||
// Detect field type.
|
||||
if ( section === 'field_options' ) {
|
||||
subsection = $panel.find( '#wpforms-field-options .wpforms-field-option:visible .wpforms-field-option-hidden-type' ).val();
|
||||
}
|
||||
|
||||
// Combine to context array.
|
||||
context = [ panel, section, subsection ].filter( function( el ) {
|
||||
return ! wpf.empty( el ) && el !== 'default';
|
||||
} );
|
||||
|
||||
// Return imploded string.
|
||||
return context.join( '/' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the search term for the current builder context.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @returns {string} Builder context term string.
|
||||
*/
|
||||
getBuilderContextTerm: function() {
|
||||
|
||||
return wpforms_builder_help.context.terms[ app.getBuilderContext() ] || '';
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* UI functions.
|
||||
*/
|
||||
ui = {
|
||||
|
||||
/**
|
||||
* Configuration.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
config: {
|
||||
speed: 300, // Fading/sliding duration in milliseconds.
|
||||
},
|
||||
|
||||
/**
|
||||
* Display the element by fading them to opaque using CSS.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {jQuery} $el Element object.
|
||||
*/
|
||||
fadeIn: function( $el ) {
|
||||
|
||||
if ( ! $el.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$el.css( 'display', '' );
|
||||
$el.css( 'transition', 'opacity ' + ui.config.speed + 'ms ease-in 0s' );
|
||||
setTimeout( function() {
|
||||
$el.css( 'opacity', '1' );
|
||||
}, 0 );
|
||||
},
|
||||
|
||||
/**
|
||||
* Hide the element by fading them to transparent using CSS.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {jQuery} $el Element object.
|
||||
*/
|
||||
fadeOut: function( $el ) {
|
||||
|
||||
if ( ! $el.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$el.css( 'opacity', '0' );
|
||||
$el.css( 'transition', 'opacity ' + ui.config.speed + 'ms ease-in 0s' );
|
||||
setTimeout( function() {
|
||||
$el.css( 'display', 'none' );
|
||||
}, ui.config.speed );
|
||||
},
|
||||
|
||||
/**
|
||||
* Collapse all categories.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
collapseAllCategories: function() {
|
||||
|
||||
el.$categories.find( '.wpforms-builder-help-category' ).removeClass( 'opened' );
|
||||
el.$categories.find( '.wpforms-builder-help-docs' ).slideUp();
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Event handlers.
|
||||
*/
|
||||
event = {
|
||||
|
||||
/**
|
||||
* Open help modal.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
openHelp: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var $firstCategory = el.$categories.find( '.wpforms-builder-help-category' ).first(),
|
||||
builderContextTerm = app.getBuilderContextTerm();
|
||||
|
||||
if ( builderContextTerm === '' && ! $firstCategory.hasClass( 'opened' ) ) {
|
||||
$firstCategory.find( 'header' ).first().click();
|
||||
} else {
|
||||
ui.collapseAllCategories();
|
||||
}
|
||||
|
||||
el.$search.find( 'input' ).val( builderContextTerm ).trigger( 'keyup' );
|
||||
|
||||
ui.fadeIn( el.$help );
|
||||
|
||||
setTimeout( function() {
|
||||
|
||||
ui.fadeIn( el.$result );
|
||||
ui.fadeIn( el.$categories );
|
||||
ui.fadeIn( el.$footer );
|
||||
|
||||
}, ui.config.speed );
|
||||
},
|
||||
|
||||
/**
|
||||
* Close help modal.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
closeHelp: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
ui.fadeOut( el.$result );
|
||||
ui.fadeOut( el.$categories );
|
||||
ui.fadeOut( el.$footer );
|
||||
|
||||
ui.fadeOut( el.$help );
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle category.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
toggleCategory: function( e ) {
|
||||
|
||||
var $category = $( this ).parent(),
|
||||
$categoryDocs = $category.find( '.wpforms-builder-help-docs' );
|
||||
|
||||
if ( ! $categoryDocs.is( ':visible' ) ) {
|
||||
$category.addClass( 'opened' );
|
||||
} else {
|
||||
$category.removeClass( 'opened' );
|
||||
}
|
||||
|
||||
$categoryDocs.stop().slideToggle( ui.config.speed );
|
||||
},
|
||||
|
||||
/**
|
||||
* View All Category Docs button click.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
viewAllCategoryDocs: function( e ) {
|
||||
|
||||
var $btn = $( this );
|
||||
|
||||
$btn.prev( 'div' ).stop().slideToggle( ui.config.speed, function() {
|
||||
$btn.closest( '.wpforms-builder-help-category' ).addClass( 'viewall' );
|
||||
} );
|
||||
ui.fadeOut( $btn );
|
||||
$btn.slideUp();
|
||||
},
|
||||
|
||||
/**
|
||||
* Input into search field.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
inputSearch: function( e ) {
|
||||
|
||||
var $input = $( this ),
|
||||
term = $input.val();
|
||||
|
||||
var tmpl = wp.template( 'wpforms-builder-help-docs' ),
|
||||
recommendedDocs = app.getRecommendedDocs( term ),
|
||||
filteredDocs = event.removeDuplicates( recommendedDocs, app.getFilteredDocs( term ) ),
|
||||
resultHTML = '';
|
||||
|
||||
el.$search.toggleClass( 'wpforms-empty', ! term );
|
||||
|
||||
if ( ! wpf.empty( recommendedDocs ) ) {
|
||||
resultHTML += tmpl( {
|
||||
docs: recommendedDocs,
|
||||
} );
|
||||
}
|
||||
|
||||
if ( ! wpf.empty( filteredDocs ) ) {
|
||||
resultHTML += tmpl( {
|
||||
docs: filteredDocs,
|
||||
} );
|
||||
}
|
||||
|
||||
el.$noResult.toggle( resultHTML === '' && term !== '' );
|
||||
|
||||
el.$result.html( resultHTML );
|
||||
|
||||
el.$help[0].scrollTop = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove duplicated items in the filtered docs.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {Array} recommendedDocs Recommended docs.
|
||||
* @param {Array} filteredDocs Filtered docs.
|
||||
*
|
||||
* @returns {Array} Filtered docs without duplicated items in the recommended docs.
|
||||
*/
|
||||
removeDuplicates: function( recommendedDocs, filteredDocs ) {
|
||||
|
||||
if ( wpf.empty( recommendedDocs ) || wpf.empty( filteredDocs ) ) {
|
||||
return filteredDocs;
|
||||
}
|
||||
|
||||
var docs = [];
|
||||
|
||||
for ( var i = 0; i < recommendedDocs.length, i++; ) {
|
||||
for ( var k = 0; k < filteredDocs.length, k++; ) {
|
||||
if ( filteredDocs[ k ].url !== recommendedDocs[ i ].url ) {
|
||||
docs.push( filteredDocs[ k ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return docs;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear search field.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
clearSearch: function( e ) {
|
||||
|
||||
el.$search.find( 'input' ).val( '' ).trigger( 'keyup' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPForms.Admin.Builder.Help.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/help.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/help.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPForms=window.WPForms||{};WPForms.Admin=WPForms.Admin||{},WPForms.Admin.Builder=WPForms.Admin.Builder||{},WPForms.Admin.Builder.Help=WPForms.Admin.Builder.Help||function(l){var n,p={init:function(){l(p.ready)},ready:function(){p.setup(),p.initCategories(),p.events()},setup:function(){n={$builder:l("#wpforms-builder"),$builderForm:l("#wpforms-builder-form"),$helpBtn:l("#wpforms-help"),$help:l("#wpforms-builder-help"),$closeBtn:l("#wpforms-builder-help-close"),$search:l("#wpforms-builder-help-search"),$result:l("#wpforms-builder-help-result"),$noResult:l("#wpforms-builder-help-no-result"),$categories:l("#wpforms-builder-help-categories"),$footer:l("#wpforms-builder-help-footer")}},events:function(){n.$helpBtn.on("click",c.openHelp),n.$closeBtn.on("click",c.closeHelp),n.$categories.on("click",".wpforms-builder-help-category header",c.toggleCategory),n.$categories.on("click",".wpforms-builder-help-category button.viewall",c.viewAllCategoryDocs),n.$search.on("keyup","input",_.debounce(c.inputSearch,250)),n.$search.on("click","#wpforms-builder-help-search-clear",c.clearSearch)},initCategories:function(){var e,r;wpf.empty(wpforms_builder_help.docs)?n.$categories.html(wp.template("wpforms-builder-help-categories-error")):(e=wp.template("wpforms-builder-help-categories"),r={categories:wpforms_builder_help.categories,docs:p.getDocsByCategories()},n.$categories.html(e(r)))},getDocsByCategories:function(){var e=wpforms_builder_help.categories,o=wpforms_builder_help.docs||[],i={};return _.each(e,function(e,r){var t=[];_.each(o,function(e){e.categories&&-1<e.categories.indexOf(r)&&t.push(e)}),i[r]=t}),i},getRecommendedDocs:function(e){if(wpf.empty(e))return[];e=e.toLowerCase();var r=wpforms_builder_help.docs,t=[];return wpf.empty(wpforms_builder_help.context.docs[e])?[]:(_.each(wpforms_builder_help.context.docs[e],function(e){wpf.empty(r[e])||t.push(r[e])}),t)},getFilteredDocs:function(r){if(wpf.empty(r))return[];var e=wpforms_builder_help.docs,t=[];return r=r.toLowerCase(),_.each(e,function(e){e.title&&-1<e.title.toLowerCase().indexOf(r)&&t.push(e)}),t},getBuilderContext:function(){if(wpf.empty(n.$builderForm.data("id")))return"new_form";var e=n.$builder.find("#wpforms-panels-toggle button.active").data("panel"),r=n.$builder.find("#wpforms-panel-"+e),t="",o="";switch(e){case"fields":t=r.find(".wpforms-panel-sidebar .wpforms-tab a.active").parent().attr("id");break;case"setup":t="";break;default:t=r.find(".wpforms-panel-sidebar a.active").data("section")}return[e,t=wpf.empty(t)?"":t.replace(/-/g,"_"),o="field_options"===t?r.find("#wpforms-field-options .wpforms-field-option:visible .wpforms-field-option-hidden-type").val():o].filter(function(e){return!wpf.empty(e)&&"default"!==e}).join("/")},getBuilderContextTerm:function(){return wpforms_builder_help.context.terms[p.getBuilderContext()]||""}},o={config:{speed:300},fadeIn:function(e){e.length&&(e.css("display",""),e.css("transition","opacity "+o.config.speed+"ms ease-in 0s"),setTimeout(function(){e.css("opacity","1")},0))},fadeOut:function(e){e.length&&(e.css("opacity","0"),e.css("transition","opacity "+o.config.speed+"ms ease-in 0s"),setTimeout(function(){e.css("display","none")},o.config.speed))},collapseAllCategories:function(){n.$categories.find(".wpforms-builder-help-category").removeClass("opened"),n.$categories.find(".wpforms-builder-help-docs").slideUp()}},c={openHelp:function(e){e.preventDefault();var r=n.$categories.find(".wpforms-builder-help-category").first(),e=p.getBuilderContextTerm();""!==e||r.hasClass("opened")?o.collapseAllCategories():r.find("header").first().click(),n.$search.find("input").val(e).trigger("keyup"),o.fadeIn(n.$help),setTimeout(function(){o.fadeIn(n.$result),o.fadeIn(n.$categories),o.fadeIn(n.$footer)},o.config.speed)},closeHelp:function(e){e.preventDefault(),o.fadeOut(n.$result),o.fadeOut(n.$categories),o.fadeOut(n.$footer),o.fadeOut(n.$help)},toggleCategory:function(e){var r=l(this).parent(),t=r.find(".wpforms-builder-help-docs");t.is(":visible")?r.removeClass("opened"):r.addClass("opened"),t.stop().slideToggle(o.config.speed)},viewAllCategoryDocs:function(e){var r=l(this);r.prev("div").stop().slideToggle(o.config.speed,function(){r.closest(".wpforms-builder-help-category").addClass("viewall")}),o.fadeOut(r),r.slideUp()},inputSearch:function(e){var r=l(this).val(),t=wp.template("wpforms-builder-help-docs"),o=p.getRecommendedDocs(r),i=c.removeDuplicates(o,p.getFilteredDocs(r)),s="";n.$search.toggleClass("wpforms-empty",!r),wpf.empty(o)||(s+=t({docs:o})),wpf.empty(i)||(s+=t({docs:i})),n.$noResult.toggle(""===s&&""!==r),n.$result.html(s),n.$help[0].scrollTop=0},removeDuplicates:function(e,r){if(wpf.empty(e)||wpf.empty(r))return r;for(var t=[],o=0;e.length,o++;)for(var i=0;r.length,i++;)r[i].url!==e[o].url&&t.push(r[i]);return t},clearSearch:function(e){n.$search.find("input").val("").trigger("keyup")}};return p}((document,window,jQuery)),WPForms.Admin.Builder.Help.init();
|
||||
@@ -0,0 +1,972 @@
|
||||
/* global wpforms_builder, wpforms_builder_providers, wpf */
|
||||
|
||||
var WPForms = window.WPForms || {};
|
||||
WPForms.Admin = WPForms.Admin || {};
|
||||
WPForms.Admin.Builder = WPForms.Admin.Builder || {};
|
||||
|
||||
/**
|
||||
* WPForms Providers module.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*/
|
||||
WPForms.Admin.Builder.Providers = WPForms.Admin.Builder.Providers || ( function( document, window, $ ) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Private functions and properties.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
var __private = {
|
||||
|
||||
/**
|
||||
* Internal cache storage, do not use it directly, but app.cache.{(get|set|delete|clear)()} instead.
|
||||
* Key is the provider slug, value is a Map, that will have it's own key as a connection id (or not).
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @type {Object.<string, Map>}
|
||||
*/
|
||||
cache: {},
|
||||
|
||||
/**
|
||||
* Config contains all configuration properties.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @type {Object.<string, *>}
|
||||
*/
|
||||
config: {
|
||||
/**
|
||||
* List of default templates that should be compiled.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @type {string[]}
|
||||
*/
|
||||
templates: [
|
||||
'wpforms-providers-builder-content-connection-fields',
|
||||
'wpforms-providers-builder-content-connection-conditionals'
|
||||
]
|
||||
},
|
||||
|
||||
/**
|
||||
* Form fields for the current state.
|
||||
*
|
||||
* @since 1.6.1.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
fields: {},
|
||||
};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Panel holder.
|
||||
*
|
||||
* @since 1.5.9
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
panelHolder: {},
|
||||
|
||||
/**
|
||||
* Form holder.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
form: $( '#wpforms-builder-form' ),
|
||||
|
||||
/**
|
||||
* Spinner HTML.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
spinner: '<i class="wpforms-loading-spinner wpforms-loading-inline"></i>',
|
||||
|
||||
/**
|
||||
* All ajax requests are grouped together with own properties.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*/
|
||||
ajax: {
|
||||
/**
|
||||
* Merge custom AJAX data object with defaults.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {object} custom AJAX data object with custom settings.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
_mergeData: function( provider, custom ) {
|
||||
|
||||
var data = {
|
||||
id: $( '#wpforms-builder-form' ).data( 'id' ),
|
||||
nonce: wpforms_builder.nonce,
|
||||
action: 'wpforms_builder_provider_ajax_' + provider,
|
||||
};
|
||||
|
||||
$.extend( data, custom );
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Make an AJAX request. It's basically a wrapper around jQuery.ajax, but with some defaults.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {*} custom Object of user-defined $.ajax()-compatible parameters.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
request: function( provider, custom ) {
|
||||
|
||||
var $holder = app.getProviderHolder( provider ),
|
||||
$lock = $holder.find( '.wpforms-builder-provider-connections-save-lock' ),
|
||||
$error = $holder.find( '.wpforms-builder-provider-connections-error' );
|
||||
|
||||
var params = {
|
||||
url: wpforms_builder.ajax_url,
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
beforeSend: function() {
|
||||
|
||||
$holder.addClass( 'loading' );
|
||||
$lock.val( 1 );
|
||||
$error.hide();
|
||||
},
|
||||
};
|
||||
|
||||
custom.data = app.ajax._mergeData( provider, custom.data || {} );
|
||||
$.extend( params, custom );
|
||||
|
||||
return $.ajax( params )
|
||||
.fail( function( jqXHR, textStatus, errorThrown ) {
|
||||
|
||||
/*
|
||||
* Right now we are logging into browser console.
|
||||
* In future that might be something better.
|
||||
*/
|
||||
console.error( 'provider:', provider );
|
||||
console.error( jqXHR );
|
||||
console.error( textStatus );
|
||||
|
||||
$lock.val( 1 );
|
||||
$error.show();
|
||||
} )
|
||||
.always( function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {
|
||||
|
||||
$holder.removeClass( 'loading' );
|
||||
|
||||
if ( 'success' === textStatus ) {
|
||||
$lock.val( 0 );
|
||||
}
|
||||
} );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Temporary in-memory cache handling for all providers.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*/
|
||||
cache: {
|
||||
|
||||
/**
|
||||
* Get the value from cache by key.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {string} key Cache key.
|
||||
*
|
||||
* @returns {*} Null if some error occurs.
|
||||
*/
|
||||
get: function( provider, key ) {
|
||||
|
||||
if (
|
||||
typeof __private.cache[ provider ] === 'undefined' ||
|
||||
! ( __private.cache[ provider ] instanceof Map )
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return __private.cache[ provider ].get( key );
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the value from cache by key and an ID.
|
||||
* Useful when Object is stored under key and we need specific value.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {string} key Cache key.
|
||||
* @param {string} id Cached object ID.
|
||||
*
|
||||
* @returns {*} Null if some error occurs.
|
||||
*/
|
||||
getById: function( provider, key, id ) {
|
||||
|
||||
if ( typeof this.get( provider, key )[ id ] === 'undefined' ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.get( provider, key )[ id ];
|
||||
},
|
||||
|
||||
/**
|
||||
* Save the data to cache.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {string} key Intended to be a string, but can be everything that Map supports as a key.
|
||||
* @param {*} value Data you want to save in cache.
|
||||
*
|
||||
* @returns {Map} All the cache for the provider. IE11 returns 'undefined' for an undefined reason.
|
||||
*/
|
||||
set: function( provider, key, value ) {
|
||||
|
||||
if (
|
||||
typeof __private.cache[ provider ] === 'undefined' ||
|
||||
! ( __private.cache[ provider ] instanceof Map )
|
||||
) {
|
||||
__private.cache[ provider ] = new Map();
|
||||
}
|
||||
|
||||
return __private.cache[ provider ].set( key, value );
|
||||
},
|
||||
|
||||
/**
|
||||
* Add the data to cache to a particular key.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @example app.cache.as('provider').addTo('connections', connection_id, connection);
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {string} key Intended to be a string, but can be everything that Map supports as a key.
|
||||
* @param {string} id ID for a value that should be added to a certain key.
|
||||
* @param {*} value Data you want to save in cache.
|
||||
*
|
||||
* @returns {Map} All the cache for the provider. IE11 returns 'undefined' for an undefined reason.
|
||||
*/
|
||||
addTo: function( provider, key, id, value ) {
|
||||
|
||||
if (
|
||||
typeof __private.cache[ provider ] === 'undefined' ||
|
||||
! ( __private.cache[ provider ] instanceof Map )
|
||||
) {
|
||||
__private.cache[ provider ] = new Map();
|
||||
this.set( provider, key, {} );
|
||||
}
|
||||
|
||||
var data = this.get( provider, key );
|
||||
data[ id ] = value;
|
||||
|
||||
return this.set(
|
||||
provider,
|
||||
key,
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the cache by key.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {string} key Cache key.
|
||||
*
|
||||
* @returns boolean|null True on success, null on data holder failure, false on error.
|
||||
*/
|
||||
delete: function( provider, key ) {
|
||||
|
||||
if (
|
||||
typeof __private.cache[ provider ] === 'undefined' ||
|
||||
! ( __private.cache[ provider ] instanceof Map )
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return __private.cache[ provider ].delete( key );
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete particular data from a certain key.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @example app.cache.as('provider').deleteFrom('connections', connection_id);
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {string} key Intended to be a string, but can be everything that Map supports as a key.
|
||||
* @param {string} id ID for a value that should be delete from a certain key.
|
||||
*
|
||||
* @returns {Map} All the cache for the provider. IE11 returns 'undefined' for an undefined reason.
|
||||
*/
|
||||
deleteFrom: function( provider, key, id ) {
|
||||
|
||||
if (
|
||||
typeof __private.cache[ provider ] === 'undefined' ||
|
||||
! ( __private.cache[ provider ] instanceof Map )
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var data = this.get( provider, key );
|
||||
|
||||
delete data[ id ];
|
||||
|
||||
return this.set(
|
||||
provider,
|
||||
key,
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear all the cache data.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
*/
|
||||
clear: function( provider ) {
|
||||
|
||||
if (
|
||||
typeof __private.cache[ provider ] === 'undefined' ||
|
||||
! ( __private.cache[ provider ] instanceof Map )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
__private.cache[ provider ].clear();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Start the engine. DOM is not ready yet, use only to init something.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
// Do that when DOM is ready.
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* DOM is fully loaded.
|
||||
* Should be hooked into in addons, that need to work with DOM, templates etc.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.6.1.2 Added initialization for `__private.fields` property.
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
// Save a current form fields state.
|
||||
__private.fields = $.extend( {}, wpf.getFields( false, true ) );
|
||||
|
||||
app.panelHolder = $( '#wpforms-panel-providers' );
|
||||
|
||||
app.Templates = WPForms.Admin.Builder.Templates;
|
||||
app.Templates.add( __private.config.templates );
|
||||
|
||||
app.bindActions();
|
||||
app.ui.bindActions();
|
||||
|
||||
app.panelHolder.trigger( 'WPForms.Admin.Builder.Providers.ready' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Process all generic actions/events, mostly custom that were fired by our API.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.6.1.2 Added a calling `app.updateMapSelects()` method.
|
||||
*/
|
||||
bindActions: function() {
|
||||
|
||||
// On Form save - notify user about required fields.
|
||||
$( document ).on( 'wpformsSaved', function() {
|
||||
|
||||
var $connectionBlocks = $( '#wpforms-panel-providers' ).find( '.wpforms-builder-provider-connection' );
|
||||
|
||||
if ( ! $connectionBlocks.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to show him "Required fields empty" popup only once.
|
||||
var isShownOnce = false;
|
||||
|
||||
$connectionBlocks.each( function() {
|
||||
|
||||
var isRequiredEmpty = false;
|
||||
|
||||
// Do the actual required fields check.
|
||||
$( this ).find( 'input.wpforms-required, select.wpforms-required, textarea.wpforms-required' ).each( function() {
|
||||
|
||||
var value = $( this ).val();
|
||||
|
||||
if ( _.isEmpty( value ) ) {
|
||||
$( this ).addClass( 'wpforms-error' );
|
||||
isRequiredEmpty = true;
|
||||
|
||||
} else {
|
||||
$( this ).removeClass( 'wpforms-error' );
|
||||
}
|
||||
} );
|
||||
|
||||
// Notify user.
|
||||
if ( isRequiredEmpty && ! isShownOnce ) {
|
||||
var $titleArea = $( this ).closest( '.wpforms-builder-provider' ).find( '.wpforms-builder-provider-title' ).clone();
|
||||
$titleArea.find( 'button' ).remove();
|
||||
var msg = wpforms_builder.provider_required_flds;
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: msg.replace( '{provider}', '<strong>' + $titleArea.text().trim() + '</strong>' ),
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
|
||||
// Save that we have already showed the user, so we won't bug it anymore.
|
||||
isShownOnce = true;
|
||||
}
|
||||
} );
|
||||
|
||||
// On "Fields" page additional update provider's field mapped items.
|
||||
if ( 'fields' === wpf.getQueryString( 'view' ) ) {
|
||||
app.updateMapSelects( $connectionBlocks );
|
||||
}
|
||||
} );
|
||||
|
||||
/*
|
||||
* Update form state when each connection is loaded into the DOM.
|
||||
* This will prevent a please-save-prompt to appear, when navigating
|
||||
* out and back to Marketing tab without doing any changes anywhere.
|
||||
*/
|
||||
$( '#wpforms-panel-providers' ).on( 'connectionRendered', function() {
|
||||
|
||||
if ( wpf.initialSave === true ) {
|
||||
wpf.savedState = wpf.getFormState( '#wpforms-builder-form');
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update selects for mapping if any form fields was added, deleted or changed.
|
||||
*
|
||||
* @since 1.6.1.2
|
||||
*
|
||||
* @param {object} $connections jQuery selector for active conenctions.
|
||||
*/
|
||||
updateMapSelects: function( $connections ) {
|
||||
|
||||
var fields = $.extend( {}, wpf.getFields() ),
|
||||
currentSaveFields,
|
||||
prevSaveFields;
|
||||
|
||||
// We should to detect changes for labels only.
|
||||
currentSaveFields = _.mapObject( fields, function( field, key ) {
|
||||
|
||||
return field.label;
|
||||
} );
|
||||
prevSaveFields = _.mapObject( __private.fields, function( field, key ) {
|
||||
|
||||
return field.label;
|
||||
} );
|
||||
|
||||
// Check if form has any fields and if they have changed labels after previous saving process.
|
||||
if (
|
||||
( _.isEmpty( currentSaveFields ) && _.isEmpty( prevSaveFields ) ) ||
|
||||
( JSON.stringify( currentSaveFields ) === JSON.stringify( prevSaveFields ) )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare a current form field IDs.
|
||||
var fieldIds = Object.keys( currentSaveFields )
|
||||
.map( function( id ) {
|
||||
|
||||
return parseInt( id, 10 );
|
||||
} );
|
||||
|
||||
// Determine deleted field IDs - it's a diff between previous and current form state.
|
||||
var deleted = Object.keys( prevSaveFields )
|
||||
.map( function( id ) {
|
||||
|
||||
return parseInt( id, 10 );
|
||||
} )
|
||||
.filter( function( id ) {
|
||||
|
||||
return ! fieldIds.includes( id );
|
||||
} );
|
||||
|
||||
// Remove from mapping selects "deleted" fields.
|
||||
for ( var index = 0; index < deleted.length; index++ ) {
|
||||
$( '.wpforms-builder-provider-connection-fields-table .wpforms-builder-provider-connection-field-value option[value="' + deleted[ index ] + '"]', $connections ).remove();
|
||||
}
|
||||
|
||||
var label, $exists;
|
||||
for ( var id in fields ) {
|
||||
|
||||
// Prepare the label.
|
||||
if ( typeof fields[ id ].label !== 'undefined' && fields[ id ].label.toString().trim() !== '' ) {
|
||||
label = wpf.sanitizeHTML( fields[ id ].label.toString().trim() );
|
||||
} else {
|
||||
label = wpforms_builder.field + ' #' + id;
|
||||
}
|
||||
|
||||
// Try to find all select options by value.
|
||||
$exists = $( '.wpforms-builder-provider-connection-fields-table .wpforms-builder-provider-connection-field-value option[value="' + id + '"]', $connections );
|
||||
|
||||
// If no option was found - add a new one for all selects.
|
||||
if ( ! $exists.length ) {
|
||||
$( '.wpforms-builder-provider-connection-fields-table .wpforms-builder-provider-connection-field-value', $connections ).append( $( '<option>', { value: id, text: label } ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Update a field label if a previous and current labels not equal.
|
||||
if ( wpf.sanitizeHTML( fields[ id ].label ) !== wpf.sanitizeHTML( prevSaveFields[ id ] ) ) {
|
||||
$exists.text( label );
|
||||
}
|
||||
}
|
||||
|
||||
// If selects for mapping was changed, that whole form state was changed as well.
|
||||
// That's why we need to re-save it.
|
||||
if ( wpf.savedState !== wpf.getFormState( '#wpforms-builder-form' ) ) {
|
||||
wpf.savedState = wpf.getFormState( '#wpforms-builder-form' );
|
||||
}
|
||||
|
||||
// Save form fields state for next saving process.
|
||||
__private.fields = fields;
|
||||
|
||||
app.panelHolder.trigger( 'WPForms.Admin.Builder.Providers.updatedMapSelects', [ $connections, fields ] );
|
||||
},
|
||||
|
||||
/**
|
||||
* All methods that modify UI of a page.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*/
|
||||
ui: {
|
||||
|
||||
/**
|
||||
* Process UI related actions/events: click, change etc - that are triggered from UI.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*/
|
||||
bindActions: function() {
|
||||
|
||||
// CONNECTION: ADD/DELETE.
|
||||
app.panelHolder
|
||||
.on( 'click', '.js-wpforms-builder-provider-account-add', function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
app.ui.account.setProvider( $( this ).data( 'provider' ) );
|
||||
app.ui.account.add();
|
||||
} )
|
||||
.on( 'click', '.js-wpforms-builder-provider-connection-add', function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
app.ui.connectionAdd( $( this ).data( 'provider' ) );
|
||||
} )
|
||||
.on( 'click', '.js-wpforms-builder-provider-connection-delete', function( e ) {
|
||||
|
||||
var $btn = $( this );
|
||||
|
||||
e.preventDefault();
|
||||
app.ui.connectionDelete(
|
||||
$btn.closest( '.wpforms-builder-provider' ).data( 'provider' ),
|
||||
$btn.closest( '.wpforms-builder-provider-connection' )
|
||||
);
|
||||
} );
|
||||
|
||||
// CONNECTION: FIELDS - ADD/DELETE.
|
||||
app.panelHolder
|
||||
.on( 'click', '.js-wpforms-builder-provider-connection-fields-add', function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var $table = $( this ).parents( '.wpforms-builder-provider-connection-fields-table' ),
|
||||
$clone = $table.find( 'tr' ).last().clone( true ),
|
||||
nextID = parseInt( /\[.+]\[.+]\[.+]\[(\d+)]/.exec( $clone.find( '.wpforms-builder-provider-connection-field-name' ).attr( 'name' ) )[ 1 ], 10 ) + 1;
|
||||
|
||||
// Clear the row and increment the counter.
|
||||
$clone.find( '.wpforms-builder-provider-connection-field-name' )
|
||||
.attr( 'name', $clone.find( '.wpforms-builder-provider-connection-field-name' ).attr( 'name' ).replace( /\[fields_meta\]\[(\d+)\]/g, '[fields_meta][' + nextID + ']' ) )
|
||||
.val( '' );
|
||||
$clone.find( '.wpforms-builder-provider-connection-field-value' )
|
||||
.attr( 'name', $clone.find( '.wpforms-builder-provider-connection-field-value' ).attr( 'name' ).replace( /\[fields_meta\]\[(\d+)\]/g, '[fields_meta][' + nextID + ']' ) )
|
||||
.val( '' );
|
||||
|
||||
// Re-enable "delete" button.
|
||||
$clone.find( '.js-wpforms-builder-provider-connection-fields-delete' ).removeClass( 'hidden' );
|
||||
|
||||
// Put it back to the table.
|
||||
$table.find( 'tbody' ).append( $clone.get( 0 ) );
|
||||
} )
|
||||
.on( 'click', '.js-wpforms-builder-provider-connection-fields-delete', function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var $row = $( this ).parents( '.wpforms-builder-provider-connection-fields-table tr' );
|
||||
|
||||
$row.remove();
|
||||
} );
|
||||
|
||||
// CONNECTION: Generated.
|
||||
$( '#wpforms-panel-providers' ).on( 'connectionGenerated', function( e, data ) {
|
||||
|
||||
wpf.initTooltips();
|
||||
|
||||
// Hide provider default settings screen.
|
||||
$( this )
|
||||
.find( '.wpforms-builder-provider-connection[data-connection_id="' + data.connection.id + '"]' )
|
||||
.closest( '.wpforms-panel-content-section' )
|
||||
.find( '.wpforms-builder-provider-connections-default' )
|
||||
.addClass( 'wpforms-hidden' );
|
||||
} );
|
||||
|
||||
// CONNECTION: Rendered.
|
||||
$( '#wpforms-panel-providers' ).on( 'connectionRendered', function( e, provider, connectionId ) {
|
||||
|
||||
wpf.initTooltips();
|
||||
|
||||
// Some our addons have another arguments for this trigger.
|
||||
// We will fix it asap.
|
||||
if ( typeof connectionId === 'undefined' ) {
|
||||
if ( ! _.isObject( provider ) || ! _.has( provider, 'connection_id' ) ) {
|
||||
return;
|
||||
}
|
||||
connectionId = provider.connection_id;
|
||||
}
|
||||
|
||||
// If connection has mapped select fields - call `wpformsFieldUpdate` trigger.
|
||||
if ( $( this ).find( '.wpforms-builder-provider-connection[data-connection_id="' + connectionId + '"] .wpforms-field-map-select' ).length ) {
|
||||
wpf.fieldUpdate();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a connection to a page.
|
||||
* This is a multi-step process, where the 1st step is always the same for all providers.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
*/
|
||||
connectionAdd: function( provider ) {
|
||||
|
||||
$.confirm( {
|
||||
title: false,
|
||||
content: wpforms_builder_providers.prompt_connection.replace( /%type%/g, 'connection' ) +
|
||||
'<input autofocus="" type="text" id="wpforms-builder-provider-connection-name" placeholder="' + wpforms_builder_providers.prompt_placeholder + '">' +
|
||||
'<p class="error">' + wpforms_builder_providers.error_name + '</p>',
|
||||
icon: 'fa fa-info-circle',
|
||||
type: 'blue',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
|
||||
var name = this.$content.find( '#wpforms-builder-provider-connection-name' ).val().trim(),
|
||||
error = this.$content.find( '.error' );
|
||||
|
||||
if ( name === '' ) {
|
||||
error.show();
|
||||
return false;
|
||||
|
||||
} else {
|
||||
app.getProviderHolder( provider ).trigger( 'connectionCreate', [ name ] );
|
||||
}
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
text: wpforms_builder.cancel,
|
||||
},
|
||||
},
|
||||
} );
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* What to do with UI when connection is deleted.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
* @param {object} $connection jQuery DOM element for a connection.
|
||||
*/
|
||||
connectionDelete: function( provider, $connection ) {
|
||||
|
||||
$.confirm( {
|
||||
title: false,
|
||||
content: wpforms_builder_providers.confirm_connection,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
|
||||
// We need this BEFORE removing, as some handlers might need DOM element.
|
||||
app.getProviderHolder( provider ).trigger( 'connectionDelete', [ $connection ] );
|
||||
|
||||
var $section = $connection.closest( '.wpforms-panel-content-section' );
|
||||
|
||||
$connection.fadeOut( 'fast', function() {
|
||||
|
||||
$( this ).remove();
|
||||
|
||||
app.getProviderHolder( provider ).trigger( 'connectionDeleted', [ $connection ] );
|
||||
|
||||
if ( ! $section.find( '.wpforms-builder-provider-connection' ).length ) {
|
||||
$section.find( '.wpforms-builder-provider-connections-default' ).removeClass( 'wpforms-hidden' );
|
||||
}
|
||||
} );
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
text: wpforms_builder.cancel,
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Account specific methods.
|
||||
*
|
||||
* @since 1.4.8
|
||||
* @since 1.5.8 Added binding `onClose` event.
|
||||
*/
|
||||
account: {
|
||||
|
||||
/**
|
||||
* Current provider in the context of account creation.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @param {string}
|
||||
*/
|
||||
provider: '',
|
||||
|
||||
/**
|
||||
* Preserve a list of action to perform when new account creation form is submitted.
|
||||
* Provider specific.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @param {Array<string, callable>}
|
||||
*/
|
||||
submitHandlers: [],
|
||||
|
||||
/**
|
||||
* Set the account specific provider.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @param {string} provider Provider slug.
|
||||
*/
|
||||
setProvider: function( provider ) {
|
||||
this.provider = provider;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add an account for provider.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*/
|
||||
add: function() {
|
||||
|
||||
var account = this;
|
||||
|
||||
$.confirm( {
|
||||
title: false,
|
||||
smoothContent: true,
|
||||
content: function() {
|
||||
|
||||
var modal = this;
|
||||
|
||||
return app.ajax
|
||||
.request( account.provider, {
|
||||
data: {
|
||||
task: 'account_template_get',
|
||||
},
|
||||
} )
|
||||
.done( function( response ) {
|
||||
|
||||
if ( ! response.success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( response.data.title.length ) {
|
||||
modal.setTitle( response.data.title );
|
||||
}
|
||||
|
||||
if ( response.data.content.length ) {
|
||||
modal.setContent( response.data.content );
|
||||
}
|
||||
|
||||
if ( response.data.type.length ) {
|
||||
modal.setType( response.data.type );
|
||||
}
|
||||
|
||||
app.getProviderHolder( account.provider ).trigger( 'accountAddModal.content.done', [ modal, account.provider, response ] );
|
||||
} )
|
||||
.fail( function() {
|
||||
app.getProviderHolder( account.provider ).trigger( 'accountAddModal.content.fail', [ modal, account.provider ] );
|
||||
} )
|
||||
.always( function() {
|
||||
app.getProviderHolder( account.provider ).trigger( 'accountAddModal.content.always', [ modal, account.provider ] );
|
||||
} );
|
||||
},
|
||||
contentLoaded: function( data, status, xhr ) {
|
||||
|
||||
var modal = this;
|
||||
|
||||
// Data is already set in content.
|
||||
this.buttons.add.enable();
|
||||
this.buttons.cancel.enable();
|
||||
|
||||
app.getProviderHolder( account.provider ).trigger( 'accountAddModal.contentLoaded', [ modal ] );
|
||||
},
|
||||
// Before the modal is displayed.
|
||||
onOpenBefore: function() {
|
||||
|
||||
var modal = this;
|
||||
|
||||
modal.buttons.add.disable();
|
||||
modal.buttons.cancel.disable();
|
||||
modal.$body.addClass( 'wpforms-providers-account-add-modal' );
|
||||
|
||||
app.getProviderHolder( account.provider ).trigger( 'accountAddModal.onOpenBefore', [ modal ] );
|
||||
},
|
||||
// Before the modal is hidden.
|
||||
onClose: function() {
|
||||
|
||||
// If an account was configured successfully - show a modal with adding a new connection.
|
||||
if ( true === app.ui.account.isConfigured( account.provider ) ) {
|
||||
app.ui.connectionAdd( account.provider );
|
||||
}
|
||||
},
|
||||
icon: 'fa fa-info-circle',
|
||||
type: 'blue',
|
||||
buttons: {
|
||||
add: {
|
||||
text: wpforms_builder.provider_add_new_acc_btn,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
var modal = this;
|
||||
|
||||
app.getProviderHolder( account.provider ).trigger( 'accountAddModal.buttons.add.action.before', [ modal ] );
|
||||
|
||||
if (
|
||||
! _.isEmpty( account.provider ) &&
|
||||
typeof account.submitHandlers[ account.provider ] !== 'undefined'
|
||||
) {
|
||||
return account.submitHandlers[ account.provider ]( modal );
|
||||
}
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
text: wpforms_builder.cancel,
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Register a template for Add New Account modal window.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*/
|
||||
registerAddHandler: function( provider, handler ) {
|
||||
|
||||
if ( typeof provider === 'string' && typeof handler === 'function' ) {
|
||||
this.submitHandlers[ provider ] = handler;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check whether the defined provider is configured or not.
|
||||
*
|
||||
* @since 1.5.8
|
||||
* @since 1.5.9 Added a new parameter - provider.
|
||||
*
|
||||
* @param {string} provider Current provider slug.
|
||||
*
|
||||
* @returns {boolean} Account status.
|
||||
*/
|
||||
isConfigured: function( provider ) {
|
||||
|
||||
// Check if `Add New Account` button is hidden.
|
||||
return app.getProviderHolder( provider ).find( '.js-wpforms-builder-provider-account-add' ).hasClass( 'hidden' );
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a jQuery DOM object, that has all the provider-related DOM inside.
|
||||
*
|
||||
* @since 1.4.7
|
||||
*
|
||||
* @returns {object} jQuery DOM element.
|
||||
*/
|
||||
getProviderHolder: function( provider ) {
|
||||
return $( '#' + provider + '-provider' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPForms.Admin.Builder.Providers.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/providers.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/providers.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,681 @@
|
||||
/* global List, wpforms_builder, wpforms_addons, wpf, WPFormsBuilder, wpforms_education */
|
||||
|
||||
/**
|
||||
* Form Builder Setup Panel module.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPForms = window.WPForms || {};
|
||||
|
||||
WPForms.Admin = WPForms.Admin || {};
|
||||
WPForms.Admin.Builder = WPForms.Admin.Builder || {};
|
||||
|
||||
WPForms.Admin.Builder.Setup = WPForms.Admin.Builder.Setup || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Elements holder.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var el = {};
|
||||
|
||||
/**
|
||||
* Runtime variables.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var vars = {};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
|
||||
// Page load.
|
||||
$( window ).on( 'load', function() {
|
||||
|
||||
// In the case of jQuery 3.+, we need to wait for a ready event first.
|
||||
if ( typeof $.ready.then === 'function' ) {
|
||||
$.ready.then( app.load );
|
||||
} else {
|
||||
app.load();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* DOM is fully loaded.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.setup();
|
||||
app.setPanelsToggleState();
|
||||
app.setupTitleFocus();
|
||||
app.setTriggerBlankLink();
|
||||
app.events();
|
||||
|
||||
el.$builder.trigger( 'wpformsBuilderSetupReady' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Page load.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
load: function() {
|
||||
|
||||
app.applyTemplateOnRequest();
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup. Prepare some variables.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
setup: function() {
|
||||
|
||||
// Cache DOM elements.
|
||||
el = {
|
||||
$builder: $( '#wpforms-builder' ),
|
||||
$form: $( '#wpforms-builder-form' ),
|
||||
$formName: $( '#wpforms-setup-name' ),
|
||||
$panel: $( '#wpforms-panel-setup' ),
|
||||
$categories: $( '#wpforms-panel-setup .wpforms-setup-templates-categories' ),
|
||||
};
|
||||
|
||||
// Template list object.
|
||||
vars.templateList = new List( 'wpforms-setup-templates-list', {
|
||||
valueNames: [
|
||||
'wpforms-template-name',
|
||||
'wpforms-template-desc',
|
||||
{
|
||||
name: 'categories',
|
||||
attr: 'data-categories',
|
||||
},
|
||||
],
|
||||
} );
|
||||
|
||||
// Other values.
|
||||
vars.spinner = '<i class="wpforms-loading-spinner wpforms-loading-white wpforms-loading-inline"></i>';
|
||||
vars.formID = el.$form.data( 'id' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind events.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
el.$panel
|
||||
.on( 'keyup', '#wpforms-setup-template-search', app.searchTemplate )
|
||||
.on( 'click', '.wpforms-setup-templates-categories li', app.selectCategory )
|
||||
.on( 'click', '.wpforms-template-select', app.selectTemplate )
|
||||
.on( 'click', '.wpforms-trigger-blank', app.selectBlankTemplate );
|
||||
|
||||
// Focus on the form title field when displaying setup panel.
|
||||
el.$builder
|
||||
.on( 'wpformsPanelSwitched', app.setupTitleFocus );
|
||||
|
||||
// Sync Setup title and settings title.
|
||||
el.$builder
|
||||
.on( 'input', '#wpforms-panel-field-settings-form_title', app.syncTitle )
|
||||
.on( 'input', '#wpforms-setup-name', app.syncTitle );
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Set panels toggle buttons state.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
setPanelsToggleState: function() {
|
||||
|
||||
el.$builder
|
||||
.find( '#wpforms-panels-toggle button:not(.active)' )
|
||||
.toggleClass( 'wpforms-disabled', vars.formID === '' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Set attributes of "blank template" link.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
setTriggerBlankLink: function() {
|
||||
|
||||
el.$builder
|
||||
.find( '.wpforms-trigger-blank' )
|
||||
.attr( {
|
||||
'data-template-name-raw': 'Blank Form',
|
||||
'data-template': 'blank',
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Force focus on the form title field when switched to the the Setup panel.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {string} view Current view.
|
||||
*/
|
||||
setupTitleFocus: function( e, view ) {
|
||||
|
||||
if ( typeof view === 'undefined' ) {
|
||||
view = wpf.getQueryString( 'view' );
|
||||
}
|
||||
|
||||
if ( view === 'setup' ) {
|
||||
el.$formName.focus();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Keep Setup title and settings title instances the same.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
syncTitle: function( e ) {
|
||||
|
||||
if ( e.target.id === 'wpforms-setup-name' ) {
|
||||
$( '#wpforms-panel-field-settings-form_title' ).val( e.target.value );
|
||||
} else {
|
||||
$( '#wpforms-setup-name' ).val( e.target.value );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Search template.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
searchTemplate: function( e ) {
|
||||
|
||||
vars.templateList.search( $( this ).val() );
|
||||
},
|
||||
|
||||
/**
|
||||
* Select category.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
selectCategory: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var $item = $( this ),
|
||||
$active = $item.closest( 'ul' ).find( '.active' ),
|
||||
category = $item.data( 'category' );
|
||||
|
||||
$active.removeClass( 'active' );
|
||||
$item.addClass( 'active' );
|
||||
|
||||
vars.templateList.filter( function( item ) {
|
||||
return category === 'all' || item.values().categories.split( ',' ).indexOf( category ) > -1;
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Select template.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
selectTemplate: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var $button = $( e.target ),
|
||||
template = $button.data( 'template' ),
|
||||
templateName = $button.data( 'template-name-raw' ),
|
||||
formName = el.$formName.val() || templateName;
|
||||
|
||||
// Don't do anything for templates that trigger education modal OR addons-modal.
|
||||
if ( $button.hasClass( 'education-modal' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$panel.find( '.wpforms-template' ).removeClass( 'active' );
|
||||
$button.closest( '.wpforms-template' ).addClass( 'active' );
|
||||
|
||||
// Save original label.
|
||||
$button.data( 'labelOriginal', $button.html() );
|
||||
|
||||
// Display loading indicator.
|
||||
$button.html( vars.spinner + wpforms_builder.loading );
|
||||
|
||||
app.applyTemplate( formName, template, $button );
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply template.
|
||||
*
|
||||
* The final part of the select template routine.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*
|
||||
* @param {string} formName Name of the form.
|
||||
* @param {string} template Template slug.
|
||||
* @param {jQuery} $button Use template button object.
|
||||
*/
|
||||
applyTemplate: function( formName, template, $button ) {
|
||||
|
||||
el.$builder.trigger( 'wpformsTemplateSelect', template );
|
||||
|
||||
if ( vars.formID ) {
|
||||
|
||||
// Existing form.
|
||||
app.selectTemplateExistingForm( formName, template, $button );
|
||||
|
||||
} else {
|
||||
|
||||
// Create a new form.
|
||||
app.selectTemplateProcess( formName, template, $button );
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Select Blank template.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
selectBlankTemplate: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var $button = $( e.target ),
|
||||
formName = el.$formName.val() || wpforms_builder.blank_form,
|
||||
template = 'blank';
|
||||
|
||||
app.applyTemplate( formName, template, $button );
|
||||
},
|
||||
|
||||
/**
|
||||
* Select template. Existing form.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {string} formName Name of the form.
|
||||
* @param {string} template Template slug.
|
||||
* @param {jQuery} $button Use template button object.
|
||||
*/
|
||||
selectTemplateExistingForm: function( formName, template, $button ) {
|
||||
|
||||
$.confirm( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.template_confirm,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
|
||||
app.selectTemplateProcess( formName, template, $button );
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
text: wpforms_builder.cancel,
|
||||
action: function() {
|
||||
|
||||
app.selectTemplateCancel();
|
||||
},
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Select template.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {string} formName Name of the form.
|
||||
* @param {string} template Template slug.
|
||||
* @param {jQuery} $button Use template button object.
|
||||
*/
|
||||
selectTemplateProcess: function( formName, template, $button ) {
|
||||
|
||||
if ( $button.data( 'addons' ) ) {
|
||||
app.addonsModal( formName, template, $button );
|
||||
} else {
|
||||
app.selectTemplateProcessAjax( formName, template );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Cancel button click routine.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
selectTemplateCancel: function( ) {
|
||||
|
||||
var $template = el.$panel.find( '.wpforms-template.active' ),
|
||||
$button = $template.find( '.wpforms-template-select' );
|
||||
|
||||
$template.removeClass( 'active' );
|
||||
$button.html( $button.data( 'labelOriginal' ) );
|
||||
},
|
||||
|
||||
/**
|
||||
* Select template. Create or update form AJAX call.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {string} formName Name of the form.
|
||||
* @param {string} template Template slug.
|
||||
*/
|
||||
selectTemplateProcessAjax: function( formName, template ) {
|
||||
|
||||
WPFormsBuilder.showLoadingOverlay();
|
||||
|
||||
var data = {
|
||||
title: formName,
|
||||
action: vars.formID ? 'wpforms_update_form_template' : 'wpforms_new_form',
|
||||
template: template,
|
||||
form_id: vars.formID, // eslint-disable-line camelcase
|
||||
nonce: wpforms_builder.nonce,
|
||||
};
|
||||
|
||||
$.post( wpforms_builder.ajax_url, data )
|
||||
.done( function( res ) {
|
||||
|
||||
if ( res.success ) {
|
||||
window.location.href = res.data.redirect;
|
||||
} else {
|
||||
wpf.debug( res );
|
||||
app.selectTemplateProcessError( res.data );
|
||||
}
|
||||
} )
|
||||
.fail( function( xhr, textStatus, e ) {
|
||||
|
||||
wpf.debug( xhr.responseText || textStatus || '' );
|
||||
app.selectTemplateProcessError( '' );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Select template AJAX call error modal.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {string} error Error message.
|
||||
*/
|
||||
selectTemplateProcessError: function( error ) {
|
||||
|
||||
var content = error && error.length ? '<p>' + error + '</p>' : '';
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.error_select_template + content,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
|
||||
app.selectTemplateCancel();
|
||||
WPFormsBuilder.hideLoadingOverlay();
|
||||
},
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Open required addons alert.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {string} formName Name of the form.
|
||||
* @param {string} template Template slug.
|
||||
* @param {jQuery} $button Use template button object.
|
||||
*/
|
||||
addonsModal: function( formName, template, $button ) {
|
||||
|
||||
var templateName = $button.data( 'template-name-raw' ),
|
||||
addonsNames = $button.data( 'addons-names' ),
|
||||
addonsSlugs = $button.data( 'addons' ),
|
||||
addons = addonsSlugs.split( ',' ),
|
||||
prompt = addons.length > 1 ? wpforms_builder.template_addons_prompt : wpforms_builder.template_addon_prompt;
|
||||
|
||||
if ( ! addons.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.confirm( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: prompt
|
||||
.replace( /%template%/g, templateName )
|
||||
.replace( /%addons%/g, addonsNames ),
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_education.install_confirm,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
|
||||
this.$$confirm
|
||||
.prop( 'disabled', true )
|
||||
.html( vars.spinner + wpforms_education.activating );
|
||||
|
||||
this.$$cancel
|
||||
.prop( 'disabled', true );
|
||||
|
||||
app.installActivateAddons( addons, this, formName, template );
|
||||
|
||||
return false;
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
text: wpforms_education.cancel,
|
||||
action: function() {
|
||||
|
||||
app.selectTemplateCancel();
|
||||
},
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Install & Activate addons via AJAX.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {Array} addons Addons slugs.
|
||||
* @param {object} previousModal Previous modal instance.
|
||||
* @param {string} formName Name of the form.
|
||||
* @param {string} template Template slug.
|
||||
*/
|
||||
installActivateAddons: function( addons, previousModal, formName, template ) {
|
||||
|
||||
var ajaxResults = [],
|
||||
ajaxErrors = [],
|
||||
promiseChain = false;
|
||||
|
||||
// Put each of the ajax call promise to the chain.
|
||||
addons.forEach( function( addon ) {
|
||||
|
||||
if ( typeof promiseChain.done !== 'function' ) {
|
||||
promiseChain = app.installActivateAddonAjax( addon );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
promiseChain = promiseChain
|
||||
.done( function( value ) {
|
||||
|
||||
ajaxResults.push( value );
|
||||
|
||||
return app.installActivateAddonAjax( addon );
|
||||
} )
|
||||
.fail( function( error ) {
|
||||
ajaxErrors.push( error );
|
||||
} );
|
||||
} );
|
||||
|
||||
promiseChain
|
||||
|
||||
// Latest promise result and error.
|
||||
.done( function( value ) {
|
||||
ajaxResults.push( value );
|
||||
} )
|
||||
.fail( function( error ) {
|
||||
ajaxErrors.push( error );
|
||||
} )
|
||||
|
||||
// Finally, resolve all the promises.
|
||||
.always( function() {
|
||||
|
||||
previousModal.close();
|
||||
|
||||
if (
|
||||
ajaxResults.length > 0 &&
|
||||
wpf.listPluck( ajaxResults, 'success' ).every( Boolean ) && // Check if every `success` is true.
|
||||
ajaxErrors.length === 0
|
||||
) {
|
||||
app.selectTemplateProcessAjax( formName, template );
|
||||
} else {
|
||||
app.installActivateAddonsError( formName, template );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Install & Activate addons error modal.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {string} formName Name of the form.
|
||||
* @param {string} template Template slug.
|
||||
*/
|
||||
installActivateAddonsError: function( formName, template ) {
|
||||
|
||||
$.confirm( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.template_addons_error,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.use_template,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
|
||||
app.selectTemplateProcessAjax( formName, template );
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
text: wpforms_builder.cancel,
|
||||
action: function() {
|
||||
|
||||
app.selectTemplateCancel();
|
||||
},
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Install & Activate single addon via AJAX.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param {string} addon Addon slug.
|
||||
*
|
||||
* @returns {Promise} jQuery ajax call promise.
|
||||
*/
|
||||
installActivateAddonAjax: function( addon ) {
|
||||
|
||||
var addonData = wpforms_addons[ addon ],
|
||||
deferred = new $.Deferred();
|
||||
|
||||
if (
|
||||
! addonData ||
|
||||
[ 'activate', 'install' ].indexOf( addonData.action ) < 0
|
||||
) {
|
||||
deferred.resolve( false );
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
return $.post(
|
||||
wpforms_education.ajax_url,
|
||||
{
|
||||
action: 'wpforms_' + addonData.action + '_addon',
|
||||
nonce: wpforms_builder.admin_nonce,
|
||||
plugin: addonData.action === 'activate' ? addon + '/' + addon + '.php' : addonData.url,
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Initiate template processing for a new form.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
applyTemplateOnRequest: function() {
|
||||
|
||||
var urlParams = new URLSearchParams( window.location.search ),
|
||||
templateId = urlParams.get( 'template_id' );
|
||||
|
||||
if (
|
||||
urlParams.get( 'view' ) !== 'setup' ||
|
||||
urlParams.get( 'form_id' ) ||
|
||||
! templateId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$panel.find( '.wpforms-template .wpforms-btn[data-template="' + templateId + '"]' ).click();
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPForms.Admin.Builder.Setup.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/setup.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/setup.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,107 @@
|
||||
/* global WPForms, jQuery, Map, wpforms_builder, wpforms_builder_providers, _ */
|
||||
|
||||
var WPForms = window.WPForms || {};
|
||||
WPForms.Admin = WPForms.Admin || {};
|
||||
WPForms.Admin.Builder = WPForms.Admin.Builder || {};
|
||||
|
||||
WPForms.Admin.Builder.Templates = WPForms.Admin.Builder.Templates || (function ( document, window, $ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Private functions and properties.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
var __private = {
|
||||
|
||||
/**
|
||||
* All templating functions for providers are stored here in a Map.
|
||||
* Key is a template name, value - Underscore.js templating function.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @type {Map}
|
||||
*/
|
||||
previews: new Map()
|
||||
};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine. DOM is not ready yet, use only to init something.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*/
|
||||
init: function () {
|
||||
|
||||
// Do that when DOM is ready.
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* DOM is fully loaded.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*/
|
||||
ready: function () {
|
||||
|
||||
$( '#wpforms-panel-providers' ).trigger( 'WPForms.Admin.Builder.Templates.ready' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Register and compile all templates.
|
||||
* All data is saved in a Map.
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @param {string[]} templates Array of template names.
|
||||
*/
|
||||
add: function ( templates ) {
|
||||
|
||||
templates.forEach( function ( template ) {
|
||||
if ( typeof template === 'string' ) {
|
||||
__private.previews.set( template, wp.template( template ) );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a templating function (to compile later with data).
|
||||
*
|
||||
* @since 1.4.8
|
||||
*
|
||||
* @param {string} template ID of a template to retrieve from a cache.
|
||||
*
|
||||
* @returns {*} A callable that after compiling will always return a string.
|
||||
*/
|
||||
get: function ( template ) {
|
||||
|
||||
var preview = __private.previews.get( template );
|
||||
|
||||
if ( typeof preview !== 'undefined' ) {
|
||||
return preview;
|
||||
}
|
||||
|
||||
return function () {
|
||||
return '';
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
})( document, window, jQuery );
|
||||
|
||||
// Initialize.
|
||||
WPForms.Admin.Builder.Templates.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/templates.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/builder/templates.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var WPForms=window.WPForms||{};WPForms.Admin=WPForms.Admin||{},WPForms.Admin.Builder=WPForms.Admin.Builder||{},WPForms.Admin.Builder.Templates=WPForms.Admin.Builder.Templates||function(e){"use strict";var r={previews:new Map},i={init:function(){e(i.ready)},ready:function(){e("#wpforms-panel-providers").trigger("WPForms.Admin.Builder.Templates.ready")},add:function(e){e.forEach(function(e){"string"==typeof e&&r.previews.set(e,wp.template(e))})},get:function(e){e=r.previews.get(e);return void 0!==e?e:function(){return""}}};return i}((document,window,jQuery)),WPForms.Admin.Builder.Templates.init();
|
||||
@@ -0,0 +1,180 @@
|
||||
/* global wpforms_challenge_admin, ajaxurl, WPFormsBuilder */
|
||||
/**
|
||||
* WPForms Challenge Admin function.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.6.2 Challenge v2
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var WPFormsChallenge = window.WPFormsChallenge || {};
|
||||
|
||||
WPFormsChallenge.admin = window.WPFormsChallenge.admin || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
l10n: wpforms_challenge_admin,
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
$( '.wpforms-challenge-list-block' )
|
||||
.on( 'click', '.challenge-skip', app.skipChallenge )
|
||||
.on( 'click', '.challenge-cancel', app.cancelChallenge )
|
||||
.on( 'click', '.toggle-list', app.toggleList );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle list icon click.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
toggleList: function( e ) {
|
||||
|
||||
var $icon = $( e.target ),
|
||||
$listBlock = $( '.wpforms-challenge-list-block' );
|
||||
|
||||
if ( ! $listBlock.length || ! $icon.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $listBlock.hasClass( 'closed' ) ) {
|
||||
wpforms_challenge_admin.option.window_closed = '0';
|
||||
$listBlock.removeClass( 'closed' );
|
||||
|
||||
setTimeout( function() {
|
||||
$listBlock.removeClass( 'transition-back' );
|
||||
}, 600 );
|
||||
} else {
|
||||
wpforms_challenge_admin.option.window_closed = '1';
|
||||
$listBlock.addClass( 'closed' );
|
||||
|
||||
// Add `transition-back` class when the forward transition is completed.
|
||||
// It is needed to properly implement transitions order for some elements.
|
||||
setTimeout( function() {
|
||||
$listBlock.addClass( 'transition-back' );
|
||||
}, 600 );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Skip the Challenge without starting it.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
skipChallenge: function() {
|
||||
|
||||
var optionData = {
|
||||
status : 'skipped',
|
||||
seconds_spent: 0,
|
||||
seconds_left : app.l10n.minutes_left * 60,
|
||||
};
|
||||
|
||||
$( '.wpforms-challenge' ).remove();
|
||||
|
||||
app.saveChallengeOption( optionData )
|
||||
.done( location.reload.bind( location ) ); // Reload the page to remove WPForms Challenge JS.
|
||||
},
|
||||
|
||||
/**
|
||||
* Cancel Challenge after starting it.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
cancelChallenge: function() {
|
||||
|
||||
var core = WPFormsChallenge.core;
|
||||
|
||||
core.timer.pause();
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
var optionData = {
|
||||
status : 'canceled',
|
||||
seconds_spent: core.timer.getSecondsSpent(),
|
||||
seconds_left : core.timer.getSecondsLeft(),
|
||||
feedback_sent: false,
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
core.removeChallengeUI();
|
||||
core.clearLocalStorage();
|
||||
|
||||
if ( typeof WPFormsBuilder !== 'undefined' ) {
|
||||
WPFormsChallenge.admin.saveChallengeOption( optionData )
|
||||
.done( WPFormsBuilder.formSave ) // Save the form before reloading if we're in a WPForms Builder.
|
||||
.done( location.reload.bind( location ) ); // Reload the page to remove WPForms Challenge JS.
|
||||
} else {
|
||||
WPFormsChallenge.admin.saveChallengeOption( optionData )
|
||||
.done( app.triggerPageSave ); // Assume we're on form embed page.
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Set Challenge parameter(s) to Challenge option.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {object} optionData Query using option schema keys.
|
||||
*
|
||||
* @returns {promise} jQuey.post() promise interface.
|
||||
*/
|
||||
saveChallengeOption: function( optionData ) {
|
||||
|
||||
var data = {
|
||||
action : 'wpforms_challenge_save_option',
|
||||
option_data: optionData,
|
||||
_wpnonce : app.l10n.nonce,
|
||||
};
|
||||
|
||||
// Save window closed (collapsed) state as well.
|
||||
data.option_data.window_closed = wpforms_challenge_admin.option.window_closed;
|
||||
|
||||
$.extend( wpforms_challenge_admin.option, optionData );
|
||||
|
||||
return $.post( ajaxurl, data, function( response ) {
|
||||
if ( ! response.success ) {
|
||||
console.error( 'Error saving WPForms Challenge option.' );
|
||||
}
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
WPFormsChallenge.admin.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/challenge/challenge-admin.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/challenge/challenge-admin.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsChallenge=window.WPFormsChallenge||{};WPFormsChallenge.admin=window.WPFormsChallenge.admin||function(o){var l={l10n:wpforms_challenge_admin,init:function(){o(l.ready)},ready:function(){l.events()},events:function(){o(".wpforms-challenge-list-block").on("click",".challenge-skip",l.skipChallenge).on("click",".challenge-cancel",l.cancelChallenge).on("click",".toggle-list",l.toggleList)},toggleList:function(e){var e=o(e.target),n=o(".wpforms-challenge-list-block");n.length&&e.length&&(n.hasClass("closed")?(wpforms_challenge_admin.option.window_closed="0",n.removeClass("closed"),setTimeout(function(){n.removeClass("transition-back")},600)):(wpforms_challenge_admin.option.window_closed="1",n.addClass("closed"),setTimeout(function(){n.addClass("transition-back")},600)))},skipChallenge:function(){var e={status:"skipped",seconds_spent:0,seconds_left:60*l.l10n.minutes_left};o(".wpforms-challenge").remove(),l.saveChallengeOption(e).done(location.reload.bind(location))},cancelChallenge:function(){var e=WPFormsChallenge.core;e.timer.pause();var n={status:"canceled",seconds_spent:e.timer.getSecondsSpent(),seconds_left:e.timer.getSecondsLeft(),feedback_sent:!1};e.removeChallengeUI(),e.clearLocalStorage(),"undefined"!=typeof WPFormsBuilder?WPFormsChallenge.admin.saveChallengeOption(n).done(WPFormsBuilder.formSave).done(location.reload.bind(location)):WPFormsChallenge.admin.saveChallengeOption(n).done(l.triggerPageSave)},saveChallengeOption:function(e){var n={action:"wpforms_challenge_save_option",option_data:e,_wpnonce:l.l10n.nonce};return n.option_data.window_closed=wpforms_challenge_admin.option.window_closed,o.extend(wpforms_challenge_admin.option,e),o.post(ajaxurl,n,function(e){e.success||console.error("Error saving WPForms Challenge option.")})}};return l}((document,window,jQuery)),WPFormsChallenge.admin.init();
|
||||
@@ -0,0 +1,274 @@
|
||||
/* global WPForms, WPFormsBuilder, wpforms_challenge_admin, WPFormsFormEmbedWizard */
|
||||
/**
|
||||
* WPForms Challenge function.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.6.2 Challenge v2
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var WPFormsChallenge = window.WPFormsChallenge || {};
|
||||
|
||||
WPFormsChallenge.builder = window.WPFormsChallenge.builder || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
$( window ).on( 'load', function() {
|
||||
|
||||
// in case of jQuery 3.+ we need to wait for an `ready` event first.
|
||||
if ( typeof $.ready.then === 'function' ) {
|
||||
$.ready.then( app.load );
|
||||
} else {
|
||||
app.load();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.setup();
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Window load.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
load: function() {
|
||||
|
||||
if ( [ 'started', 'paused' ].indexOf( wpforms_challenge_admin.option.status ) > -1 ) {
|
||||
WPFormsChallenge.core.updateTooltipUI();
|
||||
app.gotoStep();
|
||||
}
|
||||
|
||||
$( '.wpforms-challenge' ).show();
|
||||
},
|
||||
|
||||
/**
|
||||
* Initial setup.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
setup: function() {
|
||||
|
||||
if ( wpforms_challenge_admin.option.status === 'inited' ) {
|
||||
WPFormsChallenge.core.clearLocalStorage();
|
||||
app.showWelcomePopup();
|
||||
}
|
||||
|
||||
$( '#wpforms-embed' ).addClass( 'wpforms-disabled' );
|
||||
|
||||
var tooltipAnchors = [
|
||||
'#wpforms-setup-name',
|
||||
'.wpforms-setup-title .wpforms-setup-title-after',
|
||||
'#add-fields a i',
|
||||
'#wpforms-builder-settings-notifications-title',
|
||||
];
|
||||
|
||||
$.each( tooltipAnchors, function( i, anchor ) {
|
||||
|
||||
WPFormsChallenge.core.initTooltips( i + 1, anchor, null );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
// Start the Challenge.
|
||||
$( '#wpforms-challenge-welcome-builder-popup' ).on( 'click', 'button', app.startChallenge );
|
||||
|
||||
// Step 1.
|
||||
$( '.wpforms-challenge-step1-done' ).on( 'click', function() {
|
||||
WPFormsChallenge.core.stepCompleted( 1 );
|
||||
} );
|
||||
|
||||
$( '#wpforms-builder' )
|
||||
|
||||
// Register select template event when the setup panel is ready.
|
||||
.on( 'wpformsBuilderSetupReady', function() {
|
||||
app.eventSelectTemplate();
|
||||
} )
|
||||
|
||||
// Restore tooltips when switching builder panels/sections.
|
||||
.on( 'wpformsPanelSwitch wpformsPanelSectionSwitch', function() {
|
||||
WPFormsChallenge.core.updateTooltipUI();
|
||||
} );
|
||||
|
||||
// Step 3 - Add fields.
|
||||
$( '.wpforms-challenge-step3-done' ).on( 'click', function() {
|
||||
WPFormsChallenge.core.stepCompleted( 3 );
|
||||
app.gotoStep( 4 );
|
||||
} );
|
||||
|
||||
// Step 4 - Notifications.
|
||||
$( document ).on( 'click', '.wpforms-challenge-step4-done', app.showEmbedPopup );
|
||||
|
||||
// Tooltipster ready.
|
||||
$.tooltipster.on( 'ready', app.tooltipsterReady );
|
||||
},
|
||||
|
||||
/**
|
||||
* Register select template event.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
eventSelectTemplate: function() {
|
||||
|
||||
$( '#wpforms-panel-setup' )
|
||||
|
||||
// Step 2 - Select the Form template.
|
||||
.off( 'click', '.wpforms-template-select' ) // Intercept Form Builder's form template selection and apply own logic.
|
||||
.on( 'click', '.wpforms-template-select', function( e ) {
|
||||
app.builderTemplateSelect( this, e );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Start the Challenge.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
startChallenge: function() {
|
||||
|
||||
WPFormsChallenge.admin.saveChallengeOption( { status: 'started' } );
|
||||
WPFormsChallenge.core.initListUI( 'started' );
|
||||
$( '.wpforms-challenge-popup-container' ).fadeOut( function() {
|
||||
$( '#wpforms-challenge-welcome-builder-popup' ).hide();
|
||||
} );
|
||||
WPFormsChallenge.core.timer.run( WPFormsChallenge.core.timer.initialSecondsLeft );
|
||||
WPFormsChallenge.core.updateTooltipUI();
|
||||
},
|
||||
|
||||
/**
|
||||
* Go to Step.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {number|string} step Last saved step.
|
||||
*/
|
||||
gotoStep: function( step ) { // eslint-disable-line
|
||||
|
||||
step = step || ( WPFormsChallenge.core.loadStep() + 1 );
|
||||
|
||||
switch ( step ) {
|
||||
case 1:
|
||||
case 2:
|
||||
WPFormsBuilder.panelSwitch( 'setup' );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
WPFormsBuilder.panelSwitch( 'fields' );
|
||||
break;
|
||||
|
||||
case 4:
|
||||
WPFormsBuilder.panelSwitch( 'settings' );
|
||||
WPFormsBuilder.panelSectionSwitch( $( '.wpforms-panel .wpforms-panel-sidebar-section-notifications' ) );
|
||||
break;
|
||||
|
||||
case 5:
|
||||
app.showEmbedPopup();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Save the second step before a template is selected.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {string} el Element selector.
|
||||
* @param {object} e Event.
|
||||
*/
|
||||
builderTemplateSelect: function( el, e ) {
|
||||
|
||||
if ( wpforms_challenge_admin.option.status === 'paused' ) {
|
||||
WPFormsChallenge.core.resumeChallenge();
|
||||
}
|
||||
|
||||
var step = WPFormsChallenge.core.loadStep();
|
||||
|
||||
if ( step <= 1 ) {
|
||||
WPFormsChallenge.core.stepCompleted( 2 )
|
||||
.done( WPForms.Admin.Builder.Setup.selectTemplate.bind( null, e ) );
|
||||
return;
|
||||
}
|
||||
|
||||
WPForms.Admin.Builder.Setup.selectTemplate.bind( null, e );
|
||||
},
|
||||
|
||||
/**
|
||||
* Tooltipster ready event callback.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
tooltipsterReady: function( e ) {
|
||||
|
||||
var step = $( e.origin ).data( 'wpforms-challenge-step' );
|
||||
var formId = $( '#wpforms-builder-form' ).data( 'id' );
|
||||
|
||||
step = parseInt( step, 10 ) || 0;
|
||||
formId = parseInt( formId, 10 ) || 0;
|
||||
|
||||
// Save challenge form ID right after it's created.
|
||||
if ( 3 === step && formId > 0 ) {
|
||||
WPFormsChallenge.admin.saveChallengeOption( { form_id: formId } ); // eslint-disable-line camelcase
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Display 'Welcome to the Form Builder' popup.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
showWelcomePopup: function() {
|
||||
|
||||
$( '#wpforms-challenge-welcome-builder-popup' ).show();
|
||||
$( '.wpforms-challenge-popup-container' ).fadeIn();
|
||||
},
|
||||
|
||||
/**
|
||||
* Display 'Embed in a Page' popup.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
showEmbedPopup: function() {
|
||||
|
||||
WPFormsChallenge.core.stepCompleted( 4 );
|
||||
WPFormsFormEmbedWizard.openPopup();
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsChallenge.builder.init();
|
||||
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsChallenge=window.WPFormsChallenge||{};WPFormsChallenge.builder=window.WPFormsChallenge.builder||function(e,o,l){var t={init:function(){l(t.ready),l(o).on("load",function(){"function"==typeof l.ready.then?l.ready.then(t.load):t.load()})},ready:function(){t.setup(),t.events()},load:function(){-1<["started","paused"].indexOf(wpforms_challenge_admin.option.status)&&(WPFormsChallenge.core.updateTooltipUI(),t.gotoStep()),l(".wpforms-challenge").show()},setup:function(){"inited"===wpforms_challenge_admin.option.status&&(WPFormsChallenge.core.clearLocalStorage(),t.showWelcomePopup()),l("#wpforms-embed").addClass("wpforms-disabled");l.each(["#wpforms-setup-name",".wpforms-setup-title .wpforms-setup-title-after","#add-fields a i","#wpforms-builder-settings-notifications-title"],function(e,o){WPFormsChallenge.core.initTooltips(e+1,o,null)})},events:function(){l("#wpforms-challenge-welcome-builder-popup").on("click","button",t.startChallenge),l(".wpforms-challenge-step1-done").on("click",function(){WPFormsChallenge.core.stepCompleted(1)}),l("#wpforms-builder").on("wpformsBuilderSetupReady",function(){t.eventSelectTemplate()}).on("wpformsPanelSwitch wpformsPanelSectionSwitch",function(){WPFormsChallenge.core.updateTooltipUI()}),l(".wpforms-challenge-step3-done").on("click",function(){WPFormsChallenge.core.stepCompleted(3),t.gotoStep(4)}),l(e).on("click",".wpforms-challenge-step4-done",t.showEmbedPopup),l.tooltipster.on("ready",t.tooltipsterReady)},eventSelectTemplate:function(){l("#wpforms-panel-setup").off("click",".wpforms-template-select").on("click",".wpforms-template-select",function(e){t.builderTemplateSelect(this,e)})},startChallenge:function(){WPFormsChallenge.admin.saveChallengeOption({status:"started"}),WPFormsChallenge.core.initListUI("started"),l(".wpforms-challenge-popup-container").fadeOut(function(){l("#wpforms-challenge-welcome-builder-popup").hide()}),WPFormsChallenge.core.timer.run(WPFormsChallenge.core.timer.initialSecondsLeft),WPFormsChallenge.core.updateTooltipUI()},gotoStep:function(e){switch(e=e||WPFormsChallenge.core.loadStep()+1){case 1:case 2:WPFormsBuilder.panelSwitch("setup");break;case 3:WPFormsBuilder.panelSwitch("fields");break;case 4:WPFormsBuilder.panelSwitch("settings"),WPFormsBuilder.panelSectionSwitch(l(".wpforms-panel .wpforms-panel-sidebar-section-notifications"));break;case 5:t.showEmbedPopup()}},builderTemplateSelect:function(e,o){"paused"===wpforms_challenge_admin.option.status&&WPFormsChallenge.core.resumeChallenge(),WPFormsChallenge.core.loadStep()<=1?WPFormsChallenge.core.stepCompleted(2).done(WPForms.Admin.Builder.Setup.selectTemplate.bind(null,o)):WPForms.Admin.Builder.Setup.selectTemplate.bind(null,o)},tooltipsterReady:function(e){var o=l(e.origin).data("wpforms-challenge-step"),e=l("#wpforms-builder-form").data("id"),o=parseInt(o,10)||0,e=parseInt(e,10)||0;3===o&&0<e&&WPFormsChallenge.admin.saveChallengeOption({form_id:e})},showWelcomePopup:function(){l("#wpforms-challenge-welcome-builder-popup").show(),l(".wpforms-challenge-popup-container").fadeIn()},showEmbedPopup:function(){WPFormsChallenge.core.stepCompleted(4),WPFormsFormEmbedWizard.openPopup()}};return t}(document,window,jQuery),WPFormsChallenge.builder.init();
|
||||
@@ -0,0 +1,813 @@
|
||||
/* global wpforms_challenge_admin */
|
||||
/**
|
||||
* WPForms Challenge function.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.6.2 Challenge v2
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var WPFormsChallenge = window.WPFormsChallenge || {};
|
||||
|
||||
WPFormsChallenge.core = window.WPFormsChallenge.core || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {};
|
||||
|
||||
/**
|
||||
* Runtime variables.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var vars = {};
|
||||
|
||||
/**
|
||||
* DOM elements.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var el = {};
|
||||
|
||||
/**
|
||||
* Timer functions and properties.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var timer = {
|
||||
|
||||
/**
|
||||
* Number of minutes to complete the challenge.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
initialSecondsLeft: WPFormsChallenge.admin.l10n.minutes_left * 60,
|
||||
|
||||
/**
|
||||
* Load timer ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @returns {string} ID from setInterval().
|
||||
*/
|
||||
loadId: function() {
|
||||
|
||||
return localStorage.getItem( 'wpformsChallengeTimerId' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Save timer ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number|string} id setInterval() ID to save.
|
||||
*/
|
||||
saveId: function( id ) {
|
||||
|
||||
localStorage.setItem( 'wpformsChallengeTimerId', id );
|
||||
},
|
||||
|
||||
/**
|
||||
* Run the timer.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number} secondsLeft Number of seconds left to complete the Challenge.
|
||||
*
|
||||
* @returns {string|void} ID from setInterval().
|
||||
*/
|
||||
run: function( secondsLeft ) {
|
||||
|
||||
if ( 5 === app.loadStep() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var timerId = setInterval( function() {
|
||||
|
||||
app.updateTimerUI( secondsLeft );
|
||||
secondsLeft--;
|
||||
if ( 0 > secondsLeft ) {
|
||||
timer.saveSecondsLeft( 0 );
|
||||
clearInterval( timerId );
|
||||
}
|
||||
}, 1000 );
|
||||
|
||||
timer.saveId( timerId );
|
||||
|
||||
return timerId;
|
||||
},
|
||||
|
||||
/**
|
||||
* Pause the timer.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
pause: function() {
|
||||
|
||||
var timerId;
|
||||
var elSeconds;
|
||||
var secondsLeft = timer.getSecondsLeft();
|
||||
|
||||
if ( 0 === secondsLeft || 5 === app.loadStep() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
timerId = timer.loadId();
|
||||
clearInterval( timerId );
|
||||
|
||||
elSeconds = $( '#wpforms-challenge-timer' ).data( 'seconds-left' );
|
||||
|
||||
if ( elSeconds ) {
|
||||
timer.saveSecondsLeft( elSeconds );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resume the timer.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
resume: function() {
|
||||
|
||||
var timerId;
|
||||
var secondsLeft = timer.getSecondsLeft();
|
||||
|
||||
if ( 0 === secondsLeft || 5 === app.loadStep() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
timerId = timer.loadId();
|
||||
|
||||
if ( timerId ) {
|
||||
clearInterval( timerId );
|
||||
}
|
||||
|
||||
timer.run( secondsLeft );
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear all frontend saved timer data.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
clear: function() {
|
||||
|
||||
localStorage.removeItem( 'wpformsChallengeSecondsLeft' );
|
||||
localStorage.removeItem( 'wpformsChallengeTimerId' );
|
||||
localStorage.removeItem( 'wpformsChallengeTimerStatus' );
|
||||
$( '#wpforms-challenge-timer' ).removeData( 'seconds-left' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Get number of seconds left to complete the Challenge.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @returns {number} Number of seconds left to complete the Challenge.
|
||||
*/
|
||||
getSecondsLeft: function() {
|
||||
|
||||
var secondsLeft = localStorage.getItem( 'wpformsChallengeSecondsLeft' );
|
||||
secondsLeft = parseInt( secondsLeft, 10 ) || 0;
|
||||
|
||||
return secondsLeft;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get number of seconds spent completing the Challenge.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number} secondsLeft Number of seconds left to complete the Challenge.
|
||||
*
|
||||
* @returns {number} Number of seconds spent completing the Challenge.
|
||||
*/
|
||||
getSecondsSpent: function( secondsLeft ) {
|
||||
|
||||
secondsLeft = secondsLeft || timer.getSecondsLeft();
|
||||
|
||||
return timer.initialSecondsLeft - secondsLeft;
|
||||
},
|
||||
|
||||
/**
|
||||
* Save number of seconds left to complete the Challenge.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number|string} secondsLeft Number of seconds left to complete the Challenge.
|
||||
*/
|
||||
saveSecondsLeft: function( secondsLeft ) {
|
||||
|
||||
localStorage.setItem( 'wpformsChallengeSecondsLeft', secondsLeft );
|
||||
},
|
||||
|
||||
/**
|
||||
* Get 'minutes' part of timer display.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number} secondsLeft Number of seconds left to complete the Challenge.
|
||||
*
|
||||
* @returns {number} 'Minutes' part of timer display.
|
||||
*/
|
||||
getMinutesFormatted: function( secondsLeft ) {
|
||||
|
||||
secondsLeft = secondsLeft || timer.getSecondsLeft();
|
||||
|
||||
return Math.floor( secondsLeft / 60 );
|
||||
},
|
||||
|
||||
/**
|
||||
* Get 'seconds' part of timer display.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number} secondsLeft Number of seconds left to complete the Challenge.
|
||||
*
|
||||
* @returns {number} 'Seconds' part of timer display.
|
||||
*/
|
||||
getSecondsFormatted: function( secondsLeft ) {
|
||||
|
||||
secondsLeft = secondsLeft || timer.getSecondsLeft();
|
||||
|
||||
return secondsLeft % 60;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get formatted timer for display.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number} secondsLeft Number of seconds left to complete the Challenge.
|
||||
*
|
||||
* @returns {string} Formatted timer for display.
|
||||
*/
|
||||
getFormatted: function( secondsLeft ) {
|
||||
|
||||
secondsLeft = secondsLeft || timer.getSecondsLeft();
|
||||
|
||||
var timerMinutes = timer.getMinutesFormatted( secondsLeft );
|
||||
var timerSeconds = timer.getSecondsFormatted( secondsLeft );
|
||||
|
||||
return timerMinutes + ( 9 < timerSeconds ? ':' : ':0' ) + timerSeconds;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*/
|
||||
app = {
|
||||
|
||||
/**
|
||||
* Public timer functions and properties.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
timer: timer,
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
$( window ).on( 'load', function() {
|
||||
|
||||
// in case of jQuery 3.+ we need to wait for an `ready` event first.
|
||||
if ( typeof $.ready.then === 'function' ) {
|
||||
$.ready.then( app.load );
|
||||
} else {
|
||||
app.load();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.setup();
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Window load.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
load: function() {
|
||||
|
||||
if ( wpforms_challenge_admin.option.status === 'started' ) {
|
||||
app.timer.run( app.timer.getSecondsLeft() );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initial setup.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
setup: function() {
|
||||
|
||||
var secondsLeft;
|
||||
var timerId = app.timer.loadId();
|
||||
|
||||
if ( timerId ) {
|
||||
clearInterval( timerId );
|
||||
secondsLeft = app.timer.getSecondsLeft();
|
||||
}
|
||||
|
||||
if ( ! timerId || 0 === app.loadStep() || wpforms_challenge_admin.option.status === 'inited' ) {
|
||||
secondsLeft = app.timer.initialSecondsLeft;
|
||||
}
|
||||
|
||||
app.initElements();
|
||||
app.refreshStep();
|
||||
app.initListUI( null, true );
|
||||
app.updateListUI();
|
||||
app.updateTimerUI( secondsLeft );
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
$( [ window, document ] )
|
||||
.on( 'blur', app.pauseChallenge )
|
||||
.on( 'focus', app.resumeChallenge )
|
||||
.on( 'click', '.wpforms-challenge-done-btn', app.resumeChallenge );
|
||||
|
||||
el.$btnPause.on( 'click', app.pauseChallenge );
|
||||
el.$btnResume.on( 'click', app.resumeChallenge );
|
||||
|
||||
el.$listSteps.on( 'click', '.wpforms-challenge-item-current', app.refreshPage );
|
||||
},
|
||||
|
||||
/**
|
||||
* DOM elements.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
initElements: function() {
|
||||
|
||||
el = {
|
||||
$challenge: $( '.wpforms-challenge' ),
|
||||
$btnPause: $( '.wpforms-challenge-pause' ),
|
||||
$btnResume: $( '.wpforms-challenge-resume' ),
|
||||
$listSteps: $( '.wpforms-challenge-list' ),
|
||||
$listBlock: $( '.wpforms-challenge-list-block' ),
|
||||
$listBtnToggle: $( '.wpforms-challenge-list-block .toggle-list' ),
|
||||
$progressBar: $( '.wpforms-challenge-bar' ),
|
||||
$tooltipBtnDone: function() {
|
||||
return $( '.wpforms-challenge-tooltip .wpforms-challenge-done-btn' );
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Get last saved step.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @returns {number} Last saved step.
|
||||
*/
|
||||
loadStep: function() {
|
||||
|
||||
var step = localStorage.getItem( 'wpformsChallengeStep' );
|
||||
step = parseInt( step, 10 ) || 0;
|
||||
|
||||
return step;
|
||||
},
|
||||
|
||||
/**
|
||||
* Save Challenge step.
|
||||
*
|
||||
* @param {number|string} step Step to save.
|
||||
*
|
||||
* @returns {object} jqXHR object from saveChallengeOption().
|
||||
*/
|
||||
saveStep: function( step ) {
|
||||
|
||||
localStorage.setItem( 'wpformsChallengeStep', step );
|
||||
|
||||
return WPFormsChallenge.admin.saveChallengeOption( { step: step } );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a step with backend data..
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
refreshStep: function() {
|
||||
|
||||
var savedStep = el.$challenge.data( 'wpforms-challenge-saved-step' );
|
||||
savedStep = parseInt( savedStep, 10 ) || 0;
|
||||
|
||||
// Step saved on a backend has a priority.
|
||||
if ( app.loadStep() !== savedStep ) {
|
||||
app.saveStep( savedStep );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Complete Challenge step.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number|string} step Step to complete.
|
||||
*
|
||||
* @returns {object} jqXHR object from saveStep().
|
||||
*/
|
||||
stepCompleted: function( step ) {
|
||||
|
||||
app.updateListUI( step );
|
||||
app.updateTooltipUI( step );
|
||||
|
||||
return app.saveStep( step );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize Challenge tooltips.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number|string} step Last saved step.
|
||||
* @param {string} anchor Element selector to bind tooltip to.
|
||||
* @param {object} args Tooltipster arguments.
|
||||
*/
|
||||
initTooltips: function( step, anchor, args ) {
|
||||
|
||||
if ( typeof $.fn.tooltipster === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $dot = $( '<span class="wpforms-challenge-dot wpforms-challenge-dot-step' + step + '" data-wpforms-challenge-step="' + step + '"> </span>' );
|
||||
var tooltipsterArgs = {
|
||||
content : $( '#tooltip-content' + step ),
|
||||
trigger : null,
|
||||
interactive : true,
|
||||
animationDuration: 0,
|
||||
delay : 0,
|
||||
theme : [ 'tooltipster-default', 'wpforms-challenge-tooltip' ],
|
||||
side : [ 'top' ],
|
||||
distance : 3,
|
||||
functionReady : function( instance, helper ) {
|
||||
|
||||
$( helper.tooltip ).addClass( 'wpforms-challenge-tooltip-step' + step );
|
||||
|
||||
// Custom positioning.
|
||||
if ( step === 4 || step === 3 ) {
|
||||
instance.option( 'side', 'right' );
|
||||
}
|
||||
|
||||
// Reposition is needed to render max-width CSS correctly.
|
||||
instance.reposition();
|
||||
},
|
||||
};
|
||||
|
||||
if ( typeof args === 'object' && args !== null ) {
|
||||
$.extend( tooltipsterArgs, args );
|
||||
}
|
||||
|
||||
$dot.insertAfter( anchor ).tooltipster( tooltipsterArgs );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update tooltips appearance.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number|string} step Last saved step.
|
||||
*/
|
||||
updateTooltipUI: function( step ) {
|
||||
|
||||
var nextStep;
|
||||
|
||||
step = step || app.loadStep();
|
||||
nextStep = step + 1;
|
||||
|
||||
$( '.wpforms-challenge-dot' ).each( function( i, el ) {
|
||||
|
||||
var $dot = $( el ),
|
||||
elStep = $dot.data( 'wpforms-challenge-step' );
|
||||
|
||||
if ( elStep < nextStep ) {
|
||||
$dot.addClass( 'wpforms-challenge-dot-completed' );
|
||||
}
|
||||
|
||||
if ( elStep > nextStep ) {
|
||||
$dot.addClass( 'wpforms-challenge-dot-next' );
|
||||
}
|
||||
|
||||
if ( elStep === nextStep ) {
|
||||
$dot.removeClass( 'wpforms-challenge-dot-completed wpforms-challenge-dot-next' );
|
||||
}
|
||||
|
||||
// Zero timeout is needed to properly detect $el visibility.
|
||||
setTimeout( function() {
|
||||
if ( $dot.is( ':visible' ) && elStep === nextStep ) {
|
||||
$dot.tooltipster( 'open' );
|
||||
} else {
|
||||
$dot.tooltipster( 'close' );
|
||||
}
|
||||
}, 0 );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Init ListUI.
|
||||
*
|
||||
* @since {vERSION}
|
||||
*
|
||||
* @param {number|string} status Challenge status.
|
||||
* @param {boolean} initial Initial run, false by default.
|
||||
*/
|
||||
initListUI: function( status, initial ) {
|
||||
|
||||
status = status || wpforms_challenge_admin.option.status;
|
||||
|
||||
if ( [ 'started', 'paused' ].indexOf( status ) > -1 ) {
|
||||
el.$listBlock.find( 'p' ).hide();
|
||||
el.$listBtnToggle.show();
|
||||
el.$progressBar.show();
|
||||
|
||||
// Transform skip button to cancel button.
|
||||
var $skipBtn = el.$listBlock.find( '.list-block-button.challenge-skip' );
|
||||
|
||||
$skipBtn
|
||||
.attr( 'title', $skipBtn.data( 'cancel-title' ) )
|
||||
.removeClass( 'challenge-skip' )
|
||||
.addClass( 'challenge-cancel' );
|
||||
}
|
||||
|
||||
// Set initial window closed (collapsed) state if window is short or if it is closed manually.
|
||||
if (
|
||||
initial &&
|
||||
(
|
||||
( $( window ).height() < 900 && wpforms_challenge_admin.option.window_closed === '' ) ||
|
||||
wpforms_challenge_admin.option.window_closed === '1'
|
||||
)
|
||||
) {
|
||||
el.$listBlock.find( 'p' ).hide();
|
||||
el.$listBtnToggle.trigger( 'click' );
|
||||
}
|
||||
|
||||
if ( status === 'paused' ) {
|
||||
|
||||
el.$challenge.addClass( 'paused' );
|
||||
el.$btnPause.hide();
|
||||
el.$btnResume.show();
|
||||
|
||||
} else {
|
||||
|
||||
// Zero timeout is needed to avoid firing 'focus' and 'click' events in the same loop.
|
||||
setTimeout( function() {
|
||||
el.$btnPause.show();
|
||||
}, 0 );
|
||||
|
||||
el.$challenge.removeClass( 'paused' );
|
||||
el.$btnResume.hide();
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update Challenge task list appearance.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number|string} step Last saved step.
|
||||
*/
|
||||
updateListUI: function( step ) {
|
||||
|
||||
step = step || app.loadStep();
|
||||
|
||||
el.$listSteps.find( 'li:lt(' + step + ')' ).addClass( 'wpforms-challenge-item-completed' );
|
||||
el.$listSteps.find( 'li:eq(' + step + ')' ).addClass( 'wpforms-challenge-item-current' );
|
||||
el.$progressBar.find( 'div' ).css( 'width', ( step * 20 ) + '%' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update Challenge timer appearance.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {number} secondsLeft Number of seconds left to complete the Challenge.
|
||||
*/
|
||||
updateTimerUI: function( secondsLeft ) {
|
||||
|
||||
if ( ! secondsLeft || isNaN( secondsLeft ) || '0' === secondsLeft ) {
|
||||
secondsLeft = 0;
|
||||
}
|
||||
|
||||
app.timer.saveSecondsLeft( secondsLeft );
|
||||
$( '#wpforms-challenge-timer' ).text( app.timer.getFormatted( secondsLeft ) ).data( 'seconds-left', secondsLeft );
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove Challenge interface.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
removeChallengeUI: function() {
|
||||
|
||||
$( '.wpforms-challenge-dot' ).remove();
|
||||
el.$challenge.remove();
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear all Challenge frontend saved data.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
clearLocalStorage: function() {
|
||||
|
||||
localStorage.removeItem( 'wpformsChallengeStep' );
|
||||
app.timer.clear();
|
||||
},
|
||||
|
||||
/**
|
||||
* Pause Challenge.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
pauseChallenge: function( e ) {
|
||||
|
||||
// Skip if out to the iframe.
|
||||
if ( document.activeElement.tagName === 'IFRAME' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if is not started.
|
||||
if ( wpforms_challenge_admin.option.status !== 'started' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
vars.pauseEvent = e.type;
|
||||
|
||||
app.pauseResumeChallenge( 'pause' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Resume Challenge.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
resumeChallenge: function( e ) {
|
||||
|
||||
// Skip if is not paused.
|
||||
if ( wpforms_challenge_admin.option.status !== 'paused' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Resume on 'focus' only if it has been paused on 'blur'.
|
||||
if ( e.type === 'focus' && vars.pauseEvent !== 'blur' ) {
|
||||
delete vars.pauseEvent;
|
||||
return;
|
||||
}
|
||||
|
||||
vars.resumeEvent = e.type;
|
||||
|
||||
app.pauseResumeChallenge( 'resume' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Pause/Resume Challenge.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {string} action Action to perform. `pause` or `resume`.
|
||||
*/
|
||||
pauseResumeChallenge: function( action ) {
|
||||
|
||||
action = action === 'pause' ? action : 'resume';
|
||||
|
||||
app.timer[ action ]();
|
||||
|
||||
var optionData = {
|
||||
status : action === 'pause' ? 'paused' : 'started',
|
||||
seconds_spent: app.timer.getSecondsSpent(),
|
||||
seconds_left : app.timer.getSecondsLeft(),
|
||||
};
|
||||
|
||||
WPFormsChallenge.admin.saveChallengeOption( optionData );
|
||||
|
||||
app.initListUI( optionData.status );
|
||||
},
|
||||
|
||||
/**
|
||||
* Refresh Page in order to re-init current step.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
refreshPage: function( e ) {
|
||||
|
||||
window.location.reload( true );
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if we're in Gutenberg editor.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @returns {boolean} Is Gutenberg or not.
|
||||
*/
|
||||
isGutenberg: function() {
|
||||
|
||||
return typeof wp !== 'undefined' && Object.prototype.hasOwnProperty.call( wp, 'blocks' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Trigger form embed page save potentially reloading it.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
triggerPageSave: function() {
|
||||
|
||||
if ( app.isGutenberg() ) {
|
||||
app.gutenbergPageSave();
|
||||
|
||||
} else {
|
||||
$( '#post #publish' ).trigger( 'click' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Save page for Gutenberg.
|
||||
*
|
||||
* @since 1.5.2
|
||||
*/
|
||||
gutenbergPageSave: function() {
|
||||
|
||||
var $gb = $( '.block-editor' ),
|
||||
$updateBtn = $gb.find( '.editor-post-publish-button.editor-post-publish-button__button' );
|
||||
|
||||
// Trigger click on the Update button.
|
||||
if ( $updateBtn.length > 0 ) {
|
||||
$updateBtn.trigger( 'click' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Use MutationObserver to wait while Guttenberg create/display panel with Publish button.
|
||||
var obs = {
|
||||
targetNode : $gb.find( '.edit-post-layout, .block-editor-editor-skeleton__publish > div' )[0],
|
||||
config : {
|
||||
childList: true,
|
||||
attributes: true,
|
||||
subtree: true,
|
||||
},
|
||||
};
|
||||
|
||||
obs.callback = function( mutationsList, observer ) {
|
||||
|
||||
var $btn = $gb.find( '.editor-post-publish-button, .editor-post-publish-panel__header-publish-button .editor-post-publish-button__button' );
|
||||
|
||||
if ( $btn.length > 0 ) {
|
||||
$btn.trigger( 'click' );
|
||||
observer.disconnect();
|
||||
}
|
||||
};
|
||||
|
||||
obs.observer = new MutationObserver( obs.callback );
|
||||
obs.observer.observe( obs.targetNode, obs.config );
|
||||
|
||||
// Trigger click on the Publish button that opens the additional publishing panel.
|
||||
$gb.find( '.edit-post-toggle-publish-panel__button, .editor-post-publish-panel__toggle.editor-post-publish-button__button' )
|
||||
.trigger( 'click' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
WPFormsChallenge.core.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/challenge/challenge-core.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/challenge/challenge-core.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,279 @@
|
||||
/* global ajaxurl */
|
||||
/**
|
||||
* WPForms Challenge function.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.6.2 Challenge v2.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var WPFormsChallenge = window.WPFormsChallenge || {};
|
||||
|
||||
WPFormsChallenge.embed = window.WPFormsChallenge.embed || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
$( window ).on( 'load', function() {
|
||||
|
||||
// in case of jQuery 3.+ we need to wait for an `ready` event first.
|
||||
if ( typeof $.ready.then === 'function' ) {
|
||||
$.ready.then( app.load );
|
||||
} else {
|
||||
app.load();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.setup();
|
||||
app.events();
|
||||
app.observeFullscreenMode();
|
||||
},
|
||||
|
||||
/**
|
||||
* Window load.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
load: function() {
|
||||
|
||||
// If the page is Add new page.
|
||||
if ( window.location.href.indexOf( 'post-new.php' ) > -1 ) {
|
||||
app.lastStep();
|
||||
$( '.wpforms-challenge-dot-completed' ).hide();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( WPFormsChallenge.core.isGutenberg() ) {
|
||||
WPFormsChallenge.core.initTooltips( 5, '.block-editor .edit-post-header', { side: 'bottom' } );
|
||||
} else {
|
||||
WPFormsChallenge.core.initTooltips( 5, '.wpforms-insert-form-button', { side: 'right' } );
|
||||
}
|
||||
|
||||
WPFormsChallenge.core.updateTooltipUI();
|
||||
},
|
||||
|
||||
/**
|
||||
* Initial setup.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
setup: function() {
|
||||
|
||||
if ( 5 === WPFormsChallenge.core.loadStep() ) {
|
||||
$( '.wpforms-challenge' ).addClass( 'wpforms-challenge-completed' );
|
||||
app.showPopup();
|
||||
}
|
||||
|
||||
$( '.wpforms-challenge' ).show();
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
$( '.wpforms-challenge-step5-done' )
|
||||
.on( 'click', app.lastStep );
|
||||
|
||||
$( '.wpforms-challenge-popup-close, .wpforms-challenge-popup-rate-btn, .wpforms-challenge-end' )
|
||||
.on( 'click', app.completeChallenge );
|
||||
|
||||
$( '#wpforms-challenge-contact-form .wpforms-challenge-popup-contact-btn' )
|
||||
.on( 'click', app.submitContactForm );
|
||||
},
|
||||
|
||||
/**
|
||||
* Last step done routine.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
lastStep: function() {
|
||||
|
||||
WPFormsChallenge.core.timer.pause();
|
||||
WPFormsChallenge.core.stepCompleted( 5 );
|
||||
$( '.wpforms-challenge' ).addClass( 'wpforms-challenge-completed' );
|
||||
app.showPopup();
|
||||
},
|
||||
|
||||
/**
|
||||
* Show either 'Congratulations' or 'Contact Us' popup.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
showPopup: function() {
|
||||
|
||||
var secondsLeft = WPFormsChallenge.core.timer.getSecondsLeft();
|
||||
|
||||
$( '.wpforms-challenge-popup-container' ).show();
|
||||
|
||||
if ( 0 < secondsLeft ) {
|
||||
var secondsSpent = WPFormsChallenge.core.timer.getSecondsSpent( secondsLeft );
|
||||
|
||||
$( '#wpforms-challenge-congrats-minutes' )
|
||||
.text( WPFormsChallenge.core.timer.getMinutesFormatted( secondsSpent ) );
|
||||
$( '#wpforms-challenge-congrats-seconds' )
|
||||
.text( WPFormsChallenge.core.timer.getSecondsFormatted( secondsSpent ) );
|
||||
$( '#wpforms-challenge-congrats-popup' ).show();
|
||||
} else {
|
||||
$( '#wpforms-challenge-contact-popup' ).show();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Hide the popoup.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
hidePopup: function() {
|
||||
|
||||
$( '.wpforms-challenge-popup-container' ).hide();
|
||||
$( '.wpforms-challenge-popup' ).hide();
|
||||
},
|
||||
|
||||
/**
|
||||
* Complete Challenge.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
completeChallenge: function() {
|
||||
|
||||
var optionData = {
|
||||
status : 'completed',
|
||||
seconds_spent: WPFormsChallenge.core.timer.getSecondsSpent(),
|
||||
seconds_left : WPFormsChallenge.core.timer.getSecondsLeft(),
|
||||
};
|
||||
|
||||
app.hidePopup();
|
||||
|
||||
WPFormsChallenge.core.removeChallengeUI();
|
||||
WPFormsChallenge.core.clearLocalStorage();
|
||||
|
||||
WPFormsChallenge.admin.saveChallengeOption( optionData )
|
||||
.done( WPFormsChallenge.core.triggerPageSave ); // Save and reload the page to remove WPForms Challenge JS.
|
||||
},
|
||||
|
||||
/**
|
||||
* Submit contact form button click event handler.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
submitContactForm: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var $btn = $( this ),
|
||||
$form = $btn.closest( '#wpforms-challenge-contact-form' );
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
var data = {
|
||||
action : 'wpforms_challenge_send_contact_form',
|
||||
_wpnonce : WPFormsChallenge.admin.l10n.nonce,
|
||||
contact_data: {
|
||||
message : $form.find( '.wpforms-challenge-contact-message' ).val(),
|
||||
contact_me: $form.find( '.wpforms-challenge-contact-permission' ).prop( 'checked' ),
|
||||
},
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
$btn.prop( 'disabled', true );
|
||||
|
||||
$.post( ajaxurl, data, function( response ) {
|
||||
|
||||
if ( ! response.success ) {
|
||||
console.error( 'Error sending WPForms Challenge Contact Form.' );
|
||||
}
|
||||
} ).done( app.completeChallenge );
|
||||
},
|
||||
|
||||
/**
|
||||
* Observe Gutenberg's Fullscreen Mode state to adjust tooltip positioning.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
observeFullscreenMode: function() {
|
||||
|
||||
var $body = $( 'body' ),
|
||||
isFullScreenPrev = $body.hasClass( 'is-fullscreen-mode' );
|
||||
|
||||
// MutationObserver configuration and callback.
|
||||
var obs = {
|
||||
targetNode : $body[0],
|
||||
config : {
|
||||
attributes: true,
|
||||
},
|
||||
};
|
||||
|
||||
obs.callback = function( mutationsList, observer ) {
|
||||
|
||||
var mutation,
|
||||
isFullScreen,
|
||||
$step5 = $( '.wpforms-challenge-tooltip-step5' ),
|
||||
$step5Arrow = $step5.find( '.tooltipster-arrow' );
|
||||
|
||||
for ( var i in mutationsList ) {
|
||||
mutation = mutationsList[ i ];
|
||||
if ( mutation.type !== 'attributes' || mutation.attributeName !== 'class' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
isFullScreen = $body.hasClass( 'is-fullscreen-mode' );
|
||||
if ( isFullScreen === isFullScreenPrev ) {
|
||||
continue;
|
||||
}
|
||||
isFullScreenPrev = isFullScreen;
|
||||
|
||||
if ( isFullScreen ) {
|
||||
$step5.css( {
|
||||
'top': '93px',
|
||||
'left': '0',
|
||||
} );
|
||||
$step5Arrow.css( 'left', '91px' );
|
||||
} else {
|
||||
$step5.css( {
|
||||
'top': '125px',
|
||||
'left': '66px',
|
||||
} );
|
||||
$step5Arrow.css( 'left', '130px' );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
obs.observer = new MutationObserver( obs.callback );
|
||||
obs.observer.observe( obs.targetNode, obs.config );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsChallenge.embed.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/challenge/challenge-embed.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/challenge/challenge-embed.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsChallenge=window.WPFormsChallenge||{};WPFormsChallenge.embed=window.WPFormsChallenge.embed||function(e,p){var n={init:function(){p(n.ready),p(e).on("load",function(){"function"==typeof p.ready.then?p.ready.then(n.load):n.load()})},ready:function(){n.setup(),n.events(),n.observeFullscreenMode()},load:function(){if(-1<e.location.href.indexOf("post-new.php"))return n.lastStep(),void p(".wpforms-challenge-dot-completed").hide();WPFormsChallenge.core.isGutenberg()?WPFormsChallenge.core.initTooltips(5,".block-editor .edit-post-header",{side:"bottom"}):WPFormsChallenge.core.initTooltips(5,".wpforms-insert-form-button",{side:"right"}),WPFormsChallenge.core.updateTooltipUI()},setup:function(){5===WPFormsChallenge.core.loadStep()&&(p(".wpforms-challenge").addClass("wpforms-challenge-completed"),n.showPopup()),p(".wpforms-challenge").show()},events:function(){p(".wpforms-challenge-step5-done").on("click",n.lastStep),p(".wpforms-challenge-popup-close, .wpforms-challenge-popup-rate-btn, .wpforms-challenge-end").on("click",n.completeChallenge),p("#wpforms-challenge-contact-form .wpforms-challenge-popup-contact-btn").on("click",n.submitContactForm)},lastStep:function(){WPFormsChallenge.core.timer.pause(),WPFormsChallenge.core.stepCompleted(5),p(".wpforms-challenge").addClass("wpforms-challenge-completed"),n.showPopup()},showPopup:function(){var e=WPFormsChallenge.core.timer.getSecondsLeft();p(".wpforms-challenge-popup-container").show(),0<e?(e=WPFormsChallenge.core.timer.getSecondsSpent(e),p("#wpforms-challenge-congrats-minutes").text(WPFormsChallenge.core.timer.getMinutesFormatted(e)),p("#wpforms-challenge-congrats-seconds").text(WPFormsChallenge.core.timer.getSecondsFormatted(e)),p("#wpforms-challenge-congrats-popup").show()):p("#wpforms-challenge-contact-popup").show()},hidePopup:function(){p(".wpforms-challenge-popup-container").hide(),p(".wpforms-challenge-popup").hide()},completeChallenge:function(){var e={status:"completed",seconds_spent:WPFormsChallenge.core.timer.getSecondsSpent(),seconds_left:WPFormsChallenge.core.timer.getSecondsLeft()};n.hidePopup(),WPFormsChallenge.core.removeChallengeUI(),WPFormsChallenge.core.clearLocalStorage(),WPFormsChallenge.admin.saveChallengeOption(e).done(WPFormsChallenge.core.triggerPageSave)},submitContactForm:function(e){e.preventDefault();var o=p(this),e=o.closest("#wpforms-challenge-contact-form"),e={action:"wpforms_challenge_send_contact_form",_wpnonce:WPFormsChallenge.admin.l10n.nonce,contact_data:{message:e.find(".wpforms-challenge-contact-message").val(),contact_me:e.find(".wpforms-challenge-contact-permission").prop("checked")}};o.prop("disabled",!0),p.post(ajaxurl,e,function(e){e.success||console.error("Error sending WPForms Challenge Contact Form.")}).done(n.completeChallenge)},observeFullscreenMode:function(){var a=p("body"),c=a.hasClass("is-fullscreen-mode"),e={targetNode:a[0],config:{attributes:!0},callback:function(e,o){var n,t,l,s=p(".wpforms-challenge-tooltip-step5"),r=s.find(".tooltipster-arrow");for(l in e)"attributes"===(n=e[l]).type&&"class"===n.attributeName&&(t=a.hasClass("is-fullscreen-mode"))!==c&&((c=t)?(s.css({top:"93px",left:"0"}),r.css("left","91px")):(s.css({top:"125px",left:"66px"}),r.css("left","130px")))}};e.observer=new MutationObserver(e.callback),e.observer.observe(e.targetNode,e.config)}};return n}((document,window),jQuery),WPFormsChallenge.embed.init();
|
||||
@@ -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();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/education/core.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/education/core.min.js
vendored
Normal 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();
|
||||
@@ -0,0 +1,526 @@
|
||||
/* global wpforms_admin_form_embed_wizard, WPFormsBuilder, ajaxurl, WPFormsChallenge, wpforms_builder */
|
||||
|
||||
/**
|
||||
* Form Embed Wizard function.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPFormsFormEmbedWizard = window.WPFormsFormEmbedWizard || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Elements.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var el = {};
|
||||
|
||||
/**
|
||||
* Runtime variables.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var vars = {
|
||||
formId: 0,
|
||||
isBuilder: false,
|
||||
isChallengeActive: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
$( window ).on( 'load', function() {
|
||||
|
||||
// in case of jQuery 3.+ we need to wait for an `ready` event first.
|
||||
if ( typeof $.ready.then === 'function' ) {
|
||||
$.ready.then( app.load );
|
||||
} else {
|
||||
app.load();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.initVars();
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Window load.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
load: function() {
|
||||
|
||||
// Initialize tooltip in page editor.
|
||||
if ( wpforms_admin_form_embed_wizard.is_edit_page === '1' && ! vars.isChallengeActive ) {
|
||||
app.initTooltip();
|
||||
}
|
||||
|
||||
// Initialize wizard state in the form builder only.
|
||||
if ( vars.isBuilder ) {
|
||||
app.initialStateToggle();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Init variables.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
initVars: function() {
|
||||
|
||||
// Caching some DOM elements for further use.
|
||||
el = {
|
||||
$wizardContainer: $( '#wpforms-admin-form-embed-wizard-container' ),
|
||||
$wizard: $( '#wpforms-admin-form-embed-wizard' ),
|
||||
$contentInitial: $( '#wpforms-admin-form-embed-wizard-content-initial' ),
|
||||
$contentSelectPage: $( '#wpforms-admin-form-embed-wizard-content-select-page' ),
|
||||
$contentCreatePage: $( '#wpforms-admin-form-embed-wizard-content-create-page' ),
|
||||
$sectionBtns: $( '#wpforms-admin-form-embed-wizard-section-btns' ),
|
||||
$sectionGo: $( '#wpforms-admin-form-embed-wizard-section-go' ),
|
||||
$newPageTitle: $( '#wpforms-admin-form-embed-wizard-new-page-title' ),
|
||||
$selectPage: $( '#wpforms-admin-form-embed-wizard-select-page' ),
|
||||
$videoTutorial: $( '#wpforms-admin-form-embed-wizard-tutorial' ),
|
||||
$sectionToggles: $( '#wpforms-admin-form-embed-wizard-section-toggles' ),
|
||||
$sectionGoBack: $( '#wpforms-admin-form-embed-wizard-section-goback' ),
|
||||
$shortcode: $( '#wpforms-admin-form-embed-wizard-shortcode-wrap' ),
|
||||
$shortcodeInput: $( '#wpforms-admin-form-embed-wizard-shortcode' ),
|
||||
$shortcodeCopy: $( '#wpforms-admin-form-embed-wizard-shortcode-copy' ),
|
||||
};
|
||||
|
||||
// Detect the form builder screen and store the flag.
|
||||
vars.isBuilder = typeof WPFormsBuilder !== 'undefined';
|
||||
|
||||
// Detect the Challenge and store the flag.
|
||||
vars.isChallengeActive = typeof WPFormsChallenge !== 'undefined';
|
||||
|
||||
// Are the pages exists?
|
||||
vars.pagesExists = el.$wizard.data( 'pages-exists' ) === 1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
// Skip wizard events in the page editor.
|
||||
if ( ! el.$wizard.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$wizard
|
||||
.on( 'click', 'button', app.popupButtonsClick )
|
||||
.on( 'click', '.tutorial-toggle', app.tutorialToggle )
|
||||
.on( 'click', '.shortcode-toggle', app.shortcodeToggle )
|
||||
.on( 'click', '.initialstate-toggle', app.initialStateToggle )
|
||||
.on( 'click', '.wpforms-admin-popup-close', app.closePopup )
|
||||
.on( 'click', '#wpforms-admin-form-embed-wizard-shortcode-copy', app.copyShortcodeToClipboard );
|
||||
},
|
||||
|
||||
/**
|
||||
* Popup buttons events handler.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
popupButtonsClick: function( e ) {
|
||||
|
||||
var $btn = $( e.target );
|
||||
|
||||
if ( ! $btn.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $div = $btn.closest( 'div' ),
|
||||
action = $btn.data( 'action' ) || '';
|
||||
|
||||
el.$contentInitial.hide();
|
||||
|
||||
switch ( action ) {
|
||||
|
||||
// Select existing page.
|
||||
case 'select-page':
|
||||
el.$newPageTitle.hide();
|
||||
el.$contentSelectPage.show();
|
||||
break;
|
||||
|
||||
// Create a new page.
|
||||
case 'create-page':
|
||||
el.$selectPage.hide();
|
||||
el.$contentCreatePage.show();
|
||||
break;
|
||||
|
||||
// Let's Go!
|
||||
case 'go':
|
||||
if ( el.$selectPage.is( ':visible' ) && el.$selectPage.val() === '' ) {
|
||||
return;
|
||||
}
|
||||
$btn.prop( 'disabled', true );
|
||||
app.saveFormAndRedirect();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$div.hide();
|
||||
$div.next().fadeIn();
|
||||
el.$sectionToggles.hide();
|
||||
el.$sectionGoBack.fadeIn();
|
||||
app.tutorialControl( 'Stop' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle video tutorial inside popup.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
tutorialToggle: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
el.$shortcode.hide();
|
||||
el.$videoTutorial.toggle();
|
||||
|
||||
if ( el.$videoTutorial.attr( 'src' ) === 'about:blank' ) {
|
||||
el.$videoTutorial.attr( 'src', wpforms_admin_form_embed_wizard.video_url );
|
||||
}
|
||||
|
||||
if ( el.$videoTutorial[0].src.indexOf( '&autoplay=1' ) < 0 ) {
|
||||
app.tutorialControl( 'Play' );
|
||||
} else {
|
||||
app.tutorialControl( 'Stop' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle video tutorial inside popup.
|
||||
*
|
||||
* @since 1.6.2.3
|
||||
*
|
||||
* @param {string} action One of 'Play' or 'Stop'.
|
||||
*/
|
||||
tutorialControl: function( action ) {
|
||||
|
||||
var iframe = el.$videoTutorial[0];
|
||||
|
||||
if ( typeof iframe === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( action !== 'Stop' ) {
|
||||
iframe.src += iframe.src.indexOf( '&autoplay=1' ) < 0 ? '&autoplay=1' : '';
|
||||
} else {
|
||||
iframe.src = iframe.src.replace( '&autoplay=1', '' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle shortcode input field.
|
||||
*
|
||||
* @since 1.6.2.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
shortcodeToggle: function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
el.$videoTutorial.hide();
|
||||
app.tutorialControl( 'Stop' );
|
||||
el.$shortcodeInput.val( '[wpforms id="' + vars.formId + '" title="false"]' );
|
||||
el.$shortcode.toggle();
|
||||
},
|
||||
|
||||
/**
|
||||
* Copies the shortcode embed code to the clipboard.
|
||||
*
|
||||
* @since 1.6.4
|
||||
*/
|
||||
copyShortcodeToClipboard: function() {
|
||||
|
||||
// Remove disabled attribute, select the text, and re-add disabled attribute.
|
||||
el.$shortcodeInput
|
||||
.prop( 'disabled', false )
|
||||
.select()
|
||||
.prop( 'disabled', true );
|
||||
|
||||
// Copy it.
|
||||
document.execCommand( 'copy' );
|
||||
|
||||
var $icon = el.$shortcodeCopy.find( 'i' );
|
||||
|
||||
// Add visual feedback to copy command.
|
||||
$icon.removeClass( 'fa-files-o' ).addClass( 'fa-check' );
|
||||
|
||||
// Reset visual confirmation back to default state after 2.5 sec.
|
||||
window.setTimeout( function() {
|
||||
$icon.removeClass( 'fa-check' ).addClass( 'fa-files-o' );
|
||||
}, 2500 );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle initial state.
|
||||
*
|
||||
* @since 1.6.2.3
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
*/
|
||||
initialStateToggle: function( e ) {
|
||||
|
||||
if ( e ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if ( vars.pagesExists ) {
|
||||
el.$contentInitial.show();
|
||||
el.$contentSelectPage.hide();
|
||||
el.$contentCreatePage.hide();
|
||||
el.$selectPage.show();
|
||||
el.$newPageTitle.show();
|
||||
el.$sectionBtns.show();
|
||||
el.$sectionGo.hide();
|
||||
} else {
|
||||
el.$contentInitial.hide();
|
||||
el.$contentSelectPage.hide();
|
||||
el.$contentCreatePage.show();
|
||||
el.$selectPage.hide();
|
||||
el.$newPageTitle.show();
|
||||
el.$sectionBtns.hide();
|
||||
el.$sectionGo.show();
|
||||
}
|
||||
el.$shortcode.hide();
|
||||
el.$videoTutorial.hide();
|
||||
app.tutorialControl( 'Stop' );
|
||||
el.$sectionToggles.show();
|
||||
el.$sectionGoBack.hide();
|
||||
},
|
||||
|
||||
/**
|
||||
* Save the form and redirect to form embed page.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
saveFormAndRedirect: function() {
|
||||
|
||||
// Just redirect if no need to save the form.
|
||||
if ( ! vars.isBuilder || WPFormsBuilder.formIsSaved() ) {
|
||||
app.embedPageRedirect();
|
||||
return;
|
||||
}
|
||||
|
||||
// Embedding in Challenge should save the form silently.
|
||||
if ( vars.isBuilder && vars.isChallengeActive ) {
|
||||
WPFormsBuilder.formSave().done( app.embedPageRedirect );
|
||||
return;
|
||||
}
|
||||
|
||||
$.confirm( {
|
||||
title: false,
|
||||
content: wpforms_builder.exit_confirm,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
closeIcon: true,
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.save_embed,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function() {
|
||||
WPFormsBuilder.formSave().done( app.embedPageRedirect );
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
text: wpforms_builder.embed,
|
||||
action: function() {
|
||||
WPFormsBuilder.setCloseConfirmation( false );
|
||||
app.embedPageRedirect();
|
||||
},
|
||||
},
|
||||
},
|
||||
onClose: function() {
|
||||
el.$sectionGo.find( 'button' ).prop( 'disabled', false );
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Prepare data for requesting redirect URL.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @returns {object} AJAX data object.
|
||||
*/
|
||||
embedPageRedirectAjaxData: function() {
|
||||
|
||||
var data = {
|
||||
action : 'wpforms_admin_form_embed_wizard_embed_page_url',
|
||||
_wpnonce: wpforms_admin_form_embed_wizard.nonce,
|
||||
formId: vars.formId,
|
||||
};
|
||||
|
||||
if ( el.$selectPage.is( ':visible' ) ) {
|
||||
data.pageId = el.$selectPage.val();
|
||||
}
|
||||
|
||||
if ( el.$newPageTitle.is( ':visible' ) ) {
|
||||
data.pageTitle = el.$newPageTitle.val();
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Redirect to form embed page.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
embedPageRedirect: function() {
|
||||
|
||||
var data = app.embedPageRedirectAjaxData();
|
||||
|
||||
// Exit if no one page is selected.
|
||||
if ( typeof data.pageId !== 'undefined' && data.pageId === '' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post( ajaxurl, data, function( response ) {
|
||||
if ( response.success ) {
|
||||
window.location = response.data;
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Display wizard popup.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {numeric} openFormId Form ID to embed. Used only if called outside of the form builder.
|
||||
*/
|
||||
openPopup: function( openFormId ) {
|
||||
|
||||
openFormId = openFormId || 0;
|
||||
|
||||
vars.formId = vars.isBuilder ? $( '#wpforms-builder-form' ).data( 'id' ) : openFormId;
|
||||
|
||||
// Regular wizard and wizard in Challenge has differences.
|
||||
el.$wizard.toggleClass( 'wpforms-challenge-popup', vars.isChallengeActive );
|
||||
el.$wizard.find( '.wpforms-admin-popup-close' ).toggle( ! vars.isChallengeActive );
|
||||
el.$wizard.find( '.wpforms-admin-popup-content-regular' ).toggle( ! vars.isChallengeActive );
|
||||
el.$wizard.find( '.wpforms-admin-popup-content-challenge' ).toggle( vars.isChallengeActive );
|
||||
|
||||
// Re-init sections.
|
||||
if ( el.$selectPage.length === 0 ) {
|
||||
el.$sectionBtns.hide();
|
||||
el.$sectionGo.show();
|
||||
} else {
|
||||
el.$sectionBtns.show();
|
||||
el.$sectionGo.hide();
|
||||
}
|
||||
el.$newPageTitle.show();
|
||||
el.$selectPage.show();
|
||||
|
||||
el.$wizardContainer.fadeIn();
|
||||
},
|
||||
|
||||
/**
|
||||
* Close wizard popup.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
closePopup: function() {
|
||||
|
||||
el.$wizardContainer.fadeOut();
|
||||
app.initialStateToggle();
|
||||
},
|
||||
|
||||
/**
|
||||
* Init embed page tooltip.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
initTooltip: function() {
|
||||
|
||||
if ( typeof $.fn.tooltipster === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $dot = $( '<span class="wpforms-admin-form-embed-wizard-dot"> </span>' ),
|
||||
isGutengerg = app.isGutenberg(),
|
||||
anchor = isGutengerg ? '.block-editor .edit-post-header' : '#wp-content-editor-tools .wpforms-insert-form-button';
|
||||
|
||||
var tooltipsterArgs = {
|
||||
content : $( '#wpforms-admin-form-embed-wizard-tooltip-content' ),
|
||||
trigger : 'custom',
|
||||
interactive : true,
|
||||
animationDuration: 0,
|
||||
delay : 0,
|
||||
theme : [ 'tooltipster-default', 'wpforms-admin-form-embed-wizard' ],
|
||||
side : isGutengerg ? 'bottom' : 'right',
|
||||
distance : 3,
|
||||
functionReady : function( instance, helper ) {
|
||||
|
||||
instance._$tooltip.on( 'click', 'button', function() {
|
||||
|
||||
instance.close();
|
||||
$( '.wpforms-admin-form-embed-wizard-dot' ).remove();
|
||||
} );
|
||||
|
||||
instance.reposition();
|
||||
},
|
||||
};
|
||||
|
||||
$dot.insertAfter( anchor ).tooltipster( tooltipsterArgs ).tooltipster( 'open' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if we're in Gutenberg editor.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @returns {boolean} Is Gutenberg or not.
|
||||
*/
|
||||
isGutenberg: function() {
|
||||
|
||||
return typeof wp !== 'undefined' && Object.prototype.hasOwnProperty.call( wp, 'blocks' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsFormEmbedWizard.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/form-embed-wizard.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/form-embed-wizard.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,131 @@
|
||||
/* global wpforms_gutenberg_form_selector */
|
||||
/*jshint es3: false, esversion: 6 */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { serverSideRender: ServerSideRender = wp.components.ServerSideRender } = wp;
|
||||
const { createElement, Fragment } = wp.element;
|
||||
const { registerBlockType } = wp.blocks;
|
||||
const { InspectorControls } = wp.blockEditor || wp.editor;
|
||||
const { SelectControl, ToggleControl, PanelBody, Placeholder } = wp.components;
|
||||
|
||||
const wpformsIcon = createElement( 'svg', { width: 20, height: 20, viewBox: '0 0 612 612', className: 'dashicon' },
|
||||
createElement( 'path', {
|
||||
fill: 'currentColor',
|
||||
d: 'M544,0H68C30.445,0,0,30.445,0,68v476c0,37.556,30.445,68,68,68h476c37.556,0,68-30.444,68-68V68 C612,30.445,581.556,0,544,0z M464.44,68L387.6,120.02L323.34,68H464.44z M288.66,68l-64.26,52.02L147.56,68H288.66z M544,544H68 V68h22.1l136,92.14l79.9-64.6l79.56,64.6l136-92.14H544V544z M114.24,263.16h95.88v-48.28h-95.88V263.16z M114.24,360.4h95.88 v-48.62h-95.88V360.4z M242.76,360.4h255v-48.62h-255V360.4L242.76,360.4z M242.76,263.16h255v-48.28h-255V263.16L242.76,263.16z M368.22,457.3h129.54V408H368.22V457.3z',
|
||||
} )
|
||||
);
|
||||
|
||||
registerBlockType( 'wpforms/form-selector', {
|
||||
title: wpforms_gutenberg_form_selector.i18n.title,
|
||||
description: wpforms_gutenberg_form_selector.i18n.description,
|
||||
icon: wpformsIcon,
|
||||
keywords: wpforms_gutenberg_form_selector.i18n.form_keywords,
|
||||
category: 'widgets',
|
||||
attributes: {
|
||||
formId: {
|
||||
type: 'string',
|
||||
},
|
||||
displayTitle: {
|
||||
type: 'boolean',
|
||||
},
|
||||
displayDesc: {
|
||||
type: 'boolean',
|
||||
},
|
||||
preview: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
example: {
|
||||
attributes: {
|
||||
preview: true,
|
||||
},
|
||||
},
|
||||
edit( props ) {
|
||||
const { attributes: { formId = '', displayTitle = false, displayDesc = false, preview = false }, setAttributes } = props;
|
||||
const formOptions = wpforms_gutenberg_form_selector.forms.map( value => (
|
||||
{ value: value.ID, label: value.post_title }
|
||||
) );
|
||||
let jsx;
|
||||
|
||||
formOptions.unshift( { value: '', label: wpforms_gutenberg_form_selector.i18n.form_select } );
|
||||
|
||||
function selectForm( value ) {
|
||||
setAttributes( { formId: value } );
|
||||
}
|
||||
|
||||
function toggleDisplayTitle( value ) {
|
||||
setAttributes( { displayTitle: value } );
|
||||
}
|
||||
|
||||
function toggleDisplayDesc( value ) {
|
||||
setAttributes( { displayDesc: value } );
|
||||
}
|
||||
|
||||
jsx = [
|
||||
<InspectorControls key="wpforms-gutenberg-form-selector-inspector-controls">
|
||||
<PanelBody title={ wpforms_gutenberg_form_selector.i18n.form_settings }>
|
||||
<SelectControl
|
||||
label={ wpforms_gutenberg_form_selector.i18n.form_selected }
|
||||
value={ formId }
|
||||
options={ formOptions }
|
||||
onChange={ selectForm }
|
||||
/>
|
||||
<ToggleControl
|
||||
label={ wpforms_gutenberg_form_selector.i18n.show_title }
|
||||
checked={ displayTitle }
|
||||
onChange={ toggleDisplayTitle }
|
||||
/>
|
||||
<ToggleControl
|
||||
label={ wpforms_gutenberg_form_selector.i18n.show_description }
|
||||
checked={ displayDesc }
|
||||
onChange={ toggleDisplayDesc }
|
||||
/>
|
||||
<p className="wpforms-gutenberg-panel-notice">
|
||||
<strong>{ wpforms_gutenberg_form_selector.i18n.panel_notice_head }</strong><br />
|
||||
{ wpforms_gutenberg_form_selector.i18n.panel_notice_text }<br />
|
||||
<a href="https://wpforms.com/docs/how-to-properly-test-your-wordpress-forms-before-launching-checklist/" target="_blank">{ wpforms_gutenberg_form_selector.i18n.panel_notice_link }</a>
|
||||
</p>
|
||||
|
||||
</PanelBody>
|
||||
</InspectorControls>
|
||||
];
|
||||
|
||||
if ( formId ) {
|
||||
jsx.push(
|
||||
<ServerSideRender
|
||||
key="wpforms-gutenberg-form-selector-server-side-renderer"
|
||||
block="wpforms/form-selector"
|
||||
attributes={ props.attributes }
|
||||
/>
|
||||
);
|
||||
} else if ( preview ) {
|
||||
jsx.push(
|
||||
<Fragment
|
||||
key="wpforms-gutenberg-form-selector-fragment-block-preview">
|
||||
<img src={ wpforms_gutenberg_form_selector.block_preview_url }/>
|
||||
</Fragment>
|
||||
);
|
||||
} else {
|
||||
jsx.push(
|
||||
<Placeholder
|
||||
key="wpforms-gutenberg-form-selector-wrap"
|
||||
className="wpforms-gutenberg-form-selector-wrap">
|
||||
<img src={ wpforms_gutenberg_form_selector.logo_url }/>
|
||||
<h3>{ wpforms_gutenberg_form_selector.i18n.title }</h3>
|
||||
<SelectControl
|
||||
key="wpforms-gutenberg-form-selector-select-control"
|
||||
value={ formId }
|
||||
options={ formOptions }
|
||||
onChange={ selectForm }
|
||||
/>
|
||||
</Placeholder>
|
||||
);
|
||||
}
|
||||
|
||||
return jsx;
|
||||
},
|
||||
save() {
|
||||
return null;
|
||||
},
|
||||
} );
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/gutenberg/formselector.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/gutenberg/formselector.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function o(n,l,s){function c(t,e){if(!l[t]){if(!n[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(i)return i(t,!0);throw new Error("Cannot find module '"+t+"'")}r=l[t]={exports:{}};n[t][0].call(r.exports,function(e){var r=n[t][1][e];return c(r||e)},r,r.exports,o,n,l,s)}return l[t].exports}for(var i="function"==typeof require&&require,e=0;e<s.length;e++)c(s[e]);return c}({1:[function(e,r,t){"use strict";var o=wp.serverSideRender,i=void 0===o?wp.components.ServerSideRender:o,n=wp.element,l=n.createElement,a=n.Fragment,o=wp.blocks.registerBlockType,m=(wp.blockEditor||wp.editor).InspectorControls,n=wp.components,f=n.SelectControl,p=n.ToggleControl,u=n.PanelBody,g=n.Placeholder,l=l("svg",{width:20,height:20,viewBox:"0 0 612 612",className:"dashicon"},l("path",{fill:"currentColor",d:"M544,0H68C30.445,0,0,30.445,0,68v476c0,37.556,30.445,68,68,68h476c37.556,0,68-30.444,68-68V68 C612,30.445,581.556,0,544,0z M464.44,68L387.6,120.02L323.34,68H464.44z M288.66,68l-64.26,52.02L147.56,68H288.66z M544,544H68 V68h22.1l136,92.14l79.9-64.6l79.56,64.6l136-92.14H544V544z M114.24,263.16h95.88v-48.28h-95.88V263.16z M114.24,360.4h95.88 v-48.62h-95.88V360.4z M242.76,360.4h255v-48.62h-255V360.4L242.76,360.4z M242.76,263.16h255v-48.28h-255V263.16L242.76,263.16z M368.22,457.3h129.54V408H368.22V457.3z"}));o("wpforms/form-selector",{title:wpforms_gutenberg_form_selector.i18n.title,description:wpforms_gutenberg_form_selector.i18n.description,icon:l,keywords:wpforms_gutenberg_form_selector.i18n.form_keywords,category:"widgets",attributes:{formId:{type:"string"},displayTitle:{type:"boolean"},displayDesc:{type:"boolean"},preview:{type:"boolean"}},example:{attributes:{preview:!0}},edit:function(e){var r=e.attributes,t=r.formId,o=void 0===t?"":t,n=r.displayTitle,l=void 0!==n&&n,t=r.displayDesc,n=void 0!==t&&t,t=r.preview,r=void 0!==t&&t,s=e.setAttributes,t=wpforms_gutenberg_form_selector.forms.map(function(e){return{value:e.ID,label:e.post_title}});function c(e){s({formId:e})}return t.unshift({value:"",label:wpforms_gutenberg_form_selector.i18n.form_select}),n=[React.createElement(m,{key:"wpforms-gutenberg-form-selector-inspector-controls"},React.createElement(u,{title:wpforms_gutenberg_form_selector.i18n.form_settings},React.createElement(f,{label:wpforms_gutenberg_form_selector.i18n.form_selected,value:o,options:t,onChange:c}),React.createElement(p,{label:wpforms_gutenberg_form_selector.i18n.show_title,checked:l,onChange:function(e){s({displayTitle:e})}}),React.createElement(p,{label:wpforms_gutenberg_form_selector.i18n.show_description,checked:n,onChange:function(e){s({displayDesc:e})}}),React.createElement("p",{className:"wpforms-gutenberg-panel-notice"},React.createElement("strong",null,wpforms_gutenberg_form_selector.i18n.panel_notice_head),React.createElement("br",null),wpforms_gutenberg_form_selector.i18n.panel_notice_text,React.createElement("br",null),React.createElement("a",{href:"https://wpforms.com/docs/how-to-properly-test-your-wordpress-forms-before-launching-checklist/",target:"_blank"},wpforms_gutenberg_form_selector.i18n.panel_notice_link))))],o?n.push(React.createElement(i,{key:"wpforms-gutenberg-form-selector-server-side-renderer",block:"wpforms/form-selector",attributes:e.attributes})):r?n.push(React.createElement(a,{key:"wpforms-gutenberg-form-selector-fragment-block-preview"},React.createElement("img",{src:wpforms_gutenberg_form_selector.block_preview_url}))):n.push(React.createElement(g,{key:"wpforms-gutenberg-form-selector-wrap",className:"wpforms-gutenberg-form-selector-wrap"},React.createElement("img",{src:wpforms_gutenberg_form_selector.logo_url}),React.createElement("h3",null,wpforms_gutenberg_form_selector.i18n.title),React.createElement(f,{key:"wpforms-gutenberg-form-selector-select-control",value:o,options:t,onChange:c}))),n},save:function(){return null}})},{}]},{},[1]);
|
||||
@@ -0,0 +1,121 @@
|
||||
/* global wpforms_admin */
|
||||
|
||||
/**
|
||||
* Logger scripts
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPFormsLogger = window.WPFormsLogger || ( function( document, window, $ ) {
|
||||
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
ready: function() {
|
||||
|
||||
$( app.bindPopup() );
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind popup to the click on logger link.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
bindPopup: function() {
|
||||
|
||||
$( '.wpforms-list-table--logs .wp-list-table' ).on( 'click', '.js-single-log-target', function( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
app.showPopup( $( this ).attr( 'data-log-id' ) );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Show popup.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {numeric} recordId Record Id.
|
||||
*/
|
||||
showPopup: function( recordId ) {
|
||||
|
||||
if ( ! recordId ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var popupTemplate = wp.template( 'wpforms-log-record' );
|
||||
|
||||
$.dialog( {
|
||||
title: false,
|
||||
boxWidth: Math.min( 550, $( window ).width() ),
|
||||
content: function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
return $.get(
|
||||
wpforms_admin.ajax_url,
|
||||
{
|
||||
action: 'wpforms_get_log_record',
|
||||
nonce: wpforms_admin.nonce,
|
||||
recordId: recordId,
|
||||
}
|
||||
).done( function( res ) {
|
||||
|
||||
if ( ! res.success || ! res.data ) {
|
||||
app.error( res.data );
|
||||
self.close();
|
||||
|
||||
return;
|
||||
}
|
||||
self.setContent( popupTemplate( res.data ) );
|
||||
|
||||
} ).fail( function( xhr, textStatus, e ) {
|
||||
|
||||
app.error( textStatus + ' ' + xhr.responseText );
|
||||
self.close();
|
||||
} );
|
||||
},
|
||||
animation: 'scale',
|
||||
columnClass: 'medium',
|
||||
closeIcon: true,
|
||||
closeAnimation: 'scale',
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Output error to the console if debug mode is on.
|
||||
*
|
||||
* @since 1.6.4
|
||||
*
|
||||
* @param {string} msg Error text.
|
||||
*/
|
||||
error: function( msg ) {
|
||||
|
||||
if ( ! wpforms_admin.debug ) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg = _.isEmpty( msg ) ? '' : ': ' + msg;
|
||||
console.log( 'WPForms Debug: Error receiving log record data' + msg );
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsLogger.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/logger/logger.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/logger/logger.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsLogger=window.WPFormsLogger||function(t,e){var i={init:function(){e(i.ready)},ready:function(){e(i.bindPopup())},bindPopup:function(){e(".wpforms-list-table--logs .wp-list-table").on("click",".js-single-log-target",function(o){o.preventDefault(),i.showPopup(e(this).attr("data-log-id"))})},showPopup:function(o){var n;o&&(n=wp.template("wpforms-log-record"),e.dialog({title:!1,boxWidth:Math.min(550,e(t).width()),content:function(){var r=this;return e.get(wpforms_admin.ajax_url,{action:"wpforms_get_log_record",nonce:wpforms_admin.nonce,recordId:o}).done(function(o){return o.success&&o.data?void r.setContent(n(o.data)):(i.error(o.data),void r.close())}).fail(function(o,n,t){i.error(n+" "+o.responseText),r.close()})},animation:"scale",columnClass:"medium",closeIcon:!0,closeAnimation:"scale"}))},error:function(o){wpforms_admin.debug&&(o=_.isEmpty(o)?"":": "+o,console.log("WPForms Debug: Error receiving log record data"+o))}};return i}((document,window),jQuery);WPFormsLogger.init();
|
||||
@@ -0,0 +1,78 @@
|
||||
/* global wpforms_admin_notices */
|
||||
|
||||
/**
|
||||
* WPForms Dismissible Notices.
|
||||
*
|
||||
* @since 1.6.7.1
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPFormsAdminNotices = window.WPFormsAdminNotices || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.6.7.1
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.6.7.1
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.6.7.1
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Dismissible notices events.
|
||||
*
|
||||
* @since 1.6.7.1
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.wpforms-notice .notice-dismiss, .wpforms-notice .wpforms-notice-dismiss',
|
||||
app.dismissNotice
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Dismiss notice event handler.
|
||||
*
|
||||
* @since 1.6.7.1
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* */
|
||||
dismissNotice: function( e ) {
|
||||
|
||||
$.post( wpforms_admin_notices.ajax_url, {
|
||||
action: 'wpforms_notice_dismiss',
|
||||
nonce: wpforms_admin_notices.nonce,
|
||||
id: ( $( this ).closest( '.wpforms-notice' ).attr( 'id' ) || '' ).replace( 'wpforms-notice-', '' ),
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsAdminNotices.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/notices.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/notices.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsAdminNotices=window.WPFormsAdminNotices||function(i,o){var s={init:function(){o(s.ready)},ready:function(){s.events()},events:function(){o(i).on("click",".wpforms-notice .notice-dismiss, .wpforms-notice .wpforms-notice-dismiss",s.dismissNotice)},dismissNotice:function(i){o.post(wpforms_admin_notices.ajax_url,{action:"wpforms_notice_dismiss",nonce:wpforms_admin_notices.nonce,id:(o(this).closest(".wpforms-notice").attr("id")||"").replace("wpforms-notice-","")})}};return s}(document,(window,jQuery));WPFormsAdminNotices.init();
|
||||
@@ -0,0 +1,259 @@
|
||||
/* global wpforms_pluginlanding, wpforms_admin */
|
||||
|
||||
/**
|
||||
* Analytics Sub-page.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPFormsPagesAnalytics = window.WPFormsPagesAnalytics || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Elements.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var el = {};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.initVars();
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Init variables.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
initVars: function() {
|
||||
|
||||
el = {
|
||||
$stepInstall: $( 'section.step-install' ),
|
||||
$stepInstallNum: $( 'section.step-install .num img' ),
|
||||
$stepSetup: $( 'section.step-setup' ),
|
||||
$stepSetupNum: $( 'section.step-setup .num img' ),
|
||||
$stepAddon: $( 'section.step-addon' ),
|
||||
$stepAddonNum: $( 'section.step-addon .num img' ),
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
// Step 'Install' button click.
|
||||
el.$stepInstall.on( 'click', 'button', app.stepInstallClick );
|
||||
|
||||
// Step 'Setup' button click.
|
||||
el.$stepSetup.on( 'click', 'button', app.gotoURL );
|
||||
|
||||
// Step 'Addon' button click.
|
||||
el.$stepAddon.on( 'click', 'button', app.gotoURL );
|
||||
},
|
||||
|
||||
/**
|
||||
* Step 'Install' button click.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
*/
|
||||
stepInstallClick: function() {
|
||||
|
||||
var $btn = $( this ),
|
||||
action = $btn.attr( 'data-action' ),
|
||||
plugin = $btn.attr( 'data-plugin' ),
|
||||
ajaxAction = '';
|
||||
|
||||
if ( $btn.hasClass( 'disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( action ) {
|
||||
case 'activate':
|
||||
ajaxAction = 'wpforms_activate_addon';
|
||||
$btn.text( wpforms_pluginlanding.activating );
|
||||
break;
|
||||
|
||||
case 'install':
|
||||
ajaxAction = 'wpforms_install_addon';
|
||||
$btn.text( wpforms_pluginlanding.installing );
|
||||
break;
|
||||
|
||||
case 'goto-url':
|
||||
window.location.href = $btn.attr( 'data-url' );
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
$btn.addClass( 'disabled' );
|
||||
app.showSpinner( el.$stepInstallNum );
|
||||
|
||||
var data = {
|
||||
action: ajaxAction,
|
||||
nonce : wpforms_admin.nonce,
|
||||
plugin: plugin,
|
||||
type : 'plugin',
|
||||
};
|
||||
$.post( wpforms_admin.ajax_url, data )
|
||||
.done( function( res ) {
|
||||
app.stepInstallDone( res, $btn, action );
|
||||
} )
|
||||
.always( function() {
|
||||
app.hideSpinner( el.$stepInstallNum );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Done part of the step 'Install'.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {object} res Result of $.post() query.
|
||||
* @param {jQuery} $btn Button.
|
||||
* @param {string} action Action (for more info look at the app.stepInstallClick() function).
|
||||
*/
|
||||
stepInstallDone: function( res, $btn, action ) {
|
||||
|
||||
var success = 'install' === action ? res.success && res.data.is_activated : res.success;
|
||||
|
||||
if ( success ) {
|
||||
el.$stepInstallNum.attr( 'src', el.$stepInstallNum.attr( 'src' ).replace( 'step-1.', 'step-complete.' ) );
|
||||
$btn.addClass( 'grey' ).removeClass( 'button-primary' ).text( wpforms_pluginlanding.activated );
|
||||
app.stepInstallPluginStatus();
|
||||
} else {
|
||||
var activationFail = ( 'install' === action && res.success && ! res.data.is_activated ) || 'activate' === action,
|
||||
url = ! activationFail ? wpforms_pluginlanding.mi_manual_install_url : wpforms_pluginlanding.mi_manual_activate_url,
|
||||
msg = ! activationFail ? wpforms_pluginlanding.error_could_not_install : wpforms_pluginlanding.error_could_not_activate,
|
||||
btn = ! activationFail ? wpforms_pluginlanding.download_now : wpforms_pluginlanding.plugins_page;
|
||||
|
||||
$btn.removeClass( 'grey disabled' ).text( btn ).attr( 'data-action', 'goto-url' ).attr( 'data-url', url );
|
||||
$btn.after( '<p class="error">' + msg + '</p>' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback for step 'Install' completion.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
stepInstallPluginStatus: function() {
|
||||
|
||||
var data = {
|
||||
action: 'wpforms_analytics_page_check_plugin_status',
|
||||
nonce : wpforms_admin.nonce,
|
||||
};
|
||||
$.post( wpforms_admin.ajax_url, data ).done( app.stepInstallPluginStatusDone );
|
||||
},
|
||||
|
||||
/**
|
||||
* Done part of the callback for step 'Install' completion.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {object} res Result of $.post() query.
|
||||
*/
|
||||
stepInstallPluginStatusDone: function( res ) {
|
||||
|
||||
if ( ! res.success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$stepSetup.removeClass( 'grey' );
|
||||
el.$stepSetupBtn = el.$stepSetup.find( 'button' );
|
||||
|
||||
if ( res.data.setup_status > 0 ) {
|
||||
el.$stepSetupNum.attr( 'src', el.$stepSetupNum.attr( 'src' ).replace( 'step-2.svg', 'step-complete.svg' ) );
|
||||
el.$stepAddon.removeClass( 'grey' );
|
||||
el.$stepAddon.find( 'button' ).attr( 'data-url', res.data.step3_button_url ).removeClass( 'grey disabled' ).addClass( 'button-primary' );
|
||||
|
||||
if ( res.data.license_level === 'pro' ) {
|
||||
var buttonText = res.data.addon_installed > 0 ? wpforms_pluginlanding.activate_now : wpforms_pluginlanding.install_now;
|
||||
el.$stepAddon.find( 'button' ).text( buttonText );
|
||||
}
|
||||
} else {
|
||||
el.$stepSetupBtn.removeClass( 'grey disabled' ).addClass( 'button-primary' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Go to URL by click on the button.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
gotoURL: function() {
|
||||
|
||||
var $btn = $( this );
|
||||
|
||||
if ( $btn.hasClass( 'disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.location.href = $btn.attr( 'data-url' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Display spinner.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {jQuery} $el Section number image jQuery object.
|
||||
*/
|
||||
showSpinner: function( $el ) {
|
||||
|
||||
$el.siblings( '.loader' ).removeClass( 'hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Hide spinner.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {jQuery} $el Section number image jQuery object.
|
||||
*/
|
||||
hideSpinner: function( $el ) {
|
||||
|
||||
$el.siblings( '.loader' ).addClass( 'hidden' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsPagesAnalytics.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/pages/mi-analytics.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/pages/mi-analytics.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsPagesAnalytics=window.WPFormsPagesAnalytics||function(e,l){var i={},o={init:function(){l(o.ready)},ready:function(){o.initVars(),o.events()},initVars:function(){i={$stepInstall:l("section.step-install"),$stepInstallNum:l("section.step-install .num img"),$stepSetup:l("section.step-setup"),$stepSetupNum:l("section.step-setup .num img"),$stepAddon:l("section.step-addon"),$stepAddonNum:l("section.step-addon .num img")}},events:function(){i.$stepInstall.on("click","button",o.stepInstallClick),i.$stepSetup.on("click","button",o.gotoURL),i.$stepAddon.on("click","button",o.gotoURL)},stepInstallClick:function(){var n=l(this),s=n.attr("data-action"),t=n.attr("data-plugin"),a="";if(!n.hasClass("disabled")){switch(s){case"activate":a="wpforms_activate_addon",n.text(wpforms_pluginlanding.activating);break;case"install":a="wpforms_install_addon",n.text(wpforms_pluginlanding.installing);break;case"goto-url":return void(e.location.href=n.attr("data-url"));default:return}n.addClass("disabled"),o.showSpinner(i.$stepInstallNum);t={action:a,nonce:wpforms_admin.nonce,plugin:t,type:"plugin"};l.post(wpforms_admin.ajax_url,t).done(function(t){o.stepInstallDone(t,n,s)}).always(function(){o.hideSpinner(i.$stepInstallNum)})}},stepInstallDone:function(t,n,s){var a;("install"===s?t.success&&t.data.is_activated:t.success)?(i.$stepInstallNum.attr("src",i.$stepInstallNum.attr("src").replace("step-1.","step-complete.")),n.addClass("grey").removeClass("button-primary").text(wpforms_pluginlanding.activated),o.stepInstallPluginStatus()):(t=(a="install"===s&&t.success&&!t.data.is_activated||"activate"===s)?wpforms_pluginlanding.mi_manual_activate_url:wpforms_pluginlanding.mi_manual_install_url,s=a?wpforms_pluginlanding.error_could_not_activate:wpforms_pluginlanding.error_could_not_install,a=a?wpforms_pluginlanding.plugins_page:wpforms_pluginlanding.download_now,n.removeClass("grey disabled").text(a).attr("data-action","goto-url").attr("data-url",t),n.after('<p class="error">'+s+"</p>"))},stepInstallPluginStatus:function(){var t={action:"wpforms_analytics_page_check_plugin_status",nonce:wpforms_admin.nonce};l.post(wpforms_admin.ajax_url,t).done(o.stepInstallPluginStatusDone)},stepInstallPluginStatusDone:function(t){t.success&&(i.$stepSetup.removeClass("grey"),i.$stepSetupBtn=i.$stepSetup.find("button"),0<t.data.setup_status?(i.$stepSetupNum.attr("src",i.$stepSetupNum.attr("src").replace("step-2.svg","step-complete.svg")),i.$stepAddon.removeClass("grey"),i.$stepAddon.find("button").attr("data-url",t.data.step3_button_url).removeClass("grey disabled").addClass("button-primary"),"pro"===t.data.license_level&&(t=0<t.data.addon_installed?wpforms_pluginlanding.activate_now:wpforms_pluginlanding.install_now,i.$stepAddon.find("button").text(t))):i.$stepSetupBtn.removeClass("grey disabled").addClass("button-primary"))},gotoURL:function(){var t=l(this);t.hasClass("disabled")||(e.location.href=t.attr("data-url"))},showSpinner:function(t){t.siblings(".loader").removeClass("hidden")},hideSpinner:function(t){t.siblings(".loader").addClass("hidden")}};return o}((document,window),jQuery);WPFormsPagesAnalytics.init();
|
||||
@@ -0,0 +1,248 @@
|
||||
/* global wpforms_pluginlanding, wpforms_admin */
|
||||
|
||||
/**
|
||||
* SMTP Sub-page.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPFormsPagesSMTP = window.WPFormsPagesSMTP || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Elements.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var el = {};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
ready: function() {
|
||||
|
||||
app.initVars();
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Init variables.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
initVars: function() {
|
||||
|
||||
el = {
|
||||
$stepInstall: $( 'section.step-install' ),
|
||||
$stepInstallNum: $( 'section.step-install .num img' ),
|
||||
$stepSetup: $( 'section.step-setup' ),
|
||||
$stepSetupNum: $( 'section.step-setup .num img' ),
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
// Step 'Install' button click.
|
||||
el.$stepInstall.on( 'click', 'button', app.stepInstallClick );
|
||||
|
||||
// Step 'Setup' button click.
|
||||
el.$stepSetup.on( 'click', 'button', app.gotoURL );
|
||||
},
|
||||
|
||||
/**
|
||||
* Step 'Install' button click.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
stepInstallClick: function() {
|
||||
|
||||
var $btn = $( this ),
|
||||
action = $btn.attr( 'data-action' ),
|
||||
plugin = $btn.attr( 'data-plugin' ),
|
||||
ajaxAction = '';
|
||||
|
||||
if ( $btn.hasClass( 'disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( action ) {
|
||||
case 'activate':
|
||||
ajaxAction = 'wpforms_activate_addon';
|
||||
$btn.text( wpforms_pluginlanding.activating );
|
||||
break;
|
||||
|
||||
case 'install':
|
||||
ajaxAction = 'wpforms_install_addon';
|
||||
$btn.text( wpforms_pluginlanding.installing );
|
||||
break;
|
||||
|
||||
case 'goto-url':
|
||||
window.location.href = $btn.attr( 'data-url' );
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
$btn.addClass( 'disabled' );
|
||||
app.showSpinner( el.$stepInstallNum );
|
||||
|
||||
var data = {
|
||||
action: ajaxAction,
|
||||
nonce : wpforms_admin.nonce,
|
||||
plugin: plugin,
|
||||
type : 'plugin',
|
||||
};
|
||||
$.post( wpforms_admin.ajax_url, data )
|
||||
.done( function( res ) {
|
||||
app.stepInstallDone( res, $btn, action );
|
||||
} )
|
||||
.always( function() {
|
||||
app.hideSpinner( el.$stepInstallNum );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Done part of the 'Install' step.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {object} res Result of $.post() query.
|
||||
* @param {jQuery} $btn Button.
|
||||
* @param {string} action Action (for more info look at the app.stepInstallClick() function).
|
||||
*/
|
||||
stepInstallDone: function( res, $btn, action ) {
|
||||
|
||||
var success = 'install' === action ? res.success && res.data.is_activated : res.success;
|
||||
|
||||
if ( success ) {
|
||||
el.$stepInstallNum.attr( 'src', el.$stepInstallNum.attr( 'src' ).replace( 'step-1.', 'step-complete.' ) );
|
||||
$btn.addClass( 'grey' ).removeClass( 'button-primary' ).text( wpforms_pluginlanding.activated );
|
||||
app.stepInstallPluginStatus();
|
||||
} else {
|
||||
var activationFail = ( 'install' === action && res.success && ! res.data.is_activated ) || 'activate' === action,
|
||||
url = ! activationFail ? wpforms_pluginlanding.manual_install_url : wpforms_pluginlanding.manual_activate_url,
|
||||
msg = ! activationFail ? wpforms_pluginlanding.error_could_not_install : wpforms_pluginlanding.error_could_not_activate,
|
||||
btn = ! activationFail ? wpforms_pluginlanding.download_now : wpforms_pluginlanding.plugins_page;
|
||||
|
||||
$btn.removeClass( 'grey disabled' ).text( btn ).attr( 'data-action', 'goto-url' ).attr( 'data-url', url );
|
||||
$btn.after( '<p class="error">' + msg + '</p>' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback for step 'Install' completion.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
*/
|
||||
stepInstallPluginStatus: function() {
|
||||
|
||||
var data = {
|
||||
action: 'wpforms_smtp_page_check_plugin_status',
|
||||
nonce : wpforms_admin.nonce,
|
||||
};
|
||||
$.post( wpforms_admin.ajax_url, data )
|
||||
.done( app.stepInstallPluginStatusDone );
|
||||
},
|
||||
|
||||
/**
|
||||
* Done part of the callback for step 'Install' completion.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {object} res Result of $.post() query.
|
||||
*/
|
||||
stepInstallPluginStatusDone: function( res ) {
|
||||
|
||||
if ( ! res.success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$stepSetup.removeClass( 'grey' );
|
||||
el.$stepSetupBtn = el.$stepSetup.find( 'button' );
|
||||
el.$stepSetupBtn.removeClass( 'grey disabled' ).addClass( 'button-primary' );
|
||||
|
||||
if ( res.data.setup_status > 0 ) {
|
||||
el.$stepSetupNum.attr( 'src', el.$stepSetupNum.attr( 'src' ).replace( 'step-2.svg', 'step-complete.svg' ) );
|
||||
el.$stepSetupBtn.text( wpforms_pluginlanding.smtp_settings_button );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Go to URL by click on the button.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
gotoURL: function() {
|
||||
|
||||
var $btn = $( this );
|
||||
|
||||
if ( $btn.hasClass( 'disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.location.href = $btn.attr( 'data-url' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Display spinner.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {jQuery} $el Section number image jQuery object.
|
||||
*/
|
||||
showSpinner: function( $el ) {
|
||||
|
||||
$el.siblings( '.loader' ).removeClass( 'hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Hide spinner.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*
|
||||
* @param {jQuery} $el Section number image jQuery object.
|
||||
*/
|
||||
hideSpinner: function( $el ) {
|
||||
|
||||
$el.siblings( '.loader' ).addClass( 'hidden' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsPagesSMTP.init();
|
||||
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/pages/smtp.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/components/admin/pages/smtp.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsPagesSMTP=window.WPFormsPagesSMTP||function(e,l){var i={},o={init:function(){l(o.ready)},ready:function(){o.initVars(),o.events()},initVars:function(){i={$stepInstall:l("section.step-install"),$stepInstallNum:l("section.step-install .num img"),$stepSetup:l("section.step-setup"),$stepSetupNum:l("section.step-setup .num img")}},events:function(){i.$stepInstall.on("click","button",o.stepInstallClick),i.$stepSetup.on("click","button",o.gotoURL)},stepInstallClick:function(){var s=l(this),n=s.attr("data-action"),t=s.attr("data-plugin"),a="";if(!s.hasClass("disabled")){switch(n){case"activate":a="wpforms_activate_addon",s.text(wpforms_pluginlanding.activating);break;case"install":a="wpforms_install_addon",s.text(wpforms_pluginlanding.installing);break;case"goto-url":return void(e.location.href=s.attr("data-url"));default:return}s.addClass("disabled"),o.showSpinner(i.$stepInstallNum);t={action:a,nonce:wpforms_admin.nonce,plugin:t,type:"plugin"};l.post(wpforms_admin.ajax_url,t).done(function(t){o.stepInstallDone(t,s,n)}).always(function(){o.hideSpinner(i.$stepInstallNum)})}},stepInstallDone:function(t,s,n){var a;("install"===n?t.success&&t.data.is_activated:t.success)?(i.$stepInstallNum.attr("src",i.$stepInstallNum.attr("src").replace("step-1.","step-complete.")),s.addClass("grey").removeClass("button-primary").text(wpforms_pluginlanding.activated),o.stepInstallPluginStatus()):(t=(a="install"===n&&t.success&&!t.data.is_activated||"activate"===n)?wpforms_pluginlanding.manual_activate_url:wpforms_pluginlanding.manual_install_url,n=a?wpforms_pluginlanding.error_could_not_activate:wpforms_pluginlanding.error_could_not_install,a=a?wpforms_pluginlanding.plugins_page:wpforms_pluginlanding.download_now,s.removeClass("grey disabled").text(a).attr("data-action","goto-url").attr("data-url",t),s.after('<p class="error">'+n+"</p>"))},stepInstallPluginStatus:function(){var t={action:"wpforms_smtp_page_check_plugin_status",nonce:wpforms_admin.nonce};l.post(wpforms_admin.ajax_url,t).done(o.stepInstallPluginStatusDone)},stepInstallPluginStatusDone:function(t){t.success&&(i.$stepSetup.removeClass("grey"),i.$stepSetupBtn=i.$stepSetup.find("button"),i.$stepSetupBtn.removeClass("grey disabled").addClass("button-primary"),0<t.data.setup_status&&(i.$stepSetupNum.attr("src",i.$stepSetupNum.attr("src").replace("step-2.svg","step-complete.svg")),i.$stepSetupBtn.text(wpforms_pluginlanding.smtp_settings_button)))},gotoURL:function(){var t=l(this);t.hasClass("disabled")||(e.location.href=t.attr("data-url"))},showSpinner:function(t){t.siblings(".loader").removeClass("hidden")},hideSpinner:function(t){t.siblings(".loader").addClass("hidden")}};return o}((document,window),jQuery);WPFormsPagesSMTP.init();
|
||||
Reference in New Issue
Block a user