UNPKG

1.91 kBJavaScriptView Raw
1/*
2 * Copyright 2012-2013 the original author or authors
3 * @license MIT, see LICENSE.txt for details
4 *
5 * @author Scott Andrews
6 */
7
8(function (define) {
9 'use strict';
10
11 define(function (require) {
12
13 var interceptor, jsonpClient;
14
15 interceptor = require('../interceptor');
16 jsonpClient = require('../client/jsonp');
17
18 /**
19 * Allows common configuration of JSONP clients.
20 *
21 * Values provided to this interceptor are added to the request, if the
22 * request dose not already contain the property.
23 *
24 * The rest/client/jsonp client is used by default instead of the
25 * common default client for the platform.
26 *
27 * @param {Client} [client=rest/client/jsonp] custom client to wrap
28 * @param {string} [config.callback.param] the parameter name for which the
29 * callback function name is the value
30 * @param {string} [config.callback.prefix] prefix for the callback function,
31 * as the callback is attached to the window object, a unique, unobtrusive
32 * prefix is desired
33 * @param {string} [request.callback.name=<generated>] pins the name of the
34 * callback function, useful for cases where the server doesn't allow
35 * custom callback names. Generally not recommended.
36 *
37 * @returns {Client}
38 */
39 return interceptor({
40 client: jsonpClient,
41 init: function (config) {
42 config.callback = config.callback || {};
43 return config;
44 },
45 request: function (request, config) {
46 request.callback = request.callback || {};
47 request.callback.param = request.callback.param || config.callback.param;
48 request.callback.prefix = request.callback.prefix || config.callback.prefix;
49 request.callback.name = request.callback.name || config.callback.name;
50 return request;
51 }
52 });
53
54 });
55
56}(
57 typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
58 // Boilerplate for AMD and Node
59));