diff options
author | Samrat Man Singh <samratmansingh@gmail.com> | 2012-07-07 08:31:08 +0545 |
---|---|---|
committer | Samrat Man Singh <samratmansingh@gmail.com> | 2012-07-07 08:31:08 +0545 |
commit | 2ce26b4ed17e153d9834e6dd21ec0da92d71139e (patch) | |
tree | 9b59308831e99ed534f28aac51b5b236ac54ce87 /syte/static/js/libs/json.js | |
parent | 705357519b7345422a003d8970d1f396579d91b2 (diff) | |
download | pelican-themes-2ce26b4ed17e153d9834e6dd21ec0da92d71139e.tar.gz |
Move syte-pelican to syte
Diffstat (limited to 'syte/static/js/libs/json.js')
-rw-r--r-- | syte/static/js/libs/json.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/syte/static/js/libs/json.js b/syte/static/js/libs/json.js new file mode 100644 index 0000000..fbf3fbc --- /dev/null +++ b/syte/static/js/libs/json.js @@ -0,0 +1,42 @@ +/*! + * RequireJS plugin for loading JSON files + * - depends on Text plugin and it was HEAVILY "inspired" by it as well. + * + * IMPORTANT: it only works on r.js optimizer after version 0.26+ 20011/09/27 + * + * @author Miller Medeiros + * @version 0.0.1 (2011/06/10) + * Released under the WTFPL <http://sam.zoy.org/wtfpl/> + */ +define(['text'], function(text){ + + var jsonParse = (typeof JSON !== 'undefined' && typeof JSON.parse === 'function')? JSON.parse : function(val){ + return eval('('+ val +')'); //quick and dirty + }, + buildMap = {}; + + //API + return { + + load : function(name, req, onLoad, config) { + text.get(req.toUrl(name), function(data){ + if (config.isBuild) { + buildMap[name] = data; + onLoad(data); + } else { + onLoad(jsonParse(data)); + } + }); + }, + + //write method based on RequireJS official text plugin by James Burke + //https://github.com/jrburke/requirejs/blob/master/text.js + write : function(pluginName, moduleName, write){ + if(moduleName in buildMap){ + var content = buildMap[moduleName]; + write('define("'+ pluginName +'!'+ moduleName +'", function(){ return '+ content +';});\n'); + } + } + + }; +});
\ No newline at end of file |