Skip to content

Commit

Permalink
add old school view - link to parent folder with .. name
Browse files Browse the repository at this point in the history
  • Loading branch information
dio-el-claire committed Jul 7, 2012
1 parent 94e90f0 commit 36ebd83
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
4 changes: 4 additions & 0 deletions js/elFinder.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ elFinder.prototype._options = {
navbar : {
minWidth : 150,
maxWidth : 500
},
cwd : {
// display parent folder with ".." name :)
oldSchool : false
}
},

Expand Down
55 changes: 41 additions & 14 deletions js/ui/cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author Dmitry (dio) Levashov
**/
$.fn.elfindercwd = function(fm) {
$.fn.elfindercwd = function(fm, options) {

this.not('.elfinder-cwd').each(function() {
// fm.time('cwdLoad');
Expand Down Expand Up @@ -200,11 +200,11 @@ $.fn.elfindercwd = function(fm) {
var code = $.ui.keyCode,
prev = keyCode == code.LEFT || keyCode == code.UP,
sel = cwd.find('[id].'+clSelected),
selector = prev ? 'first' : 'last',
selector = prev ? 'first:' : 'last',
s, n, sib, top, left;

function sibling(n, direction) {
return n[direction+'All']('[id]:not(.'+clDisabled+'):first');
return n[direction+'All']('[id]:not(.'+clDisabled+'):not(.elfinder-cwd-parent):first');
}

if (sel.length) {
Expand Down Expand Up @@ -251,11 +251,10 @@ $.fn.elfindercwd = function(fm) {

} else {
// there are no selected file - select first/last one
n = cwd.find('[id]:not(.'+clDisabled+'):'+(prev ? 'last' : 'first'))
n = cwd.find('[id]:not(.'+clDisabled+'):not(.elfinder-cwd-parent):'+(prev ? 'last' : 'first'))
}

if (n && n.length) {

if (n && n.length && !n.is('.elfinder-cwd-parent')) {
if (append) {
// append new files to selected
n = s.add(s[prev ? 'prevUntil' : 'nextUntil']('#'+n.attr('id'))).add(n);
Expand Down Expand Up @@ -520,10 +519,10 @@ $.fn.elfindercwd = function(fm) {
dirs = false,
findNode = function(file) {
var pointer = cwd.find('[id]:first'), file2;

while (pointer.length) {
file2 = fm.file(pointer.attr('id'));
if (file2 && fm.compare(file, file2) < 0) {
if (!pointer.is('.elfinder-cwd-parent') && file2 && fm.compare(file, file2) < 0) {
return pointer;
}
pointer = pointer.next('[id]');
Expand Down Expand Up @@ -551,7 +550,7 @@ $.fn.elfindercwd = function(fm) {
}

if ((node = findNode(file)) && node.length) {
node.before(itemhtml(file));
node.before(itemhtml(file));
} else if ((ndx = findIndex(file)) >= 0) {
buffer.splice(ndx, 0, file);
} else {
Expand Down Expand Up @@ -632,6 +631,24 @@ $.fn.elfindercwd = function(fm) {
wrapper.bind(scrollEvent, render).trigger(scrollEvent);

trigger();

phash = fm.cwd().phash;

if (options.oldSchool && phash && !query) {
var parent = $.extend(true, {}, fm.file(phash), {name : '..', mime : 'directory'});
parent = $(itemhtml(parent))
.addClass('elfinder-cwd-parent')
.bind('mousedown click mouseup dblclick mouseenter', function(e) {
e.preventDefault();
e.stopPropagation();
})
.dblclick(function() {
fm.exec('open', this.id);
});

(list ? cwd.find('tbody') : cwd).prepend(parent);
}

},

/**
Expand Down Expand Up @@ -748,9 +765,17 @@ $.fn.elfindercwd = function(fm) {
.droppable(droppable)
// prepend fake file/dir
.bind('create.'+fm.namespace, function(e, file) {
var parent = list ? cwd.find('tbody') : cwd;
var parent = list ? cwd.find('tbody') : cwd,
p = parent.find('.elfinder-cwd-parent'),
file = $(itemhtml(file)).addClass(clTmp);

cwd.trigger('unselectall');
parent.prepend($(itemhtml(file)).addClass(clTmp));
if (p.length) {
p.after(file);
} else {
parent.prepend(file);
}

cwd.scrollTop(0)
})
// unselect all selected files
Expand Down Expand Up @@ -826,9 +851,11 @@ $.fn.elfindercwd = function(fm) {
content(lastSearch, true);
})
.bind('searchend', function() {
query && content(fm.files());
lastSearch = [];
query = '';
if (query) {
query = '';
content(fm.files());
}
})
.bind('searchstart', function(e) {
query = e.data.query;
Expand Down Expand Up @@ -945,7 +972,7 @@ $.fn.elfindercwd = function(fm) {
callback : function() {
var sel = [], phash;

cwd.find('[id]:not(.'+clSelected+')').trigger(evtSelect);
cwd.find('[id]:not(.'+clSelected+'):not(.elfinder-cwd-parent)').trigger(evtSelect);

if (buffer.length) {
phash = fm.cwd().hash;
Expand Down

0 comments on commit 36ebd83

Please sign in to comment.