/* global wpforms_builder, wpforms_education */ /** * WPForms Education core for Lite. * * @since 1.6.6 */ 'use strict'; var WPFormsEducation = window.WPFormsEducation || {}; WPFormsEducation.liteCore = window.WPFormsEducation.liteCore || ( function( document, window, $ ) { /** * 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.openModalButtonClick(); }, /** * Registers click events that should open upgrade modal. * * @since 1.6.6 */ openModalButtonClick: function() { $( '#wpforms-builder, #wpcontent' ).on( 'click', '.education-modal', function( event ) { var $this = $( this ), name = ''; event.preventDefault(); event.stopImmediatePropagation(); if ( $this.hasClass( 'wpforms-add-fields-button' ) ) { name = $this.text() + ' ' + wpforms_builder.field; } else { name = $this.data( 'name' ); } app.upgradeModal( name, $this.data( 'license' ), $this.data( 'video' ) ); } ); }, /** * Upgrade modal. * * @since 1.6.6 * * @param {string} feature Feature name. * @param {string} type Feature license type: pro or elite. * @param {string} video Feature video URL. */ upgradeModal: function( feature, type, video ) { // Provide a default value. if ( typeof type === 'undefined' || type.length === 0 ) { type = 'pro'; } // Make sure we received only supported type. if ( $.inArray( type, [ 'pro', 'elite' ] ) < 0 ) { return; } var message = wpforms_education.upgrade[type].message.replace( /%name%/g, feature ), upgradeURL = wpforms_education.upgrade[type].url + '&utm_content=' + encodeURIComponent( feature.trim() ); $.alert( { title : feature + ' ' + wpforms_education.upgrade[type].title, icon : 'fa fa-lock', content : message, boxWidth: '550px', theme : 'modern,wpforms-education', onOpenBefore: function() { var videoHtml = ! _.isEmpty( video ) ? '' : ''; this.$btnc.after( '