(function ($) { window.mpl = $.extend({ backbone: { views: function (ismodel) { this.ismodel = ismodel; this.el = null; this.events = null; this.render = function (params, p1, p2, p3, p4, p5) { var rended = this._render(params, p1, p2, p3, p4, p5); if (this.el === null) this.el = rended; if (typeof this.events == 'object') { mpl.trigger(this); } if (this.ismodel != 'no-model') { if (mpl.front) { params = $().extend($().extend({ args: {}, model: id }, params)); if (params.name !== 'mpl_row' && params.name !== 'mpl_column') { mpl.front.id = null; mpl.front.id = mpl.front.model++; mpl.section_name = params.name; mpl.storage[mpl.front.id] = []; mpl.storage[mpl.front.id].push(params); params.section_num = mpl.front.id; } else { mpl.storage[mpl.front.id].push(params); } } else { var id = mpl.model++; rended.attr({ id: 'model-' + id }).addClass('mpl-model').data({ 'model': id }); params = $().extend($().extend({ args: {}, model: id }, params)); mpl.storage[id] = params; } } return rended; }; this.extend = function (obj) { for (var i in obj) { if (i == 'render') { this._render = obj.render; } else { this[i] = obj[i]; } } return this; }; }, save: function (pop) { var mid = pop.data('model'); if (mid !== undefined) { if (mpl.front) { mpl.front.save_value = true; if (mpl.storage[mid][0]) { var datas = mpl.tools.getFormData(pop, true), prev = {}, hidden = [], exp = new RegExp(mpl_site_url, "g"); map_values = mpl.params.get_values(mpl.storage[mid][0].name); pop.find('form.fields-edit-form .mpl-param-row').each(function () { if ($(this).hasClass('relation-hidden')) { $(this).find('.mpl-param').each(function () { hidden.push(this.name); }); } }); for (var name in datas) { if (typeof (name) == 'undefined' || name === '') continue; if (hidden.indexOf(name) > -1) datas[name] = ''; if (datas[name] !== '') { if (typeof datas[name] == 'object') { if (typeof (datas[name][0]) == 'string' && datas[name][0] == '') delete datas[name][0]; datas[name] = mpl.tools.base64.encode(JSON.stringify(datas[name]).toString().replace(exp, '%SITE_URL%')); } prev[name] = datas[name]; } else if (hidden.indexOf(name) == -1) { if (map_values[name] !== undefined && map_values[name] !== '' && typeof (prev[name]) == 'undefined') prev[name] = '__empty__'; } if (datas[name] === '' && typeof (prev[name]) == 'undefined') { if (typeof (mpl.storage[mid][0].args[name]) == 'undefined') continue; else delete mpl.storage[mid][0].args[name]; } else { mpl.storage[mid][0].args[name] = prev[name]; if (name == 'content' && mpl.maps[mpl.storage[mid][0].name].is_container === true) { mpl.storage[mid][0].end = '[/' + mpl.storage[mid][0].name + ']'; } else { if( mpl.storage[mid][0].name !=='mpl_section_html' ) mpl.storage[mid][0].args[name] = mpl.tools.esc_attr(mpl.storage[mid][0].args[name]); } } } delete map_values, exp, hidden, datas; mpl.confirm(true); } } else { if (mpl.storage[mid]) { var datas = mpl.tools.getFormData(pop, true), prev = {}, hidden = [], exp = new RegExp(mpl_site_url, "g"); map_values = mpl.params.get_values(mpl.storage[mid].name); pop.find('form.fields-edit-form .mpl-param-row').each(function () { if ($(this).hasClass('relation-hidden')) { $(this).find('.mpl-param').each(function () { hidden.push(this.name); }); } }); for (var name in datas) { if (typeof (name) == 'undefined' || name === '') continue; if (hidden.indexOf(name) > -1) datas[name] = ''; if (datas[name] !== '') { if (typeof datas[name] == 'object') { if (typeof (datas[name][0]) == 'string' && datas[name][0] == '') delete datas[name][0]; datas[name] = mpl.tools.base64.encode(JSON.stringify(datas[name]).toString().replace(exp, '%SITE_URL%')); } prev[name] = datas[name]; } else if (hidden.indexOf(name) == -1) { if (map_values[name] !== undefined && map_values[name] !== '' && typeof (prev[name]) == 'undefined') prev[name] = '__empty__'; } if (datas[name] === '' && typeof (prev[name]) == 'undefined') { if (typeof (mpl.storage[mid].args[name]) == 'undefined') continue; else delete mpl.storage[mid].args[name]; } else { mpl.storage[mid].args[name] = prev[name]; if (name == 'content' && mpl.maps[mpl.storage[mid].name].is_container === true) { mpl.storage[mid].end = '[/' + mpl.storage[mid].name + ']'; } else { mpl.storage[mid].args[name] = mpl.tools.esc_attr(mpl.storage[mid].args[name]); } } } delete map_values, exp, hidden, datas; mpl.confirm(true); } } } }, /* View Events */ settings: function (e, atts) { if (e === undefined) return; var el = (typeof (e.tagName) != 'undefined') ? e : this; if (mpl.front) { var mid = mpl.front.get.front_model(el), data = mpl.storage[mid][0], popup = mpl.tools.popup; } else { var mid = mpl.get.model(el), data = mpl.storage[mid], popup = mpl.tools.popup; } if (mpl.maps[data.name] === undefined) return false; var map = $().extend({}, mpl.maps['_std']); map = $().extend(map, mpl.maps[data.name]); if (map.title === undefined) map.title = map.name + ' Settings'; var attz = { title: map.title, width: map.pop_width, height: 400, scrollBack: false, scrollTo: false, storage: data.args, params: map, class: data.name + '_wrpop mpl-elm-settings-popup', }; //if (mpl.front) { // attz['no_cancel'] = true; //} if (atts !== undefined) attz = $.extend(attz, atts); var pop = popup.render(el, attz); mpl.ui.fix_position_popup(pop); pop.data({ model: mid, callback: mpl.backbone.save }); if (mpl.front) { pop.data({ el: $('section[data-front-model="' + mid + '"]') }) } var form = $('
'), tab_icon = 'et-puzzle'; if (map.params[0] !== undefined) { mpl.params.fields.render(form, map.params, data.args); } else { for (var n in map.params) { popup.add_tab(pop, { title: n, class: 'mpl-tab-general-' + mpl.tools.esc_slug(n), cfg: n + '|' + mid + '|' + data.name, callback: mpl.params.fields.tabs }); } pop.find('.m-p-wrap>.mpl-pop-tabs>li').first().trigger('click'); } pop.find('.m-p-body').append(form); delete groups, map; return pop; }, double: function (e, exp) { if (e === undefined) return false; var el = (typeof (e.tagName) != 'undefined') ? e : this; var id = mpl.get.model(el), data = mpl.storage[id], cdata = $().extend(true, {}, data), cel, func, is_col = (['mpl_column', 'mpl_column_inner'].indexOf(data.name) > -1); cdata.args._id = Math.round(Math.random() * 1000000); if (exp === undefined) var exp = mpl.backbone.export(id); if (data.name != 'mpl_column_text') cdata.args.content = mpl.params.process_alter(exp.content, data.name); el = $('#model-' + id); if (is_col && el.parent().find('>.mpl-model').length >= 10) { alert(mpl.__.i54); return; } cdata.model = mpl.model++; if (data.name == 'mpl_row') { cel = mpl.views.row.render(cdata, true); } else if (data.name == 'mpl_column') { cel = mpl.views.column.render(cdata, true); } else if (mpl.tags.indexOf(cdata.name)) { try { func = mpl.maps[cdata.name].views.type; } catch (ex) { func = cdata.name; } if (typeof mpl.views[func] == 'object') cel = mpl.views[func].render(cdata); else cel = mpl.views.mpl_element.render(cdata); } else { cel = mpl.views. mpl_undefined .render({ args: { content: cdata.content }, name: 'mpl_undefined', end: '[/mpl_undefined]', full: cdata.content }); } el.after(cel); if (is_col) mpl.views.column.reset_view(el.parent()); if (el.height() > 300 && !el.hasClass('mpl-column')) $('html,body').scrollTop($(window).scrollTop() + el.height()); mpl.ui.sortInit(); return cel; }, add: function (e) { e.preventDefault(); var el = (typeof (e.tagName) != 'undefined') ? e : this; var atts = { title: mpl.__.i02, width: 1300, class: 'no-footer mpl-adding-elements', float: true }; if ($(window).width() < 1350) { atts.class += ' mpl-small-screen-pop'; atts.width = 950; } var pop = mpl.tools.popup.render(el, atts); var pos = 'bottom', model = mpl.get.model(el); if ($(el).closest('.pos-top').length > 0) pos = 'top'; pop.data({ model: model, pos: pos }); pop.find('h3.m-p-header').append( $('') .on('keyup', mpl.ui.search_elements) ).append(''); var components = $(mpl.template('components', { model: model, pos: pos })); pop.find('.m-p-body').append(components); mpl.trigger({ el: components, events: { 'ul.mpl-components-categories li[data-category]:click': 'categories', 'ul.mpl-components-list-main li:click': 'items', }, categories: function (e) { var category = $(this).data('category'), atts = {}, el; mpl.cfg.elmTabActive = category; mpl.backbone.stack.set('MPL_Configs', mpl.cfg); $(this).parent().find('.active').removeClass('active'); $(this).addClass('active'); e.data.el.find('#mpl-clipboard,.mpl-wp-widgets-pop').remove(); if ($(this).hasClass('mcl-clipboard')) { e.data.el.find('.mpl-components-list-main').css({ display: 'none' }); el = $(mpl.template('clipboard', atts)); e.data.el.append(el); if (typeof atts.callback == 'function') atts.callback(el); return; } else if ($(this).hasClass('mcl-wp-widgets')) { e.data.el.find('.mpl-components-list-main').css({ display: 'none' }); el = $(mpl.template('wp-widgets-element', atts)); e.data.el.append(el); if (typeof atts.callback == 'function') atts.callback(el, e); return; } e.data.el.find('.mpl-components-list-main').show(); if (category == 'all') { e.data.el.find('.mpl-components-list-main li').show(); } else { e.data.el.find('.mpl-components-list-main li, #mpl-clipboard').css({ display: 'none' }); e.data.el.find('.mpl-components-list-main .mcpn-' + category).show(); } }, items: function (e) { if ($(this).data('rule') == 'pro') { var title = $(this).find(".cpdes").text(); mpl.msg(title + 'Support By Pro Version Of Mageewp Page Layout.', 'MPL Pro Support', 'sl-close', 3000); } else { var full = mpl.ui.prepare($(this).data('name'), $(this).data('data')); if (mpl.front) { $.ajax({ url: mpl_ajax_url, method: 'POST', dataType: 'html', data: { action: 'mpl_front_section_data', shortcode: full }, success: function (html) { var new_css = html.match(/