1var wpfdColorboxInit; 2var loading; 3jQuery(document).ready(function ($) { 4 var videoTypes = ['m4a', 'mp4', 'webm', 'ogg', 'ogv', 'flv']; 5 var audioTypes = ['mp3', 'wav', 'wma', 'm4a']; 6 var imageTypes = ['jpg', 'png', 'gif', 'jpeg', 'jpe', 'bmp', 'ico', 'tiff', 'tif', 'svg', 'svgz']; 7 (wpfdColorboxInit = function () { 8 // $('.wpfdlightbox').colorbox({iframe:true, innerWidth:'90%', innerHeight:'90%',maxWidth:'90%',maxHeight:'90%'}); 9 $('.wpfdlightbox').each(function () { 10 var filetype = $(this).data('file-type'); 11 var previewLink = $(this).prop('href'); 12 sW = $(window).width(); 13 sH = $(window).height(); 14 sR = sW / sH; 15 $(this).unbind('click').click(function (e) { 16 e.preventDefault(); 17 fileid = $(this).data('id'); 18 catid = $(this).data('catid'); 19 downloadLink = wpfdcolorbox.wpfdajaxurl + 'action=wpfd&task=file.download&wpfd_category_id=' + catid + '&wpfd_file_id=' + fileid + '&preview=1'; 20 21 if ($(this).hasClass('wpfd_previewlink')) { 22 var href = jQuery(this).attr('href'); 23 // var href = decodeURIComponent(jQuery(this).attr('href')); 24 // href = href.replace('docs.google.com/viewer?url=', ''); 25 var extLink = href.replace(/^https?\:\/\//i, ''); 26 27 if (typeof (_gaq) !== 'undefined') { 28 _gaq.push(['_trackEvent', 'WPFD', 'Preview', extLink]); 29 } else if (typeof (ga) !== "undefined") { 30 ga('send', 'event', 'WPFD', 'Preview', extLink); 31 } 32 } 33 if (typeof fileid == 'string') { 34 while (fileid.indexOf(':') > -1) { 35 fileid = fileid.replace(':', '-'); 36 } 37 } 38 html = '<div class="dropblock">'; 39 html +=' <a href="#" id="wpfd-dropblock-close"><span class="dashicons dashicons-dismiss"></span></a>'; 40 if (audioTypes.indexOf(filetype) > -1) { //is audio 41 html += '<audio class="video-js vjs-default-skin" id="player-' + fileid + '" controls autoplay> '; 42 html += '<source src="' + downloadLink + '" type="audio/' + filetype + '">'; 43 html += ' <p class="vjs-no-js">Your browser does not support the <code>audio</code> element.</p></audio>'; 44 } else if (imageTypes.indexOf(filetype) > -1) { //is image 45 html += '<img src="' + downloadLink + '" class="video-js vjs-default-skin" id="player-' + fileid + '" /> '; 46 } else if (videoTypes.indexOf(filetype) > -1) { 47 html += '<video width="1000" height="1000" class="video-js vjs-default-skin" id="player-' + fileid + '" controls="controls" preload="auto" autoplay="true">'; 48 html += '<p class="vjs-no-js">Your browser does not support the <code>video</code> element.</p>'; 49 html += '<source src="' + downloadLink + '" type="video/'+filetype+'">'; 50 html += '</video>'; 51 } else if (previewLink.includes('file.preview') || previewLink.includes('/previews/') || previewLink.includes('/watermark/')) { 52 html += '<div style="display: block;width: 600px; height: 90vh;overflow-y: auto">'; 53 html += '<img src="' + previewLink + '" class="video-js vjs-default-skin" id="player-' + fileid + '" /> '; 54 html += '</div>' 55 } else { //other type 56 viewlink = $(this).attr('href'); 57 //googleViewer = 'https://docs.google.com/viewer?url='+ encodeURIComponent(encodeURI(viewlink))+'&embedded=true'; 58 html += '<iframe mozallowfullscreen="true" webkitallowfullscreen="true" allowfullscreen="true" class="cboxIframe" src="' + viewlink + '" frameborder="0"></iframe>'; 59 } 60 html += '</div>'; 61 //loader init 62 loader = $("#wpfd-box-loading"); 63 if (loader.length === 0) { 64 $('body').append('<div id="wpfd-box-loading" style="display: none;"><div class="loading"></div></div>'); 65 loader = $("#wpfd-box-loading"); 66 } 67 loader.show(); 68 69 $(document).unbind('click', '#wpfd-box-loading, .wpfd-loading-close').on('click', '#wpfd-box-loading, .wpfd-loading-close', function () { 70 $("#wpfd-box-loading").remove(); 71 }); 72 73 var timeout = 5000; // After 5s display waiting notify 74 // Set time out to display close notification 75 loading = setTimeout(function() { 76 var currentLoading = $('#wpfd-box-loading'); 77 if (currentLoading.length > 0) { 78 $('.wpfd-loading-status', currentLoading).remove(); 79 var status = $('<div class="wpfd-loading-status" style="text-align:center;">' + wpfdcolorboxvars.preview_loading_message + '</div>'); 80 currentLoading.append(status); 81 } 82 }, timeout); 83 84 //player box init 85 pBox = $("#wpfd-box-player"); 86 if (pBox.length === 0) { 87 $('body').append('<div id="wpfd-box-player" style="display: none;"></div>'); 88 pBox = $("#wpfd-box-player"); 89 } 90 pBox.hide(); 91 pBox.empty(); 92 pBox.prepend(html); 93 94 $('#wpfd-dropblock-close').click(function(e) { 95 e.preventDefault(); 96 pBox.hide();
97 if($("#player-"+fileid).length) { 98 myPlayer = videojs("player-"+fileid); 99 myPlayer.dispose(); 100 } 101 }); 102 103 pBox.click(function (e) { 104 if ($(e.target).is('#wpfd-box-player')) { 105 pBox.hide(); 106 if ($("#player-" + fileid).length) { 107 myPlayer = videojs("player-" + fileid); 108 myPlayer.dispose(); 109 } 110 } 111 $('#wpfd-box-player').unbind('click.box').bind('click.box', function (e) { 112 if ($(e.target).is('#wpfd-box-player')) { 113 pBox.hide(); 114 } 115 }); 116 }); 117 118 //player 119 if (imageTypes.indexOf(filetype) > -1 || previewLink.includes('file.preview') || previewLink.includes('/previews/')) { //is image 120 new_img = new Image(); 121 new_img.onload = function () { 122 var img_width = this.width, 123 img_heigth = this.height; 124 vR = img_width / img_heigth; 125 if (vR > sR) { 126 new_vW = parseInt(sW * 0.9); 127 new_vH = parseInt(new_vW / vR); 128 } else { 129 new_vH = parseInt(sH * 0.9); 130 new_vW = parseInt(new_vH * vR); 131 } 132 133 if (new_vW > img_width && new_vH > img_heigth) { 134 new_vW = img_width; 135 new_vH = img_heigth; 136 } 137 138 // $("#player-" + fileid).css('width', new_vW); 139 // $("#player-" + fileid).css('height', new_vH); 140 $("#player-" + fileid).css('width', '100%'); 141 $("#player-" + fileid).css('maxHeight', 'unset'); 142 // $("#player-" + fileid).css('height', 'auto'); 143 // centerDropblock(fileid, new_vH / 2, new_vW / 2); 144 loader.hide(0, function(){ 145 clearTimeout(loading); 146 }); 147 pBox.show(); 148 149 } 150 if (previewLink.includes('file.preview') || previewLink.includes('/previews/')) { 151 new_img.src = previewLink; 152 } else { 153 new_img.src = downloadLink; 154 } 155 } else if (videoTypes.indexOf(filetype) > -1 || (audioTypes.indexOf(filetype) > -1)) { // video or audio 156 videojs("player-" + fileid, {}, function () { 157 // Player (this) is initialized and ready. 158 var myPlayer = this; 159 if (audioTypes.indexOf(filetype) > -1) { //is audio 160 new_vW = 350; 161 new_vH = 60; 162 myPlayer.dimensions(new_vW, new_vH); 163 // centerDropblock(fileid, new_vH / 2, new_vW / 2); 164 loader.hide(0, function(){ 165 clearTimeout(loading); 166 }); 167 pBox.show(); 168 169 } else { //is video 170 171 myPlayer.on('loadedmetadata', function () { 172 173 var v = document.getElementById('player-' + fileid + '_html5_api'); 174 vW = v.videoWidth; 175 vH = v.videoHeight; 176 vR = vW / vH; 177 if (vR > sR) { 178 new_vW = parseInt(sW * 0.9); 179 new_vH = parseInt(new_vW / vR); 180 } else { 181 new_vH = parseInt(sH * 0.9); 182 new_vW = parseInt(new_vH * vR); 183 } 184 185 myPlayer.dimensions(new_vW, new_vH); 186 // centerDropblock(fileid, new_vH / 2, new_vW / 2); 187 loader.hide(0, function(){ 188 clearTimeout(loading); 189 }); 190 pBox.show(); 191 }); 192 193 } 194 195 //error handling 196 myPlayer.on('error', function () { // error event listener 197 // dispose the old player and its HTML 198 error = myPlayer.error(); 199
200 myPlayer.dispose(); 201 pBox.empty(); 202 pBox.prepend('<div class="dropblock">' + error.message + '</div>'); 203 204 new_vW = 300; 205 new_vH = 200; 206 var dropblock = pBox.find('.dropblock'); 207 dropblock.css('width', new_vW).css('height', new_vH); 208 // dropblock.css('margin-top', (-new_vH / 2) + 'px').css('margin-left', (-new_vW / 2) + 'px'); 209 loader.hide(0, function(){ 210 clearTimeout(loading); 211 }); 212 pBox.show(); 213 }) 214 }); 215 216 } else { //other type => use googler viewer 217 218 new_vW = sW * 0.9; 219 new_vH = sH * 0.9; 220 var dropblock = pBox.find('.dropblock'); 221 dropblock.css('width', new_vW).css('height', new_vH); 222 // dropblock.css('margin-top', (-new_vH / 2) + 'px').css('margin-left', (-new_vW / 2) + 'px'); 223 224 $('.dropblock iframe').on('load', function () { 225 loader.hide(0, function(){ 226 clearTimeout(loading); 227 }); 228 pBox.show(); 229 }) 230 } 231 }); 232 }); 233 })(); 234 235 centerDropblock = function (fileid, margin_top, margin_left) { 236 237 //re-position dropblock#wpfd-box-player .dropblock 238 var dropblock = $("#player-" + fileid).parent('.dropblock'); 239 dropblock.css('margin-top', (-margin_top) + 'px'); 240 dropblock.css('margin-left', (-margin_left) + 'px'); 241 dropblock.css('height', ''); 242 dropblock.css('width', ''); 243 dropblock.css('top', ''); 244 dropblock.css('left', ''); 245 } 246}); 247 248jQuery(document).keyup(function (e) { 249 if (e.keyCode == 27) { // escape key maps to keycode `27` 250 pBox = jQuery("#wpfd-box-player"); 251 if (pBox.length) { 252 pBox.hide(); 253 if (pBox.find(".video-js").length) { 254 var playerId = pBox.find(".video-js").first().attr("id"); 255 myPlayer = videojs(playerId); 256 myPlayer.dispose(); 257 } 258 } 259 } 260});
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.