Last active
December 29, 2015 03:29
-
-
Save tonyjunkes/7607874 to your computer and use it in GitHub Desktop.
CFC for generating JSON data from a folder of images to be used with CKEditor's Image Browser addon.
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
component name="ImageBrowser" | |
output="false" | |
{ | |
remote array function list(required string dir = "") | |
output="false" | |
returnformat="JSON" | |
{ | |
var length = 0; | |
var path = var image = var folder = ""; | |
var result = []; | |
arrayEach( | |
directoryList(expandPath("./#ARGUMENTS.dir#"), true, "path"), | |
function(x) { | |
length = listLen(x, "\/"); | |
if (reFind("\w.*\.(jpg|png|gif|bmp)", listGetAt(x, length, "\/"))) { | |
image = listGetAt(x, length, "\/"); | |
path = reMatch("(#listGetAt(dir, 1, "\/")#).*", reReplace(listDeleteAt(x, length, "\/"), "\\", "/", "ALL"))[1]; | |
folder = listGetAt(x, length - 1, "\/"); | |
arrayAppend(result, {"image": "/#path#/#image#", "folder": "#folder#"}); | |
} | |
} | |
); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment