Skip to content

Instantly share code, notes, and snippets.

@hijarian
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hijarian/9abfb9730869a579e9e0 to your computer and use it in GitHub Desktop.
Save hijarian/9abfb9730869a579e9e0 to your computer and use it in GitHub Desktop.
How to select first uploaded file in elfinder
/**
* Handler for 'upload' event.
* That event passes `event` object to its handlers.
*
* This object has `data` object, which contains list of stats for uploaded files under `added` key.
*
* Trick is as follows:
* elfinder lists all files as `div` elements with IDs equal to file "hashes", internal elfinder IDs.
* We get the "hash" of first uploaded element and just double-click on the corresponding `div` element.
*/
var selectFirstUploaded = function (event) {
var first_uploaded_hash = "";
if (event.data.added.length > 0)
first_uploaded_hash = event.data.added[0].hash;
// elfinder docs and sources do not give me any clue about how to programmatically select a file in file browser
// (trigger its `getFileCallback`), so I just double-click on a visible block.
if (first_uploaded_hash)
$('#' + first_uploaded_hash).dblclick();
};
function initElfinder(browser_window_selector, options) {
var instance = $(browser_window_selector).elfinder(options).elfinder('instance');
instance.bind('upload', selectFirstUploaded);
return instance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment