1 /* 2 * Timemap.js Copyright 2010 Nick Rabinowitz. 3 * Licensed under the MIT License (see LICENSE.txt) 4 */ 5 6 /** 7 * @fileOverview 8 * JSON Loaders (JSONP, JSON String) 9 * 10 * @author Nick Rabinowitz (www.nickrabinowitz.com) 11 */ 12 13 // for JSLint 14 /*global TimeMap */ 15 16 (function() { 17 var loaders = TimeMap.loaders; 18 19 /** 20 * @class 21 * JSONP loader - expects a service that takes a callback function name as 22 * the last URL parameter. 23 * 24 * <p>The jsonp loader assumes that the JSON can be loaded from a url with a "?" instead of 25 * the callback function name, e.g. "http://www.test.com/getsomejson.php?callback=?". See 26 * <a href="http://api.jquery.com/jQuery.ajax/">the jQuery.ajax documentation</a> for more 27 * details on how to format the url, especially if the parameter is not called "callback". 28 * This works for services like Google Spreadsheets, etc., and accepts remote URLs.</p> 29 * @name TimeMap.loaders.jsonp 30 * @augments TimeMap.loaders.remote 31 * 32 * @example 33 TimeMap.init({ 34 datasets: [ 35 { 36 title: "JSONP Dataset", 37 type: "jsonp", 38 options: { 39 url: "http://www.example.com/getsomejson.php?callback=?" 40 } 41 } 42 ], 43 // etc... 44 }); 45 * 46 * @constructor 47 * @param {Object} options All options for the loader: 48 * @param {String} options.url URL of JSON service to load, callback name replaced with "?" 49 * @param {mixed} [options[...]] Other options (see {@link loaders.remote}) 50 */ 51 loaders.jsonp = function(options) { 52 var loader = new loaders.remote(options); 53 54 // set ajax settings for loader 55 loader.opts.dataType = 'jsonp'; 56 57 return loader; 58 }; 59 60 /** 61 * @class 62 * JSON string loader - expects a plain JSON array. 63 * 64 * <p>The json_string loader assumes an array of items in plain JSON, with no 65 * callback function - this will require a local URL.</p> 66 * @name TimeMap.loaders.json 67 * @class 68 * 69 * @augments TimeMap.loaders.remote 70 * 71 * @example 72 TimeMap.init({ 73 datasets: [ 74 { 75 title: "JSON String Dataset", 76 type: "json_string", 77 options: { 78 url: "mydata.json" // Must be a local URL 79 } 80 } 81 ], 82 // etc... 83 }); 84 * 85 * @param {Object} options All options for the loader 86 * @param {String} options.url URL of JSON file to load 87 * @param {mixed} [options[...]] Other options (see {@link loaders.remote}) 88 */ 89 loaders.json = function(options) { 90 var loader = new loaders.remote(options); 91 92 // set ajax settings for loader 93 loader.opts.dataType = 'json'; 94 95 return loader; 96 }; 97 98 // For backwards compatibility 99 loaders.json_string = loaders.json; 100 101 })(); 102