: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
var ThemifyBuilderCommon;
(function ($,document, Themify) {
const cl = document.body.classList;
show ? cl.add('tbp_loading') : cl.remove('tbp_loading');
this.pageId = themifyBuilder.pageId;
this.options = _tbp_app.options;
this.labels = themifyBuilder.labels;
_tbp_app.options = themifyBuilder.labels = themifyBuilder.pageId = null;
document.body.classList.add('tbp_page',this.pageId + '_page');
const template = document.getElementById('tmpl-tbp_builder_lightbox'),
btn = document.getElementsByClassName('page-title-action')[0],
items = document.getElementsByClassName('tbp_lightbox_edit'),
import_btn = document.createElement('div');
import_btn.className = 'tbp_admin_import ' + this.pageId + '_import';
import_btn.innerHTML = themifyBuilder.import_btn ? themifyBuilder.import_btn : '';
document.body.appendChild(template.content);
this.lightbox = document.getElementById('tb_lightbox_parent');
this.lightboxContainer = this.lightbox.getElementsByClassName('tb_options_tab_wrapper')[0];
this.lightbox.getElementsByClassName('ti-close')[0].addEventListener('click', this.close.bind(this));
btn.addEventListener('click', this.edit.bind(this));
if (themifyBuilder.import_btn) {
btn.parentNode.insertBefore(import_btn, btn.nextSibling);
themify_create_pluploader($(import_btn.firstElementChild));
const alertLoading = document.createElement('DIV');
alertLoading.className = 'alert';
document.body.appendChild(alertLoading);
for (let i = items.length - 1; i > -1; --i) {
items[i].addEventListener('click', this.edit.bind(this));
if(_tbp_app.draftBtn!==undefined){
this.lightbox.getElementsByClassName('tbp_submit_draft_btn')[0].textContent = _tbp_app.draftBtn;
this.lightbox.getElementsByClassName('tbp_btn_save')[0].textContent = _tbp_app.publishBtn;
ThemifyBuilderCommon = {Lightbox: {$lightbox: $(this.lightbox)}};
const link = document.createElement('link'),
loader = document.createElement('div');
link.href = _tbp_app.api_base;
loader.className = 'tb_busy';
document.head.appendChild(link);
document.body.appendChild(loader);
themifyBuilder.import_btn = null;
if (ThemifyConstructor.values[key] !== undefined) {
return ThemifyConstructor.values[key];
for (let i = this.options.length - 1; i > -1; --i) {
if (this.options[i].id === key) {
return this.options[i]['options'] === undefined ? this.options[i] : Object.keys(this.options[i]['options'])[0];
* @arg string file URL to the JSON file containing the demo data
* @arg string theme_id ID of the newly created theme
* @arg function callback function to call after all import is done
import_sample_content( file, theme_id, callback ) {
success : function( resp ) {
max_query = 5; // maximum number of requests to send simultaneously
let count = 0; // keep track of how many requests are ongoing simultaneously
if ( resp.terms !== undefined ) {
$.each( resp.terms, function( term_id, term ) {
action : 'tbp_import_term',
if ( resp.posts !== undefined ) {
$.each( resp.posts, function( post_id, post ) {
action : 'tbp_import_post',
if ( queue.length === 0 ) {
function make_request() {
if ( queue.length === 0 || count > max_query ){
success : function( response ) {
for ( let i = 0; i < max_query; ++i ) {
const editBtn = this.lightbox.getElementsByClassName('builder_button_edit')[0];
editBtn.textContent = this.pageId==='tbp_theme' && _tbp_app.active!=this.id?_tbp_app.publishBtn:this.labels['save'];
editBtn.textContent =_tbp_app.next;
if (ThemifyConstructor['tbp_type'] !== undefined) {
var bindings = undefined;
saveLightbox = function (is_draft, id, data) {
url: themifyBuilder.ajaxurl,
action: _this.pageId + '_saving',
tb_load_nonce: themifyBuilder.tb_load_nonce
if ( _this.pageId === 'tbp_theme' ) {
const $theme = $( '.layout_preview_list.selected', _this.lightbox ),
slug = $theme.attr( 'data-slug' );
if ( slug === 'blank' ) {
window.location = resp.redirect;
const theme_id = resp.redirect.match( /id=(\d+)/ )[1];
// import tbp_template posts for the theme
TBP.import_sample_content( 'https://themify.me/public-api/builder-pro-demos/pro-' + slug + '-templates.json', theme_id, function() {
if ( $( '.tbp_import_demo input', $theme ).is( ':checked' ) ) {
TBP.import_sample_content( 'https://themify.me/public-api/builder-pro-demos/pro-' + slug + '.json', theme_id, function() {
window.location = resp.redirect;
window.location = resp.redirect;
window.location = resp.redirect;
if ( _this.pageId === 'tbp_theme' ) {
_this.lightbox.getElementsByClassName('ti-close')[0].click();
window.location.reload();
_this.lightbox.classList.add('tbp_lightbox_is_saved');
_this.lightbox.classList.remove('tbp_lightbox_is_saved');
function resizeMasonryItem(item){
const rowGap = parseInt(window.getComputedStyle(el).getPropertyValue('grid-row-gap')),
rowHeight = parseInt(window.getComputedStyle(el).getPropertyValue('grid-auto-rows'));
if(isNaN(rowGap) || isNaN(rowHeight)){
const itemHeight = item.getElementsByClassName('thumbnail')[0].getBoundingClientRect().height + item.getElementsByClassName('layout_action')[0].getBoundingClientRect().height,
rowSpan = Math.ceil((itemHeight+rowGap)/(rowHeight+rowGap));
item.style.gridRowEnd = 'span '+rowSpan;
item.dataset['masonry'] = 'done';
const allItems = el.querySelectorAll('.layout_preview_list:not([data-masonry="done"])');
for(let i=0,len=allItems.length;i<len;i++){
resizeMasonryItem(allItems[i]);
setPredesgnedList = function (result) {
document.body.classList.add('tbp_step_2');
let api_base = _tbp_app.api_base,
type = result['tbp_template_type'];
const demo_base = _tbp_app.demo_base,
container = _this.lightbox.getElementsByClassName('tb_options_tab_content'),
callback = function (data) {
const f = document.createDocumentFragment(),
wrap = document.createElement('div'),
ul = document.createElement('ul'),
selected = container[1] !== undefined ? container[1].getAttribute('data-' + type + '-selected') : null;
wrap.className = 'tbp_predesigned_row_container';
wrap.id = _this.pageId + '_import';
ul.className = 'tbp_predesigned_theme_lists';
if('footer' === type || 'header' === type){
ul.className += ' tbp_predesigned_'+type;
if (data[0] === undefined || data[0].slug !== 'blank') {
data.unshift({'slug': 'blank', link: '#', 'title': {rendered: _tbp_app.blank}, 'id': ''});
for (let i = 0, len = data.length; i < len; ++i) {
let li = document.createElement('li'),
img = document.createElement('img'),
thumb = document.createElement('div'),
action = document.createElement('div'),
title = document.createElement('div'),
aImg = document.createElement('a'),
aTitle = document.createElement('a'),
icon = document.createElement('i'),
preview = document.createElement('div');
li.className = 'layout_preview_list';
li.setAttribute('data-slug', data[i].slug);
li.setAttribute('data-id', data[i].id);
preview.className = 'layout_preview';
thumb.className = 'thumbnail';
action.className = 'layout_action';
title.className = 'layout_title';
aImg.title = data[i].title.rendered;
if (selected === data[i].slug || (!selected && data[i].slug === 'blank')) {
li.className += ' selected';
if (data[i].slug === 'blank') {
preview.className += ' layout_preview_blank';
if ( demo_base && data[i].link && data[i].link !== '#' ) {
aImg.href = aTitle.href = demo_base + data[i].slug;
aTitle.target = '_blank';
aTitle.innerHTML = data[i].title.rendered;
title.appendChild(aTitle);
// for Templates; no preview page
title.innerHTML = data[i].title.rendered;
img.src = data[i]['tbp_image_full'] ? data[i].tbp_image_full : themifyBuilder.ph_image;
img.alt = data[i].title.rendered;
action.appendChild(title);
action.appendChild(aImg);
preview.appendChild(thumb);
preview.appendChild(action);
if ( _this.pageId === 'tbp_theme' ) {
let importtick = document.createElement( 'input' ),
importWarning = document.createElement( 'span' ),
importlbl = document.createElement( 'label' );
importtick.type = 'checkbox';
importlbl.className = 'tbp_import_demo';
importlbl.appendChild( importtick );
importlbl.appendChild( document.createTextNode( tbpAdminVars.i18n.import ) );
importWarning.appendChild( document.createTextNode( tbpAdminVars.i18n.import_warning ) );
importlbl.appendChild( importWarning );
li.appendChild( importlbl );
const lightboxTitle = _this.lightbox.getElementsByClassName('tbp_lightbox_title')[0],
prevLink = document.createElement('a'),
icon = document.createElement('i');
prevLink.className = 'tbp_wizard_step_prev';
icon.className = 'ti-arrow-left';
prevLink.appendChild(icon);
lightboxTitle.innerHTML = '';
lightboxTitle.appendChild(prevLink);
lightboxTitle.appendChild(document.createTextNode(_tbp_app.import));
prevLink.addEventListener('click', function (e) {
document.body.classList.remove('tbp_step_2');
container[1].style['display'] = 'none';
container[0].style['display'] = '';
this.parentNode.innerHTML = _tbp_app.add_template;
if (container[1] !== undefined) {
container[1].innerHTML = '';
container[1].appendChild(wrap);
container[1].style['display'] = '';
const tabContent = document.createElement('div');
tabContent.className = 'tb_options_tab_content';
tabContent.appendChild(wrap);
container[0].parentNode.insertBefore(tabContent, container[0].nextSibling);
container[0].style['display'] = 'none';
ul.addEventListener('click', function (e) {
if (e.target.closest('.layout_title, .tbp_import_demo') === null) {
const el = e.target.closest('.layout_preview_list');
if (el !== null && !el.classList.contains('selected')) {
const childs = this.children;
for (let i = childs.length - 1; i > -1; --i) {
childs[i].classList.remove('selected');
el.classList.add('selected');
container[1].setAttribute('data-' + type + '-selected', el.dataset['slug']);
if ( _this.pageId === 'tbp_template' ) {
let img = ul.getElementsByTagName('img');
$(img).one('load', function () {
$(_this.lightbox).find('.tbp_step_2_actions').first().off('click').on('click', function (e) {
if (e.target.classList.contains('tbp_submit_draft_btn') || e.target.classList.contains('tbp_btn_save')) {
result['import'] = ul.getElementsByClassName('selected')[0].getAttribute('data-slug');
saveLightbox(e.target.classList.contains('tbp_submit_draft_btn'), null, result);
if (type !== undefined) {
if (cachePredesing[type] === undefined) {
container[0].classList.add('tb_busy');
$.getJSON(api_base, function (data) {
cachePredesing[type] = data;
container[0].classList.remove('tb_busy');
callback(cachePredesing[type]);
ThemifyConstructor['tbp_image'] = {
const input = $(e.currentTarget).parent().children('input').first();
input.val('').trigger('change');
Themify.triggerEvent(input[0], 'change');
const image = self.image.render(data, self),
image.getElementsByClassName('tb_clear_input')[0].addEventListener('click', this.change.bind(this));
image.appendChild(self.hidden.render(attach, self));
ThemifyConstructor['tbp_type'] = {
if (bindings === undefined) {
bindings = data['binding'];
TBP.type =TBP.getValue(this.id);
const select = self.select.render(data, self);
select.querySelector('select').addEventListener('change', function (e) {
ThemifyConstructor['condition'].reInit();
ThemifyConstructor['condition'] = {
const wrap=document.getElementById(this.id);
wrap.parentNode.replaceChild(this.render(TBP.conditions,ThemifyConstructor),wrap);
includeRender(vals, self) {
const wrap = document.createElement('div'),
select = document.createElement('select'),
wrap.className = 'tbp_include tbp_inner_block';
select.appendChild(self.select.make_options(args,vals['include'], self));
select.setAttribute('data-id', args.id);
wrap.appendChild(select);
renderSelect(options,selected){
const f = document.createDocumentFragment(),
select = document.createElement('select'),
makeOptions = function(val,label,has_query,def){
const opt = document.createElement('option');
if(val===selected || (def===val && TBP.id===null)){
if(has_query!==undefined){
opt.setAttribute('data-hasQuery',has_query?1:0);
for(let j=0,len=options[i].length;j<len;++j){
let group = document.createElement('optgroup'),
groupF = document.createDocumentFragment();
group.label = options[i][j]['label'];
group.setAttribute('data-id', options[i][j].id);
for (let k in options[i][j]['options']) {
let item=options[i][j]['options'][k];
groupF.appendChild(makeOptions(k, item['label']!==undefined?item['label']:item,item['has_query'],options[i][j]['selected']));
group.appendChild(groupF);