Advertising
- Someone
- Monday, May 21st, 2012 at 6:57:34am MDT
- (function($) {
- /**
- * @class File manager (main controller)
- * @author dio dio@std42.ru
- **/
- elFinder = function(el, o) {
- var self = this, id;
- $(el).data('elfinder',this);
- this.log = function(m) {
- window.console && window.console.log && window.console.log(m);
- }
- /**
- * Object. File manager configuration
- **/
- this.options.downloadLinkFormat = '/%s';
- this.options = $.extend({}, this.options, o||{});
- if(id = document.location.hash.replace(/^#(\.\/)?/,'').replace(/\??&.*$/,''))
- this.options.startDir = id;
- if (!this.options.url) {
- alert('Invalid configuration! You have to set URL option.');
- return;
- }
- /**
- * String. element id, create random if not set;
- **/
- this.id = '';
- if ((id = $(el).attr('id'))) {
- this.id = id;
- } else {
- this.id = 'el-finder-'+Math.random().toString().substring(2);
- }
- /**
- * String. Version number;
- **/
- this.version = '1.1 RC3';
- /**
- * String. jQuery version;
- **/
- this.jquery = $.fn.jquery.split('.').join('');
- /**
- * Object. Current Working Dir info
- **/
- this.cwd = {};
- this.lockedFolders = {};
- /**
- * Object. Current Dir Content. Files/folders info
- **/
- this.cdc = {};
- this.cdc_pos = 0;
- /**
- * Object. Current Tree Content.
- **/
- this.tree = {};
- /**
- * Object. Buffer for copied files
- **/
- this.buffer = {};
- /**
- * Array. Selected files IDs
- **/
- this.selected = [];
- /**
- * Boolean. Enable/disable actions
- **/
- this.locked = false;
- /**
- * Number. Max z-index on page + 1, need for contextmenu and quicklook
- **/
- this.zIndex = 2;
- /**
- * Object. Some options get from server
- **/
- this.params = { uplMaxSize : '' };
- this.vCookie = 'el-finder-view-'+this.id;
- this.oCookie = 'el-finder-order-'+this.id;
- /**
- * Object. View. After init we can accessel as this.view.win
- **/
- this.view = new this.view(this, el);
- /**
- * Object. User Iterface. Controller for commands/buttons/contextmenu
- **/
- this.ui = new this.ui(this);
- /**
- * Object. Set/update events
- **/
- this.eventsManager = new this.eventsManager(this);
- /**
- * Object. Quick Look like in MacOS X :)
- **/
- //this.quickLook = new this.quickLook(this);
- /**
- * Set/get cookie value
- *
- * @param String name cookie name
- * @param String value cookie value, null to unset
- **/
- this.cookie = function(name, value) {
- if (typeof value == 'undefined') {
- if (document.cookie && document.cookie != '') {
- var i, c = document.cookie.split(';');
- name += '=';
- for (i=0; i<c.length; i++) {
- c[i] = $.trim(c[i]);
- if (c[i].substring(0, name.length) == name) {
- return decodeURIComponent(c[i].substring(name.length));
- }
- }
- }
- return '';
- } else {
- var d, o = $.extend({}, this.options.cookie);
- if (value===null) {
- value = '';
- o.expires = -1;
- }
- if (typeof(o.expires) == 'number') {
- d = new Date();
- d.setTime(d.getTime()+(o.expires * 24 * 60 * 60 * 1000));
- o.expires = d;
- }
- document.cookie = name+'='+encodeURIComponent(value)+'; expires='+o.expires.toUTCString()+(o.path ? '; path='+o.path : '')+(o.domain ? '; domain='+o.domain : '')+(o.secure ? '; secure' : '');
- }
- }
- this.options.order=this.cookie(this.oCookie)||'-name';
- /**
- * Set/unset this.locked flag
- *
- * @param Boolean state
- **/
- this.lock = function(l) {
- this.view.spinner((this.locked = l||false));
- this.eventsManager.lock = this.locked;
- }
- /**
- * Set/unset lock for keyboard shortcuts
- *
- * @param Boolean state
- **/
- this.lockShortcuts = function(l) {
- this.eventsManager.lock = l;
- }
- /**
- * Set file manager view type (list|icon)
- *
- * @param String v view name
- **/
- this.setView = function(v) {
- if (v == 'list' || v == 'icon') {
- this.options.view = v;
- this.cookie(this.vCookie, v);
- }
- }
- this.setOrder = function(o) {
- var self=this;
- this.view.win.addClass('el-finder-disabled');
- var oo=this.options.order;
- var desc=(oo.match(/^-/) == '-' ? true : false);
- if(desc && oo.replace(/^-/,'')==o)oo=o;
- else if(oo==o)oo='-'+o;
- else oo=o;
- this.options.order = oo;
- this.cookie(this.oCookie, this.options.order);
- if(this.cdc_pos>0){
- this.ajax({ cmd : 'open', target : this.cwd.hash, tree : false }, function(data) {
- self.reload(data);
- });
- }
- else {
- var tmp=[];
- for(var i in this.cdc)
- tmp.push(this.cdc[i]);
- function convText(mime, t){
- return String(mime=='directory' ? (desc ? 0 : 1) : (desc ? 1 : 0)) + t;
- }
- function convNumeric(mime, t){
- return (mime=='directory' ? (desc ? -0xfffffffffffffff0 : 0xfffffffffffffff0) : 0) + t;
- }
- switch(o){
- default:
- tmp = tmp.sort(function(a, b){ return convText(a.mime, a[o]).localeCompare(convText(b.mime, b[o]))*(desc ? 1 : -1); });
- break;
- case 'hits':
- case 'size':
- tmp = tmp.sort(function(a, b){ return (convNumeric(a.mime, a[o]) - convNumeric(b.mime, b[o]))*(desc ? 1 : -1); });
- break;
- }
- this.reload({
- cwd:this.cwd,
- cdc:tmp,
- cdc_pos:0,
- cdc_append:false
- });
- this.lock(false);
- /*
- pl.sort(function(a, b) {
- var _a = self.tree.find('a[key="'+a+'"]').text()||'',
- _b = self.tree.find('a[key="'+b+'"]').text()||'';
- return _a.localeCompare(_b);
- });*/
- }
- }
- /**
- * make ajax request, show message on error, call callback on success
- *
- * @param Object. data for ajax request
- * @param Function
- * @param Object overrwrite some options
- */
- this.ajax = function(data, callback, options) {
- var self = this, opts = {
- url : this.options.url,
- uploadUrl: this.options.url,
- async : true,
- type : 'POST',
- data : data,
- dataType : 'html',
- cache : false,
- lock : true,
- force : false,
- silent : false
- }
- opts[this.options.session.type] = this.options.session.id;
- if (typeof(options) == 'object') {
- opts = $.extend({}, opts, options);
- }
- if (!opts.silent) {
- opts.error = self.view.fatal;
- }
- opts.success = function(data) {
- try {
- data=$.parseJSON(data);
- }
- catch(e){
- alert('parseJSON: '+e+': '+data);
- }
- self.ajaxSuccess(opts, data, callback);
- }
- opts.lock && this.lock(true);
- opts.data.order = self.options.order;
- if(opts.data.cmd == 'open') {
- var e = $(window),
- w = e.width(),
- h = e.height();
- switch(this.options.view) {
- case 'list':
- opts.data.limit = Math.round((h/56)*4);
- break;
- case 'icon':
- opts.data.limit = Math.round(((w/113)*((h/77)+1))*2);
- //alert(w+'x'+h+' '+(w/113)+' x '+(h/77));
- break;
- }
- }
- if(!opts.data.init){
- opts.data.tree_expanded = [];
- this.view.tree.find('ul:visible:not(:first)').each(function(){
- opts.data.tree_expanded.push($(this).parent().find('a').attr('key'));
- });
- }
- if(!opts.data.startDir && this.options.startDir) opts.data.startDir = this.options.startDir;
- $.ajax(opts);
- }
- /**
- * Blubb
- *
- * @return null
- **/
- this.ajaxSuccess = function(opts, data, callback) {
- var self = this;
- opts.lock && this.lock();
- data.debug && this.log(data.debug);
- if(data.run){
- switch(data.run){
- default:
- this.view.error('Unknown run method: '+data.run);
- break;
- case 'page_reload':
- setTimeout(function(){document.location = '/';}, 1500);
- break;
- case 'registered':
- //$('[name=s_guest]').attr('name','s_user');
- self.options.session.type='s_user';
- this.ajax({cwd:'My_files',tree:true}, function(data) {
- self.reload(data);
- });
- break;
- }
- }
- if (data.error) {
- !opts.silent && this.view.error(data.error, data.errorData);
- if (!opts.force && !data.force) {
- return;
- }
- }
- if(data.message && !opts.silent) this.view.message(data.message);
- if(data.session) $('[name=session]').val(data.session);
- if(data.startDir) self.options.startDir = data.startDir;
- callback && callback(data);
- delete data;
- }
- /**
- * Update file manager content
- *
- * @param Object Data from server
- **/
- this.reload = function(data) {
- var i, currentDir;
- this.cwd = data.cwd;
- if(!this.cwd.columns)this.cwd.columns = {name:'Name', time:'Time', size:'Size', hits:'Hits', mime:'Kind'};
- this.cdc_pos = data.cdc_pos;
- if(!data.cdc_append) this.cdc = {};
- if(data.tree) {
- this.view.renderNav(data);
- this.eventsManager.updateNav();
- }
- switch(this.cwd.type) {
- default:
- alert('elFinder.refresh('+this.cwd.type+') not implemented yet');
- break;
- case 'folder':
- for (i=0; i<data.cdc.length ; i++) {
- this.cdc[data.cdc[i].hash] = data.cdc[i];
- this.cwd.size += Number(data.cdc[i].size);
- }
- this.updateCwd();
- if (data.select && data.select.length) {
- var l = data.select.length;
- while (l--) {
- this.cdc[data.select[l]] && this.selectById(data.select[l]);
- }
- }
- break;
- case 'file':
- this.cdc = {};
- this.cdc[this.cwd.hash] = this.cwd;
- this.updateCwd();
- break;
- case 'template':
- this.cdc = data.cdc;
- this.updateCwd();
- break;
- }
- if (this.options.autoReload>0) {
- this.iID && clearInterval(this.iID);
- this.iID = setInterval(function() { !self.locked && self.ui.exec('reload'); }, this.options.autoReload*60000);
- }
- if(this.options.onChdir)this.options.onChdir(this);
- }
- this.openHistory = function(opts) {
- if(window.History) {
- window.History.pushState({
- fn:'elfinder.go',
- opts:{
- cmd:'open',
- target:opts.hash,
- tree:opts.tree,
- startDir:this.options.startDir
- }
- },
- opts.name,
- '/'+opts.hash);
- }
- else {
- var self = this;
- this.ajax({ cmd : 'open', target : opts.hash, tree: opts.tree }, function(data) { self.reload(data); });
- }
- }
- /**
- * Redraw current directory
- *
- */
- this.updateCwd = function() {
- this.lockShortcuts();
- this.selected = [];
- this.view.renderCwd();
- this.eventsManager.updateCwd();
- this.ui.update();
- this.view.tree.find('a[key="'+this.cwd.hash+'"]').trigger('select');
- }
- /**
- * Execute after files was dropped onto folder
- *
- * @param Object drop event
- * @param Object drag helper object
- * @param String target folder ID
- */
- this.drop = function(e, ui, target) {
- /*if (ui.helper.find('[key="'+target+'"]').length) {
- return self.view.error('Unable to copy into itself');
- }*/
- var ids = [], sel = this.getSelected(), cut = true, oldBuffer;
- for(var x in sel) {
- ids.push(sel[x].hash);
- if(!sel[x].rm) cut = false;
- }
- //ui.helper.hide();
- /*ui.helper.find('div:not(.noaccess):has(>label):not(:has(em[class="readonly"],em[class=""]))').each(function() {
- ids.push($(this).hide().attr('key'));
- });*/
- /*if (!ui.helper.find('div:has(>label):visible').length) {
- ui.helper.hide();
- }*/
- if (ids.length) {
- oldBuffer = self.buffer;
- self.setBuffer(ids, e.shiftKey ? false : cut, target);
- if (self.buffer.files) {
- /* some strange jquery ui bug (in list view) */
- setTimeout(function() { self.ui.exec('paste'); self.buffer = oldBuffer; }, 300);
- }
- } else {
- $(this).removeClass('el-finder-droppable');
- }
- }
- /**
- * Return selected files data
- *
- * @param Number if set, returns only element with this index or empty object
- * @return Array|Object
- */
- this.getSelected = function(ndx) {
- var self = this;
- function getEl(hash) {
- if(!hash) return;
- else if(self.cdc[hash]) return self.cdc[hash];
- else if(self.cwd.hash == hash) return self.cwd;
- else if(self.tree[hash]) return self.tree[hash];
- else throw new Exception('fm.getSelected(): key not found');
- }
- if (ndx>=0) {
- return this.selected[ndx] && getEl(this.selected[ndx]) || {};
- }
- for (var i=0, s=[], e; i<this.selected.length; i++) {
- e = getEl(this.selected[i]);
- e && s.push(e);
- }
- return s;
- }
- this.select = function(el, reset) {
- reset && $('.ui-selected', self.view.cwd).removeClass('ui-selected');
- el.addClass('ui-selected');
- self.updateSelect();
- }
- this.selectById = function(id) {
- var el = $('[key="'+id+'"]', this.view.cwd);
- if (el.length) {
- this.select(el);
- this.checkSelectedPos();
- }
- }
- this.unselect = function(el) {
- el.removeClass('ui-selected');
- self.updateSelect();
- }
- this.toggleSelect = function(el) {
- el.toggleClass('ui-selected');
- this.updateSelect();
- }
- this.selectAll = function() {
- $('.el-finder-list [key]', self.view.cwd).addClass('ui-selected')
- self.updateSelect();
- }
- this.unselectAll = function() {
- $('.ui-selected', self.view.cwd).removeClass('ui-selected');
- self.updateSelect();
- }
- this.updateSelect = function() {
- self.selected = [];
- $('.ui-selected', self.view.cwd).each(function() {
- self.selected.push($(this).attr('key'));
- });
- self.ui.update();
- //self.quickLook.update();
- }
- /**
- * Scroll selected element in visible position
- *
- * @param Boolean check last or first selected element?
- */
- this.checkSelectedPos = function(last) {
- var s = self.view.cwd.find('.ui-selected:'+(last ? 'last' : 'first')).eq(0),
- e = $(window),
- p = s.position(),
- h = s.outerHeight(),
- ph = e.height(),
- pt = e.scrollTop();
- if (p.top - pt < 0) {
- if(self.view.cwd.find('.el-finder-list [key]:first').eq(0).attr('key') === s.attr('key')) e.scrollTop(0);
- else e.scrollTop(p.top);
- }
- else if (p.top + h*3 > pt + ph) e.scrollTop(p.top + h*3 - ph);
- }
- /**
- * Add files to clipboard buffer
- *
- * @param Array files IDs
- * @param Boolean copy or cut files?
- * @param String destination folder ID
- */
- this.setBuffer = function(files, cut, dst) {
- var i, id, f;
- this.buffer = {
- src : this.cwd.hash,
- dst : dst,
- files : [],
- names : [],
- cut : cut||0
- };
- for (i=0; i<files.length; i++) {
- id = files[i];
- f = this.cdc[id];
- if(!f && id == this.cwd.hash) f = this.cwd;
- if(!f && this.tree[id]) f = this.tree[id];
- if (f && !f.system && f.read && f.type != 'link') {
- this.buffer.files.push(f.hash);
- this.buffer.names.push(f.name);
- }
- }
- if (!this.buffer.files.length) {
- this.buffer = {};
- }
- }
- /**
- * Return true if file name is acceptable
- *
- * @param String file/folder name
- * @return Boolean
- */
- this.isValidName = function(n) {
- return n.match(/^[^\\\/\<\>:]+$/);
- }
- /**
- * Return true if file with this name exists
- *
- * @param String file/folder name
- * @return Boolean
- */
- this.fileExists = function(n) {
- if(this.cdc.type != 'folder') return false;
- for (var i in this.cdc) {
- if (this.cdc[i].name == n) {
- return i;
- }
- }
- return false;
- }
- /**
- * Return name for new file/folder
- *
- * @param String base name (i18n)
- * @param String extension for file
- * @return String
- */
- this.uniqueName = function(n, ext) {
- n = self.i18n(n);
- var name = n, i = 0, ext = ext||'';
- if (!this.fileExists(name+ext)) {
- return name+ext;
- }
- while (i++<100) {
- if (!this.fileExists(name+i+ext)) {
- return name+i+ext;
- }
- }
- return name.replace('100', '')+Math.random()+ext;
- }
- this.time = function() {
- return new Date().getMilliseconds();
- }
- /* here we init file manager */
- this.setView(this.cookie(this.vCookie));
- //resize(self.options.width, self.options.height);
- // w && self.view.win.width(w);
- // h && self.view.nav.add(self.view.cwd).height(h);
- this.ajax({
- cmd : 'open',
- target : this.options.startDir,
- init : true,
- tree : true
- },
- function(data) {
- //if (data.cwd) {
- if((!self.options.startDir || data.cwd.hash!=self.options.startDir) && data.cwd.hash != 'Error'){
- document.location='/'+data.cwd.hash;
- //window.History.replaceState({fn:'elfinder.go', data:{cmd:'open',target:data.cwd.hash,tree:true}}, data.cwd.name, data.cwd.hash);
- //return;
- }
- self.eventsManager.init();
- self.reload(data);
- self.params = data.params;
- // self.log(self.params)
- $('*', document.body).each(function() {
- var z = parseInt($(this).css('z-index'));
- if (z >= self.zIndex) {
- self.zIndex = z+1;
- }
- });
- //if(window.History)window.History.pushState({fn:'elfinder.open',data:data},self.cwd.name,'/'+self.cwd.hash);
- self.ui.init();
- //}
- }, {force : true});
- }
- /**
- * Translate message into selected language
- *
- * @param String message in english
- * @param String translated or original message
- */
- elFinder.prototype.i18n = function(m) {
- return this.options.i18n[this.options.lang] && this.options.i18n[this.options.lang][m] ? this.options.i18n[this.options.lang][m] : m;
- }
- /**
- * Default config
- *
- */
- elFinder.prototype.options = {
- /* connector url. Required! */
- url : '',
- startDir : '',
- templates : {},
- /* interface language */
- lang : 'en',
- /* additional css class for filemanager container */
- cssClass : '',
- /* characters number to wrap file name in icon view. set to 0 to disable wrap */
- wrap : 14,
- /* i18 messages. not set manually! */
- i18n : {},
- /* fm view (icon|list) */
- view : 'list',
- /* disable shortcuts exclude arrows/space */
- disableShortcuts : false,
- /* cookie options */
- cookie : {
- expires : 30,
- domain : '',
- path : '/',
- secure : false
- },
- /* buttons on toolbar */
- toolbar : [
- //['back', 'reload'],
- ['select', 'open'],
- ['mkdir', 'mkfile', 'upload', 'remote'],
- ['copy', 'paste', 'rm'],
- ['rename', 'edit'],
- //['info', 'quicklook'],
- ['list', 'icon'],
- //['help']
- ],
- /* contextmenu commands */
- contextmenu : {
- 'cwd' : ['get_link', 'delim', 'reload', 'delim', 'mkdir', 'upload', 'remote', 'delim', 'paste', 'delim', 'info'],
- 'file' : ['get_link', 'delim', 'open', 'delim', 'copy', 'cut', 'rm', 'delim', 'duplicate', 'rename', 'delim', 'info'],
- 'group' : ['get_link', 'delim', 'copy', 'cut', 'rm', 'delim', 'duplicate', 'delim', 'info']
- },
- /* auto reload time (min) */
- autoReload : 0
- }
- $.fn.elfinder = function(o) {
- return this.each(function() {
- var cmd = typeof(o) == 'string' ? o : '';
- if (!this.elfinder) {
- this.elfinder = new elFinder(this, typeof(o) == 'object' ? o : {})
- }
- switch(cmd) {
- case 'close':
- case 'hide':
- this.elfinder.close();
- break;
- case 'open':
- case 'show':
- this.elfinder.open();
- break;
- }
- })
- }
- })(jQuery);
- /**
- * @class Display stuff
- * @author dio dio@std42.ru
- **/
- (function($) {
- elFinder.prototype.view = function(fm, el) {
- var self = this;
- this.fm = fm;
- /**
- * Object. Mimetypes to kinds mapping
- **/
- this.kinds = {
- 'unknown' : 'Unknown',
- 'directory' : 'Folder',
- 'symlink' : 'Alias',
- 'symlink-broken' : 'Broken alias',
- 'application/x-empty' : 'Plain text',
- 'application/postscript' : 'Postscript document',
- 'application/octet-stream' : 'Application',
- 'application/vnd.ms-office' : 'Microsoft Office document',
- 'application/vnd.ms-word' : 'Microsoft Word document',
- 'application/vnd.ms-excel' : 'Microsoft Excel document',
- 'application/vnd.ms-powerpoint' : 'Microsoft Powerpoint presentation',
- 'application/pdf' : 'Portable Document Format (PDF)',
- 'application/vnd.oasis.opendocument.text' : 'Open Office document',
- 'application/x-shockwave-flash' : 'Flash application',
- 'application/xml' : 'XML document',
- 'application/x-bittorrent' : 'Bittorrent file',
- 'application/x-7z-compressed' : '7z archive',
- 'application/x-tar' : 'TAR archive',
- 'application/x-gzip' : 'GZIP archive',
- 'application/x-bzip2' : 'BZIP archive',
- 'application/zip' : 'ZIP archive',
- 'application/x-rar' : 'RAR archive',
- 'application/javascript' : 'Javascript application',
- 'text/plain' : 'Plain text',
- 'text/x-php' : 'PHP source',
- 'text/html' : 'HTML document',
- 'text/javascript' : 'Javascript source',
- 'text/css' : 'CSS style sheet',
- 'text/rtf' : 'Rich Text Format (RTF)',
- 'text/rtfd' : 'RTF with attachments (RTFD)',
- 'text/x-c' : 'C source',
- 'text/x-c++' : 'C++ source',
- 'text/x-shellscript' : 'Unix shell script',
- 'text/x-python' : 'Python source',
- 'text/x-java' : 'Java source',
- 'text/x-ruby' : 'Ruby source',
- 'text/x-perl' : 'Perl script',
- 'text/xml' : 'XML document',
- 'image/x-ms-bmp' : 'BMP image',
- 'image/jpeg' : 'JPEG image',
- 'image/gif' : 'GIF Image',
- 'image/png' : 'PNG image',
- 'image/x-targa' : 'TGA image',
- 'image/tiff' : 'TIFF image',
- 'image/vnd.adobe.photoshop' : 'Adobe Photoshop image',
- 'audio/mpeg' : 'MPEG audio',
- 'audio/midi' : 'MIDI audio',
- 'audio/ogg' : 'Ogg Vorbis audio',
- 'audio/mp4' : 'MP4 audio',
- 'audio/wav' : 'WAV audio',
- 'video/x-dv' : 'DV video',
- 'video/mp4' : 'MP4 video',
- 'video/mpeg' : 'MPEG video',
- 'video/x-msvideo' : 'AVI video',
- 'video/quicktime' : 'Quicktime video',
- 'video/x-ms-wmv' : 'WM video',
- 'video/x-flv' : 'Flash video',
- 'video/x-matroska' : 'Matroska video'
- }
- this.tlb = $('<ul />');
- this.nav = $('<div class="el-finder-nav"/>').resizable({handles : 'e', autoHide : true, minWidth : 200, maxWidth: 500});
- this.cwd = $('<div class="el-finder-cwd"/>').attr('unselectable', 'on');
- this.spn = $('<div class="el-finder-spinner"/>');
- this.err = $('<p class="el-finder-err"><strong/></p>').click(function() { $(this).hide(); });
- this.msg = $('<p class="el-finder-msg"><strong/></p>').click(function() { $(this).hide(); });
- this.wrz = $('<div class="el-finder-workzone"/>')
- .append(this.nav)
- .append(this.cwd)
- .append(this.spn)
- .append(this.err)
- .append(this.msg)
- .append('<div style="clear:both"/>');
- this.win = $(el).empty().attr('id', this.fm.id).addClass('el-finder '+(fm.options.cssClass||''))
- .append($('<div class="el-finder-toolbar"/>').append(this.tlb))
- .append(this.wrz);
- //.append(this.stb);
- this.tree = $('<ul class="el-finder-tree"></ul>').appendTo(this.nav);
- this.uploads = $('#FileUploadFiles').detach().appendTo(this.nav).prepend('<hr/>');
- this.nav.append('<div style="text-align:center;"><div style="width:160px;height:600px;background:#999;margin:0 auto;">Banner AD 160x600</div></div>');
- /*
- * Render ajax spinner
- */
- this.spinner = function(show) {
- this.win.toggleClass('el-finder-disabled', show);
- this.spn.toggle(show);
- }
- /*
- * Display ajax error
- */
- this.fatal = function(t) {
- self.error(t.status != '404' ? 'Invalid backend configuration' : 'Unable to connect to backend')
- }
- /*
- * Render error
- */
- this.error = function(err, data) {
- this.fm.lock();
- this.err.show().children('strong').html(this.fm.i18n(err)+' '+this.formatErrorData(data));
- setTimeout(function() { self.err.fadeOut('slow'); }, 4000);
- }
- /*
- * Render message
- */
- this.message = function(msg) {
- this.fm.lock();
- this.msg.show().children('strong').html(msg);
- setTimeout(function() { self.msg.fadeOut('slow'); }, 4000);
- }
- /*
- * Render navigation panel with dirs tree
- */
- this.renderNav = function(data) {
- var self = this;
- if(!data.tree_expanded){
- data.tree_expanded = [];
- this.tree.find('ul:visible:not(:first)').each(function(){
- data.tree_expanded.push($(this).parent().find('a').attr('key'));
- });
- }
- if(data.treeEntryPoint){
- x = this.tree.find('a[key='+data.treeEntryPoint+']');
- x.parent().find('a[key]').each(function(k, v){
- delete self.fm.tree[v.getAttribute('key')];
- });
- x.parent().replaceWith(traverse(data.tree, false).find('li:first'));
- }
- else {
- this.fm.tree = {};
- this.tree.html(traverse(data.tree, true));
- }
- if(data.tree_expanded){
- for(var i in data.tree_expanded) {
- this.tree.find('[key='+data.tree_expanded[i]+']').find('div').addClass('expanded').parent().next('ul').show();
- }
- }
- function traverse(tree, root) {
- var i, hash, c, ul = $('<ul/>'), li;
- root || ul.css({display:'none'});
- for(i = 0; i < tree.length; i++) {
- if(tree[i] == 'delim') {
- $('<li><hr/></li>').appendTo(ul);
- continue;
- }
- self.fm.tree[tree[i].hash] = tree[i];
- c = '';
- if(!tree[i].read && !tree[i].write) c = 'noaccess';
- else if(!tree[i].read) c = 'dropbox';
- else if(!tree[i].write) c = 'readonly';
- if(tree[i].type == 'file') c += ' el-finder-nav-file';
- li = $('<li><a href="/'+tree[i].hash+'" class="'+c+'" key="'+tree[i].hash+'"><div'+(tree[i].dirs.length ? ' class="collapsed"' : '')+'/>'+tree[i].name+'</a></li>');
- if (tree[i].dirs.length) {
- li.append(traverse(tree[i].dirs));
- }
- //if(root && i == 0) li.append('<hr/>');
- li.appendTo(ul);
- }
- return ul;
- }
- }
- /*
- * Render current directory
- */
- this.renderCwd = function() {
- this.cwd.empty();
- switch(this.fm.cwd.type) {
- default:
- return alert('elFinder.renderCwd('+this.cwd.type+') not implemented yet');
- case 'file':
- return this.renderFile();
- case 'template':
- return this.renderTemplate();
- case 'folder':
- return this.renderFolder();
- }
- /*var s = '', hash = this.fm.cwd.hash, e, i;
- for(;;) {
- i = this.tree.find('[key='+hash+']');
- if(!i.length) break;
- s = '/<a href="/'+hash+'/" key="'+hash+'">'+i.text()+'</a>'+s;
- i = i.parent('li').parent('ul').prev();
- hash = i.attr('key');
- }*/
- }
- this.renderFile = function() {
- this.renderTemplate('cwd-info');
- this.renderTemplate('file');
- if(this.fm.cwd.session.init_status == 'wait') {
- var wait = this.fm.cwd.session.time_waiting,
- interval = setInterval(function(){
- if(--wait <= 0){
- clearInterval(interval);
- $('#WaitForDownloadTicket').hide().next().show();
- return;
- }
- $('#WaitForDownloadTicket span').html(wait);
- }, 1000);
- }
- if(this.fm.cwd.session.init_status != 'ok') return;
- switch(this.fm.cwd.session.mime_class) {
- case 'txt':
- $('.text-tab').click(function(){{
- $('.text-tab').removeClass('active');
- $('.text-content').hide();
- $(this).addClass('active');
- $('#'+this.getAttribute('data-id')).show();
- }});
- $.getJSON(
- this.fm.cwd.session.link_special+'?cb=?',
- function(d){{
- if(d.code)$('#text-code').html(unescape(d.code));
- else $('.text-code').remove();
- $('#text-plain,#text-edit textarea').html(unescape(d.plain));
- $('.text-tab.text-'+(d.code?'code':'plain')).trigger('click');
- $('#TextView')
- .tabs()
- .show();
- }}
- );
- break;
- case 'flv':
- case 'mp4':
- var playlist = [];
- this.fm.cwd.session.splash && playlist.push({url:this.fm.cwd.session.splash, autoPlay:true});
- playlist.push({url:this.fm.cwd.session.link_special, autoPlay:false});
- $f('FlashVideoPlayer','/lib/swf/flowplayer-3.2.7.swf',{
- pageUrl:'/'+this.fm.cwd.hash,
- playlist:playlist,
- plugins:{
- flvseek:{url:'/lib/swf/flowplayer.pseudostreaming-3.2.7.swf'},
- controls:{url:'/lib/swf/flowplayer.controls-3.2.5.swf'},
- sharing:{
- url:'/lib/swf/flowplayer.sharing-3.2.1.swf',
- embed:false,
- email:{subject:'Found a nice video on {BASE_DOMAIN}'}
- }
- }
- });
- break;
- case 'mp3':
- $f('FlashAudioPlayer','/lib/swf/flowplayer-3.2.7.swf',{
- clip:{
- url:this.fm.cwd.session.link_special,
- autoPlay:false
- },
- plugins:{
- controls:{
- url:'/lib/swf/flowplayer.controls-3.2.5.swf',
- fullscreen:false,
- height:30,
- autoHide:false
- },
- audio:{url:'/lib/swf/flowplayer.audio-3.2.2.swf'}
- }
- });
- break;
- }
- }
- this.renderTemplate = function(name, opts) {
- if(name == 'cwd-info' && typeof(this.fm.cwd.pth) == 'undefined') {
- this.fm.cwd.pth = [];
- var self = this, hash;
- this.tree
- .find('[key='+this.fm.cwd.hash+']')
- .parents('ul').each(function(i, e) {
- hash = $(e).prev().attr('key');
- if(hash)self.fm.cwd.pth.push(hash);
- });
- this.fm.cwd.pth.reverse();
- }
- var tmpl = $.tmpl('FM-'+(name||this.fm.cdc.template), $.extend({self:this, tree:this.fm.tree, cwd:this.fm.cwd, cdc:this.fm.cdc}, opts||{}))
- .appendTo(this.cwd)
- .wrap('<div class="el-finder-template"/>');
- if(name == 'cwd-info') this.fm.eventsManager.updateCwdInfo(tmpl);
- this.fm.eventsManager.updateCwdTemplate(tmpl);
- }
- this.renderFolder = function() {
- if(!this.fm.cwd.system) this.renderTemplate('cwd-info');
- var self = this,
- num = 0,
- size = 0,
- t = $('<div class="el-finder-list"/>').append(this.renderTableHeader(this.fm.cwd.columns, true)),
- u = this.fm.options.view == 'list' ? t.find('table') : t;
- for (var hash in this.fm.cdc) {
- size += Number(this.fm.cdc[hash].size);
- this.renderItem(this.fm.options.view, this.fm.cdc[hash], num++%2).appendTo(u);
- }
- t.appendTo(this.cwd);
- if(!num) {
- t.hide();
- this.fm.cwd.empty = true;
- this.fm.cwd.write && this.renderTemplate('empty-folder');
- return;
- }
- if(num == 1 && this.fm.options.view == 'icon') t.find('table').hide();
- this.fm.eventsManager.updateCwdMore();
- }
- this.renderTableHeader = function(columns, order) {
- var tmpl = $.tmpl(
- 'FM-item-table-header',
- {
- self:this,
- cwd:this.fm.cwd,
- tableOrder:order
- });
- if(order) {
- tmpl.find('th').css({cursor:'pointer'}).click(function(){self.fm.setOrder($(this).attr('orderCol'));})
- tmpl.find('[orderCol='+this.fm.options.order.replace(/^-/,'')+']').addClass(this.fm.options.order.match(/^-/) ? 'desc' : 'asc');
- }
- return tmpl;
- }
- this.renderItem = function(tmpl, item, odd) {
- return $.tmpl(
- 'FM-item-'+tmpl,
- {
- self : this,
- cwd : this.fm.cwd,
- mimeSize: 'big',
- odd : odd||false,
- f : item,
- img : item.ico||item.tmb||false,
- mimeStr : this.mime2class(item.mime)
- });
- }
- /*
- * Re-render file (after editing)
- */
- this.updateFile = function(f) {
- this.cwd.find('[key="'+f.hash+'"]').replaceWith(renderItem(this.fm.options.view, f, false));
- }
- /*
- * Return wraped file name if needed
- */
- this.formatName = function(n) {
- var w = self.fm.options.wrap;
- if (w>0) {
- if (n.length > w*2) {
- return n.substr(0, w)+"­"+n.substr(w, w-5)+"…"+n.substr(n.length-3);
- } else if (n.length > w) {
- return n.substr(0, w)+"­"+n.substr(w);
- }
- }
- return n;
- }
- /*
- * Return error message
- */
- this.formatErrorData = function(data) {
- var i, err = ''
- if (typeof(data) == 'object') {
- err = '<br />';
- for (i in data) {
- err += i+' '+self.fm.i18n(data[i])+'<br />';
- }
- }
- return err;
- }
- /*
- * Convert mimetype into css class
- */
- this.mime2class = function(mime) {
- return String(mime).replace('/' , ' ').replace(/\./g, '-');
- }
- /*
- * Return localized date
- */
- this.formatTime = function(d) {
- return d ? d.replace(/([a-z]+)\s/i, function(a1, a2) { return self.fm.i18n(a2)+' '; }) : '';
- }
- /*
- * Return formated file size
- */
- this.formatSize = function(s) {
- if(!s) return 0;
- var n = 1, u = '';
- if (s > 1073741824) {
- n = 1073741824;
- u = 'Gb';
- } else if (s > 1048576) {
- n = 1048576;
- u = 'Mb';
- } else if (s > 1024) {
- n = 1024;
- u = 'Kb';
- }
- return Math.round(s/n)+' '+u;
- }
- /*
- * Return kind of file
- */
- this.mime2kind = function(mime) {
- return this.fm.i18n(this.kinds[mime]||'unknown');
- }
- }
- })(jQuery);
- /**
- * @class elFinder user Interface.
- * @author dio dio@std42.ru
- **/
- (function($) {
- elFinder.prototype.ui = function(fm) {
- var self = this;
- this.fm = fm;
- this.cmd = {};
- this.buttons = {};
- this.menu = $('<div class="el-finder-contextmenu" />').appendTo(document.body).hide();
- this.exec = function(cmd, arg) {
- if (this.cmd[cmd]) {
- if (!this.fm.locked) {
- $('.el-finder-info').remove();
- this.cmd[cmd].exec(arg);
- this.update();
- }
- }
- }
- this.cmdName = function(cmd) {
- if (this.cmd[cmd] && this.cmd[cmd].name) {
- return this.fm.i18n(this.cmd[cmd].name);
- }
- return cmd;
- }
- this.isCmdAllowed = function(cmd) {
- return self.cmd[cmd] && self.cmd[cmd].isAllowed();
- }
- this.execIfAllowed = function(cmd) {
- this.isCmdAllowed(cmd) && this.exec(cmd);
- }
- this.includeInCm = function(cmd, t) {
- return this.isCmdAllowed(cmd) && this.cmd[cmd].cm(t);
- }
- this.showMenu = function(e) {
- var t, win, size, id = '';
- this.hideMenu();
- if (!self.fm.selected.length) {
- t = 'cwd';
- } else if (self.fm.selected.length == 1) {
- t = 'file';
- } else {
- t = 'group';
- }
- menu(t);
- win = $(window);
- size = {
- sT : win.scrollTop(),
- cW : this.menu.width(),
- cH : this.menu.height()
- };
- this.menu
- .css({
- left : ((e.clientX + size.cW) > size.width ? ( e.clientX - size.cW) : e.clientX),
- top : ((e.clientY + size.cH) > size.height && e.clientY > size.cH ? (e.clientY + size.sT - size.cH) : e.clientY + size.sT)
- })
- .show()
- .find('div[name]')
- .hover(
- function() {
- var t = $(this), s = t.children('div'), w;
- t.addClass('hover');
- if (s.length) {
- if (!s.attr('pos')) {
- w = t.outerWidth();
- s.css($(window).width() - w - t.offset().left > s.width() ? 'left' : 'right', w-5).attr('pos', true);
- }
- s.show();
- }
- },
- function() { $(this).removeClass('hover').children('div').hide(); }
- ).click(function(e) {
- e.stopPropagation();
- var t = $(this);
- if (!t.children('div').length) {
- self.hideMenu();
- self.exec(t.attr('name'), t.attr('argc'));
- }
- });
- // self.fm.log(self.menu.html())
- function menu(t) {
- var i, j, a, html, l, src = self.fm.options.contextmenu[t]||[];
- for (i=0; i < src.length; i++) {
- if (src[i] == 'delim') {
- self.menu.children().length && !self.menu.children(':last').hasClass('delim') && self.menu.append('<div class="delim" />');
- } else if (self.fm.ui.includeInCm(src[i], t)) {
- a = self.cmd[src[i]].argc();
- html = '';
- if (a.length ) {
- html = '<span/><div class="el-finder-contextmenu-sub" style="z-index:'+(parseInt(self.menu.css('z-index'))+1)+'">';
- for (var j=0; j < a.length; j++) {
- html += '<div name="'+src[i]+'" argc="'+a[j].argc+'" class="'+a[j]['class']+'">'+a[j].text+'</div>';
- };
- html += '</div>';
- }
- self.menu.append('<div class="'+src[i]+'" name="'+src[i]+'">'+html+self.cmdName(src[i])+'</div>');
- }
- };
- }
- }
- this.hideMenu = function() {
- this.menu.hide().empty();
- }
- this.update = function() {
- for (var i in this.buttons) {
- this.buttons[i].toggleClass('disabled', !this.cmd[i].isAllowed());
- }
- }
- this.init = function() {
- var i, j, n, c=false, zindex = 2, z, fm=this.fm, t = fm.options.toolbar, name;
- for (i in this.commands) {
- this.commands[i].prototype = this.command.prototype;
- this.cmd[i] = new this.commands[i](this.fm);
- }
- for (i=0; i<t.length; i++) {
- if (c) {
- this.fm.view.tlb.append('<li class="delim"></li>');
- }
- c = false;
- for (j=0; t[i] && j<t[i].length; j++) {
- n = t[i][j];
- if (this.cmd[n]) {
- c = true;
- name = this.cmdName(n);
- this.buttons[n] = $('<li class="'+n+'" name="'+n+'"><p/>'+name+'</li>')
- .appendTo(this.fm.view.tlb)
- .click(function(e) { e.stopPropagation(); })
- .bind('click', (function(ui){ return function() {
- !$(this).hasClass('disabled') && ui.exec($(this).attr('name'));
- } })(this)
- ).hover(
- function() { !$(this).hasClass('disabled') && $(this).addClass('el-finder-tb-hover')},
- function() { $(this).removeClass('el-finder-tb-hover')}
- );
- if(n=='upload')
- this.buttons[n].mouseover(function(){
- if(fm.cwd.write && fm.cwd.type == 'folder')
- if($.browser.opera)fileinputFuckaround(this);
- });
- }
- }
- }
- this.update();
- /* set z-index for context menu */
- this.menu.css('z-index', this.fm.zIndex);
- }
- }
- /**
- * @class elFinder user Interface Command.
- * @author dio dio@std42.ru
- **/
- elFinder.prototype.ui.prototype.command = function(fm) { }
- /**
- * Return true if command can be applied now
- * @return Boolean
- **/
- elFinder.prototype.ui.prototype.command.prototype.isAllowed = function() {
- return true;
- }
- /**
- * Return true if command can be included in contextmenu of required type
- * @param String contextmenu type (cwd|group|file)
- * @return Boolean
- **/
- elFinder.prototype.ui.prototype.command.prototype.cm = function(t) {
- return false;
- }
- /**
- * Return not empty array if command required submenu in contextmenu
- * @return Array
- **/
- elFinder.prototype.ui.prototype.command.prototype.argc = function(t) {
- return [];
- }
- elFinder.prototype.ui.prototype.commands = {
- /**
- * @class Go into previous folder
- * @param Object elFinder
- **/
- back : function(fm) {
- var self = this;
- this.name = 'Back';
- this.fm = fm;
- this.exec = function() {
- window.history.back();
- }
- this.isAllowed = function() {
- return true;
- }
- },
- /**
- * @class Reload current directory and navigation panel
- * @param Object elFinder
- **/
- reload : function(fm) {
- var self = this;
- this.name = 'Reload';
- this.fm = fm;
- this.exec = function() {
- this.fm.ajax({ cmd : 'open', target : this.fm.cwd.hash, tree : true }, function(data) {
- self.fm.reload(data);
- });
- }
- this.cm = function(t) {
- return t == 'cwd';
- }
- },
- /**
- * @class Open file/folder
- * @param Object elFinder
- **/
- open : function(fm) {
- var self = this;
- this.name = 'Open';
- this.fm = fm;
- /**
- * Open file/folder
- * @param String file/folder id (only from click on nav tree)
- **/
- this.exec = function(dir) {
- var t = null;
- if (dir) {
- t = self.fm.tree[$(dir).attr('key')];
- } else {
- t = this.fm.getSelected(0);
- }
- if (!t.hash) {
- return;
- }
- if (!t.read) {
- return this.fm.view.error('Access denied');
- }
- /*if (t.type == 'link' && !t.link) {
- return this.fm.view.error('Unable to open broken link');
- }*/
- open(t);
- /*if (t.mime == 'directory') {
- openDir(t.link||t.hash);
- } else {
- openFile(t);
- }*/
- function open(t) {
- /*for(x in t) alert(x+'='+t[x]+'; ');
- alert(''+self.fm.cwd.type+' = '+t+' = '+((self.fm.cwd.type == 'file' || t.type == 'file') ? true : false ))*/
- self.fm.openHistory({
- name:t.name,
- hash:t.hash,
- //tree:false
- tree:t.type != 'folder' || self.fm.cwd.type != 'folder'
- });
- }
- function openFile(f) {
- window.open('/'+f.hash, false, 'top=50,left=50,scrollbars=yes,resizable=yes');
- return;
- var s, ws = '';
- if (f.dim) {
- s = f.dim.split('x');
- ws = 'width='+(parseInt(s[0])+20)+',height='+(parseInt(s[1])+20)+',';
- }
- window.open(f.url);
- }
- }
- this.isAllowed = function() {
- return this.fm.selected.length == 1 && this.fm.getSelected(0).read && this.fm.getSelected(0).exec;
- }
- this.cm = function(t) {
- return t == 'file';
- }
- },
- /**
- * @class Display files/folders info in dialog window
- * @param Object elFinder
- **/
- info : function(fm) {
- var self = this;
- this.name = 'Get info';
- this.fm = fm;
- /**
- * Open dialog windows for each selected file/folder or for current folder
- **/
- this.exec = function() {
- var f, s, cnt = this.fm.selected.length, w = $(window).width(), h = $(window).height();
- this.fm.lockShortcuts(true);
- if (!cnt) {
- /** nothing selected - show cwd info **/
- info(self.fm.cwd);
- } else {
- /** show info for each selected obj **/
- $.each(this.fm.getSelected(), function() {
- info(this);
- });
- }
- function info(f) {
- var p = ['50%', '50%'], x, y, d,
- tb = '<table cellspacing="0"><tr><td>'+self.fm.i18n('Name')+'</td><td>'+f.name+'</td></tr><tr><td>'+self.fm.i18n('Link')+'</td><td><a href="/'+f.hash+'">/'+f.hash+'</a></td></tr><tr><td>'+self.fm.i18n('Kind')+'</td><td>'+self.fm.view.mime2kind(f.link ? 'symlink' : f.mime)+'</td></tr><tr><td>'+self.fm.i18n('Size')+'</td><td>'+self.fm.view.formatSize(f.size)+'</td></tr><tr><td>'+self.fm.i18n('Modified')+'</td><td>'+self.fm.view.formatDate(f.time)+'</td></tr><tr><td>'+self.fm.i18n('Hits')+'</td><td>'+(f.hits||0)+'</td></tr>';
- if (f.link) {
- tb += '<tr><td>'+self.fm.i18n('Link to')+'</td><td>'+f.linkTo+'</td></tr>';
- }
- if (f.dim) {
- tb += '<tr><td>'+self.fm.i18n('Dimensions')+'</td><td>'+f.dim+' px.</td></tr>';
- }
- if (f.url) {
- tb += '<tr><td>'+self.fm.i18n('URL')+'</td><td><a href="'+f.url+'" target="_blank">'+f.url+'</a></td></tr>';
- }
- if (cnt>1) {
- d = $('.el-finder-dialog-info:last');
- if (!d.length) {
- x = Math.round(((w-350)/2)-(cnt*10));
- y = Math.round(((h-300)/2)-(cnt*10));
- p = [x>20?x:20, y>20?y:20];
- } else {
- x = d.offset().left+10;
- y = d.offset().top+10;
- p = [x<w-350 ? x : 20, y<h-300 ? y : 20];
- }
- }
- $('<div />').append(tb+'</table>').dialog({
- dialogClass : 'el-finder-dialog el-finder-dialog-info',
- width : 390,
- position : p,
- title : self.fm.i18n(f.mime == 'directory' ? 'Folder info' : 'File info'),
- close : function() { if (--cnt <= 0) { self.fm.lockShortcuts(); } $(this).dialog('destroy'); },
- buttons : { Ok : function() { $(this).dialog('close'); }}
- });
- }
- }
- this.cm = function(t) {
- return this.fm.cwd.type == 'folder';
- }
- },
- /**
- * @class Rename file/folder
- * @param Object elFinder
- **/
- rename : function(fm) {
- var self = this;
- this.name = 'Rename';
- this.fm = fm;
- this.exec = function() {
- var s = this.fm.getSelected(), el, c, input, f, n;
- if (s.length == 1) {
- f = s[0];
- el = this.fm.view.cwd.find('[key="'+f.hash+'"]');
- c = this.fm.options.view == 'icon' ? el.children('label') : el.find('td').eq(1);
- n = c.html();
- input = $('<input type="text" />').css({width:'100%'}).val(f.name).appendTo(c.empty())
- .bind('change blur', rename)
- .keydown(function(e) {
- e.stopPropagation();
- if (e.keyCode == 27) {
- restore();
- } else if (e.keyCode == 13) {
- if (f.name == input.val()) {
- restore();
- } else {
- $(this).trigger('change');
- }
- }
- })
- .click(function(e) { e.stopPropagation(); })
- .select()
- .focus();
- this.fm.lockShortcuts(true);
- }
- function restore() {
- c.html(n);
- self.fm.lockShortcuts();
- }
- function rename() {
- if (!self.fm.locked) {
- var err, name = input.val();
- if (f.name == input.val()) {
- return restore();
- }
- if (!self.fm.isValidName(name)) {
- err = 'Invalid name';
- }/* else if (self.fm.fileExists(name)) {
- err = 'File or folder with the same name already exists';
- }*/
- if (err) {
- self.fm.view.error(err);
- el.addClass('ui-selected');
- self.fm.lockShortcuts(true);
- return input.select().focus();
- }
- self.fm.ajax({cmd : 'rename', current : self.fm.cwd.hash, target : f.hash, new_name : name}, function(data) {
- if (data.error) {
- restore();
- } else {
- self.fm.reload(data);
- }
- }, { force : true });
- }
- }
- }
- /**
- * Return true if only one file selected and has write perms and current dir has write perms
- * @return Boolean
- */
- this.isAllowed = function() {
- return this.fm.cwd.write && this.fm.getSelected(0).write;
- }
- this.cm = function(t) {
- return t == 'file';
- }
- },
- /**
- * @class Copy file/folder to "clipboard"
- * @param Object elFinder
- **/
- copy : function(fm) {
- this.name = 'Copy';
- this.fm = fm;
- this.exec = function() {
- this.fm.setBuffer(this.fm.selected);
- }
- this.isAllowed = function() {
- if (this.fm.selected.length) {
- var s = this.fm.getSelected(), l = s.length;
- while (l--) {
- if (!s[l].system && s[l].read) {
- return true;
- }
- }
- }
- return false;
- }
- this.cm = function(t) {
- return t != 'cwd';
- }
- },
- /**
- * @class Cut file/folder to "clipboard"
- * @param Object elFinder
- **/
- cut : function(fm) {
- this.name = 'Cut';
- this.fm = fm;
- this.exec = function() {
- this.fm.setBuffer(this.fm.selected, 1);
- }
- this.isAllowed = function() {
- if (this.fm.selected.length) {
- var s = this.fm.getSelected(), l = s.length;
- while (l--) {
- if (s[l].read && s[l].rm) {
- return true;
- }
- }
- }
- return false;
- }
- this.cm = function(t) {
- return t != 'cwd';
- }
- },
- /**
- * @class Paste file/folder from "clipboard"
- * @param Object elFinder
- **/
- paste : function(fm) {
- var self = this;
- this.name = 'Paste';
- this.fm = fm;
- this.exec = function() {
- var i, d, f, r, msg = '';
- if (!this.fm.buffer.dst) {
- this.fm.buffer.dst = this.fm.cwd.hash;
- }
- d = this.fm.view.tree.find('[key="'+this.fm.buffer.dst+'"]');
- if (!d.length || d.hasClass('noaccess') || d.hasClass('readonly')) {
- return this.fm.view.error('Access denied');
- }
- var o = {
- cmd : 'paste',
- current : this.fm.cwd.hash,
- src : this.fm.buffer.src,
- dst : this.fm.buffer.dst,
- targets : this.fm.buffer.files,
- cut : this.fm.buffer.cut
- };
- this.fm.ajax(o, function(data) {
- data.cdc && self.fm.reload(data);
- }, {force : true});
- }
- this.isAllowed = function() {
- return this.fm.cwd.write && this.fm.cwd.type == 'folder' && this.fm.buffer.files;
- }
- this.cm = function(t) {
- return t == 'cwd' && this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- },
- /**
- * @class Remove files/folders
- * @param Object elFinder
- **/
- rm : function(fm) {
- var self = this;
- this.name = 'Remove';
- this.fm = fm;
- this.exec = function() {
- var i, ids = [], s =this.fm.getSelected();
- for (var i=0; i < s.length; i++) {
- if (!s[i].rm) {
- return this.fm.view.error(s[i].name+': '+this.fm.i18n('Access denied'));
- }
- ids.push(s[i].hash);
- };
- if (ids.length) {
- this.fm.lockShortcuts(true);
- $('<div><div class="ui-state-error ui-corner-all"><span class="ui-icon ui-icon-alert"/><strong>'+this.fm.i18n('Are you shure you want to remove files?<br /> This cannot be undone!')+'</strong></div></div>')
- .dialog({
- title : this.fm.i18n('Confirmation required'),
- dialogClass : 'el-finder-dialog',
- width : 350,
- close : function() { self.fm.lockShortcuts(); },
- buttons : {
- Cancel : function() { $(this).dialog('close'); },
- Ok : function() {
- $(this).dialog('close');
- var o = { cmd : 'rm', current : self.fm.cwd.hash };
- if (self.fm.jquery > 132) {
- o.targets = ids;
- } else {
- o['targets[]'] = ids;
- }
- self.fm.ajax(o, function(data) { data.tree && self.fm.reload(data); }, {force : true});
- }
- }
- });
- }
- }
- this.isAllowed = function(f) {
- if (this.fm.selected.length) {
- var s = this.fm.getSelected(), l = s.length;
- while (l--) {
- if (s[l].rm) {
- return true;
- }
- }
- }
- return false;
- }
- this.cm = function(t) {
- return t != 'cwd';
- }
- },
- /**
- * @class Create new folder
- * @param Object elFinder
- **/
- mkdir : function(fm) {
- var self = this;
- this.name = 'New folder';
- this.fm = fm;
- this.exec = function() {
- self.fm.unselectAll();
- var n = this.fm.uniqueName('Untitled folder');
- input = $('<input type="text"/>').val(n);
- prev = this.fm.view.cwd.find('.el-finder-list .directory:last');
- f = {name : n, hash : '', mime :'directory', read : true, write : true, date : '', size : 0},
- el = this.fm.options.view == 'list'
- ? $(this.fm.view.renderItem(this.fm.options.view, f)).children('td').eq(1).empty().append(input).end().end()
- : this.fm.view.renderItem(this.fm.options.view, f).children('label').empty().append(input).end()
- el.addClass('directory ui-selected');
- if(this.fm.cwd.empty)this.fm.view.cwd.find('.el-finder-list').show();
- //this.fm.view.cwd.find('el-finder-list').show();
- if (prev.length) {
- el.insertAfter(prev);
- } else if (this.fm.options.view == 'list') {
- el.insertAfter(this.fm.view.cwd.find('.el-finder-list tr').eq(0))
- } else {
- el.insertAfter(this.fm.view.cwd.find('.el-finder-list table').eq(0));
- }
- self.fm.checkSelectedPos();
- input.select().focus()
- .click(function(e) { e.stopPropagation(); })
- .bind('change blur', mkdir)
- .keydown(function(e) {
- e.stopPropagation();
- if (e.keyCode == 27) {
- el.remove();
- if(self.fm.cwd.empty)self.fm.view.cwd.find('.el-finder-list').hide();
- self.fm.lockShortcuts();
- } else if (e.keyCode == 13) {
- mkdir();
- }
- });
- self.fm.lockShortcuts(true);
- function mkdir() {
- if (!self.fm.locked) {
- var err, name = input.val();
- if (!self.fm.isValidName(name)) {
- err = 'Invalid name';
- } else if (self.fm.fileExists(name)) {
- err = 'File or folder with the same name already exists';
- }
- if (err) {
- self.fm.view.error(err);
- self.fm.lockShortcuts(true);
- el.addClass('ui-selected');
- return input.select().focus();
- }
- self.fm.ajax({cmd : 'mkdir', current : self.fm.cwd.hash, name : name}, function(data) {
- if (data.error) {
- el.addClass('ui-selected');
- return input.select().focus();
- }
- self.fm.reload(data);
- }, {force : true});
- }
- }
- }
- this.isAllowed = function() {
- return this.fm.cwd.write && this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- this.cm = function(t) {
- return t == 'cwd' && this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- },
- /**
- * @class Upload files
- * @param Object elFinder
- **/
- upload : function(fm) {
- var self = this;
- this.name = 'Upload';
- this.fm = fm;
- this.exec = function() {
- if(!$.browser.opera)document.fileupload.file1.click();
- }
- this.isAllowed = function() {
- return this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- this.cm = function(t) {
- return t == 'cwd' && this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- },
- /**
- * @class Upload files
- * @param Object elFinder
- **/
- /*remote : function(fm) {
- var self = this;
- this.name = 'Remote upload';
- this.fm = fm;
- this.exec = function() {
- var self = this;
- this.fm.lockShortcuts(true);
- $('<textarea/>')
- .html('Paste your links here and click ok')
- .focus(function(){this.select();})
- .dialog({
- width : 617,
- title : this.fm.i18n(this.name),
- dialogClass : 'el-finder-dialog',
- modal : true,
- close : function() { self.fm.lockShortcuts(); d.tabs('destroy').dialog('destroy').remove() },
- buttons : {
- Ok : function() {
- self.fm.ajax({
- cmd : 'remote',
- current : self.fm.cwd.hash,
- links : this.value
- });
- $(this).dialog('close');
- },
- Cancel : function() { $(this).dialog('close'); }
- }
- })
- .css({width:'100%',height:'130px'});
- }
- this.isAllowed = function() {
- return this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- this.cm = function(t) {
- return t == 'cwd' && this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- },*/
- /**
- * @class Make file/folder copy
- * @param Object elFinder
- **/
- duplicate : function(fm) {
- var self = this;
- this.name = 'Duplicate';
- this.fm = fm;
- this.exec = function() {
- var i, ids = [], s =this.fm.getSelected();
- for (i=0; i < s.length; i++) {
- if(!s[i].read)return this.fm.view.error(s[i].name+': '+this.fm.i18n('Access denied'));
- ids.push(s[i].hash);
- };
- this.fm.ajax({
- cmd : 'duplicate',
- current : this.fm.cwd.hash,
- targets : ids
- },
- function(data) {
- self.fm.reload(data);
- });
- }
- this.isAllowed = function() {
- return this.fm.cwd.write && this.fm.cwd.type == 'folder';
- }
- this.cm = function(t) {
- return (t == 'file' || t == 'group') && this.fm.cwd.type == 'folder';
- }
- },
- /**
- * @class Get downloadlink
- * @param Object elFinder
- **/
- get_link : function(fm) {
- var self = this;
- this.name = 'Get link';
- this.fm = fm;
- this.exec = function() {
- var i, links = [], s = this.fm.getSelected(), clip=null, clipDom=null;
- this.fm.lockShortcuts(true);
- if(!s.length)s=[this.fm.cwd];
- if(!s.length)return this.fm.view.error(this.fm.i18n('No items selected'));
- for (i=0; i < s.length; i++)
- links.push(this.fm.options.downloadLinkFormat.replace(/%s/,s[i].hash));
- var d = $('<textarea/>')
- .html(links.join('\n'))
- .focus(function(){this.select()})
- .dialog({
- width : 617,
- title : this.fm.i18n('Downloadlinks'),
- dialogClass : 'el-finder-dialog',
- modal : true,
- buttons : [
- {
- id: 'get_link_dialog_clipboard',
- text: 'Copy to clipboard',
- click: function() { alert('Failed copying links to clipboard'); return false; }
- },
- {
- id: 'get_link_dialog_ok',
- text: 'Ok',
- click: function() { $(this).dialog('close'); }
- }
- ],
- open : function(){
- var d=$(this), p=d.parent(), t=p.find('#get_link_dialog_clipboard'),w=t.width(),h=t.height();
- clip = new ZeroClipboard.Client()
- clip.setHandCursor(true);
- clip.addEventListener('mouseDown',function(){
- clip.setText(d.val());
- });
- clip.addEventListener('onComplete',function(){
- if(clip)clip.destroy();
- d.dialog('close');
- });
- $('<div/>')
- .html(clip.getHTML(w, h+10))
- .css({
- position:'relative',
- marginBottom:-h,
- width:w,
- height:h,
- zIndex:1101
- })
- .insertBefore(t);
- },
- close : function(){
- self.fm.lockShortcuts();
- if(clip)clip.destroy();
- }
- })
- .css({width:'100%',height:'130px'});
- }
- this.isAllowed = function() {
- var s = this.fm.getSelected(0);
- return s.read && s.exec && !s.system;
- }
- this.cm = function(t) {
- return true;
- }
- },
- /**
- * @class Switch elFinder into icon view
- * @param Object elFinder
- **/
- icon : function(fm) {
- this.name = 'View as icons';
- this.fm = fm;
- this.exec = function() {
- this.fm.view.win.addClass('el-finder-disabled');
- this.fm.setView('icon');
- this.fm.updateCwd();
- this.fm.view.win.removeClass('el-finder-disabled');
- //$('div.image', this.fm.view.cwd).length && this.fm.tmb();
- }
- this.isAllowed = function() {
- return this.fm.options.view != 'icon' && this.fm.cwd.type == 'folder' && !this.fm.cwd.empty;
- }
- this.cm = function(t) {
- return t == 'cwd';
- }
- },
- /**
- * @class Switch elFinder into list view
- * @param Object elFinder
- **/
- list : function(fm) {
- this.name = 'View as list';
- this.fm = fm;
- this.exec = function() {
- this.fm.view.win.addClass('el-finder-disabled');
- this.fm.setView('list');
- this.fm.updateCwd();
- this.fm.view.win.removeClass('el-finder-disabled');
- }
- this.isAllowed = function() {
- return this.fm.options.view != 'list' && this.fm.cwd.type == 'folder' && !this.fm.cwd.empty;
- }
- this.cm = function(t) {
- return t == 'cwd';
- }
- },
- help : function(fm) {
- this.name = 'Help';
- this.fm = fm;
- this.exec = function() {
- var h, ht = this.fm.i18n('helpText'), a, s, tabs, self = this;
- h = '<div class="el-finder-logo"/><strong>'+this.fm.i18n('elFinder: Web file manager')+'</strong><br/>'+this.fm.i18n('Version')+': '+this.fm.version+'<br clear="all"/>'
- +'<p><strong><a href="http://elrte.ru/donate?prod=elfinder&lang='+this.fm.options.lang+'" target="_blank">'+this.fm.i18n('Donate to support project development')+'</a></strong></p>'
- + '<p><a href="http://elrte.ru/redmine/wiki/elfinder/" target="_blank">'+this.fm.i18n('elFinder documentation')+'</a></p>';
- h += '<p>'+(ht != 'helpText' ? ht : 'elFinder works similar to file manager on your computer. <br /> To make actions on files/folders use icons on top panel. If icon action it is not clear for you, hold mouse cursor over it to see the hint. <br /> Manipulations with existing files/folders can be done through the context menu (mouse right-click).<br/> To copy/delete a group of files/folders, select them using Shift/Alt(Command) + mouse left-click.')+'</p>';
- h += '<p>'
- + '<strong>'+this.fm.i18n('elFinder support following shortcuts')+':</strong><ul>'
- + '<li><kbd>Ctrl+A</kbd> - '+this.fm.i18n('Select all files')+'</li>'
- + '<li><kbd>Ctrl+C/Ctrl+X/Ctrl+V</kbd> - '+this.fm.i18n('Copy/Cut/Paste files')+'</li>'
- + '<li><kbd>Enter</kbd> - '+this.fm.i18n('Open selected file/folder')+'</li>'
- //+ '<li><kbd>Space</kbd> - '+this.fm.i18n('Open/close QuickLook window')+'</li>'
- + '<li><kbd>Delete/Cmd+Backspace</kbd> - '+this.fm.i18n('Remove selected files')+'</li>'
- + '<li><kbd>Ctrl+I</kbd> - '+this.fm.i18n('Selected files or current directory info')+'</li>'
- + '<li><kbd>Ctrl+N</kbd> - '+this.fm.i18n('Create new directory')+'</li>'
- + '<li><kbd>Ctrl+U</kbd> - '+this.fm.i18n('Open upload files form')+'</li>'
- + '<li><kbd>Left arrow</kbd> - '+this.fm.i18n('Select previous file')+'</li>'
- + '<li><kbd>Right arrow </kbd> - '+this.fm.i18n('Select next file')+'</li>'
- + '<li><kbd>Ctrl+Right arrow</kbd> - '+this.fm.i18n('Open selected file/folder')+'</li>'
- + '<li><kbd>Ctrl+Left arrow</kbd> - '+this.fm.i18n('Return into previous folder')+'</li>'
- + '<li><kbd>Shift+arrows</kbd> - '+this.fm.i18n('Increase/decrease files selection')+'</li></ul>'
- + '</p><p>'
- + this.fm.i18n('Contacts us if you need help integrating elFinder in you products')+': dev@std42.ru</p>';
- a = '<div class="el-finder-help-std"/>'
- +'<p>'+this.fm.i18n('Javascripts/PHP programming: Dmitry (dio) Levashov, dio@std42.ru')+'</p>'
- +'<p>'+this.fm.i18n('Python programming, techsupport: Troex Nevelin, troex@fury.scancode.ru')+'</p>'
- +'<p>'+this.fm.i18n('Design: Valentin Razumnih')+'</p>'
- +'<p>'+this.fm.i18n('Spanish localization')+': Alex (xand) Vavilin, xand@xand.es, <a href="http://xand.es" target="_blank">http://xand.es</a></p>'
- +'<p>'+this.fm.i18n('Icons')+': <a href="http://www.famfamfam.com/lab/icons/silk/" target="_blank">Famfam silk icons</a>, <a href="http://www.fatcow.com/free-icons/" target="_blank">Fatcow icons</a>'+'</p>'
- +'<p>'+this.fm.i18n('Copyright: <a href="http://www.std42.ru" target="_blank">Studio 42 LTD</a>')+'</p>'
- +'<p>'+this.fm.i18n('License: BSD License')+'</p>'
- +'<p>'+this.fm.i18n('Web site: <a href="http://www.elrte.ru/elfinder/" target="_blank">elrte.ru</a>')+'</p>';
- s = '<div class="el-finder-logo"/><strong><a href="http://www.eldorado-cms.ru" target="_blank">ELDORADO.CMS</a></strong><br/>'
- +this.fm.i18n('Simple and usefull Content Management System')
- +'<hr/>'
- + this.fm.i18n('Support project development and we will place here info about you');
- tabs = '<ul><li><a href="#el-finder-help-h">'+this.fm.i18n('Help')+'</a></li><li><a href="#el-finder-help-a">'+this.fm.i18n('Authors')+'</a><li><a href="#el-finder-help-sp">'+this.fm.i18n('Sponsors')+'</a></li></ul>'
- +'<div id="el-finder-help-h"><p>'+h+'</p></div>'
- +'<div id="el-finder-help-a"><p>'+a+'</p></div>'
- +'<div id="el-finder-help-sp"><p>'+s+'</p></div>';
- this.fm.lockShortcuts(true);
- var d = $('<div/>').html(tabs).dialog({
- width : 617,
- title : this.fm.i18n('Help'),
- dialogClass : 'el-finder-dialog',
- modal : true,
- close : function() { self.fm.lockShortcuts(); d.tabs('destroy').dialog('destroy').remove() },
- buttons : {
- Ok : function() { $(this).dialog('close'); }
- }
- }).tabs()
- }
- this.cm = function(t) {
- return t == 'cwd';
- }
- }
- }
- })(jQuery);
- /**
- * @class Bind/update events
- * @author dio dio@std42.ru
- **/
- (function($) {
- elFinder.prototype.eventsManager = function(fm, el) {
- var self = this;
- this.lock = false;
- this.fm = fm;
- this.ui = fm.ui;
- this.tree = fm.view.tree
- this.cwd = fm.view.cwd;
- this.pointer = '';
- /**
- * Initial events binding
- *
- **/
- this.init = function() {
- this.cwd
- .bind('click', function(e) {
- var t = $(e.target);
- if (t.hasClass('ui-selected')) {
- self.fm.unselectAll();
- } else {
- if (!t.attr('key')) {
- t = t.parent('[key]');
- }
- if (e.ctrlKey || e.metaKey) {
- self.fm.toggleSelect(t);
- } else {
- self.fm.select(t, true);
- }
- }
- })
- .bind(window.opera?'click':'contextmenu', function(e) {
- if (window.opera && !e.ctrlKey) {
- return;
- }
- var t = $(e.target);
- if(t.is('input'))return;
- e.preventDefault();
- e.stopPropagation()
- if (t.hasClass('el-finder-cwd')) {
- self.fm.unselectAll();
- } else {
- self.fm.select(t.attr('key') ? t : t.parents('[key]'));
- }
- self.fm.ui.showMenu(e);
- });
- $('html').selectable({
- filter : '.el-finder-list [key]',
- //cancel : '.el-finder-template',
- delay : 300,
- stop : function() { self.fm.updateSelect() }
- });
- $(document).bind('click', function() {
- self.fm.ui.hideMenu();
- $('input', self.cwd).trigger('change');
- });
- /* open parents dir in tree */
- this.tree.bind('select', function(e) {
- self.tree.find('a').removeClass('selected');
- $(e.target).addClass('selected').parents('li:has(ul)').children('ul').show().prev().children('div').addClass('expanded');
- });
- /* bind shortcuts */
- $(document).bind($.browser.mozilla || $.browser.opera ? 'keypress' : 'keydown', function(e) {
- var meta = e.ctrlKey||e.metaKey;
- if (self.lock) {
- return;
- }
- switch(e.keyCode) {
- /* arrows left/up. with Ctrl - exec "back", w/o - move selection */
- case 37:
- case 38:
- e.stopPropagation();
- e.preventDefault();
- if (e.keyCode == 37 && meta) {
- self.ui.execIfAllowed('back');
- } else {
- moveSelection(false, !e.shiftKey);
- }
- break;
- /* arrows right/down. with Ctrl - exec "open", w/o - move selection */
- case 39:
- case 40:
- e.stopPropagation();
- e.preventDefault();
- if (meta) {
- self.ui.execIfAllowed('open');
- } else {
- moveSelection(true, !e.shiftKey);
- }
- break;
- }
- });
- $(document).bind($.browser.opera ? 'keypress' : 'keydown', function(e) {
- if (self.lock) {
- return;
- }
- switch(e.keyCode) {
- /* Space - QuickLook */
- /*case 32:
- e.preventDefault();
- e.stopPropagation();
- self.fm.quickLook.toggle();
- break;*/
- /* Esc */
- /*case 27:
- self.fm.quickLook.hide();
- break;*/
- }
- });
- if (!this.fm.options.disableShortcuts) {
- $(document).bind('keydown', function(e) {
- var meta = e.ctrlKey||e.metaKey;
- if (self.lock) {
- return;
- }
- if($(e.target).is('input,select'))return;
- //e.target
- //e.srcElement
- switch (e.keyCode) {
- /* Meta+Backspace - delete */
- case 8:
- if (meta && self.ui.isCmdAllowed('rm')) {
- e.preventDefault();
- self.ui.exec('rm');
- }
- break;
- /* Enter - exec "select" command if enabled, otherwise exec "open" */
- case 13:
- if (self.ui.isCmdAllowed('select')) {
- return self.ui.exec('select');
- }
- self.ui.execIfAllowed('open');
- break;
- /* Delete */
- case 46:
- self.ui.execIfAllowed('rm');
- break;
- /* Ctrl+A */
- case 65:
- if (meta) {
- e.preventDefault();
- self.fm.selectAll();
- }
- break;
- /* Ctrl+C */
- case 67:
- meta && self.ui.execIfAllowed('copy');
- break;
- /* Ctrl+I - get info */
- case 73:
- if (meta) {
- e.preventDefault();
- self.ui.exec('info');
- }
- break;
- /* Ctrl+N - new folder */
- case 78:
- if (meta) {
- e.preventDefault();
- self.ui.execIfAllowed('mkdir');
- }
- break;
- /* Ctrl+U - upload files */
- case 85:
- if (meta) {
- e.preventDefault();
- self.ui.execIfAllowed('upload');
- }
- break;
- /* Ctrl+V */
- case 86:
- meta && self.ui.execIfAllowed('paste');
- break;
- /* Ctrl+X */
- case 88:
- meta && self.ui.execIfAllowed('cut');
- break;
- case 113:
- self.ui.execIfAllowed('rename');
- break;
- }
- });
- }
- }
- /**
- * Update navigation droppable/draggable
- *
- **/
- this.updateNav = function() {
- $('a:not(.iClick)', this.tree)
- .addClass('iClick')
- .click(function(e) {
- e.preventDefault();
- var t = $(this), c;
- if (e.target.nodeName == 'DIV' && $(e.target).hasClass('collapsed')) {
- $(e.target).toggleClass('expanded').parent().next('ul').toggle(300);
- setTimeout(function(){
- self.fm.ajax({cmd:'silent'}, false, {lock:false})
- }, 350);
- } else if (t.attr('key') != self.fm.cwd.hash) {
- if (t.hasClass('noaccess') || t.hasClass('dropbox')) {
- self.fm.view.error('Access denied');
- } else {
- self.ui.exec('open', t.trigger('select')[0]);
- }
- } else {
- c = t.children('.collapsed');
- if (c.length) {
- c.toggleClass('expanded');
- t.next('ul').toggle(300);
- }
- }
- });
- $('a:not(.noaccess,.readonly,.iDrop)', this.tree)
- .addClass('iDrop')
- .droppable({
- tolerance : 'pointer',
- accept : '(div,tr)[key]',
- over : function() { $(this).addClass('el-finder-droppable'); },
- out : function() { $(this).removeClass('el-finder-droppable'); },
- drop : function(e, ui) { $(this).removeClass('el-finder-droppable'); self.fm.drop(e, ui, $(this).attr('key')); }
- });
- }
- /**
- * Update folders droppable & files/folders draggable
- **/
- this.updateCwd = function() {
- //var overTimeout;
- $('a[key]', this.cwd)
- .bind('click', function(e) {
- $(this).trigger('dblclick');
- return false;
- });
- var items=$('[key]', this.cwd)
- /*.mouseover(function(e){
- if(e.ctrlKey || e.metaKey) return;
- if(overTimeout) clearTimeout(overTimeout);
- if(self.fm.selected.length > 1) return;
- var el = this;
- overTimeout = setTimeout(function(){self.fm.select($(el), true);overTimeout = null;}, 500);
- })
- .mouseout(function(e){
- if(overTimeout){
- clearTimeout(overTimeout);
- overTimeout = null;
- }
- })*/
- .bind('click', function(e) {
- if(e.shiftKey||e.ctrlKey)return;
- self.fm.select($(this), true);
- self.ui.exec(self.ui.isCmdAllowed('select') ? 'select' : 'open');
- })
- .draggable({
- delay : 3,
- addClasses : false,
- appendTo : '.el-finder-cwd',
- cursorAt : {top:0,left:0},
- revert : true,
- revertDuration: 200,
- start : function(e, ui) {
- if(e.shiftKey||e.ctrlKey)return false;
- },
- drag : function(e, ui) {
- ui.helper.toggleClass('el-finder-drag-copy', e.shiftKey||e.ctrlKey);
- },
- helper : function() {
- var t = $(this),
- h = $('<div class="el-finder-drag-helper"/>'),
- num
- c = 0;
- !t.hasClass('ui-selected') && self.fm.select(t, true);
- /*self.cwd.find('.ui-selected').each(function(i) {
- var el = $(self.fm.view.renderIcon(self.fm.cdc[$(this).attr('key')]));
- //var el = self.fm.options.view == 'icon' ? $(this).clone().removeClass('ui-selected') : $(self.fm.view.renderIcon(self.fm.cdc[$(this).attr('key')]))
- if (c++ == 0 || c%7 == 0) {
- el.css('margin-left', 0);
- }
- h.append(el);
- });*/
- c = self.cwd.find('.ui-selected').length;
- h.html('Dragging '+c+' '+(c == 1 ? 'item' : 'items'));
- return h;
- //return h.css('width', (c<=12 ? 85+(c-1)*29 : 387)+'px');
- //return h.css('width', (c<=7 ? 180+(c-1)*50 : 450)+'px');
- }
- });
- items
- .filter('.directory')//TODO: filter readonly, noaccess
- .droppable({
- tolerance : 'pointer',
- accept : '(div,tr)[key]',
- over : function() { $(this).addClass('el-finder-droppable'); },
- out : function() { $(this).removeClass('el-finder-droppable'); },
- drop : function(e, ui) { $(this).removeClass('el-finder-droppable'); self.fm.drop(e, ui, $(this).attr('key')); }
- });
- items
- .find('.controls a')
- .click(function(){
- self.fm.select($(this).parents('[key]'),true);
- self.ui.exec(this.name);
- return false;
- });
- if ($.browser.msie) {
- $('[key]', this.cwd)
- .bind('dragstart', function() { self.cwd.selectable('disable').removeClass('ui-state-disabled ui-selectable-disabled'); })
- .bind('dragstop', function() { self.cwd.selectable('enable'); });
- $('*:not(input,select,button)', this.cwd).attr('unselectable', 'on');
- }
- }
- this.updateCwdInfo = function(tmpl) {
- var self = this;
- $('.share-facebook', tmpl).click(function(){
- window.open('http://facebook.com/sharer.php?u='+encodeURIComponent('http://file.loc/'+self.fm.cwd.hash));
- return false;
- });
- $('.share-twitter', tmpl).click(function(){
- window.open('http://twitter.com/intent/tweet?text='+encodeURIComponent('Check out '+(self.fm.cwd.type === 'file' ? 'this file' : 'these files')+', http://file.loc/'+self.fm.cwd.hash));
- return false;
- });
- $('.share-email', tmpl).click(function(){
- ps.set('/sendmail', {sharename: share.name, share:ps.location(), sharetype:util.shareType(share), filescount:share.files.length});
- });
- $('#QuickSearch input', tmpl)
- .focus(function(){
- if(this.value === 'Quick search') this.value = '';
- })
- .blur(function(){
- if(this.value === '') this.value = 'Quick search';
- });
- }
- this.updateCwdTemplate = function(tmpl) {
- var self = this;
- tmpl
- .find('form')
- .submit(function(){
- var frm = {};
- $.map($(this).serializeArray(), function(n, i){ frm[n['name']] = n['value']; });
- self.fm.ajax($.extend({cmd:'open', target:self.fm.cwd.hash, tree:false}, frm), function(data) {
- self.fm.reload(data);
- });
- return false;
- });
- }
- this.updateCwdMore = function() {
- var self = this, w = $(window), e = $('.el-finder-more-files');
- function cdc_more_scrolling() {
- var w = $(window), e = $('.el-finder-more-files');
- if(e.position().top <= w.height() + w.scrollTop()){
- w.unbind('scroll', cdc_more_scrolling);
- e.click();
- return true;
- }
- }
- w.unbind('scroll', cdc_more_scrolling);
- if(this.fm.cdc_pos){
- $('<button class="el-finder-more-files">More</button>')
- .appendTo(this.fm.view.cwd)
- .click(function(){
- var t=$(this).replaceWith('<div class="el-finder-more-files-loading">Loading...</div>');
- self.fm.ajax({cmd:'open', target:self.fm.cwd.hash, tree:false, start:self.fm.cdc_pos}, function(data) {
- self.fm.reload(data);
- },
- {lock:false});
- });
- cdc_more_scrolling() || w.bind('scroll', cdc_more_scrolling);
- }
- }
- /**
- * Move selection in current dir
- *
- * @param Boolean move forward?
- * @param Boolean clear current selection?
- **/
- function moveSelection(forward, reset) {
- var p, _p, cur, cwd = self.cwd.find('.el-finder-list');
- if (!$('[key]', cwd).length) {
- return;
- }
- if (self.fm.selected.length == 0) {
- p = $('[key]:'+(forward ? 'first' : 'last'), cwd);
- self.fm.select(p);
- } else if (reset) {
- p = $('.ui-selected:'+(forward ? 'last' : 'first'), cwd);
- _p = p[forward ? 'next' : 'prev']('[key]');
- if (_p.length) {
- p = _p;
- }
- self.fm.select(p, true);
- } else {
- if (self.pointer) {
- cur = $('[key="'+self.pointer+'"].ui-selected', cwd);
- }
- if (!cur || !cur.length) {
- cur = $('.ui-selected:'+(forward ? 'last' : 'first'), cwd);
- }
- p = cur[forward ? 'next' : 'prev']('[key]');
- if (!p.length) {
- p = cur;
- } else {
- if (!p.hasClass('ui-selected')) {
- self.fm.select(p);
- } else {
- if (!cur.hasClass('ui-selected')) {
- self.fm.unselect(p);
- } else {
- _p = cur[forward ? 'prev' : 'next']('[key]')
- if (!_p.length || !_p.hasClass('ui-selected')) {
- self.fm.unselect(cur);
- } else {
- while ((_p = forward ? p.next('[key]') : p.prev('[key]')) && p.hasClass('ui-selected')) {
- p = _p;
- }
- self.fm.select(p);
- }
- }
- }
- }
- }
- self.pointer = p.attr('key');
- self.fm.checkSelectedPos(forward);
- }
- }
- })(jQuery);
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.