xcat-core/xCAT-UI/js/jquery/jquery.serverBrowser.min.js
2011-01-14 16:17:41 +00:00

18 lines
5.6 KiB
JavaScript

/*
Author: ApmeM (artem.votincev@gmail.com)
Date: 9-June-2010
Version: 1.4
Download: http://code.google.com/p/jq-serverbrowse/
*/
(function(b){b.fn.serverBrowser=function(p){this.each(function(){function l(){return c.systemImageUrl.length==0?c.imageUrl:c.systemImageUrl}function q(a){if(c.basePath=="")return true;var d=c.basePath.split(c.separatorPath),e=a.split(c.separatorPath);if(d.length>e.length)return false;var g=true;b.each(d,function(m,r){if(r!=e[m])g=false});return g}function s(a){c.basePath.split(c.separatorPath);a=a.split(c.separatorPath);var d=[];b.each(a,function(e,g){g==".."?d.pop():d.push(g)});return d.join(c.separatorPath)}
function t(){var a=[];b.each(f.selectedItems,function(d,e){a.push(b.data(e,"path"))});a.length==0&&a.push(f.browserHistory.pop());if(c.multiselect)c.onSelect(a);else if(a.length==1)c.onSelect(a[0]);else if(a.length>1){alert("Plugin work incorrectly. If error repeat, please add issue into http://code.google.com/p/jq-serverbrowse/issues/list with steps to reproduce.");return}h.dialog("close")}function u(){n.css({height:h.height()-i.outerHeight(true)-2});k.css({height:h.height()-i.outerHeight(true)-
2,width:h.width()-n.outerWidth(true)-4})}function v(a){var d=b("<div></div>").css({margin:"2px"}).appendTo(k);if(a.isError){d.addClass("ui-state-error ui-corner-all").css({padding:"0pt 0.7em"});var e=b("<p></p>").appendTo(d);b("<span></span>").addClass("ui-icon ui-icon-alert").css({"float":"left","margin-right":"0.3em"}).appendTo(e);b("<span></span>").text(a.name).appendTo(e)}else{var g=a.path+c.separatorPath+a.name;d.hover(function(){b(this).addClass("ui-state-hover")},function(){b(this).removeClass("ui-state-hover")});
e=b("<img />").css({width:"16px",margin:"0 5px 0 0"}).appendTo(d);b("<span></span>").text(a.name).appendTo(d);if(a.isFolder)e.attr({src:l()+"folder.png"});else{ext=a.name.split(".").pop();ext==""||ext==a.name||c.knownExt.length>0&&b.inArray(ext,c.knownExt)<0?e.attr({src:l()+"unknown.png"}):e.attr({src:c.imageUrl+ext+".png"})}b.data(d,"path",g);d.unbind("click").bind("click",function(){if(b(this).hasClass("ui-state-active")){var m=[];b.each(f.selectedItems,function(r,w){b.data(w,"path")!=g&&m.push(w)});
f.selectedItems=m}else{!c.multiselect&&f.selectedItems.length>0&&b(f.selectedItems[0]).click();f.selectedItems.push(d)}b(this).toggleClass("ui-state-active")});d.unbind("dblclick").bind("dblclick",function(){if(a.isFolder)j(g);else{f.selectedItems=[d];t()}})}}function j(a){f.selectedItems=[];a=s(a);if(q(a)){f.browserHistory.push(a);x.val(a);b.ajax({url:c.handlerUrl,type:c.requestMethod,data:{action:"browse",path:a,time:(new Date).getTime()},beforeSend:function(){k.empty().css({"text-align":"center"});
b("<img />").attr({src:l()+"loading.gif"}).css({width:"32px"}).appendTo(k)},success:function(d){k.empty().css({"text-align":"left"});a!=c.basePath&&c.showUpInList&&v({name:"..",isFolder:true,isError:false,path:a});b.each(d,function(e,g){v(b.extend(g,{path:a}))})},dataType:"json"})}else alert("Path should be based from "+c.basePath)}var c={onSelect:function(a){alert("You select: "+a)},onLoad:function(){return c.basePath},multiselect:false,imageUrl:"img/",systemImageUrl:"",showUpInList:false,basePath:"C:",
separatorPath:"/",useKnownPaths:true,knownPaths:[{text:"Desktop",image:"desktop.png",path:"C:/Users/All Users/Desktop"},{text:"Documents",image:"documents.png",path:"C:/Users/All Users/Documents"}],knownExt:[],handlerUrl:"browserDlg.txt",title:"Browse",width:300,height:300,position:["center","center"],requestMethod:"POST"};p&&b.extend(c,p);b.extend(c,{autoOpen:false,modal:true,buttons:{Open:function(){t()},Cancel:function(){h.dialog("close")}},resize:function(a,d){u(a,d)}});var f={browserHistory:[],
selectedItems:[]},h=b('<div title="'+c.title+'"></div>').css({overflow:"hidden"}).appendTo(document.body);h.dialog(c);var i=b("<div></div>").addClass("ui-widget-content").appendTo(h).css({height:"30px",width:"100%","padding-top":"7px"}),o=b("<div></div>").css({"float":"left","vertical-align":"middle","margin-left":"6px"}).addClass("ui-corner-all").hover(function(){b(this).addClass("ui-state-hover")},function(){b(this).removeClass("ui-state-hover")});b("<span></span>").text("Look in: ").appendTo(o.clone(false).appendTo(i));
var x=b('<input type="text">').keypress(function(a){if(a.keyCode=="13"){a.preventDefault();j(x.val())}}).css("width","200px").appendTo(o.clone(false).appendTo(i));b("<div></div>").addClass("ui-corner-all ui-icon ui-icon-circle-arrow-w").click(function(){f.browserHistory.pop();var a=c.basePath;if(f.browserHistory.length>0)a=f.browserHistory.pop();j(a)}).appendTo(o.clone(true).appendTo(i));b("<div></div>").addClass("ui-corner-all ui-icon ui-icon-arrowreturnthick-1-n").click(function(){backPath=f.browserHistory[f.browserHistory.length-
1];backPath!=c.basePath&&j(backPath+c.separatorPath+"..")}).appendTo(o.clone(true).appendTo(i));var n=b("<div></div>").addClass("ui-widget-content").css({"text-align":"center",overflow:"auto","float":"left",width:"100px"});if(c.useKnownPaths){n.appendTo(h);b.each(c.knownPaths,function(a,d){var e=b("<div></div>").css({margin:"10px"}).hover(function(){b(this).addClass("ui-state-hover")},function(){b(this).removeClass("ui-state-hover")}).click(function(){j(d.path)}).appendTo(n);b("<img />").attr({src:l()+
c.separatorPath+d.image}).css({width:"32px",margin:"5px 10px 5px 5px"}).appendTo(e);b("<br/>").appendTo(e);b("<span></span>").text(d.text).appendTo(e)})}var k=b("<div></div>").addClass("ui-widget-content").css({"float":"right",overflow:"auto"}).appendTo(h);b(this).click(function(){f.browserHistory=[];var a=s(c.onLoad());a=a.split(c.separatorPath);a.pop();a=a.join(c.separatorPath);if(!q(a))a=c.basePath;j(a);h.dialog("open");u()})});return this}})(jQuery);