From 42f041a02e6f244b262ba198954b3ab7ee68c153 Mon Sep 17 00:00:00 2001 From: javi Date: Tue, 21 Oct 2014 17:15:27 +0200 Subject: [PATCH] added support for dynamic callback generation for jsonp --- lib/torque/core.js | 8 ++++++++ lib/torque/request.js | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/lib/torque/core.js b/lib/torque/core.js index 7d5e7f1..1d51919 100644 --- a/lib/torque/core.js +++ b/lib/torque/core.js @@ -50,6 +50,10 @@ return exports.torque.extend({}, a); } + exports.torque.isFunction = function(f) { + return typeof f == 'function' || false; + } + exports.torque.isArray = function(value) { return value && typeof value == 'object' && Object.prototype.toString.call(value) == '[object Array]'; }; @@ -65,4 +69,8 @@ return !!document.createElement('canvas'); }; + exports.torque.flags = { + sprites_to_images: navigator.userAgent.indexOf('Safari') === -1 + } + })(typeof exports === "undefined" ? this : exports); diff --git a/lib/torque/request.js b/lib/torque/request.js index 93d6b80..47f82db 100644 --- a/lib/torque/request.js +++ b/lib/torque/request.js @@ -13,6 +13,10 @@ // function name var fnName = options.callbackName || 'torque_' + Date.now(); + if (torque.isFunction(fnName)) { + fnName = fnName(); + } + function clean() { head.removeChild(script); clearTimeout(timeoutTimer);