: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if(layout!=='lightboxed'){
this.bindEvents(module,data);
api.Utils.runJs(this.el,'module');
let value=this.get('mod_settings').shortcode_gallery;
if(api.activeModel?.id===this.id){
const textarea=ThemifyConstructor.getEl('shortcode_gallery');
setShortcodeValue(shortcode,trigger=true){
if(api.activeModel?.id===this.id){
ThemifyConstructor.settings.shortcode_gallery=shortcode;
const textarea=ThemifyConstructor.getEl('shortcode_gallery');
textarea.value=shortcode;
Themify.triggerEvent(textarea,'change');
api.undoManager.start('inline');
this.get('mod_settings').shortcode_gallery=shortcode;
api.undoManager.end('inline');
el.tfOn(_CLICK_,async e=>{
const target=e.target?.closest('.tb_add_gal_btn,.tb_del_gal');
if(target.classList.contains('tb_del_gal')){
const itemId=target.dataset.id,
galleryField=ThemifyConstructor.gallery,
oldVal=this.getShortcodeValue(),
shortcode = galleryField.parseIds(oldVal),
index = shortcode?.indexOf(itemId) ?? -1;
shortcode.splice(index,1);
const layout=data.layout_gallery|| 'grid',
trigger=layout==='slider' || (layout==='showcase' && index===0),
val=shortcode.length > 0 ? galleryField.replaceShortcode(oldVal, shortcode.join(',')) : '';
if(api.activeModel?.id===this.id){
api.LightBox.el.querySelector('.tf_close[data-id="'+itemId+'"]')?.closest('.tb_gal_item')?.remove();
if(!this.setShortcodeValue(val,trigger)){
const galItem=target.closest('.gallery-item') || target.closest('.gallery-icon');
if(layout==='grid' && data.layout_masonry){
api.Utils.runJs(this.el,'module');
this.previewLive(this.get('mod_settings'));
const btn=createElement(),
input=createElement('input');
input.tfOn('change',async e=>{
const inp=e.currentTarget;
if(!this.setShortcodeValue(inp.value)){
const layout=data.layout_gallery|| 'grid';
await this[layout].call(this,e.detail.images,data,true);
api.Utils.runJs(this.el,'module');
},{passive:true,once:true})
.value=this.getShortcodeValue() || '';
ThemifyConstructor.gallery.init(btn,input);
grid(images,data,addImages){
const fr=createDocumentFragment(),
frImages=createDocumentFragment(),
showTitle=data.gallery_image_title==='yes',
showCaption=data.gallery_exclude_caption!=='yes',
pagination=data.gallery_pagination && data.gallery_per_page>0,
{gallery_columns:desktopCols=3,t_columns:tabletCols,m_columns:mobileCols}=data,
classes=['module-gallery-grid'],
items=pagination?images.slice(0,data.gallery_per_page):images;
for(let i=0;i<items.length;++i){
dl=createElement('dl','gallery-item'),
dt=createElement('dt','gallery-icon tf_rel'),
img=this.constructor.setEditableImage(createElement('img'),'','thumb_w_gallery','thumb_h_gallery',data),
src=item.large?.[0] || item.full?.[0] || item.thumbnail,
caption=item.caption || '';
img.src=ThemifyImageResize.getCache(src,data.thumb_w_gallery,data.thumb_h_gallery,.8) || src;
if( data.link_opt!=='none'){
let link=createElement('a',{href:'#',title:caption,'data-title':title,rel:item.id || ''});
link.className='themify_lightbox';
dt.appendChild(createElement('span',{class:'tb_del_btn tb_del_gal tf_close tb_disable_sorting',role:'button','data-id':item.id || '',title:'Delete Image'}));
if((title!=='' && showTitle===true) || (caption!=='' && showCaption===true)){
let dd=createElement('dd','wp-caption-text gallery-caption');
if(title!=='' && showTitle===true){
dd.appendChild(createElement('strong','themify_image_title tf_block',title));
if(caption!=='' && showCaption===true){
dd.appendChild(createElement('span','themify_image_caption',caption));
frImages.appendChild(dl);
this.el.tfClass('module-gallery-grid')[0].replaceChildren(frImages);
gridSt.setProperty('--gald',desktopCols);
gridSt.setProperty('--galt',tabletCols || desktopCols);
gridSt.setProperty('--galm',mobileCols || tabletCols || desktopCols);
classes.push('gallery-masonry');
grid.className=classes.join(' ');
grid.appendChild(frImages);
fr.append(grid,createElement('span',{class:'tb_add_gal_btn tb_add_btn tf_plus_icon',role:'button',title:'Add Images'}));
showcase(images,data,addImages){
const constructor=this.constructor,
fr=createDocumentFragment(),
frImages=createDocumentFragment(),
showCaseWrap=createElement('','gallery-showcase-image'),
imageWrap=createElement('','image-wrapper gallery-icon tf_rel'),
thumbsWrap=createElement('','gallery-images tf_hidden'),
mainItem=images[0] || {},
src=mainItem.large?.[0] || mainItem.full?.[0] || mainItem.thumbnail,
mainImg=constructor.setEditableImage(createElement('img'),'','s_image_w_gallery','s_image_h_gallery',data);
mainImg.src=ThemifyImageResize.getCache(src,data.s_image_w_gallery,data.s_image_h_gallery,.8) || src;
mainImg.dataset.orig = src;
imageWrap.appendChild(mainImg);
if((mainItem.title && data.gallery_image_title==='yes') || (mainItem.caption && data.gallery_exclude_caption!=='yes')){
const showCaseTitle=createElement('','gallery-showcase-title tf_hidden tf_abs tf_textl');
if(mainItem.title && data.gallery_image_title==='yes' ){
showCaseTitle.appendChild(createElement('strong','gallery-showcase-title-text',mainItem.title));
if(mainItem.caption && data.gallery_exclude_caption!=='yes'){
showCaseTitle.appendChild(createElement('span','gallery-showcase-caption',mainItem.caption));
imageWrap.appendChild(showCaseTitle);
showCaseWrap.appendChild(imageWrap);
for(let i=0;i<images.length;++i){
galItem=createElement('','gallery-icon tf_rel'),
linkImage=createElement('a',{href:'#',title:item.title || ''}),
dataset=linkImage.dataset,
thumb=constructor.setEditableImage(createElement('img'),'','thumb_w_gallery','thumb_h_gallery',data),
src=item.large?.[0] || item.full?.[0] || item.thumbnail;
thumb.src=ThemifyImageResize.getCache(src,data.thumb_w_gallery,data.thumb_h_gallery,.8) || src;
thumb.dataset.orig = src;
dataset.caption=item.caption || '';
dataset.orig=dataset.image=src;
ThemifyImageResize.toBlob(linkImage, data.s_image_w_gallery, data.s_image_h_gallery).then(url=>{
linkImage.appendChild(thumb);
galItem.append(linkImage,createElement('span',{role:'button',class:'tb_del_btn tb_del_gal tf_close tb_disable_sorting',title:'Delete Image','data-id':item.id}));
frImages.appendChild(galItem);
el.tfClass('gallery-images')[0].replaceChildren(frImages);
el.tfClass('gallery-showcase-image')[0].replaceWith(showCaseWrap);
thumbsWrap.append(frImages,createElement('span',{role:'button',class:'tb_add_gal_btn tf_plus_icon tf_opacity tf_rel',title:'Add Images'}));
fr.append(showCaseWrap,thumbsWrap);
slider(images,data,addImages){
const fr=createDocumentFragment(),
cssUrl=ThemifyBuilderModuleJs.cssUrl+'sliders/',
id='tb_'+this.id+'_thumbs',
pause_on_hover_slider:'resume',
auto_scroll_opt_slider: 'off',
height_slider: 'variable'
showTitle=args.gallery_image_title==='yes',
showCaption=args.gallery_exclude_caption!=='yes',
showThumbs=args.slider_thumbs!=='yes';
for(let i=0;i<slides.length;++i){
let isSlider=slides[i]==='slider',
hasNav= (slides[i]===( (isSlider === true && showThumbs===false) || data.show_arrow_buttons_vertical ? 'slider' : 'thumbs' )) ? (args.show_arrow_slider === 'yes' ? 1 : 0):0,
swiperContainer=createElement('','tf_swiper-container tf_carousel themify_builder_slider tf_rel tf_overflow'),
swiperWrapper=createElement('','tf_swiper-wrapper tf_lazy tf_rel tf_w tf_h tf_textc'),
dataset=swiperContainer.dataset,
imgWKey= 's_image_w_gallery',
imgHKey= 's_image_h_gallery';
imgWKey='thumb_w_gallery';
imgHKey='thumb_h_gallery';
swiperContainer.className+=' '+id;
if (args.auto_scroll_opt_slider !== 'off'){
dataset.auto=args.auto_scroll_opt_slider;
dataset.pause_hover=args.pause_on_hover_slider === 'resume' ? 1 : 0;
if (args.play_pause_control === 'yes'){
dataset.effect=args.effect_slider;
dataset.css_url=cssUrl+'carousel,'+cssUrl+'gallery';
dataset.pager=(isSlider === false || showThumbs===false) && args.show_nav_slider === 'yes'?1:0;
dataset.speed=args.speed_opt_slider;
dataset.wrapvar=args.wrap_slider === 'yes' ? 1 : 0;
dataset.slider_nav=hasNav;
dataset.height=args.horizontal === 'yes' ? 'variable' : args.height_slider;
dataset.touch_swipe=args.touch_swipe;
if(isSlider === false || showThumbs===false){
dataset.visible=args.visible_opt_slider || '';
dataset.tabVisible=args.tab_visible_opt_slider || '';
dataset.mobVisible=args.mob_visible_opt_slider || '';
dataset.scroll=args.scroll_opt_slider;
for(let j=0;j<images.length;++j){
slideItem=createElement('','tf_swiper-slide'),
slideInner=createElement('','slide-inner-wrap'),
slideImage=createElement('','tf_lazy slide-image gallery-icon'),
img=this.constructor.setEditableImage(createElement('img'),'',imgWKey,imgHKey,args),
src=item.full?.[0] || item.large?.[0] || item.thumbnail,
{title='',caption=''}=item;
if(args.left_margin_slider!==undefined){
slideInner.style.marginLeft=args.left_margin_slider+'px';
if(args.right_margin_slider!==undefined){
slideInner.style.marginRight=args.right_margin_slider+'px';
img.src=ThemifyImageResize.getCache(src,args[imgWKey],args[imgHKey],.8) || src;
if(isSlider===true && data.link_opt!=='none'){
let link=createElement('a');
link.className+=' themify_lightbox';
slideImage.appendChild(link);
slideImage.appendChild(img);
if((showThumbs===false || isSlider===false) && images.length>1){
slideImage.appendChild(createElement('',{role:'button',class:'tb_del_btn tb_del_gal tf_close tb_disable_sorting','data-id':item.id,title:'Delete Slide'}));
slideInner.appendChild(slideImage);
if(isSlider===true && ((title!=='' && showTitle===true) || (caption!=='' && showCaption===true))){
let content=createElement('','content tf_opacity tf_texl tf_abs');
if(title!=='' && showTitle===true){
content.appendChild(createElement('h3','slide-title',title));
if(caption!=='' && showCaption===true){
content.appendChild(createElement('p','',caption));
slideInner.appendChild(content);
slideItem.appendChild(slideInner);
swiperWrapper.appendChild(slideItem);
swiperContainer.appendChild(swiperWrapper);
swiperContainer.appendChild(createElement('span',{role:'button',class:'tb_add_gal_btn tb_add_btn tf_plus_icon',title:'Add Slides'}));
let sliderVertical=createElement('','themify_builder_slider_vertical tf_rel');
sliderVertical.appendChild(swiperContainer);
fr.appendChild(sliderVertical);
fr.appendChild(swiperContainer);
for(let swipers=this.el.tfClass('tf_swiper-container'),i=swipers.length-1;i>-1;--i){
let parent=swipers[i].parentNode;
if(parent.classList.contains('themify_builder_slider_vertical')){
this.el.tfClass('tb_data_mod_name')[0].after(fr);
async lightboxed(images,data){
const fr=createDocumentFragment(),
showTitle=data.gallery_image_title==='yes',
showCaption=data.gallery_exclude_caption!=='yes',
thumbnailGallery=data.thumbnail_gallery || null,
items=[];//in live preview this always show 1 element, but maybe in the "preview" we will change this?
const field={full:[thumbnailGallery]};
if(showTitle===true || showCaption===true){
let cache=this.constructor.cache,
res=cache.get(thumbnailGallery);
res=await api.LocalFetch({action:'tb_gallery_lightbox_data',url:thumbnailGallery});
cache.set(thumbnailGallery,res);
field.title=res?.title ?? images[0].title;
field.caption=res?.caption ?? images[0].caption;
for(let i=0;i<items.length;++i){
let dl=createElement('dl','gallery-item'),
img=this.constructor.setEditableImage(createElement('img'),(thumbnailGallery?'thumbnail_gallery':''),'thumb_w_gallery','thumb_h_gallery',data),
src=item.full?.[0] || item.large?.[0] || item.thumbnail,
{title='',caption=''}=item;
dl.className+=' tf_hidden';
img.src=ThemifyImageResize.getCache(src,data.thumb_w_gallery,data.thumb_h_gallery,.8) || src;
let dt=createElement('dt','gallery-icon'),
link=createElement('a',{class:'themify_lightbox',href:item.link,title:title,'data-title':data.lightbox_title || '',rel:this.id});
if((title!=='' && showTitle===true) || (caption!=='' && showCaption===true)){
let dd=createElement('dd','wp-caption-text gallery-caption');
if(title!=='' && showTitle===true){
dd.appendChild(createElement('strong','themify_image_title tf_block',title));
if(caption!=='' && showCaption===true){
dd.appendChild(createElement('span','themify_image_caption',caption));
Themify.on('tb_options_expand', container=> {
if ( api.isVisual && container&& api.activeModel?.get('mod_name')==='gallery') {
for(let sliderRanges=container.querySelectorAll('#gr_ga_c,#gr_ga_r'),i=sliderRanges.length-1;i>-1;--i){
let isVertical=sliderRanges[i].id==='gr_ga_r';
sliderRanges[i].closest('.tb_slider_container').querySelector('input[type="range"]')?.tfOn('input',()=>{
const gallery=api.activeModel.el.tfClass('gallery-masonry')[0];
window.Isotope?.data(gallery)?.layout();
Themify.trigger('builder_load_module_partial',[gallery.parentNode,true]);