[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('yql', function (Y, NAME) { 9 10 /** 11 * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/). 12 * @module yql 13 */ 14 /** 15 * Utility Class used under the hood by the YQL class 16 * @class YQLRequest 17 * @constructor 18 * @param {String} sql The SQL statement to execute 19 * @param {Function/Object} callback The callback to execute after the query (Falls through to JSONP). 20 * @param {Object} params An object literal of extra parameters to pass along (optional). 21 * @param {Object} opts An object literal of configuration options (optional): proto (http|https), base (url) 22 */ 23 var YQLRequest = function (sql, callback, params, opts) { 24 25 if (!params) { 26 params = {}; 27 } 28 params.q = sql; 29 //Allow format override.. JSON-P-X 30 if (!params.format) { 31 params.format = Y.YQLRequest.FORMAT; 32 } 33 if (!params.env) { 34 params.env = Y.YQLRequest.ENV; 35 } 36 37 this._context = this; 38 39 if (opts && opts.context) { 40 this._context = opts.context; 41 delete opts.context; 42 } 43 44 if (params && params.context) { 45 this._context = params.context; 46 delete params.context; 47 } 48 49 this._params = params; 50 this._opts = opts; 51 this._callback = callback; 52 53 }; 54 55 YQLRequest.prototype = { 56 /** 57 * @private 58 * @property _jsonp 59 * @description Reference to the JSONP instance used to make the queries 60 */ 61 _jsonp: null, 62 /** 63 * @private 64 * @property _opts 65 * @description Holder for the opts argument 66 */ 67 _opts: null, 68 /** 69 * @private 70 * @property _callback 71 * @description Holder for the callback argument 72 */ 73 _callback: null, 74 /** 75 * @private 76 * @property _params 77 * @description Holder for the params argument 78 */ 79 _params: null, 80 /** 81 * @private 82 * @property _context 83 * @description The context to execute the callback in 84 */ 85 _context: null, 86 /** 87 * @private 88 * @method _internal 89 * @description Internal Callback Handler 90 */ 91 _internal: function () { 92 this._callback.apply(this._context, arguments); 93 }, 94 /** 95 * @method send 96 * @description The method that executes the YQL Request. 97 * @chainable 98 * @return {YQLRequest} 99 */ 100 send: function () { 101 var qs = [], url = ((this._opts && this._opts.proto) ? this._opts.proto : Y.YQLRequest.PROTO), o; 102 103 Y.Object.each(this._params, function (v, k) { 104 qs.push(k + '=' + encodeURIComponent(v)); 105 }); 106 107 qs = qs.join('&'); 108 109 url += ((this._opts && this._opts.base) ? this._opts.base : Y.YQLRequest.BASE_URL) + qs; 110 111 o = (!Y.Lang.isFunction(this._callback)) ? this._callback : { on: { success: this._callback } }; 112 113 o.on = o.on || {}; 114 this._callback = o.on.success; 115 116 o.on.success = Y.bind(this._internal, this); 117 118 this._send(url, o); 119 return this; 120 }, 121 /** 122 * Private method to send the request, overwritten in plugins 123 * @method _send 124 * @private 125 * @param {String} url The URL to request 126 * @param {Object} o The config object 127 */ 128 _send: function() { 129 //Overwritten in plugins 130 } 131 }; 132 133 /** 134 * @static 135 * @property FORMAT 136 * @description Default format to use: json 137 */ 138 YQLRequest.FORMAT = 'json'; 139 /** 140 * @static 141 * @property PROTO 142 * @description Default protocol to use: http 143 */ 144 YQLRequest.PROTO = 'http'; 145 /** 146 * @static 147 * @property BASE_URL 148 * @description The base URL to query: query.yahooapis.com/v1/public/yql? 149 */ 150 YQLRequest.BASE_URL = ':/' + '/query.yahooapis.com/v1/public/yql?'; 151 /** 152 * @static 153 * @property ENV 154 * @description The environment file to load: http://datatables.org/alltables.env 155 */ 156 YQLRequest.ENV = 'http:/' + '/datatables.org/alltables.env'; 157 158 Y.YQLRequest = YQLRequest; 159 160 /** 161 * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/). 162 * @class YQL 163 * @constructor 164 * @param {String} sql The SQL statement to execute 165 * @param {Function} callback The callback to execute after the query (optional). 166 * @param {Object} params An object literal of extra parameters to pass along (optional). 167 * @param {Object} opts An object literal of configuration options (optional): proto (http|https), base (url) 168 */ 169 Y.YQL = function (sql, callback, params, opts) { 170 return new Y.YQLRequest(sql, callback, params, opts).send(); 171 }; 172 173 174 }, '3.17.2', {"requires": ["oop"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |