Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // modified d3.jsonp plugin from https://github.com/d3/d3-plugins/blob/master/jsonp/jsonp.js
- // switch `callback` on lines 10 and 24 to `prefix`
- d3.jsonp = function (url, callback) {
- function rand() {
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
- c = '', i = -1;
- while (++i < 15) c += chars.charAt(Math.floor(Math.random() * 52));
- return c;
- }
- function create(url) {
- var e = url.match(/prefix=d3.jsonp.(\w+)/),
- c = e ? e[1] : rand();
- d3.jsonp[c] = function(data) {
- callback(data);
- delete d3.jsonp[c];
- script.remove();
- };
- return 'd3.jsonp.' + c;
- }
- var cb = create(url),
- script = d3.select('head')
- .append('script')
- .attr('type', 'text/javascript')
- .attr('src', url.replace(/(\{|%7B)prefix(\}|%7D)/, cb));
- };
Add Comment
Please, Sign In to add comment