-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.jdownload.min.js
executable file
·1 lines (1 loc) · 2.24 KB
/
jquery.jdownload.min.js
1
(function(a){a.fn.jDownload=function(f){var e={root:"/",filePath:null,event:"click",dialogTitle:"jDownload",dialogDesc:"Download the file now?",dialogWidth:400,dialogHeight:"auto",dialogModal:true,showfileInfo:true,start:null,stop:null,download:null,cancel:null};f=a.extend(e,f);var g="jDownloadDialog_"+a(".jDownloadDialog").length;var b="jDownloadFrame_"+a(".jDownloadFrame").length;var i='<iframe class="jDownloadFrame" src="" id="'+b+'"></iframe>';var d='<div class="jDownloadDialog" title="'+f.dialogTitle+'" id="'+g+'"></div>';a("body").append(i+d);var h=a("#"+b);var j=a("#"+g);h.css({height:"0px",width:"0px",visibility:"hidden"});j.dialog({autoOpen:false,buttons:{Cancel:function(){if(a.isFunction(f.cancel)){f.cancel()}a(this).dialog("close")},Download:function(){if(a.isFunction(f.download)){f.download()}c()}},width:f.dialogWidth,height:f.dialogHeight,modal:f.dialogModal,close:(a.isFunction(f.stop))?f.stop:null});a(this).bind(f.event,function(){if(a.isFunction(f.start)){f.start()}var l=a(this);j.html("");var k=(f.filePath==null)?a(this).attr("href"):f.filePath;j.html('<p>Fetching File...</p><img src="'+f.root+'jdownload/loader.gif" alt="Loading" />');a.ajax({type:"GET",url:f.root+"jdownload/jdownload.php",data:"action=download&path="+k,error:function(m,o,n){j.html('<p class="jDownloadError">Fatal Error.</p>')},success:function(m){setTimeout(function(){if(m=="error"){j.html('<p class="jDownloadError">File cannot be found.</p>')}else{if(f.showfileInfo==true){var n=f.root+"jdownload/jdownload.php";a.ajax({url:n,type:"GET",dataType:"json",data:"action=info&path="+k,success:function(p){if(p.error=="denied"){j.html('<p class="jDownloadError">This file type is not allowed.</p>')}else{var o='<div class="jDownloadInfo">';o+="<p><span>File Name:</span> "+p.filename+"</p>";o+="<p><span>File Type:</span> "+p.filetype+"</p>";o+="<p><span>File Size:</span> "+p.filesize+" KB</p>";o+="</div>";a(".jDownloadInfo, .jDownloadError").remove();var q=(l.attr("title").length>0)?l.attr("title"):"Download the file now?";j.html("<p>"+q+"</p>"+o)}}})}}},200)}});j.data("jDownloadData",{filePath:k}).dialog("open");return false});function c(k){h.attr("src",f.root+"jdownload/jdownload.php?action=download&path="+j.data("jDownloadData").filePath);j.dialog("close");return false}}})(jQuery);