diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-11-22 23:19:36 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-11-22 23:19:36 -0500 |
| commit | 070b5e6d9d3c7e23c06f0ae0b75026923529c24d (patch) | |
| tree | 89c430dd17ca54ff60f885ecd99cf6cfa0f0b7ff /js/api/gallery.js | |
| parent | 04537ed34d443d0610b77420d1dbef64bc05fbfa (diff) | |
| parent | 1631cdf643283fc71bc9d70b5dcbce03ab9c2386 (diff) | |
Merge branch 'master' of lmno:dither
Diffstat (limited to 'js/api/gallery.js')
| -rw-r--r-- | js/api/gallery.js | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/js/api/gallery.js b/js/api/gallery.js index 92764c6..8f9914b 100644 --- a/js/api/gallery.js +++ b/js/api/gallery.js @@ -22,37 +22,59 @@ shader_gallery.bind = function(){ ShaderAPI.list_users(function(err, users){ var $el = $("#pick-user").empty() - for (var i in users) { + + var $option = $("<option>") + var username = "users" + $option.val("LATEST").html(username) + $el.append( $option ) + + users.sort(function(a,b){ + return a.username < b.username ? -1 : a.username > b.username ? 1 : 0 + }).forEach(function(user){ var $option = $("<option>") - var username = users[i].username + var username = user.username $option.val(username).html(username) $el.append( $option ) - } - }) + }) + }); $(document).on("change", "#pick-user", function(){ var name = $(this).val() - ShaderAPI.username(name, load_shaders) + if (name == "LATEST") { + ShaderAPI.latest(load_shaders) + } + else { + ShaderAPI.username(name, load_shaders) + } }) $(document).on("click", ".shader", function(){ run_shader( $(this).data("shader") ) }) } -function new_shader(){ +function new_shader(opt){ + opt = opt || {} + shader_id_root = null run_shader({ id: "", shader_id: "", image_url: $("#url").val(), - script: "", - name: "" + script: opt.shader || "", + name: opt.name || "" }) } function run_shader(shader_object){ console.log(shader_object) shader_id_root = shader_object.shader_id if ($("#persist-image:checked").length) { + var new_w = parseInt(shader_object.width, 10) + var new_h = parseInt(shader_object.height, 10) $("#url").val( shader_object.image_url ) + if (new_w && new_h) { + preserve_dimensions = true + actual_w = w = new_w + actual_h = h = new_h + } load() } $("#shader").val(shader_object.script) @@ -75,10 +97,12 @@ function load_shaders(err, shaders){ function display_shader(shader_object){ var $shader = $("<div>").addClass("shader") $shader.data("shader", shader_object) + $shader.data("id", shader_object.id) var html = shader_gallery_template for (var field in shader_object) { html = html.replace("{" + field + "}", shader_object[field]) } $shader.html(html) + shader_object.id && $shader.data("id", shader_object.id) return $shader; } |
