forked from daixianceng/XLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XLoader.min.js
1 lines (1 loc) · 4.88 KB
/
XLoader.min.js
1
(function(e){e.fn.extend({XLoader:function(t){var n=e(this);var r=e('<div id="XLoaderContainer"></div>');var i=location.href;var s=true;var o={id:"XLoaderTable"};var u={number:{text:"No.","class":"table-col-1"},image:{text:"Picture","class":"table-col-2"},name:{text:"Name","class":"table-col-2"},size:{text:"Size","class":"table-col-1"},textarea:{text:"Description","class":"table-col-2"},modify:{text:"Modify","class":"table-col-1"}};var a={};var f={name:"descriptions[]"};var l={text:"Delete","class":"XLoaderDeleteLink"};var c="imageNames[]";var h="";var p=function(t,n){for(var r in n){if(e.isPlainObject(t[r])&&e.isPlainObject(n[r])){p(t[r],n[r])}else{t[r]=n[r]}}};if(typeof t.container!=="undefined"){r=e(t.container)}else{n.after(r)}if(typeof t.target!=="undefined"){i=t.target}if(t.registerStyle===false){s=false}if(e.isPlainObject(t.tableOptions)){p(o,t.tableOptions)}if(e.isPlainObject(t.columnOptions)){(function(){for(var n in u){if(e.isPlainObject(t.columnOptions[n])){p(u[n],t.columnOptions[n])}else{delete u[n]}}})()}if(e.isPlainObject(t.imageOptions)){p(a,t.imageOptions)}if(e.isPlainObject(t.textareaOptions)){p(f,t.textareaOptions)}if(e.isPlainObject(t.deleteLinkOptions)){p(l,t.deleteLinkOptions)}if(typeof t.hiddenFieldName!=="undefined"){c=t.hiddenFieldName}if(typeof t.resourcesUrl!=="undefined"){h=t.resourcesUrl}if(s){e("body").append('<style type="text/css">#XLoaderTable{font-family:Arial,Helvetica,sans-serif;font-size:13px;color:#333;background:#eee;border-spacing:1px}#XLoaderTable .table-col-1{width:100px}#XLoaderTable .table-col-2{width:200px}#XLoaderTable th{font-size:14px;font-weight:200;color:#ddd;background:#333;height:40px}#XLoaderTable img{max-width:180px}#XLoaderTable tr{background:#fff}#XLoaderTable td{text-align:center;padding:10px}#XLoaderTable textarea{resize:none;width:178px;height:100%;padding:5px;font-family:Arial,Helvetica,sans-serif;font-size:13px;color:#333;border:1px dashed #ccc;outline:none}#XLoaderTable textarea:hover,#XLoaderTable textarea:focus{border-color:#333}.XLoaderDeleteLink{color:#fff;background-color:#d9534f;border-color:#d43f3a;padding:5px 12px;font-weight:bold;line-height:18px;cursor:default;-webkit-background-clip:border-box;background-clip:border-box;border-radius:2px;-webkit-box-shadow:none;box-shadow:none;text-shadow:0 1px rgba(0, 0, 0, .1);display:inline-block;text-decoration:none;}.XLoaderDeleteLink:hover{text-shadow:0 1px rgba(0, 0, 0, .3);-webkit-box-shadow:0 1px 1px rgba(0, 0, 0, .2);box-shadow:0 1px 1px rgba(0, 0, 0, .2);border-color:#ac2925;background-color:#c13e2c;}.XLoaderDeletedRow{color:#a94442;background-color:#f2dede;text-shadow:0 1px 0 rgba(255, 255, 255, .5);}</style>')}var d=e('<div style="display:none;"><iframe name="XLoaderFrame"></iframe><form action="'+i+'" method="post" enctype="multipart/form-data" target="XLoaderFrame"></form></div>').appendTo("body");var v=e("<table><thead><tr></tr></thead><tbody></tbody></table>");n.change(function(){if(this.files.length===0)return;var t=e('<input type="file" name="'+n.attr("name")+'" multiple>').get(0);t.files=this.files;d.find("form").empty().append(t).submit()});n.parents("form").submit(function(){n.attr("disabled",true)});(function(){for(var t in o){v.attr(t,o[t])}for(var n in u){var r=e("<th></th>");for(var t in u[n]){if(t==="text"){r.text(u[n][t])}else{r.attr(t,u[n][t])}}v.find("thead tr").append(r)}})();(function(){var t=false;var n=0;e.extend({XLoaderData:function(s,o){var p=e.parseJSON(s);if(!p||p.length===0)return;if(!t){r.append(v);t=true}for(var d=0;d<p.length;d++){n++;var m=e("<tr></tr>");for(var g in u){switch(g){case"number":m.append("<td>"+n+"</td>");break;case"image":var y=e('<td><img src="'+p[d].uri+'"></td>');for(var b in a){if(b==="src")continue;y.find("img").attr(b,a[b])}m.append(y);break;case"name":m.append("<td>"+p[d].name+'<input type="hidden" name="'+c+'" value="'+p[d].name+'"></td>');break;case"size":m.append("<td>"+p[d].size+"</td>");break;case"textarea":var y=e("<td><textarea></textarea></td>");for(var b in f){y.find("textarea").attr(b,f[b])}if(p[d].description){y.find("textarea").val(p[d].description)}m.append(y);break;case"modify":var y=e('<td><a href="#"></a></td>');for(var b in l){if(b==="text"){y.find("a").text(l[b])}else{y.find("a").attr(b,l[b])}}(function(){var t=m;var n=p[d].name;var r="";var s=false;if(o==="target"){r=i}else if(o==="resources"){r=h}y.find("a").click(function(){if(s)return false;s=true;e.ajax({url:r,type:"post",data:{filename:n,action:"delete"},dataType:"json",success:function(e){if(e.error==="no"){t.empty().html('<td class="XLoaderDeletedRow" colspan="'+Object.keys(u).length+'">The "'+n+'" has been deleted.</td>')}},error:function(e,t,n){alert(t)},complete:function(e,t){s=false}});return false})})();m.append(y);break}}v.find("tbody").append(m)}}})})();(function(){if(h!==""){e.ajax({url:h,type:"post",timeout:3e4,data:{action:"load"},dataType:"text",success:function(t){e.XLoaderData(t,"resources")},error:function(e,t,n){alert(t)}})}})()}})})(jQuery)