diff options
| author | pepper <peppersclothescult@gmail.com> | 2014-01-21 00:56:21 -0800 |
|---|---|---|
| committer | pepper <peppersclothescult@gmail.com> | 2014-01-21 00:56:21 -0800 |
| commit | 6671e52efea7bf4ee8e45c500166fbc8d865bbdb (patch) | |
| tree | edf17796610012a534e090c06ba7b83c9b4037d6 /js/api | |
| parent | f850411f437d3eb9cb1d37456d0eab29a9358918 (diff) | |
| parent | 60a5e5581ccbf05170ccd6bab292562c460a42c2 (diff) | |
mergin again
Merge branch 'master' of ghghgh.us:/home/git/dither into pepper
Diffstat (limited to 'js/api')
| -rw-r--r-- | js/api/get.js | 101 | ||||
| -rw-r--r-- | js/api/set.js | 39 |
2 files changed, 140 insertions, 0 deletions
diff --git a/js/api/get.js b/js/api/get.js new file mode 100644 index 0000000..ae06dbd --- /dev/null +++ b/js/api/get.js @@ -0,0 +1,101 @@ +;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){ + if (! cb) { + cb = limit + limit = ShaderAPI.limit + } + 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(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){ + $.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) + } + } + }) +} diff --git a/js/api/set.js b/js/api/set.js new file mode 100644 index 0000000..1e7e31f --- /dev/null +++ b/js/api/set.js @@ -0,0 +1,39 @@ +function save_shader(){ + typeof shader_id_root == 'undefined' ? shader_id_root = "" : shader_id_root + var params = { + script : $("#shader").val(), + image_url : $("#url").val(), + username : user.username, + shader_id : shader_id_root + } + console.log(params) + $.post("/cgi-bin/im/shader/save", params, function(resp){ + console.log(resp); + data = JSON.parse(resp) + if (data.ERROR ){ + alert(data.ERROR) + return false + } + if (! shader_id_root) { + shader_id_root = data.id; + } + + var blob = dataUriToBlob(cc.clone().resize(200,200).canvas.toDataURL("image/png")) + var form = new FormData(); + + form.append("id", data.id); + form.append("qqfile", blob); + $.ajax({ + url: "/cgi-bin/im/shader/thumbnail_upload", + type: "POST", + data: form, + processData: false, + contentType: false, + }).done(function(resp){ + console.log(resp); + }); + + }) + //maintain the shader_id_root... + return shader_id_root; +} |
