var ET_PageBuilder = ET_PageBuilder || {}; window.wp = window.wp || {}; /** * The builder version and product name will be updated by grunt release task. Do not edit! */ window.et_builder_version = '3.0.97'; window.et_builder_product_name = 'Divi'; ( function($) { var et_error_modal_shown = window.et_error_modal_shown, et_is_loading_missing_modules = false, et_pb_bulder_loading_attempts = 0, et_ls_prefix = 'et_pb_templates_', et_pb_hovered_item_buffer = {}, et_pb_all_unsynced_options = {}, et_pb_all_legacy_synced_options = [], et_pb_key_pressed = { 's' : false, 'r' : false, 'c' : false }; // Rebuild BB template function et_pb_template_rebuild(template, map) { // If we don't have a map, do nothing if (_.isUndefined(map)) { return template; } var placeholder = //g; function unique(match, key) { return map[key]; } return template.replace(placeholder, unique); } function et_builder_maybe_clear_localstorage() { var settings_product_version = et_pb_options.product_version, forced_clear_setting_name, forced_clear; forced_clear_setting_name = 'et_forced_localstorage_clear'; forced_clear = localStorage.getItem( forced_clear_setting_name ); if ( ! forced_clear ) { forced_clear = wpCookies.get( forced_clear_setting_name ); } // attempt to clear localStorage only once if ( forced_clear !== settings_product_version ) { localStorage.clear(); wpCookies.set( forced_clear_setting_name, settings_product_version ); localStorage.setItem( forced_clear_setting_name, settings_product_version ); setTimeout( function() { window.location.reload(); }, 100 ); } } function et_builder_load_backbone_templates( reload_template ) { // run et_pb_append_templates as many times as needed var et_pb_templates_count = 0, date_now = new Date(), today_date = date_now.getYear() + '_' + date_now.getMonth() + '_' + date_now.getDate(), et_ls_all_modules = ( et_pb_options['et_builder_module_parent_shortcodes'] + '|' + et_pb_options['et_builder_module_child_shortcodes'] ).split( '|' ), product_version = et_pb_options.product_version, active_plugins = et_pb_options.active_plugins.join('|'), local_storage_buffer = '', processed_modules_count = 0, missing_modules = { missing_modules_array: [] }, et_pb_templates_interval; reload_template = _.isUndefined( reload_template ) ? false : reload_template; if ( ! reload_template ) { if ( ! $( 'script[src="' + et_pb_options.builder_js_src + '"]' ).length ) { $( '.et-pb-cache-update' ).show(); } $( 'body' ).on( 'click', '.et_builder_increase_memory', function() { var $this_button = $(this); $.ajax({ type: "POST", dataType: 'json', url: et_pb_options.ajaxurl, data: { action : 'et_pb_increase_memory_limit', et_admin_load_nonce : et_pb_options.et_admin_load_nonce }, success: function( data ) { if ( ! _.isUndefined( data.success ) ) { $this_button.addClass( 'et_builder_modal_action_button_success' ).text( et_pb_options.memory_limit_increased ); } else { $this_button.addClass( 'et_builder_modal_action_button_fail' ).prop( 'disabled', true ).text( et_pb_options.memory_limit_not_increased ); } } }); return false; } ); $( 'body' ).on( 'click', '.et_pb_reload_builder', function() { location.reload(); return false; } ); } if ( et_should_load_from_local_storage() ) { for ( et_ls_module_index in et_ls_all_modules ) { var et_ls_module_slug = et_ls_all_modules[ et_ls_module_index ], et_ls_template_slug = et_ls_prefix + et_ls_module_slug, et_ls_template_content = LZString.decompressFromUTF16( localStorage.getItem( et_ls_template_slug ) ); // count the processed modules processed_modules_count++; if ( _.isUndefined( et_ls_template_content ) || _.isNull( et_ls_template_content ) || '' === et_ls_template_content ) { missing_modules['missing_modules_array'].push( et_ls_module_slug ); } else { local_storage_buffer += LZString.decompressFromUTF16( localStorage.getItem( et_ls_template_slug ) ); } // perform ajax request if missing_modules_array length equals to the templates amount setting or if all the modules processed and we need to retrieve something if ( ! et_is_loading_missing_modules && ( ( missing_modules['missing_modules_array'].length === parseInt( et_pb_options.et_builder_templates_amount ) ) || ( missing_modules['missing_modules_array'].length && ( et_ls_all_modules.length === processed_modules_count ) ) ) ) { et_is_loading_missing_modules = true; $.ajax({ type: "POST", dataType: 'json', url: et_pb_options.ajaxurl, data: { action : 'et_pb_get_backbone_template', et_post_type : et_pb_options.post_type, et_modules_slugs : JSON.stringify( missing_modules ), et_admin_load_nonce : et_pb_options.et_admin_load_nonce }, success: function( data ) { et_is_loading_missing_modules = false; var template; // Backend always returns an array of templates, even for a single module. if ( !_.isUndefined(data.templates) && data.templates.length ) { _.each( data.templates, function( single_module ) { template = et_pb_template_rebuild(single_module['template'], data.unique); try { localStorage.setItem( et_ls_prefix + single_module['slug'], LZString.compressToUTF16( template ) ); } catch(e) { // do not use localStorage if it full or any other error occurs et_builder_maybe_clear_localstorage(); } $( 'body' ).append( template ); } ); } } }); // reset the array of missing modules missing_modules['missing_modules_array'] = []; } } $( 'body' ).append( local_storage_buffer ); } else { // run et_pb_append_templates as many times as needed et_pb_templates_interval = setInterval( function() { if ( et_pb_templates_count === Math.ceil( et_pb_options.et_builder_modules_count/et_pb_options.et_builder_templates_amount ) ) { clearInterval( et_pb_templates_interval ); return false; } et_pb_append_templates( et_pb_templates_count * et_pb_options.et_builder_templates_amount ); et_pb_templates_count++; }, 800); et_ls_set_transient(); } function et_builder_has_storage_support() { try { return 'localStorage' in window && window.localStorage !== null; } catch (e) { return false; } } function et_ls_set_transient() { if ( ! et_builder_has_storage_support() ) { return false; } try { localStorage.setItem( et_ls_prefix + 'settings_date', today_date ); localStorage.setItem( et_ls_prefix + 'settings_product_version', product_version ); localStorage.setItem( et_ls_prefix + 'settings_active_plugins', active_plugins ); } catch(e) { // do not use localStorage if it full or any other error occurs } } function et_should_load_from_local_storage() { if ( ! et_builder_has_storage_support() ) { return false; } if ( ! _.isUndefined( et_pb_options.force_cache_purge ) && 'true' === et_pb_options.force_cache_purge ) { return false; } var et_ls_settings_date = localStorage.getItem( et_ls_prefix + 'settings_date' ), et_ls_settings_product_version = localStorage.getItem( et_ls_prefix + 'settings_product_version' ), et_ls_settings_active_plugins = localStorage.getItem( et_ls_prefix + 'settings_active_plugins' ); if ( _.isUndefined( et_ls_settings_date ) || _.isNull( et_ls_settings_date ) ) { return false; } if ( _.isUndefined( et_ls_settings_product_version ) || _.isNull( et_ls_settings_product_version ) ) { return false; } if ( et_ls_settings_active_plugins !== active_plugins ) { return false; } if ( today_date != et_ls_settings_date || product_version != et_ls_settings_product_version ) { et_remove_ls_templates(); return false; } return true; } function et_remove_ls_templates() { if ( ! et_builder_has_storage_support() ) { return false; } _.forEach( _.keys( localStorage ), function( key ) { if ( startsWith( key, 'et_pb_templates_' ) ) { localStorage.removeItem( key ); } } ); } function et_pb_append_templates( start_from ) { $.ajax({ type: "POST", dataType: 'json', url: et_pb_options.ajaxurl, data: { action : 'et_pb_get_backbone_templates', et_post_type : et_pb_options.post_type, et_admin_load_nonce : et_pb_options.et_admin_load_nonce, et_templates_start_from : start_from }, error: function() { var $failure_notice_template = $( '#et-builder-failure-notice-template' ); if ( et_error_modal_shown ) { return; } if ( ! $failure_notice_template.length ) { return; } if ( $( '.et_pb_failure_notification_modal' ).length ) { return; } if ( et_builder_has_storage_support() ) { localStorage.removeItem( et_ls_prefix + 'settings_date' ); localStorage.removeItem( et_ls_prefix + 'settings_product_version' ); localStorage.removeItem( et_ls_prefix + 'settings_active_plugins' ); } $( 'body' ).addClass( 'et_pb_stop_scroll' ).append( $failure_notice_template.html() ); }, success: function( data ) { //append retrieved templates to body var template; for ( var name in data.templates ) { template = et_pb_template_rebuild(data.templates[name], data.unique); if ( et_builder_has_storage_support() ) { try { localStorage.setItem( 'et_pb_templates_' + name, LZString.compressToUTF16( template ) ); } catch(e) { // do not use localStorage if it full or any other error occurs et_builder_maybe_clear_localstorage(); } } $( 'body' ).append( template ); } } }); } } et_builder_load_backbone_templates(); /** * Get value from object located at path. * * @see https://stackoverflow.com/a/15643385/2639936 * * @param obj * @param path * @return {*} */ function get( obj, path ) { return _.reduce( path.split( '.' ), function ( prev, curr ) { return prev ? prev[curr] : undefined; }, obj ); } /** * Check if path exists in object. * * @see https://stackoverflow.com/a/42042678/2639936 * * @param obj * @param path * @return {boolean} */ function has( obj, path ) { if ( ! path ) { return true; } var path_parts = path.split( '.' ); var first_part = _.first( path_parts ); return _.has( obj, first_part ) && has( obj[first_part], _.rest( path_parts ).join( '.' ) ); } /** * Determine whether or not a string ends with another string. * * @param string * @param substring * @return {boolean} */ function endsWith( string, substring ) { return string.substr( string.length - substring.length, string.length ) === substring; } /** * Determine whether or not a string starts with another string. * * @param string * @param substring * @return {boolean} */ function startsWith( string, substring ) { return string.substr( 0, string.length ) === substring; } $( document ).ready( function() { // Explicitly define ERB-style template delimiters to prevent // template delimiters being overwritten by 3rd party plugin _.templateSettings = { evaluate : /<%([\s\S]+?)%>/g, interpolate: /<%=([\s\S]+?)%>/g, escape : /<%-([\s\S]+?)%>/g }; //Helpers ET_PageBuilder.Helpers = {}; ET_PageBuilder.Helpers.getSettingValue = function($setting) { var setting_value; var checked_values = []; var custom_css_option_value; var name = $setting.is('#et_pb_content_main') ? 'et_pb_content_new' : $setting.attr('id'); // Process all checkboxex for the current setting at once if ($setting.is(':checkbox')) { // name attribute is used in normal html checkboxes, use it instead of ID name = $setting.attr('name'); $setting.closest('.et-pb-option-container').find('[name="' + name + '"]:checked').each(function () { checked_values.push($(this).val()); }); setting_value = checked_values.join(","); } else if ($setting.is('#et_pb_content_main')) { // Process main content setting_value = $setting.html(); // Replace temporary ^^ signs with double quotes setting_value = setting_value.replace( /\^\^/g, '%22' ); } else if ( $setting.closest( '.et-pb-custom-css-option' ).length ) { // Custom CSS settings content should be modified before it is added to the shortcode attribute custom_css_option_value = $setting.val(); // replace new lines with || and backlash \ with %92 in Custom CSS settings setting_value = '' !== custom_css_option_value ? custom_css_option_value.replace( /(?:\r\n|\r|\n)/g, '\|\|' ).replace( /\\/g, '%92' ) : ''; } else if ( $setting.hasClass( 'et-pb-range-input' ) ) { // Get range input value setting_value = et_pb_get_range_input_value($setting); if ($setting.hasClass('et-pb-validate-unit')) { setting_value = et_pb_sanitize_input_unit_value(setting_value.toString(), false, 'no_default_unit'); } } else if ($setting.hasClass('et-pb-range')) { var $real_setting = $setting.siblings('.et-pb-range-input'); setting_value = et_pb_get_range_input_value($real_setting); if ($real_setting.hasClass('et-pb-validate-unit')) { setting_value = et_pb_sanitize_input_unit_value(setting_value.toString(), false, 'no_default_unit'); } } else if ( $setting.hasClass( 'et-pb-validate-unit' ) ) { // Process validated unit setting_value = et_pb_sanitize_input_unit_value( $setting.val(), false, '' ); } else if ( $setting.hasClass( 'et-pb-text-align-select') ) { // Process text alignment option. Check for button's et_text_align_active class name to ensure that an option is selected. // This prevents the builder unwantedly treats first option as selected option if ( $setting.closest( '.et-pb-option-container' ).find( '.et_text_align_active' ).length ) { setting_value = $setting.val(); } } else if ( ! $setting.is( ':checkbox' ) ) { // Process all other settings: inputs, textarea#et_pb_content_new, range sliders etc. setting_value = $setting.is('textarea#et_pb_content_new') ? et_pb_get_content( 'et_pb_content_new' ) : $setting.val(); if ( $setting.hasClass( 'et-pb-range-input' ) && setting_value === 'px' ) { setting_value = ''; } } if (_.isNull(setting_value)) { setting_value = ''; } return setting_value; }; // Models ET_PageBuilder.Module = Backbone.Model.extend( { defaults: { type : 'element', _builder_version : et_pb_options.product_version } } ); ET_PageBuilder.SavedTemplate = Backbone.Model.extend( { defaults: { title : 'template', ID : 0, shortcode : '', is_global : 'false', layout_type : '', module_type : '', categories : [], unsynced_options : [] } } ); ET_PageBuilder.History = Backbone.Model.extend( { defaults : { timestamp : _.now(), shortcode : '', current_active_history : false, verb : 'did', noun : 'something' }, max_history_limit : 100, validate : function( attributes, options ) { var histories_count = options.collection.length, active_history_model = options.collection.findWhere({ current_active_history : true }), shortcode = attributes.shortcode, last_model = _.isUndefined( active_history_model ) ? options.collection.at( ( options.collection.length - 1 ) ) : active_history_model, last_shortcode = _.isUndefined( last_model ) ? false : last_model.get( 'shortcode' ), previous_active_histories; if ( shortcode === last_shortcode ) { return 'duplicate'; } // Turn history tracking off ET_PageBuilder_App.enable_history = false; // Limit number of history limit var histories_count = options.collection.models.length, remove_limit = histories_count - ( this.max_history_limit - 1 ), ranges, deleted_model; // Some models are need to be removed if ( remove_limit > 0 ) { // Loop and shift (remove first model in collection) n-times for (var i = 1; i <= remove_limit; i++) { options.collection.shift(); }; } } } ); // helper module ET_PageBuilder.Layout = Backbone.Model.extend( { defaults: { moduleNumber : 0, forceRemove : false, modules : $.parseJSON( et_pb_options.et_builder_modules ), views : [ ] }, initialize : function() { // Single and double quotes are replaced with %% in et_builder_modules // to avoid js conflicts. // Replace them with appropriate signs. _.each( this.get( 'modules' ), function( module ) { module['title'] = module['title'].replace( /%%/g, '"' ); module['title'] = module['title'].replace( /\|\|/g, "'" ); } ); }, addView : function( module_cid, view ) { var views = this.get( 'views' ); views[module_cid] = view; this.set( { 'views' : views } ); }, getView : function( cid ) { return this.get( 'views' )[cid]; }, getChildViews : function( parent_id ) { var views = this.get( 'views' ), child_views = {}; _.each( views, function( view, key ) { if ( typeof view !== 'undefined' && view['model']['attributes']['parent'] === parent_id ) child_views[key] = view; } ); return child_views; }, getChildrenViews : function( parent_id ) { var this_el = this, views = this_el.get( 'views' ), child_views = {}, grand_children; _.each( views, function( view, key ) { if ( typeof view !== 'undefined' && view['model']['attributes']['parent'] === parent_id ) { grand_children = this_el.getChildrenViews( view['model']['attributes']['cid'] ); if ( ! _.isEmpty( grand_children ) ) { _.extend( child_views, grand_children ); } child_views[key] = view; } } ); return child_views; }, getParentViews : function( parent_cid ) { var parent_view = this.getView( parent_cid ), parent_views = {}; while( ! _.isUndefined( parent_view ) ) { parent_views[parent_view['model']['attributes']['cid']] = parent_view; parent_view = this.getView( parent_view['model']['attributes']['parent'] ); } return parent_views; }, getSectionView : function( parent_cid ) { var views = this.getParentViews( parent_cid ), section_view; section_view = _.filter( views, function( item ) { if ( item.model.attributes.type === "section" ) { return true; } else { return false; } } ); if ( _.isUndefined( section_view[0] ) ) { return false; } else { return section_view[0]; } }, setNewParentID : function( cid, new_parent_id ) { var views = this.get( 'views' ); views[cid]['model']['attributes']['parent'] = new_parent_id; this.set( { 'views' : views } ); }, removeView : function( cid ) { var views = this.get( 'views' ), new_views = {}; _.each( views, function( value, key ) { if ( key != cid ) new_views[key] = value; } ); this.set( { 'views' : new_views } ); }, generateNewId : function() { var moduleNumber = this.get( 'moduleNumber' ) + 1; this.set( { 'moduleNumber' : moduleNumber } ); return moduleNumber; }, generateTemplateName : function( name ) { var default_elements = [ 'row', 'row_inner', 'section', 'column', 'column_inner']; if ( -1 !== $.inArray( name, default_elements ) ) { name = 'et_pb_' + name; } return '#et-builder-' + name + '-module-template'; }, getModuleOptionsNames : function( module_type ) { var modules = this.get('modules'); return this.addAdminLabel( _.findWhere( modules, { label : module_type } )['options'] ); }, getNumberOf : function( element_name, module_cid ) { var views = this.get( 'views' ), num = 0; _.each( views, function( view ) { if ( typeof view !== 'undefined' ) { var type = view['model']['attributes']['type']; if ( view['model']['attributes']['parent'] === module_cid && ( type === element_name || type === ( element_name + '_inner' ) ) ) num++; } } ); return num; }, getNumberOfModules : function( module_name ) { var views = this.get( 'views' ), num = 0; _.each( views, function( view ) { if ( typeof view !== 'undefined' ) { if ( view['model']['attributes']['type'] === module_name ) num++; } } ); return num; }, getTitleByShortcodeTag : function ( tag ) { var modules = this.get('modules'); return _.findWhere( modules, { label : tag } )['title']; }, getDefaultAdminLabel : function( module_type ) { var is_structure_element = $.inArray( module_type, [ 'section', 'row', 'column', 'row_inner', 'column_inner' ] ) > -1; if ( is_structure_element ) { return typeof et_pb_options.noun[ module_type ] !== 'undefined' ? et_pb_options.noun[ module_type ] : module_type; } return this.getTitleByShortcodeTag( module_type ); }, isModuleFullwidth : function ( module_type ) { var modules = this.get('modules'); return 'on' === _.findWhere( modules, { label : module_type } )['fullwidth_only'] ? true : false; }, isChildrenLocked : function ( module_cid ) { var children_views = this.getChildrenViews( module_cid ), children_locked = false; _.each( children_views, function( child ) { if ( child.model.get( 'et_pb_locked' ) === 'on' || child.model.get( 'et_pb_parent_locked' ) === 'on' ) { children_locked = true; } } ); return children_locked; }, addAdminLabel : function ( optionsNames ) { return _.union( optionsNames, ['admin_label'] ); }, removeGlobalAttributes : function ( view, keep_attributes ) { var this_class = this, keep_attributes = _.isUndefined( keep_attributes ) ? false : keep_attributes, global_item_cid = _.isUndefined( view.model.attributes.global_parent_cid ) ? view.model.attributes.cid : view.model.attributes.global_parent_cid, global_item_view = this.getView( global_item_cid ); global_item_children_views = this.getChildrenViews( global_item_cid ); // Modify global item's attributes if ( this.is_global( global_item_view.model ) ) { if ( keep_attributes ) { global_item_view.model.set( 'et_pb_temp_global_module', global_item_view.model.get( 'et_pb_global_module' ) ); } global_item_view.model.unset( 'et_pb_global_module' ); } // Modify global item children's attributes _.each( global_item_children_views, function( global_item_children_view ) { if ( this_class.is_global_children( global_item_children_view.model ) ) { if ( keep_attributes ) { global_item_children_view.model.set( 'et_pb_temp_global_parent', global_item_children_view.model.get( 'et_pb_global_parent' ) ); } global_item_children_view.model.unset( 'et_pb_global_parent' ); } if ( this_class.has_global_parent_cid( global_item_children_view.model ) ) { if ( keep_attributes ) { global_item_children_view.model.set( 'et_pb_temp_global_parent_cid', global_item_children_view.model.get( 'global_parent_cid' ) ); } global_item_children_view.model.unset( 'global_parent_cid' ); } }); }, removeTemporaryGlobalAttributes : function ( view, restore_attributes ) { var this_class = this, restore_attributes = _.isUndefined( restore_attributes ) ? false : restore_attributes, global_item_model = _.isUndefined( view.model.attributes.et_pb_temp_global_module ) ? ET_PageBuilder_Modules.findWhere({ et_pb_temp_global_module : view.model.attributes.et_pb_temp_global_parent }) : view.model, global_item_cid = global_item_model.attributes.cid, global_item_view = ET_PageBuilder_Layout.getView( global_item_cid ); global_item_children_views = ET_PageBuilder_Layout.getChildrenViews( global_item_cid ); if ( this.is_temp_global( global_item_view.model ) ) { if ( restore_attributes ) { global_item_view.model.set( 'et_pb_global_module', global_item_view.model.get( 'et_pb_temp_global_module' ) ); } global_item_view.model.unset( 'et_pb_temp_global_module' ); } _.each( global_item_children_views, function( global_item_children_view ) { if ( this_class.is_temp_global_children( global_item_children_view.model ) ) { if ( restore_attributes ) { global_item_children_view.model.set( 'et_pb_global_parent', global_item_children_view.model.get( 'et_pb_temp_global_parent' ) ); } global_item_children_view.model.unset( 'et_pb_temp_global_parent' ); } if ( this_class.has_temp_global_parent_cid( global_item_children_view.model ) ) { if ( restore_attributes ) { global_item_children_view.model.set( 'global_parent_cid', global_item_children_view.model.get( 'et_pb_temp_global_parent_cid' ) ); } global_item_children_view.model.unset( 'et_pb_temp_global_parent_cid' ); } }); if ( restore_attributes ) { // Update global template et_pb_update_global_template( global_item_cid ); } }, is_app : function( model ) { if ( model.attributes.type === 'app' ) { return true; } return false; }, is_global : function( model ) { // App cannot be global module. Its model.get() returns error if ( this.is_app( model ) ) { return false; } return model.has( 'et_pb_global_module' ) && model.get( 'et_pb_global_module' ) !== '' ? true : false; }, is_global_children : function( model ) { // App cannot be global module. Its model.get() returns error if ( this.is_app( model ) ) { return false; } return model.has( 'et_pb_global_parent' ) && model.get( 'et_pb_global_parent' ) !== '' ? true : false; }, has_global_parent_cid : function( model ) { return model.has( 'global_parent_cid' ) && model.get( 'global_parent_cid' ) !== '' ? true : false; }, is_temp_global : function( model ) { return model.has( 'et_pb_temp_global_module' ) && model.get( 'et_pb_temp_global_module' ) !== '' ? true : false; }, is_temp_global_children : function( model ) { return model.has( 'et_pb_temp_global_parent' ) && model.get( 'et_pb_temp_global_parent' ) !== '' ? true : false; }, has_temp_global_parent_cid : function( model ) { return model.has( 'et_pb_temp_global_parent_cid' ) && model.get( 'et_pb_temp_global_parent_cid' ) !== '' ? true : false; }, changeColumnStructure: function( that, options, skip_reinit, skip_history ) { var layout = options.layout.split(','), specialty_columns = options.specialty_columns, layout_specialty = options.layout_specialty, layout_elements_num = _.size( layout ), this_view = that.options.view; global_module_cid = et_pb_get_global_parent_cid( that ); if ( options.is_structure_change ) { var row_columns = ET_PageBuilder_Layout.getChildViews( that.model.get( 'cid' ) ), columns_structure_old = [], index_count = 0; _.each( row_columns, function( row_column ) { columns_structure_old[index_count] = row_column.model.get( 'cid' ); index_count = index_count + 1; } ); } _.each( layout, function( element, index ) { var update_content = layout_elements_num == ( index + 1 ) ? 'true' : 'false', column_attributes = { type : 'column', cid : ET_PageBuilder_Layout.generateNewId(), parent : that.model.get( 'cid' ), layout : element, view : this_view }; if ( typeof that.model.get( 'et_pb_global_parent' ) !== 'undefined' && '' !== that.model.get( 'et_pb_global_parent' ) ) { column_attributes.et_pb_global_parent = that.model.get( 'et_pb_global_parent' ); column_attributes.global_parent_cid = that.model.get( 'global_parent_cid' ); } if ( typeof layout_specialty[index] !== 'undefined' && layout_specialty[index] === '1' ) { column_attributes.layout_specialty = layout_specialty[index]; column_attributes.specialty_columns = parseInt( specialty_columns ); } if ( typeof that.model.get( 'specialty_row' ) !== 'undefined' ) { that.model.set( 'module_type', 'row_inner', { silent : true } ); that.model.set( 'type', 'row_inner', { silent : true } ); } that.collection.add( [ column_attributes ], { update_shortcodes : update_content } ); } ); if ( options.is_structure_change ) { var columns_structure_new = []; row_columns = ET_PageBuilder_Layout.getChildViews( that.model.get( 'cid' ) ); index_count = 0; _.each( row_columns, function( row_column ) { columns_structure_new[index_count] = row_column.model.get( 'cid' ); index_count = index_count + 1; } ); // delete old columns IDs columns_structure_new.splice( 0, columns_structure_old.length ); for ( index = 0; index < columns_structure_old.length; index++ ) { var is_extra_column = ( columns_structure_old.length > columns_structure_new.length ) && ( index > ( columns_structure_new.length - 1 ) ) ? true : false, old_column_cid = columns_structure_old[index], new_column_cid = is_extra_column ? columns_structure_new[columns_structure_new.length-1] : columns_structure_new[index], column_html = ET_PageBuilder_Layout.getView( old_column_cid ).$el.html(), modules = ET_PageBuilder_Layout.getChildViews( old_column_cid ), $updated_column, column_html_old = ''; ET_PageBuilder_Layout.getView( old_column_cid ).model.destroy(); ET_PageBuilder_Layout.getView( old_column_cid ).remove(); ET_PageBuilder_Layout.removeView( old_column_cid ); $updated_column = $('.et-pb-column[data-cid="' + new_column_cid + '"]'); if ( ! is_extra_column ) { $updated_column.html( column_html ); } else { $updated_column.find( '.et-pb-insert-module' ).remove(); column_html_old = $updated_column.html(); $updated_column.html( column_html_old + column_html ); } _.each( modules, function( module ) { module.model.set( 'parent', new_column_cid, { silent : true } ); } ); } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'edited', 'column' ); if ( ! skip_reinit ) { et_reinitialize_builder_layout(); } } if ( typeof that.model.get( 'template_type' ) !== 'undefined' && 'section' === that.model.get( 'template_type' ) && 'on' === that.model.get( 'et_pb_specialty' ) ) { et_reinitialize_builder_layout(); } if ( typeof that.model.get( 'et_pb_template_type' ) !== 'undefined' && 'row' === that.model.get( 'et_pb_template_type' ) ) { et_add_template_meta( '_et_pb_row_layout', options.layout ); } if ( typeof global_module_cid !== 'undefined' && '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); } if ( ! skip_history ) { // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'added', 'column' ); } ET_PageBuilder_Events.trigger( 'et-add:columns' ); }, } ); // Collections ET_PageBuilder.Modules = Backbone.Collection.extend( { model : ET_PageBuilder.Module } ); ET_PageBuilder.SavedTemplates = Backbone.Collection.extend( { model : ET_PageBuilder.SavedTemplate } ); ET_PageBuilder.Histories = Backbone.Collection.extend( { model : ET_PageBuilder.History } ); //Views ET_PageBuilder.TemplatesView = window.wp.Backbone.View.extend( { className : 'et_pb_saved_layouts_list', tagName : 'ul', render: function() { var global_class = '', layout_category = typeof this.options.category === 'undefined' ? 'all' : this.options.category; this.collection.each( function( single_template ) { if ( 'all' === layout_category || ( -1 !== $.inArray( layout_category, single_template.get( 'categories' ) ) ) ) { var single_template_view = new ET_PageBuilder.SingleTemplateView( { model: single_template } ); this.$el.append( single_template_view.el ); global_class = typeof single_template_view.model.get( 'is_global' ) !== 'undefined' && 'global' === single_template_view.model.get( 'is_global' ) ? 'global' : ''; } }, this ); if ( 'global' === global_class ) { this.$el.addClass( 'et_pb_global' ); } return this; } } ); ET_PageBuilder.SingleTemplateView = window.wp.Backbone.View.extend( { tagName : 'li', template: _.template( $( '#et-builder-saved-entry' ).html() ), events: { 'click' : 'insertSection', }, initialize: function(){ this.render(); }, render: function() { this.$el.html( this.template( this.model.toJSON() ) ); if ( typeof this.model.get( 'module_type' ) !== 'undefined' && '' !== this.model.get( 'module_type' ) && 'module' === this.model.get( 'layout_type' ) ) { this.$el.addClass( this.model.get( 'module_type' ) ); } }, insertSection : function( event ) { var clicked_button = $( event.target ), parent_id = typeof clicked_button.closest( '.et_pb_modal_settings' ).data( 'parent_cid' ) !== 'undefined' ? clicked_button.closest( '.et_pb_modal_settings' ).data( 'parent_cid' ) : '', current_row = typeof $( '.et-pb-settings-heading' ).data( 'current_row' ) !== 'undefined' ? $( '.et-pb-settings-heading' ).data( 'current_row' ) : '', global_id = 'global' === this.model.get( 'is_global' ) ? this.model.get( 'ID' ) : '', specialty_row = typeof $( '.et-pb-saved-modules-switcher' ).data( 'specialty_columns' ) !== 'undefined' ? 'on' : 'off', shortcode = this.model.get( 'shortcode' ), unsynced_options = this.model.get( 'unsynced_options' ), update_global = false, global_holder_id = 'row' === this.model.get( 'layout_type' ) ? current_row : parent_id, global_holder_view = ET_PageBuilder_Layout.getView( global_holder_id ), history_noun = this.options.model.get( 'layout_type' ) === 'row_inner' ? 'saved_row' : 'saved_' + this.options.model.get( 'layout_type' ), $modal_container = clicked_button.closest( '.et_pb_modal_settings_container' ), global_parent_cid = et_pb_get_global_parent_cid( global_holder_view ); if ( 'on' === specialty_row ) { global_holder_id = global_holder_view.model.get( 'parent' ); global_holder_view = ET_PageBuilder_Layout.getView( global_holder_id ); } if ( 'section' !== this.model.get( 'layout_type' ) && ( '' !== global_parent_cid ) ) { update_global = true; // reset global id when adding global module into global section or row. global_id = ''; } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'added', history_noun ); event.preventDefault(); // apply wpautop to the shortcode to make sure all the line breaks inserted correctly if ( typeof window.switchEditors !== 'undefined' ) { shortcode = et_pb_fix_shortcodes( window.switchEditors.wpautop( shortcode ) ); } ET_PageBuilder_App.createLayoutFromContent( shortcode , parent_id, '', { ignore_template_tag : 'ignore_template', current_row_cid : current_row, global_id : global_id, after_section : parent_id, is_reinit : 'reinit', 'unsynced_options' : unsynced_options } ); et_reinitialize_builder_layout(); if ( true === update_global ) { et_pb_update_global_template( global_parent_cid ); } if ( $modal_container.length ) { $modal_container.find( '.et-pb-modal-close' ).click(); } } } ); ET_PageBuilder.TemplatesModal = window.wp.Backbone.View.extend( { className : 'et_pb_modal_settings', template : _.template( $( '#et-builder-load_layout-template' ).html() ), events : { 'click .et-pb-options-tabs-links li a' : 'switchTab' }, render: function() { this.$el.html( this.template( { "display_switcher" : "off" } ) ); this.$el.addClass( 'et_pb_modal_no_tabs' ); return this; }, switchTab: function( event ) { var $this_el = $( event.currentTarget ).parent(); event.preventDefault(); et_handle_templates_switching( $this_el, 'section', '' ); } } ); ET_PageBuilder.SectionView = window.wp.Backbone.View.extend( { className : 'et_pb_section', template : _.template( $('#et-builder-section-template').html() ), events: { 'click .et-pb-settings-section' : 'showSettings', 'click .et-pb-clone-section' : 'cloneSection', 'click .et-pb-remove-section' : 'removeSection', 'click .et-pb-section-add-main' : 'addSection', 'click .et-pb-section-add-fullwidth' : 'addFullwidthSection', 'click .et-pb-section-add-specialty' : 'addSpecialtySection', 'click .et-pb-section-add-saved' : 'addSavedSection', 'click .et-pb-expand' : 'expandSection', 'click .et-pb-insert-row' : 'addFirstRow', 'contextmenu .et-pb-section-add' : 'showRightClickOptions', 'click.et_pb_section > .et-pb-controls .et-pb-unlock' : 'unlockSection', 'contextmenu.et_pb_section > .et-pb-controls' : 'showRightClickOptions', 'contextmenu.et_pb_row > .et-pb-right-click-trigger-overlay' : 'showRightClickOptions', 'click.et_pb_section > .et-pb-controls' : 'hideRightClickOptions', 'click.et_pb_row > .et-pb-right-click-trigger-overlay' : 'hideRightClickOptions', 'click > .et-pb-locked-overlay' : 'showRightClickOptions', 'contextmenu > .et-pb-locked-overlay' : 'showRightClickOptions', 'click' : 'setABTesting', }, initialize : function() { this.child_views = []; this.listenTo( this.model, 'change:admin_label', this.renameModule ); this.listenTo( this.model, 'change:et_pb_disabled', this.toggleDisabledClass ); }, render : function() { this.$el.html( this.template( this.model.toJSON() ) ); if ( this.model.get( 'et_pb_specialty' ) === 'on' ) { this.$el.addClass( 'et_pb_section_specialty' ); if ( this.model.get( 'et_pb_specialty_placeholder' ) === 'true' ) { this.$el.addClass( 'et_pb_section_placeholder' ); } } if ( this.model.get( 'et_pb_specialty' ) === 'on' || this.model.get( 'et_pb_fullwidth' ) === 'on' ) { this.$el.find( '.et-pb-insert-row' ).remove(); } if ( typeof this.model.get( 'et_pb_global_module' ) !== 'undefined' || ( typeof this.model.get( 'et_pb_template_type' ) !== 'undefined' && 'section' === this.model.get( 'et_pb_template_type' ) && 'global' === et_pb_options.is_global_template ) ) { this.$el.addClass( 'et_pb_global' ); } if ( typeof this.model.get( 'et_pb_disabled' ) !== 'undefined' && this.model.get( 'et_pb_disabled' ) === 'on' ) { this.$el.addClass( 'et_pb_disabled' ); } if ( typeof this.model.get( 'et_pb_locked' ) !== 'undefined' && this.model.get( 'et_pb_locked' ) === 'on' ) { this.$el.addClass( 'et_pb_locked' ); } if ( typeof this.model.get( 'et_pb_collapsed' ) !== 'undefined' && this.model.get( 'et_pb_collapsed' ) === 'on' ) { this.$el.addClass( 'et_pb_collapsed' ); } if ( typeof this.model.get( 'pasted_module' ) !== 'undefined' && this.model.get( 'pasted_module' ) ) { et_pb_handle_clone_class( this.$el ); } if ( ! _.isUndefined( this.model.get( 'et_pb_temp_global_module' ) ) ) { this.$el.addClass( 'et_pb_global_temp' ); } // AB Testing related class if ( ET_PageBuilder_AB_Testing.is_active() ) { if ( ET_PageBuilder_AB_Testing.is_subject( this.model ) ) { this.$el.addClass( 'et_pb_ab_subject' ); // Apply subject rank coloring ET_PageBuilder_AB_Testing.set_subject_rank_coloring( this ); } if ( ET_PageBuilder_AB_Testing.is_goal( this.model ) ) { this.$el.addClass( 'et_pb_ab_goal' ); } // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'section' ) ) { this.$el.addClass( 'et_pb_ab_no_permission' ); } } this.makeRowsSortable(); return this; }, showSettings : function( event ) { var that = this, $current_target = typeof event !== 'undefined' ? $( event.currentTarget ) : '', modal_view, view_settings = { model : this.model, collection : this.collection, attributes : { 'data-open_view' : 'module_settings' }, triggered_by_right_click : this.triggered_by_right_click, do_preview : this.do_preview }; if ( typeof event !== 'undefined' ) { event.preventDefault(); } if ( this.isSectionLocked() ) { return; } if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'section' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } } if ( '' !== $current_target && $current_target.closest( '.et_pb_section_specialty' ).length ) { var $specialty_section_columns = $current_target.closest( '.et_pb_section_specialty' ).find( '.et-pb-section-content > .et-pb-column' ), columns_layout = ''; if ( $specialty_section_columns.length ) { $specialty_section_columns.each( function() { columns_layout += '' === columns_layout ? '1_1' : ',1_1'; }); } view_settings.model.attributes.columns_layout = columns_layout; } modal_view = new ET_PageBuilder.ModalView( view_settings ); et_modal_view_rendered = modal_view.render(); if ( false === et_modal_view_rendered ) { et_builder_load_backbone_templates( true ); setTimeout( function() { that.showSettings(); }, 500 ); ET_PageBuilder_Events.trigger( 'et-pb-loading:started' ); return; } ET_PageBuilder_Events.trigger( 'et-pb-loading:ended' ); $('body').append( et_modal_view_rendered.el ); if ( ( typeof modal_view.model.get( 'et_pb_global_module' ) !== 'undefined' && '' !== modal_view.model.get( 'et_pb_global_module' ) ) || ( typeof this.model.get( 'et_pb_template_type' ) !== 'undefined' && 'section' === this.model.get( 'et_pb_template_type' ) && 'global' === et_pb_options.is_global_template ) ) { $( '.et_pb_modal_settings_container' ).addClass( 'et_pb_saved_global_modal' ); } if ( typeof this.model.get( 'et_pb_specialty' ) !== 'undefined' && 'on' === this.model.get( 'et_pb_specialty' ) ) { $( '.et_pb_modal_settings_container' ).addClass( 'et_pb_specialty_section_settings' ); } et_pb_open_current_tab(); }, addSection : function( event ) { var module_id = ET_PageBuilder_Layout.generateNewId(); event.preventDefault(); et_pb_close_all_right_click_options(); if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'added', 'section' ); this.collection.add( [ { type : 'section', module_type : 'section', et_pb_fullwidth : 'off', et_pb_specialty : 'off', cid : module_id, view : this, created : 'auto', admin_label : et_pb_options.noun['section'] } ] ); }, addFullwidthSection : function( event ) { var module_id = ET_PageBuilder_Layout.generateNewId(); event.preventDefault(); et_pb_close_all_right_click_options(); if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'added', 'fullwidth_section' ); this.collection.add( [ { type : 'section', module_type : 'section', et_pb_fullwidth : 'on', et_pb_specialty : 'off', cid : module_id, view : this, created : 'auto', admin_label : et_pb_options.noun['section'] } ] ); }, addSpecialtySection : function( event ) { var module_id = ET_PageBuilder_Layout.generateNewId(), $event_target = $(event.target), template_type = typeof $event_target !== 'undefined' && typeof $event_target.data( 'is_template' ) !== 'undefined' ? 'section' : ''; event.preventDefault(); et_pb_close_all_right_click_options(); if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'added', 'specialty_section' ); this.collection.add( [ { type : 'section', module_type : 'section', et_pb_fullwidth : 'off', et_pb_specialty : 'on', cid : module_id, template_type : template_type, view : this, created : 'auto', admin_label : et_pb_options.noun['section'] } ] ); }, addSavedSection : function( event ) { var parent_cid = this.model.get( 'cid' ), view_settings = { attributes : { 'data-open_view' : 'saved_templates', 'data-parent_cid' : parent_cid }, view : this }, main_view = new ET_PageBuilder.ModalView( view_settings ); et_pb_close_all_right_click_options(); if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } $( 'body' ).append( main_view.render().el ); generate_templates_view( 'include_global', '', 'section', $( '.et-pb-saved-modules-tab' ), 'regular', 0, 'all' ); event.preventDefault(); }, expandSection : function( event ) { event.preventDefault(); var $parent = this.$el.closest('.et_pb_section'); $parent.removeClass('et_pb_collapsed'); // Add attribute to shortcode this.options.model.attributes.et_pb_collapsed = 'off'; // Carousel effect for AB Testing subject if ( ET_PageBuilder_AB_Testing.is_active() && this.model.get( 'et_pb_ab_subject' ) === 'on' ) { ET_PageBuilder_AB_Testing.subject_carousel( this.model.get( 'cid' ) ); } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'expanded', 'section' ); // Rebuild shortcodes ET_PageBuilder_App.saveAsShortcode(); }, unlockSection : function( event ) { event.preventDefault(); if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } var this_el = this, $parent = this_el.$el.closest('.et_pb_section'), request = et_pb_user_lock_permissions(), children_views; request.done( function ( response ) { if ( true === response ) { $parent.removeClass('et_pb_locked'); // Add attribute to shortcode this_el.options.model.attributes.et_pb_locked = 'off'; children_views = ET_PageBuilder_Layout.getChildrenViews( this_el.model.get('cid') ); _.each( children_views, function( view, key ) { view.$el.removeClass('et_pb_parent_locked'); view.model.set( 'et_pb_parent_locked', 'off', { silent : true } ); } ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'unlocked', 'section' ); // Rebuild shortcodes ET_PageBuilder_App.saveAsShortcode(); } else { alert( et_pb_options.locked_section_permission_alert ); } }); }, addFirstRow: function() { if ( ET_PageBuilder_App.isLoading ) { return; } var module_id = ET_PageBuilder_Layout.generateNewId(), global_parent = typeof this.model.get( 'et_pb_global_module' ) !== 'undefined' && '' !== this.model.get( 'et_pb_global_module' ) ? this.model.get( 'et_pb_global_module' ) : '', global_parent_cid = '' !== global_parent ? this.model.get( 'cid' ) : '', new_row_view; this.collection.add( [ { type : 'row', module_type : 'row', cid : module_id, parent : this.model.get( 'cid' ), view : this, et_pb_global_parent : global_parent, global_parent_cid : global_parent_cid, admin_label : et_pb_options.noun['row'] } ] ); new_row_view = ET_PageBuilder_Layout.getView( module_id ); new_row_view.displayColumnsOptions(); }, addRow : function( appendAfter ) { if ( ET_PageBuilder_App.isLoading ) { return; } var module_id = ET_PageBuilder_Layout.generateNewId(), global_parent = typeof this.model.get( 'et_pb_global_module' ) !== 'undefined' && '' !== this.model.get( 'et_pb_global_module' ) ? this.model.get( 'et_pb_global_module' ) : '', global_parent_cid = '' !== global_parent ? this.model.get( 'cid' ) : '', new_row_view; this.collection.add( [ { type : 'row', module_type : 'row', cid : module_id, parent : this.model.get( 'cid' ), view : this, appendAfter : appendAfter, et_pb_global_parent : global_parent, global_parent_cid : global_parent_cid, admin_label : et_pb_options.noun['row'] } ] ); new_row_view = ET_PageBuilder_Layout.getView( module_id ); new_row_view.displayColumnsOptions(); }, cloneSection : function( event ) { event.preventDefault(); if ( this.isSectionLocked() ) { return; } if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'section' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } if ( ET_PageBuilder_AB_Testing.has_goal( this.model ) && ! ET_PageBuilder_AB_Testing.is_subject( this.model ) ) { ET_PageBuilder_AB_Testing.alert( 'cannot_clone_section_has_goal' ); return; } } var $cloned_element = this.$el.clone(), content, clone_section, view_settings = { model : this.model, view : this.$el, view_event : event }; clone_section = new ET_PageBuilder.RightClickOptionsView( view_settings, true ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'cloned', 'section' ); clone_section.copy( event ); clone_section.pasteAfter( event ); }, makeRowsSortable : function() { var this_el = this, sortable_el = this_el.model.get( 'et_pb_fullwidth' ) !== 'on' ? '.et-pb-section-content' : '.et_pb_fullwidth_sortable_area', connectWith = ':not(.et_pb_locked) > ' + sortable_el; if ( this_el.model.get( 'et_pb_specialty' ) === 'on' ) { return; } // AB Testing adjustment if ( ET_PageBuilder_AB_Testing.is_active() ) { // Disable sortable of AB Testing item for user with no ab_testing permission if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'section' ) ) { return; } } this_el.$el.find( sortable_el ).sortable( { connectWith: connectWith, delay: 100, cancel : '.et-pb-settings, .et-pb-clone, .et-pb-remove, .et-pb-row-add, .et-pb-insert-module, .et-pb-insert-column, .et-pb-insert-row, .et_pb_locked, .et-pb-disable-sort', update : function( event, ui ) { var $sortable_el = this_el.$el.find( sortable_el ); // Loading process occurs. Dragging is temporarily disabled if ( ET_PageBuilder_App.isLoading ) { $sortable_el.sortable('cancel'); return; } // AB Testing adjustment if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for permission user first if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( $( ui.item ).children('.et-pb-row-content').attr( 'data-cid' ), 'row' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); $sortable_el.sortable('cancel'); et_reinitialize_builder_layout(); return; } else { // User has proper permission. Verify whether the action is permissible or not // IMPORTANT: update event is fired twice, once when the module is moved from its origin and once when the // module is landed on its destination. This causes two different way in deciding $sender and $target var $item = $( ui.item ), $sender = _.isEmpty( $( ui.sender ) ) ? $( event.target ).parents('.et_pb_section') : $( ui.sender ).parents('.et_pb_section'), $target = _.isEmpty( $( ui.sender ) ) ? $( event.toElement ).parents('.et_pb_section') : $( event.target ).parents('.et_pb_section'), is_subject = $item.hasClass('et_pb_ab_subject'), is_goal = $item.hasClass('et_pb_ab_goal'), has_subject = $item.find('.et_pb_ab_subject').length, has_goal = $item.find('.et_pb_ab_goal').length, is_sender_inside_subject = $sender.closest('.et_pb_ab_subject').length, is_target_inside_subject = $target.closest('.et_pb_ab_subject').length, is_target_inside_goal = $target.closest('.et_pb_ab_goal').length; // Row is goal, being moved to subject-section if ( is_goal && ! is_subject && is_target_inside_subject ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_goal_into_subject'); $sortable_el.sortable('cancel'); et_reinitialize_builder_layout(); return; } // Row has goal, being moved to subject-section if ( has_goal && is_target_inside_subject ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_goal_into_subject' ); $sortable_el.sortable('cancel'); et_reinitialize_builder_layout(); return; } // Row is subject, being moved to goal-section if ( is_subject && ! is_goal && is_target_inside_goal ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_subject_into_goal'); $sortable_el.sortable('cancel'); et_reinitialize_builder_layout(); return; } // Row has subject, being moved to goal-section if ( has_subject && is_target_inside_goal ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_subject_into_goal'); $sortable_el.sortable('cancel'); et_reinitialize_builder_layout(); return; } // Row is a goal inside subject, being moved to anywhere if ( is_goal && is_sender_inside_subject ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_row_goal_out_from_subject'); $sortable_el.sortable('cancel'); et_reinitialize_builder_layout(); } } } if ( ! $( ui.item ).closest( event.target ).length ) { // don't allow to move the row to another section if the section has only one row if ( ! $( event.target ).find( '.et_pb_row' ).length ) { $(this).sortable( 'cancel' ); alert( et_pb_options.section_only_row_dragged_away ); } // do not allow to drag rows into sections where sorting is disabled if ( $( ui.item ).closest( '.et-pb-disable-sort').length ) { $( event.target ).sortable( 'cancel' ); } // makes sure the code runs one time, if row is dragged into another section return; } var module_cid = $( ui.item ).find( '.et-pb-row-content' ).data( 'cid' ); var model = this_el.collection.find( function( model ) { return model.get('cid') == module_cid; } ); if ( $( ui.item ).closest( '.et_pb_section.et_pb_global' ).length && $( ui.item ).hasClass( 'et_pb_global' ) ) { $( ui.sender ).sortable( 'cancel' ); alert( et_pb_options.global_row_alert ); } else if ( ( $( ui.item ).closest( '.et_pb_section.et_pb_global' ).length || $( ui.sender ).closest( '.et_pb_section.et_pb_global' ).length ) && '' === et_pb_options.template_post_id ) { var global_module_cid, $moving_from, $moving_to; $moving_from = $( ui.sender ).closest( '.et_pb_section.et_pb_global' ); $moving_to = $( ui.item ).closest( '.et_pb_section.et_pb_global' ); if ( $moving_from === $moving_to ) { global_module_cid = model.get( 'global_parent_cid' ); et_pb_update_global_template( global_module_cid ); et_reinitialize_builder_layout(); } else { var $global_element = $moving_from; // remove global parent attributes if moved not to global parent. if ( $moving_to.length === 0 && ( ( ! _.isUndefined( model.get( 'et_pb_global_parent' ) ) && '' !== model.get( 'et_pb_global_parent' ) ) || ! _.isUndefined( model.get( 'global_parent_cid' ) ) ) ) { model.unset( 'et_pb_global_parent' ); model.unset( 'global_parent_cid' ); // remove global attributes from all the child components ET_PageBuilder_Layout.removeGlobalAttributes( ET_PageBuilder_Layout.getView( model.get( 'cid' ) ) ); } for ( var i = 1; i <= 2; i++ ) { global_module_cid = $global_element.find( '.et-pb-section-content' ).data( 'cid' ); if ( typeof global_module_cid !== 'undefined' && '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); et_reinitialize_builder_layout(); } $global_element = $moving_to; } } } ET_PageBuilder_Layout.setNewParentID( ui.item.find( '.et-pb-row-content' ).data( 'cid' ), this_el.model.attributes.cid ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'moved', 'row' ); ET_PageBuilder_Events.trigger( 'et-sortable:update' ); // Prepare collection sorting based on layout position var section_cid = parseInt( $(this).attr( 'data-cid') ), sibling_row_index = 0; // Loop row block based on DOM position to ensure its index order $(this).find('.et-pb-row-content').each(function(){ sibling_row_index++; var sibling_row_cid = parseInt( $(this).data('cid') ), layout_index = section_cid + sibling_row_index, sibling_model = ET_PageBuilder_Modules.findWhere({ cid : sibling_row_cid }); // Set layout_index sibling_model.set({ layout_index : layout_index }); }); // Sort collection based on layout_index ET_PageBuilder_Modules.comparator = 'layout_index'; ET_PageBuilder_Modules.sort(); }, start : function( event, ui ) { et_pb_close_all_right_click_options(); // copy row if Alt key pressed if ( event.altKey ) { var movedRow = ET_PageBuilder_Layout.getView( $( ui.item ).children('.et-pb-row-content').data( 'cid' ) ); var view_settings = { model : movedRow.model, view : movedRow.$el, view_event : event }; var clone_row = new ET_PageBuilder.RightClickOptionsView( view_settings, true ); clone_row.copy( event, true ); clone_row.pasteAfter( event, undefined, undefined, undefined, true, true ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'cloned', 'row' ); } } } ); }, addChildView : function( view ) { this.child_views.push( view ); }, removeChildViews : function() { var child_views = ET_PageBuilder_Layout.getChildViews( this.model.attributes.cid ); _.each( child_views, function( view ) { if ( typeof view.model !== 'undefined' ) view.model.destroy(); view.remove(); } ); }, removeSection : function( event, remove_all ) { var rows, remove_last_specialty_section = false; if ( event ) event.preventDefault(); if ( this.isSectionLocked() || ET_PageBuilder_Layout.isChildrenLocked( this.model.get( 'cid' ) ) ) { return; } if ( ET_PageBuilder_App.isLoading && _.isUndefined( remove_all ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() && _.isUndefined( remove_all ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'section' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } if ( ET_PageBuilder_AB_Testing.is_unremovable_subject( this.model ) && _.isUndefined( remove_all ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { return; } if ( ET_PageBuilder_AB_Testing.has_goal( this.model ) && ! ET_PageBuilder_AB_Testing.is_subject( this.model ) && _.isUndefined( remove_all ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { ET_PageBuilder_AB_Testing.alert( 'cannot_remove_section_has_goal' ); return; } if ( ET_PageBuilder_AB_Testing.has_unremovable_subject( this.model ) && _.isUndefined( remove_all ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { ET_PageBuilder_AB_Testing.alert( 'cannot_remove_section_has_unremovable_subject' ); return; } } if ( this.model.get( 'et_pb_fullwidth' ) === 'on' ) { this.removeChildViews(); } else { rows = ET_PageBuilder_Layout.getChildViews( this.model.get('cid') ); _.each( rows, function( row ) { if ( row.model.get( 'type' ) === 'column' ) { // remove column in specialty section row.removeColumn(); } else { row.removeRow( false, true ); } } ); } // the only section left is specialty or fullwidth section if ( ! ET_PageBuilder_Layout.get( 'forceRemove' ) && ( this.model.get( 'et_pb_specialty' ) === 'on' || this.model.get( 'et_pb_fullwidth' ) === 'on' ) && ET_PageBuilder_Layout.getNumberOfModules( 'section' ) === 1 ) { remove_last_specialty_section = true; } // if there is only one section, don't remove it // allow to remove all sections if removeSection function is called directly // remove the specialty section even if it's the last one on the page if ( ET_PageBuilder_Layout.get( 'forceRemove' ) || remove_last_specialty_section || ET_PageBuilder_Layout.getNumberOfModules( 'section' ) > 1 ) { this.model.destroy(); ET_PageBuilder_Layout.removeView( this.model.get('cid') ); this.remove(); } // start with the clean layout if the user removed the last specialty section on the page if ( remove_last_specialty_section ) { ET_PageBuilder_App.removeAllSections( true ); return; } // Enable history saving and set meta for history if ( _.isUndefined( remove_all ) ) { ET_PageBuilder_App.allowHistorySaving( 'removed', 'section' ); } else { ET_PageBuilder_App.allowHistorySaving( 'cleared', 'layout' ); } // trigger remove event if the row was removed manually ( using a button ) if ( event ) { ET_PageBuilder_Events.trigger( 'et-module:removed' ); } // Run AB Testing updater ET_PageBuilder_AB_Testing.update(); }, isSectionLocked : function() { if ( 'on' === this.model.get( 'et_pb_locked' ) ) { return true; } return false; }, showRightClickOptions : function( event ) { event.preventDefault(); var et_right_click_options_view, view_settings = { model : this.model, view : this.$el, view_event : event }; et_right_click_options_view = new ET_PageBuilder.RightClickOptionsView( view_settings ); }, hideRightClickOptions : function( event ) { event.preventDefault(); et_pb_close_all_right_click_options(); }, renameModule : function() { this.$( '.et-pb-section-title' ).html( this.model.get( 'admin_label' ) ); }, toggleDisabledClass : function() { if ( typeof this.model.get( 'et_pb_disabled' ) !== 'undefined' && 'on' === this.model.get( 'et_pb_disabled' ) ) { this.$el.addClass( 'et_pb_disabled' ); } else { this.$el.removeClass( 'et_pb_disabled' ); } }, setABTesting : function ( event ) { event.preventDefault(); event.stopPropagation(); ET_PageBuilder_AB_Testing.set( this, event ); } } ); ET_PageBuilder.RowView = window.wp.Backbone.View.extend( { className : 'et_pb_row', template : _.template( $('#et-builder-row-template').html() ), events : { 'click .et-pb-settings-row' : 'showSettings', 'click .et-pb-insert-column' : 'displayColumnsOptions', 'click .et-pb-clone-row' : 'cloneRow', 'click .et-pb-row-add' : 'addNewRow', 'click .et-pb-remove-row' : 'removeRow', 'click .et-pb-change-structure' : 'changeStructure', 'click .et-pb-expand' : 'expandRow', 'contextmenu .et-pb-row-add' : 'showRightClickOptions', 'click.et_pb_row > .et-pb-controls .et-pb-unlock' : 'unlockRow', 'contextmenu.et_pb_row > .et-pb-controls' : 'showRightClickOptions', 'contextmenu.et_pb_row > .et-pb-right-click-trigger-overlay' : 'showRightClickOptions', 'contextmenu .et-pb-column' : 'showRightClickOptions', 'click.et_pb_row > .et-pb-controls' : 'hideRightClickOptions', 'click.et_pb_row > .et-pb-right-click-trigger-overlay' : 'hideRightClickOptions', 'click > .et-pb-locked-overlay' : 'showRightClickOptions', 'contextmenu > .et-pb-locked-overlay' : 'showRightClickOptions', 'click' : 'setABTesting', }, initialize : function() { this.listenTo( ET_PageBuilder_Events, 'et-add:columns', this.toggleInsertColumnButton ); this.listenTo( this.model, 'change:admin_label', this.renameModule ); this.listenTo( this.model, 'change:et_pb_disabled', this.toggleDisabledClass ); }, render : function() { var parent_views = ET_PageBuilder_Layout.getParentViews( this.model.get( 'parent' ) ); if ( typeof this.model.get( 'view' ) !== 'undefined' && typeof this.model.get( 'view' ).model.get( 'layout_specialty' ) !== 'undefined' ) { this.model.set( 'specialty_row', '1', { silent : true } ); } this.$el.html( this.template( this.model.toJSON() ) ); if ( typeof this.model.get( 'et_pb_global_module' ) !== 'undefined' || ( typeof this.model.get( 'et_pb_template_type' ) !== 'undefined' && 'row' === this.model.get( 'et_pb_template_type' ) && 'global' === et_pb_options.is_global_template ) ) { this.$el.addClass( 'et_pb_global' ); } if ( typeof this.model.get( 'et_pb_disabled' ) !== 'undefined' && this.model.get( 'et_pb_disabled' ) === 'on' ) { this.$el.addClass( 'et_pb_disabled' ); } if ( typeof this.model.get( 'et_pb_locked' ) !== 'undefined' && this.model.get( 'et_pb_locked' ) === 'on' ) { this.$el.addClass( 'et_pb_locked' ); _.each( parent_views, function( parent ) { parent.$el.addClass( 'et_pb_children_locked' ); } ); } if ( typeof this.model.get( 'et_pb_parent_locked' ) !== 'undefined' && this.model.get( 'et_pb_parent_locked' ) === 'on' ) { this.$el.addClass( 'et_pb_parent_locked' ); } if ( typeof this.model.get( 'et_pb_collapsed' ) !== 'undefined' && this.model.get( 'et_pb_collapsed' ) === 'on' ) { this.$el.addClass( 'et_pb_collapsed' ); } if ( typeof this.model.get( 'pasted_module' ) !== 'undefined' && this.model.get( 'pasted_module' ) ) { et_pb_handle_clone_class( this.$el ); } if ( ET_PageBuilder_Layout.is_temp_global( this.model ) ) { this.$el.addClass( 'et_pb_global_temp' ); } // AB Testing related class if ( ET_PageBuilder_AB_Testing.is_active() ) { if ( ET_PageBuilder_AB_Testing.is_subject( this.model ) ) { this.$el.addClass( 'et_pb_ab_subject' ); // Apply subject rank coloring ET_PageBuilder_AB_Testing.set_subject_rank_coloring( this ); } if ( ET_PageBuilder_AB_Testing.is_goal( this.model ) ) { this.$el.addClass( 'et_pb_ab_goal' ); } if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'row' ) ) { this.$el.addClass( 'et_pb_ab_no_permission' ); } } return this; }, showSettings : function( event ) { var that = this, modal_view, view_settings = { model : this.model, collection : this.collection, attributes : { 'data-open_view' : 'module_settings' }, triggered_by_right_click : this.triggered_by_right_click, do_preview : this.do_preview }; if ( typeof event !== 'undefined' ) { event.preventDefault(); } if ( this.isRowLocked() ) { return; } if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'row' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } } modal_view = new ET_PageBuilder.ModalView( view_settings ); et_modal_view_rendered = modal_view.render(); if ( false === et_modal_view_rendered ) { et_builder_load_backbone_templates( true ); setTimeout( function() { that.showSettings(); }, 500 ); ET_PageBuilder_Events.trigger( 'et-pb-loading:started' ); return; } ET_PageBuilder_Events.trigger( 'et-pb-loading:ended' ); $('body').append( et_modal_view_rendered.el ); if ( ( typeof modal_view.model.get( 'et_pb_global_module' ) !== 'undefined' && '' !== modal_view.model.get( 'et_pb_global_module' ) ) || ( ET_PageBuilder_Layout.getView( modal_view.model.get('cid') ).$el.closest( '.et_pb_global' ).length ) || ( typeof this.model.get( 'et_pb_template_type' ) !== 'undefined' && 'row' === this.model.get( 'et_pb_template_type' ) && 'global' === et_pb_options.is_global_template ) ) { $( '.et_pb_modal_settings_container' ).addClass( 'et_pb_saved_global_modal' ); } }, displayColumnsOptions : function( event ) { if ( event ) { event.preventDefault(); } if ( this.isRowLocked() ) { return; } if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } var view, this_view = this; this.model.set( 'open_view', 'column_settings', { silent : true } ); view = new ET_PageBuilder.ModalView( { model : this.model, collection : this.collection, attributes : { 'data-open_view' : 'column_settings' }, view : this_view } ); $('body').append( view.render().el ); this.toggleInsertColumnButton(); }, changeStructure : function( event ) { event.preventDefault(); var view, this_view = this; if ( this.isRowLocked() ) { return; } if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'row' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } } this.model.set( 'change_structure', 'true', { silent : true } ); this.model.set( 'open_view', 'column_settings', { silent : true } ); ET_PageBuilder.Events = ET_PageBuilder_Events; view = new ET_PageBuilder.ModalView( { model : this.model, collection : this.collection, attributes : { 'data-open_view' : 'column_settings' }, view : this_view } ); $('body').append( view.render().el ); }, expandRow : function( event ) { event.preventDefault(); var $parent = this.$el.closest('.et_pb_row'); $parent.removeClass('et_pb_collapsed'); // Add attribute to shortcode this.options.model.attributes.et_pb_collapsed = 'off'; // Carousel effect for AB Testing subject if ( ET_PageBuilder_AB_Testing.is_active() && this.model.get( 'et_pb_ab_subject' ) === 'on' ) { ET_PageBuilder_AB_Testing.subject_carousel( this.model.get( 'cid' ) ); } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'expanded', 'row' ); // Rebuild shortcodes ET_PageBuilder_App.saveAsShortcode(); }, unlockRow : function( event ) { event.preventDefault(); if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } var this_el = this, $parent = this_el.$el.closest('.et_pb_row'), request = et_pb_user_lock_permissions(), children_views, parent_views; request.done( function ( response ) { if ( true === response ) { $parent.removeClass('et_pb_locked'); // Add attribute to shortcode this_el.options.model.attributes.et_pb_locked = 'off'; children_views = ET_PageBuilder_Layout.getChildrenViews( this_el.model.get('cid') ); _.each( children_views, function( view, key ) { view.$el.removeClass('et_pb_parent_locked'); view.model.set( 'et_pb_parent_locked', 'off', { silent : true } ); } ); parent_views = ET_PageBuilder_Layout.getParentViews( this_el.model.get('parent') ); _.each( parent_views, function( view, key ) { if ( ! ET_PageBuilder_Layout.isChildrenLocked( view.model.get( 'cid' ) ) ) { view.$el.removeClass('et_pb_children_locked'); } } ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'unlocked', 'row' ); // Rebuild shortcodes ET_PageBuilder_App.saveAsShortcode(); } else { alert( et_pb_options.locked_row_permission_alert ); } }); }, toggleInsertColumnButton : function() { // Manually added row inner (ie empty specialty section's specialty column) has no model if (typeof this.model === 'undefined') { return; } var model_id = this.model.get( 'cid' ), columnsInRow; // check if the current row has at least one column columnsInRow = this.collection.find( function( model ) { return ( model.get( 'type' ) === 'column' || model.get( 'type' ) === 'column_inner' ) && model.get( 'parent' ) === model_id; } ); if ( ! _.isUndefined( columnsInRow ) ) { this.$( '.et-pb-insert-column' ).hide(); // show "change columns structure" icon, if current row's column layout is set this.$( '.et-pb-change-structure' ).show(); } }, addNewRow : function( event ) { var $parent_section = this.$el.closest( '.et-pb-section-content' ), $current_target = $( event.currentTarget ), parent_view_cid = $current_target.closest( '.et-pb-column-specialty' ).length ? $current_target.closest( '.et-pb-column-specialty' ).data( 'cid' ) : $parent_section.data( 'cid' ), parent_view = ET_PageBuilder_Layout.getView( parent_view_cid ), global_module_cid = ''; event.preventDefault(); if ( ET_PageBuilder_App.isLoading ) { return; } et_pb_close_all_right_click_options(); if ( 'on' === this.model.get( 'et_pb_parent_locked' ) ) { return; } if ( this.$el.closest( '.et_pb_section.et_pb_global' ).length && typeof parent_view.model.get( 'et_pb_template_type' ) === 'undefined' ) { global_module_cid = et_pb_get_global_parent_cid( this ); } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'add_row' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'added', 'row' ); parent_view.addRow( this.$el ); if ( '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); } }, cloneRow : function( event ) { var global_module_cid = '', parent_view = ET_PageBuilder_Layout.getView( this.model.get( 'parent' ) ), clone_row, view_settings = { model : this.model, view : this.$el, view_event : event }; event.preventDefault(); if ( this.isRowLocked() ) { return; } if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ) ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } // Row with goal (unless the row is subject) cannot be cloned if ( ET_PageBuilder_AB_Testing.has_goal( this.model ) && ! ET_PageBuilder_AB_Testing.is_subject( this.model ) ) { ET_PageBuilder_AB_Testing.alert( 'cannot_clone_row_has_goal' ); return; } } if ( this.$el.closest( '.et_pb_section.et_pb_global' ).length && typeof parent_view.model.get( 'et_pb_template_type' ) === 'undefined' ) { global_module_cid = et_pb_get_global_parent_cid( this ); } clone_row = new ET_PageBuilder.RightClickOptionsView( view_settings, true ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'cloned', 'row' ); clone_row.copy( event ); clone_row.pasteAfter( event ); if ( '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); } }, removeRow : function( event, force ) { var columns, global_module_cid = '', parent_view = ET_PageBuilder_Layout.getView( this.model.get( 'parent' ) ); if ( this.isRowLocked() || ET_PageBuilder_Layout.isChildrenLocked( this.model.get( 'cid' ) ) ) { return; } if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() && _.isUndefined( force ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ) ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } if ( ET_PageBuilder_AB_Testing.is_unremovable_subject( this.model ) && _.isUndefined( force ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { return; } if ( ET_PageBuilder_AB_Testing.has_goal( this.model ) && ! ET_PageBuilder_AB_Testing.is_subject( this.model ) && _.isUndefined( force ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { ET_PageBuilder_AB_Testing.alert( 'cannot_remove_row_has_goal' ); return; } if ( ET_PageBuilder_AB_Testing.has_unremovable_subject( this.model ) && _.isUndefined( force ) && ! ET_PageBuilder_Layout.get( 'forceRemove' ) ) { ET_PageBuilder_AB_Testing.alert( 'cannot_remove_row_has_unremovable_subject' ); return; } } if ( event ) { event.preventDefault(); // don't allow to remove a specialty section, even if there is only one row in it if ( this.$el.closest( '.et-pb-column-specialty' ).length ) { event.stopPropagation(); } if ( this.$el.closest( '.et_pb_section.et_pb_global' ).length && typeof parent_view.model.get( 'et_pb_template_type' ) === 'undefined' ) { global_module_cid = et_pb_get_global_parent_cid( this ); } } columns = ET_PageBuilder_Layout.getChildViews( this.model.get('cid') ); _.each( columns, function( column ) { column.removeColumn(); } ); // if there is only one row in the section, don't remove it if ( ET_PageBuilder_Layout.get( 'forceRemove' ) || ET_PageBuilder_Layout.getNumberOf( 'row', this.model.get('parent') ) > 1 ) { this.model.destroy(); ET_PageBuilder_Layout.removeView( this.model.get('cid') ); this.remove(); } else { this.$( '.et-pb-insert-column' ).show(); // hide "change columns structure" icon, column layout can be re-applied using "Insert column(s)" button this.$( '.et-pb-change-structure' ).hide(); } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'removed', 'row' ); // trigger remove event if the row was removed manually ( using a button ) if ( event ) { ET_PageBuilder_Events.trigger( 'et-module:removed' ); } if ( '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); } // Run AB Testing updater ET_PageBuilder_AB_Testing.update(); }, isRowLocked : function() { if ( 'on' === this.model.get( 'et_pb_locked' ) || 'on' === this.model.get( 'et_pb_parent_locked' ) ) { return true; } return false; }, showRightClickOptions : function( event ) { event.preventDefault(); var $event_target = $( event.target ), et_right_click_options_view, view_settings; // Do nothing if Module or "Insert Module" clicked if ( $event_target.closest( '.et-pb-insert-module' ).length || $event_target.closest('.et-pb-insert-row').length || $event_target.hasClass( 'et_pb_module_block' ) || $event_target.closest( '.et_pb_module_block' ).length ) { return; } et_right_click_options_view, view_settings = { model : this.model, view : this.$el, view_event : event }; et_right_click_options_view = new ET_PageBuilder.RightClickOptionsView( view_settings ); }, hideRightClickOptions : function( event ) { event.preventDefault(); et_pb_close_all_right_click_options(); }, renameModule : function() { this.$( '.et-pb-row-title' ).html( this.model.get( 'admin_label' ) ); }, toggleDisabledClass : function() { if ( typeof this.model.get( 'et_pb_disabled' ) !== 'undefined' && 'on' === this.model.get( 'et_pb_disabled' ) ) { this.$el.addClass( 'et_pb_disabled' ); } else { this.$el.removeClass( 'et_pb_disabled' ); } }, setABTesting : function ( event ) { event.preventDefault(); event.stopPropagation(); ET_PageBuilder_AB_Testing.set( this, event ); } } ); ET_PageBuilder.ModalView = window.wp.Backbone.View.extend( { className : 'et_pb_modal_settings_container', template : _.template( $('#et-builder-modal-template').html() ), events : { 'click .et-pb-modal-save' : 'saveSettings', 'click .et-pb-modal-preview-template' : 'preview', 'click .et-pb-preview-mobile' : 'resizePreviewScreen', 'click .et-pb-preview-tablet' : 'resizePreviewScreen', 'click .et-pb-preview-desktop' : 'resizePreviewScreen', 'click .et-pb-modal-close' : 'closeModal', 'click .et-pb-modal-save-template' : 'saveTemplate', 'change #et_pb_select_category' : 'applyFilter' }, initialize : function( attributes ) { this.listenTo( ET_PageBuilder_Events, 'et-add:columns', this.removeView ); // listen to module settings box that is created after the user selects new module to add this.listenTo( ET_PageBuilder_Events, 'et-new_module:show_settings', this.removeView ); this.listenTo( ET_PageBuilder_Events, 'et-saved_layout:loaded', this.removeView ); this.options = attributes; }, render : function() { var view, view_settings = { model : this.model, collection : this.collection, view : this.options.view }, fake_value = false; this.$el.attr( 'tabindex', 0 ); // set tabindex to make the div focusable // update the row view if it has been dragged into another column if ( typeof this.model !== 'undefined' && typeof this.model.get( 'view' ) !== 'undefined' && ( this.model.get( 'module_type' ) === 'row_inner' || this.model.get( 'module_type' ) === 'row' ) && this.model.get( 'parent' ) !== this.model.get( 'view' ).$el.data( 'cid' ) ) { this.model.set( 'view', ET_PageBuilder_Layout.getView( this.model.get( 'parent' ) ), { silent : true } ); } if ( this.attributes['data-open_view'] === 'all_modules' && this.model.get( 'module_type' ) === 'section' && this.model.get( 'et_pb_fullwidth' ) === 'on' ) { this.model.set( 'type', 'column', { silent : true } ); fake_value = true; } if ( typeof this.model !== 'undefined' ) { var this_parent_view = ET_PageBuilder_Layout.getView( this.model.get( 'parent' ) ); if ( this.attributes['data-open_view'] === 'column_specialty_settings' ) { this.model.set( 'open_view', 'column_specialty_settings', { silent : true } ); } this.$el.html( this.template( this.model.toJSON() ) ); if ( this.attributes['data-open_view'] === 'column_specialty_settings' ) { this.model.unset( 'open_view', 'column_specialty_settings', { silent : true } ); } } else this.$el.html( this.template() ); if ( fake_value ) this.model.set( 'type', 'section', { silent : true } ); this.container = this.$('.et-pb-modal-container'); if ( this.attributes['data-open_view'] === 'column_settings' ) { view = new ET_PageBuilder.ColumnSettingsView( view_settings ); } else if ( this.attributes['data-open_view'] === 'all_modules' ) { view_settings['attributes'] = { 'data-parent_cid' : this.model.get( 'cid' ) } view = new ET_PageBuilder.ModulesView( view_settings ); } else if ( this.attributes['data-open_view'] === 'module_settings' ) { var this_module_type = this.model.get( 'module_type' ); // check the Row parent and if it's inside the column then change the type Row to Row Inner. if ( 'row' === this_module_type && ! _.isUndefined( this_parent_view ) && 'column' === this_parent_view.model.get('type') ) { this_module_type = 'row_inner'; } view_settings['attributes'] = { 'data-module_type' : this_module_type } view_settings['view'] = this; view = new ET_PageBuilder.ModuleSettingsView( view_settings ); } else if ( this.attributes['data-open_view'] === 'save_layout' ) { view = new ET_PageBuilder.SaveLayoutSettingsView( view_settings ); } else if ( this.attributes['data-open_view'] === 'column_specialty_settings' ) { view = new ET_PageBuilder.ColumnSettingsView( view_settings ); } else if ( this.attributes['data-open_view'] === 'saved_templates' ) { view = new ET_PageBuilder.TemplatesModal( { attributes: { 'data-parent_cid' : this.attributes['data-parent_cid'] } } ); } else if ( this.attributes['data-open_view'] === 'help' ) { view = new ET_PageBuilder.HelpView(); } // do not proceed and return false if no template for this module exist yet if ( typeof view.attributes !== 'undefined' && 'no_template' === view.attributes['data-no_template'] ) { return false; } this.container.append( view.render().el ); if ( this.attributes['data-open_view'] === 'column_settings' ) { // if column settings layout was generated, remove open_view attribute from a row // the row module modal window shouldn't have this attribute attached this.model.unset( 'open_view', { silent : true } ); } // show only modules that the current element can contain if ( this.attributes['data-open_view'] === 'all_modules' ) { if ( this.model.get( 'module_type' ) === 'section' && typeof( this.model.get( 'et_pb_fullwidth' ) !== 'undefined' ) && this.model.get( 'et_pb_fullwidth' ) === 'on' ) { $( view.render().el ).find( '.et-pb-all-modules li:not(.et_pb_fullwidth_only_module)' ).remove(); } else { $( view.render().el ).find( 'li.et_pb_fullwidth_only_module' ).remove(); } } if ( $( '.et_pb_modal_overlay' ).length ) { $( '.et_pb_modal_overlay' ).remove(); $( 'body' ).removeClass( 'et_pb_stop_scroll' ); } if ( $( 'body' ).hasClass( 'et_pb_modal_fade_in' ) ) { $( 'body' ).append( '
' ); } else { $( 'body' ).append( '' ); } $( 'body' ).addClass( 'et_pb_stop_scroll' ); // Hide "Save & Add To Library" button if current module has/is goal/subject. // Divi Library should never saved module which has AB Testing attribute if ( this.isABTestingModule() ) { var $settings_container = $( view.render().el ).closest( '.et_pb_modal_settings_container' ); $settings_container.addClass( 'has_ab_testing_module' ); $settings_container.find( '.et-pb-modal-save-template' ).remove(); } return this; }, closeModal : function( event ) { event.preventDefault(); if ( $( '.et_modal_on_top' ).length ) { $( '.et_modal_on_top' ).remove(); } else { if ( typeof this.model !== 'undefined' && this.model.get( 'type' ) === 'module' && this.$( '#et_pb_content_new' ).length ) et_pb_tinymce_remove_control( 'et_pb_content_new' ); et_pb_hide_active_color_picker( this ); et_pb_close_modal_view( this, 'trigger_event' ); } }, removeView : function() { if ( typeof this.model === 'undefined' || ( this.model.get( 'type' ) === 'row' || this.model.get( 'type' ) === 'column' || this.model.get( 'type' ) === 'row_inner' || this.model.get( 'type' ) === 'column_inner' || ( this.model.get( 'type' ) === 'section' && ( this.model.get( 'et_pb_fullwidth' ) === 'on' || this.model.get( 'et_pb_specialty' ) === 'on' ) ) ) ) { if ( typeof this.model !== 'undefined' && typeof this.model.get( 'type' ) !== 'undefined' && ( this.model.get( 'type' ) === 'column' || this.model.get( 'type' ) === 'column_inner' || ( this.model.get( 'type' ) === 'section' && this.model.get( 'et_pb_fullwidth' ) === 'on' ) ) ) { var that = this, $opened_tab = $( that.el ).find( '.et-pb-main-settings.active-container' ); // if we're adding module from library, then close everything. Otherwise leave overlay in place and add specific classes if ( $opened_tab.hasClass( 'et-pb-saved-modules-tab' ) ) { et_pb_close_modal_view( that ); } else { that.remove(); $( 'body' ).addClass( 'et_pb_modal_fade_in' ); $( '.et_pb_modal_overlay' ).addClass( 'et_pb_no_animation' ); setTimeout( function() { $( '.et_pb_modal_settings_container' ).addClass( 'et_pb_no_animation' ); $( 'body' ).removeClass( 'et_pb_modal_fade_in' ); }, 500); } } else { et_pb_close_modal_view( this ); } } else { this.removeOverlay(); } }, saveSettings : function( event, close_modal ) { var that = this, global_module_cid = '', this_view = ET_PageBuilder_Layout.getView( that.model.get( 'cid' ) ), this_parent_view = ! _.isUndefined( that.model.get( 'parent' ) ) ? ET_PageBuilder_Layout.getView( that.model.get( 'parent' ) ) : '', global_holder_view = this_view, update_template_only = false, close_modal = _.isUndefined( close_modal ) ? true : close_modal, is_disabled = 'not-allowed' === $( event.target ).css( 'cursor' ); // get the global module ID if exists. if ( ! _.isUndefined( global_holder_view.model.get( 'et_pb_global_module' ) ) ) { // if the module is global global_module_cid = global_holder_view.model.get( 'cid' ); } else { // check all parents to find the global parent if exists while ( ! _.isUndefined( global_holder_view.model.get( 'parent' ) ) && '' === global_module_cid ) { // Refresh global holder for new loop global_holder_view = ET_PageBuilder_Layout.getView( global_holder_view.model.get( 'parent' ) ); global_module_cid = '' === global_module_cid && ! _.isUndefined( global_holder_view.model.get( 'et_pb_global_module' ) ) ? global_holder_view.model.get( 'cid' ) : global_module_cid; } } event.preventDefault(); if ( is_disabled ) { return; } // Disabling state and mark it. It takes a while for generating shortcode, // so ensure that user doesn't update the page before shortcode generation has completed $('#publish').addClass( 'disabled' ); ET_PageBuilder_App.disable_publish = true; if ( ( typeof global_holder_view.model.get( 'global_parent_cid' ) !== 'undefined' && '' !== global_holder_view.model.get( 'global_parent_cid' ) ) || ( typeof global_holder_view.model.get( 'et_pb_global_module' ) !== 'undefined' && '' !== global_holder_view.model.get( 'et_pb_global_module' ) ) ) { global_module_cid = typeof global_holder_view.model.get( 'global_parent_cid' ) !== 'undefined' ? global_holder_view.model.get( 'global_parent_cid' ) : global_holder_view.model.get( 'cid' ); } that.performSaving(); if ( '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'edited', that.model.get( 'type' ), that.model.get( 'admin_label' ) ); // In some contexts, closing modal view isn't needed & only settings saving needed if ( ! close_modal ) { return; } et_pb_tinymce_remove_control( 'et_pb_content_new' ); et_pb_hide_active_color_picker( that ); et_pb_close_modal_view( that, 'trigger_event' ); if ( ET_PageBuilder_AB_Testing.is_active() ) { // Update subject rank coloring and subject ID ET_PageBuilder_AB_Testing.set_subject_rank_coloring( this_view ); } }, preview : function( event ) { var cid = this.model.get( 'cid' ) , shortcode, $button = $( event.target ).is( 'a' ) ? $( event.target ) : $( event.target ).parent( 'a' ), $container = $( event.target ).parents( '.et-pb-modal-container' ), request_data, section_view, msie = document.documentMode; event.preventDefault(); // Save modified settings, if it is necesarry. Direct preview from right click doesn't need to be saved if ( _.isUndefined( this.options.triggered_by_right_click ) ) { this.saveSettings( event, false ); } else { // Triggered by right click is one time thing. Remove it as soon as it has been used delete this.options.triggered_by_right_click; } if ( ! _.isUndefined( this.options.do_preview ) ) { // Do preview is one time thing. Remove it as soon as it has been used delete this.options.do_preview; } if ( et_pb_options.is_divi_library === "1" && $.inArray( et_pb_options.layout_type, [ "row", "module" ] ) > -1 ) { // Divi Library's layout editor auto generates section and row in module and row layout type // The auto generates item cause cause an issue during shortcode generation // Removing its cid will force ET_PageBuilder_App.generateCompleteShortcode to generate the whole page's layout shortcode which solves the preview issue cid = undefined; } else if ( this.model.get( 'type' ) !== 'section' ) { // Module's layout depends on the column it belongs. Hence, always preview the item in context of section section_view = ET_PageBuilder_Layout.getSectionView( this.model.get( 'parent' ) ); if ( ! _.isUndefined( section_view ) ) { cid = section_view.model.attributes.cid; } } // Get shortcode based on section's cid shortcode = ET_PageBuilder_App.generateCompleteShortcode( cid ); request_data = { et_pb_preview_nonce : et_pb_options.et_pb_preview_nonce, shortcode : shortcode, post_title : $('#title').val() }; // Toggle button state $button.toggleClass( 'active' ); // Toggle container state $container.toggleClass( 'et-pb-item-previewing' ); if ( $button.hasClass( 'active' ) ) { // Create the iFrame on the fly. This will speed up modalView init var $iframe = $('', { id : 'et-pb-preview-screen', src : et_pb_options.preview_url + '&et_pb_preview_nonce=' + et_pb_options.et_pb_preview_nonce } ), has_render_page = false; // Add the iframe into preview tab $('.et-pb-preview-tab' ).html( $iframe ); // Pass the item's setup to the screen $('#et-pb-preview-screen').load( function(){ if ( has_render_page ) { return; } // Get iFrame preview = document.getElementById( 'et-pb-preview-screen' ); // IE9 below fix. They have postMessage, but it has to be in string if ( ! _.isUndefined( msie ) && msie < 10 ) { request_data = JSON.stringify( request_data ); } // Pass shortcode structure to iFrame to be displayed preview.contentWindow.postMessage( request_data, et_pb_options.preview_url ); has_render_page = true; }); } else { $( '.et-pb-preview-tab' ).empty(); // Reset active state $('.et-pb-preview-screensize-switcher a').removeClass( 'active' ); // Set desktop as active $('.et-pb-preview-desktop').addClass( 'active' ); } }, resizePreviewScreen : function( event ) { event.preventDefault(); var $link = $( event.target ), width = _.isUndefined( $link.data( 'width' ) ) ? '100%' : $link.data( 'width' ); // Reset active state $('.et-pb-preview-screensize-switcher a').removeClass( 'active' ); // Set current as active $link.addClass( 'active' ); // Set iFrame width $('#et-pb-preview-screen').animate({ 'width' : width }); }, getAttr: function( object, name ) { return _.isUndefined( object[ name ] ) ? '' : object[ name ]; }, performSaving : function( option_tabs_selector ) { var thisClass = this; var attributes = {}; var unsetAttrs = []; var defaults = {}; var options_selector = typeof option_tabs_selector !== 'undefined' && '' !== option_tabs_selector ? option_tabs_selector : 'input, select, textarea, #et_pb_content_main'; var shortcode_name = thisClass.model.get( 'module_type' ); var $et_form_validation; shortcode_name = shortcode_name.indexOf( 'et_pb_' ) === -1 ? ( 'et_pb_' + shortcode_name ) : shortcode_name; $et_form_validation = $(this)[0].$el.find('form.validate'); if ( $et_form_validation.length ) { validator = $et_form_validation.validate(); if ( !validator.form() ) { et_builder_debug_message('failed form validation'); et_builder_debug_message('failed elements: '); et_builder_debug_message( validator.errorList ); validator.focusInvalid(); return; } et_builder_debug_message('passed form validation'); } var global_module_id = 'global' === et_pb_options.is_global_template ? et_pb_options.template_post_id : this.model.get( 'et_pb_global_module' ); // update the unsynced options for the module if ( $( '.et_pb_global_sync_switcher' ).length > 0 && typeof global_module_id !== 'undefined' && '' !== global_module_id ) { var unsynced_options_array = []; if ( $( '.et_pb_global_unsynced' ).length > 0 ) { $( '.et_pb_global_unsynced' ).each( function() { var $this_el = $( this ); var this_option_name = $this_el.data( 'option_name' ); // transform 'content_new' and 'raw_content' to 'et_pb_content_field' this_option_name = _.includes( ['content_new', 'raw_content'], this_option_name ) ? 'et_pb_content_field' : this_option_name; unsynced_options_array.push( this_option_name ); // unsync mobile options if exist if ( ! _.isUndefined( $this_el.data( 'additional_options' ) ) && 'mobile' === $this_el.data( 'additional_options' ) ) { unsynced_options_array.push( this_option_name + '_tablet' ); unsynced_options_array.push( this_option_name + '_phone' ); } }); } // Automatically sync/unsync gallery_ids and gallery_orderby on gallery module if src is synced/unsynced if ( 'et_pb_gallery' === shortcode_name ) { if ( _.contains( unsynced_options_array, 'src' ) ) { unsynced_options_array = _.union( unsynced_options_array, [ 'gallery_ids', 'gallery_orderby' ] ); } else { unsynced_options_array = _.without( unsynced_options_array, 'gallery_ids', 'gallery_orderby' ); } } et_pb_all_unsynced_options[ global_module_id ] = unsynced_options_array; // update the value in hidden option so unsynced options will be saved on post Update. if ( 'global' === et_pb_options.is_global_template && $( '#et_pb_unsynced_global_attrs' ).length !== 0 ) { $( '#et_pb_unsynced_global_attrs' ).val( JSON.stringify( unsynced_options_array ) ); } } ET_PageBuilder.Events.trigger( 'et-modal-settings:save', this ); var migrations = _.isUndefined( et_pb_options.et_pb_module_settings_migrations ) ? false : et_pb_options.et_pb_module_settings_migrations; var name_changes = _.isUndefined( migrations.name_changes ) ? false : migrations.name_changes; // Delete migrated attributes to avoid unwanted value re-assignment // Their values were migrated to new attributes at this point if ( name_changes && ! _.isUndefined( name_changes[shortcode_name] ) ) { _.forEach( name_changes[shortcode_name], function( new_name, old_name ) { unsetAttrs.push( 'et_pb_' + old_name ); }); } this.$( options_selector ).each( function() { var $this_el = $(this); var default_value = et_pb_get_default_setting_value($this_el) || ''; var name = $this_el.is('#et_pb_content_main') ? 'et_pb_content_new' : $this_el.attr('id'); var isEqualToDefault = function (v1, v2) { return $this_el.hasClass('et-pb-range-input') ? _.isEqual(parseFloat(v1), parseFloat(v2)) : _.isEqual(v1, v2); }; // name attribute is used in normal html checkboxes, use it instead of ID if ( $this_el.is( ':checkbox' ) ) { name = $this_el.attr('name'); } if ( typeof name === 'undefined' || ( -1 !== name.indexOf( 'qt_' ) && 'button' === $this_el.attr( 'type' ) ) ) { // settings should have an ID and shouldn't be a Quick Tag button from the tinyMCE in order to be saved return true; } if ( $this_el.hasClass( 'et-pb-helper-field' ) ) { // don't process helper fields return true; } // All checkbox values are saved at once on the next step, so if the attribute name // already exists, do nothing if ( $this_el.is( ':checkbox' ) && typeof attributes[name] !== 'undefined' ) { return true; } // Validate colorpicker - if invalid color given, return to default color if ( $this_el.hasClass( 'et-pb-color-picker-hex' ) && new Color( $this_el.val() ).error && ! $this_el.hasClass( 'et-pb-is-cleared' ) ) { $this_el.val( $this_el.data( 'selected-value') ); } // convert default value to string to make sure current and default values have the same type default_value = default_value + ''; // if default value is set, add it to the defaults object if ( default_value !== '' ) { defaults[ name ] = default_value; } // save the attribute value var setting_value = ET_PageBuilder.Helpers.getSettingValue($this_el); if ( ! isEqualToDefault(setting_value, default_value) ) { attributes[name] = setting_value; } else { unsetAttrs.push(name); } } ); // add defaults object attributes['module_defaults'] = defaults; // remove padding_mobile based on last_edited value to remove dependency to padding_mobile and rely on responsive padding var module_attributes = this.model.attributes, module_previous_attributes = this.model._previousAttributes, module_type = module_attributes.type, custom_padding_last_edited = _.isUndefined(attributes.et_pb_custom_padding_last_edited) ? [] : attributes.et_pb_custom_padding_last_edited.split('|'), responsive_padding_active = typeof custom_padding_last_edited === 'object' && custom_padding_last_edited[0] === 'on', is_custom_padding_updated = thisClass.getAttr( attributes, 'et_pb_custom_padding' ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_custom_padding' ), is_custom_padding_tablet_updated = responsive_padding_active && thisClass.getAttr( attributes, 'et_pb_custom_padding_tablet' ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_custom_padding_tablet' ), is_custom_padding_phone_updated = responsive_padding_active && thisClass.getAttr( attributes, 'et_pb_custom_padding_phone' ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_custom_padding_phone' ), is_custom_padding_field_updated = is_custom_padding_updated || is_custom_padding_tablet_updated || is_custom_padding_phone_updated; // remove padding_mobile on section if responsive padding is active if ( module_type === 'section' && ( responsive_padding_active || is_custom_padding_field_updated ) ) { attributes.et_pb_padding_mobile = ''; } if ( module_type === 'row' || module_type === 'row_inner' ) { // remove padding_mobile on row if responsive padding is active if ( ( responsive_padding_active || is_custom_padding_field_updated ) ) { attributes.et_pb_padding_mobile = ''; } // remove column_padding var column_count = typeof module_attributes.columns_layout === 'undefined' ? 0 : module_attributes.columns_layout.split(',').length; for (var column_index = 1; column_index <= column_count; column_index++) { var column_padding_last_edited_value = attributes['et_pb_padding_' + column_index + '_last_edited'], column_padding_last_edited = typeof column_padding_last_edited_value === 'undefined' ? [] : column_padding_last_edited_value.split('|'), column_responsive_padding_active = typeof column_padding_last_edited === 'object' && column_padding_last_edited[0] === 'on', is_column_padding_top_updated = thisClass.getAttr( attributes, 'et_pb_padding_top_' + column_index ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_padding_top_' + column_index ), is_column_padding_right_updated = thisClass.getAttr( attributes, 'et_pb_padding_right_' + column_index ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_padding_right_' + column_index ), is_column_padding_bottom_updated = thisClass.getAttr( attributes, 'et_pb_padding_bottom_' + column_index ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_padding_bottom_' + column_index ), is_column_padding_left_updated = thisClass.getAttr( attributes, 'et_pb_padding_left_' + column_index ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_padding_left_' + column_index ), is_column_padding_updated = is_column_padding_top_updated || is_column_padding_right_updated || is_column_padding_bottom_updated || is_column_padding_left_updated, is_column_padding_tablet_updated = column_responsive_padding_active && thisClass.getAttr( attributes, 'et_pb_padding_' + column_index + '_tablet' ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_padding_' + column_index + '_tablet' ), is_column_padding_phone_updated = column_responsive_padding_active && thisClass.getAttr( attributes, 'et_pb_padding_' + column_index + '_phone' ) !== thisClass.getAttr( module_previous_attributes, 'et_pb_padding_' + column_index + '_phone'), is_column_padding_field_updated = is_column_padding_updated || is_column_padding_tablet_updated || is_column_padding_phone_updated; if ( column_responsive_padding_active || is_column_padding_field_updated ) { attributes.et_pb_column_padding_mobile = ''; break; } } } // set model attributes this.model.set( attributes ); unsetAttrs.map(this.model.unset.bind(this.model)); }, isABTestingModule: function() { var model = this.model; return ET_PageBuilder_AB_Testing.is_active() && (ET_PageBuilder_AB_Testing.is_subject(model) || ET_PageBuilder_AB_Testing.has_subject(model) || ET_PageBuilder_AB_Testing.is_goal(model) || ET_PageBuilder_AB_Testing.has_goal(model)); }, saveTemplate : function( event ) { var module_width = -1 !== this.model.get( 'module_type' ).indexOf( 'fullwidth' ) ? 'fullwidth' : 'regular', columns_layout = typeof this.model.get( 'columns_layout' ) !== 'undefined' ? this.model.get( 'columns_layout' ) : '0', is_disabled = 'not-allowed' === $( event.target ).css( 'cursor' ) || this.isABTestingModule(); event.preventDefault(); if ( is_disabled ) { return; } et_pb_create_prompt_modal( 'save_template', this, module_width, columns_layout ); }, removeOverlay : function() { var $overlay = $( '.et_pb_modal_overlay' ); if ( $overlay.length ) { $overlay.addClass( 'et_pb_overlay_closing' ); setTimeout( function() { $overlay.remove(); $( 'body' ).removeClass( 'et_pb_stop_scroll' ); }, 600 ); } // Check for existence of disable_publish element, don't do auto enable publish // if not necesarry. Example: opening Modal View, then close it without further action if ( ! _.isUndefined( ET_PageBuilder_App.disable_publish ) ) { var auto_enable_publishing = setTimeout( function() { // Check for disable_publish state, auto enable after three seconds // This means no et_pb_set_content triggered if ( ! _.isUndefined( ET_PageBuilder_App.disable_publish ) ) { $('#publish').removeClass( 'disabled' ); delete ET_PageBuilder_App.disable_publish; } }, 3000 ); } }, applyFilter : function(event) { var $event_target = $(event.target), all_data = $event_target.data( 'attr' ), selected_category = $event_target.val(); all_data.append_to.html( '' ); generate_templates_view( all_data.include_global, '', all_data.layout_type, all_data.append_to, all_data.module_width, all_data.specialty_cols, selected_category ); } } ); ET_PageBuilder.ColumnView = window.wp.Backbone.View.extend( { template : _.template( $('#et-builder-column-template').html() ), templateAddRow : _.template( $('#et-builder-specialty-column-template').html() ), events : { 'click .et-pb-insert-module' : 'addModule', 'click .et-pb-insert-row' : 'addModule', 'contextmenu > .et-pb-insert-module' : 'showRightClickOptions', 'click' : 'hideRightClickOptions' }, initialize : function() { this.$el.attr( 'data-cid', this.model.get( 'cid' ) ); }, render : function() { var this_el = this, is_fullwidth_section = this.model.get( 'module_type' ) === 'section' && this.model.get( 'et_pb_fullwidth' ) === 'on', connect_with = ( ! is_fullwidth_section ? ".et-pb-column:not(.et-pb-column-specialty, .et_pb_parent_locked)" : ".et_pb_fullwidth_sortable_area" ); this.$el.html( this.template( this.model.toJSON() ) ); // Specialty section's column button displays add row instead of add module if (typeof this.model.attributes.specialty_columns !== 'undefined' ) { this.$el.html( this.templateAddRow( this.model.toJSON() ) ); } if ( is_fullwidth_section ) this.$el.addClass( 'et_pb_fullwidth_sortable_area' ); if ( this.model.get( 'layout_specialty' ) === '1' ) { connect_with = '.et-pb-column-specialty:not(.et_pb_parent_locked)'; } if ( this.model.get( 'created' ) === 'manually' && ! _.isUndefined( this.model.get( 'et_pb_specialty_columns' ) ) ) { this.$el.addClass( 'et-pb-column-specialty' ); } if ( this.isColumnParentLocked( this.model.get( 'parent' ) ) ) { this.$el.addClass( 'et_pb_parent_locked' ); this.model.set( 'et_pb_parent_locked', 'on', { silent : true } ); } // AB Testing adjustment if ( ET_PageBuilder_AB_Testing.is_active() ) { // Disable sortable of AB Testing item for user with no ab_testing permission if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'column' ) ) { return this; } } this.$el.sortable( { cancel : '.et-pb-settings, .et-pb-clone, .et-pb-remove, .et-pb-insert-module, .et-pb-insert-column, .et-pb-insert-row, .et_pb_locked, .et-pb-disable-sort', connectWith: connect_with, delay: 100, items : ( this.model.get( 'layout_specialty' ) !== '1' ? '.et_pb_module_block' : '.et_pb_row' ), receive: function(event, ui) { var $this = $(this), columns_number, cancel_action = false; if ( $this.hasClass( 'et-pb-column-specialty' ) ) { // revert if the last row is being dragged out of the specialty section // or the module block is placed directly into the section // or 3-column row is placed into the row that can't handle it if ( ! $( ui.sender ).find( '.et_pb_row' ).length || $( ui.item ).is( '.et_pb_module_block' ) ) { alert( et_pb_options.section_only_row_dragged_away ); cancel_action = true; } else { columns_number = $(ui.item).find( '.et-pb-row-container > .et-pb-column' ).length; if ( columns_number === 3 && parseInt( ET_PageBuilder_Layout.getView( $this.data( 'cid' ) ).model.get( 'specialty_columns' ) ) !== 3 ) { alert( et_pb_options.stop_dropping_3_col_row ); cancel_action = true; } } } // do not allow to drag modules into sections and rows where sorting is disabled if ( $( ui.item ).closest( '.et-pb-disable-sort').length ) { cancel_action = true; } if ( ( $( ui.item ).closest( '.et_pb_section.et_pb_global' ).length || $( ui.item ).closest( '.et_pb_row.et_pb_global' ).length ) && $( ui.item ).hasClass( 'et_pb_global' ) ) { alert( et_pb_options.global_module_alert ); cancel_action = true; } if ( cancel_action ) { $(ui.sender).sortable('cancel'); et_reinitialize_builder_layout(); } // Remove insert row button if a row is pasted into specialty's column if ($this.is('.et-pb-column-specialty') && $this.find('.et_pb_row').length <= 1 && $this.find('.et-pb-insert-row').length) { $this.find('.et-pb-insert-row').remove(); } }, update : function( event, ui ) { // Loading process occurs. Dragging is temporarily disabled if ( ET_PageBuilder_App.isLoading ) { this_el.$el.sortable( 'cancel' ); return; } // AB Testing adjustment :: module as subject / goal if ( ET_PageBuilder_AB_Testing.is_active() ) { var is_row_inner = $( ui.item ).hasClass( 'et_pb_row' ), cid = is_row_inner ? $( ui.item ).children( '.et-pb-row-content' ).attr( 'data-cid' ) : $( ui.item ).attr( 'data-cid' ); // Check for permission user first if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( cid ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); this_el.$el.sortable('cancel'); et_reinitialize_builder_layout(); return; } else { // User has proper permission. Verify whether the action is permissible or not // IMPORTANT: update event is fired twice, once when the module is moved from its origin and once when the // module is landed on its destination. This causes two different way in deciding $sender and $target var $item = $( ui.item ), $sender = _.isEmpty( $( ui.sender ) ) ? $( event.target ) : $( ui.sender ), $target = _.isEmpty( $( ui.sender ) ) ? $( event.toElement ).parent() : $( event.target ), is_subject = $item.hasClass('et_pb_ab_subject'), is_goal = $item.hasClass('et_pb_ab_goal'), is_sender_inside_subject = $sender.closest('.et_pb_ab_subject').length, is_target_inside_subject = $target.closest('.et_pb_ab_subject').length, is_target_inside_goal = $target.closest('.et_pb_ab_goal').length; // Goal inside subject cannot be moved outside subject if ( is_goal && ! is_subject && is_sender_inside_subject ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_module_goal_out_from_subject' ); $( this_el.$el ).sortable('cancel'); et_reinitialize_builder_layout(); return; } // Goal outside subject cannot be moved inside subject if ( is_goal && ! is_subject && ! is_sender_inside_subject && is_target_inside_subject ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_goal_into_subject' ); $( this_el.$el ).sortable('cancel'); et_reinitialize_builder_layout(); return; } // Subject cannot be moved into goal (assuming goal is row or section) if ( is_subject && ! is_goal && is_target_inside_goal ) { ET_PageBuilder_AB_Testing.alert( 'cannot_move_subject_into_goal' ); $( this_el.$el ).sortable('cancel'); et_reinitialize_builder_layout(); return; } } } var model, $module_block, module_cid = ui.item.data( 'cid' ); $module_block = $( ui.item ); if ( typeof module_cid === 'undefined' && $(event.target).is('.et-pb-column-specialty') ) { $module_block = $( ui.item ).closest( '.et_pb_row' ).find( '.et-pb-row-content' ); module_cid = $module_block.data( 'cid' ); } // if the column doesn't have modules, add the dragged module before 'Insert Module' button or append to column if ( ! $(event.target).is('.et-pb-column-specialty') && $( ui.item ).closest( event.target ).length && $( event.target ).find( '.et_pb_module_block' ).length === 1 ) { // if .et-pb-insert-module button exists, then add the module before that button. Otherwise append to column if ( $( event.target ).find( '.et-pb-insert-module' ).length ) { $module_block.insertBefore( $( event.target ).find( '.et-pb-insert-module' ) ); } else { $( event.target ).append( $module_block ); } } model = this_el.collection.find( function( model ) { return model.get('cid') == module_cid; } ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'moved', 'module', model.get( 'admin_label' ) ); if ( model.get( 'parent' ) === this_el.model.attributes.cid && $( ui.item ).closest( event.target ).length ) { // order of items have been changed within the same row ET_PageBuilder_Events.trigger( 'et-model-changed-position-within-column' ); } else { model.set( 'parent', this_el.model.attributes.cid ); } // Prepare collection sorting based on layout position var column_cid = parseInt( $(this).attr( 'data-cid') ), sibling_module_index = 0; // Loop module block based on DOM position to ensure its index order $(this).find('.et_pb_module_block').each(function(){ sibling_module_index++; var sibling_module_cid = parseInt( $(this).data('cid') ), layout_index = column_cid + sibling_module_index, sibling_model = ET_PageBuilder_Modules.findWhere({ cid : sibling_module_cid }); // Set layout_index sibling_model.set({ layout_index : layout_index }); }); // Sort collection based on layout_index ET_PageBuilder_Modules.comparator = 'layout_index'; ET_PageBuilder_Modules.sort(); if ( ( $( ui.item ).closest( '.et_pb_section.et_pb_global' ).length || $( ui.item ).closest( '.et_pb_row.et_pb_global' ).length || $( ui.sender ).closest( '.et_pb_row.et_pb_global' ).length || $( ui.sender ).closest( '.et_pb_section.et_pb_global' ).length ) && '' === et_pb_options.template_post_id ) { var module_cid = ui.item.data( 'cid' ), $from_global_row = $( ui.sender ).closest( '.et_pb_row.et_pb_global' ), $to_global_row = $( ui.item ).closest( '.et_pb_row.et_pb_global' ), global_module_cid, $moving_from, $moving_to; $moving_from = $from_global_row.length > 0 ? $from_global_row : $( ui.sender ).closest( '.et_pb_section.et_pb_global' ); $moving_to = $to_global_row.length > 0 ? $to_global_row : $( ui.item ).closest( '.et_pb_section.et_pb_global' ); if ( $moving_from === $moving_to ) { var global_module_cid = $from_global_row.length > 0 ? $( ui.sender ).closest( '.et-pb-row-content' ).data( 'cid' ) : $( ui.sender ).closest( '.et-pb-section-content' ).data( 'cid' ); et_pb_update_global_template( global_module_cid ); et_reinitialize_builder_layout(); } else { var $global_element = $moving_from; // remove global parent attributes if moved not to global parent. if ( $moving_to.length === 0 && ( ( ! _.isUndefined( model.get( 'et_pb_global_parent' ) ) && '' !== model.get( 'et_pb_global_parent' ) ) || ! _.isUndefined( model.get( 'global_parent_cid' ) ) ) ) { model.unset( 'et_pb_global_parent' ); model.unset( 'global_parent_cid' ); // remove global attributes from all the child components ET_PageBuilder_Layout.removeGlobalAttributes( ET_PageBuilder_Layout.getView( model.get( 'cid' ) ) ); } for ( var i = 1; i <= 2; i++ ) { global_module_cid = typeof $global_element.find( '.et-pb-section-content' ).data( 'cid' ) !== 'undefined' ? $global_element.find( '.et-pb-section-content' ).data( 'cid' ) : $global_element.find( '.et-pb-row-content' ).data( 'cid' ); if ( typeof global_module_cid !== 'undefined' && '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); et_reinitialize_builder_layout(); } $global_element = $moving_to; } } } }, start : function( event, ui ) { et_pb_close_all_right_click_options(); // copy module if Alt key pressed if ( event.altKey ) { var is_row_inner = $( ui.item ).hasClass( 'et_pb_row' ); var cid = is_row_inner ? $( ui.item ).children( '.et-pb-row-content' ).attr( 'data-cid' ) : $( ui.item ).attr( 'data-cid' ); var movedModule = ET_PageBuilder_Layout.getView( cid ); var view_settings = { model : movedModule.model, view : movedModule.$el, view_event : event }; var clone_module = new ET_PageBuilder.RightClickOptionsView( view_settings, true ); clone_module.copy( event, true ); clone_module.pasteAfter( event, undefined, undefined, undefined, true, true ); // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'cloned', 'module', movedModule.model.get( 'admin_label' ) ); } } } ); return this; }, addModule : function( event ) { var $event_target = $(event.target), $add_module_button = $event_target.is( 'span' ) ? $event_target.parent('.et-pb-insert-module') : $event_target; event.preventDefault(); event.stopPropagation(); if ( this.isColumnLocked() ) return; if ( ET_PageBuilder_App.isLoading ) { return; } if ( ET_PageBuilder_AB_Testing.is_selecting() ) { return; } // AB Testing-related action if ( ET_PageBuilder_AB_Testing.is_active() ) { // Check for user permission and module status if ( ! ET_PageBuilder_AB_Testing.is_user_has_permission( this.model.get( 'cid' ), 'add_module' ) ) { ET_PageBuilder_AB_Testing.alert( 'has_no_permission' ); return; } } if ( ! $add_module_button.parent().is( event.delegateTarget ) ) { return; } et_pb_close_all_right_click_options(); if ($(event.target).is('.et-pb-insert-row')) { this.addRow(); } else { var view; view = new ET_PageBuilder.ModalView( { model : this.model, collection : this.collection, attributes : { 'data-open_view' : 'all_modules' }, view : this } ); $('body').append( view.render().el ); } }, // Add New Row functionality for the specialty section column addRow : function( appendAfter ) { var module_id = ET_PageBuilder_Layout.generateNewId(), global_parent = typeof this.model.get( 'et_pb_global_parent' ) !== 'undefined' && '' !== this.model.get( 'et_pb_global_parent' ) ? this.model.get( 'et_pb_global_parent' ) : '', global_parent_cid = '' !== global_parent ? this.model.get( 'global_parent_cid' ) : '', new_row_view; if ( ET_PageBuilder_App.isLoading ) { return; } if ( this.isColumnLocked() ) { return; } this.collection.add( [ { type : 'row', module_type : 'row', cid : module_id, parent : this.model.get( 'cid' ), view : this, appendAfter : appendAfter, et_pb_global_parent : global_parent, global_parent_cid : global_parent_cid, admin_label : et_pb_options.noun['row'] } ] ); new_row_view = ET_PageBuilder_Layout.getView( module_id ); new_row_view.displayColumnsOptions(); }, removeColumn : function() { var modules; modules = ET_PageBuilder_Layout.getChildViews( this.model.get('cid') ); _.each( modules, function( module ) { if ( module.model.get( 'type' ) === 'row' || module.model.get( 'type' ) === 'row_inner' ) { module.removeRow(); } else { module.removeModule(); } } ); ET_PageBuilder_Layout.removeView( this.model.get('cid') ); this.model.destroy(); this.remove(); }, isColumnLocked : function() { if ( 'on' === this.model.get( 'et_pb_locked' ) || 'on' === this.model.get( 'et_pb_parent_locked' ) ) { return true; } return false; }, isColumnParentLocked : function( cid ) { var parent_view = ET_PageBuilder_Layout.getView( cid ); if ( ! _.isUndefined( parent_view ) && ( 'on' === parent_view.model.get('et_pb_locked' ) || 'on' === parent_view.model.get('et_pb_parent_locked' ) ) ) { return true; } return false; }, showRightClickOptions : function( event ) { event.preventDefault(); var et_right_click_options_view, view_settings = { model : this.model, view : this.$el, view_event : event }; // Fullwidth and regular section uses different type for column ( section vs column ) // Add marker so it can be identified view_settings.model.attributes.is_insert_module = true; et_right_click_options_view = new ET_PageBuilder.RightClickOptionsView( view_settings ); return; }, hideRightClickOptions : function( event ) { event.preventDefault(); et_pb_close_all_right_click_options(); } } ); ET_PageBuilder.ColumnSettingsView = window.wp.Backbone.View.extend( { className : 'et_pb_modal_settings', template : _.template( $('#et-builder-column-settings-template').html() ), events : { 'click .et-pb-column-layouts li' : 'addColumns', 'click .et-pb-options-tabs-links li a' : 'switchTab' }, initialize : function( attributes ) { this.listenTo( ET_PageBuilder_Events, 'et-add:columns', this.removeView ); this.listenTo( ET_PageBuilder_Events, 'et-modal-view-removed', this.removeViewAndEmptySection ); this.options = attributes; }, render : function() { this.$el.html( this.template( this.model.toJSON() ) ); if ( ET_PageBuilder_Layout.getView( this.model.get('cid') ).$el.closest( '.et_pb_global' ).length ) { this.$el.addClass( 'et_pb_no_global' ); } if ( typeof this.model.get( 'et_pb_specialty' ) !== 'undefined' && 'on' === this.model.get( 'et_pb_specialty' ) || typeof this.model.get( 'change_structure' ) !== 'undefined' && 'true' === this.model.get( 'change_structure' ) ) { this.$el.addClass( 'et_pb_modal_no_tabs' ); } return this; }, addColumns : function( event ) { event.preventDefault(); var that = this, $layout_el = $(event.target).is( 'li' ) ? $(event.target) : $(event.target).closest( 'li' ), layout = $layout_el.data('layout'), layout_specialty = 'section' === that.model.get( 'type' ) && 'on' === that.model.get( 'et_pb_specialty' ) ? $layout_el.data('specialty').split(',') : '', column_settings = { 'layout' : layout, 'layout_specialty' : layout_specialty, 'is_structure_change' : typeof that.model.get( 'change_structure' ) !== 'undefined' && 'true' === that.model.get( 'change_structure' ), 'specialty_columns' : $layout_el.data('specialty_columns') }; ET_PageBuilder_Layout.changeColumnStructure( that, column_settings ); }, removeView : function() { var that = this; // remove it with some delay to make sure animation applied to modal before removal setTimeout( function() { that.remove(); }, 300 ); }, switchTab : function( event ) { var $this_el = $( event.currentTarget ).parent(); event.preventDefault(); et_handle_templates_switching( $this_el, 'row', '' ); }, /** * Remove modal view and empty specialty section, if the user hasn't selected a section layout * and closed a modal window */ removeViewAndEmptySection : function() { if ( this.model.get( 'et_pb_specialty' ) === 'on' ) { this.options.view.model.destroy(); ET_PageBuilder_Layout.removeView( this.options.view.model.get('cid') ); this.options.view.remove(); } this.remove(); } } ); ET_PageBuilder.SaveLayoutSettingsView = window.wp.Backbone.View.extend( { className : 'et_pb_modal_settings', template : _.template( $('#et-builder-load_layout-template').html() ), events : { 'click .et_pb_layout_button_load' : 'loadLayout', 'click .et_pb_layout_button_delete' : 'deleteLayout', 'click .et-pb-options-tabs-links li a' : 'switchTab' }, initialize : function( attributes ) { this.options = attributes; this.layoutIsLoading = false; this.listenTo( ET_PageBuilder_Events, 'et-modal-view-removed', this.remove ); }, render : function() { var $this_el = this.$el, post_type = $('#post_type').val(); $this_el.html( this.template( { "display_switcher" : "on" } ) ); et_load_saved_layouts( 'predefined', 'et-pb-all-modules-tab', $this_el, post_type ); et_load_saved_layouts( 'not_predefined', 'et-pb-saved-modules-tab', $this_el, post_type ); return this; }, deleteLayout : function( event ) { event.preventDefault(); var $layout = $( event.currentTarget ).closest( 'li' ); if ( $layout.hasClass( 'et_pb_deleting_layout' ) ) return; else $layout.addClass( 'et_pb_deleting_layout' ); $.ajax( { type: "POST", url: et_pb_options.ajaxurl, data: { action : 'et_pb_delete_layout', et_admin_load_nonce : et_pb_options.et_admin_load_nonce, et_layout_id : $layout.data( 'layout_id' ) }, beforeSend : function() { ET_PageBuilder_Events.trigger( 'et-pb-loading:started' ); $layout.css( 'opacity', '0.5' ); }, complete : function() { ET_PageBuilder_Events.trigger( 'et-pb-loading:ended' ); }, success: function( data ){ if ( $layout.closest( 'ul' ).find( '> li' ).length == 1 ) $layout.closest( 'ul' ).prev( 'h3' ).hide(); $layout.remove(); } } ); }, loadLayout : function( event ) { event.preventDefault(); if ( this.layoutIsLoading ) { return; } else { this.layoutIsLoading = true; this.$el.find( '.et-pb-main-settings' ).css( { 'opacity' : '0.5' } ); } var $layout = $( event.currentTarget ).closest( 'li' ), replace_content = $layout.closest( '.et-pb-main-settings' ).find( '#et_pb_load_layout_replace' ).is( ':checked' ), content = et_pb_get_content( 'content' ), this_el = this; $.ajax( { type: "POST", url: et_pb_options.ajaxurl, data: { action : 'et_pb_load_layout', et_admin_load_nonce : et_pb_options.et_admin_load_nonce, et_layout_id : $layout.data( 'layout_id' ), et_replace_content : ( replace_content ? 'on' : 'off' ) }, beforeSend : function() { ET_PageBuilder_Events.trigger( 'et-pb-loading:started' ); }, complete : function() { ET_PageBuilder_Events.trigger( 'et-pb-loading:ended' ); ET_PageBuilder_Events.trigger( 'et-saved_layout:loaded' ); }, success: function( data ){ content = replace_content ? data : data + content; ET_PageBuilder_App.removeAllSections(); if ( content !== '' ) { ET_PageBuilder_App.allowHistorySaving( 'loaded', 'layout' ); } ET_PageBuilder_App.createNewLayout( content, 'load_layout' ); } } ); }, switchTab: function( event ) { var $this_el = $( event.currentTarget ).parent(); event.preventDefault(); et_handle_templates_switching( $this_el, 'layout', '' ); } } ); ET_PageBuilder.ModulesView = window.wp.Backbone.View.extend( { className : 'et_pb_modal_settings', template : _.template( $('#et-builder-modules-template').html() ), events : { 'click .et-pb-all-modules li' : 'addModule', 'click .et-pb-options-tabs-links li a' : 'switchTab' }, initialize : function( attributes ) { this.options = attributes; this.listenTo( ET_PageBuilder_Events, 'et-modal-view-removed', this.remove ); }, render : function() { var template_type_holder = typeof ET_PageBuilder_Layout.getView( this.model.get('parent') ) !== 'undefined' ? ET_PageBuilder_Layout.getView( this.model.get('parent') ) : this; this.$el.html( this.template( ET_PageBuilder_Layout.toJSON() ) ); if ( ET_PageBuilder_Layout.getView( this.model.get('cid') ).$el.closest( '.et_pb_global' ).length || typeof template_type_holder.model.get('et_pb_template_type') !== 'undefined' && 'module' === template_type_holder.model.get('et_pb_template_type') ) { this.$el.addClass( 'et_pb_no_global' ); } return this; }, addModule : function( event ) { var $this_el = $( event.currentTarget ), label = $this_el.find( '.et_module_title' ).text(), type = $this_el.attr( 'class' ).replace( ' et_pb_fullwidth_only_module', '' ), global_module_cid = '', parent_view = ET_PageBuilder_Layout.getView( this.model.get('parent') ), template_type_holder = typeof parent_view !== 'undefined' ? parent_view : this event.preventDefault(); if ( typeof this.model.get( 'et_pb_global_parent' ) !== 'undefined' && typeof this.model.get( 'et_pb_global_parent' ) !== '' ) { global_module_cid = this.model.get( 'global_parent_cid' ); } // Enable history saving and set meta for history ET_PageBuilder_App.allowHistorySaving( 'added', 'module', label ); this.collection.add( [ { type : 'module', cid : ET_PageBuilder_Layout.generateNewId(), module_type : type, admin_label : label, parent : this.attributes['data-parent_cid'], view : this.options.view, global_parent_cid : global_module_cid } ] ); this.remove(); if ( '' !== global_module_cid ) { et_pb_update_global_template( global_module_cid ); } if ( typeof template_type_holder.model.get( 'et_pb_template_type' ) !== 'undefined' && 'module' === template_type_holder.model.get( 'et_pb_template_type' ) ) { et_add_template_meta( '_et_pb_module_type', type ); } et_pb_open_current_tab(); }, switchTab : function( event ) { var $this_el = $( event.currentTarget ).parent(), module_width = typeof this.model.get( 'et_pb_fullwidth' ) && 'on' === this.model.get( 'et_pb_fullwidth' ) ? 'fullwidth' : 'regular'; event.preventDefault(); et_handle_templates_switching( $this_el, 'module', module_width ); } } ); ET_PageBuilder.ModuleSettingsView = window.wp.Backbone.View.extend( { className : 'et_pb_module_settings', initialize : function() { if ( ! $( ET_PageBuilder_Layout.generateTemplateName( this.attributes['data-module_type'] ) ).length ) { this.attributes['data-no_template'] = 'no_template'; return; } this.template = _.template( $( ET_PageBuilder_Layout.generateTemplateName( this.attributes['data-module_type'] ) ).html() ); this.listenTo( ET_PageBuilder_Events, 'et-modal-view-removed', this.removeModule ); this.listenTo( ET_PageBuilder_Events, 'et-advanced-module:saved', this.renderMap ); }, events : { }, render : function() { var thisClass = this, $this_el = this.$el, content = '', this_module_cid = this.model.attributes.cid, $content_textarea, $content_textarea_container, $content_textarea_option, advanced_mode = false, view, $color_picker, $upload_button, $video_image_button, $gallery_button, $icon_font_list, $et_affect_fields, $et_form_validation, $icon_font_options = [ "et_pb_font_icon", "et_pb_button_one_icon", "et_pb_button_two_icon", "et_pb_button_icon" ], $add_email_account_buttons, $preview_panel, $previewable_upload_button_add, $previewable_upload_button_edit, $previewable_upload_button_delete; // Update module's _builder_version to current builder's version thisClass.model.set( 'et_pb__builder_version', et_pb_options.product_version ); // Replace encoded double quotes with normal quotes, // escaping is applied in modules templates _.each( this.model.attributes, function( value, key, list ) { if ( typeof value === 'string' && key !== 'et_pb_content_new' && -1 === $.inArray( key, $icon_font_options ) && ! /^\%\%\d+\%\%$/.test( $.trim( value ) ) ) { return list[ key ] = value.replace( /%22/g, '"' ); } } ); this.$el.html( this.template( this.model.attributes ) ); $content_textarea = this.$el.find( '#et_pb_content_new' ); $color_picker = this.$el.find('.et-pb-color-picker-hex'); $color_picker_alpha = this.$el.find('.et-builder-color-picker-alpha'); $upload_button = this.$el.find('.et-pb-upload-button'); $preview_panel = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview'); $previewable_upload_button_add = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview-button--add'); $previewable_upload_button_edit = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview-button--edit'); $previewable_upload_button_delete = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview-button--delete'); $video_image_button = this.$el.find('.et-pb-video-image-button'); $gallery_button = this.$el.find('.et-pb-gallery-button'); $time_picker = this.$el.find('.et-pb-date-time-picker'); $icon_font_list = this.$el.find('.et_font_icon'); $validation_element = $this_el.find('.et-validate-number'); $et_form_validation = $this_el.find('form.validate'); $warning = $this_el.find('.et-pb-option--warning'); $add_email_account_buttons = $this_el.find('.et_pb_email_add_account'); // validation if ( $et_form_validation.length ) { et_builder_debug_message('validation enabled'); $et_form_validation.validate({ debug: true }); } if ( $color_picker.length ) { var draggingID, changeID; $color_picker.each( function() { var $this = $(this); $this.wpColorPicker({ defaultColor : $this.data('default-color'), palettes : '' !== et_pb_options.page_color_palette ? et_pb_options.page_color_palette.split( '|' ) : et_pb_options.default_color_palette.split( '|' ), change : function( event, ui ) { var $this_el = $(this); var $option_container = $this_el.closest( '.et-pb-option-container' ); var $reset_button = $option_container.find( '.et-pb-reset-setting' ); var $custom_color_container = $this_el.closest( '.et-pb-custom-color-container' ); var $preview = $option_container.find( '.et-pb-option-preview' ); var has_preview = $this_el.hasClass('et-pb-color-picker-hex-has-preview'); var is_gradient_colorpicker = $this_el.closest('.et_pb_background-tab--gradient').length > 0; var current_value = ui.color.toString().toLowerCase(); var default_value; if ( $custom_color_container.length ) { $custom_color_container.find( '.et-pb-custom-color-picker' ).val( ui.color.toString() ); // trigger change event if color picker inside font option for further processing if ( $option_container.hasClass('et-pb-option-container--font') ) { $custom_color_container.find( '.et-pb-custom-color-picker' ).trigger('change'); } } default_value = et_pb_get_default_setting_value( $this_el ).toLowerCase(); // do not apply default rules for reset button inside the font option. It has specific rules if ( ! $option_container.hasClass('et-pb-option-container--font') ) { if ( current_value !== default_value ) { if ( $reset_button.length ) { $reset_button.addClass( 'et-pb-reset-icon-visible' ); } if ( has_preview ) { $preview.removeClass('et-pb-option-preview--empty'); } } else { if ( $reset_button.length ) { $reset_button.removeClass( 'et-pb-reset-icon-visible' ); } if ( has_preview ) { $preview.addClass('et-pb-option-preview--empty'); } } } if ( has_preview) { $preview.css( { backgroundColor: current_value } ); } if ( is_gradient_colorpicker ) { et_pb_update_gradient_preview( $this_el ); } if ( _.has( event, 'originalEvent' ) && _.has( event.originalEvent, 'type' ) && event.originalEvent.type === 'square' ) { $option_container.find( '.button-confirm' ).css( 'backgroundColor', current_value + ' !important' ); if ( ! $option_container.hasClass( 'is-dragging' ) ) { $option_container.addClass( 'is-dragging' ); } clearTimeout( draggingID ); draggingID = setTimeout( function() { et_pb_reposition_colorpicker_element( $this_el ); $option_container.find( '.button-confirm' ).css( 'backgroundColor', '' ); $option_container.removeClass( 'is-dragging' ); }, 300 ); } // Set focus back to clearpicker input after color change so enter could close the colorpicker clearTimeout( changeID ); changeID = setTimeout( function() { $this_el.focus(); }, 300 ); // Remove clear marker class name to make color validation works again if ( $this_el.hasClass( 'et-pb-is-cleared' ) ) { $this_el.removeClass( 'et-pb-is-cleared' ) } //Since this event is triggered before the input value is changed we can't use 'et_pb_setting:change' $this_el.trigger('et_pb_setting:color_picker:change', [current_value]); }, clear: function() { $(this).val( et_pb_options.invalid_color ); $(this).closest( '.et-pb-option-container' ).find( '.et-pb-main-setting' ).val( '' ); $(this).siblings('.et-pb-color-picker-hex').trigger('et_pb_setting:color_picker:change', ['']); }, width : $this.closest( '.et-pb-option--background' ).length ? 660 : 300, height : 190, diviColorpicker : $this.closest( '.et-pb-option--background' ).length ? true : false }); var default_color = $this.data('default-color') || '', $reset_button = $this.closest( '.et-pb-option-container' ).find( '.et-pb-reset-setting' ); if ( $this.hasClass('et-pb-color-picker-hex-has-preview') ) { var $option_container = $this.closest('.et-pb-option-container'); $option_container.find('.et-pb-option-preview-button--add, .et-pb-option-preview-button--edit, .et-pb-option-preview').click( function(e) { e.stopPropagation(); $this.wpColorPicker('open'); }); $option_container.find('.et-pb-option-preview-button--delete').click( function(e) { e.stopPropagation(); // Clear color value on DOM and colorpicker then add cleared class name to bypass color validation $this.wpColorPicker( 'color', '' ).val( '' ).addClass( 'et-pb-is-cleared' ); $option_container.find('.et-pb-option-preview').removeAttr('style').addClass('et-pb-option-preview--empty'); }); } if ( ! $reset_button.length ) { return true; } var value = $this.val() + ''; if ( default_color.toLowerCase() !== value.toLowerCase() ) { $reset_button.addClass( 'et-pb-reset-icon-visible' ); } } ); } if ( $color_picker_alpha.length ) { $color_picker_alpha.each(function(){ var $this_color_picker_alpha = $(this), color_picker_alpha_val = $this_color_picker_alpha.data('value').split('|'), color_picker_alpha_hex = color_picker_alpha_val[0] || '#444444', color_picker_alpha_opacity = color_picker_alpha_val[2] || 1.0; $this_color_picker_alpha.attr('data-opacity', color_picker_alpha_opacity ); $this_color_picker_alpha.val( color_picker_alpha_hex ); $this_color_picker_alpha.minicolors({ control: 'hue', defaultValue: $(this).data('default-color') || '', opacity: true, changeDelay: 200, show: function() { $this_color_picker_alpha.minicolors('opacity', $this_color_picker_alpha.data('opacity') ); }, change: function(hex, opacity) { if( !hex ) { return; } var rgba_object = $this_color_picker_alpha.minicolors('rgbObject'), $field = $( $this_color_picker_alpha.data('field') ), values = [], values_string; values.push( hex ); values.push( rgba_object.r + ', ' + rgba_object.g + ', ' + rgba_object.b ); values.push( opacity ); values_string = values.join('|'); if ( $field.length ) { $field.val( values_string ); } }, theme: 'bootstrap' }); }); } if ( $upload_button.length ) { et_pb_activate_upload( $upload_button ); } if ( $previewable_upload_button_add.length || $previewable_upload_button_edit.length || $preview_panel ) { function et_pb_trigger_upload_button( e ) { e.preventDefault(); e.stopPropagation(); if ( $(this).hasClass( 'et-pb-option-preview' ) && ! $(this).hasClass( 'et-pb-option-preview--empty' ) && $(this).siblings( '.button' ).attr( 'data-type' ) === 'video' ) { return; } // If current background image preview is overwritten by featured image, image editing should be disabled if ( et_pb_is_featured_image_background( $(this) ) ) { return; } $(this).closest( '.et-pb-option' ).find( '.et-pb-upload-button' ).trigger( 'click' ); } $preview_panel.click( et_pb_trigger_upload_button ); $previewable_upload_button_add.click( et_pb_trigger_upload_button ); $previewable_upload_button_edit.click( et_pb_trigger_upload_button ); } if ( $previewable_upload_button_delete.length ) { $previewable_upload_button_delete.click( function( e ) { e.preventDefault(); e.stopPropagation(); // If current background image preview is overwritten by featured image, image removal should be disabled if ( et_pb_is_featured_image_background( $(this) ) ) { return; } var $option = $( this ).closest( '.et-pb-option' ), $input = $option.find( '.et-pb-upload-field' ), $preview = $option.find( '.et-pb-option-preview' ); $input.val( '' ); $preview.addClass( 'et-pb-option-preview--empty' ).find('.et-pb-preview-content').remove(); } ); } if ( $video_image_button.length ) { et_pb_generate_video_image( $video_image_button ); } if ( $gallery_button.length ) { et_pb_activate_gallery( $gallery_button ); } if ( $add_email_account_buttons.length ) { et_pb_email_lists_buttons_setup( $add_email_account_buttons, this ); } if ( $time_picker.length ) { // use the specified date format to avoid issues with date translation to different languages $time_picker.datetimepicker({'dateFormat':'yy-mm-dd'}); } if( $validation_element.length ){ $validation_element.keyup( function() { var $this_el = $( this ); if ( $this_el.val() < 0 || ( !$.isNumeric( $this_el.val() ) && $this_el.val() !== '' ) ) { $this_el.val( 0 ); } if ( $this_el.val() > 100 ) { $this_el.val( 100 ); } if ( $this_el.val() !=='' ) { $this_el.val( Math.round( $this_el.val() ) ); } }); } if ( $icon_font_list.length ) { var that = this; $icon_font_list.each( function() { var $this_icon_list = $( this ), $icon_font_field = $this_icon_list.siblings('.et-pb-font-icon'), current_symbol_val = $.trim( $icon_font_field.val() ), $icon_font_symbols = $this_icon_list.find( 'li' ), active_symbol_class = 'et_active', $current_symbol, top_offset, icon_index_number; function et_pb_icon_font_init() { if ( current_symbol_val !== '' ) { current_symbol_val = current_symbol_val.replace('[', '%91'); current_symbol_val = current_symbol_val.replace(']', '%93'); // font icon index is used now in the following format: %%index_number%% if ( current_symbol_val.search( /^%%/ ) !== -1 ) { icon_index_number = parseInt( current_symbol_val.replace( /%/g, '' ) ); $current_symbol = $this_icon_list.find( 'li' ).eq( icon_index_number ); } else { // set the 1st icon as active if wrong value saved for current_symbol_val if ( '"' === current_symbol_val ) { $current_symbol = $this_icon_list.find( 'li' ).eq( 0 ); } else { $current_symbol = $this_icon_list.find( 'li[data-icon="' + current_symbol_val + '"]' ); } } $current_symbol.addClass( active_symbol_class ); if ( $this_icon_list.is( ':visible' ) ) { setTimeout( function() { top_offset = $current_symbol.offset().top - $this_icon_list.offset().top; if ( top_offset > 0 ) { $this_icon_list.animate( { scrollTop : top_offset }, 0 ); } }, 110 ); } } } et_pb_icon_font_init(); that.$el.find( '.et-pb-options-tabs-links' ).on( 'et_pb_main_tab:changed', et_pb_icon_font_init ); $icon_font_symbols.click( function() { var $this_element = $(this), this_symbol = $this_element.index(); if ( $this_element.hasClass( active_symbol_class ) ) { return false; } $this_element.siblings( '.' + active_symbol_class ).removeClass( active_symbol_class ).end().addClass( active_symbol_class ); this_symbol = '%%' + this_symbol + '%%'; $icon_font_field.val( this_symbol ); } ); }); } if ( $content_textarea.length ) { $content_textarea_option = $content_textarea.closest( '.et-pb-option' ); if ( $content_textarea_option.hasClass( 'et-pb-option-advanced-module' ) ) advanced_mode = true; if ( ! advanced_mode ) { $content_textarea_container = $content_textarea.closest( '.et-pb-option-container' ); content = $content_textarea.html(); $content_textarea.remove(); $content_textarea_container.prepend( et_pb_content_html ); setTimeout( function() { if ( typeof window.switchEditors !== 'undefined' ) { window.switchEditors.go( 'et_pb_content_new', et_get_editor_mode() ); } et_pb_set_content( 'et_pb_content_new', content ); window.wpActiveEditor = 'et_pb_content_new'; }, 100 ); } else { var view_cid = ET_PageBuilder_Layout.generateNewId(); this.view_cid = view_cid; $content_textarea_option.hide(); $content_textarea.attr( 'id', 'et_pb_content_main' ); view = new ET_PageBuilder.AdvancedModuleSettingsView( { model : this, el : this.$el.find( '.et-pb-option-advanced-module-settings' ), attributes : { cid : view_cid, value_changes : thisClass.model.get( 'value_changes' ), } } ); ET_PageBuilder_Layout.addView( view_cid, view ); $content_textarea_option.before( view.render() ); if ( $content_textarea.html() !== '' ) { view.generateAdvancedSortableItems( $content_textarea.html(), this.$el.find( '.et-pb-option-advanced-module-settings' ).data( 'module_type' ) ); ET_PageBuilder_Events.trigger( 'et-advanced-module:updated_order', this.$el ); } } } if ( $warning.length ) { $warning.each(function() { var $warning_option = $(this); var $warning_field = $warning_option.find('.et-pb-option-warning'); var display_if = $warning_field.attr('data-display_if'); var name = $warning_field.attr('data-name'); if ( et_pb_options[name] === display_if ) { $warning_option.addClass('et-pb-option--warning-active'); } }); } this.renderMap(); et_pb_init_main_settings( this.$el, this_module_cid ); if ( ! advanced_mode ) { setTimeout( function() { $this_el.find('select, input, textarea, radio').filter(':eq(0)').focus(); }, 1 ); } return this; }, removeModule : function() { // remove Module settings, when modal window is closed or saved this.remove(); }, is_latlng : function( address ) { var latlng = address.split( ',' ), lat = ! _.isUndefined( latlng[0] ) ? parseFloat( latlng[0] ) : false, lng = ! _.isUndefined( latlng[1] ) ? parseFloat( latlng[1] ) : false; if ( typeof google !== 'undefined' && lat && ! _.isNaN( lat ) && lng && ! _.isNaN( lng ) ) { return new google.maps.LatLng( lat, lng ); } return false; }, renderMap: function() { this_el = this, $map = this.$el.find('.et-pb-map'); if ( typeof google !== 'undefined' && $map.length ) { view_cid = this.view_cid; var $address = this.$el.find('.et_pb_address'), $address_lat = this.$el.find('.et_pb_address_lat'), $address_lng = this.$el.find('.et_pb_address_lng'), $find_address = this.$el.find('.et_pb_find_address'), $zoom_level = this.$el.find('.et_pb_zoom_level'), geocoder = new google.maps.Geocoder(), markers = {}; var geocode_address = function() { var address = $address.val(); if ( address.length <= 0 ) { return; } geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var result = results[0], location = result.geometry.location, address_is_latlng = this_el.is_latlng( address ); // If user passes valid lat lng instead of address, override geocode with given lat & lng if ( address_is_latlng ) { location = address_is_latlng; } if ( ! isNaN( location.lat() ) && ! isNaN( location.lng() ) ) { $address.val( result.formatted_address); $address_lat.val(location.lat()); $address_lng.val(location.lng()); update_center( location ); } else { alert( et_pb_options.map_pin_address_invalid ); } } else { alert( et_pb_options.geocode_error + ': ' + status); } }); } var update_center = function( LatLng ) { $map.map.setCenter( LatLng ); } var update_zoom = function () { $map.map.setZoom( parseInt( $zoom_level.val() ) ); } $address.on('blur', geocode_address ); $find_address.on('click', function(e){ e.preventDefault(); }); $zoom_level.on('blur', update_zoom ); setTimeout( function() { $map.map = new google.maps.Map( $map[0], { zoom: parseInt( $zoom_level.val() ), mapTypeId: google.maps.MapTypeId.ROADMAP }); if ( '' != $address_lat.val() && '' != $address_lng.val() ) { update_center( new google.maps.LatLng( $address_lat.val(), $address_lng.val() ) ); } if ( '' != $zoom_level ) { update_zoom(); } setTimeout( function() { var map_pins = ET_PageBuilder_Layout.getChildViews( view_cid ); if ( _.size( map_pins ) ) { _.each( map_pins, function( map_pin, key ) { // Skip current map pin if it has no lat or lng, as it will trigger maximum call stack exceeded if ( _.isUndefined( map_pin.model.get('et_pb_pin_address_lat') ) || _.isUndefined( map_pin.model.get('et_pb_pin_address_lng') ) ) { return; } markers[key] = new google.maps.Marker({ map: $map.map, position: new google.maps.LatLng( parseFloat( map_pin.model.get('et_pb_pin_address_lat') ) , parseFloat( map_pin.model.get('et_pb_pin_address_lng') ) ), title: map_pin.model.get('et_pb_title'), icon: { url: et_pb_options.images_uri + '/marker.png', size: new google.maps.Size( 46, 43 ), anchor: new google.maps.Point( 16, 43 ) }, shape: { coord: [1, 1, 46, 43], type: 'rect' } }); }); } }, 500 ); google.maps.event.addListener( $map.map, 'center_changed', function() { var center = $map.map.getCenter(); $address_lat.val( center.lat() ); $address_lng.val( center.lng() ); }); google.maps.event.addListener( $map.map, 'zoom_changed', function() { var zoom_level = $map.map.getZoom(); $zoom_level.val( zoom_level ); }); }, 200 ); } } } ); ET_PageBuilder.AdvancedModuleSettingsView = window.wp.Backbone.View.extend( { initialize : function() { this.listenTo( ET_PageBuilder_Events, 'et-advanced-module:updated', this.generateContent ); this.listenTo( ET_PageBuilder_Events, 'et-modal-view-removed', this.removeModule ); this.module_type = this.$el.data( 'module_type' ); ET_PageBuilder.Events = ET_PageBuilder_Events; this.child_views = []; this.$el.attr( 'data-cid', this.attributes['cid'] ); this.$sortable_options = this.$el.find('.et-pb-sortable-options'); this.$content_textarea = this.$el.siblings('.et-pb-option-main-content').find('#et_pb_content_main'); this.$sortable_options.sortable( { axis : 'y', cancel : '.et-pb-advanced-setting-remove, .et-pb-advanced-setting-options', update : function( event, ui ) { ET_PageBuilder_Events.trigger( 'et-advanced-module:updated' ); ET_PageBuilder_Events.trigger( 'et-advanced-module:updated_order' ); } } ); this.$add_sortable_item = this.$el.find( '.et-pb-add-sortable-option' ).addClass( 'et-pb-add-sortable-initial' ); }, events : { 'click .et-pb-add-sortable-option' : 'addModule', 'click .et-pb-advanced-setting-clone' : 'cloneModule' }, render : function() { return this; }, addModule : function( event ) { event.preventDefault(); this.model.collection.add( [ { type : 'module', module_type : this.module_type, cid : ET_PageBuilder_Layout.generateNewId(), view : this, created : 'manually', mode : 'advanced', parent : this.attributes['cid'], parent_cid : this.model.model.attributes['cid'] } ], { update_shortcodes : 'false' } ); this.$add_sortable_item.removeClass( 'et-pb-add-sortable-initial' ); ET_PageBuilder_Events.trigger( 'et-advanced-module:updated_order' ); }, cloneModule : function( event ) { event.preventDefault(); var cloned_cid = $( event.target ).closest( 'li' ).data( 'cid' ), cloned_model = ET_PageBuilder_App.collection.find( function( model ) { return model.get('cid') == cloned_cid; } ), module_attributes = _.clone( cloned_model.attributes ); module_attributes.created = 'manually'; module_attributes.cloned_cid = cloned_cid; module_attributes.cid = ET_PageBuilder_Layout.generateNewId(); this.model.collection.add( module_attributes ); ET_PageBuilder_Events.trigger( 'et-advanced-module:updated' ); ET_PageBuilder_Events.trigger( 'et-advanced-module:saved' ); ET_PageBuilder_Events.trigger( 'et-advanced-module:updated_order' ); }, generateContent : function() { var content = ''; this.$sortable_options.find( 'li' ).each( function() { var $this_el = $(this); content += ET_PageBuilder_App.generateModuleShortcode( $this_el, false ); } ); // Replace double quotes with ^^ in temporary shortcodes content = content.replace( /%22/g, '^^' ); this.$content_textarea.html( content ); if ( ! this.$sortable_options.find( 'li' ).length ) this.$add_sortable_item.addClass( 'et-pb-add-sortable-initial' ); else this.$add_sortable_item.removeClass( 'et-pb-add-sortable-initial' ); }, generateAdvancedSortableItems : function( content, module_type ) { var this_el = this, et_pb_shortcodes_tags = ET_PageBuilder_App.getShortCodeChildTags(), reg_exp = window.wp.shortcode.regexp( et_pb_shortcodes_tags ), inner_reg_exp = ET_PageBuilder_App.wp_regexp_not_global( et_pb_shortcodes_tags ), matches = content.match( reg_exp ); if ( content !== '' ) this.$add_sortable_item.removeClass( 'et-pb-add-sortable-initial' ); _.each( matches, function ( shortcode, shortcode_index ) { var shortcode_element = shortcode.match( inner_reg_exp ), shortcode_name = shortcode_element[2], shortcode_attributes = shortcode_element[3] !== '' ? window.wp.shortcode.attrs( shortcode_element[3] ) : '', shortcode_content = shortcode_element[5], module_cid = ET_PageBuilder_Layout.generateNewId(), module_settings, prefixed_attributes = {}, found_inner_shortcodes = typeof shortcode_content !== 'undefined' && shortcode_content !== '' && shortcode_content.match( reg_exp ), name_changes = et_pb_options.et_pb_module_settings_migrations.name_changes; module_settings = { type : 'module', module_type : module_type, cid : ET_PageBuilder_Layout.generateNewId(), view : this_el, created : 'auto', mode : 'advanced', parent : this_el.attributes['cid'], parent_cid : this_el.model.model.attributes['cid'] }; if ( _.isObject( shortcode_attributes['named'] ) ) { for ( var key in shortcode_attributes['named'] ) { var prefixed_key = key !== 'admin_label' ? 'et_pb_' + key : key, setting_value; if ( shortcode_name === 'column' && prefixed_key === 'et_pb_type' ) prefixed_key = 'layout'; setting_value = shortcode_attributes['named'][key]; // Replace temporary ^^ signs with double quotes setting_value = setting_value.replace( /\^\^/g, '"' ); prefixed_attributes[prefixed_key] = setting_value; } module_settings['et_pb_content_new'] = shortcode_content; module_settings = _.extend( module_settings, prefixed_attributes ); } if ( ! found_inner_shortcodes ) { module_settings['et_pb_content_new'] = shortcode_content; } // BEGIN Settings Migrations // Applying attribute name migration for current module item if ( ! _.isEmpty( name_changes ) && ! _.isEmpty( name_changes[ this_el.module_type ] ) ) { _.forEach( name_changes[ this_el.module_type ], function( new_attr_name, old_attr_name ) { if ( ! _.isUndefined( module_settings[ 'et_pb_' + old_attr_name ] ) ) { module_settings[ 'et_pb_' + new_attr_name ] = module_settings[ 'et_pb_' + old_attr_name ]; // Delete migrated name to avoid unwanted value re-assignment when module item is re-opened delete module_settings[ 'et_pb_' + old_attr_name ]; } } ); } // Applying value migration for current module item if ( ! _.isUndefined( this_el.attributes.value_changes ) && ! _.isUndefined( this_el.attributes.value_changes[ shortcode_index ] ) ) { _.forEach( this_el.attributes.value_changes[ shortcode_index ], function( value, attribute_name ) { module_settings[ 'et_pb_' + attribute_name ] = value; } ); } // END Settings Migrations this_el.model.collection.add( [ module_settings ], { update_shortcodes : 'false' } ); } ); }, removeModule : function() { // remove Module settings, when modal window is closed or saved _.each( this.child_views, function( view ) { view.removeView(); } ); this.remove(); } } ); ET_PageBuilder.AdvancedModuleSettingView = window.wp.Backbone.View.extend( { tagName : 'li', initialize : function() { this.template = _.template( $( '#et-builder-advanced-setting' ).html() ); }, events : { 'click .et-pb-advanced-setting-options' : 'showSettings', 'click .et-pb-advanced-setting-remove' : 'removeView' }, render : function() { var view; this.$el.html( this.template( this.model.attributes ) ); view = new ET_PageBuilder.AdvancedModuleSettingTitleView( { model : this.model, view : this } ); this.$el.prepend( view.render().el ); this.child_view = view; if ( typeof this.model.get( 'cloned_cid' ) === 'undefined' || '' === this.model.get( 'cloned_cid' ) ) { this.showSettings(); } return this; }, showSettings : function( event ) { var view; if ( event ) event.preventDefault(); view = new ET_PageBuilder.AdvancedModuleSettingEditViewContainer( { view : this, attributes : { show_settings_clicked : ( event ? true : false ) } } ); $('.et_pb_modal_settings_container').after( view.render().el ); }, removeView : function( event ) { if ( event ) event.preventDefault(); this.child_view.remove(); this.remove(); this.model.destroy(); ET_PageBuilder_Events.trigger( 'et-advanced-module:updated' ); ET_PageBuilder_Events.trigger( 'et-advanced-module:updated_order' ); } } ); ET_PageBuilder.AdvancedModuleSettingTitleView = window.wp.Backbone.View.extend( { tagName : 'span', className : 'et-sortable-title', initialize : function() { template_name = '#et-builder-advanced-setting-' + this.model.get( 'module_type' ) + '-title'; this.template = _.template( $( template_name ).html() ); this.listenTo( ET_PageBuilder_Events, 'et-advanced-module:updated', this.render ); }, render : function() { var view; // If admin label is empty, delete it so builder will use heading value instead if ( ! _.isUndefined( this.model.attributes.et_pb_admin_title ) && this.model.attributes.et_pb_admin_title === '' ) { delete this.model.attributes.et_pb_admin_title; } this.$el.html( this.template( this.model.attributes ) ); return this; } } ); ET_PageBuilder.AdvancedModuleSettingEditViewContainer = window.wp.Backbone.View.extend( { className : 'et_pb_modal_settings_container', initialize : function() { this.template = _.template( $( '#et-builder-advanced-setting-edit' ).html() ); this.model = this.options.view.model; this.listenTo( ET_PageBuilder_Events, 'et-modal-view-removed', this.removeView ); }, events : { 'click .et-pb-modal-save' : 'saveSettings', 'click .et-pb-modal-close' : 'removeView' }, is_latlng : function( address ) { var latlng = address.split( ',' ), lat = ! _.isUndefined( latlng[0] ) ? parseFloat( latlng[0] ) : false, lng = ! _.isUndefined( latlng[1] ) ? parseFloat( latlng[1] ) : false; if ( lat && ! _.isNaN( lat ) && lng && ! _.isNaN( lng ) ) { return new google.maps.LatLng( lat, lng ); } return false; }, render : function() { var this_module_cid = this.model.attributes.cid, view, $color_picker, $upload_button, $video_image_button, $map, $social_network_picker, $icon_font_list, this_el = this, $preview_panel, $previewable_upload_button_add, $previewable_upload_button_edit, $previewable_upload_button_delete; this.$el.html( this.template() ); this.$el.addClass( 'et_pb_modal_settings_container_step2' ); this.$el.attr( 'data-parent-cid', this_module_cid ); if ( this.model.get( 'created' ) !== 'auto' || this.attributes['show_settings_clicked'] ) { view = new ET_PageBuilder.AdvancedModuleSettingEditView( { view : this } ); this.$el.append( view.render().el ); this.child_view = view; } // Update module's _builder_version to current builder's version this.model.set( 'et_pb__builder_version', et_pb_options.product_version ); ET_PageBuilder.Events.trigger( 'et-advanced-module-settings:render', this ); $color_picker = this.$el.find('.et-pb-color-picker-hex'); $color_picker_alpha = this.$el.find('.et-builder-color-picker-alpha'); if ( $color_picker.length ) { var draggingID, changeID; $color_picker.each( function() { var $this = $(this); $this.wpColorPicker({ defaultColor : $this.data('default-color'), palettes : '' !== et_pb_options.page_color_palette ? et_pb_options.page_color_palette.split( '|' ) : et_pb_options.default_color_palette.split( '|' ), change : function( event, ui ) { var $this_el = $(this); var $option_container = $this_el.closest( '.et-pb-option-container' ); var $reset_button = $option_container.find( '.et-pb-reset-setting' ); var $custom_color_container = $this_el.closest( '.et-pb-custom-color-container' ); var $preview = $option_container.find( '.et-pb-option-preview' ); var has_preview = $this_el.hasClass('et-pb-color-picker-hex-has-preview'); var is_gradient_colorpicker = $this_el.closest('.et_pb_background-tab--gradient').length > 0; var current_value = ui.color.toString().toLowerCase(); var default_value; if ( $custom_color_container.length ) { $custom_color_container.find( '.et-pb-custom-color-picker' ).val( ui.color.toString() ); } if ( ! $reset_button.length && ( ! has_preview && ! is_gradient_colorpicker ) ) { return; } default_value = et_pb_get_default_setting_value( $this_el ).toLowerCase(); if ( current_value !== default_value ) { $reset_button.addClass( 'et-pb-reset-icon-visible' ); if ( has_preview ) { $preview.removeClass('et-pb-option-preview--empty'); } } else { $reset_button.removeClass( 'et-pb-reset-icon-visible' ); if ( has_preview ) { $preview.addClass('et-pb-option-preview--empty'); } } if ( has_preview) { $preview.css( { backgroundColor: current_value } ); } if ( is_gradient_colorpicker ) { et_pb_update_gradient_preview( $this_el ); } if ( has_preview || is_gradient_colorpicker ) { if ( _.has( event, 'originalEvent' ) && _.has( event.originalEvent, 'type' ) && event.originalEvent.type === 'square' ) { $option_container.find( '.button-confirm' ).css( 'backgroundColor', current_value + ' !important' ); if ( ! $option_container.hasClass( 'is-dragging' ) ) { $option_container.addClass( 'is-dragging' ); } clearTimeout( draggingID ); draggingID = setTimeout( function() { et_pb_reposition_colorpicker_element( $this_el ); $option_container.find( '.button-confirm' ).css( 'backgroundColor', '' ); $option_container.removeClass( 'is-dragging' ); }, 300 ); } // Set focus back to clearpicker input after color change so enter could close the colorpicker clearTimeout( changeID ); changeID = setTimeout( function() { $this_el.focus(); }, 300 ); } // Remove clear marker class name to make color validation works again if ( $this_el.hasClass( 'et-pb-is-cleared' ) ) { $this_el.removeClass( 'et-pb-is-cleared' ) } // Since this event is triggered before the input value is changed we can't use 'et_pb_setting:change' $this_el.trigger('et_pb_setting:color_picker:change', [current_value]); }, width : $this.closest( '.et-pb-option--background' ).length ? 660 : 300, height : 190, diviColorpicker : $this.closest( '.et-pb-option--background' ).length ? true : false }); if ( $this.hasClass('et-pb-color-picker-hex-has-preview') ) { var $option_container = $this.closest('.et-pb-option-container'); $option_container.find('.et-pb-option-preview-button--add, .et-pb-option-preview-button--edit, .et-pb-option-preview').click( function(e) { e.stopPropagation(); $this.wpColorPicker('open'); }); $option_container.find('.et-pb-option-preview-button--delete').click( function(e) { e.stopPropagation(); // Remove clear marker class name to make color validation works again $this.wpColorPicker( 'color', '' ).val( '' ).addClass( 'et-pb-is-cleared' ); $option_container.find('.et-pb-option-preview').removeAttr('style').addClass('et-pb-option-preview--empty'); }); } } ); } if ( $color_picker_alpha.length ) { $color_picker_alpha.each(function(){ var $this_color_picker_alpha = $(this), color_picker_alpha_val = $this_color_picker_alpha.data('value').split('|'), color_picker_alpha_hex = color_picker_alpha_val[0] || '#444444', color_picker_alpha_opacity = color_picker_alpha_val[2] || 1.0; $this_color_picker_alpha.attr('data-opacity', color_picker_alpha_opacity ); $this_color_picker_alpha.val( color_picker_alpha_hex ); $this_color_picker_alpha.minicolors({ control: 'hue', defaultValue: $(this).data('default-color') || '', opacity: true, changeDelay: 200, show: function() { $this_color_picker_alpha.minicolors('opacity', $this_color_picker_alpha.data('opacity') ); }, change: function(hex, opacity) { if( !hex ) { return; } var rgba_object = $this_color_picker_alpha.minicolors('rgbObject'), $field = $( $this_color_picker_alpha.data('field') ), values = [], values_string; values.push( hex ); values.push( rgba_object.r + ', ' + rgba_object.g + ', ' + rgba_object.b ); values.push( opacity ); values_string = values.join('|'); if ( $field.length ) { $field.val( values_string ); } }, theme: 'bootstrap' }); }); } $upload_button = this.$el.find('.et-pb-upload-button'); $preview_panel = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview'); $previewable_upload_button_add = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview-button--add'); $previewable_upload_button_edit = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview-button--edit'); $previewable_upload_button_delete = this.$el.find('.et-pb-option-container--upload .et-pb-option-preview-button--delete'); if ( $upload_button.length ) { et_pb_activate_upload( $upload_button ); } if ( $previewable_upload_button_add.length || $previewable_upload_button_edit.length || $preview_panel.length ) { function et_pb_trigger_upload_button( e ) { e.preventDefault(); e.stopPropagation(); if ( $(this).hasClass( 'et-pb-option-preview' ) && ! $(this).hasClass( 'et-pb-option-preview--empty' ) ) { return; } $(this).closest( '.et-pb-option' ).find( '.et-pb-upload-button' ).trigger( 'click' ); } $preview_panel.click( et_pb_trigger_upload_button ); $previewable_upload_button_add.click( et_pb_trigger_upload_button ); $previewable_upload_button_edit.click( et_pb_trigger_upload_button ); } if ( $previewable_upload_button_delete.length ) { $previewable_upload_button_delete.click( function( e ) { e.preventDefault(); e.stopPropagation(); var $option = $( this ).closest( '.et-pb-option' ), $input = $option.find( '.et-pb-upload-field' ), $preview = $option.find( '.et-pb-option-preview' ); $input.val( '' ); $preview.addClass( 'et-pb-option-preview--empty' ).find('.et-pb-preview-content').remove(); } ); } $video_image_button = this.$el.find('.et-pb-video-image-button'); if ( $video_image_button.length ) { et_pb_generate_video_image( $video_image_button ); } $map = this.$el.find('.et-pb-map'); if ( typeof google !== 'undefined' && $map.length ) { var map, marker, $address = this.$el.find('.et_pb_pin_address'), $address_lat = this.$el.find('.et_pb_pin_address_lat'), $address_lng = this.$el.find('.et_pb_pin_address_lng'), $find_address = this.$el.find('.et_pb_find_address'), $zoom_level = this.$el.find('.et_pb_zoom_level'), geocoder = new google.maps.Geocoder(); var geocode_address = function() { var address = $address.val().trim(); if ( address.length <= 0 ) { return; } geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var result = results[0], location = result.geometry.location, address_is_latlng = this_el.is_latlng( address ); // If user passes valid lat lng instead of address, override geocode with given lat & lng if ( address_is_latlng ) { location = address_is_latlng; } if ( ! isNaN( location.lat() ) && ! isNaN( location.lng() ) ) { $address.val( result.formatted_address); $address_lat.val(location.lat()); $address_lng.val(location.lng()); update_map( location ); } else { alert( et_pb_options.map_pin_address_invalid ); } } else { alert( et_pb_options.geocode_error + ': ' + status); } }); } var update_map = function( LatLng ) { marker.setPosition( LatLng ); map.setCenter( LatLng ); } $address.on('change', geocode_address ); $find_address.on('click', function(e){ e.preventDefault(); }); setTimeout( function() { map = new google.maps.Map( $map[0], { zoom: parseInt( $zoom_level.val() ), mapTypeId: google.maps.MapTypeId.ROADMAP }); marker = new google.maps.Marker({ map: map, draggable: true, icon: { url: et_pb_options.images_uri + '/marker.png', size: new google.maps.Size( 46, 43 ), anchor: new google.maps.Point( 16, 43 ) }, shape: { coord: [1, 1, 46, 43], type: 'rect' }, }); google.maps.event.addListener(marker, 'dragend', function() { var drag_position = marker.getPosition(); $address_lat.val(drag_position.lat()); $address_lng.val(drag_position.lng()); update_map(drag_position); latlng = new google.maps.LatLng( drag_position.lat(), drag_position.lng() ); geocoder.geocode({'latLng': latlng }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if ( results[0] ) { $address.val( results[0].formatted_address ); } else { alert( et_pb_options.no_results ); } } else { alert( et_pb_options.geocode_error_2 + ': ' + status); } }); }); if ( '' != $address_lat.val() && '' != $address_lng.val() ) { update_map( new google.maps.LatLng( $address_lat.val(), $address_lng.val() ) ); } }, 200 ); } $gallery_button = this.$el.find('.et-pb-gallery-button'); if ( $gallery_button.length ) { et_pb_activate_gallery( $gallery_button ); } $social_network_picker = this.$el.find('.et-pb-social-network'); if ( $social_network_picker.length ) { var $color_reset = this.$el.find('.reset-default-color'), $social_network_icon_color = this.$el.find('#et_pb_background_color'); if ( $color_reset.length ){ $color_reset.click(function(){ $main_settings = $color_reset.parents('.et-pb-main-settings'); $social_network_picker = $main_settings.find('.et-pb-social-network'); $social_network_icon_color = $main_settings.find('#et_pb_background_color'); if ( $social_network_icon_color.length ) { $social_network_icon_color.wpColorPicker('color', $social_network_picker.find( 'option:selected' ).data('color') ); $color_reset.css( 'display', 'none' ); } }); } $social_network_picker.change(function(){ $main_settings = $social_network_picker.parents('.et-pb-main-settings'); // If $social_network_picker.change() is triggered during setting view render, ignore it // Continuing will cause saved background_color being overwrite by selected social_network's pre-defined color if ( $social_network_picker.data( 'is_rendering_setting_view' ) ) { return; } if ( $social_network_picker.val().length ) { var $social_network_title = $main_settings.find('#et_pb_content_new'), $social_network_icon_color = $main_settings.find('#et_pb_background_color'); if ( $social_network_title.length ) { $social_network_title.val( $social_network_picker.find( 'option:selected' ).text() ); } if ( $social_network_icon_color.length ) { var selectedColor = $social_network_picker.find( 'option:selected' ).data('color'); $social_network_icon_color.val( selectedColor ).wpColorPicker('color', selectedColor ); $social_network_icon_color.closest( '.et-pb-option-container' ).find( '.et-pb-option-preview' ).css({ backgroundColor: selectedColor, }); } } }); if ( $social_network_icon_color.val() !== $social_network_picker.find( 'option:selected' ).data('color') ) { $color_reset.css( 'display', 'inline' ); } } $icon_font_list = this.$el.find('.et_font_icon'); if ( $icon_font_list.length ) { var that = this; $icon_font_list.each( function() { var $this_icon_list = $( this ), $icon_font_field = $this_icon_list.siblings('.et-pb-font-icon'), current_symbol_val = $.trim( $icon_font_field.val() ), $icon_font_symbols = $this_icon_list.find( 'li' ), active_symbol_class = 'et_active', $current_symbol, top_offset, icon_index_number; function et_pb_icon_font_init() { if ( current_symbol_val !== '' ) { // font icon index is used now in the following format: %%index_number%% if ( current_symbol_val.search( /^%%/ ) !== -1 ) { icon_index_number = parseInt( current_symbol_val.replace( /%/g, '' ) ); $current_symbol = $this_icon_list.find( 'li' ).eq( icon_index_number ); } else { $current_symbol = $this_icon_list.find( 'li[data-icon="' + current_symbol_val + '"]' ); } $current_symbol.addClass( active_symbol_class ); if ( $this_icon_list.is( ':visible' ) ) { setTimeout( function() { top_offset = $current_symbol.offset().top - $this_icon_list.offset().top; if ( top_offset > 0 ) { $this_icon_list.animate( { scrollTop : top_offset }, 0 ); } }, 110 ); } } } et_pb_icon_font_init(); that.$el.find( '.et-pb-options-tabs-links' ).on( 'et_pb_main_tab:changed', et_pb_icon_font_init ); $icon_font_symbols.click( function() { var $this_element = $(this), this_symbol = $this_element.index(); if ( $this_element.hasClass( active_symbol_class ) ) { return false; } $this_element.siblings( '.' + active_symbol_class ).removeClass( active_symbol_class ).end().addClass( active_symbol_class ); this_symbol = '%%' + this_symbol + '%%'; $icon_font_field.val( this_symbol ); } ); }); } et_pb_set_child_defaults( this.$el, this_module_cid ); et_pb_init_main_settings( this.$el, this_module_cid ); return this; }, removeView : function( event ) { if ( event ) event.preventDefault(); // remove advanced tab WYSIWYG, only if the close button is clicked if ( this.$el.find( '#et_pb_content_new' ) && event ) et_pb_tinymce_remove_control( 'et_pb_content_new' ); et_pb_hide_active_color_picker( this ); if ( this.child_view ) this.child_view.remove(); this.remove(); }, saveSettings : function( event ) { var this_view = this, attributes = {}, this_model_defaults = this.model.get( 'module_defaults' ) || ''; event.preventDefault(); this.$( 'input, select, textarea' ).each( function() { var $this_el = $(this), id = $this_el.attr('id'), setting_value, checked_values = []; // name attribute is used in normal html checkboxes, use it instead of ID if ( $this_el.is( ':checkbox' ) ) { id = $this_el.attr('name'); } if ( typeof id === 'undefined' || ( -1 !== id.indexOf( 'qt_' ) && 'button' === $this_el.attr( 'type' ) ) ) { // settings should have an ID and shouldn't be a Quick Tag button from the tinyMCE in order to be saved return true; } if ( ! $this_el.is( ':checkbox' ) ) { id = $this_el.attr('id').replace( 'data.', '' ); } // All checkbox values are saved at once on the next step, so if the attribute name // already exists, do nothing if ( $this_el.is( ':checkbox' ) && typeof attributes[id] !== 'undefined' ) { return true; } setting_value = $this_el.is('#et_pb_content_new') ? et_pb_get_content( 'et_pb_content_new' ) : $this_el.val(); // Text align specific issue: $('select').val() chooses first value if there is no selected option found. // This causes innacuracy in form of first