/** * Wpfd * * We developed this code with our hearts and passion. * We hope you found it useful, easy to understand and to customize. * Otherwise, please feel free to contact us at contact@joomunited.com * * @package WP File Download * @copyright Copyright (C) 2013 JoomUnited (http://www.joomunited.com). All rights reserved. * @copyright Copyright (C) 2013 Damien Barrère (http://www.crac-design.com). All rights reserved. * @license GNU General Public License version 2 or later; http://www.gnu.org/licenses/gpl-2.0.html */ jQuery(document).ready(function($) { var table_tree = $('.wpfd-foldertree-mappa'); var table_hash = window.location.hash; var table_root_cat = $('.wpfd-content-mappa').data('category'); var table_cParents = {}; $(".wpfd-content-mappa").each(function(index ){ var table_topCat = $(this).data('category'); table_cParents[table_topCat] = {parent:0,term_id: table_topCat,name: $(this).find("h2").text()}; $(this).find(".wpfdcategory.catlink").each(function(index ){ var tempidCat = $(this).data('idcat'); table_cParents[tempidCat]= {parent:table_topCat,term_id:tempidCat,name: $(this).text()}; }) }) //load media tables $('.wpfd-content .mediaTable').mediaTable(); var tpltable_source = $("#wpfd-template-mappa").html(); var tpltable_sourcecategories = $("#wpfd-template-mappa-categories").html(); Handlebars.registerHelper('bytesToSize', function(bytes) { return bytes == 'n/a' ? bytes : bytesToSize(parseInt(bytes)); }); function table_initClick(){ $('.wpfd-content-mappa .catlink').click(function(e){ e.preventDefault(); table_load($(this).parents('.wpfd-content-mappa').data('category'),$(this).data('idcat')); }); } table_initClick(); table_hash = table_hash.replace('#',''); if (table_hash != '') { var hasha = table_hash.split('-'); var re = new RegExp("^(p[0-9]+)$"); var page = null; var stringpage = hasha.pop(); if (re.test(stringpage)) { page = stringpage.replace('p',''); } var hash_category_id = hasha[0]; if(!parseInt(hash_category_id)){ return; } setTimeout(function () { table_load($('.wpfd-content-mappa').data('category'), hash_category_id, page); },100) } function table_load(sourcecat,category, page){ var pathname = window.location.pathname; $(".wpfd-content-multi[data-category="+sourcecat+"]").find('#current_category').val(category); $(".wpfd-content-multi[data-category="+sourcecat+"]").next('.wpfd-pagination').remove(); $(".wpfd-content-multi[data-category="+sourcecat+"] table tbody").empty(); $(".wpfd-content-multi[data-category="+sourcecat+"] table").after($('#wpfd-loading-wrap').html()); $(".wpfd-content-multi[data-category="+sourcecat+"] .wpfd-categories").empty(); //Get categories $.ajax({ url: wpfdTableTheme.ajaxurl+"action=wpfd&task=categories.display&view=categories&id="+category+"&top="+sourcecat, dataType : "json" }).done(function(categories) { if (page !=null) { window.history.pushState('', document.title, pathname + '#'+category+'-'+categories.category.slug+'-p' + page ); } else { window.history.pushState('', document.title, pathname + '#'+category+'-'+categories.category.slug ); } $(".wpfd-content-multi[data-category="+sourcecat+"]").find('#current_category_slug').val(categories.category.slug); var template = Handlebars.compile(tpltable_sourcecategories); var html = template(categories); $(".wpfd-content-multi[data-category="+sourcecat+"] .wpfd-categories").prepend(html); if (table_tree.length) { table_tree.find('li').removeClass('selected'); table_tree.find('i.md').removeClass('md-folder-open').addClass("md-folder"); table_tree.jaofiletree('open', category); var el = table_tree.find('a[data-file="'+category+'"]').parent(); el.find(' > i.md').removeClass("md-folder").addClass("md-folder-open"); if (!el.hasClass('selected') ) { el.addClass('selected'); } } //Get files $.ajax({ url: wpfdTableTheme.ajaxurl+"action=wpfd&task=files.display&view=files&id="+category+"&rootcat="+table_root_cat+"&page=" + page, dataType : "json" }).done(function(content) { // $.extend(content,categories); $(".wpfd-content-multi[data-category="+sourcecat+"]").after(content.pagination); delete content.pagination; var template_table = Handlebars.compile(tpltable_source); var html = template_table(content); //html = $('