Skip to content

Instantly share code, notes, and snippets.

@mbostock mbostock/jsonp.diff
Created Aug 31, 2010

Embed
What would you like to do?
Polymaps / JSONP Queue
diff --git a/src/Queue.js b/src/Queue.js
index d243c13..616dbc6 100644
--- a/src/Queue.js
+++ b/src/Queue.js
@@ -99,5 +99,41 @@ po.queue = (function() {
return {abort: abort};
}
- return {text: text, xml: xml, json: json, image: image};
+ function jsonp(src, callback) {
+ var script, head, callbackId = "p01YmAp5" + po.id();
+
+ function send() {
+ window[callbackId] = callback;
+ script = document.createElement("script");
+ script.setAttribute("type", "text/javascript");
+ script.setAttribute("src", src.replace(/{C}/g, callbackId));
+ script.addEventListener("load", cleanup, false);
+ (head = document.head).appendChild(script);
+ }
+
+ function abort(hard) {
+ if (dequeue(send)) return true;
+ if (hard && script) { head.removeChild(script); return true; }
+ return false;
+ }
+
+ function cleanup() {
+ active--;
+ head.removeChild(script);
+ delete window[callbackId];
+ process();
+ }
+
+ queued.push(send);
+ process();
+ return {about: abort};
+ }
+
+ return {
+ text: text,
+ xml: xml,
+ json: json,
+ jsonp: jsonp,
+ image: image
+ };
})();
diff --git a/src/Url.js b/src/Url.js
index b4798f6..f786769 100644
--- a/src/Url.js
+++ b/src/Url.js
@@ -8,6 +8,7 @@ po.url = function(template) {
return template.replace(/{(.)}/g, function(s, v) {
switch (v) {
case "S": return hosts[(Math.abs(c.zoom) + c.row + column) % hosts.length];
+ case "C": return "{C}";
case "Z": return c.zoom;
case "X": return column;
case "Y": return c.row;
@Kreozot

This comment has been minimized.

Copy link

commented Aug 18, 2015

A diff?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.