/* global FusionApp, fusionAllElements, fusionAppConfig, FusionPageBuilderViewManager, FusionPageBuilderElements, FusionEvents, fusionMultiElements, FusionPageBuilderApp, fusionBuilderText, diffDOM, tinyMCE, fusionGetPercentPaddingHorizontalNegativeMargin, fusionGetPercentPaddingHorizontalNegativeMarginIfSiteWidthPercent, fusionTriggerEvent, fusionVendorShortcodes, fusionSanitize */ /* eslint no-useless-escape: 0 */ /* eslint no-shadow: 0 */ /* eslint max-depth: 0 */ /* eslint no-unused-vars: 0 */ /* eslint guard-for-in: 0 */ /* eslint no-continue: 0 */ /* eslint no-bitwise: 0 */ /* eslint no-mixed-operators: 0 */ /* eslint no-empty-function: 0 */ var FusionPageBuilder = FusionPageBuilder || {}; ( function() { var fusionElements = [], fusionGeneratorElements = [], fusionComponents = [], fusionFormComponents = [], sortedElements; jQuery.fn.outerHTML = function() { return ( ! this.length ) ? this : ( this[ 0 ].outerHTML || ( function( el ) { var div = document.createElement( 'div' ), contents; div.appendChild( el.cloneNode( true ) ); contents = div.innerHTML; div = null; return contents; }( this[ 0 ] ) ) ); }; // Loop over all available elements and add them to Avada Builder. sortedElements = _.sortBy( fusionAllElements, function( element ) { return element.name.toLowerCase(); } ); _.each( sortedElements, function( element ) { var newElement, targetObject = fusionGeneratorElements; if ( 'undefined' === typeof element.hide_from_builder ) { newElement = { title: element.name, label: element.shortcode }; if ( 'undefined' !== typeof element.component && element.component ) { targetObject = fusionComponents; } if ( 'undefined' === typeof element.generator_only && 'undefined' === typeof element.form_component ) { fusionElements.push( newElement ); } if ( ( 'undefined' !== typeof element.form_component && element.form_component ) || ( 'undefined' !== typeof element.allow_in_form && element.allow_in_form ) ) { fusionFormComponents.push( newElement ); return; } targetObject.push( Object.assign( {}, newElement, { generator_only: 'undefined' !== typeof element.generator_only ? true : element.generator_only, templates: 'undefined' !== typeof element.templates ? element.templates : false, components_per_template: 'undefined' !== typeof element.components_per_template ? element.components_per_template : false, template_tooltip: 'undefined' !== typeof element.template_tooltip ? element.template_tooltip : false } ) ); } } ); window.FusionPageBuilderViewManager = jQuery.extend( true, {}, new FusionPageBuilder.ViewManager() ); // Avada Builder App View FusionPageBuilder.AppView = Backbone.View.extend( { model: FusionPageBuilder.Element, collection: FusionPageBuilderElements, elements: { modules: fusionElements, generator_elements: fusionGeneratorElements, components: fusionComponents, componentsCounter: 0, usedComponents: [], form_components: fusionFormComponents }, events: { contextmenu: 'contextMenu' }, template: FusionPageBuilder.template( jQuery( '#fusion-builder-front-end-template' ).html() ), /** * Init. * * @since 2.0.0 * @return {void} */ initialize: function() { this.extraShortcodes = new FusionPageBuilder.ExtraShortcodes(); this.inlineEditors = new FusionPageBuilder.InlineEditorManager(); this.inlineEditorHelpers = new FusionPageBuilder.InlineEditorHelpers(); this.DraggableHelpers = new FusionPageBuilder.DraggableHelpers(); this.SettingsHelpers = new FusionPageBuilder.SettingsHelpers(); this.navigator = new FusionPageBuilder.Navigator(); this.navigatorView = new FusionPageBuilder.NavigatorView( { model: this.navigator } ); this.FormNav = new FusionPageBuilder.FormNav(); this.FormNavView = new FusionPageBuilder.FormNavView( { model: this.FormNav } ); this.dynamicValues = new FusionPageBuilder.DynamicValues(); this.studio = new FusionPageBuilder.Studio(); this.website = new FusionPageBuilder.Website(); this.formStyles = false; this.offCanvasStyles = false; this.activeStudio = false; // Post contents this.postContent = false; // Post Id this.postID = false; // Dummy text area to decode text encoded by the builder. this.dummyTextArea = document.createElement( 'textarea' ); // Listen for new elements this.listenTo( this.collection, 'add', this.addBuilderElement ); // Listen for data update this.listenTo( FusionEvents, 'fusion-data-updated', this.updateData ); // Listen for preview toggle. this.listenTo( FusionEvents, 'fusion-preview-toggle', this.previewToggle ); this.previewMode = false; // Listen for preview update to set some global styles. this.listenTo( FusionEvents, 'fusion-preview-update', this.setGlobalStyles ); // Listen for frame resizes and sets helper class for CSS. this.listenTo( FusionEvents, 'fusion-preview-resize', this.setStackedContentClass ); this.listenTo( FusionEvents, 'fusion-to-content_break_point-changed', this.setStackedContentClass ); // Listen for header_position option change. this.listenTo( FusionEvents, 'fusion-to-header_position-changed', this.reInitScrollingSections ); this.listenTo( window.FusionEvents, 'fusion-preferences-droppables_visible-updated', this.toggleDroppablesVisibility ); this.listenTo( window.FusionEvents, 'fusion-preferences-sticky_header-updated', this.toggleStickyHeader ); this.listenTo( window.FusionEvents, 'fusion-preferences-tooltips-updated', this.toggleTooltips ); this.listenTo( window.FusionEvents, 'fusion-preferences-element_filters-updated', this.toggleElementFilters ); this.listenTo( window.FusionEvents, 'fusion-preferences-transparent_header-updated', this.toggleTransparentHeader ); this.listenTo( window.FusionEvents, 'fusion-preferences-styling_mode-updated', this.toggleDarkMode ); this.listenTo( window.FusionEvents, 'fusion-preferences-element_transform-updated', this.toggleElementTransform ); this.listenTo( window.FusionEvents, 'fusion-preferences-options_subtabs-updated', this.optionsSubTabs ); // Listen to the fusion-content-changed event and re-trigger sticky header resize. this.listenTo( FusionEvents, 'fusion-content-changed', function() { fusionTriggerEvent( 'fusion-resize-stickyheader' ); } ); this.listenTo( FusionEvents, 'fusion-builder-loaded', this.fusionLibraryUI ); // Base64 encode/decode. this._keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; // Make sure to delay ajax requests to prevent duplicates. this._fusion_do_shortcode = _.debounce( _.bind( FusionApp.callback.fusion_do_shortcode, this ), 300 ); this.blankPage = false; this.render(); this.reRenderElements = false; this.contextMenuView = false; this.clipboard = {}; // Stored latest shortcode content to avoid unnecessary ajax. this.lastAjaxCid = false; this.ajaxContentRequests = []; // DiffDOM this._diffdom = new diffDOM( { valueDiffing: false } ); jQuery( jQuery( '#fb-preview' )[ 0 ].contentWindow ).on( 'resize', function() { FusionEvents.trigger( 'fusion-preview-resize' ); } ); jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( 'body' ).on( 'click', function( event ) { FusionPageBuilderApp.sizesHide( event ); } ); this.correctTooltipPosition(); this.loaded = false; this.shortcodeAjax = false; this.inlineElements = [ 'fusion_highlight', 'fusion_tooltip', 'fusion_dropcap', 'fusion_popover', 'fusion_one_page_text_link', 'fusion_modal_text_link' ]; this.documentWrite = false; this.previewDocumentWrite = false; this.viewsToRerender = []; this.listenTo( FusionEvents, 'fusion-data-updated', this.resetRenderVariable ); this.mediaMap = { images: {}, menus: {}, forms: {}, post_cards: {}, videos: {}, icons: {}, off_canvases: {} }; this.listenTo( FusionEvents, 'fusion-content-preview-width', this.contentPreviewWidth ); this.listenTo( FusionEvents, 'fusion-content-preview-background-color', this.contentPreviewBackgroundColor ); this.listenTo( FusionEvents, 'fusion-mega-menu-width', this.megaManueWidth ); this.contentPreviewBackgroundColor(); }, resetRenderVariable: function() { this.reRenderElements = false; }, /** * Gets callback function for option change. * * @since 2.0.0 * @param {Object} modelData - The model data. * @param {string} paramName - Parameter name. * @param {mixed} paramValue - The value of the defined parameter. * @param {Object} view - The view object. * @param {boolean} skip - If set to true we bypass changing the parameter in this view. * @return {Object} */ getCallbackFunction: function( modelData, paramName, paramValue, view, skip ) { var element = fusionAllElements[ view.model.get( 'element_type' ) ], option = element.params[ paramName ], callbackFunction, thisView; // Check if it is subfield. if ( 'undefined' === typeof option && 'undefined' !== typeof element.subparam_map && 'undefined' !== typeof element.subparam_map[ paramName ] ) { option = element.params[ element.subparam_map[ paramName ] ]; } if ( 'undefined' !== typeof modelData.noTemplate && modelData.noTemplate ) { // No template, we need to use fusion_do_shortcode. callbackFunction = {}; callbackFunction.ajax = true; callbackFunction[ 'function' ] = 'fusion_do_shortcode'; skip = 'undefined' === typeof skip ? false : skip; thisView = FusionPageBuilderViewManager.getView( modelData.cid ); if ( ! skip ) { thisView.changeParam( paramName, paramValue ); } if ( 'undefined' !== typeof modelData.multi && false !== modelData.multi ) { // Parent or child element, get the parent total content. callbackFunction.parent = this.getParentElementCid( modelData ); callbackFunction.content = this.getParentElementContent( modelData, view ); } else { // Regular element, just get element content. callbackFunction.parent = false; callbackFunction.content = FusionPageBuilderApp.generateElementShortcode( thisView.$el ); } } else { callbackFunction = this.CheckIfCallback( element, option, view.model ); } return callbackFunction; }, getParentElementCid: function( modelData ) { if ( 'multi_element_child' === modelData.multi ) { // Child, return parent value. return modelData.parent; } // Parent, return cid. return modelData.cid; }, getParentElementContent: function( modelData, view ) { var parentView; if ( 'multi_element_child' === modelData.multi ) { // Child, update parent and get total content. parentView = FusionPageBuilderViewManager.getView( modelData.parent ); parentView.updateElementContent(); return parentView.getContent(); } // Already on parent, get full content. return view.getContent(); }, /** * Check if the element has a callback. * * @since 2.0.0 * @param {Object} element - The element. * @param {Object} option - The option. * @param {Object} model - The model. * @return {Object} - Returns the callback, or empty object if none is defined. */ CheckIfCallback: function( element, option, model ) { // First check if the option has a callback if ( 'undefined' !== typeof option && 'undefined' !== typeof option.callback ) { return option.callback; } // Check if the element itself has a callback and query_data is empty. if ( 'undefined' !== typeof element && 'undefined' !== typeof element.callback && 'undefined' === typeof model.attributes.query_data ) { return element.callback; } return {}; }, /** * Set some global styles in a style tag added to body. * * @since 2.0.0 * @return {void} */ setGlobalStyles: function( id, setAll ) { var styles = '', setAllStyles = false, margin = 0; if ( 'undefined' !== typeof setAll ) { setAllStyles = setAll; } else if ( 'undefined' === typeof id ) { setAllStyles = true; } // Container outline and controls positioning. if ( 'hundredp_padding' === id || setAllStyles ) { margin = fusionGetPercentPaddingHorizontalNegativeMargin(); margin = fusionGetPercentPaddingHorizontalNegativeMarginIfSiteWidthPercent( 0, margin ); // If we are editing content nested inside a layout section, then no negative margins on containers. if ( 'object' === typeof FusionApp.data.template_override && 'object' === typeof FusionApp.data.template_override.content && 'fusion_tb_section' !== FusionApp.data.postDetails.post_type ) { margin = 0; } styles += 'body:not(.has-sidebar) .width-100 .fusion-builder-container:before,'; styles += 'body:not(.has-sidebar) .width-100 .fusion-builder-container:after,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container:hover > .fusion-builder-module-controls-container-wrapper,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-container-spacing.fusion-container-margin-top,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-container-spacing.fusion-container-margin-bottom,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-container-spacing.fusion-container-padding-top,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-container-spacing.fusion-container-padding-bottom,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-container-spacing.fusion-container-padding-right'; styles += '{margin-left:' + margin + ';margin-right:' + margin + '}'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-container-spacing.fusion-container-padding-left{margin-left:' + margin + ';}'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-container-spacing.fusion-container-padding-right{margin-right:' + margin + ';}'; // Flex styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-flex-container .fusion-container-spacing.fusion-container-padding-left{margin-left:0;}'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-flex-container .fusion-container-spacing.fusion-container-padding-right{margin-right:0;}'; styles += 'body:not(.has-sidebar) .width-100 .fusion-builder-container:before,'; styles += 'body:not(.has-sidebar) .width-100 .fusion-builder-container:after,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container:hover > .fusion-builder-module-controls-container-wrapper,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-flex-container .fusion-container-spacing.fusion-container-margin-top,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-flex-container .fusion-container-spacing.fusion-container-margin-bottom,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-flex-container .fusion-container-spacing.fusion-container-padding-top,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-flex-container .fusion-container-spacing.fusion-container-padding-bottom,'; styles += '.fusion-builder-live .width-100 .fusion-builder-container .fusion-flex-container .fusion-container-spacing.fusion-container-padding-right'; styles += '{margin-left:' + 0 + ';margin-right:' + 0 + '}'; } if ( styles ) { if ( ! this.$el.children( 'style' ).length ) { this.$el.prepend( '' ); } this.$el.children( 'style' ).html( styles ); } }, /** * Corrects the position of tooltips that would overflow the viewport. * * @since 2.0.0 * @return {void} */ correctTooltipPosition: function() { var self = this; this.$el.on( 'mouseenter', '.fusion-builder-module-controls-type-container a, .fusion-builder-column-controls a, .fusion-builder-module-controls a, a.fusion-builder-add-element', function() { var anchorWidth = jQuery( this ).outerWidth(), tooltip = jQuery( this ).children( '.fusion-container-tooltip, .fusion-column-tooltip, .fusion-element-tooltip' ), tooltipWidth, tooltipOffset, tooltipOffsetLeft, tooltipOffsetRight, referenceWrapper, referenceWrapperOffsetLeft, referenceWrapperOffsetRight; if ( ! tooltip.length ) { return; } if ( jQuery( this ).closest( '.fusion-has-filters, .awb-sticky' ).length ) { return; } tooltip.children( '.fusion-tooltip-text' ).removeAttr( 'style' ); tooltipWidth = tooltip.outerWidth(); tooltipOffset = tooltip.offset(); tooltipOffsetLeft = tooltipOffset.left; tooltipOffsetRight = tooltipOffsetLeft + tooltipWidth; referenceWrapperOffsetLeft = 0; referenceWrapperOffsetRight = self.$el.width(); jQuery( this ).closest( '.fusion-fullwidth:not(.video-background):not(.has-pattern-background):not(.has-mask-background) .fusion-row' ).css( 'z-index', 'auto' ); jQuery( this ).closest( '.fusion-fullwidth:not(.video-background):not(.has-pattern-background):not(.has-mask-background)' ).children( '.fullwidth-faded' ).css( 'z-index', 'auto' ); jQuery( this ).closest( '.fusion-fullwidth:not(.video-background):not(.has-pattern-background):not(.has-mask-background)' ).children( '.awb-background-slider' ).css( 'z-index', '0' ); if ( ! jQuery( this ).closest( '.fusion-element-alignment-left' ).length && ! jQuery( this ).closest( '.fusion-element-alignment-right' ).length ) { jQuery( this ).closest( '.fusion-builder-container' ).css( 'z-index', 'auto' ); } // Carousels need different positioning. referenceWrapper = tooltip.closest( '.fusion-carousel-wrapper' ); if ( referenceWrapper.length ) { referenceWrapperOffsetLeft = referenceWrapper.offset().left; referenceWrapperOffsetRight = referenceWrapperOffsetLeft + referenceWrapper.outerWidth(); } if ( tooltipOffsetLeft < referenceWrapperOffsetLeft ) { tooltip.children( '.fusion-tooltip-text' ).css( 'margin-left', ( ( tooltipWidth / 2 ) + anchorWidth ) + 'px' ); } else if ( tooltipOffsetRight > referenceWrapperOffsetRight ) { tooltip.children( '.fusion-tooltip-text' ).css( 'margin-left', 'calc(' + anchorWidth + 'px - ' + tooltipWidth + 'px)' ); } if ( jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '.fusion-footer-parallax' ).length ) { jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '#main' ).css( 'z-index', 'auto' ); if ( 'fixed' === jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '.fusion-footer-parallax' ).css( 'position' ) ) { jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '.fusion-footer-parallax' ).css( 'z-index', '-1' ); if ( jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '#sliders-container' ).find( '.tfs-slider[data-parallax="1"]' ).length ) { jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '#sliders-container' ).css( 'z-index', 'auto' ); } } } } ); this.$el.on( 'mouseleave', '.fusion-builder-module-controls-container a', function() { var parentElement = jQuery( this ).closest( '.fusion-builder-module-controls-container' ).parent( '.fusion-builder-live-element' ); if ( ! parentElement.length || ! parentElement.find( '.fusion-modal.in' ).length ) { jQuery( this ).closest( '.fusion-row' ).css( 'z-index', '' ); jQuery( this ).closest( '.fusion-builder-container' ).css( 'z-index', '' ); if ( jQuery( this ).closest( '.fusion-fullwidth' ).find( '.awb-background-slider' ).length ) { jQuery( this ).closest( '.fusion-fullwidth' ).find( '.awb-background-slider' ).css( 'z-index', '' ); } } if ( jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '.fusion-footer-parallax' ).length ) { jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '#main' ).css( 'z-index', '' ); jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '.fusion-footer-parallax' ).css( 'z-index', '' ); jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '#sliders-container' ).css( 'z-index', '' ); } } ); }, /** * Renders the view. * * @since 2.0.0 * @return {Object} this */ render: function() { this.$el.find( '.fusion-builder-live-editor' ).html( this.template() ); // Make sure context menu is available. this.delegateEvents(); this.setStackedContentClass(); return this; }, /** * Store shortcode data. * * @since 2.0.0 * @return {void} */ updateData: function() { var self = this; this.elements.components.forEach( function( component, index ) { var re = new RegExp( '\\[' + component.label, 'g' ); if ( 'string' === typeof FusionApp.data.template_category && ( 'object' !== typeof component.templates || component.templates.includes( FusionApp.data.template_category ) ) ) { self.elements.componentsCounter++; } } ); this.extraShortcodes.addData( FusionApp.data.shortcodeMap ); this.dynamicValues.addData( FusionApp.initialData.dynamicValues, FusionApp.data.dynamicOptions ); }, convertGalleryElement: function( content ) { var regExp = window.wp.shortcode.regexp( 'fusion_gallery' ), innerRegExp = this.regExpShortcode( 'fusion_gallery' ), matches = content.match( regExp ), newContent = content, fetchIds = []; if ( matches ) { _.each( matches, function( shortcode ) { var shortcodeElement = shortcode.match( innerRegExp ), shortcodeAttributes = '' !== shortcodeElement[ 3 ] ? window.wp.shortcode.attrs( shortcodeElement[ 3 ] ) : '', children = '', newShortcode = '', ids; // Check for the old format shortcode if ( 'undefined' !== typeof shortcodeAttributes.named.image_ids ) { ids = shortcodeAttributes.named.image_ids.split( ',' ); // Add new children shortcodes _.each( ids, function( id ) { children += '[fusion_gallery_image image="" image_id="' + id + '" /]'; fetchIds.push( id ); } ); // Add children shortcodes, remove image_ids attribute. newShortcode = shortcode.replace( '/]', ']' + children + '[/fusion_gallery]' ).replace( 'image_ids="' + shortcodeAttributes.named.image_ids + '" ', '' ); // Replace the old shortcode with the new one newContent = newContent.replace( shortcode, newShortcode ); } } ); // Fetch attachment data if ( 0 < fetchIds.length ) { wp.media.query( { post__in: fetchIds, posts_per_page: fetchIds.length } ).more(); } } return newContent; }, /** * Converts the shortcodes to builder elements. * * @since 2.0.0 * @param {string} content - The content. * @return {void} */ createBuilderLayout: function( content ) { var self = this; if ( FusionApp.data.is_fusion_element && 'mega_menus' !== FusionApp.data.fusion_element_type ) { content = self.validateLibraryContent( content ); } content = this.convertGalleryElement( content ); this.shortcodesToBuilder( content ); this.builderToShortcodes(); setTimeout( function() { self.scrollingContainers(); self.maybeFormStyles(); self.maybeOfCanvasStyles(); }, 100 ); }, /** * Validate library content. * * @since 2.0.0 * @param {string} content - The content. * @return {string} */ validateLibraryContent: function( content ) { var contentIsEmpty = '' === content, openContainer = '[fusion_builder_container type="flex" hundred_percent="no" flex_column_spacing="' + FusionApp.settings.col_spacing + '" equal_height_columns="no" menu_anchor="" hide_on_mobile="small-visibility,medium-visibility,large-visibility" class="" id="" background_color="" background_image="" background_position="center center" background_repeat="no-repeat" fade="no" background_parallax="none" parallax_speed="0.3" video_mp4="" video_webm="" video_ogv="" video_url="" video_aspect_ratio="16:9" video_loop="yes" video_mute="yes" overlay_color="" overlay_opacity="0.5" video_preview_image="" border_size="" border_color="" border_style="solid" padding_top="" padding_bottom="" padding_left="" padding_right=""][fusion_builder_row]', closeContainer = '[/fusion_builder_row][/fusion_builder_container]', openColumn = '[fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" border_position="all" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="small-visibility,medium-visibility,large-visibility" center_content="no" last="no" min_height="" hover_type="none" link=""]', closeColumn = '[/fusion_builder_column]', columnEdit = 'columns' === FusionApp.data.fusion_element_type || 'post_cards' === FusionApp.data.fusion_element_type, elementEdit = 'elements' === FusionApp.data.fusion_element_type, containerEdit = 'sections' === FusionApp.data.fusion_element_type; // The way it is setup now, we dont want blank page template on library items. if ( columnEdit && '[fusion_builder_blank_page][/fusion_builder_blank_page]' === content ) { content = openColumn + closeColumn; contentIsEmpty = false; } if ( elementEdit && '[fusion_builder_blank_page][/fusion_builder_blank_page]' === content ) { content = ''; contentIsEmpty = true; } if ( containerEdit && '[fusion_builder_blank_page][/fusion_builder_blank_page]' === content ) { content = openContainer + closeContainer; contentIsEmpty = false; } if ( ! contentIsEmpty ) { // Editing element if ( elementEdit ) { content = openContainer + openColumn + content + closeColumn + closeContainer; } else if ( columnEdit ) { content = openContainer + content + closeContainer; } } else { // If library element is blank if ( elementEdit ) { // eslint-disable-line no-lonely-if content = openContainer + openColumn + closeColumn + closeContainer; } } function replaceDollars() { return '$$'; } content = content.replace( /$$/g, replaceDollars ); return content; }, /** * Convert library content to shortcodes. * * @since 2.0.0 * @return {void} */ libraryBuilderToShortcodes: function() { var shortcode = '', cid, view, element; // Editing an element. if ( 'elements' === FusionApp.data.fusion_element_type ) { // Inner row. element = this.$el.find( '.fusion-builder-column-outer .fusion_builder_row_inner' ); if ( element.length ) { cid = element.data( 'cid' ); view = FusionPageBuilderViewManager.getView( cid ); shortcode = view.getInnerRowContent(); // Regular element. } else if ( this.$el.find( '.fusion-builder-live-element' ).length ) { element = this.$el.find( '.fusion-builder-live-element' ); shortcode = FusionPageBuilderApp.generateElementShortcode( this.$el.find( '.fusion-builder-live-element' ), false ); } if ( element.length ) { this.$el.find( '.fusion-builder-column .fusion-builder-add-element' ).hide(); } // Editing a column. } else if ( 'columns' === FusionApp.data.fusion_element_type || 'post_cards' === FusionApp.data.fusion_element_type ) { element = this.$el.find( '.fusion-builder-column-outer' ); if ( element.length ) { cid = element.data( 'cid' ); view = FusionPageBuilderViewManager.getView( cid ); shortcode = view.getColumnContent(); } // Editing a container. } else if ( 'sections' === FusionApp.data.fusion_element_type ) { element = this.$el.find( '.fusion-builder-container' ); if ( element.length ) { cid = element.data( 'cid' ); view = FusionPageBuilderViewManager.getView( cid ); shortcode = view.getContent(); } } FusionApp.setPost( 'post_content', shortcode ); this.navigator.update(); }, /** * Build the initial layout for the builder. * * @since 2.0.0 * @param {Object} data - The data. * @param {Object} data.fusionGlobalManager - The FusionPageBuilder.Global object. * @param {string} data.postContent - The post-content. * @return {void} */ initialBuilderLayout: function( data ) { var self = this; // Clear all views FusionPageBuilderViewManager.removeViews(); this.postContent = data.postDetails.post_content; this.postID = data.postDetails.post_id; // Add data for exta shortcodes. self.updateData( data ); setTimeout( function() { var content = self.postContent, contentErrorMarkup = '', contentErrorTitle = '', moreDetails = fusionBuilderText.unknown_error_link; try { self.setGlobalStyles( '', true ); content = self.convertGalleryElement( content ); if ( ! FusionApp.data.is_fusion_element || 'mega_menus' === FusionApp.data.fusion_element_type ) { content = self.validateContent( content ); } else { content = self.validateLibraryContent( content ); } self.shortcodesToBuilder( content ); // Add data for exta shortcodes. self.updateData( data ); setTimeout( function() { self.scrollingContainers(); self.reRenderElements = true; self.maybeFormStyles(); self.maybeOfCanvasStyles(); if ( 0 < FusionPageBuilderViewManager.countElementsByType( 'fusion_builder_next_page' ) ) { FusionEvents.trigger( 'fusion-next-page' ); } self.loaded = true; FusionEvents.trigger( 'fusion-builder-loaded' ); }, 100 ); } catch ( error ) { console.log( error ); // jshint ignore:line if ( 'undefined' !== error.name && 'ContentException' === error.name ) { contentErrorTitle = fusionBuilderText.content_error_title; contentErrorMarkup = jQuery( '
' + fusionBuilderText.content_error_description + '
' ); } else { contentErrorTitle = fusionBuilderText.unknown_error_title; // If we have full stack use that rather than external link. if ( 'string' === typeof error.stack ) { moreDetails = '' + fusionBuilderText.unknown_error_copy + ''; } contentErrorMarkup = jQuery( '
' + error + '

' + moreDetails + '

' ); } contentErrorMarkup.dialog( { title: contentErrorTitle, dialogClass: 'fusion-builder-dialog fusion-builder-error-dialog fusion-builder-settings-dialog', autoOpen: true, modal: true, width: 400, open: function() { if ( jQuery( this ).find( '.copy-full-description' ).length ) { jQuery( this ).find( '.copy-full-description' ).on( 'click', function( event ) { var $temp = jQuery( '