diff options
| author | jules <jules@okfoc.us> | 2014-02-02 02:25:07 -0500 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2014-02-02 02:25:07 -0500 |
| commit | ff36ed287ec8747fe25e429bc5fa11961274bbd3 (patch) | |
| tree | cae45435286369ed6f658729eca0c09a80a5effe /js | |
| parent | 76a4f773a56eaf59953f2f7ebe027d8b0a4b3ee7 (diff) | |
add examples from json
Diffstat (limited to 'js')
| -rw-r--r-- | js/api/gallery.js | 7 | ||||
| -rw-r--r-- | js/api/localstorage.js | 2 | ||||
| -rw-r--r-- | js/help.js | 22 |
3 files changed, 27 insertions, 4 deletions
diff --git a/js/api/gallery.js b/js/api/gallery.js index c83d5f6..0e6614b 100644 --- a/js/api/gallery.js +++ b/js/api/gallery.js @@ -39,14 +39,15 @@ shader_gallery.bind = function(){ }) } -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){ diff --git a/js/api/localstorage.js b/js/api/localstorage.js index eeae658..309d49d 100644 --- a/js/api/localstorage.js +++ b/js/api/localstorage.js @@ -5,7 +5,7 @@ local_shaders.init = function(){ } local_shaders.bind = function(){ local_shaders.buttons = {} - if ('SHADERS' in window) { + if ('EXAMPLE_SHADERS' in window) { local_shaders.bindButtons( window.SHADERS ) } local_shaders.bindButtons( local_shaders.getShaders() ) @@ -16,6 +16,28 @@ help.bind = function(){ stop: drag_stop }) $("#commands,#tutorial").disableSelection(); + + $("#examples").change(function(){ + help.load_example($(this).val()) + $("#toggle-images").trigger("click") + }) + + if ('EXAMPLE_SHADERS' in window) { + help.examples = {} + window.EXAMPLE_SHADERS.forEach(function(s){ + help.examples[ s.name ] = s.shader + var $option = $("<option value='" + s.name +"'>" + s.name + "</option>") + $("#examples").append($option) + }) + } +} + +help.examples = {} + +help.load_example = function(name){ + var s = help.examples[name] + $("#shader").html(s) + new_shader({ name: name, shader: s }) } function drag_start(){ dragging = true; $(this).addClass("dragging") } |
