jsonp-url.js revision f376730c08e3eb4277ea5f192f34f3164790033b
* Adds support for parsing complex callback identifiers from the jsonp url. * This includes callback=foo[1]bar.baz["goo"] as well as referencing methods * RegExp used by the default URL formatter to insert the generated callback * name into the JSONP url. Looks for a query param callback=. If a value * is assigned, it will be clobbered. * @default /\bcallback=.*?(?=&|$)/i * Template used by the default URL formatter to add the callback function * @default "callback={callback}" * <p>Parses the url for a callback named explicitly in the string. * Override this if the target JSONP service uses a different query * parameter or url format.</p> * <p>If the callback is declared inline, the corresponding function will * be returned. Otherwise null.</p> * @method _defaultCallback * @param url {String} the url to search in * @return {Function} the callback function if found, or null // Strip the ["string keys"] and [1] array indexes keys[i] = parseInt($1, 10) | 0; .replace(/^\./, ''); // remove leading dot // Validate against problematic characters. if (!/[^\w\.\$@]/.test(locator)) { path = locator.split('.
'); for (i = path.length - 1; i >= 0; --i) { if (path[i].charAt(0) === '@
') { path[i] = keys[parseInt(path[i].substr(1), 10)]; // First look for a global function, then the Y, then try the Y // again from the second token (to support "callback=Y.handler") callback = getByPath(Y.config.win, path) || getByPath(Y, path.slice(1)); * URL formatter that looks for callback= in the url and appends it * if not present. The supplied proxy name will be assigned to the query * param. Override this method by passing a function as the * "format" property in the config object to the constructor. * @param url { String } the original url * @param proxy {String} the function name that will be used as a proxy to * the configured callback methods. * @return {String} fully qualified JSONP url _format: function (url, proxy) { var callback = this._template.replace(/\{callback\}/, proxy), if (this._pattern.test(url)) { return url.replace(this._pattern, callback); lastChar = url.slice(-1); if (lastChar !== '&
' && lastChar !== '?
') { url += (url.indexOf('?
') > -1) ? '&
' : '?
';