(function($) {
var uniqID = function() {
return Math.round(new Date().getTime() + (Math.random() * 100));
}
var blWrap = function(bltype,blmode,blview) {
var id = uniqID(),
menu_lock = (PAGE_MODE == 'c') ? '' : property.ISLOCK,
bl_class = (typeof menu_lock != 'undefined' && menu_lock == 'true') ? 'hide ' : '';
if(bltype == 'F') bl_class += 'colorSet ';
if(bltype == 'P' && blmode == 'project') bl_class += 'galProjectBg ';
$str = $('
');
$str.css({
'text-align' : 'center',
'font-size' : '20px',
'background-image' : 'url(https://storage.googleapis.com/i.addblock.net/preloader2.gif)',
'background-position' : 'center center',
'background-repeat' : 'no-repeat',
'min-height' : '50px'
});
return {
id : id,
tpl : $str
}
}
var blGalleryData = function(page) {
var blPAGEMODE = (PAGE_MODE == 'c') ? MODE : property.PUBLISH,
blPARENT = (PAGE_MODE == 'c') ? PARENT : property.PARENT,
blVIEW = (PAGE_MODE == 'c') ? VIEW : property.VIEW;
var r;
$.ajax({
url: '/template/gallery/bl_data/view/' + blVIEW,
data: { mode: blPAGEMODE, page: page, gacte_home: blPARENT.gcate_home },
dataType: 'json',
type: 'POST',
async: false,
cache: false,
success : function(data) {
checkError(data);
r = data;
}
},'json');
return r;
}
var blGalleryItemEmpty = function() {
var str = '\
\
';
return str;
}
var blGalleryItem = function(idx,obj) {
var blSID = (PAGE_MODE == 'c') ? SID : property.SID,
blONE = (PAGE_MODE == 'c') ? ONE : property.ONE,
blVIEW = (PAGE_MODE == 'c') ? VIEW : property.blVIEW,
blPAGEMODE = (PAGE_MODE == 'c') ? MODE : property.PUBLISH,
blRPATH = (PAGE_MODE == 'c') ? RESOURCE+'/'+blSID+'/' : property.RESOURCE+'/'+blSID+'/';
var gsettings = (typeof obj.gsettings != 'undefined' && obj.gsettings) ? $.parseJSON(obj.gsettings) : {},
imgPATH = (typeof gsettings.storage != 'undefined' && gsettings.storage) ? gsettings.storage : blRPATH,
s = ((obj.image).indexOf('[{') > -1 ) ? $.parseJSON(obj.image) : obj.image,
src = (typeof s[0]['file'] != 'undefined') ? getServeImage(s[0]['file'],"600",imgPATH) : getServeImage(obj.image,"600",imgPATH),
img_src = (typeof gsettings.storage != 'undefined' && gsettings.storage) ? gsettings.storage + '600/' + obj.image : blRPATH + '600/' + obj.image,
g_url = (blPAGEMODE == 'config' || blPAGEMODE == 'demo') ? '/'+CONFIG_URL+'config/page' : property.URL,
g_link = obj.page + '/view/' + obj.seq,
g_link_option = '',
blitem_active = (blVIEW == obj.seq) ? ' active' : '';
if(typeof gsettings['glink'] != 'undefined' && gsettings['glink']) {
var g_link = (checkBase64Encode(gsettings['glink'])) ? Base64.decode(gsettings['glink']) : gsettings['glink'],
g_link_target = gsettings['glink_target'],
glink_val = (g_link) ? makeLinkUrl(g_link, blONE, blVIEW) : '',
menu_list = (typeof MENULIST != 'undefined') ? MENULIST : property.MENULIST;
if(menu_list.indexOf(g_link.replace(/ /g,'-'))>-1) {
g_link_option = 'data-user-link="' + glink_val + '"';
g_link = glink_val;
} else if(g_link.match(/^\@/g)) {
g_link_option = 'attr-bookmark="' + g_link.replace(/^\@/g,'') + '"';
} else {
g_link_option = 'attr-link="' + g_link + '"';
}
if(g_link_target.length > 0 ) g_link_option += ' target="' + g_link_target + '"';
} else {
g_link = (g_url == '/') ? g_url + g_link : g_url + '/' + g_link;
}
var str = '\
\
';
return str;
}
var blGallery = function(page) {
var id = uniqID(),
r = blGalleryData(page),
bl_g_data = r.list,
bl_g_page = Number(r.page),
bl_g_end_page = Number(r.end_page),
bl_g_total = Number(r.total);
var str = '\
\
\
\
';
bl_g_data.forEach(function(o,i) {
str = str +'\
' + blGalleryItem(((bl_g_page*4)-4)+i,o) + '\
';
});
if(bl_g_data.length < 4) {
for(var i=0; i< (4-bl_g_data.length); i++) {
str = str + blGalleryItemEmpty();
}
}
str = str +'\
\
\
';
if(bl_g_page > 1) {
str = str + '\
\
';
} else {
str = str + '\
\
';
}
if(bl_g_page < bl_g_end_page) {
str = str + '\
\
';
} else {
str = str + '\
\
';
}
str = str + '\
';
return {
str: $(str),
page: bl_g_page,
end_page: bl_g_end_page,
total: bl_g_total
};
}
var blForum = function(d,wrap) {
var block_bg = $('html').css('background-color'),
css_str = htmlspecialchars_decode(d.elcss);
if($('.dsgn-body').find('#page-bottomlistcss').length > 0 ) $('.dsgn-body').find('#page-bottomlistcss').html(css_str);
else $('.dsgn-body').prepend('');
var blPAGE = (PAGE_MODE == 'c') ? PAGE : property.PAGE,
blVIEW = (PAGE_MODE == 'c') ? VIEW : property.VIEW;
var msny = (d.feature=='masonry') ? true : false;
wrap.addClass('element page-bottomlist ' + d.elname)
.attr('data-id', d.seq)
.attr('data-el','el_bottomlist')
.attr('data-name', d.elname)
.attr('data-msny', msny)
.attr('data-type', d.type)
.attr('data-type2', d.type2)
.attr('data-mode', d.mode)
.attr('data-width', d.folder);
wrap.html(htmlspecialchars_decode(d.eltag));
var view = wrap.find('[data-loop="true"]').attr('data-view');
if(typeof view == 'undefined') view = 10;
if(typeof $.cookie('forum_' + d.seq) != 'undefined' && $.cookie('forum_' + d.seq))
$.forum.init(d.seq,blPAGE,view,$.cookie('forum_' + d.seq),$.cookie('forum_'+ d.seq +'_sfl'),$.cookie('forum_'+ d.seq +'_stx'),$.cookie('forum_'+ d.seq +'_scate'));
else
$.forum.init(d.seq,blPAGE,view);
$('option').css('background-color',block_bg);
wrap.find('[data-id="' + blVIEW + '"]').closest('tr').addClass('active').siblings('tr').removeClass('active');
}
$(document).on('click','.bl-g-control', function(e){
if($(this).hasClass('empty')) return false;
var step = $(this).data('slide'),
page = $(this).data('page'),
bl_g = blGallery(Number(page));
$('.page-bottomlist.bl-gallery-wrap').html(bl_g.str);
changeBrokenImages($('.page-bottomlist.bl-gallery-wrap'));
});
$.bottomlist = {
init : function() {
var blSID = (PAGE_MODE == 'c') ? SID : property.SID,
blPARENT = (PAGE_MODE == 'c') ? PARENT : property.PARENT,
blPAGE = (PAGE_MODE == 'c') ? PAGE : property.PAGE;
if(typeof blSID == 'undefined' || !blSID) { console.log('blSID undefined'); return false; }
if(typeof blPARENT == 'undefined' || !blPARENT) { console.log('blPARENT undefined'); return false; }
if(typeof blPAGE == 'undefined' || !blPAGE) { console.log('blPAGE undefined'); return false; }
if(blPARENT.mode===null) { console.log('blPARENT.mode null'); return false; }
var blPARENT_SETTINGS = (typeof blPARENT.settings != 'undefined' && blPARENT.settings) ? jQuery.parseJSON(blPARENT.settings) : {},
blSETTINGS = (PAGE_MODE == 'c') ? SETTINGS : property.SETTINGS;
if(typeof blSETTINGS == 'undefined' || !blSETTINGS) blSETTINGS = {};
var checkUrl = blPAGE.split(','),
blTYPE = (checkUrl[0] == 'forum') ? 'F' : 'P',
blPID = blPARENT.pid,
blVIEW = (PAGE_MODE == 'c') ? VIEW : property.VIEW;
if(typeof blTYPE == 'undefined' || !blTYPE) { console.log('blTYPE undefined'); return false; }
if(typeof blPID == 'undefined' || !blPID) { console.log('blPID undefined'); return false; }
if(typeof blVIEW == 'undefined' || !blVIEW) { console.log('blVIEW undefined'); return false; }
$('.page-bottomlist').remove();
var blwrap = blWrap(blTYPE,blPARENT.mode,blVIEW),
$blwrap = $(blwrap.tpl);
if(blTYPE == 'F') $blwrap.addClass('el_bl');
$blwrap.append('');
if($('.el-footer').length) {
$lastEl = ($('.el-footer_ctrl').length > 0) ? $('.el-footer_ctrl') : $('.el-footer');
if(blVIEW && blPARENT.mode=='project') $lastEl.before($blwrap);
else $('.forum-view').append($blwrap);
} else {
$('.dsgn-body').append($blwrap);
}
$blwrap.removeAttr('style');
switch(blTYPE) {
case 'F' :
var getblForum = $.ajax({ url : '/template/element/type/get/seq/' + blPID, data: { use : 'bottomlist'}, dataType: 'json', type: 'POST', async: false, cache: false });
getblForum.then(function(data) {
checkError(data);
var d = data[0];
blForum(d,$blwrap);
});
break;
case 'P' :
$blwrap.addClass('bl-gallery-wrap');
var bl_g = blGallery(),
bl_g_html = bl_g.str;
$blwrap.html(bl_g_html);
changeBrokenImages($blwrap);
var g_color = (typeof $('.dsgn-body').attr('data-gcolor')!='undefined') ? $('.dsgn-body').attr('data-gcolor') : '';
if(g_color) {
//var checkCss = ($('.galProjectCss').text().indexOf('.galProjectBg svg') > -1) ? true : false;
var pr_rgba = hexToRgba(g_color),
galProjectCssStr = ($('.galProjectCss').length>0) ? $('.galProjectCss').text() : '';
galProjectCssStr += '.dsgn-body[data-gcolor="'+g_color+'"] .galProjectBg .bl-g-control svg {fill: rgba('+pr_rgba.r+','+pr_rgba.g+','+pr_rgba.b+',1);}\n\
.dsgn-body[data-gcolor="'+g_color+'"] .galProjectBg .bl-g-control.empty svg {fill: rgba('+pr_rgba.r+','+pr_rgba.g+','+pr_rgba.b+',0.4);}\n';
$('.galProjectCss').text(galProjectCssStr);
}
break;
default:
// console.log('TYPE default');
break;
}
// setHeight(pageHeight());
},
destory : function() {
var $obj = $('.page-bottomlist');
$obj.fadeOut('slow',function() {
$(this).remove();
});
}
}
}(jQuery));