Skip to content

Commit

Permalink
[ui:cwd] correction for touch device (support long tap) & syntax stri…
Browse files Browse the repository at this point in the history
…ctly

ref. Studio-42#266

Tap: Item select or Similar dblClick (selected item)
Long-tap: Similar dblClick (When nothing is chosen) or Multi (un)select
(When some are chosen)
  • Loading branch information
nao-pon committed Sep 5, 2013
1 parent c843ffc commit caacf71
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions js/ui/cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ $.fn.elfindercwd = function(fm, options) {
// !append && unselectAll();
} else {
// there are no selected file - select first/last one
n = cwd.find('[id]:not(.'+clDisabled+'):not(.elfinder-cwd-parent):'+(prev ? 'last' : 'first'))
n = cwd.find('[id]:not(.'+clDisabled+'):not(.elfinder-cwd-parent):'+(prev ? 'last' : 'first'));
}

if (n && n.length && !n.is('.elfinder-cwd-parent')) {
Expand Down Expand Up @@ -285,7 +285,7 @@ $.fn.elfindercwd = function(fm, options) {
var phash = fm.cwd().hash;

cwd.find('[id]:not(.'+clSelected+'):not(.elfinder-cwd-parent)').trigger(evtSelect);
selectedFiles = $.map(fm.files(), function(f) { return f.phash == phash ? f.hash : null });
selectedFiles = $.map(fm.files(), function(f) { return f.phash == phash ? f.hash : null ;});
trigger();
},

Expand Down Expand Up @@ -397,7 +397,7 @@ $.fn.elfindercwd = function(fm, options) {
dirs = true;
}
if (f.tmb) {
f.tmb === 1 ? ltmb.push(f.hash) : (atmb[f.hash] = f.tmb)
f.tmb === 1 ? ltmb.push(f.hash) : (atmb[f.hash] = f.tmb);
}
return itemhtml(f);
}
Expand Down Expand Up @@ -442,7 +442,7 @@ $.fn.elfindercwd = function(fm, options) {
cwd.removeClass(clDropActive);
return false;
}
})
});
}
}),

Expand Down Expand Up @@ -508,7 +508,7 @@ $.fn.elfindercwd = function(fm, options) {
if (attachThumbnails(data.images||[]) && data.tmb) {
loadThumbnails();
}
})
});
return;
}

Expand Down Expand Up @@ -662,6 +662,7 @@ $.fn.elfindercwd = function(fm, options) {
parent = $(itemhtml(parent))
.addClass('elfinder-cwd-parent')
.bind('mousedown click mouseup touchstart touchmove touchend dblclick mouseenter', function(e) {
//.bind('mousedown click mouseup dblclick mouseenter', function(e) {
e.preventDefault();
e.stopPropagation();
})
Expand Down Expand Up @@ -699,8 +700,14 @@ $.fn.elfindercwd = function(fm, options) {
} else if (e.ctrlKey || e.metaKey) {
p.trigger(p.is('.'+clSelected) ? evtUnselect : evtSelect);
} else {
unselectAll();
p.trigger(evtSelect);
if ($(this).data('touching') && p.is('.'+clSelected)) {
$(this).data('touching', null);
fm.dblclick({file : this.id});
unselectAll();
} else {
unselectAll();
p.trigger(evtSelect);
}
}

trigger();
Expand All @@ -709,19 +716,24 @@ $.fn.elfindercwd = function(fm, options) {
.delegate(fileSelector, 'dblclick.'+fm.namespace, function(e) {
fm.dblclick({file : this.id});
})
// call fm.open() for touch device
.delegate(fileSelector, 'touchend.'+fm.namespace, function(e) {
var p = this.id ? $(this) : $(this).parents('[id]:first');
if (p.is('.'+clSelected)) {
fm.dblclick({file : this.id});
}
// for touch device
.delegate(fileSelector, 'touchstart.'+fm.namespace, function(e) {
$(this).data('touching', true);
var p = this.id ? $(this) : $(this).parents('[id]:first'),
sel = p.prevAll('.'+clSelected+':first').length +
p.nextAll('.'+clSelected+':first').length;
$(this).data('longtap', setTimeout(function(){
// long tap
p.trigger(p.is('.'+clSelected) ? evtUnselect : evtSelect);
trigger();
if (sel == 0 && p.is('.'+clSelected)) {
p.trigger('click');
trigger();
}
}, 500));
})
// unselect on scrolling for touch device
.delegate(fileSelector, 'touchmove.'+fm.namespace, function(e) {
var p = this.id ? $(this) : $(this).parents('[id]:first');
if (p.is('.'+clSelected)) {
p.trigger(evtUnselect);
}
.delegate(fileSelector, 'touchmove.'+fm.namespace+' touchend.'+fm.namespace, function(e) {
clearTimeout($(this).data('longtap'));
})
// attach draggable
.delegate(fileSelector, 'mouseenter.'+fm.namespace, function(e) {
Expand Down Expand Up @@ -777,7 +789,7 @@ $.fn.elfindercwd = function(fm, options) {
target.is('.'+clDraggable) && target.draggable('enable');
})
.delegate(fileSelector, 'scrolltoview', function() {
scrollToView($(this))
scrollToView($(this));
})
.delegate(fileSelector, 'hover', function(e) {
fm.trigger('hover', {hash : $(this).attr('id'), type : e.type});
Expand All @@ -791,7 +803,7 @@ $.fn.elfindercwd = function(fm, options) {
if (!file.is('.'+clDisabled)) {
if (!file.is('.'+clSelected)) {
// cwd.trigger('unselectall');
unselectAll()
unselectAll();
file.trigger(evtSelect);
trigger();
}
Expand Down Expand Up @@ -936,7 +948,7 @@ $.fn.elfindercwd = function(fm, options) {
.add(function(e) {
var phash = fm.cwd().hash,
files = query
? $.map(e.data.added || [], function(f) { return f.name.indexOf(query) === -1 ? null : f })
? $.map(e.data.added || [], function(f) { return f.name.indexOf(query) === -1 ? null : f ;})
: $.map(e.data.added || [], function(f) { return f.phash == phash ? f : null; })
;
add(files);
Expand All @@ -953,7 +965,7 @@ $.fn.elfindercwd = function(fm, options) {
add([file]);
$.inArray(file.hash, sel) !== -1 && selectFile(file.hash);
}
})
});
} else {
$.each($.map(e.data.changed || [], function(f) { return f.phash == phash ? f : null; }), function(i, file) {
remove([file.hash]);
Expand Down Expand Up @@ -1036,7 +1048,7 @@ $.fn.elfindercwd = function(fm, options) {
description : 'selectffile',
callback : function(e) {
unselectAll();
scrollToView(cwd.find('[id]:first').trigger(evtSelect))
scrollToView(cwd.find('[id]:first').trigger(evtSelect));
trigger();
}
})
Expand Down

0 comments on commit caacf71

Please sign in to comment.