';
jQuery('.nbd-sidebar-con-inner.wishlist').prepend(wish_html);
}
};
var nbd_preview_html = [];
var previewTempalte = function(e, tid){
e.preventDefault();
NBDPopup.initPopup();
if( nbd_preview_html[tid] != undefined ){
jQuery('.nbd-popup-content-inner').html(nbd_preview_html[tid]);
}else{
jQuery('#nbd-popup-loading').removeClass('hide');
jQuery('.nbd-popup-content-inner').addClass('hide');
jQuery.ajax({
url: nbds_frontend.url,
method: "POST",
data: 'action=nbd_get_template_preview&template_id=' + tid + '&nonce=' + nonce
}).done(function(data){
if( data.flag == 1 ){
jQuery('.nbd-popup-content-inner').html(data.html);
nbd_preview_html[tid] = data.html;
}
jQuery('#nbd-popup-loading').addClass('hide');
jQuery('.nbd-popup-content-inner').removeClass('hide');
});
}
};
var nbd_list_product_html = '';
var showPopupCreateTemplate = function(){
NBDPopup.initPopup();
if( nbd_list_product_html != '' ){
jQuery('.nbd-popup-content-inner').html( nbd_list_product_html );
}else{
jQuery('#nbd-popup-loading').removeClass('hide');
jQuery('.nbd-popup-content-inner').addClass('hide');
jQuery.ajax({
url: nbds_frontend.url,
method: "POST",
data: 'action=nbd_get_list_product_ready_to_create_template' + '&nonce=' + nonce
}).done(function(data){
if( data.flag == 1 ){
jQuery('.nbd-popup-content-inner').html(data.html);
nbd_list_product_html = data.html;
}
jQuery('#nbd-popup-loading').addClass('hide');
jQuery('.nbd-popup-content-inner').removeClass('hide');
});
}
};
var nbd_preview_product_html = [];
var previewNBDProduct = function(pid){
if( nbd_preview_product_html[pid] != undefined ){
jQuery('.nbd-popup-content-inner').html(nbd_preview_product_html[pid]);
}else{
jQuery('#nbd-popup-loading').removeClass('hide');
jQuery('.nbd-popup-content-inner').addClass('hide');
jQuery.ajax({
url: nbds_frontend.url,
method: "POST",
data: 'action=nbd_get_preview_product_before_create_template&product_id=' + pid + '&nonce=' + nonce + '&art_id=' + art_id
}).done(function(data){
if( data.flag == 1 ){
jQuery('.nbd-popup-content-inner').html(data.html);
nbd_preview_product_html[pid] = data.html;
}
jQuery('#nbd-popup-loading').addClass('hide');
jQuery('.nbd-popup-content-inner').removeClass('hide');
});
}
};
var changePreviewImage = function(e){
var src = jQuery(e).attr('src');
jQuery('.nbd-popup-list-preview img').removeClass('active');
jQuery(e).addClass('active');
jQuery('#nbd-popup-large-preview').attr('src', src);
};
var switchNBDProductVariation = function(e){
var vid = jQuery(e).val(),
btn = jQuery('#nbd-popup-link-create-template'),
origin_fref = btn.data('href'),
new_href = origin_fref + '&variation_id=' + vid;
btn.attr('href', new_href);
}
jQuery( document ).ready(function(){
var templates = '[]';
localStorage.setItem("nbd_favourite_templates", templates);
renderNBDGallery( true );
NBDPopup.calcWidth();
});
jQuery("body").click(function(e) {
if(e.target.id == 'nbd-popup'){
NBDPopup.hidePopup();
}
});
jQuery(document).bind('keydown', function(e) {
if( e.which == 27 ){
NBDPopup.hidePopup();
}
});
jQuery(window).on('resize', function () {
NBDPopup.calcWidth();
});
var isNBDLoading = false;
jQuery(window).on('scroll', function () {
!isNBDLoading && (nbd_page.current_page < nbd_page.last_page) && isScrolledIntoView('#nbd-pagination') && loadMoreGallery( nbd_page );
});
var renderNBDGallery = function( init, callback ){
imagesLoaded( jQuery('#nbdesigner-gallery'), function() {
if( !init ) jQuery('#nbdesigner-gallery').masonry('reloadItems');
jQuery('#nbdesigner-gallery').masonry({
itemSelector: '.nbdesigner-item',
transitionDuration: 0
});
jQuery.each(jQuery('#nbdesigner-gallery .nbdesigner-item'), function(e) {
jQuery(this).addClass("in-view");
});
if( typeof callback == 'function' ){
callback();
}
});
};
var loadMoreGallery = function( nbd_page ){
jQuery('#nbd-load-more').show();
isNBDLoading = true;
nbd_page.current_page++;
jQuery('#nbd-pagination').addClass('nbdesigner-disable');
var data = {
action: 'nbd_get_next_gallery_page',
url: nbd_page.url,
page: nbd_page.current_page,
row: nbd_page.row,
per_row: nbd_page.per_row,
total: nbd_page.total,
limit: nbd_page.limit,
nonce: nonce
};
jQuery.ajax({
url: nbds_frontend.url,
method: "POST",
data: data
}).done(function(data){
jQuery('#nbd-pagination').removeClass('nbdesigner-disable');
var new_url = addParameter(nbd_page.url, 'paged', nbd_page.current_page, false);
history.pushState(null, null, new_url );
isNBDLoading = false;
if( data.flag ){
jQuery('#nbdesigner-gallery').append(data.items);
jQuery('#nbd-pagination-wrap').html('').html(data.pagination);
renderNBDGallery( false, function(){
jQuery('#nbd-load-more').hide();
} );
}else{
jQuery('#nbd-load-more').hide();
}
});
};
var NBDPopup = {
initPopup: function(){
jQuery('.nbd-popup').addClass('active');
jQuery('.nbd-popup').removeClass('hide');
jQuery('body').addClass('open-nbd-popup');
},
calcWidth: function(){
var width = jQuery(window).width(),
height = jQuery(window).height(),
popupWidth = 600,
minHeight = 500,
popupTop = 100;
if( width < 600 ) {
popupWidth = width - 30;
}
if( height < 700 ) {
minHeight = height - 200;
}
jQuery('.nbd-popup-content-wrap').css({
'width': popupWidth + 'px',
'margin': popupTop + 'px auto',
'min-height': minHeight + 'px'
});
jQuery('.nbd-popup-content').css({
'min-height': minHeight + 'px'
});
},
hidePopup: function(){
jQuery('.nbd-popup').removeClass('active');
jQuery('body').removeClass('open-nbd-popup');
setTimeout(function(){
jQuery('.nbd-popup').addClass('hide');
}, 500);
}
};
var isScrolledIntoView = function(elem){
var docViewTop = jQuery(window).scrollTop();
var docViewBottom = docViewTop + jQuery(window).height();
var elemTop = jQuery(elem).offset().top;
var elemBottom = elemTop + jQuery(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
};