PHP Classes

File: media/file-picker.min.js

Recommend this page to a friend!
  Classes of Peter He   File Picker   media/file-picker.min.js   Download  
File: media/file-picker.min.js
Role: Application script
Content type: text/plain
Description: main js file
Class: File Picker
Let the user browse and pick server side files
Author: By
Last change:
Date: 15 years ago
Size: 5,753 bytes
 

Contents

Class file image Download
/*
Program Name: File Picker
Program URI: http://code.google.com/p/file-picker/
Description: Display and choose files from your website.

Copyright (c) 2008 Hpyer (hpyer[at]yahoo.cn)
Dual licensed under the MIT (MIT-LICENSE.txt)
and GPL (GPL-LICENSE.txt) licenses.
*/

var FilePicker={params:{uri:".",key:"FP_RESULT",multi:true,access:"file-picker.php",unicode:true,delay:300},last_click:null,timer:null,init:function(A){$.extend(this.params,A);$.base64.is_unicode=this.params.use_unicode;$.ajaxSetup({url:this.params.access,dataType:"json"});this.do_translate_options();this.events_binder();this.get_list()},do_complete:function(){var A=FilePicker;var B='{uri:"'+A.get_uri()+'", files:['+A.get_selected(true)+"]}";A.do_close(B)},do_close:function(obj){var self=FilePicker;if(typeof (obj)!="string"){obj=""}eval("window.opener."+self.params.key+"='"+obj+"';");window.close()},get_uri:function(){var A;A=$.base64.decode($("#folders_tree").val());A=A=="/"?"":A;return this.params.uri+A},get_selected:function(B){var A=$("li.selected");if(A.length==1){return B?'"'+A.text()+'"':A.text()}return $.map(A,function(C){return'"'+C.innerHTML+'"'}).join(", ")},do_select:function(B,A){A=A||false;B.addClass("selected");$("#filename_box").val(A?this.get_selected():"")},do_unselect:function(){$("li.selected").removeClass("selected");$("#filename_box").val("");FilePicker.do_hide_info();$("#filename_box").focus()},do_show_info:function(A){var B=$("#info_box").addClass("info_box").css("top",(A.pageY+10)+"px").css("left",(A.pageX+10)+"px").fadeIn("fast")},do_hide_info:function(A){var B=$("#info_box").empty();if(!A){B.hide()}},do_translate_options:function(){$("#folders_tree option").each(function(){$(this).text($.base64.decode($(this).text()))})},do_up:function(){var A=$.base64.decode($("#folders_tree").val());var C=A.lastIndexOf("/");if(C<0||A=="/"){return false}var B=A.substr(0,C);B=(B=="")?"/":$.base64.encode(B);$("#folders_tree").val(B);FilePicker.get_list()},do_dblclick:function(){var A=FilePicker;clearTimeout(A.timer);var C=$(this);if(C.attr("ftype")=="folder"){var B=$.base64.decode($("#folders_tree").val());if(B!="/"){B+="/"}$("#folders_tree").val($.base64.encode(B+C.text()));A.get_list()}else{A.do_select(C);A.do_complete()}},do_click:function(A){var B=FilePicker;var D=$(this);B.do_hide_info();$("#filename_box").focus();if(!B.params.multi){B.do_unselect()}if(B.params.multi&&D.attr("ftype")=="folder"){if(!A.shiftKey){B.last_click=D.attr("id")}if(A.ctrlKey){return false}var C=$("li.selected").removeClass("selected");if(C.length==1&&C.attr("id")==D.attr("id")){B.do_unselect();return false}B.do_select(D)}else{if(A.ctrlKey){B.last_click=D.attr("id");$("li.selected[ftype=folder]").removeClass("selected");$(this).toggleClass("selected");$("#filename_box").val(B.get_selected())}else{if(B.params.multi&&A.shiftKey){}else{B.last_click=D.attr("id");var C=$("li.selected").removeClass("selected");if(C.length==1&&C.attr("id")==D.attr("id")){B.do_unselect();return false}B.do_select(D,true)}}}if(B.params.multi&&A.shiftKey){if(!B.last_click){B.last_click=D.attr("id");B.do_select(D)}else{B.do_unselect();var E=parseInt(B.last_click.split("_")[1]);var F=parseInt(D.attr("id").split("_")[1]);if(E>F){$("#list > li").slice(F,E+1).each(function(){FilePicker.do_select($(this))})}else{$("#list > li").slice(E,F+1).each(function(){FilePicker.do_select($(this))})}}$("li.selected[ftype=folder]").removeClass("selected");$("#filename_box").val(B.get_selected())}clearTimeout(B.timer);B.timer=setTimeout(function(){B.get_info(A)},B.params.delay);return false},get_info:function(A){this.do_hide_info(true);var B=$("li.selected");if(B.length==1){this.do_show_info(A);$("<img />").attr("id","info_loading_img").attr("src",$("#loading_img").attr("src")).appendTo("#info_box");$.ajax({data:{action:"info",dir:$("#folders_tree").val(),file:$.base64.encode(B.text())},success:function(E){var C=FilePicker;$("#info_box").html($("<label></label>").attr("id","btn_close").text("X").click(function(){C.do_hide_info(false)}));var D=0;$.each(E,function(F,G){if($("#info_box").css("display")=="none"){return false}if(G.key=="preview"){var H=C.get_uri()+"/"+$.base64.decode(G.value);$("<img />").attr("id","preview_img").attr("alt",G.trans).attr("src",H).click(function(){window.open(this.src,"_blank","")}).prependTo("#info_box")}else{if(F==0){G.value=$.base64.decode(G.value)}$("#info_box").append("<strong>"+G.trans+"</strong>:<br /> &nbsp; "+G.value+"<br />")}F++})}})}},get_list:function(A){if(typeof (A)=="undefined"){A=true}this.last_click=null;this.do_hide_info();$("#loading_img").show();$("#list").empty();$("#filename_box").val("");$.ajax({cache:A,data:{action:"list",dir:$("#folders_tree").val(),filter:$("#filter_box").val()},success:function(C){var B=FilePicker;$("#loading_img").hide();var D=[];$.each(C,function(E,F){F.name=$.base64.decode(F.name);$("<li></li>").attr("id","item_"+E).attr("ftype",F.type).attr("title",F.name).html(F.name).addClass(F.type).click(B.do_click).dblclick(B.do_dblclick).appendTo("#list");if(F.type!="folder"){D.push(F.name)}});$("#filename_box").autocompleteArray(D,{onItemSelect:function(){$("li:not(li[ftyp:folder])").each(function(){if($(this).html()==$("#filename_box").val()){$(this).click();return false}})}});B.do_unselect()}})},events_binder:function(){var A=FilePicker;$("body").bind("selectstart",function(){return false});$("#file_picker_form").bind("submit",function(){return false});$("#list_box").bind("click",A.do_unselect);$("#folders_tree").bind("change",function(){A.get_list(true)});$("#btn_refresh").bind("click",function(){A.get_list(false)});$("#btn_up").bind("click",A.do_up);$("#btn_complete").bind("click",A.do_complete);$("#btn_cancel").bind("click",A.do_close);$("#info_box").ppdrag()}};