Ubuntu

­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ /** * ********************* * * mBuilder Composer * * ********************* * mBuilder is a visual editor for shortcodes and makes working with shortcodes more easier and fun. * It is added as a part of Massive Dynamic since V3.0.0 and designed to work with customizer. Enjoy Editing ;) * * @summary mBuilder provides some functionality for editing shortcodes in customizer. * * @author PixFlow * * @version 1.0.0 * @requires jQuery, jQuery.ui * * @class * @classdesc initialize all of the mBuilder features. */ var mBuilder = function () { // All shortcode attributes and contents stored in models, and should update after editing if (typeof mBuilderModels == 'undefined') { mBuilderModels = {}; mBuilderModels.models = {} } this.models = mBuilderModels; this.lock = false; // All available shortcodes this.shortcodes = mBuilderShortcodes; this.settingPanel = null; // Defines droppable areas for drop shortcodes this.droppables = '' + '.vc_column_container,' + '.wpb_accordion_content,' + '.wpb_toggle_content,' + '.wpb_tour_tabs_wrapper,' + '.wpb_tab'; // Container shortcodes this.containers = { 'md_accordion_tab': '> .wpb_accordion_section > .wpb_accordion_content', 'md_toggle_tab': '> .wpb_accordion_section > .wpb_toggle_content', 'md_toggle_tab2': '> .wpb_accordion_section > .wpb_toggle_content', 'md_tab': '> .wpb_tab', 'md_tabs': "> .wpb_tabs > .wpb_wrapper", 'md_modernTab': "> .wpb_tab", 'md_modernTabs': "> .wpb_tabs > .wpb_wrapper", 'vc_column': '> .wpb_column > .vc_column-inner> .wpb_wrapper', 'vc_column_inner': '> .wpb_column > .vc_column-inner> .wpb_wrapper', 'md_hor_tab': "> .wpb_tab", 'md_hor_tabs': "> .wpb_tabs > .wpb_wrapper", 'md_hor_tab2': "> .wpb_tab", 'md_hor_tabs2': "> .wpb_tabs > .wpb_wrapper", }; //Tab Shortcodes this.tabs = { 'md_tabs': ['md_tab', '
  • Tab
  • '], 'md_modernTabs': ['md_modernTab', '
  • Tab
  • '], 'md_hor_tabs': ['md_hor_tab', '
  • Tab
  • '], 'md_hor_tabs2': ['md_hor_tab2', '
  • Tab
  • '], }; //Full shortcodes this.fullShortcodes = [ 'md_team_member_classic', 'vc_empty_space', 'md_button', 'md_call_to_action', 'md_imagebox_full', 'md_portfolio_multisize', 'md_showcase', 'md_blog', 'md_blog_carousel', 'md_client_normal', 'md_instagram', 'md_blog_masonry', 'md_process_steps', 'md_teammember2', 'pixflow_subscribe', 'md_pricetabel', 'md_google_map', 'md_masterslider', 'md_rev_slider', 'md_blog_classic', 'vc_facebook', 'vc_tweetmeme', 'vc_pinterest', 'vc_gmaps', 'vc_round_chart', 'vc_line_chart', 'md_product_categories', 'md_products', 'md_textbox', 'md_full_button', 'md_testimonial_classic', 'md_client_carousel', 'md_fancy_text', 'md_iconbox_side', 'md_iconbox_side2', 'md_slider', 'md_testimonial_carousel', 'md_modern_subscribe', 'md_double_slider', 'md_skill_style2', 'md_slider_carousel', 'md_slider', 'md_text_box' ]; //used in shortcodeTag method this.compiledTags = []; var isLocal = $.ui.tabs.prototype._isLocal; $.ui.tabs.prototype._isLocal = function (anchor) { return true; }; this.save_callback_function = null; this.customSection = []; this.should_close_shortcode_setting_panel = true ; this.selected_shortcode_id = '' ; this.shortcodes_param = {} ; this.make_links_target_blank(); this.event_drivens(); this.renderControls(); this.addEvents(); this.setSortable(); this.mediaPanel(); this.multiMediaPanel(); this.dropdown(); this.googleFontPanel(); this.shortcode_panel_functionality(); this.set_parents(); this.preview_mode(); this.on_before_unload(); this.getEditorFonts(); this.getCustomSection(); this.createSectionSource(); this.shortcode_panel_drop_shortcodes(); }; /** * @summary makes shortcodes sortable. * * @since 1.0.0 */ mBuilder.prototype.setSortable = function () { "use strict"; var t = this, lastObj = null; var fly = null; $('.mBuilder-overlay,.mBuilder-overlay-holder').remove(); var d = $('
    ').appendTo('body'), overlay = $('
    ').appendTo('body'), direction = 'down', overEmpty = false, overs = $, helper; overlay.click(function () { d.css('width', ''); overlay.css('display', 'none'); }); $('.mBuilder-element:not(.vc_row,.mBuilder-vc_column)').draggable({ zIndex: 999999, helper: 'clone', appendTo: '.layout', delay: 300, containment: [$('.layout').offset().left, $('.layout').offset().top, $('.layout').offset().left+$('.layout').width(), $('.layout').offset().top+$('.layout').height()], scroll: false, items: ":not(.disable-sort)", start: function (event, ui) { t.removeColumnSeparator(); $('.layout').css('overflow','hidden'); ui.helper.css({ width: $(this).width(), height: $(this).height() }); clearInterval(fly); var that = this; if ($(this).hasClass("mBuilder-md_portfolio_multisize")) { ui.helper.addClass("portfolio-draged"); } setTimeout(function () { overs = $('.mBuilder-element:not(.vc_row,.mBuilder-vc_column),.vc_empty-element') .not(ui.helper) .not(ui.helper.find('.mBuilder-element:not(.vc_row,.mBuilder-vc_column),.vc_empty-element')) .not($(that).find('.mBuilder-element:not(.vc_row,.mBuilder-vc_column),.vc_empty-element')); }, 100); $(this).addClass('ui-sortable-helper'); overlay.css('display', 'block'); }, drag: function (event) { clearInterval(fly); if (event.clientY < 100) { fly = setInterval(function () { if($(window).scrollTop()==0){ clearInterval(fly); } $(window).scrollTop($(window).scrollTop() - 50) }, 50); } else if (event.clientY > $(window).height() - 50) { fly = setInterval(function () { if($(window).scrollTop()>=$(document).height()-$(window).height()){ clearInterval(fly); } $(window).scrollTop($(window).scrollTop() + 50) }, 50); } var el = null; overs.each(function () { if ( $(this).css('display') != 'none' && event.pageY > $(this).offset().top && event.pageY < $(this).offset().top + $(this).outerHeight() && event.pageX > $(this).offset().left && event.pageX < $(this).offset().left + $(this).outerWidth() ) { el = this; } }); if (el) { overEmpty = false; var obj = $(el); if (el != this && obj.length && !obj.hasClass('vc_empty-element')) { if (t.containers[obj.attr('data-mbuilder-el')] && !obj.find('.mBuilder-element').length) { overEmpty = true; } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); } } else { overEmpty = true; } var objTop = obj.offset().top, objLeft = obj.offset().left, objHeight = obj.outerHeight(), objWidth = obj.outerWidth(), objHalf = objTop + objHeight / 2; if (lastObj) { lastObj.css({'transform': ''}) } if (!overEmpty) { if (event.pageY < objHalf) { obj.not('.vc_row').css({'transform': 'translateY(5px)'}); d.css({'top': objTop, 'left': objLeft, width: objWidth, height: 5, background: ''}); direction = 'up'; } else { obj.not('.vc_row').css({'transform': 'translateY(-5px)'}); d.css({'top': objTop + objHeight, 'left': objLeft, width: objWidth, height: 5, background: ''}); direction = 'down'; } } else { d.css({ 'top': objTop, 'left': objLeft, height: objHeight, width: objWidth, background: 'rgba(136,206,255,0.4)', border: 'solid 2px #8fcbff' }); } lastObj = obj; } else { if (lastObj) { lastObj.css({'transform': ''}) } lastObj = null; d.css({width: '', border: ''}); } }, stop: function (event, ui) { $('.layout').css('overflow',''); t.removeColumnSeparator(); try { if (ui.helper.hasClass("portfolio-draged")) { ui.helper.removeClass("portfolio-draged"); } clearInterval(fly); $(this).removeClass('ui-sortable-helper'); if (!lastObj || !lastObj.length) { d.css({'width': '', border: ''}); setTimeout(function () { overlay.css('display', 'none'); }, 300); return; } if (direction == 'up') { if (lastObj.hasClass('vc_empty-element')) { var p = lastObj.find('.wpb_wrapper'); } else if (t.containers[lastObj.attr('data-mbuilder-el')] && overEmpty) { var p = lastObj.find(t.containers[lastObj.attr('data-mbuilder-el')]); } else { var p = lastObj.prev('.insert-between-placeholder'); if (!p.length) { var p = lastObj.parent().closest('.mBuilder-element').prev('.insert-between-placeholder'); } } } else { if (lastObj.hasClass('vc_empty-element')) { var p = lastObj.find('.wpb_wrapper'); } else if (t.containers[lastObj.attr('data-mbuilder-el')] && overEmpty) { var p = lastObj.find(t.containers[lastObj.attr('data-mbuilder-el')]); } else { var p = lastObj.next('.insert-between-placeholder'); if (!p.length) { var p = lastObj.parent().closest('.mBuilder-element').next('.insert-between-placeholder'); } } } var placeholder = p.get(0); if (placeholder != null) { if ($(this).closest('.vc_column_container').find('.mBuilder-element').not($(this).find('.mBuilder-element')).length < 2 && lastObj.get(0) != this) { $(this).closest('.vc_column_container').addClass('vc_empty-element'); } if (lastObj.hasClass('vc_empty-element')) { $(this).appendTo(placeholder); lastObj.removeClass('vc_empty-element') } else { if (!$(this).find(placeholder).length) { if (t.containers[lastObj.attr('data-mbuilder-el')] && overEmpty) { p.html(''); $(this).appendTo(placeholder); } else { $(this).insertAfter(placeholder); } } } setTimeout(function () { t.createPlaceholders(); }, 100); $('body').addClass('changed'); } d.css({'width': '', border: ''}); setTimeout(function () { overlay.css('display', 'none'); }, 300); } catch (e) { console.log(e); d.css({'width': '', border: ''}); setTimeout(function () { overlay.css('display', 'none'); }, 300); } $(window).resize(); } }); // Row movement $(".content-container,.post-content").sortable({ cursor: "move", delay: 100, cancel: ".disable-sort", handle: ".mBuilder_row_move", items: ".vc_row", update: function (event, ui) { $('body').addClass('changed'); t.createPlaceholders(); }, start : function () { builder.mBuilder_closeShortcodeSetting(); } }); //$(".content-container").disableSelection(); }; /** * @summary add shortcode controllers for edit,delete,clone and etc. * * @since 1.0.0 */ mBuilder.prototype.renderControls = function () { var t = this; var countTiny = 0; $('body').addClass('compose-mode'); var settingSvg = '', duplicateSvg = '', deleteSvg = '', leftAlignSvg = '', centerAlignSvg = '', rightAlignSvg = '', optionSvg = '', col1_1Svg = '', col1_2Svg = '', col1_3Svg = '', col1_4Svg = '', col2_4Svg = '', col3_4Svg = '', col3_9Svg = '', layoutSvg = '', moveSvg = '', rowSettingSvg = '', rowDeleteSvg = '', saveSection = ''+ ''+ '' + '' + '' + ''+ ''; $('.mBuilder-element').not('.vc_row, .vc_row_inner,.mBuilder-vc_row_inner,.mBuilder-vc_column,.mBuilder-vc_column_inner').each(function () { var $this = $(this); if ($this.hasClass('mBuilder-md_tabs') || $this.hasClass('mBuilder-md_toggle') || $this.hasClass('mBuilder-md_accordion') || $this.hasClass('mBuilder-md_modernTabs') || $this.hasClass('mBuilder-md_hor_tabs') || $this.hasClass('mBuilder-md_toggle2') || $this.hasClass('mBuilder-md_hor_tabs2')) { if (!$this.find('.tabs-family').length) { var html = '
    ' + '
    ' + moveSvg + '
    ' + '
    ' + settingSvg + '
    ' + '
    ' + deleteSvg + '
    ' + '
    '; $this.append(html); } } else if (!$this.find('.mBuilder_controls').length) { if ($this.hasClass('mBuilder-md_tab') || $this.hasClass('mBuilder-md_toggle_tab') || $this.hasClass('mBuilder-md_accordion_tab') || $this.hasClass('mBuilder-md_modernTab') || $this.hasClass('mBuilder-md_hor_tab') || $this.hasClass('mBuilder-md_toggle_tab2') || $this.hasClass('mBuilder-md_hor_tab2')) { var html = '
    ' + '
    ' + settingSvg + '
    ' + '
    ' + deleteSvg + '
    '; html += '
    '; $this.append(html); } else { var el = $this.attr('data-mbuilder-el'), fullClass = ''; if (t.fullShortcodes.indexOf(el) != -1) { fullClass = 'md-full-shortcode-gizmo'; } var $elem = $this; if ($this.find('.gizmo-container').length) { $elem = $this.find('.gizmo-container').first(); } if( el == 'md_live_text' ){ $elem = $this.find('.live-text-container'); } var container_class='settings-holder inside-shortcode'; if ($this.hasClass('mBuilder-md_portfolio_multisize')){ container_class = 'settings-holder'; } var html = '
    ' + '' + '' + '' + '' + ''; html += '
    ' $elem.append(html); } } if (t.shortcodes[$this.attr('data-mbuilder-el')] && t.shortcodes[$this.attr('data-mbuilder-el')].as_parent) { if (!$this.find(' > .mBuilder_controls [data-control="add_section"]').length) { var btn = $(''); var link = $(''); link.append(btn); $this.find(' > .mBuilder_controls').append(link); var child = t.shortcodes[$(this).attr('data-mbuilder-el')].as_parent['only']; btn.click(function () { t.buildShortcode(this, child); }) } } }); $('.mBuilder-element.vc_row,.vc_row.vc_inner').each(function () { var $this = $(this); if (!$this.find('> .mBuilder_row_controls ').length) { $this.find('>.wrap').after(''+ '
    '+ '
    '+ '' + layoutSvg + ''+ '
    '+ '' + col1_1Svg + ' '+ '' + col1_2Svg + ' '+ '' + col1_3Svg + ''+ '' + col1_4Svg + ''+ '' + col2_4Svg + ''+ '' + col3_4Svg + ''+ '' + col3_9Svg + ''+ '
    '+ ''+ '
    '+ '
    '+ ''+ '
    ' + moveSvg + '
    '+ ''+ ''+ ''+ ''+ '
    '+ ''); } var layoutValue=''; $this.find('>.wrap >.mBuilder-vc_column').each(function(){ var row_str = $(this).attr("class"); var array_row_str = row_str.match(/col-sm-([0-9]+)/); layoutValue += (array_row_str[1] + '/12+'); }); $this.find('> .mBuilder_row_controls input[name="cols"]').val(layoutValue.substr(0,layoutValue.length-1)); if (!$this.hasClass('vc_inner')) { if (!$this.find('> .row_border ').length) { $this.append('
    '); } }else{ $this.append('
    '); } }); $('.mBuilder-vc_column,.mBuilder-vc_column_inner').each(function () { var itemClass = ($(this).hasClass('mBuilder-vc_column')) ? 'element-vc_column' : 'element-vc_column_inner'; if (!$(this).find('> .vc_column_container > .mbuilder-column-options').length) { $(this).find(' > .vc_column_container').append('
    ' + '' + '
    ' + 'Column Setting'+ 'Design' + 'Spacing' + 'Responsive' + '
    '+ ''+ '
    ' ); } if (!$(this).find('> .column-left-space').length){ $(this).append('
    '); } if (!$(this).find('> .column-right-space').length){ $(this).append('
    '); } }); for (var i in this.fullShortcodes) { $('.mBuilder-element[data-mbuilder-el="' + this.fullShortcodes[i] + '"]').find('.vc_control-btn-align').remove(); $('.mBuilder-element[data-mbuilder-el="' + this.fullShortcodes[i] + '"]').find('.vc_control-btn-edit').css('left', -99); $('.mBuilder-element[data-mbuilder-el="' + this.fullShortcodes[i] + '"]').find('.vc_control-btn-clone').css('left', 3); $('.mBuilder-element[data-mbuilder-el="' + this.fullShortcodes[i] + '"]').find('.vc_control-btn-delete').css('left', 105); } this.createPlaceholders(); $('body').trigger('render_control_finished'); }; /** * @summary add event to add section controllers for opening the section type * * @since 5.0 */ mBuilder.prototype.bind_section_events = function(){ $('body').on('click', '.section-open' , function(e){ e.stopPropagation(); }); $('body').on('click', '.add-section' , function(e){ e.stopPropagation(); builder.open_pixflow_shortcode_panel('sections'); var placeholder = $(this).parents('.vc_row').next(); placeholder.toggleClass('section-open'); if( ! placeholder.hasClass('section-open') ){ $('.section-open').removeClass('section-open'); builder.close_pixflow_shortcode_panel(); } }); } mBuilder.prototype.bind_resize_events = function (){ var that = this ; $('body').off('render_control_finished.live_spacing finish_shortcode_progress.live_spacing').on( 'render_control_finished.live_spacing finish_shortcode_progress.live_spacing' , function(){ that.vc_row_resize(); }); } mBuilder.prototype.bind_shortcode_setting_panel = function(){ var that = this ; $('body').off('close-shortcode-setting-panel').on( 'close-shortcode-setting-panel' , function(){ that.mBuilder_closeShortcodeSetting(); }); } /* * @summary The function called when build shortcode is finished and specifies new live text shortcode * * @since Function available since Release 5 */ mBuilder.prototype.bind_finish_shortcode_build_events = function(){ var that = this; $('body').off('finish_build_shortcode.md_live_text').on('finish_build_shortcode.md_live_text' , function(event , id, shortcode){ if( shortcode != 'md_live_text' ){ return ; } that.setModelattr( id , 'is_new_shortcode' , 'yes' ); $('[data-mbuilder-id="' + id + '"]').find('.md-live-text').addClass('md-live-text-new'); }); } /* * @summary The flow of the program is determined by events such as user actions (mouse clicks, key presses), finish function jobs, or messages from other programs/threads. * * @since Function available since Release 5 */ mBuilder.prototype.event_drivens = function (){ this.bind_resize_events(); this.bind_shortcode_setting_panel(); this.bind_finish_shortcode_build_events(); } mBuilder.prototype.open_shortcode_panel = function ( el_id , params , that ){ var t = this ; $( 'body' ).off('update_shortcode.apply_n_close'); var response = t.htmlSource = t.form_builder( el_id ) ; t.mBuilder_shortcodeSetting(t.shortcodes[params['type']].name , mBuilderValues.dontShow , response , mBuilderValues.apply , function () { if (params['type'] == 'vc_column' || params['type'] == 'vc_column_inner') { var css = '{'; $('#mBuilder-form #mBuilderSpacing .column-design-css input,#mBuilder-form #mBuilderDesign .column-design-css input,' + '#mBuilder-form #mBuilderSpacing .column-design-css select,#mBuilder-form #mBuilderDesign .column-design-css select ').each(function () { if ($(this).closest('.column-design-css').hasClass('column-design-prefix-px')) { var prefix = 'px'; } else { var prefix = ''; } if ($(this).parent().hasClass('mBuilder-upload-img')) { if ($(this).val() != '' && $(this).val() != 'undefined') { var val = $(this).parent().css('background-image'); }else{ return; } } else { var val = $(this).val() } css += $(this).attr('name').replace(/_/g, '-') + ':' + val + prefix + ';'; }); $('#mBuilder-form #mBuilderDesignOptions .column-design-css select').each(function () { css += $(this).attr('name').replace(/_/g, '-') + ':' + $(this).val() + ';'; }); css += '}'; css = css.replace(/["]/g, '``'); var cssInput = $(''); cssInput.val(css).appendTo($('#mBuilder-form #mBuilderSpacing')); } $.fn.serializeObject = function () { var o = {}; var a = this.serializeArray(); $.each(a, function () { if ($('input[name="' + this.name + '"], textarea[name="' + this.name + '"]').hasClass('mbuilder-skip') || this.value == '' && !$('input[name="' + this.name + '"]').hasClass('simple-textbox') && $('[name="' + this.name + '"]').prop('tagName') != 'TEXTAREA') { return true; } if (this.value == 'Array') { this.value = ''; } if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } if($('input[name="'+this.name+'"]').hasClass('md-base64')){ o[this.name] = 'pixflow_base64'+t.b64EncodeUnicode(o[this.name]); } if($('textarea[name="'+this.name+'"]').hasClass('textarea_raw_html')){ o[this.name] = t.b64EncodeUnicode(o[this.name]); } }); return o; }; var formData = $('#mBuilder-form').serializeObject(); delete formData['google-fonts-families']; delete formData['google-fonts-styles']; var regex = /align="(.*?)"/; if (t.models.models[el_id].attr) { var res = t.models.models[el_id].attr.match(regex); } else { var res = null; } if (res != null) { formData.align = res[1]; } var isTab = false; if (t.tabs[params['type']] || params['type'] == 'vc_row_inner') isTab = true; if (params['type'] == 'vc_column' || params['type'] == 'vc_column_inner') { if (params['attr'] && params['attr'] != '' && params['attr'].match(/^(width=['"].*?['"])|.*? width=['"].*?['"]/g)) { formData.width = params['attr'].match(/^(width=['"].*?['"])| width=['"].*?['"]/g); formData.width = formData.width[formData.width.length - 1].replace(/(width=)|(['"])|(undefined)|( )/g, ''); } } t.updateShortcode(el_id, params['type'], formData, undefined, isTab); cssInput && cssInput.remove(); }, mBuilderValues.applyClose , function () { $( 'body' ).on( 'update_shortcode.apply_n_close',function(){ $('.setting-panel-close').click(); t.active_setting_panel_model_id = ''; }); } ); var isLocal = $.ui.tabs.prototype._isLocal; $.ui.tabs.prototype._isLocal = function (anchor) { return true; }; $('#mBuilderTabs').tabs(); $('.setting-panel-wrapper .setting-panel-container').removeClass('dont-show'); setTimeout(function () { t.dependencyInjection(); }, 1); var name = $(that).attr('data-tabName'); if ($(that).parent().hasClass('mBuilder_row_background')){ $('.setting-panel-container').addClass('row-background') } $('.setting-panel-container').find('a[href="#mBuilder'+name+'"]').click(); } /** * @summary add event to document for close shortcode setting panel by Esc button * * @since 4.5 */ mBuilder.prototype.close_shortcode_setting_panel = function(){ $(document).on('keydown' , function(e){ if ( e.keyCode == 27 && $('.setting-panel-close').length ){ $('.setting-panel-close').click(); } }); return ; } /** * @summary Trigger events when click on shortcode setting panel button * * @since 4.5 */ mBuilder.prototype.update_shortcode_progress = function(){ $('body').on('click' , '.setting-panel-btn1' , function(){ $(this).find('.update-shortcode-progress').addClass('setting-panel-btn-click-effect'); setTimeout(function(){ $('.update-shortcode-progress-second').addClass('setting-panel-btn-click-effect2'); } , 300 ); }); $('body').off('finish_shortcode_progress.shortcode_progress').on('finish_shortcode_progress.shortcode_progress' , function(){ setTimeout(function () { $('.setting-panel-btn-click-effect2 , .setting-panel-btn-click-effect').removeClass('setting-panel-btn-click-effect2 setting-panel-btn-click-effect'); },1000); }); } mBuilder.prototype.check_shortcode_setting_pannel_status = function(e){ var that = this ; if( $( e.target ).hasClass( 'datepicker--cell' ) || $( e.target ).hasClass( 'mce-txt' ) || e.target.tagName == "svg" || e.target.tagName == "path" || $( e.target ).hasClass('btn-icon') || $( e.target ).hasClass('px-icon') || $( e.target ).hasClass('popover-content') || $( e.target ).hasClass('search-control') || $(e.target).hasClass('text-center') || $(e.target).hasClass('btn') || that.should_close_shortcode_setting_panel == false ){ that.should_close_shortcode_setting_panel = true ; return false; } return true ; } /** * @summary add event to shortcode controllers for edit,delete,clone and etc. * * @since 1.0.0 */ var prev_panel_id ; mBuilder.prototype.addEvents = function () { var t = this, $bodyGizmoOff = $('body:not(.gizmo-off)'), $body = $('body'); t.bind_section_events(); t.close_shortcode_setting_panel(); t.update_shortcode_progress(); $('body').on('click','a[href="#"]',function(e){ e.preventDefault(); }); $('body').on('click' , '.popupSaveSection' , function (e) { e.stopPropagation(); }); $('body').on('click' , '.popupSaveSection-container, .popupSaveSection-close' , function () { t.closeSaveSectionPopup(); } ); $('body').on('click' , '.mBuilder_row_save-section' , function () { var rowId = $(this).closest('.mBuilder-element').attr('id'); t.popupSaveSection( rowId ); } ); $('body').on( 'mouseenter' , '.vc_row:not(.vc_inner)' , function(){ var that = $(this) , $header = $('header[class *= "top"]'); if ( ! $header.length || that.hasClass('vertical-aligned') || that.find('> .wrap').position().top > $('header').height() ) return; if($(this).index() == 1){ setTimeout( function(){ var top_space = $header.height()+$header.position().top-that.find('> .wrap').position().top ; that.find('.mbuilder-column-options').css({ top: top_space + 'px' }); } , 10 ); } }); $('body').on( 'mouseleave' , '.vc_row' , function(){ $('.mbuilder-column-options').first().css({ top: '' }); }); $( 'body' ).on( 'click', '.pixflow-delete-section', function(){ t.deleteSection( $( this ).attr( 'data-section-name' ) ); } ); $( 'body' ).on( 'delete_section', function( e, name ){ $( '[data-section-name="' + name + '"]' ).parent().fadeOut( 500, function(){ $( this ).remove(); } ); } ); $('.builder-save .save').click(function (e) { e.preventDefault(); t.saveContent(); }); $('body').on('click' , '.meditor a' , function(e){ e.preventDefault(); }); $bodyGizmoOff.on('mousedown', '.meditor', function (e) { e.stopPropagation(); }); $bodyGizmoOff.on('click', '.mBuilder_container, .mce-grid, .mce-reset, .mce-container, .mce-btn, .pixflow-shortcodes-panel, .datepicker--cell, .setting-panel-wrapper, .datepickers-container *, .media-modal, .sp-container ', function (e) { e.stopPropagation(); }); $bodyGizmoOff.on('mouseleave', '.vc_row', function () { t.removeColumnSeparator(); }); $(document).click(function (e) { closeAll(); if ( t.check_shortcode_setting_pannel_status(e) ){ $('body').trigger('close-shortcode-setting-panel'); } }); function closeAll(notMe) { $('.mBuilder-element').removeClass('onTop'); var $activeElems = $('.active-gizmo').not(notMe); $activeElems.each(function () { var $this = $(this), $innerRow = $this.closest('.mBuilder-vc_row_inner'), $container = $this.find('>.mBuilder_container, .options-holder, > .extra-option'); $this.removeClass('active-gizmo'); TweenMax.to($this.find('.options-holder,.mBuilder_container'), .2, { scale: .9, opacity: 0, onComplete: function () { TweenMax.set($container, {height: 0, zIndex: -333, display: 'none'}); } }); $this.closest('div[class*=mBuilder-vc_column]').removeClass('upper_zIndex'); if ($this.hasClass('mBuilder_setting_panel') || $this.hasClass('mBuilder_row_layout')) { $this.closest('div[class*=vc_row]').removeClass('upper_zIndex'); } $this.find('>.mBuilder_container, .options-holder').removeClass('open'); if ($this.hasClass('mBuilder_row_layout')) { $this.find('input').focus(); } if ($innerRow.length) { $innerRow.removeClass('upper_inner_row_zIndex'); $innerRow.parents('.vc_row').removeClass('upper_inner_row_zIndex'); $innerRow.siblings('.mBuilder-element').removeClass('lower_inner_row_zIndex') } }) $('.section-open').removeClass('section-open'); builder.close_pixflow_shortcode_panel(); $('.show-column-layout').removeClass('show-column-layout'); } // Row Layout $body.off('click.mbuilder', '.mBuilder-element .mBuilder_row_layout .col,.mBuilder-element .mBuilder_row_layout .submit'); $body.on('click.mbuilder', '.mBuilder-element .mBuilder_row_layout .col,.mBuilder-element .mBuilder_row_layout .submit', function (e) { e.stopPropagation(); var row = $(this).closest('.vc_row'), value = $(this).attr('data-colSize'); if ($(this).hasClass('submit')) { value = $(this).prev().val(); } $(this).closest('.mBuilder_row_layout').find('input[name="cols"]').val(value); t.changeRowLayout(value, row); }); // Edit Element $body.off('click.mbuilder', '.mBuilder-element .extra-option > a,.mBuilder_row_background > .bg-button,.mBuilder-element .mBuilder_row_setting,.mBuilder-element .sc-setting ,.mBuilder-element .animation-setting , .mBuilder-element .open-setting'); $body.on('click.mbuilder', '.mBuilder-element .extra-option > a,.mBuilder_row_background > .bg-button,.mBuilder-element .mBuilder_row_setting,.mBuilder-element .sc-setting ,.mBuilder-element .animation-setting ,.mBuilder-element .open-setting-panel', function (e) { e.stopPropagation(); closeAll(); var params = t.getModelParams($(this).closest('.mBuilder-element').attr('data-mBuilder-id')), el_id = $(this).closest('.mBuilder-element').attr('data-mBuilder-id'), that = this; if( prev_panel_id == el_id && ! $(this).closest('.mBuilder-element').hasClass('vc_row') ){ return; } t.selected_shortcode_id = el_id; if (params == null) { params = []; params['attr'] = ''; params['content'] = ''; params['type'] = $(this).closest('.mBuilder-element').attr('data-mbuilder-el'); } t.active_setting_panel_model_id = el_id; if(params['type'] == 'md_live_text'){ t.update_meditor_shortcode_model(el_id); } t.mBuilder_shortcodeSetting(t.shortcodes[params['type']].name , '', '', mBuilderValues.apply , function () { }, mBuilderValues.applyClose , function () { }); if('vc_row_inner' == params['type']){ t.update_meditor_models(); } t.open_shortcode_panel( el_id , params , that); prev_panel_id = el_id; }); // Delete Element $body.off('click.mbuilder', '.mBuilder-element .mBuilder_row_delete,.mBuilder-element .sc-delete'); $body.on('click.mbuilder', '.mBuilder-element .mBuilder_row_delete,.mBuilder-element .sc-delete', function (e) { var el_id = $(this).closest('.mBuilder-element').attr('data-mBuilder-id'); $(this).parents('.mBuilder_controls').addClass('active-gizmo'); e.stopPropagation(); var $elem = $('div[data-mbuilder-id=' + el_id + ']'); if ($elem.hasClass('mBuilder-md_button')) { deleteFunc(el_id); } else if (!$(this).closest('.mBuilder_controls').find('.deleteMessage').length) { //close option panel on click var $this = $(this), $optionsHolder = $(this).closest('.mBuilder_container, .options-holder'); var deleteBox = '

    ' + mBuilderValues.deleteDescText + '

    ' + mBuilderValues.deleteText + '
    '; TweenMax.to($optionsHolder, .2, { scale: .9, opacity: 0, onComplete: function () { TweenMax.set($optionsHolder, {height: 0, zIndex: -333}); //add delete alertBox var $parent = $this.closest('.mBuilder_controls.sc-control,.mBuilder_row_controls'); $parent.after(deleteBox); var $deleteMsgBox = $parent.siblings('.deleteMessage'), $deleteBtn = $deleteMsgBox.find('.deleteBtn'); //deletBox Animation // for tab if ($elem.hasClass('mBuilder-md_tab') || $elem.hasClass('mBuilder-md_modernTab')) { var left = parseInt($elem.find(' > .mBuilder_controls.tab ').css('left')); left += 44; $elem.find(' > .deleteMessage').css({'left': left}) } else if ($elem.hasClass('mBuilder-md_hor_tab') || $elem.hasClass('mBuilder-md_hor_tab2')) { var top = parseInt($elem.find(' > .mBuilder_controls.tab ').css('top')); top += 44; $elem.find(' > .deleteMessage').css({'top': top}) } else if ($elem.hasClass('vc_row')) { if ($('body .vc_row').first().attr('id') == $elem.attr('id')) { top = '40%'; $elem.find(' > .deleteMessage').css({'top': top}) } } TweenMax.to($deleteMsgBox, .2, {opacity: 1, bottom: '15px'}); if ($parent.hasClass('sc-control')) { $parent.addClass('deleteEffect') } else { $parent.siblings('.wrap,.sc-control').addClass('deleteEffect') } $deleteBtn.click(function () { deleteFunc(el_id); }) $(document).click(function (e) { e.stopPropagation(); TweenMax.to($deleteMsgBox, .3, { opacity: 0, bottom: '20px', onComplete: function () { $deleteMsgBox.remove(); } }); $deleteMsgBox.parents('.mBuilder_controls').removeClass('active-gizmo'); if ($parent.hasClass('sc-control')) { $parent.removeClass('deleteEffect') } else { $deleteMsgBox.siblings('.wrap').removeClass('deleteEffect'); } }); } }); $optionsHolder.removeClass('open'); toggle = -1; } function deleteFunc(el_id) { t.deleteModel(el_id); var p = $('div[data-mbuilder-id=' + el_id + ']').parent().closest('.mBuilder-element'); // for tab var $elem = $('div[data-mbuilder-id=' + el_id + ']'); if ($elem.hasClass('mBuilder-md_tab') || $elem.hasClass('mBuilder-md_modernTab') || $elem.hasClass('mBuilder-md_hor_tab') || $elem.hasClass('mBuilder-md_hor_tab2')) { var id = $elem.children('.wpb_tab ').attr('id'); $('a[href="#' + id + '"]').parent().remove(); } $('div[data-mbuilder-id=' + el_id + ']').remove(); if (p.attr('data-mbuilder-el') == 'vc_column' || p.attr('data-mbuilder-el') == 'vc_column_inner') { if (!p.find('.mBuilder-element').length) { p.find('.wpb_column').addClass('vc_empty-element'); } } t.createPlaceholders(); $('body').css('height',$('body').css('height')); $('body').css('height','auto'); } }); // Copy Element $body.off('click.mbuilder', '.mBuilder_row_duplicate,.mBuilder-element .sc-duplicate,.tab .sc-duplicate'); $body.on('click.mbuilder', '.mBuilder_row_duplicate,.mBuilder-element .sc-duplicate,.tab .sc-duplicate', function (e) { e.stopPropagation(); TweenMax.set($(this).closest('.options-holder'), {height: 0, zIndex: -333, scale: .9, opacity: 0}); closeAll(); t.duplicate(this); }); // Element Alignments $body.off('click.mbuilder', '.mBuilder-element .sc-alignment span'); $body.on('click.mbuilder', '.mBuilder-element .sc-alignment span', function (e) { e.preventDefault(); e.stopPropagation(); var element = $(this).closest('.mBuilder-element'); var id = element.attr('data-mbuilder-id'); var regex = /(align=".*?")/g; t.models.models[id].attr = t.models.models[id].attr.replace(regex, ''); if ($(this).hasClass('left') || $(this).hasClass('mdb-leftalignsvg')) { e.preventDefault(); t.models.models[id].attr += ' align="left"'; element.find('[class *= "md-align-"]') .removeClass('md-align-right') .removeClass('md-align-center') .addClass('md-align-left') } if ($(this).hasClass('center') || $(this).hasClass('mdb-centeralignsvg')) { e.preventDefault(); t.models.models[id].attr += ' align="center"'; element.find('[class *= "md-align-"]') .removeClass('md-align-right') .removeClass('md-align-left') .addClass('md-align-center') } if ($(this).hasClass('right') || $(this).hasClass('mdb-rightalignsvg')) { e.preventDefault(); t.models.models[id].attr += ' align="right"'; element.find('[class *= "md-align-"]') .removeClass('md-align-center') .removeClass('md-align-left') .addClass('md-align-right') } }); // Hover on delete shortcode button $body.on({ mouseenter: function () { $(this).closest('.mBuilder_controls').addClass('delete_hover'); }, mouseleave: function () { $(this).closest('.mBuilder_controls').removeClass('delete_hover'); } }, '.mBuilder-element .sc-delete'); // open and close setting drop down menu $body.off('click.mbuilder', '.mBuilder_row_controls .mBuilder_setting_panel,.mBuilder_row_layout,.mbuilder-column-options,.sc-option'); $body.on('click.mbuilder', '.mBuilder_row_controls .mBuilder_setting_panel,.mBuilder_row_layout,.mbuilder-column-options,.sc-option', function (e) { e.stopPropagation(); var $this = $(this), $innerRow = $this.closest('.mBuilder-vc_row_inner'), $container = $this.find('>.mBuilder_container, > .options-holder, > .extra-option'), $active_gizmo = $this.closest('.active-gizmo'); if ( $active_gizmo.length < 1 ) { closeAll(this); if ($this.closest('.gizmo-container').length) { $this.closest('.gizmo-container').addClass('active-gizmo'); } else if ($this.hasClass('sc-option')) { $this.closest('.mBuilder_controls').addClass('active-gizmo'); } $this.closest('.mBuilder-element').addClass('onTop'); TweenMax.set($container, {scale: .9,height: 'auto', zIndex: 333, display:'block'}); TweenMax.to($container, .2, {scale: 1, opacity: 1}); $this.closest('div[class*=mBuilder-vc_column]').addClass('upper_zIndex'); if ($this.hasClass('mBuilder_setting_panel') || $this.hasClass('mBuilder_row_layout')) { $this.closest('div[class*=vc_row]').addClass('upper_zIndex'); $this.closest('.mBuilder_setting_panel,.mBuilder_row_layout').addClass('active-gizmo'); } $this.find('>.mBuilder_container, .options-holder').removeClass('open'); /* inner Row */ if ($innerRow.length) { $innerRow.addClass('upper_inner_row_zIndex'); $innerRow.parents('.vc_row').addClass('upper_inner_row_zIndex'); $innerRow.siblings('.mBuilder-element').addClass('lower_inner_row_zIndex') } } else { closeAll(); } if ($this.hasClass('mBuilder_row_layout')) { $this.find('input').focus(); } // set sc-option position for first row var $thisScOptionPositionY = parseInt(e.clientY) - 100; var $thisScOptionOpen = parseInt($(".active-gizmo div.options-holder").height()); if ($thisScOptionPositionY <= $thisScOptionOpen) { $(".vc_row .sc-option .options-holder").css({'top': '48px', 'z-index': '99999999'}); } else { $(".vc_row .sc-option .options-holder").css({'top': ($thisScOptionOpen * (-1)) - 7, 'z-index': '99999999'}); } // END set sc-option position for first row t.mBuilder_closeShortcodeSetting(); if( $this.hasClass('mBuilder_row_layout') ){ $this.parent().prev().addClass('show-column-layout'); } }); $body.off('click.mbuilder', '.mBuilder_row_layout input'); $body.on('click.mbuilder', '.mBuilder_row_layout input', function (e) { e.stopPropagation(); }); var time = []; $body.on('mouseenter', '.mBuilder_row_controls .mBuilder_setting_panel,.mBuilder_row_layout, .mbuilder-column-options ', function (e) { e.stopPropagation(); clearTimeout(time[$(this)]); }); $body.on('mouseleave', '.mBuilder_row_controls .mBuilder_setting_panel,.mBuilder_row_layout, .mbuilder-column-options', function (e) { e.stopPropagation(); var $this = $(this), $innerRow = $this.closest('.mBuilder-vc_row_inner'), $container =$this.find('>.mBuilder_container, > .options-holder, > .extra-option') ; clearTimeout(time[$this]); time[$this] = setTimeout(function () { TweenMax.to($container, .3, { scale: .9, opacity: 0, delay: 0, onComplete: function () { TweenMax.set($container, {height: 0, zIndex: -333, display: 'none'}); $this.removeClass('active-gizmo'); } }); $this.closest('div[class*=mBuilder-vc_column]').removeClass('upper_zIndex'); if ($this.hasClass('mBuilder_setting_panel') || $this.hasClass('mBuilder_row_layout')) { $this.closest('div[class*=vc_row]').removeClass('upper_zIndex'); } $container.removeClass('open'); if ($innerRow.length) { $innerRow.removeClass('upper_inner_row_zIndex'); $innerRow.parents('.vc_row').removeClass('upper_inner_row_zIndex'); $innerRow.siblings('.mBuilder-element').removeClass('lower_inner_row_zIndex') } toggle = -1; closeAll($this); }, 200); }); // open shortcode setting panel on one click $body.on('click', '.sc-control', function (e) { e.stopPropagation(); var model_id = $(this).closest('.mBuilder-element').attr('data-mbuilder-id'); if( t.is_shortcode_panel_open(model_id) && $('.setting-panel-container').length ){ return ; } $(this).find('.sc-setting').click(); }); }; /** * Duplicate element instantly * @param element */ mBuilder.prototype.duplicate = function( element ){ var that = this ; var el = $( element ).closest('.mBuilder-element'), el_id = el.attr('data-mBuilder-id'); do { var newID = Math.floor(100 + (Math.random() * 300) + 1); } while (this.models.models.hasOwnProperty(newID)); this.models.models[newID] = JSON.parse(JSON.stringify(this.models.models[el_id])); var $container = $('div[data-mbuilder-id=' + el_id + ']'), $containerPlaceholder = $container.next('.insert-between-placeholder,.insert-after-row-placeholder'), $newContainer = $container.clone().attr('data-mbuilder-id', newID), $newContainerPlaceholder = $containerPlaceholder.clone(); $containerPlaceholder.after($newContainer); $newContainer.after($newContainerPlaceholder); if ( $( element ).hasClass('mBuilder-vc_column_inner') || $( element ).hasClass('mBuilder-vc_column') ){ $newContainer.find('.mBuilder-element').remove(); $container.after($newContainer); } if ( $( element ).hasClass('mBuilder_row_duplicate') ) { var el = $('div[data-mBuilder-id=' + newID + ']'); el.find('.mBuilder-element').each(function () { var child_id = $(this).attr('data-mBuilder-id'); do { var newID = Math.floor(100 + (Math.random() * 300) + 1); } while ( that.models.models.hasOwnProperty( newID ) ); that.models.models[ newID ] = JSON.parse( JSON.stringify( that.models.models[child_id] ) ); $( this ).attr( 'data-mBuilder-id', newID ); }); } this.renderControls(); this.setSortable(); var $newElm = $('div[data-mbuilder-id=' + newID + ']'); if($newElm.find('.meditor').length){ this.bind_text_editor($newElm.find('.meditor')); } $('body').trigger('duplicate_shortcode', $newElm); } mBuilder.prototype.bind_text_editor = function(new_el){ var content_defaults = { text: 'Default Content', }, content_controllers = 'content', content_selector = (new_el) ? new_el : '.inline-md-editor' , that = this ; this.set_editable(content_defaults,content_controllers,content_selector); $('body').off('update_shortcode.bind_text_editor'); $('body').on('update_shortcode.bind_text_editor' , function(){ that.bind_text_editor(); }); } mBuilder.prototype.update_meditor_models = function(){ var t = this; $('.mBuilder-md_live_text').each(function(){ var model_id = $(this).attr('data-mbuilder-id'); t.update_meditor_shortcode_model(model_id); }); } mBuilder.prototype.set_editable = function(defaults,controllers,selector){ var editable_model = Backbone.Model.extend({ defaults: 'default' }); var editable_view = Backbone.View.extend({ initialize: function() { this.$el.attr('data-button-class',controllers); meditor.editable_init(selector); }, events: { 'click': 'editable_click' , 'blur' : 'check_defult_text' , 'mouseup' : 'update_font_family_controller' , 'mouseleave' : 'update_font_family_controller' }, check_defult_text: function(e){ var $el = $(e.target).closest('.meditor'); if ( $el.text().trim() == ''){ $el.html( 'Click here to edit.' ); } }, update_font_family_controller: function(){ var parent_select = this.get_selection_parent_element(); if( $(parent_select).length && this.get_selected_text() != '' ){ if( $(parent_select)[0].tagName == "SPAN" && !$(parent_select).children().length ){ var font_size = $(parent_select).css('font-size'); }else{ var $get_first_span = $(parent_select).find('span').first(); var font_size = $get_first_span.css('font-size'); } if( typeof font_size != "undefined" ){ $('.font-size-controller .active-item .text-controller-icon').text(parseInt(font_size)); } } }, get_selected_text: function() { if (window.getSelection) { return window.getSelection().toString(); } else if (document.selection) { return document.selection.createRange().text; } return ''; }, get_selection_parent_element: function () { var parent_el = null, sel; if (window.getSelection) { sel = window.getSelection(); if (sel.rangeCount) { parent_el = sel.getRangeAt(0).commonAncestorContainer; if (parent_el.nodeType != 1) { parent_el = parent_el.parentNode; } } } else if ((sel = document.selection) && sel.type != "Control") { parent_el = sel.createRange().parentElement(); } return parent_el; }, editable_click: function(e){ e.stopPropagation(); if($('body').hasClass('gizmo-off')) return ; var $el = $(e.target).closest('.meditor'); if($el.attr('id') == 'meditor_focus'){ return ; } $('.meditor').attr({ 'contenteditable':'false' , 'id': '' , }).addClass('unselectable'); $el.parents('.mBuilder-element').not('.vc_row, .mBuilder-vc_column').draggable({disabled:true}); var focues_element = $el.attr({ 'contenteditable': true , 'id': 'meditor_focus' , }).removeClass('unselectable').get(0); if( focues_element != "undefined" ){ focues_element.focus(); } $('.meditor-panel').css({ display: 'flex' }); $el.closest('.mBuilder-md_live_text').addClass('active-md-editor'); builder.mBuilder_closeShortcodeSetting(); } }); var $editables = $(selector); if( typeof $editables[0] !== 'undefined' ){ var model = new editable_model(); var view = new editable_view({model: model, el: $editables, tagName: $editables[0].tagName}); } } mBuilder.prototype.update_meditor_shortcode_model = function( model_id ){ var t = this, $model = $("[data-mbuilder-id="+model_id+"]"), $shortcode = $model.find('.inline-md-editor'), $new_content = $shortcode.html(), line_height = $shortcode.attr('data-lineheight'), letter_spacing = $shortcode.attr('data-letterspace'); t.setModelattr(model_id , 'meditor_line_height' , line_height); t.setModelattr(model_id , 'meditor_letter_spacing' , letter_spacing); t.models.models[model_id].content = t.b64EncodeUnicode($new_content); } /** * @summary creates placeholders and droppable areas. * * @since 1.0.0 */ mBuilder.prototype.createPlaceholders = function () { $('.insert-between-placeholder').remove(); $('.insert-after-row-placeholder').remove(); var containers = ''; for (i in this.shortcodes) { if (this.shortcodes[i].as_parent && this.shortcodes[i].as_parent.only) containers += "[data-mbuilder-el='" + this.shortcodes[i].as_parent.only + "'],"; } containers = containers.slice(0, -1); $('
    ').addClass('insert-between-placeholder').insertAfter($('.mBuilder-element').not('.vc_row,.mBuilder-vc_column, .mBuilder-vc_column_inner').not(containers)); $('.mBuilder-vc_column, .mBuilder-vc_column_inner').each(function () { $('
    ').addClass('insert-between-placeholder').insertBefore($(this).find('.wpb_wrapper:first .mBuilder-element:first-of-type').not('.mBuilder-vc_column_inner').not(containers)); }); $('.insert-between-placeholder').each(function () { $(this).attr('data-index', $('div').index(this)); }); var rows = $('.vc_row').not('.vc_inner'); $('
    ').addClass('insert-after-row-placeholder').insertAfter(rows); $('
    ').addClass('insert-after-row-placeholder').prependTo('.content-container'); if (! $('.mBuilder-element').length) { var element_svg =' elements Created with Sketch. '; var sections_svg =' sections Created with Sketch. '; var import_svg =' Page 1 Created with Sketch. '; var content = $('

    start with Massive Builder

    Create a new page

    '), btn = $('
    '+element_svg+'Add Elements
    ' + '
    '+sections_svg+'Pre-made Sections
    ' + '
    '+import_svg+'Import Template
    '); btn.find('.elements').click(function (e) { e.stopPropagation(); $(this).closest('.insert-after-row-placeholder').removeClass('section-open'); $('.pixflow-add-element-button').click(); }); btn.find('.sections').click(function (e) { e.stopPropagation(); $(this).closest('.insert-after-row-placeholder').addClass('section-open'); builder.open_pixflow_shortcode_panel('sections') }); btn.find('.import').click(function (e) { e.stopPropagation(); $(this).closest('.insert-after-row-placeholder').removeClass('section-open'); window.location.href = $('.pixflow-builder-toolbar .site-setting').attr('href'); }); $('.insert-after-row-placeholder').first().addClass('blank-page'); $('.insert-after-row-placeholder').html(content); content.append(btn); } else { $('.insert-after-row-placeholder').first().removeClass('blank-page').off('click'); } pixflow_footerPosition(); }; /** * @summary remove from models object. * * @param {integer} id * @since 1.0.0 */ mBuilder.prototype.deleteModel = function (id) { var t = this; for (var index in t.models.models) { var $el = $('div[data-mBuilder-id=' + index + ']'), $parent = $el.parent().closest('.mBuilder-element'); if ($parent.length) { var parentId = $parent.attr('data-mBuilder-id'); t.models.models[index].parentId = parentId; } } delete t.models.models[id]; for(var element_num in t.models.models ) { var elements = t.models.models[element_num] ; if (elements['parentId'] == id) { t.deleteModel(element_num); } } $('body').addClass('changed'); }; /** * @summary apply row layout changes. * * @param {string} exp - layout expression example: (3/12)+(3/12)+(3/12)+(3/12) * @param {object} row - jQuery Object * @since 1.0.0 */ mBuilder.prototype.changeRowLayout = function (exp, row) { var t = this; if(t.lock) { return; } if (exp.match(/([0-9]+)\/12/g)) { var columns = exp.match(/([0-9]+)\/12/g); var sum = 0; for (i in columns) { var size = parseInt(columns[i].replace('/12', '')); sum += size; } if (sum > 12) { alert('Sum of all columns is greater than 12 columns.'); return; } else if (sum < 12) { alert('Sum of all columns is less than 12 columns.'); return; } var i = 0; row.find('[data-mbuilder-el="vc_column"],[data-mbuilder-el="vc_column_inner"]').first() .siblings('[data-mbuilder-el="vc_column"],[data-mbuilder-el="vc_column_inner"]').addBack().each(function () { if (columns[i]) { var size = columns[i].replace('/12', ''); $(this).find('> .vc_column_container').removeClass(function (index, css) { return (css.match(/(^|\s)col-sm-[0-9]+/g) || []).join(' '); }).addClass('col-sm-' + size); $(this).removeClass(function (index, css) { return (css.match(/(^|\s)col-sm-[0-9]+/g) || []).join(' '); }).addClass('col-sm-' + size); if(t.models.models[$(this).attr('data-mbuilder-id')].attr == undefined){ t.models.models[$(this).attr('data-mbuilder-id')].attr = ''; } if (t.models.models[$(this).attr('data-mbuilder-id')].attr && t.models.models[$(this).attr('data-mbuilder-id')].attr != '' && builder.models.models[$(this).attr('data-mbuilder-id')].attr.match(/^(width=)|.*? width=/g)) { t.models.models[$(this).attr('data-mbuilder-id')].attr = t.models.models[$(this).attr('data-mbuilder-id')].attr.replace(/[^-_]?width=["'].*?["']/g, ' width="' + columns[i] + '"'); } else { t.models.models[$(this).attr('data-mbuilder-id')].attr += ' width="' + columns[i] + '"'; } i++; } else { var el_id = $(this).attr('data-mbuilder-id'), $el = $('div[data-mBuilder-id=' + el_id + ']'), $lastCol = row.find('> .wrap > .mBuilder-vc_column, > .wrap > .mBuilder-vc_column_inner').eq(columns.length - 1).find('.vc_column-inner > .wpb_wrapper'); $el.find('.vc_column-inner > .wpb_wrapper > .mBuilder-element').each(function () { var $obj = $(this).appendTo($lastCol); $obj.after('
    '); }); t.deleteModel(el_id); $(this).remove(); } }); this.create_column( columns, i, row ); } else { alert('You entered wrong pattern, try premade patterns instead.'); } }; mBuilder.prototype.create_column = function( columns, count, $row ){ var that = this; if ( count >= columns.length ) { $('body').off('duplicate_shortcode.row_layout'); that.vc_column_resize( $row ); return true; } $('body').off('duplicate_shortcode.row_layout').on('duplicate_shortcode.row_layout',function( e, new_column ){ that.setModelattr( $( new_column ).attr( 'data-mbuilder-id' ), 'width', columns[ count ] ); var size = columns[ count ].replace('/12', ''); $( new_column ).find('> .vc_column_container').removeClass(function (index, css) { return (css.match(/(^|\s)col-sm-[0-9]+/g) || []).join(' '); }).addClass('col-sm-' + size); $( new_column ).removeClass(function (index, css) { return (css.match(/(^|\s)col-sm-[0-9]+/g) || []).join(' '); }).addClass('col-sm-' + size); $( new_column ).find(' > .wpb_column ').addClass( 'vc_empty-element' ); that.create_column( columns, count+1, $row ); }); if ($row.hasClass('vc_inner')) { that.duplicate( $row.find('.mBuilder-vc_column_inner:last') ); } else { that.duplicate( $row.find('.mBuilder-vc_column:last') ); } } /** * @summary open shortcode setting panel. * * @param {string} title * @param {string} customClass * @param {string} text * @param {string} btn1 * @param {function} callback1 - optional * @param {string} btn2 - optional * @param {function} callback2 - optional * @param {function} closeCallback - optional * @since 1.0.0 */ mBuilder.prototype.mBuilder_shortcodeSetting = function (title, customClass, text, btn1, callback1, btn2, callback2, closeCallback) { "use strict"; var t = this; var update_shortcode_html = '
    '; customClass += " md-dark-background-panel"; if ($('.setting-panel-wrapper').length) { $('.setting-panel-wrapper .setting-panel-title').html(title); $('.setting-panel-wrapper .setting-panel-text').html(text); $('.setting-panel-wrapper .setting-panel-container').attr('class', '').addClass('setting-panel-container ' + customClass); $('.setting-panel-wrapper .setting-panel-btn1').html(''+btn1+'' + update_shortcode_html); var $messageBox = $('.setting-panel-wrapper'), $btn1; } else { var model_id = t.active_setting_panel_model_id, model_type = t.models.models[model_id].type; var $messageBox = $('' + '
    ' + '
    ' + '
    ' + '
    ' + title + '
    ' + '
    ' + text + '
    ' + ' ' + '
    ' + '
    ').appendTo('body'), $btn1; } $messageBox.animate({opacity: 1}, 200); $messageBox.find('.setting-panel-container').draggable({ handle: ".setting-panel-title" , cursor: "move" , stop: function(){ t.should_close_shortcode_setting_panel = false; } }); this.settingPanel = $messageBox; $btn1 = $messageBox.find('.setting-panel-btn1'); $btn1.off('click'); $btn1.click(function (e) { e.preventDefault(); if (typeof callback1 == 'function') { tinymce.triggerSave(); $('#md_text_title1_text').keyup(); callback1(); } }); var $close = $messageBox.find('.setting-panel-close'); $close.off('click'); $close.on('click' , function (e) { e.preventDefault(); e.stopPropagation(); if (typeof closeCallback == 'function') { closeCallback(); } t.mBuilder_closeShortcodeSetting(); }); }; /** * @summary close shortcode setting panel. * * @since 1.0.0 */ mBuilder.prototype.mBuilder_closeShortcodeSetting = function () { "use strict"; $('.sp-container').remove(); $('.setting-panel-wrapper').fadeOut(300, function () { $(this).remove(); }) prev_panel_id =''; }; /** * @summary get Model * * @param {integer} id - model ID * * @return {object} - model * @since 1.0.0 */ mBuilder.prototype.getModelParams = function (id) { return this.models.models[id]; }; /** * @summary Add Shortcode Panel to the customizer side * * @since 1.0.0 */ var clear_shortcodes_panel_animation_open; var clear_shortcodes_panel_animation_close; mBuilder.prototype.shortcode_panel_functionality = function () { var t = this; t.add_nicescroll(); t.search_shortcode(); $('.pixflow-shortcodes-panel .pixflow-add-element-button').click(function (e) { e.stopPropagation(); clearTimeout(clear_shortcodes_panel_animation_open); clearTimeout(clear_shortcodes_panel_animation_close); if( $('.active-preview').length ){ $('.builder-preview').click(); } $(this).toggleClass('close-element-button'); t.shortcode_panel_animation(); }); t.shortcode_panel_tabs(); }; function check_over_empty_page(el){ obj = $(el).closest('.blank-page'); if (obj.length) { lastObj = obj; var objTop = obj.offset().top + 100, objLeft = obj.offset().left + 100, objHeight = obj.outerHeight() - 200, objWidth = obj.outerWidth() - 200; d.css({ 'top': objTop, 'left': objLeft, height: objHeight, width: objWidth, background: 'transparent', }); if( ! $('.drop-here-container').length ){ $('.empty-page-title').append('
    Drop It Here
    '); } return true; } return false; } function check_over_rows( obj, d ){ if (obj.hasClass('mBuilder-vc_column') || obj.hasClass('mBuilder-vc_column_inner')) { if (obj.find('> .vc_empty-element').length) { obj = obj.find('> .vc_empty-element'); overEmpty = true; } else { if (!obj.hasClass('mBuilder-vc_column_inner')) { d.css({border: '', borderTop: '4px solid #43dc9d'}); obj = obj.closest('.vc_row'); } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); obj = obj.closest('.vc_inner'); } } return [true,obj]; } else if (obj.hasClass('vc_row')) { if (!obj.hasClass('vc_inner')) { d.css({border: '', borderTop: '4px solid #43dc9d'}); } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); obj = obj.closest('.vc_inner'); } return [true,obj]; } return [false,obj]; } function check_over_shortcode( obj, t, d ){ if (obj.length && !obj.hasClass('vc_row') && !obj.hasClass('mBuilder-vc_column') && !obj.hasClass('mBuilder-vc_column_inner')) { if (t.containers[obj.attr('data-mbuilder-el')]) { if (!obj.find('.mBuilder-element').length) { overEmpty = true; } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); } } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); } return true; } return false; } function check_over_page(obj){ if (obj.hasClass('content-container') && $('.vc_row').length) { lastObj = obj; d.css({ border: '', height: '0px', left: $('.vc_row').last().offset().left + 'px', borderTop: '4px solid #43dc9d', top: $('.vc_row').last().offset().top + $('.vc_row').last().outerHeight() + 'px', width: obj.width() }); return true; } return false; } function is_over_shortcode_panel( el, d ){ if($(el).closest('.pixflow-shortcodes-panel').length){ overEmpty = true; lastObj = null; d.css({width: '', border: ''}); return true; } } function close_shortcode_panel_on_drag(){ if(!$('.pixflow-shortcodes-panel').hasClass('close')){ $('.pixflow-shortcodes-panel').addClass('close'); } } function get_hovered_element(helper,x,y){ helper.css('display','none'); var el = document.elementFromPoint(x, y); helper.css('display',''); return el; } /////////////////////////////////// var fly = null; function shortcode_panel_drag_fly(event){ clearInterval(fly); if (event.clientY < 100) { fly = setInterval(function () { if($(window).scrollTop()==0){ clearInterval(fly); } $(window).scrollTop($(window).scrollTop() - 50) }, 50); } else if (event.clientY > $(window).height() - 50) { fly = setInterval(function () { if($(window).scrollTop()>=$(document).height()-$(window).height()){ clearInterval(fly); } $(window).scrollTop($(window).scrollTop() + 50) }, 50); } } mBuilder.prototype.applyDragForce = function ( selector ) { var t = this, section = null, placeholder = null, sectionType = false , lastObj = null, d = $('.mBuilder-drag-overlay'); $( selector ).draggable({ appendTo: "body", helper: "clone", zIndex: 9999999, containment: 'document', cursorAt: {top: 20, left: 50}, start: function (event, ui) { clearInterval(fly); section = $(this).data('section-id'); if( $(this).hasClass('pixflow-custom-section') ){ sectionType = true; }else{ sectionType = false; } $(this).css('visibility', 'hidden'); if($('.insert-after-row-placeholder.blank-page').length){ $('#p-btn-addsections').click(); } }, drag: function (event, ui) { shortcode_panel_drag_fly(event); var el = get_hovered_element(ui.helper,event.clientX, event.clientY); if (el) { if (el == d.get(0)) return true; if(is_over_shortcode_panel( el, d )){ return true; } close_shortcode_panel_on_drag(); var selector = $('.section-open').length ? '.section-open' : '.vc_row:not(.vc_inner)'; var obj = $( el ).closest( selector ); if( !obj.length ){ if( lastObj != null ){ lastObj.removeClass('section-placeholder'); } lastObj = null; d.css( {width: '', border: ''} ); return true; } if( obj.hasClass( 'vc_row' ) ){ var objTop = obj.offset().top, objLeft = obj.offset().left, objHeight = obj.outerHeight(), objWidth = obj.outerWidth(), objHalf = objTop + objHeight / 2; if (event.clientY + $(window).scrollTop() < objHalf) { d.css({ 'top': objTop, 'left': objLeft, width: objWidth, height: 5, background: '#6226eb', }); lastObj = obj.prev('.insert-after-row-placeholder'); } else { d.css({ 'top': objTop + objHeight, 'left': objLeft, width: objWidth, height: 5, background: '#6226eb', }); lastObj = obj.next('.insert-after-row-placeholder'); } }else { if( ! $('.drop-here-container').length ){ $('.empty-page-title').append('
    Drop It Here
    '); } obj.addClass('section-placeholder'); lastObj = obj; } } else { if(lastObj != null){ lastObj.removeClass('section-placeholder'); } lastObj = null; } }, stop: function (event, ui){ $('.drop-here-container').remove(); clearInterval( fly ); d.css({'width': '', border: ''}); $('.insert-after-row-placeholder.blank-page').removeClass('section-open'); try { $('.pixflow-shortcodes-panel').getNiceScroll().resize(); } catch (e) {} $(this).css('visibility', 'visible'); if (!lastObj || !lastObj.length) { return; } lastObj.removeClass('section-placeholder'); placeholder = lastObj.get(0); if (placeholder != null) { if (lastObj.hasClass('insert-after-row-placeholder')) { $(placeholder).addClass('dropped'); t.section_builder(section ,placeholder, sectionType ); } } } }); } mBuilder.prototype.shortcode_panel_drop_shortcodes = function(){ var t = this, shortcode = null, section = null, placeholder = null, lastObj = null, d = $('
    ').appendTo('body'), direction = 'down', overEmpty = false; $('.pixflow-shortcodes-panel .shortcodes').draggable({ appendTo: "body", helper: "clone", containment: 'document', zIndex: 9999999, cursorAt: {top: 20, left: 50}, start: function (event, ui) { t.shortcode_panel_animation(); clearInterval(fly); shortcode = $(this).attr('id'); $(this).css('visibility', 'hidden'); }, drag: function (event, ui) { shortcode_panel_drag_fly(event); var el = get_hovered_element(ui.helper,event.clientX, event.clientY); if (el) { if (el == d.get(0)) return true; if(is_over_shortcode_panel( el, d )){ return true; } close_shortcode_panel_on_drag(); overEmpty = false; var obj = $(el).closest('.mBuilder-element,.vc_inner ,.content-container,.section-open'); if (obj.hasClass('content-container') && $('.content-container').find('.blank-page').length) { obj = $(el).closest('.mBuilder-element,.vc_inner'); } if(check_over_page(obj)){ return true; } if(!check_over_shortcode( obj , t, d )){ var is_over_row = check_over_rows( obj, d ); if(is_over_row[0]){ obj = is_over_row[1]; }else{ if(!check_over_empty_page(el)){ if (lastObj) { lastObj.css({'transform': ''}) } lastObj = null; d.css({width: '', border: ''}); return true; } } } if(!obj.length){ return true; } var objTop = obj.offset().top, objLeft = obj.offset().left, objHeight = obj.outerHeight(), objWidth = obj.outerWidth(), objHalf = objTop + objHeight / 2; if (lastObj) { lastObj.css({'transform': ''}) } if (!overEmpty) { if (event.clientY + $(window).scrollTop() < objHalf) { obj.not('.vc_row').css({'transform': 'translateY(5px)'}); d.css({'top': objTop, 'left': objLeft, width: objWidth, height: 5, background: ''}); direction = 'up'; } else { obj.not('.vc_row').css({'transform': 'translateY(-5px)'}); d.css({ 'top': objTop + objHeight, 'left': objLeft, width: objWidth, height: 5, background: '' }); direction = 'down'; } } else { d.css({ 'top': objTop, 'left': objLeft, height: objHeight, width: objWidth, background: 'rgba(136,206,255,0.4)', border: 'solid 2px #8fcbff' }); } lastObj = obj; } else { if (lastObj) { lastObj.css({'transform': ''}) } lastObj = null; d.css({width: '', border: ''}); } }, stop: function (event, ui){ $('.drop-here-container').remove(); t.clear_shortcodes_panel_input(); t.removeColumnSeparator(); clearInterval(fly); t.shortcode_panel_animation(); try { $('.pixflow-shortcodes-panel').getNiceScroll().resize(); } catch (e) {} $(this).css('visibility', 'visible'); if (!lastObj || !lastObj.length) { return; } lastObj.css({'transform': ''}) if(lastObj.hasClass('section-open')){ direction = 'up'; } if (direction == 'up') { if (lastObj.hasClass('vc_row') && !lastObj.hasClass('vc_inner')) { if (lastObj.prev('.insert-after-row-placeholder').length) { var p = lastObj.prev('.insert-after-row-placeholder'); } else { var p = lastObj.prev().prev('.insert-after-row-placeholder'); } } else if (lastObj.hasClass('blank-page')) { var p = lastObj; } else if (lastObj.hasClass('vc_empty-element')) { var p = lastObj.closest('.vc_column_container'); } else if (t.containers[lastObj.attr('data-mbuilder-el')] && overEmpty) { var p = lastObj.find(t.containers[lastObj.attr('data-mbuilder-el')]); } else if (lastObj.hasClass('section-open')) { var p = lastObj; }else { var p = lastObj.prev('.insert-between-placeholder'); if (!p.length) { var p = lastObj.parent().closest('.mBuilder-element').prev('.insert-between-placeholder'); } } } else { if (lastObj.hasClass('vc_row') && !lastObj.hasClass('vc_inner')) { var p = lastObj.next('.insert-after-row-placeholder'); } else if (lastObj.hasClass('blank-page')) { var p = lastObj; } else if (lastObj.hasClass('vc_empty-element')) { var p = lastObj.closest('.vc_column_container'); } else if (t.containers[lastObj.attr('data-mbuilder-el')] && overEmpty) { var p = lastObj.find(t.containers[lastObj.attr('data-mbuilder-el')]); } else { var p = lastObj.next('.insert-between-placeholder'); if (!p.length) { var p = lastObj.parent().closest('.mBuilder-element').next('.insert-between-placeholder'); } } } placeholder = p.get(0); d.css({'width': '', border: ''}); if (lastObj.hasClass('content-container')) { placeholder = $('.insert-after-row-placeholder').last(); t.buildShortcode(placeholder, 'vc_row', {}, function (response) { if($('body').hasClass('one_page_scroll')){ pixflow_one_page_for_customizer(); } if (shortcode == 'vc_row') { return; } t.buildShortcode(response.find('.vc_column_container'), shortcode); }); } else { if (placeholder != null) { if (p.hasClass('insert-after-row-placeholder')) { var attr = {}; if ( p.hasClass('blank-page') ){ attr.row_padding_top = t.top_page_space() + 50; } t.buildShortcode(placeholder, 'vc_row', attr, function (response) { if($('body').hasClass('one_page_scroll')){ pixflow_one_page_for_customizer(); } if (shortcode == 'vc_row') { return; } t.buildShortcode(response.find('.vc_column_container'), shortcode); }); } else { if (shortcode == 'vc_row') { shortcode = 'vc_row_inner'; } t.buildShortcode(placeholder, shortcode); } } } } }); $('.pixflow-shortcodes-panel .section-container, .pixflow-shortcodes-panel .pixflow-custom-section').draggable({ appendTo: "body", helper: "clone", zIndex: 9999999, containment: 'document', cursorAt: {top: 20, left: 50}, start: function (event, ui) { clearInterval(fly); section = $(this).data('section-id'); if( $(this).hasClass('pixflow-custom-section') ){ sectionType = true; }else{ sectionType = false; } $(this).css('visibility', 'hidden'); if($('.insert-after-row-placeholder.blank-page').length){ $('#p-btn-addsections').click(); } }, drag: function (event, ui) { shortcode_panel_drag_fly(event); var el = get_hovered_element(ui.helper,event.clientX, event.clientY); if (el) { if (el == d.get(0)) return true; if(is_over_shortcode_panel(el)){ return true; } close_shortcode_panel_on_drag(); var selector = $('.section-open').length ? '.section-open' : '.vc_row:not(.vc_inner)'; var obj = $( el ).closest( selector ); if( !obj.length ){ if( lastObj != null ){ lastObj.removeClass('section-placeholder'); } lastObj = null; d.css( {width: '', border: ''} ); return true; } if( obj.hasClass( 'vc_row' ) ){ var objTop = obj.offset().top, objLeft = obj.offset().left, objHeight = obj.outerHeight(), objWidth = obj.outerWidth(), objHalf = objTop + objHeight / 2; if (event.clientY + $(window).scrollTop() < objHalf) { d.css({ 'top': objTop, 'left': objLeft, width: objWidth, height: 5, background: '#6226eb', }); lastObj = obj.prev('.insert-after-row-placeholder'); } else { d.css({ 'top': objTop + objHeight, 'left': objLeft, width: objWidth, height: 5, background: '#6226eb', }); lastObj = obj.next('.insert-after-row-placeholder'); } }else { if( ! $('.drop-here-container').length ){ $('.empty-page-title').append('
    Drop It Here
    '); } obj.addClass('section-placeholder'); lastObj = obj; } } else { if(lastObj != null){ lastObj.removeClass('section-placeholder'); } lastObj = null; } }, stop: function (event, ui){ $('.drop-here-container').remove(); clearInterval( fly ); d.css({'width': '', border: ''}); $('.insert-after-row-placeholder.blank-page').removeClass('section-open'); try { $('.pixflow-shortcodes-panel').getNiceScroll().resize(); } catch (e) {} $(this).css('visibility', 'visible'); if (!lastObj || !lastObj.length) { return; } lastObj.removeClass('section-placeholder'); placeholder = lastObj.get(0); if (placeholder != null) { if (lastObj.hasClass('insert-after-row-placeholder')) { $(placeholder).addClass('dropped'); t.section_builder( section ,placeholder, sectionType ); } } } }); function check_over_empty_page(el){ obj = $(el).closest('.blank-page'); if (obj.length) { lastObj = obj; var objTop = obj.offset().top + 100, objLeft = obj.offset().left + 100, objHeight = obj.outerHeight() - 200, objWidth = obj.outerWidth() - 200; d.css({ 'top': objTop, 'left': objLeft, height: objHeight, width: objWidth, background: 'transparent', }); if( ! $('.drop-here-container').length ){ $('.empty-page-title').append('
    Drop It Here
    '); } return true; } return false; } function check_over_rows(obj){ if (obj.hasClass('mBuilder-vc_column') || obj.hasClass('mBuilder-vc_column_inner')) { if (obj.find('> .vc_empty-element').length) { obj = obj.find('> .vc_empty-element'); overEmpty = true; } else { if (!obj.hasClass('mBuilder-vc_column_inner')) { d.css({border: '', borderTop: '4px solid #43dc9d'}); obj = obj.closest('.vc_row'); } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); obj = obj.closest('.vc_inner'); } } return [true,obj]; } else if (obj.hasClass('vc_row')) { if (!obj.hasClass('vc_inner')) { d.css({border: '', borderTop: '4px solid #43dc9d'}); } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); obj = obj.closest('.vc_inner'); } return [true,obj]; } return [false,obj]; } function check_over_shortcode(obj){ if (obj.length && !obj.hasClass('vc_row') && !obj.hasClass('mBuilder-vc_column') && !obj.hasClass('mBuilder-vc_column_inner')) { if (t.containers[obj.attr('data-mbuilder-el')]) { if (!obj.find('.mBuilder-element').length) { overEmpty = true; } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); } } else { d.css({border: '', borderTop: '4px solid #8fcbff'}); } return true; } return false; } function check_over_page(obj){ if (obj.hasClass('content-container') && $('.vc_row').length) { lastObj = obj; d.css({ border: '', height: '0px', left: $('.vc_row').last().offset().left + 'px', borderTop: '4px solid #43dc9d', top: $('.vc_row').last().offset().top + $('.vc_row').last().outerHeight() + 'px', width: obj.width() }); return true; } return false; } function is_over_shortcode_panel(el){ if($(el).closest('.pixflow-shortcodes-panel').length){ overEmpty = true; lastObj = null; d.css({width: '', border: ''}); return true; } } function close_shortcode_panel_on_drag(){ if(!$('.pixflow-shortcodes-panel').hasClass('close')){ $('.pixflow-shortcodes-panel').addClass('close'); } } function get_hovered_element(helper,x,y){ helper.css('display','none'); var el = document.elementFromPoint(x, y); helper.css('display',''); return el; } /////////////////////////////////// var fly = null; function shortcode_panel_drag_fly(event){ clearInterval(fly); if (event.clientY < 100) { fly = setInterval(function () { if($(window).scrollTop()==0){ clearInterval(fly); } $(window).scrollTop($(window).scrollTop() - 50) }, 50); } else if (event.clientY > $(window).height() - 50) { fly = setInterval(function () { if($(window).scrollTop()>=$(document).height()-$(window).height()){ clearInterval(fly); } $(window).scrollTop($(window).scrollTop() + 50) }, 50); } } }; mBuilder.prototype.add_nicescroll = function(){ $('.pixflow-shortcodes-container, .pixflow-sections-container').niceScroll({ horizrailenabled: false, cursorcolor: "rgba(204, 204, 204, 0.2)", cursorborder: "1px solid rgba(204, 204, 204, 0.2)", cursorwidth: "2px", enablescrollonselection: false }); }; mBuilder.prototype.search_shortcode = function() { var typing_in_search_box_time, typing_interval_done = 500, $shortcodes_category = $('.pixflow-shortcodes-panel .category-container'), $shortcodes = $('.category-container .shortcodes'), first_search_value = ""; $('.pixflow-search-shortcode').keyup(function (e) { var search_value = $(this).val().toLowerCase(); if (first_search_value != search_value) { $shortcodes.removeClass('active'); $shortcodes_category.removeClass('show'); clearTimeout(typing_in_search_box_time); typing_in_search_box_time = setTimeout(function () { if (search_value != "") { $('.category-container .shortcodes[data-name*="' + search_value + '"]').addClass('active'); $('.category-container .shortcodes[data-name*="' + search_value + '"]').parents('.category-container').addClass('show') } else { $shortcodes.addClass('active'); $shortcodes_category.addClass('show'); } }, typing_interval_done); } first_search_value = search_value; }); }; mBuilder.prototype.shortcode_panel_animation = function() { $('.pixflow-shortcodes-panel').toggleClass('close'); }; /** * @summary build shortcode in the placeholder that given. * * @param {object | string} placeholder - placeholder to drop shortcode. * @param {string} shortcode - shortcode type * @param {Object} atts - attributes of the shortcode * @param {function} callback - a callback function to call after build shortcode * @since 1.0.0 */ mBuilder.prototype.buildShortcode = function (placeholder, shortcode, atts, callback) { if (placeholder && shortcode) { var t = this, dropSection = 'pre-made' , atts = atts; var loaderHtml = $('
    ' + '
    ' + '' + '' + '' + '
    '); if (placeholder.prevObject) { var shortcodeloader = $(placeholder.prevObject).find('.vc_column-inner'); $(loaderHtml).prependTo($(shortcodeloader)); } else if ($(placeholder).hasClass('insert-between-placeholder')) { $(placeholder).css({ 'display': 'block', 'height': '60px' }).append(loaderHtml); } else { if(!$(placeholder).hasClass('section-open')){ $(placeholder).css({ 'bottom': '0', 'height': 'auto' }); } $(loaderHtml).prependTo($(placeholder)); } if( typeof atts != "undefined" && true == atts.customSection ){ dropSection = 'custom'; } $.ajax({ type: 'post', url: mBuilderValues.ajax_url, data: { action: 'mBuilder_buildShortcode', nonce: mBuilderValues.ajax_nonce, shortcode: shortcode, act: 'build', attrs: JSON.stringify(atts), mbuilder_editor: true , section_type : dropSection }, success: function (response) { if ($(placeholder).hasClass('insert-between-placeholder')) { $(placeholder).css({ 'display': 'none', 'height': '0px' }); } $('.showbox-shotcode').remove(); var attrs = ''; $.each(atts, function (index, value) { attrs = attrs + ' ' + index + '="' + value + '"'; }); attrs = attrs.trim(); response = t.setSettings(response, shortcode, placeholder, attrs); var id = response['id']; response = $(response['shortcode']); if ($(placeholder).hasClass('vc_column_container') || $(placeholder).hasClass('vc_row') || $(placeholder).hasClass('vc_row_inner') || $(t.droppables).filter($(placeholder)).length) { if ($(placeholder).hasClass('vc_row') || $(placeholder).hasClass('vc_row_inner')) { $(placeholder).find('>.wrap').append(response); } else if ($(placeholder).find('>.vc_column-inner>.wpb_wrapper').length) { $(placeholder).find('>.vc_column-inner>.wpb_wrapper').append(response); } else { if (!$(placeholder).find('.mBuilder-element').length) { $(placeholder).html(''); } $(placeholder).append(response); } $(placeholder).removeClass('vc_empty-element'); } else if ($(placeholder).hasClass('vc_btn-content')) { if (t.tabs[$(placeholder).closest('.mBuilder-element').attr('data-mbuilder-el')]) { var tab = $(t.tabs[$(placeholder).closest('.mBuilder-element').attr('data-mbuilder-el')][1]); $(placeholder).closest('.mBuilder-element').find('ul').first().append(tab); var unique = Math.floor(Math.random() * 1000000); tab.find('a').attr('href', '#tab-' + unique); response.find('.wpb_tab').first().attr('id', 'tab-' + unique); } if ($(placeholder).closest('.mBuilder-element').find('ul.px_tabs_nav').parent().length) { $(placeholder).closest('.mBuilder-element').find('ul.px_tabs_nav').first().parent().append(response); } else { $(placeholder).closest('.mBuilder-element').find('.wpb_wrapper').first().append(response); } t.updateShortcode($(placeholder).closest('.mBuilder-element').attr('data-mbuilder-id'), $(placeholder).closest('.mBuilder-element').attr('data-mbuilder-el'), t.models.models[$(placeholder).closest('.mBuilder-element').attr('data-mbuilder-id')].attr, undefined, true); } else { $(placeholder).before(response); } t.specialShortcodes(shortcode, id); t.renderControls(); t.setSortable(); $(window).resize(); if (typeof callback == 'function') { callback(response); } // Callback for sectio //n builder if (typeof atts != 'undefined' && typeof atts['section_id'] != 'undefined' && typeof callback == 'function') { callback(id); } $('body').addClass('changed'); $('body').trigger('finish_build_shortcode' , [ id, shortcode ] ); } }) } }; /** * @summary create shortcode model and add it to the models object * * @param {string} response - HTML response after build shortcode * @param {string} type - shortcode type * @param {string | object} parent - parent selector or jQuery object * @param {string} atts - attributes of the shortcode * @param {string} content - content of the shortcode * * @return {object} - model ID and HTML of the shortcode * @since 1.0.0 */ mBuilder.prototype.setSettings = function (response, type, parent, atts, content) { var rand, inModels = true, t = this; parent = $(parent); if (parent.hasClass && parent.hasClass('insert-between-placeholder')) { parent = parent.closest('.mBuilder-element').attr('data-mbuilder-id'); } else { parent = parent.attr('data-mbuilder-id'); } var istab = false; for (var i in t.tabs) { if (t.tabs[i][0] == type) { istab = true; } } if (istab) { var unique = Math.floor(Math.random() * 1000000); atts += ' tab_id=\'' + unique + '\''; } if (type == 'md_text' && !content) { content = $(response).find('.md-text-content').html(); } while (inModels) { rand = parseInt(Math.random() * 10000); if (typeof this.models.models[rand] == 'undefined') { t.models.models[rand] = { attr: atts, content: content, parentId: parent, type: type }; inModels = false; } } var o = $(response).clone(); o.find('.mBuilder-element').each(function () { var r = t.setSettings($(this)[0].outerHTML, $(this).attr('data-mBuilder-el'), $(this).parent().closest('.mBuilder-element')); $(r['shortcode']).insertAfter($(this)); $(this).remove(); }); var result = []; var m_builder_element = o.filter('div').first().attr('data-mbuilder-id', rand); o.each(function(){ if($(this)[0] == m_builder_element[0]) return; $(this).removeAttr('data-mbuilder-id').prependTo(m_builder_element); }); result['shortcode'] = m_builder_element[0].outerHTML; result['id'] = rand; o.remove(); return result; }; /** * @summary update shortcode model and rebuild it after edit * * @param {integer} id - ID of shortcode model * @param {string} shortcode - shortcode type * @param {string | object} attr - attributes of the shortcode * @param {string} content - content of the shortcode * @since 1.0.0 */ mBuilder.prototype.updateShortcode = function (id, shortcode, attr, content, asParent ) { // Update elems object var t = this, attrs = oldClasses = ''; if (typeof attr == 'object') { $.each(attr, function (index, value) { if (index == 'content') { return true; } value = value.replace(new RegExp('"', 'g'), "'"); attrs = attrs + index + '=' + '"' + value + '" '; }); } else { attrs = attr; } if (!content) { var content = ''; if (shortcode == 'vc_row') { content = $('[data-mbuilder-id="' + id + '"]').find('> .wrap').html(); } else if (t.shortcodes[shortcode] && t.shortcodes[shortcode].as_parent && !t.tabs[shortcode]) { content = $('[data-mbuilder-id="' + id + '"]').find('> .wpb_content_element > .wpb_wrapper').html(); } else if (t.containers[shortcode]) { content = $('[data-mbuilder-id="' + id + '"]').find(t.containers[shortcode]).html(); } else { content = attr['content']; } t.models.models[id]['content'] = attr['content']; } else { t.models.models[id]['content'] = content; } t.models.models[id]['attr'] = attrs; oldClasses = $('[data-mbuilder-id="' + id + '"]').attr('class'); attrs = typeof attr == 'object' ? JSON.stringify(attr) : attr; // Build shortcode $.ajax({ type: 'post', url: mBuilderValues.ajax_url, data: { action: 'mBuilder_buildShortcode', nonce: mBuilderValues.ajax_nonce, shortcode: shortcode, act: 'rebuild', id: id, content: content, attrs: attrs, mbuilder_editor: true }, success: function (response) { var container = $('.mBuilder-element[data-mbuilder-id=' + id + ']'); html = document.createElement('div'); html.innerHTML = response ; for(var i = 0 ; i < html.children.length ; i ++){ html.children[i].setAttribute('data-mbuilder-id', id); } var parent = container.parent().closest('.mBuilder-element'); if (asParent || ( parent.length && t.shortcodes[parent.attr('data-mbuilder-el')] && t.shortcodes[parent.attr('data-mbuilder-el')].as_parent && t.shortcodes[parent.attr('data-mbuilder-el')].as_parent.only == container.attr('data-mbuilder-el') ) ) { var parentId = parent.attr('data-mbuilder-id'); var type = parent.attr('data-mbuilder-el'); builder.update_meditor_models(); $.ajax({ type: 'post', url: mBuilderValues.ajax_url, data: { action: 'mBuilder_doShortcode', nonce: mBuilderValues.ajax_nonce, shortcode: t.shortcodeTag(parent, false), mbuilder_editor: true }, success: function (response) { try { parent.replaceWith(response); var id = $(response).find('[data-mbuilder-el="' + shortcode + '"]').first().attr('data-mbuilder-id'); t.specialShortcodes( shortcode, id ); for (var i in t.shortcodes) { if (t.shortcodes[i].as_parent && t.shortcodes[i].as_parent.only == shortcode) { t.specialShortcodes(i, $( '[data-mbuilder-id="' + id + '"]' ).closest( '[data-mbuilder-el="' + i + '"]' ).attr( 'data-mbuilder-id' ) ); } } t.renderControls(); t.setSortable(); $(window).resize(); } catch (e) { console.log(e); } $('body').trigger('update_shortcode'); } }) } else { try { container.replaceWith(html.innerHTML); html = '' ; html = $(response); t.specialShortcodes(shortcode, id); t.renderControls(); $(window).resize(); } catch (e) { console.log(e); } $('body').trigger('update_shortcode'); } var $mbuilderId = $('[data-mbuilder-id="' + id + '"]'); if ($mbuilderId.data('mbuilder-el') == 'md_text') { $mbuilderId.attr('class', oldClasses); } if($mbuilderId.hasClass('vc_row') && $('body').hasClass('one_page_scroll')){ pixflow_one_page_for_customizer(); } t.setSortable(); $('body').addClass('changed'); $('body').trigger('finish_shortcode_progress'); } }) }; mBuilder.prototype.shortcodeRegex = function ( tag ) { return new RegExp( '\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g' ); } mBuilder.prototype.sectionExists = function ( sectionName ) { if( "undefined" == typeof this.customSection[ sectionName ] ){ return true; } return false; } mBuilder.prototype.getCustomSection = function(){ if( ! customSections.length ){ return this.customSection; } this.customSection = JSON.parse( customSections ); return true; }; mBuilder.prototype.createSectionSource = function(){ var userSections = ''; if( Object.keys( this.customSection ).length == 0 ){ return ; } for( var i in this.customSection ){ userSections += '
    ' + i + '
    +
    '; } var html = '
    Your Sections
    ' + userSections + '
    '; $('.pixflow-custom-sections').remove(); $('.pixflow-sections-container').append(html); }; mBuilder.prototype.addToSectionPanel = function( sectionName ) { var userSections = ''; if( Object.keys( this.customSection ).length == 1 ){ this.createSectionSource(); return; } userSections += '
    ' + sectionName + '
    +
    ' + '
    '; $('.pixflow-custom-sections').append( userSections ); }; /** * @summary Save section * * @param {object} selector - DOM element | jQuery element * @param {string} sectionName - Used for custom section name * * @return {string} - shortcodeTag * @since 5.1 */ mBuilder.prototype.saveSection = function( selector, sectionName ){ if( ! this.sectionExists( sectionName ) ){ document.getElementsByClassName("popupSaveSection-error")[0].innerHTML = 'section is already exists please choose another name'; return ; } // upadte meditor shortcodes models before create section this.update_meditor_models(); var that = this, getShortocdeTag = that.shortcodeTag( selector ), regex = that.shortcodeRegex( 'vc_row' ), params = regex.exec( getShortocdeTag ), rowAttrs = wp.shortcode.attrs( params[3] ), sectionContent = params[5]; rowAttrs.named['content'] = sectionContent; sectionName = sectionName.trim(); document.getElementsByClassName("popupSaveSection-button")[0].innerHTML = 'SAVING'; $.ajax({ type: 'post', url: mBuilderValues.ajax_url, data: { action : 'mBuilder_save_custom_section', section : rowAttrs.named, section_name : sectionName, }, success: function ( response ) { if( response == 1 ){ that.customSection[ sectionName ] = rowAttrs.named ; document.getElementsByClassName("popupSaveSection-button")[0].innerHTML = 'SAVED'; setTimeout(function(){ that.closeSaveSectionPopup(); },500); that.addToSectionPanel( sectionName ); that.applyDragForce( '.pixflow-custom-section[data-section-id="' + sectionName + '"]'); setTimeout(function () { $('.pixflow-add-element-button').click(); var down = $('.pixflow-sections-container'); down.scrollTop( down.prop("scrollHeight") ); $('.panel-tab[data-tab="sections"]').click(); }, 500 ); return ; } document.getElementsByClassName("popupSaveSection-button")[0].innerHTML = 'CREATE'; document.getElementsByClassName("popupSaveSection-error")[0].innerHTML = 'Oops! Something went wrong with Saving!'; }, error: function () { document.getElementsByClassName("popupSaveSection-button")[0].innerHTML = 'CREATE'; document.getElementsByClassName("popupSaveSection-error")[0].innerHTML = 'Network error!'; }, }); } /** * @summary Close Save section popup * * @return {void} * @since 5.1 */ mBuilder.prototype.closeSaveSectionPopup = function( ){ $('.popupSaveSection-container').fadeOut(500,function(){ $(this).css({'opacity':'1'}); document.getElementsByClassName("popupSaveSection-field")[0].value = ''; document.getElementsByClassName("popupSaveSection-button")[0].innerHTML = 'CREATE'; }); document.getElementsByClassName("popupSaveSection-error")[0].innerHTML = ''; } mBuilder.prototype.deleteSection = function( sectionName ){ var that = this; if( that.sectionExists( sectionName ) ){ alert('section is not exists '); return ; } sectionName = sectionName.trim(); $.ajax({ type: 'post', url: mBuilderValues.ajax_url, data: { action : 'mBuilder_delete_custom_section', section_name : sectionName, }, success: function ( response ) { if( response == 1 ){ delete that.customSection[ sectionName ]; $('body').trigger( 'delete_section', [ sectionName ] ); return ; } alert('Error on delete section'); }, error: function () { alert('Network error'); }, }); } /** * @summary generate shortcodeTag from DOM element * * @param {object} obj - DOM element | jQuery element * @param {bool} onlyChildren - if true it returns just children shortcodeTags * @param {int} depth - used in recursive calls * * @return {string} - shortcodeTag * @since 1.0.0 */ mBuilder.prototype.shortcodeTag = function (obj, onlyChildren, depth) { var t = this, el = $(obj), id = el.attr('data-mbuilder-id'); if (!el.length) { return ''; } if (!depth) { depth = 0; } var model = t.models.models[id]; model.attr = model.attr != undefined ? model.attr : ''; model.content = model.content != undefined ? model.content : ''; if (!onlyChildren) { var tag = '[' + model.type + ' ' + model.attr + ' mbuilder-id="' + id + '"]' + model.content; } depth++; el.find('.mBuilder-element').each(function () { for (var i in t.compiledTags) { if (t.compiledTags[i] == this) return; } tag += t.shortcodeTag(this, false, depth); }); t.compiledTags.push(el.get(0)); depth--; if (!onlyChildren) { tag += '[/' + model.type + ']'; } if (depth == 0) { t.compiledTags = []; } return tag; }; /** * @summary save contents and shortcodes to the database * * @since 1.0.0 */ mBuilder.prototype.saveContent = function () { var t = this; $('body').addClass('content-saving'); // Set Parents this.set_parents(); // Calculate orders $('.mBuilder-element').each(function () { var $el = $(this), id = $el.attr('data-mBuilder-id'); var order = 1; $el.siblings(".mBuilder-element").addBack().each(function () { t.models.models[$(this).attr('data-mbuilder-id')]['order'] = order++; }); }); // upadte meditor shortcodes models t.update_meditor_models(); var models = {}; for(i in t.models.models){ if(t.models.models[i]!=null){ models[i] = t.models.models[i]; } } this.save_button_animation_start(); $.ajax({ type: 'post', url: mBuilderValues.ajax_url, data: { action: 'mBuilder_saveContent', nonce: mBuilderValues.ajax_nonce, models: JSON.stringify(models), id: $('meta[name="post-id"]').attr('content'), mbuilder_editor: true }, success: function (response) { $('body').removeClass('content-saving changed'); t.save_button_animation_end(); if(typeof t.save_callback_function == 'function') { t.save_callback_function(); } } }); }; /** * @summary Apply dependencies to the shortcode setting panel * * @since 1.0.0 */ var dependChange = [] ; mBuilder.prototype.dependencyInjection = function () { var tabs = this.settingPanel.find('#mBuilderTabs > ul li'); this.settingPanel.find('[data-mBuilder-dependency]').each(function () { var json = JSON.parse($(this).attr('data-mBuilder-dependency')); var el = $(this); if(typeof json.element == 'undefined') return ; var depend = $('[name=' + json.element + ']'); dependChange.push(depend); if (depend.attr('type') != 'hidden' || depend.attr('data-type') == 'dropdown') { if (typeof json.value != 'object') { json.value = [json.value]; } if ($.inArray($(depend).val(), json.value) != -1 && !$(depend).closest('.vc_column').hasClass('dependency-hide') ) { el.removeClass('dependency-hide'); } else { el.addClass('dependency-hide'); } el.find('select,input').trigger('change'); tabs.each(function () { var id = $(this).attr('aria-controls'); var result = false; var element = document.getElementById(id); $(element).find('>.vc_column').each(function () { if (!$(this).hasClass('dependency-hide')) { result = true; return false; } }); if (!result) { $(this).addClass('dependency-hide'); } else { $(this).removeClass('dependency-hide'); } }); // depend.change(function () { if (typeof json.value != 'object') { json.value = [json.value]; } if ($.inArray($(this).val(), json.value) != -1 && ! $(this).closest('.vc_column').hasClass('dependency-hide') ) { el.removeClass('dependency-hide'); } else { el.addClass('dependency-hide'); } el.find('select,input').trigger('change'); el.find('.dropdown-title').click(); tabs.each(function () { var id = $(this).attr('aria-controls'); var result = false; var element = document.getElementById(id); $(element).find('>.vc_column').each(function () { if (!$(this).hasClass('dependency-hide')) { result = true; return false; } }); if (!result) { $(this).addClass('dependency-hide'); } else { $(this).removeClass('dependency-hide'); } }); }); } else { if (typeof json.value != 'object') { json.value = [json.value]; } if ($.inArray(depend.val(), json.value) != -1 && !depend.closest('.vc_column').hasClass('dependency-hide') ) { el.removeClass('dependency-hide'); } else { el.addClass('dependency-hide'); } el.find('select,input').trigger('change'); tabs.each(function () { var id = $(this).attr('aria-controls'); var result = false; var element = document.getElementById(id); $(element).find('>.vc_column').each(function () { if (!$(this).hasClass('dependency-hide') ) { result = true; return false; } }); if (!result) { $(this).addClass('dependency-hide'); } else { $(this).removeClass('dependency-hide'); } }); depend.siblings('[data-name=' + depend.attr('name') + ']').change(function () { setTimeout(function(){ if (typeof json.value != 'object') { json.value = [json.value]; } if ($.inArray(depend.val(), json.value) != -1 && ! depend.closest('.vc_column').hasClass('dependency-hide') ) { el.removeClass('dependency-hide'); } else { el.addClass('dependency-hide'); } el.find('select,input').trigger('change'); tabs.each(function () { var id = $(this).attr('aria-controls'); var result = false; var element = document.getElementById(id); $(element).find('>.vc_column').each(function () { if (!$(this).hasClass('dependency-hide')) { result = true; return false; } }); if (!result) { $(this).addClass('dependency-hide'); } else { $(this).removeClass('dependency-hide'); } }); },1); }); } }); setTimeout(function(){ $('.setting-panel-container').css('display' , 'block'); } , 50 ); }; /** * @summary media panel for the image controller in the shortcode setting panel * * @since 1.0.0 */ mBuilder.prototype.mediaPanel = function () { // Set all variables to be used in scope var frame; // ADD IMAGE LINK $('body').on('click', '.mBuilder-upload-img.single', function (event) { event.preventDefault(); $(this).addClass('active-upload'); // If the media frame already exists, reopen it. if (frame) { frame.open(); return; } // Create a new media frame frame = window.top.wp.media({ title: 'Select or Upload Media Of Your Chosen Persuasion', button: { text: 'Use this media' }, multiple: false // Set to true to allow multiple files to be selected }); var t = this; // When an image is selected in the media frame... frame.on('select', function () { var $this = $('.mBuilder-upload-img.single.active-upload'); // Get media attachment details from the frame state var attachment = frame.state().get('selection').first().toJSON(); // Send the attachment URL to our custom image input field. $this.css('background-image', 'url("' + attachment.url + '")').css('background-size', '100% 100%'); // Send the attachment id to our hidden input $this.find('input').val(attachment.id); $this.find('.remove-img').removeClass('mBuilder-hidden'); $('.mBuilder-upload-img.single').removeClass('active-upload'); }); // Finally, open the modal on click frame.open(); }); // DELETE IMAGE LINK $('body').on('click', '.mBuilder-upload-img.single .remove-img', function (event) { event.preventDefault(); event.stopPropagation(); // Clear out the preview image $(this).closest('.mBuilder-upload-img').css({'background-image': '', 'background-size': ''}); $(this).parent().removeClass('has-img'); $(this).addClass('mBuilder-hidden'); // Delete the image id from the hidden input $(this).siblings('input').val(''); }); }; /** * @summary set parents for models and delete extra models * * @since 1.0.0 */ mBuilder.prototype.set_parents = function () { var t = this; for (var index in t.models.models) { var $el = $('div[data-mBuilder-id=' + index + ']'), $parent = $el.parent().closest('.mBuilder-element'); if (!$el.length) { delete(t.models.models[index]); } if ($parent.length) { var parentId = $parent.attr('data-mBuilder-id'); t.models.models[index].parentId = parentId; } } }; /** * @summary dropdown controller in the shortcode setting panel * * @since 1.0.0 */ mBuilder.prototype.dropdown = function(){ $('body').on('click','.dropdown-title',function(){ var $dropdown = $(this).parent(), this_tab = $(this).closest( '.mBuilder-edit-el' ); $( '#mBuilderTabs .mbuilder-dropdown' ).not( $dropdown ).removeClass( 'open' ); if ( $dropdown.hasClass( 'open' ) ){ $dropdown.removeClass( 'open' ) }else{ $dropdown.addClass( 'open' ); var last_dropdown = this_tab.find( '.mbuilder-controller' ).last(); if ( last_dropdown.is( '.dropdown' ) && last_dropdown.find( '.mbuilder-dropdown.open' ).length ) { this_tab.scrollTop( this_tab[0].scrollHeight ); } } }); $('body').on('click','.dropdown-option',function(){ var $dropdown = $(this).closest('.mbuilder-dropdown'), $selected_element = $(this).closest('.mbuilder-dropdown').find('.mbilder-dropdown-selected'); $dropdown.find('.dropdown-option').removeClass('selected-option'); $(this).addClass('selected-option'); $selected_element.html($(this).text()); $dropdown.find('input').val($(this).attr('data-dropdown-value')); $dropdown.find('input').trigger('change_font_family'); $dropdown.find('input').trigger('change'); $dropdown.find('.dropdown-title').click(); }); $('body').on('click','.mBuilder-edit-el',function(e){ if ($(e.target).hasClass('dropdown-title') || $(e.target).closest('.dropdown-title').length ){ return; } $('.mbuilder-dropdown').removeClass('open') }); } /** * @summary multi media panel for the multi image controller in the shortcode setting panel * * @since 1.0.0 */ mBuilder.prototype.multiMediaPanel = function () { // Set all variables to be used in scope var frame; // ADD IMAGE LINK $('body').on('click', '.mBuilder-upload-imgs .mBuilder-upload-img', function (event) { event.preventDefault(); // If the media frame already exists, reopen it. /* if (false) { frame.open(); return; }*/ // Create a new media frame frame = window.top.wp.media({ title: 'Select or Upload Media Of Your Chosen Persuasion', button: { text: 'Use this media' }, multiple: 'add' // Set to true to allow multiple files to be selected }); var t = this, $container = $(t).parent(); // When an image is selected in the media frame... frame.on('select', function () { // Get media attachment details from the frame state var attachment = frame.state().get('selection').toJSON(); var attachments = ''; $container.find('.mBuilder-upload-img').remove(); for (var i = 0; i < attachment.length; i++) { if(attachment[i]['id'] == ''){ continue; } attachments = attachments + attachment[i]['id'] + ','; if (attachment[i]['id'] != "" ) $container.append('
    '); } $container.append('
    X
    '); attachments = attachments.slice(0, -1); // Send the attachment id to our hidden input $container.find('input').val(attachments); }); // Finally, open the modal on click frame.on('open',function() { var selection = frame.state().get('selection'); var ids = $container.find('input').val().split(','); ids.forEach(function(id) { var attachment = wp.media.attachment(id); attachment.fetch(); selection.add( attachment ? [ attachment ] : [] ); }); }); frame.open(); }); // DELETE IMAGE LINK $('body').on('click', '.mBuilder-upload-imgs .mBuilder-upload-img .remove-img', function (event) { var t = this, $container = $(t).parent().parent(), $this = $(this).parent(); event.preventDefault(); event.stopPropagation(); // Delete the image id from the hidden input var val = $container.find('input').val(), valarr = val.split(","), index = valarr.indexOf($this.attr('data-id')); if (index > -1) { valarr.splice(index, 1); } $container.find('input').val(valarr.join()); // Clear out the preview image $this.remove(); }); }; /** * @summary Google Font Controller in the Shortcode setting panel * * @since 1.0.0 */ mBuilder.prototype.googleFontPanel = function () { function generateInputVal(paramName) { var $fontFamily = $('.google-fonts-families[data-input="' + paramName + '"]'), $fontStyle = $('.google-fonts-styles[data-input="' + paramName + '"]'), $input = $('input[name="' + paramName + '"]'), fontFamily = 'font_family:' + encodeURIComponent($fontFamily.find('>input').val()), fontStyle = 'font_style:' + encodeURIComponent($fontStyle.find('>input').val()); $input.attr('value',fontFamily + '|' + fontStyle); } $('body').on('change_font_family', 'input[name="google-fonts-families"]', function (event) { // check if event doesn't call from jquery var $this = $(this).parent(); $('.google-fonts-styles[data-input="' + $this.attr("data-input") + '"] .dropdown-options').html('
    Loading...
    '); $.ajax({ type: 'post', url: mBuilderValues.ajax_url, data: { action: 'pixflow_loadFontStyles', nonce: mBuilderValues.ajax_nonce, fontKey: $this.find(".selected-option").attr('data-font-id'), value: '', mbuilder_editor: true }, success: function (response) { $('.google-fonts-styles[data-input="' + $this.attr("data-input") + '"] .dropdown-options').html(response); generateInputVal($this.attr('data-input')); } }); }); $('body').on('change', 'input[name = "google-fonts-styles"]', function (event) { generateInputVal($(this).parent().attr('data-input')); }); }; /** * @summary call user functions that sets to call after each shortcode build or rebuild * * @param {string} type - shortcode type * @param {object} obj - jQuery object of shortcode * @since 1.0.0 */ mBuilder.prototype.specialShortcodes = function (type, id) { var that = this; var obj = $( '[data-mbuilder-id='+ id +']' ); var obj_child = obj.find('[data-mbuilder-id]'); if ( obj_child.length ){ obj_child.each(function(){ that.specialShortcodes( $(this).attr('data-mbuilder-el') , $(this).attr('data-mbuilder-id') ); }); } if (typeof this[type + "Shortcode"] == 'function') { this[type + "Shortcode"](obj); } obj.parents('.mBuilder-element[data-mbuilder-el="md_accordion_tab"]').find('h3.ui-state-active').siblings('.wpb_accordion_content').css('height', ''); obj.parents('.mBuilder-element[data-mbuilder-el="md_toggle_tab"]').find('h3.ui-state-active').siblings('.wpb_toggle_content').css('height', ''); obj.parents('.mBuilder-element[data-mbuilder-el="md_toggle_tab2"]').find('h3.ui-state-active').siblings('.wpb_toggle_content').css('height', ''); }; mBuilder.prototype.vc_empty_spaceShortcode = function (obj) { var that = this; var id = $(obj).attr('data-mbuilder-id'); $(obj).find( '.vc_empty_space' ).resizable({ maxWidth : 500, minWidth : 0, handles : 's', create: function (event,ui) { if( !that.getModelattr(id,'height') ){ that.setModelattr(id,'height',$(obj).height()); } if( ! $(obj).find( '.space-resize-val').length ) { $(this).append('
    Spacing: ' + parseInt( $(obj).css('height') ) + 'px
    '); } }, resize : function () { if( ! $(obj).find( '.space-resize-value').length ) { $(this).append('
    Spacing: ' + parseInt( $(obj).css('height') ) + 'px
    '); }else{ $(obj).find('.space-resize-value').text('Spacing: '+ $(obj).height() + 'px'); } } , stop : function () { that.setModelattr( id,'height', $( this ).height() ); } }); $('body').off('duplicate_shortcode.empty_space').on('duplicate_shortcode.empty_space',function(e, obj){ if( ! $( obj ).hasClass( 'mBuilder-vc_empty_space' ) ) { return; } var id = $( obj ).attr( 'data-mbuilder-id' ); $(obj).find('.ui-resizable-handle').remove(); $(obj).find( '.vc_empty_space' ).resizable({ maxWidth : 500, minWidth : 0, handles : 's', create: function (event,ui) { if( !that.getModelattr(id,'height') ){ that.setModelattr(id,'height',$(obj).height()); } }, stop : function () { that.setModelattr( id,'height', $( this ).height() ); } }); }); }; mBuilder.prototype.md_portfolio_multisizeShortcode = function (obj) { 'use strict'; var $portfolioItem = $(obj).find('.isotope .item'), panelSetting = '
    ' + '
    SET IMAGE SIZE
    '+ '
    ' + '
    '+ ' ' + ' ' + ' ' + '
    ' + '
    '; $portfolioItem.append(panelSetting); $portfolioItem.find('.portfolio-size').each(function (index, value) { $(this).attr('data-item_id', $(this).parent().parent().attr('data-item_id')); }); $portfolioItem.hover(function () { var $this =$(this), position = parseInt($this.css('padding-top'))+10; $this.find('.portfolio-panel-setting').css({top: position,right:position, opacity: '1'}); }, function () { var $this =$(this), position = parseInt($this.css('padding-top')); $(this).find('.portfolio-panel-setting').css({top: position,right:position+10, opacity: '0'}); }); $portfolioItem.find('.portfolio-panel-setting').hover(function(){ $(this).addClass('hovering'); TweenMax.fromTo($(this).find('.tooltip'),.3, {top:-60,opacity:0}, {top:-33,opacity:1}); },function(){ $(this).removeClass('hovering'); TweenMax.fromTo($(this).find('.tooltip'),.3, {top:-33,opacity:1}, {top:-70,opacity:0}); }); $portfolioItem.find('.portfolio-panel-setting span').click(function () { if ($(this).hasClass('small-size')) { $(this).parents('.item').removeClass('thumbnail-medium thumbnail-large').addClass('thumbnail-small'); $(this).siblings('.state').removeClass('active-average active-large').addClass('active-small'); $(this).siblings().removeClass('current'); $(this).addClass('current'); pixflow_portfolioMultisize(); } else if ($(this).hasClass('average-size')) { $(this).parents('.item').removeClass('thumbnail-small thumbnail-large').addClass('thumbnail-medium'); $(this).siblings().removeClass('current'); $(this).siblings('.state').removeClass('active-large active-small').addClass('active-average'); $(this).addClass('current'); pixflow_portfolioMultisize(); } else if ($(this).hasClass('large-size')) { $(this).parents('.item').removeClass('thumbnail-medium thumbnail-small').addClass('thumbnail-large'); $(this).siblings().removeClass('current'); $(this).addClass('current'); $(this).siblings('.state').removeClass('active-average active-small').addClass('active-large'); pixflow_portfolioMultisize(); } else if ($(this).hasClass('setting')) { $(this).closest('.vc_md_portfolio_multisize').find('a[title="Edit Portfolio Multi-Size"]')[0].click(); } var item = $(this).parents('.portfolio-item'), post_id = item.data("item_id"), size = $(this).attr('data-size'); jQuery.ajax({ type: "post", url: mBuilderValues.ajax_url, data: "action=pixflow_portfolio_size&nonce=" + mBuilderValues.ajax_nonce + "&portfolio_size=" + size + "&post_id=" + post_id, success: function (res) { return res; } }) }); $portfolioItem.find('.portfolio-panel-setting span').hover(function(){ var $item = $(this); if($item.hasClass('small-size')){ $item.siblings('.state').removeClass('average large').addClass('small'); }else if($item.hasClass('average-size')){ $item.siblings('.state').removeClass('large small').addClass('average'); }else{ $item.siblings('.state').removeClass('average small').addClass('large'); } },function(){ var $item = $(this); if($item.hasClass('small-size')){ $item.siblings('.state').removeClass('average large').addClass('small'); }else if($item.hasClass('average-size')){ $item.siblings('.state').removeClass('large small').addClass('average'); }else{ $item.siblings('.state').removeClass('average small').addClass('large'); } $('.state').removeClass('average small large'); }); $('.portfolio .shortcode-btn a').click(function(e){ e.preventDefault(); return; }) }; mBuilder.prototype.md_tabsShortcode = function (obj) { obj.find('.px_tabs_nav > li').click(function () { var id = $(this).find('> a').attr('href'), num = $(this).position().left; $(id).next().css({left: num}); }); obj.find('ul.ui-tabs-nav').sortable({ cursor: "move", items: "li:not(.unsortable)", delay: 100, axis: "x", zIndex: 10000, tolerance: "intersect", update: function (event, ui) { $('body').addClass('changed'); var prev = ui.item.prev(); var prevId = prev.find('a').attr('href'); var id = ui.item.find('a').attr('href'); if (prevId) { $(id).parent().insertAfter($(prevId).parent()); } else { $(id).parent().insertAfter($(id).parent().parent().find('ul').first()); } } }); }; mBuilder.prototype.md_live_textShortcode = function(obj){ var t = this; $(function(){ t.bind_text_editor(obj.find('.meditor')); }); } mBuilder.prototype.md_modernTabsShortcode = function (obj) { obj.find('.px_tabs_nav > li').click(function () { var id = $(this).find('> a').attr('href'), num = $(this).position().left; $(id).next().css({left: num}); }); setTimeout(function () { obj.find('.px_tabs_nav > li').first().click(); }, 500); obj.find('ul.ui-tabs-nav').sortable({ cursor: "move", items: "li:not(.unsortable)", delay: 100, axis: "x", zIndex: 10000, tolerance: "intersect", update: function (event, ui) { $('body').addClass('changed'); var prev = ui.item.prev(); var prevId = prev.find('a').attr('href'); var id = ui.item.find('a').attr('href'); if (prevId) { $(id).parent().insertAfter($(prevId).parent()); } else { $(id).parent().insertAfter($(id).parent().parent().find('ul').first()); } } }) }; mBuilder.prototype.md_hor_tabsShortcode = function (obj) { obj.find('.px_tabs_nav > li').click(function () { var id = $(this).find('> a').attr('href'), num = $(this).position().top + 15; $(id).next().css({top: num}); }); obj.find('ul.ui-tabs-nav').sortable({ cursor: "move", items: "li:not(.unsortable)", delay: 100, axis: "y", zIndex: 10000, tolerance: "intersect", update: function (event, ui) { $('body').addClass('changed'); var prev = ui.item.prev(); var prevId = prev.find('a').attr('href'); var id = ui.item.find('a').attr('href'); if (prevId) { $(id).parent().insertAfter($(prevId).parent()); } else { $(id).parent().insertAfter($(id).parent().parent().find('ul').first()); } } }) }; mBuilder.prototype.md_hor_tabs2Shortcode = function (obj) { obj.find('.px_tabs_nav > li').click(function () { var id = $(this).find('> a').attr('href'), num = $(this).position().top + 20; $(id).next().css({top: num}); }); obj.find('ul.ui-tabs-nav').sortable({ cursor: "move", items: "li:not(.unsortable)", delay: 100, axis: "y", zIndex: 10000, tolerance: "intersect", update: function (event, ui) { $('body').addClass('changed'); var prev = ui.item.prev(); var prevId = prev.find('a').attr('href'); var id = ui.item.find('a').attr('href'); if (prevId) { $(id).parent().insertAfter($(prevId).parent()); } else { $(id).parent().insertAfter($(id).parent().parent().find('ul').first()); } } }) }; /** * @summary get value attribite from model attributes * * @since 1.0.0 */ mBuilder.prototype.getModelattr = function (modelID, attr) { var t = this, attrs = t.models.models[ modelID ].attr, pattern = attr + '=\\s*("|\')((.|"|\\r|\\n)*?)("|\')|([w-]+)s*=s*([^s\'"]+)(?:s|$)', regex = new RegExp( pattern, 'gm' ); if( attr == 'row_type' ){ console.log( pattern ) } var result = regex.exec( attrs ); if ( result !== null ) { return result[ 2 ]; } else { return false; } }; mBuilder.prototype.removeColumnSeparator = function () { var $coulmnMode = $('.column-hover-mode'); if ($coulmnMode.length) { $coulmnMode.remove(); } }; // Create A list Of Fonts with Their Varients var font_name_list = [], font_name_list_len = '' ; font_var_list = []; mBuilder.prototype.getEditorFonts = function () { var $fontList , count = 0 , google_font_url = mBuilderValues.google_font; $.get( google_font_url , function (data) { $fontList = JSON.parse(data) ; for( count in $fontList.items ){ $fontVarMenu = []; for(var i=0 ; i < $fontList.items[count].variants.length ; i++){ var e = { text:$fontList.items[count].variants[i], classes:'pixflow-editor-font' } $fontVarMenu.push(e); } font_name_list.push($fontList.items[count].family.toString()); font_var_list.push($fontVarMenu); } font_name_list_len = font_name_list.length; return ; }); }; //popupSaveSection mBuilder.prototype.popupSaveSection = function ( rowId ) { var that = this; $( '.popupSaveSection-container' ).css({ 'display': 'flex' }); if ( ! $('.popupSaveSection').length ){ var popupSaveSection = '
    '+ '
    ' + '
    +
    ' + '
    ' + 'Save Your Section'+ 'Sections are reusable. It is a good idea to save your section, so you can use it again later.'+ ''+ ''+ 'CREATE'+ '
    '; $('body').append( popupSaveSection ); } $('.popupSaveSection-button').off('click').on('click',function(){ var value = $('.popupSaveSection-input input').val(); that.saveSection( '#' + rowId, value); }) }; // Convert String to base64 mBuilder.prototype.b64EncodeUnicode = function (str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { return String.fromCharCode('0x' + p1); })); }; /** * @summary set value to model attribute * * @since 1.0.0 */ mBuilder.prototype.setModelattr = function (modelID, attr, value) { var t = this, attrs = t.models.models[modelID].attr; var re = new RegExp(attr + '=(\'|")([.\\s\\S]*?)(\'|")', 'gm'); var str = attrs; var m; if ((m = re.exec(str)) !== null) { var find = new RegExp(attr + '=(\'|")([.\\s\\S]*?)(\'|")', 'gm'); var replace = attr + '="' + value + '" '; attrs = str.replace(find, replace); } else { attrs = attrs + ' ' + attr + '="' + value + '" '; } t.models.models[modelID].attr = attrs; }; mBuilder.prototype.make_links_target_blank = function () { $('body').on('click','a:not(.pixflow-builder-toolbar a)',function(e){ $(this).attr('target','_blank'); }); }; /* * Preview button functionality in pixflow builder toolbar * */ mBuilder.prototype.preview_mode = function () { "use strict"; var $preview_button = $('.builder-preview'); if (!$preview_button.length) return; function preview_off($this,$body){ if($body.length){ //$('.mBuilder_row_controls').css('display','flex'); $( ".mBuilder-vc_column .vc_column-inner > .wpb_wrapper" ).removeClass("disable-sort"); $( ".content-container" ).removeClass("disable-sort"); $('.meditor').attr('contenteditable' , 'true' ); } try { $(".px_tabs_nav").sortable("enable"); $('.mBuilder-element:not(.vc_row,.mBuilder-vc_column)').draggable("enable"); }catch(e){} $body.removeClass('gizmo-off'); $('.pixflow-shortcodes-panel').css({left:''}); $('.space-resize-val , .ui-resizable-handle').css('display' , 'block'); $('.space-resize-val').css('display' , 'flex'); try{ $this.removeClass('hold-collapse'); $('.wpb_content_element .px_tabs_nav.md-custom-tab > li:last-child').css('display','inline-block'); $('.sortable-handle').css('border','1px dashed rgba(92,92,92,.9)'); }catch (e){} } function preview_on($this,$body){ if($body.length){ $( ".mBuilder-vc_column .vc_column-inner > .wpb_wrapper" ).addClass("disable-sort"); $( ".content-container" ).addClass("disable-sort"); $body.addClass('gizmo-off'); $('.meditor').attr({ contentEditable: 'false' }); $('.space-resize-val , .ui-resizable-handle').css('display' , 'none'); $('.pixflow-shortcodes-panel').css({left:'-310px'}); try { $(".px_tabs_nav").sortable("disable"); $('.mBuilder-element:not(.vc_row,.mBuilder-vc_column)').draggable("disable"); }catch(e){} $(this).addClass('hold-collapse'); } try { $this.addClass('hold-collapse'); $body.off('click','.vc_empty-element,.vc_templates-blank, .vc_add-element-action, .vc_control-btn-append, .vc_element-container'); $('.vc_row .vc_vc_column,.sortable-handle').css('border','none'); $('.wpb_content_element .px_tabs_nav.md-custom-tab > li:last-child').css('display','none'); } catch (e) {} } $preview_button.unbind('click'); $preview_button.click(function () { var $this = $(this), $body = $('body.pixflow-builder'); $this.toggleClass('active-preview'); $('.pixflow-add-element-button').removeClass('close-element-button'); if($this.hasClass('hold-collapse')){ preview_off($this,$body); }else { preview_on($this,$body); } }); }; mBuilder.prototype.save_button_animation_start = function(){ $('.builder-controls .builder-save').addClass('saving'); $('.builder-controls .builder-save .save-loading').animate({width: '90%'}, 7000); $('.builder-controls .builder-save .save').html(mBuilderValues.saving); }; mBuilder.prototype.save_button_animation_end = function(){ $('.builder-controls .builder-save .save-loading').stop().animate({'width': '100%'}, 200, 'swing', function () { $('.builder-controls .builder-save .save').html(mBuilderValues.saved); $('.builder-controls .builder-save .save-loading').css('width', '0%'); $('.builder-controls .builder-save').removeClass('active-dropdown-view'); setTimeout(function () { $('.builder-controls .builder-save').removeClass('saving'); $('.builder-controls .builder-save .save').html(mBuilderValues.save); }, 2000); }); }; mBuilder.prototype.mBuilder_message_box = function(title, customClass, text, btn1, callback1, btn2, callback2, closeCallback){ "use strict"; var t = this; $('.message-box-wrapper').remove(); var $messageBox = $('' + '
    ' + '
    ' + '
    ' + '
    ' + title + '
    ' + '
    ' + text + '
    ' + ' ' + '
    ' + '
    ').appendTo('body'), $btn1; $messageBox.animate({opacity:1},200); $btn1 = $messageBox.find('.message-box-btn1'); $btn1.click(function(){ if(typeof callback1 == 'function') { callback1(); } }); if(btn2){ var $btn2 = $('').insertAfter($btn1); $btn2.click(function(){ if(typeof callback2 == 'function'){ callback2(); } }); } if(!btn2){ $btn1.css("width","100%"); } var $close = $messageBox; $close.on('click', function(e) { if (e.target !== this) return; if(typeof closeCallback == 'function'){ closeCallback(); } t.mBuilder_close_message_box(); }); }; mBuilder.prototype.mBuilder_close_message_box = function(){ "use strict"; $('.message-box-wrapper').fadeOut(300,function(){ $(this).remove(); }) }; mBuilder.prototype.on_before_unload = function(){ var t = this; var leave_builder_msg = "You're about to leave Massive Builder", edit_setting_msg = "You're about to edit setting", import_demo_msg = "You're about to import template"; $('.builder-dashboard a, .builder-sitesetting a, .builder-customizer a, .builder-close a').click(function(){ var $that = $(this); if($('body').hasClass('changed')) { if($that.parent().hasClass('builder-sitesetting')){ var leave_msg = edit_setting_msg; }else if($that.parent().hasClass('builder-customizer')){ var leave_msg = import_demo_msg; }else{ var leave_msg = leave_builder_msg; } t.mBuilder_message_box(leave_msg, '', mBuilderValues.saveMessages , mBuilderValues.updateFirst , function () { t.save_callback_function = function () { window.location = $that.attr('href'); } t.saveContent(); }, mBuilderValues.justLeave , function () { window.location = $that.attr('href'); }, function () { return false; }); return false; } }) }; var open_shortcode_time = open_shortcode_time_duration = '' ; mBuilder.prototype.remove_time_out = function (){ clearTimeout(open_shortcode_time_duration); } mBuilder.prototype.shortcode_panel_tabs = function(){ "use strict"; $('.pixflow-shortcodes-panel .panel-tabs .panel-tab').click(function(){ var $this = $(this); if($this.hasClass('active-tab')){ return; } $([$this, $this.siblings()]).toggleClass('active-tab'); $('.sections-tab,.elements-tab').toggleClass('active-tab'); }) }; mBuilder.prototype.open_pixflow_shortcode_panel = function(tab){ "use strict"; if(typeof tab == 'undefined'){ var tab = 'elements'; } if(tab == 'elements'){ $('.pixflow-shortcodes-panel .panel-tabs .panel-tab[data-tab="elements"]').click(); }else{ $('.pixflow-shortcodes-panel .panel-tabs .panel-tab[data-tab="sections"]').click(); } clearTimeout(open_shortcode_time); clearTimeout(open_shortcode_time_duration); var $shortcodes_panel = $(".pixflow-shortcodes-panel"); $shortcodes_panel.removeClass('hide-panel'); $(".pixflow-add-element-button").addClass('clicked'); $shortcodes_panel.addClass("opened"); $shortcodes_panel.find('.pixflow-search-shortcode').focus(); $shortcodes_panel.find('.shortcodes').mousedown(function () { builder.mBuilder_closeShortcodeSetting(); }) }; mBuilder.prototype.close_pixflow_shortcode_panel = function() { var $shortcodes_panel = $(".pixflow-shortcodes-panel"); clearTimeout(open_shortcode_time_duration); if ($shortcodes_panel.hasClass("opened")) { $(".pixflow-add-element-button").removeClass('clicked'); $shortcodes_panel.removeClass("opened"); open_shortcode_time = setTimeout(function () { $shortcodes_panel.addClass('hide-panel') },800); this.clear_shortcodes_panel_input(); } }; mBuilder.prototype.clear_shortcodes_panel_input = function() { $('.pixflow-search-shortcode').val(''); $('.pixflow-shortcodes-container .category-container').addClass('show').find('.shortcodes').addClass('active'); }; /* * Section Builder function * */ mBuilder.prototype.section_builder = function( section_id, placeholder, sectionType ){ var t = builder; this.buildShortcode( placeholder , 'vc_row' , { 'section_id' :section_id , 'customSection' : sectionType } // Callback function to set model attributes , function(id){ if(parseInt(id)){ // Set Row Attributes var $row = $('.mBuilder-element[data-mbuilder-id="'+id+'"]'), row_attrs = $row.find('> .section-shortcode-attrs').text(); t.models.models[id]['attr'] = row_attrs; // Set Shortcodes attribitues in Row $row.find('.mBuilder-element').each(function(){ var $model = $(this), model_id = $model.data('mbuilder-id'), model_attrs = $model.find('> .section-shortcode-attrs').text(); t.models.models[model_id]['attr'] = model_attrs; if ($model.hasClass('mBuilder-vc_empty_space')) { t.vc_empty_spaceShortcode($model); } }) $('.section-shortcode-attrs').remove(); // Init live Text Editors var $live_texts = $row.find('.meditor'); if($live_texts.length){ t.bind_text_editor($live_texts); } } if($('body').hasClass('one_page_scroll')){ pixflow_one_page_for_customizer(); } } ); } /** * Check if new shortcode drop and refresh shortcode params * * @param boolean reset specifies the shortcode params should be refresh or not * * @return boolean * @since 5 */ mBuilder.prototype.refresh_shortcode_params = function( reset ) { if( !this.shortcodes_param.length || reset ){ this.shortcodes_param = _.extend( this.shortcodes_param, JSON.parse( shortcode_maps.shortcodes_param ) ); } return true; }; /** * Get the shortcode params * * @param string model_type the name of shortcode * * @return Object params of shortcode * @since 5 */ mBuilder.prototype.get_shortcode_param = function( model_type ) { this.refresh_shortcode_params(); var params = this.shortcodes_param[model_type].params; return params; }; /** * Check if title slider is on while text number is less that 2 then set title slider off * * @param int model_id it contains the id of shortcode * * @return boolean * @since 5 */ mBuilder.prototype.set_title_slider = function ( model_id ){ var that = this; var title_slider = that.getModelattr( model_id , 'md_text_use_title_slider' ); if( false !== title_slider ){ var text_number = that.getModelattr( model_id , 'md_text_number' ); if( text_number < 2 || false === text_number ){ that.setModelattr( model_id , 'md_text_use_title_slider' , '' ); } } return true; } /** * Create group of each shortcode * * @param Object params of shortcodes * * @return Object form with tabs * @since 5 */ mBuilder.prototype.get_groups_param = function( params ){ var form = {}; params.forEach(function( param ){ if( typeof param.group == 'undefined' ){ param.group = "General" ; } if(typeof form[param.group] == 'undefined'){ form[param.group] = [] ; } form[param.group].push( param ); }); return form ; } /** * Generate the css attribute for coulmn shortcode * * @param string model_type the name of shortcode * * @return array final css that contains css property Individually and css contains the css string * @since 5 */ mBuilder.prototype.generate_css_attr = function( model_type , model_id ){ var final_css = [] ; var that = this ; if( "vc_column" == model_type ){ var css = that.getModelattr( model_id , 'css' ); if ( false != css ){ var matches = css.match(/.*?{(.*?)}.*?/); if( "object" == typeof matches && null != matches[1] ){ css = matches[1]; css = css.replace( /``/g , '\'' ); css = css.replace( /[!]important/g, '' ).trim(); css = css.replace( /px/g , '' ).trim(); css = css.replace(/url[(](.*?)[)]/g,'$1').trim(); css = css.split(';'); css.forEach(function( css_prop ){ if( css_prop != '' ){ var css_property = css_prop.split(/:(?!\/\/)/g); var object_name = css_property[0].replace( /-/g , '_' ).trim(); final_css[object_name] = css_property[1].trim() ; } }); }else{ css = '' ; } } } return [ final_css , css ] ; } /** * Set the general tab in the first tab * * @param Objcet form contains the form tabs * @param int model_id it contains the id of shortcode * * @return boolean * @since 5 */ mBuilder.prototype.reorder_groups = function( form ){ if( typeof form["General"] != "undefined" && form["General"].length ){ var general_tab = form["General"] ; delete form['General']; form = jQuery.extend( { 'General' : general_tab } , form ); } return form; } /** * Set the custom classes for each controller * * @param Object params of shortcodes * @param Object group_html contains the html source of each tab * @param String group show the tab name * * @return Object group_html with the custom classes * @since 5 */ mBuilder.prototype.set_custom_classes = function(param , group_html , group ){ var dependency = ''; if( typeof param.dependency != "undefined" ){ dependency = "data-mBuilder-dependency='" + JSON.stringify( param.dependency ) + "'"; } if( typeof param.mb_dependency != "undefined" ){ dependency = "data-mBuilder-dependency='" + JSON.stringify( param.mb_dependency ) + "'"; } if( typeof group_html[group] == "undefined" ){ group_html[group] = '' ; } var edit_classes = ( typeof param.edit_field_class != "undefined" ) ? param.edit_field_class : '' ; edit_classes += ' setting-background mbuilder-controller '; if(typeof param.color_picker != 'undefined'){ edit_classes += ' has-colorpicker '; } group_html[group] += '
    '; return group_html; } /** * Create the params of shortcodes * * @param Object params of shortcodes * @param array final css that contains css property Individually and css contains the css string * @param int model_id it contains the id of shortcode * * @return Object shortcode params of shortcodes * @since 5 */ mBuilder.prototype.create_dependecy = function( param, final_css, model_id) { var shortcodes_param = {} ; var default_value = '' ; var that = this ; if( 'content' == param.param_name ){ if( "undefined" == typeof shortcodes_param [param.param_name ] ){ shortcodes_param [param.param_name ] = ''; } shortcodes_param [ param.param_name ] = that.models.models[ model_id ].content; } else if( false !== that.getModelattr( model_id , 'css' ) && param.param_name in final_css && typeof shortcodes_param[param.param_name] == "undefined" ){ shortcodes_param[ param.param_name ] = final_css[ param.param_name ].replace('!important' , ''); } else { if( "undefined" == typeof shortcodes_param [param.param_name ] ){ shortcodes_param [param.param_name ] = ''; } shortcodes_param [ param.param_name ] = that.getModelattr( model_id, param.param_name ) ; } if( typeof param.value != "string" && typeof param.value != "undefined"){ default_value = Object.keys(param.value)[0]; }else{ default_value = ( typeof param.value != "undefined" ) ? param.value : '' ; } shortcodes_param [ param.param_name ] = ( shortcodes_param [param.param_name ] !== false ) ? shortcodes_param [param.param_name ].replace( /"/g , '"' ) : default_value ; return shortcodes_param; } /** * Create the html source of each external type * * @param Object params of shortcodes * @param array final css that contains css property Individually and css contains the css string * @param Object shortcode params of shortcodes * * @return array the new form html source and js sources that need to be load * @since 5 */ mBuilder.prototype.load_external_type = function(param , group_data , shortcodes_param){ var group_html = group_data[0] , group = group_data[1] , group_js = group_data[2]; var param_class_name = param['type'].replace( /_/g , '-' ).toLowerCase() ; group_html[group] +='
    ' ; group_html[group] += builder[ shortcode_maps.mBuilder_external_types[param['type']]['callback'] ]( shortcode_maps.mBuilder_external_types[param['type']]['callback'] , param , shortcodes_param [ param.param_name ] ); group_html[group] +='
    '; group_js.push ( shortcode_maps.mBuilder_external_types[param['type']]['requiredjs'] ); return [group_html , group_js]; } /** * Create the html source of text feild controller * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return object the html source of form panel * @since 5 */ mBuilder.prototype.create_textfield_source = function ( group_data , param , shortcodes_param ) { var group_html = group_data[0] , group = group_data[1]; group_html[group] += '' + param.heading + '' + '
    '; return group_html; } /** * Create the html source of hidden feild controller * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return object the html source of form panel * @since 5 */ mBuilder.prototype.create_hidden_source = function ( group_data , param , shortcodes_param ) { var group_html = group_data[0] , group = group_data[1]; group_html[group] += ''; return group_html ; } /** * Create the html source of textarea html feild controller * * @param int model_id it contains the id of shortcode * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * * @return object the html source of form panel * @since 5 */ mBuilder.prototype.create_textarea_html_source = function ( group_data, param, model_id ) { var group_html = group_data[0] , group = group_data[1] , that = this ; group_html[group] += '
    '; return group_html; } /** * Create the html source of textarea feild controller * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return object the html source of form panel * @since 5 */ mBuilder.prototype.create_textarea_source = function( group_data , param , shortcodes_param ){ var group_html = group_data[0] , group = group_data[1]; group_html[group] += '' + '
    '; return group_html; } /** * Create the html source of dropdown source feild controller * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return object the html source of form panel * @since 5 */ mBuilder.prototype.create_dropdown_source = function( group_data , param , shortcodes_param ){ var group_html = group_data[0] , group = group_data[1]; var default_value = ( typeof param.value != "undefined" ) ? Object.keys(param.value)[0] : '' ; var options = '', selected_value = new Array(default_value , param.value[default_value] ); $.each( param.value , function( option_key , option_value ){ var option_class =' dropdown-option active-text-color '; if ( option_value == shortcodes_param [ param.param_name ] ) { option_class += ' selected-option '; selected_value[0] = option_key; selected_value[1]= option_value; } options += '
    ' + option_key + '
    '; }); group_html[group] += '
    ' + '
    '+ ''+ ''+ ' '+ '
    ' + '
    '; return group_html; } /** * Create the html source of single image attach feild controller * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return array the new html source of form panel and attachment id * @since 5 */ mBuilder.prototype.create_attach_image_source = function( group_data , param , shortcodes_param ){ var group_html = group_data[0] , group = group_data[1] , attachment_id = group_data[2]; var image_id = parseInt( shortcodes_param [ param.param_name ] ) , placeholder = '' ; if( '' != image_id && typeof image_id == "number" && 0 != image_id && ! isNaN(image_id) ){ attachment_id.push( image_id ); placeholder += '
    '; group_html[group] += '
    ' + param.heading + '
    ' + '
    ' + placeholder + '
    ' + '
    '; }else{ placeholder = '
    '; group_html[group] += '
    ' + param.heading + '
    ' + '
    ' + placeholder + '
    ' + '
    '; } return [ group_html , attachment_id ] ; } /** * Create the html source of multi image attach feild controller * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return array the new html source of form panel and attachment id * @since 5 */ mBuilder.prototype.create_attach_images_source = function( group_data , param , shortcodes_param ){ var group_html = group_data[0] , group = group_data[1] , attachment_id = group_data[2]; var images_id = ( "undefined" != typeof shortcodes_param [ param.param_name ] && "" != shortcodes_param [ param.param_name ] ) ? shortcodes_param [ param.param_name ].split(',') : [] , placeholder = ''; if( images_id.length ){ for( var count in images_id ){ if( 'length' !== images_id[ count ]){ attachment_id.push( images_id[ count ] ); placeholder += '
    '; } } placeholder += '
    '; }else{ placeholder = '
    '; } group_html[group] += '
    ' + param.heading + '
    ' + '
    ' + placeholder + '
    ' ; return [ group_html , attachment_id ]; } /** * Create the html source of google font feild controller * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return Object the new html source of form panel * @since 5 */ mBuilder.prototype.create_google_fonts_source = function ( group_data , param , shortcodes_param ) { var group_html = group_data[0] , group = group_data[1] , that = this ; var input_value = shortcodes_param [ param.param_name ]; var value = decodeURIComponent( input_value ) ; value = value.replace( "font_family:" , '' ); value = value.replace( "font_style:" , '' ); var font_family = value.split(':'); font_family = font_family[0]; var font_style = value.split('|'); font_style = font_style[1]; value = { font_family: font_family , font_style: font_style }; var fonts = shortcode_maps.google_gonts , font_key = 0 , options = '' , option_classes = ' dropdown-option active-text-color ' selected_value = []; $.each( fonts , function( fkey , font_data ){ var select = '' ; if( value.font_family.toLowerCase() == font_data.font_family.toLowerCase() ){ font_key = fkey ; option_classes += 'selected-option'; selected_value[0] = font_data.font_family + ':' + font_data.font_styles; selected_value[1] = font_data.font_family; }else{ option_classes = ' dropdown-option active-text-color ' } options += '
    ' + font_data.font_family + '
    '; }); font_style_options = that.load_font_styles( font_key , value['font_style'] ); group_html[ group ] += '
    '+ '
    ' + ''+ ''+ ' '+ '
    ' + '
    ' + ''+ ''+ ' '+ '
    ' + '' + '
    '; return group_html; } /** * Check if the cuurent shortcode setting panel open preventy from re open it again * * @param int id it contains the id of shortcode * * @return Object the new html source of form panel * @since 5 */ mBuilder.prototype.is_shortcode_panel_open = function( id ) { if (id == this.selected_shortcode_id) { return true; } this.selected_shortcode_id = id; return false; } /** * Build setting panel form and inputs to edit shortcodes visually * * @param model_id int shorcode model id * * @return void * @since 5 */ mBuilder.prototype.form_builder = function( model_id ){ var that = this ; that.set_title_slider( model_id ); // Get groups of params var model_type = that.models.models[ model_id ]['type']; var params = that.get_shortcode_param( model_type ); var form = that.get_groups_param( params ) ; // Generate VC column shortcode css attributes var css_attrs = that.generate_css_attr(model_type , model_id ); var final_css = css_attrs[0] ; // var css = css_attrs[1] ; form = that.reorder_groups(form); var group_html = {}; var group_js = [] ; var form_html = '
      '; var attachment_id = [] ; $.each(form, function(group, params) { form_html += '
    • ' + group + '
    • ' ; $.each( params , function( key , param ){ // Continue if param is inline color picker if( ( param.type == 'md_vc_colorpicker' && param.inline_color_picker == true ) || param.type == 'md_vc_separator' ){ return true; } group_html = that.set_custom_classes(param , group_html , group); var shortcodes_param = that.create_dependecy( param , final_css , model_id); if( typeof shortcode_maps.mBuilder_external_types[param.type] != "undefined" && typeof builder[ shortcode_maps.mBuilder_external_types[param['type']]['callback'] ] == "function" ){ var load_external_result = that.load_external_type( param , [ group_html , group , group_js ] , shortcodes_param ); group_js = load_external_result[1]; group_html = load_external_result[0]; }else{ var param_result = that.create_param_source( param, [ group_html , group , attachment_id , model_id ], shortcodes_param ); attachment_id = param_result[1]; group_html = param_result[0]; // Add inline color picker filed group_html = that.add_inline_color_picker( [params , param , model_id], group_html, group); } group_html[ group ] += '
    '; }); }); form_html = that.create_form_source( form_html , group_html , group_js ); that.get_attachment_url( attachment_id ); return form_html; }; /** * Call the function of params and create the html source * * @param array group_data contains the html group of shortcode and the name of shortcodes tab * @param Object params of shortcodes * @param Object shortcode params of shortcodes * * @return array the new html source of form panel and attachment id * @since 5 */ mBuilder.prototype.create_param_source = function ( param, group_data , shortcodes_param) { var group_html = group_data[0] , group = group_data[1] , attachment_id = group_data[2] , model_id = group_data[3] , that = this; switch( param.type ){ case 'textfield': group_html = that.create_textfield_source( [ group_html , group ] , param , shortcodes_param ); break; case 'hidden': group_html = that.create_hidden_source( [ group_html , group ] , param , shortcodes_param ); break; case 'textarea_html': group_html = that.create_textarea_html_source( [ group_html , group ], param , model_id ); break; case 'textarea': group_html = that.create_textarea_source( [ group_html , group ] , param , shortcodes_param ); break; case 'dropdown': group_html = that.create_dropdown_source( [ group_html , group ] , param , shortcodes_param ); break; case 'attach_image': var result = that.create_attach_image_source( [ group_html , group , attachment_id ] , param , shortcodes_param ); group_html = result[0]; attachment_id = result[1]; break; case 'attach_images': var result = that.create_attach_images_source( [ group_html , group , attachment_id ] , param , shortcodes_param ); group_html = result[0]; attachment_id = result[1]; break; case 'google_fonts': group_html = that.create_google_fonts_source( [ group_html , group ] , param , shortcodes_param ); default: break; } var output = [ group_html , attachment_id ]; return output; } /** * Create the html source of single image attach feild controller * * @param Object the form html source * @param Object the form html source * @param array group_js the list of java script url that should be to load * * @return string the html source of form * @since 5 */ mBuilder.prototype.create_form_source = function( form_html , group_html , group_js){ form_html += "" ; group_js = _.uniq( group_js ); $.each( group_html , function( key , html){ form_html += '
    ' + html + "
    " ; }); form_html += '' + '' + '' + ''; for ( var js in group_js ){ if( group_js[js] != "length"){ form_html += ''; } } form_html += '
    '; return form_html; } mBuilder.prototype.add_inline_color_picker = function( params_data , group_html, group ){ var params = params_data[0] , param = params_data[1], model_id = params_data[2], that = this; if(typeof param.color_picker != 'undefined'){ var color_picker_param = params.filter(function( obj ) { return obj.param_name == param.color_picker; }); color_picker_param = color_picker_param[0]; if( typeof color_picker_param != 'undefined' ){ color_picker_param.opacity = ( typeof color_picker_param.opacity == 'undefined' ) ? false : color_picker_param.opacity; group_html[group] += ''; } } return group_html; } mBuilder.prototype.pixflow_vc_base64_text_field = function ( temp_name , settings, value ){ var that = this; if(value.indexOf('pixflow_base64') !== -1){ value = value.replace('pixflow_base64',''); value = that.base64_decode(value); } var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { param_name : settings['param_name'] , base64_value : that.base64_encode( value ) } ) ; return output; }; mBuilder.prototype.pixflow_vc_iconpicker_field = function( temp_name , settings, value ){ var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { param_name : settings['param_name'] , value : value , type: settings['type'] } ) ; return output; } mBuilder.prototype.pixflow_vc_description_field = function (temp_name , settings, value ){ var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { param_name : settings['param_name'] , value : settings['value'] , } ) ; output = output.replace(/</g, "<").replace(/>/g, ">"); return output; } mBuilder.prototype.pixflow_group_title_field = function (temp_name , settings, value ){ var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { param_name : settings['param_name'] , title : settings['heading'] } ) ; //output = output.replace(/</g, "<").replace(/>/g, ">"); return output; } mBuilder.prototype.pixflow_vc_datepicker_field = function( temp_name , settings, value ){ var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { param_name : settings['param_name'] , value : value , type: settings['type'] } ) ; return output; } mBuilder.prototype.pixflow_vc_base64_textarea_field = function ( temp_name , settings, value ) { var that = this ; if(value.indexOf('pixflow_base64') !== -1){ value = value.replace('pixflow_base64',''); value = that.base64_decode( value ); } var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { param_name : settings['param_name'] , value : value , base64_value: that.base64_encode( value ) } ) ; return output; } mBuilder.prototype.pixflow_vc_multiselect_field = function ( temp_name , settings, value ) { var that = this , items = ( typeof settings['items'] != "undefined" && typeof settings['items'] == "object" ) ? settings['items'] : [] , defaults = ( typeof settings['defaults'] != "undefined" && settings['defaults'] == 'all') ? items : [] , id = that.uniqid() , length = items.length , template = wp.template( 'mbuilder-field-type-' + temp_name ); value = ( value != '') ? value : defaults.join(','); var values = value.trim().split(',') ; values = values.map( Function.prototype.call, String.prototype.trim ); var output = template( { id: id , value : value , param_name : settings['param_name'] , type : settings['type'] , values: values , length: length , items: items } ) ; return output; } mBuilder.prototype.pixflow_vc_url_field = function ( temp_name , settings, value ) { var that = this ; var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { id: that.uniqid() , value : value , param_name : settings['param_name'] , base64_value: that.base64_encode( value ) } ) ; return output; } mBuilder.prototype.pixflow_vc_colorpicker_field = function ( temp_name , settings, value ) { var that = this ; var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { id: that.uniqid() , param_name : settings['param_name'] , value : value , opacity: ( typeof settings['opacity'] != "undefined" && settings['opacity'] === true ) ? true : false } ) ; return output; } mBuilder.prototype.pixflow_vc_checkbox_field = function ( temp_name , settings, value ) { var that = this, template = wp.template( 'mbuilder-field-type-' + temp_name ), checked = (value.toLocaleLowerCase() == 'yes')?'checked="checked"':'', output = template( { id: that.uniqid() , param_name : settings['param_name'] , value : value.toLocaleLowerCase() , type: settings['type'], checked: checked } ) ; return output; } mBuilder.prototype.pixflow_vc_slider_field = function ( temp_name , settings , value ) { var that = this ; var defaults_setting = {}; var defaults = { 'min': '0', 'max': '100', 'prefix': '%', 'step': '1', 'decimal': '0' }; defaults_setting = ( typeof settings['defaultSetting'] != "undefined" && settings['defaultSetting'] != '' ) ? settings['defaultSetting'] : defaults ; if( typeof value != "undefined" ){ if( parseInt( defaults_setting['step'] ) < 1 ){ value = ( parseFloat(value) === '' ) ? defaults_setting['min'] : parseFloat(value) ; value = that.number_format( value , 1 ); }else{ value = ( parseInt( value ) === '' ) ? defaults_setting['min'] : parseInt( value ) ; } }else{ value = 0 ; } if ( isNaN( value ) == true ){ value = 0; } var template = wp.template( 'mbuilder-field-type-' + temp_name ), output = template( { id: that.uniqid() , param_name : settings['param_name'] , value : value , type: settings['type'], min: defaults_setting['min'] , max: defaults_setting['max'] , step: defaults_setting['step'] , prefix: defaults_setting['prefix'] } ) ; return output; } mBuilder.prototype.pixflow_vc_gradientcolorpicker_field = function ( temp_name , settings , value ) { var that = this ; if(value.indexOf('pixflow_base64') !== -1){ value = value.replace('pixflow_base64',''); value = that.base64_decode(value); } value = value.replace('``', '"'); value = value.replace('\'', '"'); var defaults = { 'color1': '#fff' ,'color2': '#000' ,'color1Pos': '0' ,'color2Pos': '100' ,'angle': '0' }; var default_color = ( typeof settings['defaultColor'] != "undefined" && settings['defaultColor'] != '' ) ? settings['defaultColor'] : defaults; if(typeof value != 'undefined' && value != ''){ try { value = JSON.parse( value ); } catch (e) { value = default_color; } }else{ value = default_color; } var template = wp.template( 'mbuilder-field-type-' + temp_name ); var output = template( { id: that.uniqid() , param_name : settings['param_name'] , json_value : JSON.stringify(value) , type: settings['type'] , color1_pos: value.color1Pos , color2_pos: value.color2Pos , color1: value.color1 , color2: value.color2 , angle: value.angle } ) ; return output; } /** * @summary formats a number with grouped thousands. * * @param {int} Required. The number to be formatted. * @param {int} Optional. Specifies how many decimals. If this parameter is set, the number will be formatted with a dot (.) as decimal point. * @param {string} Optional. Specifies what string to use for decimal point * @param {string} Optional. Specifies what string to use for thousands separator. Only the first character of separator is used. * *@return {int} The formatted number * * @since 4.5 */ mBuilder.prototype.number_format = function( number, decimals, dec_point, thousands_sep) { var number = number*1; var str = number.toFixed( decimals ? decimals : 0 ).toString().split('.'); var parts = []; for ( var i=str[0].length; i>0; i-=3 ) { parts.unshift( str[0].substring(Math.max(0,i-3),i) ); } str[0] = parts.join( thousands_sep?thousands_sep : ',' ); return str.join( dec_point ? dec_point : '.' ); } mBuilder.prototype.base64_decode = function (str) { return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); }; mBuilder.prototype.base64_encode = function (str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { return String.fromCharCode('0x' + p1); })); }; mBuilder.prototype.uniqid = function() { this.length = 8; this.timestamp = +new Date; var _getRandom_int = function( min, max ) { return Math.floor( Math.random() * ( max - min + 1 ) ) + min; } this.generate = function() { var ts = this.timestamp.toString(); var parts = ts.split( "" ).reverse(); var id = ""; for( var i = 0; i < this.length; ++i ) { var index = _getRandom_int( 0, parts.length - 1 ); id += parts[index]; } return id; } return this.generate(); } mBuilder.prototype.get_attachment_url = function ( images_id ){ var that = this ; var request_count = 0 ; wp.media.attachment( images_id[ request_count ] ).fetch().then(function () { if(typeof wp.media.attachment( images_id[ request_count ] ).attributes.sizes != 'undefined' && typeof wp.media.attachment( images_id[ request_count ] ).attributes.sizes.thumbnail != 'undefined'){ var img_url = wp.media.attachment( images_id[ request_count ] ).attributes.sizes.thumbnail.url; } else { var img_url = wp.media.attachment( images_id[ request_count ] ).get('url'); } $('.change-bg-' + images_id[ request_count ]).css({ backgroundImage : 'url(' + img_url +')' }); request_count++; if ( typeof images_id[request_count] != "undefined" ) { that.get_attachment_url( images_id.slice( 1 , images_id.length ) ); } }); } mBuilder.prototype.load_font_styles = function( key , value ){ var fonts = shortcode_maps.google_gonts ; var font_key = key; var value = value; var font_styles = fonts[font_key]; font_styles = font_styles.font_types.split(','); var options = '' , option_classes = ' dropdown-option active-text-color ', selected_value = []; for( var count in font_styles ){ if ( value.toLowerCase() == font_styles[ count ].toLowerCase() ){ option_classes += 'selected-option' selected_value[0] = font_styles[ count ]; var temp = font_styles[ count ].split(':'); selected_value[1] = temp[0]; }else{ option_classes = ' dropdown-option active-text-color '; } options += '
    '; var title = font_styles[ count ].split(':'); options += title[0] + '
    '; } return [options,selected_value]; } // builder instance var builder = null; var $ = jQuery; $(function () { builder = new mBuilder(); $('[data-mbuilder-el] , .vc_row').each(function () { var type = ( $(this).hasClass('vc_row') ) ? 'vc_row' : $(this).attr('data-mbuilder-el'); if (typeof builder[type + "Shortcode"] == 'function') { builder[type + 'Shortcode']($(this)); } }); }); $(document).on('mouseenter', '.vc_row', function () { var mainPadding = parseInt($('main').css('padding-top')), top = mainPadding, num = 0, firstRow = $('main .vc_row').first(), $firstRowControls = firstRow.find('> .wrap + .mBuilder_row_controls'), $headerTop = $('header[class *= "top"]'), headerHeight = $headerTop.height()+3; firstRow.addClass('first-row'); if (!$(this).closest('.first-row').length //|| firstRow.hasClass('vertical-aligned') ){ return; } if($('header').is('.left') || $('header').is('.right')){ $firstRowControls.css('top', '0'); }else { if (!$(this).hasClass('vc_inner')) { if (mainPadding >= headerHeight + 45) { //content is not under header now check if row has space to view its settings or not if (!$firstRowControls.hasClass('flag')) { var number = ($(this).hasClass('sloped_row') || $(this).hasClass('row_video')) ? '2px':'-45px'; $firstRowControls.css('top', parseInt( number ) - 4 + 'px' ); $firstRowControls.addClass('flag'); } } else { //row has enough space to view its setting // check if it is under header or not var headerTop = parseInt($headerTop.css('top')); headerHeight += headerTop; num = (headerHeight + 45 <= mainPadding ) ? - 45 : headerHeight - mainPadding; if(num < 0) num = 2; if (!$firstRowControls.hasClass('flag')) { $firstRowControls.css({'top': parseInt( num ) - 4 + 'px' }); $firstRowControls.addClass('flag') } } } else { var $innerRow = $(this), $innerRowControls = $innerRow.find('.mBuilder_row_controls'), rowTop = $innerRowControls.closest('.first-row').find('> .mBuilder_row_controls').position().top; if ($innerRowControls.offset().top <= rowTop){ $innerRowControls.css({'top': parseInt( rowTop ) - 4 + 'px' }); } } } }); mBuilder.prototype.top_page_space = function(){ var $header_top = $( 'header[class *= "top"]' ), header_height = $header_top.height()+3, header_top_space = parseInt( $header_top.css( 'top' ) ); return header_height + header_top_space; }; $(document).on('mouseleave', '.vc_row ', function () { var firstRow = $('main .vc_row').first(), firstRowControls = firstRow.find('> .wrap + .mBuilder_row_controls'); if($(this).hasClass('vc_inner')){ if (! $(this).closest('.first-row').length){ return; } }else if (! $(this).hasClass('first-row')){ return; } firstRow.removeClass('first-row'); if (firstRowControls.hasClass('flag')) { firstRowControls.removeClass('flag') } }); $(document).on('click','.pixflow-add-element-button',function(e){ e.stopPropagation(); builder.open_pixflow_shortcode_panel(); if ( $('.setting-panel-wrapper').length > 0 ){ builder.mBuilder_closeShortcodeSetting(); } }); window.onbeforeunload = function (e) { e = e || window.event; if($('body').hasClass('changed')){ if (e) { e.returnValue = 'Sure?'; } // For Safari return 'Sure?'; } }; mBuilder.prototype.vc_column_resize = function (obj) { var that = this; obj.find('.mBuilder-vc_column,.mBuilder-vc_column_inner').each(function(){ that.column_left_space($(this),that); that.column_right_space($(this),that); }); } mBuilder.prototype.get_model_id = function ($obj) { return $obj.attr('data-mbuilder-id'); } mBuilder.prototype.column_left_space = function ($obj,that) { var $left_space_element = $obj.find('> .column-left-space'), $column = $obj.find('> .vc_column_container > .vc_column-inner'); $left_space_element.width(parseInt($column.css('padding-left'))); if (! $left_space_element.find('.column-resize-val').length ){ $left_space_element.append('
    Spacing: '+$column.css('padding-left')+'
    '); } this.set_column_resize($left_space_element,that,this.get_model_id($obj)); } mBuilder.prototype.column_right_space = function ($obj,that) { var $right_space_element = $obj.find('> .column-right-space'), $column = $obj.find('> .vc_column_container > .vc_column-inner'); $right_space_element.width(parseInt($column.css('padding-right'))); if (! $right_space_element.find('.column-resize-val').length ){ $right_space_element.append('
    Spacing: '+$column.css('padding-right')+'
    '); } this.set_column_resize($right_space_element,that,this.get_model_id($obj)); } mBuilder.prototype.set_column_resize = function ($space_element,that,id){ var $column = $space_element.parent().find('> .vc_column_container > .vc_column-inner'); //check if it is left space or right var padding = ($space_element.hasClass('column-left-space'))?'padding-left':'padding-right'; $space_element.resizable({ maxWidth : 500, minWidth : 0, handles: (padding== 'padding-left')?'e':'w' , create: function(){ var colum_space_width = $(this).width(); if( colum_space_width <= 15 ){ $(this).addClass('defult_space_width'); }else{ $(this).removeClass('defult_space_width'); } } , start: function () { $(this).addClass('start-resizing'); $(this).removeClass('defult_space_width'); }, resize : function (event, ui) { $(this).css('left',''); $column.css(padding,''); var column_style = $column.attr('style') + ';' + padding + ':'+$(this).width()+'px !important;'; $column.attr('style',column_style); if($(this).find('> .column-resize-val').length){ $(this).find('> .column-resize-val .column-resize-value').text('Spacing: '+ $(this).width()+'px'); if ($(window).width() <= 1366){ if (!$(this).find('> .column-resize-val em').length){ $(this).find('> .column-resize-val .column-resize-value').after('Space controller has no effect in this screen size'); } } }else{ $(this).append('
    Spacing: '+ $(this).width() +'
    '); if ($(window).width() <= 1366){ if (!$(this).find('> .column-resize-val em').length){ $(this).find('> .column-resize-val .column-resize-value').after('Space controller has no effect in this screen size'); } } } }, stop : function (event,ui) { var colum_space_width = $(this).width(); var model_css = that.getModelattr(id,'css'); $(this).find('> .column-resize-val em').remove(); if (model_css){ var re = new RegExp(padding+':(.*?);', 'gm'); if ((re.exec(model_css)) !== null) { var find = new RegExp(padding+":(.*?);", 'gm'); var replace = padding+':' + $(this).width() + 'px!important;'; model_css = model_css.replace(find, replace); } else { model_css = model_css.replace("}",''); model_css = model_css + padding + ':' + $(this).width() + 'px!important;}'; } }else{ var css_style = $column.attr('class'); css_style = css_style.replace(/ /g,'.'); model_css = '.'+css_style+'{'+padding+':' + $(this).width() + 'px!important;}' } that.setModelattr(id,'css',model_css); that.setModelattr(id,padding.replace('-' , '_'),$(this).width()) if( colum_space_width <= 15 ){ $(this).addClass('defult_space_width'); }else{ $(this).removeClass('defult_space_width'); } $(this).removeClass('start-resizing'); var $isotopes = $column.find('.isotope'); if($isotopes.length){ $isotopes.isotope('layout') } } }); } mBuilder.prototype.vc_row_resize = function () { var that = this; $('.vc_row').each(function () { var $element_object = $(this), id = $element_object.attr('data-mbuilder-id'); that.vc_column_resize($(this)); if (!$(this).hasClass('fit-to-height')) { that.row_shortcode_top_resize($element_object, id); that.row_shortcode_bottom_resize($element_object, id); } }); } mBuilder.prototype.row_shortcode_top_resize = function($element_object , id ){ var row_padding = parseInt( $element_object.css('padding-top') ) , resize_area = $element_object.find('> .row-top-space'); resize_area.css('height' , + row_padding + 'px' ); if(resize_area.css('height' )== 0){ } var resize_info = { resize_area : resize_area , dir : 'top' } this.make_element_resizable( id , resize_info, $element_object ); } mBuilder.prototype.row_shortcode_bottom_resize = function( $element_object , id ){ var row_padding = parseInt( $element_object.css('padding-bottom') ) , resize_area = $element_object.find('> .row-bottom-space'), resize_s = $element_object.find('> .row-bottom-space .ui-resizable-s'); resize_s.css('height' , row_padding ) resize_area.css('height' , + row_padding + 'px' ); var resize_info = { resize_area : resize_area , dir : 'bottom' } this.make_element_resizable( id , resize_info , $element_object ); } mBuilder.prototype.make_element_resizable = function( id , resize_info , $element_object ){ var that = this; resize_info.resize_area.resizable({ maxHeight: 800, minHeight: 0, handles: 's' , create: function(){ var space_height = $(this).height(); if( ! $(this).find('.row-resize-val').length ) { $(this).append('
    Spacing: ' + parseInt( space_height ) + 'px
    '); } if( space_height <= 15 ){ $(this).addClass('defult-space-height'); }else{ $(this).removeClass('defult-space-height'); } }, start: function () { $(this).addClass('start-resizing'); $(this).removeClass('defult-space-height'); // $('.ui-resizable-s').css('height' , $(this).height()); }, resize : function () { var space_height = $(this).height(); $(this).css('top' , ''); $element_object.css( 'padding-' + resize_info.dir , space_height +'px'); // $('.ui-resizable-s').css('height' , $(this).height()); if($(this).find('> .row-resize-val').length){ $(this).find('> .row-resize-val .row-resize-value').text('spacing: '+ $(this).height() +'px'); }else{ $(this).append('
    Spacing: '+ space_height +'px
    '); } } , stop: function(){ var space_height = $(this).height(); if($element_object.hasClass('vc_inner')){ id = $element_object.closest('.mBuilder-vc_row_inner').attr('data-mbuilder-id'); that.setModelattr( id , 'inner_row_padding_'+ resize_info.dir , $(this).height() ); }else{ that.setModelattr( id , 'row_padding_'+ resize_info.dir , $(this).height() ); } if( space_height <= 15 ){ $(this).addClass('defult-space-height'); }else{ $(this).removeClass('defult-space-height'); } $(this).removeClass('start-resizing'); } }); }