1/** 2 * WP File Download 3 * 4 * @package WP File Download 5 * @author Joomunited 6 * @version 1.0 7 */ 8function preloader() { 9 jQuery('.wpfd-loading').css('background', "transparent url(" + wpfdfrontend.pluginurl + "/app/site/assets/images/theme/loadingfile.svg) no-repeat center center"); 10} 11 12function addLoadEvent(func) { 13 var oldonload = window.onload; 14 if (typeof window.onload != 'function') { 15 window.onload = func; 16 } else { 17 window.onload = function () { 18 if (oldonload) { 19 oldonload(); 20 } 21 func(); 22 } 23 } 24} 25 26function wpfdSendTrackingEventThenDownload(Action, Label, Url) { 27 "use strict"; 28 var rtn = false; 29 if (typeof (_gaq) !== "undefined") { 30 _gaq.push(['_trackEvent', 'WPFD', Action, Label]); 31 rtn = true; 32 } 33 34 if (typeof (ga) !== "undefined") { 35 try { 36 var trackers = window.ga.getAll(); 37 // Send event to all trackers 38 trackers.forEach(function (tracker) { 39 var trackerName = tracker.get('name'); 40 if (trackerName) { 41 ga(trackerName + '.send', 'event', 'WPFD', Action, Label); 42 } 43 }); 44 } catch (error) { 45 console.log(error); 46 } 47 rtn = true; 48 } 49 50 if (typeof (gtag) !== "undefined") { 51 gtag('event', Action, { 52 'event_category': 'WPFD', 53 'event_label': Label 54 }); 55 rtn = true; 56 } 57 58 return rtn; 59} 60 61function wpfdTrackDownload() { 62 if (typeof (wpfdparams) !== "undefined" && wpfdparams.ga_download_tracking === "1") { 63 jQuery(document).on('click', 'a.wpfd_downloadlink', function (e) { 64 var href = jQuery(this).attr('href'); 65 var extLink = href.replace(/^https?\:\/\//i, ''); 66 67 wpfdSendTrackingEventThenDownload('Download', extLink, href); 68 }) 69 70 //run below code when open preview on new tab 71 .on('click', 'a.wpfd_previewlink', function (e) { 72 var href = jQuery(this).attr('href'); 73 var extLink = href.replace(/^https?\:\/\//i, ''); 74 75 wpfdSendTrackingEventThenDownload('Preview', extLink, href); 76 }); 77 } 78} 79 80function wpfd_remove_loading(el) { 81 jQuery('.wpfd-loading', el).remove(); 82} 83 84// Remove property with empty value 85cleanObj = function (obj) { 86 for (var k in obj) { 87 if (obj.hasOwnProperty(k)) { 88 if (!obj[k]) delete obj[k]; 89 } 90 } 91 return obj; 92}; 93 94window.wpfdAjax = {}; 95jQuery(document).ready(function ($) { 96 addLoadEvent(preloader); 97 wpfdTrackDownload(); 98 $(document).on('click', '.wpfd-open-tree', function (e) { 99 var $this = $(this); 100 var tree = $this.parent().find('.wpfd-foldertree'); 101 102 // tree.toggleClass('tree-open'); 103 if (tree.hasClass('tree-open')) { 104 tree.slideUp(500).removeClass('tree-open'); 105 } else { 106 tree.slideDown(500).addClass('tree-open'); 107 } 108 }); 109 $(document).on('wpfd:category-loaded', function (e) { 110 var tree2 = $('.wpfd-foldertree'); 111 // Hide all opened left tree 112 if (tree2.hasClass('tree-open')) { 113 tree2.slideUp(500).removeClass('tree-open'); 114 } 115 }); 116 117 // wpfd_list 118 var wpfd_category_content = $('.wpfd-all-file-category'); 119 if (wpfd_category_content.length) { 120 var hash_category_id = ''; 121 var default_hash = window.location.hash; 122 default_hash = default_hash.replace('#', ''); 123 if (default_hash !== '' && default_hash.indexOf('-wpfd-') !== -1) { 124 var hasha = default_hash.split('-'); 125 var re = new RegExp("^(p[0-9]+)$"); 126 var page = null; 127 var stringpage = hasha.pop(); 128 129 if (re.test(stringpage)) { 130 page = stringpage.replace('p', ''); 131 } 132 133 hash_category_id = hasha[0]; 134 } 135 136 if (hash_category_id != 'all_0') { 137 wpfd_category_content.each(function () { 138 var curCatContentTheme = $(this).attr('data-theme'); 139 var atts_shortcode = window["wpfdfrontend_" + curCatContentTheme]; 140 var curCatContent = $(this); 141 $.ajax({ 142 method: "POST", 143 url: wpfdparams.wpfdajaxurl + "task=categories.contentAllCat", 144 data: { 145 atts_shortcode: atts_shortcode.shortcode_param, 146 wpfdajaxnone: atts_shortcode.wpfdajaxnone 147 }, 148 beforeSend: function () { 149 var htmlToAppend = $('#wpfd-loading-wrap').html(); 150 curCatContent.html(htmlToAppend); 151 }, 152 success: function (result) { 153 if (result.success) { 154 curCatContent.html(result.content); 155 156 var script = document.createElement('script'); 157 script.src = atts_shortcode.wpfdscripturl; 158 document.body.appendChild(script); 159 } 160 } 161 }) 162 }) 163 } 164 } 165 166 167 setTimeout(function () { 168 if ($('.wpfd_root_category_default_open').length > 0) { 169 $('.wpfd_root_category_default_open').each(function () { 170 $('.wpfdcategory.catlink[data-idcat="' + $(this).val() + '"]').trigger('click'); 171 }); 172 } 173 }, 1000); 174 175 function wpfdDownloadFiles() { 176 if (!wpfdparams.offRedirectLinkDownloadImageFile) { 177 $('.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) { 178 event.preventDefault(); 179 var fileId = $(this).parents('.wpfd-single-file').data('id'); 180 var categoryId = $(this).parents('.wpfd-single-file').data('catid'); 181 var cloudType = $(this).parents('.wpfd-single-file').find('.wpfd_root_category_type').val(); 182 183 if (!fileId || !categoryId) { 184 return false;
185 } 186 187 if ($(this).find('.wpfd-add-to-cart').length) { 188 return false; 189 } 190 191 window.location.href = wpfdparams.site_url + "?wpfd_action=wpfd_download_file&wpfd_file_id=" + fileId + "&wpfd_category_id=" + categoryId + "&cloudType=" + cloudType; 192 }); 193 } 194 } 195 196 wpfdDownloadFiles(); 197 198 function wpfdPreviewFileNewName() { 199 $('.wpfd-button-preview').click(function (e) { 200 var newWindow = $(this).attr('target'); 201 var previewLink = $(this).attr('href'); 202 var fileTitle = $(this).parents('.wpfd-single-file').find('.wpfd_file_preview_link_download').attr('data-filetitle'); 203 var fileExt = $(this).parents('.wpfd-single-file').find('.wpfd_file_ext').val(); 204 var fileName = fileExt ? fileTitle + '.' + fileExt : fileTitle; 205 fileName = fileName ? fileName : 'WPFD Preview File'; 206 207 if (newWindow === '_blank' && (previewLink.indexOf('previews') !== -1) && previewLink.indexOf('docs.google.com') === -1) { 208 e.preventDefault(); 209 var win = window.open(previewLink, '_blank'); 210 win.onload = function () { 211 setTimeout(function () { 212 win.document.title = fileName; 213 }, 100); 214 215 setTimeout(function () { 216 $(win.document.head).append('<title>' + fileName + '</title>'); 217 }, 3000); 218 }; 219 220 setTimeout(function () { 221 if (win.document.title !== fileName) { 222 win.document.title = fileName; 223 } 224 }, 1000); 225 226 setTimeout(function () { 227 if (win.document.title !== fileName) { 228 win.document.title = fileName; 229 } 230 }, 3000); 231 } 232 }); 233 } 234 235 wpfdPreviewFileNewName(); 236 237 if ($('.wpfd-single-file .file-custom-field.file-url').length) { 238 var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link'; 239 $('.wpfd-single-file .file-custom-field.file-url').each(function () { 240 var label = $(this).attr('data-field-label'); 241 var url = $(this).attr('data-field-val'); 242 var urlContents = '<div><span>
242' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>'; 243 $(this).empty().append(urlContents); 244 }); 245 } 246}); 247
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.