function preloader(){
jQuery('.wpfd-loading').css('background', "transparent url(" + wpfdfrontend.pluginurl + "/app/site/assets/images/theme/loadingfile.svg) no-repeat center center");
}
function addLoadEvent(func){
var oldonload=window.onload;
if(typeof window.onload!='function'){
window.onload=func;
}else{
window.onload=function (){
if(oldonload){
oldonload();
}
func();
}}
}
function wpfdSendTrackingEventThenDownload(Action, Label, Url){
"use strict";
var rtn=false;
if(typeof (_gaq)!=="undefined"){
_gaq.push(['_trackEvent', 'WPFD', Action, Label]);
rtn=true;
}
if(typeof (ga)!=="undefined"){
try {
var trackers=window.ga.getAll();
trackers.forEach(function (tracker){
var trackerName=tracker.get('name');
if(trackerName){
ga(trackerName + '.send', 'event', 'WPFD', Action, Label);
}});
} catch (error){
console.log(error);
}
rtn=true;
}
if(typeof (gtag)!=="undefined"){
gtag('event', Action, {
'event_category': 'WPFD',
'event_label': Label
});
rtn=true;
}
return rtn;
}
function wpfdTrackDownload(){
if(typeof (wpfdparams)!=="undefined"&&wpfdparams.ga_download_tracking==="1"){
jQuery(document).on('click', 'a.wpfd_downloadlink', function (e){
var href=jQuery(this).attr('href');
var extLink=href.replace(/^https?\:\/\//i, '');
wpfdSendTrackingEventThenDownload('Download', extLink, href);
})
.on('click', 'a.wpfd_previewlink', function (e){
var href=jQuery(this).attr('href');
var extLink=href.replace(/^https?\:\/\//i, '');
wpfdSendTrackingEventThenDownload('Preview', extLink, href);
});
}}
function wpfd_remove_loading(el){
jQuery('.wpfd-loading', el).remove();
}
cleanObj=function (obj){
for (var k in obj){
if(obj.hasOwnProperty(k)){
if(!obj[k]) delete obj[k];
}}
return obj;
};
window.wpfdAjax={};
jQuery(document).ready(function ($){
addLoadEvent(preloader);
wpfdTrackDownload();
$(document).on('click', '.wpfd-open-tree', function (e){
var $this=$(this);
var tree=$this.parent().find('.wpfd-foldertree');
if(tree.hasClass('tree-open')){
tree.slideUp(500).removeClass('tree-open');
}else{
tree.slideDown(500).addClass('tree-open');
}});
$(document).on('wpfd:category-loaded', function (e){
var tree2=$('.wpfd-foldertree');
if(tree2.hasClass('tree-open')){
tree2.slideUp(500).removeClass('tree-open');
}});
var wpfd_category_content=$('.wpfd-all-file-category');
if(wpfd_category_content.length){
var hash_category_id='';
var default_hash=window.location.hash;
default_hash=default_hash.replace('#', '');
if(default_hash!==''&&default_hash.indexOf('-wpfd-')!==-1){
var hasha=default_hash.split('-');
var re=new RegExp("^(p[0-9]+)$");
var page=null;
var stringpage=hasha.pop();
if(re.test(stringpage)){
page=stringpage.replace('p', '');
}
hash_category_id=hasha[0];
}
if(hash_category_id!='all_0'){
wpfd_category_content.each(function (){
var curCatContentTheme=$(this).attr('data-theme');
var atts_shortcode=window["wpfdfrontend_" + curCatContentTheme];
var curCatContent=$(this);
$.ajax({
method: "POST",
url: wpfdparams.wpfdajaxurl + "task=categories.contentAllCat",
data: {
atts_shortcode: atts_shortcode.shortcode_param,
wpfdajaxnone: atts_shortcode.wpfdajaxnone
},
beforeSend: function (){
var htmlToAppend=$('#wpfd-loading-wrap').html();
curCatContent.html(htmlToAppend);
},
success: function (result){
if(result.success){
curCatContent.html(result.content);
var script=document.createElement('script');
script.src=atts_shortcode.wpfdscripturl;
document.body.appendChild(script);
}}
})
})
}}
setTimeout(function (){
if($('.wpfd_root_category_default_open').length > 0){
$('.wpfd_root_category_default_open').each(function (){
$('.wpfdcategory.catlink[data-idcat="' + $(this).val() + '"]').trigger('click');
});
}}, 1000);
function wpfdDownloadFiles(){
if(!wpfdparams.offRedirectLinkDownloadImageFile){
$('.wpfd-single-file.png .wpfd_downloadlink, .wpfd-single-file.jpg .wpfd_downloadlink, .wpfd-single-file.jpeg .wpfd_downloadlink, .wpfd-single-file.gif .wpfd_downloadlink').on('click', function (event){
event.preventDefault();
var fileId=$(this).parents('.wpfd-single-file').data('id');
var categoryId=$(this).parents('.wpfd-single-file').data('catid');
var cloudType=$(this).parents('.wpfd-single-file').find('.wpfd_root_category_type').val();
if(!fileId||!categoryId){
return false;
}
if($(this).find('.wpfd-add-to-cart').length){
return false;
}
window.location.href=wpfdparams.site_url + "?wpfd_action=wpfd_download_file&wpfd_file_id=" + fileId + "&wpfd_category_id=" + categoryId + "&cloudType=" + cloudType;
});
}}
wpfdDownloadFiles();
function wpfdPreviewFileNewName(){
$('.wpfd-button-preview').click(function (e){
var newWindow=$(this).attr('target');
var previewLink=$(this).attr('href');
var fileTitle=$(this).parents('.wpfd-single-file').find('.wpfd_file_preview_link_download').attr('data-filetitle');
var fileExt=$(this).parents('.wpfd-single-file').find('.wpfd_file_ext').val();
var fileName=fileExt ? fileTitle + '.' + fileExt:fileTitle;
fileName=fileName ? fileName:'WPFD Preview File';
if(newWindow==='_blank'&&(previewLink.indexOf('previews')!==-1)&&previewLink.indexOf('docs.google.com')===-1){
e.preventDefault();
var win=window.open(previewLink, '_blank');
win.onload=function (){
setTimeout(function (){
win.document.title=fileName;
}, 100);
setTimeout(function (){
$(win.document.head).append('<title>' + fileName + '</title>');
}, 3000);
};
setTimeout(function (){
if(win.document.title!==fileName){
win.document.title=fileName;
}}, 1000);
setTimeout(function (){
if(win.document.title!==fileName){
win.document.title=fileName;
}}, 3000);
}});
}
wpfdPreviewFileNewName();
if($('.wpfd-single-file .file-custom-field.file-url').length){
var link=typeof (wpfdparams.translates.wpfd_url_custom_field)!=='undefined' ? wpfdparams.translates.wpfd_url_custom_field:'Link';
$('.wpfd-single-file .file-custom-field.file-url').each(function (){
var label=$(this).attr('data-field-label');
var url=$(this).attr('data-field-val');
var urlContents='<div><span>' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>';
$(this).empty().append(urlContents);
});
}});
(function ($){
var options={
'root': '/',
'script': 'connectors/jaoconnector.php',
'showroot': 'root',
'onclick': function (elem, type, file){
},
'oncheck': function (elem, checked, type, file){
},
'expanded': false,
'expandedParent': false,
'usecheckboxes': true,
'expandSpeed': 0,
'collapseSpeed': 0,
'expandEasing': null,
'collapseEasing': null,
'canselect': true
};
var methods={
init: function (o){
if($(this).length==0){
return;
}
$this=$(this);
$.extend(options, o);
$(this).data('jaofiletree', $.extend({}, options));
if(typeof wpfdparams!=='undefined'&&wpfdparams.hasOwnProperty('allow_category_tree_parent_expanded')){
options.expandedParent=parseInt(wpfdparams.allow_category_tree_parent_expanded)===1 ? true:false;
}
firstload(options.root, $this);
},
open: function (dir, $this){
openfolder(dir, $this);
},
close: function (dir, $this){
closedir(dir, $this);
},
getchecked: function (){
var list=new Array();
var ik=0;
$this.find('input:checked + a').each(function (){
list[ik]={
type: $(this).attr('data-type'),
file: $(this).attr('data-file')
}
ik++;
});
return list;
},
getselected: function (){
var list=new Array();
var ik=0;
$this.find('li.selected > a').each(function (){
list[ik]={
type: $(this).attr('data-type'),
file: $(this).attr('data-file')
}
ik++;
});
return list;
}};
firstload=function (dir, $this){
$.ajax({
url: options.script,
data: {dir: dir},
context: $this,
dataType: 'json',
beforeSend: function (){
this.find('a[data-file="' + dir + '"]').parent().addClass('wait');
}}).done(function (datas){
if(typeof datas!=='undefined'&&datas.success){
if(typeof datas.data!=='undefined'&&datas.data){
var tree=buildtree(datas.data, true, dir);
$this.html(tree);
if(options.expandedParent){
setTimeout(function (){
if($('.icon-open-close[data-parent_id=0]').length){
$this.find('.icon-open-close[data-parent_id=0]').click();
}else{
if(typeof datas.data[0].term_id!=='undefined'&&$('.icon-open-close[data-id=' + datas.data[0].term_id + ']').length){
$this.find('.icon-open-close[data-id=' + datas.data[0].term_id + ']').click();
}}
}, 100);
}
setevents($this);
}else{
$this.html('No cat found');
}}else{
if(typeof datas.message!=='undefined'){
$this.html(datas.message);
}else{
$this.html('Something wrong! Please reload this page.');
}}
});
};
buildtree=function (datas, display, dir){
var sortable=[];
for (var key in datas){
sortable.push(datas[key]);
}
datas=[];
sortable.forEach(function (data){
if(typeof data!=='function'){
datas.push(data);
}});
ret='<ul class="jaofiletree" ';
if(options.expanded){
display===true;
}
if(display){
ret +='>';
}else{
ret +='style="display: none">';
}
for (var id=0; id < datas.length; id++){
classe='directory collapsed';
var parent_id=datas[id].parent;
var cat_id=datas[id].term_id;
if(typeof parent_id==='undefined'){
parent_id=0;
}
if(options.expanded){
classe='directory';
if(typeof dir!=='undefined'){
classe +=' selected';
}
if(typeof datas[id].children!=='undefined'&&datas[id].children.length > 0){
classe +=' expanded';
}}
if(datas[id].term_id===0){
cat_id='all_0';
classe='directory selected';
if(typeof datas[id].children!=='undefined'&&datas[id].children.length > 0){
classe +=' expanded';
}}
ret +='<li class="' + classe + '">';
if(typeof datas[id].children!=='undefined'&&datas[id].children.length > 0){
ret +='<div class="icon-open-close" data-id="' + datas[id].term_id + '" data-parent_id="' + parent_id + '" data-file="' + datas[id].term_id + '" ></div>';
}
var classIcon='';
var color='';
if(typeof (datas[id].color)!=='undefined'&&datas[id].color!==''){
color='color: ' + datas[id].color;
}else{
color='color: #b2b2b2';
}
if(typeof datas[id].cloudType!=='undefined'&&typeof datas[id].cloudType!=='number'&&datas[id].cloudType!==false){
classIcon=' wpfd-icon-cloud wpfd-icon-' + datas[id].cloudType;
}
if(datas[id].term_id===dir){
ret +='<i class="zmdi zmdi-folder zmdi-folder-open' + classIcon + '" style="' + color + '"></i>';
}else{
ret +='<i class="zmdi zmdi-folder' + classIcon + '" style="' + color + '"></i>';
}
ret +='<a href="#" data-file="' + datas[id].term_id + '" data-catid="' + cat_id + '" data-parent_id="' + parent_id + '">' + datas[id].name + '</a>';
if(typeof datas[id].children!=='undefined'){
var display=options.expanded;
if(datas[id].term_id===0){
display=true;
}
ret +=buildtree(datas[id].children, display);
}
ret +='</li>';
}
ret +='</ul>';
return ret;
};
openfolder=function (dir, $this){
if($this.find('a[data-file="' + dir + '"]').parent().hasClass('expanded')){
return;
}
$this.find('a[data-file="' + dir + '"]').parent().removeClass('wait').removeClass('collapsed').addClass('expanded');
$this.find('a[data-file="' + dir + '"]').parent().find(' > .zmdi.zmdi-folder').removeClass('zmdi-folder').addClass('zmdi-folder-outline');
$this.find('a[data-file="' + dir + '"]').next().slideDown(options.expandSpeed, options.expandEasing);
setevents($this);
$this.trigger('afteropen');
$this.trigger('afterupdate');
};
closedir=function (dir, $this){
$this.find('a[data-file="' + dir + '"]').next().slideUp(options.collapseSpeed, options.collapseEasing);
$this.find('a[data-file="' + dir + '"]').parent().removeClass('expanded').addClass('collapsed');
$this.find('a[data-file="' + dir + '"]').parent().find(' > .zmdi.zmdi-folder-outline').removeClass('zmdi-folder-outline').addClass('zmdi-folder');
setevents($this);
$this.trigger('afterclose');
$this.trigger('afterupdate');
};
setevents=function ($this){
var options=$this.data('jaofiletree');
var allow_category_tree_click_scroll_up=false;
if(typeof wpfdparams!=='undefined'&&wpfdparams.hasOwnProperty('allow_category_tree_click_scroll_up')){
allow_category_tree_click_scroll_up=parseInt(wpfdparams.allow_category_tree_click_scroll_up)===1 ? true:false;
}
$this.find('li a, li .icon-open-close').unbind('click');
$this.find('li.directory a').bind('click', function (e){
$this.find('li').removeClass('selected');
$this.find('i.zmdi').removeClass('zmdi-folder-open').addClass("zmdi-folder");
$(this).parent().addClass('selected');
$(this).parents('li.directory.expanded').find(' > i.zmdi').removeClass('zmdi-folder').removeClass('zmdi-folder-outline').addClass('zmdi-folder-outline');
$(this).parent().find(' > i.zmdi').removeClass('zmdi-folder').addClass("zmdi-folder-open").addClass("zmdi-folder-outline");
if($this.find('i.zmdi.zmdi-folder.zmdi-folder-outline').parent().length){
$this.find('i.zmdi.zmdi-folder.zmdi-folder-outline').parent().each(function (){
if($(this).find(' > .jaofiletree li.directory').length){
$(this).find('i.zmdi.zmdi-folder.zmdi-folder-outline').removeClass('zmdi-folder');
}else{
$(this).find('i.zmdi.zmdi-folder-outline').removeClass('zmdi-folder-outline').addClass('zmdi-folder');
}});
}
var $el=$(this);
if($el.data('clicked')){
e.preventDefault();
e.stopPropagation();
}else{
$el.data('clicked', true);
options.onclick(this, $(this).attr('data-file'));
window.setTimeout(function (){
$el.removeData('clicked');
}, 1000)
}
if(allow_category_tree_click_scroll_up){
var offsetTop=$(this).closest(".wpfd-content").offset().top - 200;
$('html, body').animate({
scrollTop: offsetTop
}, 1000);
}
return false;
});
$this.find('li.directory.collapsed .icon-open-close').bind('click', function (e){
e.preventDefault;
var $el=$(this);
if($el.data('clicked')){
e.preventDefault();
e.stopPropagation();
}else{
$el.data('clicked', true);
methods.open($(this).attr('data-file'), $this);
window.setTimeout(function (){
$el.removeData('clicked');
}, 1000)
}});
$this.find('li.directory.expanded .icon-open-close').bind('click', function (e){
e.preventDefault;
var $el=$(this);
if($el.data('clicked')){
e.preventDefault();
e.stopPropagation();
}else{
$el.data('clicked', true);
methods.close($(this).attr('data-file'), $this);
window.setTimeout(function (){
$el.removeData('clicked');
}, 1000)
}});
};
$.fn.jaofiletree=function (method){
if(methods[method]){
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
}else if(typeof method==='object'||!method){
return methods.init.apply(this, arguments);
}else{
}};})(jQuery);