Last active
August 29, 2015 14:24
-
-
Save hijarian/9abfb9730869a579e9e0 to your computer and use it in GitHub Desktop.
How to select first uploaded file in elfinder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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