From a703503ee09092a98fbab31e763bc64081d0e7d5 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 20 Jan 2014 19:03:18 -0500 Subject: move js api into js --- js/api/get.js | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 js/api/get.js (limited to 'js/api/get.js') diff --git a/js/api/get.js b/js/api/get.js new file mode 100644 index 0000000..dd43130 --- /dev/null +++ b/js/api/get.js @@ -0,0 +1,92 @@ +;var ShaderAPI = {} +ShaderAPI.limit = 24 + +// info - fetch a single shader +// id: shader id +ShaderAPI.info = function(id, cb){ + ShaderAPI.fetch({ + f: "info", + id: id + }, cb) +} + +// all - fetch all shaders +ShaderAPI.all = function(cb){ + ShaderAPI.fetch({ + f: "all" + }, cb) +} + +// range - fetch a pageful of results +// limit: number of shaders to fetch +// offset: number of results to skip +ShaderAPI.range = function(limit, offset, cb){ + ShaderAPI.fetch({ + f: "range", + limit: limit || ShaderAPI.limit, + last: offset + }, cb) +} + +// latest - get the latest N shaders +// limit: number of shaders to fetch +ShaderAPI.latest = function(limit, cb){ + ShaderAPI.fetch({ + f: "range", + limit: limit || ShaderAPI.limit + }, cb) +} + +// page - get a page of N results +// page: page number, start counting at 1 +// limit: number of shaders to fetch +ShaderAPI.page = function(page, limit, cb){ + ShaderAPI.fetch({ + f: "range", + last: (page-1) * limit, + limit: limit || ShaderAPI.limit + }, cb) +} + +// history - get all previous versions of a shader +// id: shader id +ShaderAPI.history = function(id, cb){ + ShaderAPI.fetch({ + f: "history", + id: id + }, cb) +} + +// username - get all ids by a user +ShaderAPI.username = function(username, cb){ + ShaderAPI.fetch({ + f: "username", + username: username + }, cb) +} + +// list_users - list all users +ShaderAPI.list_users = function(list_users, cb){ + ShaderAPI.fetch({ + f: "list_users" + }, cb) +} + +// originals - get the earliest version of all named shaders +ShaderAPI.originals = function(cb){ + ShaderAPI.fetch({ + f: "originals" + }, cb) +} + +// fetch - AJAX wrapper +ShaderAPI.fetch = function(params, cb){ + $.getJSON("/cgi-bin/im/shader/view", params, function(data){ + if (data.SUCCESS) { + cb(null, data.data) + } + else if (data.ERROR) { + cb(data.ERROR, data.data) + } + }) +} -- cgit v1.2.3-70-g09d2 From d947152a7c8553462091f25f8cff249c0cb43004 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 21 Jan 2014 00:40:33 -0500 Subject: shader api test --- js/api/get.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'js/api/get.js') diff --git a/js/api/get.js b/js/api/get.js index dd43130..ec269b0 100644 --- a/js/api/get.js +++ b/js/api/get.js @@ -81,12 +81,17 @@ ShaderAPI.originals = function(cb){ // fetch - AJAX wrapper ShaderAPI.fetch = function(params, cb){ - $.getJSON("/cgi-bin/im/shader/view", params, function(data){ - if (data.SUCCESS) { - cb(null, data.data) - } - else if (data.ERROR) { - cb(data.ERROR, data.data) - } + $.ajax({ + url: "http://asdf.us/cgi-bin/im/shader/view", + data: params, + dataType: "jsonp", + success: function(data){ + if (data.SUCCESS) { + cb(null, data.data) + } + else if (data.ERROR) { + cb(data.ERROR, data.data) + } + } }) } -- cgit v1.2.3-70-g09d2 From ced1db8df6c73f7bd0a4debd3f20b5570b99e7b4 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 21 Jan 2014 01:18:36 -0500 Subject: shader loader demo --- js/api/get.js | 6 ++- js/render.js | 5 +- shader-api.html | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 shader-api.html (limited to 'js/api/get.js') diff --git a/js/api/get.js b/js/api/get.js index ec269b0..ae06dbd 100644 --- a/js/api/get.js +++ b/js/api/get.js @@ -31,6 +31,10 @@ ShaderAPI.range = function(limit, offset, cb){ // latest - get the latest N shaders // limit: number of shaders to fetch ShaderAPI.latest = function(limit, cb){ + if (! cb) { + cb = limit + limit = ShaderAPI.limit + } ShaderAPI.fetch({ f: "range", limit: limit || ShaderAPI.limit @@ -66,7 +70,7 @@ ShaderAPI.username = function(username, cb){ } // list_users - list all users -ShaderAPI.list_users = function(list_users, cb){ +ShaderAPI.list_users = function(cb){ ShaderAPI.fetch({ f: "list_users" }, cb) diff --git a/js/render.js b/js/render.js index 9d3ab04..fdb0125 100644 --- a/js/render.js +++ b/js/render.js @@ -93,11 +93,14 @@ function animate(t){ draw(t) // timing = +(new Date()) - timing fps = avg(fps, 1000/step_t, 4) - status(~~(fps) + " fps") + // status(~~(fps) + " fps") } + function draw(t) { t -= start_t t -= pause_t frame = giveFrame(t) shade(frame, t) } + +function status(s){ $("#status").html(s); console.log(s) } diff --git a/shader-api.html b/shader-api.html new file mode 100644 index 0000000..284d1a4 --- /dev/null +++ b/shader-api.html @@ -0,0 +1,155 @@ + + + + + + + + + +
+ + + + + + + + + +
+ +
+ +
+
+ + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2