autocomplete-sources-debug.js revision 76ca635d61eb3f9fb7c9d788a44fa8b1690aa138
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassYUI.add('autocomplete-sources', function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Mixes support for JSONP and YQL result sources into AutoCompleteBase.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module autocomplete
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @submodule autocomplete-sources
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassvar ACBase = Y.AutoCompleteBase,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Lang = Y.Lang,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _SOURCE_SUCCESS = '_sourceSuccess',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass MAX_RESULTS = 'maxResults',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass REQUEST_TEMPLATE = 'requestTemplate',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass RESULT_LIST_LOCATOR = 'resultListLocator';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// Add prototype properties and methods to AutoCompleteBase.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.mix(ACBase.prototype, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Regular expression used to determine whether a String source is a YQL
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * query.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property _YQL_SOURCE_REGEX
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type RegExp
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _YQL_SOURCE_REGEX: /^(?:select|set|use)\s+/i,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Runs before AutoCompleteBase's <code>_createObjectSource()</code> method
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * and augments it to support additional object-based source types.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _beforeCreateObjectSource
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} source
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _beforeCreateObjectSource: function (source) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // If the object is a <select> node, use the options as the result
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // source.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (source instanceof Y.Node &&
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass source.get('nodeName').toLowerCase() === 'select') {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._createSelectSource(source);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // If the object is a JSONPRequest instance, try to use it as a JSONP
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // source.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (Y.JSONPRequest && source instanceof Y.JSONPRequest) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._createJSONPSource(source);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Fall back to a basic object source.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._createObjectSource(source);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Creates a DataSource-like object that uses <code>Y.io</code> as a source.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * See the <code>source</code> attribute for more details.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _createIOSource
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} source URL.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} DataSource-like object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createIOSource: function (source) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var cache = {},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ioSource = {type: 'io'},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that = this,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ioRequest, lastRequest, loading;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Private internal _sendRequest method that will be assigned to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // ioSource.sendRequest once io-base and json-parse are available.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass function _sendRequest(request) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var query = request.query;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Return immediately on a cached response.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (cache[query]) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](cache[query], request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Cancel any outstanding requests.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (ioRequest && ioRequest.isInProgress()) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ioRequest.abort();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ioRequest = Y.io(that._getXHRUrl(source, query), {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass on: {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass success: function (tid, response) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var data;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass try {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass data = Y.JSON.parse(response.responseText);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } catch (ex) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.error('JSON parse error', ex);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (data) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass cache[query] = data;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](data, request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ioSource.sendRequest = function (request) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Keep track of the most recent request in case there are multiple
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // requests while we're waiting for the IO module to load. Only the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // most recent request will be sent.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass lastRequest = request;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (loading) { return; }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass loading = true;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Lazy-load the io-base and json-parse modules if necessary,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // then overwrite the sendRequest method to bypass this check in
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // the future.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.use('io-base', 'json-parse', function () {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ioSource.sendRequest = _sendRequest;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _sendRequest(lastRequest);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return ioSource;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Creates a DataSource-like object that uses the specified JSONPRequest
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * instance as a source. See the <code>source</code> attribute for more
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * details.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _createJSONPSource
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {JSONPRequest|String} source URL string or JSONPRequest instance.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} DataSource-like object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createJSONPSource: function (source) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var cache = {},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass jsonpSource = {type: 'jsonp'},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that = this,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass lastRequest, loading;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass function _sendRequest(request) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var query = request.query;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (cache[query]) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](cache[query], request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Hack alert: JSONPRequest currently doesn't support
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // per-request callbacks, so we're reaching into the protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // _config object to make it happen.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass //
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // This limitation is mentioned in the following JSONP
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // enhancement ticket:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass //
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // http://yuilibrary.com/projects/yui3/ticket/2529371
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass source._config.on.success = function (data) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass cache[query] = data;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](data, request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass source.send(query);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass jsonpSource.sendRequest = function (request) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Keep track of the most recent request in case there are multiple
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // requests while we're waiting for the JSONP module to load. Only
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // the most recent request will be sent.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass lastRequest = request;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (loading) { return; }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass loading = true;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Lazy-load the JSONP module if necessary, then overwrite the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // sendRequest method to bypass this check in the future.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.use('jsonp', function () {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Turn the source into a JSONPRequest instance if it isn't
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // one already.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (!(source instanceof Y.JSONPRequest)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass source = new Y.JSONPRequest(source, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass format: Y.bind(that._jsonpFormatter, that)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass jsonpSource.sendRequest = _sendRequest;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _sendRequest(lastRequest);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return jsonpSource;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Creates a DataSource-like object that uses the specified &lt;select&gt;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * node as a source.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _createSelectSource
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Node} source YUI Node instance wrapping a &lt;select&gt; node.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} DataSource-like object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createSelectSource: function (source) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var that = this;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass type: 'select',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass sendRequest: function (request) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var options = [];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass source.get('options').each(function (option) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass options.push({
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass html : option.get('innerHTML'),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass index : option.get('index'),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass node : option,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass selected: option.get('selected'),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass text : option.get('text'),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass value : option.get('value')
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](options, request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Creates a DataSource-like object that calls the specified URL or
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * executes the specified YQL query for results. If the string starts
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * with "select ", "use ", or "set " (case-insensitive), it's assumed to be
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * a YQL query; otherwise, it's assumed to be a URL (which may be absolute
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * or relative). URLs containing a "{callback}" placeholder are assumed to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * be JSONP URLs; all others will use XHR. See the <code>source</code>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * attribute for more details.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _createStringSource
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} source URL or YQL query.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} DataSource-like object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createStringSource: function (source) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (this._YQL_SOURCE_REGEX.test(source)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Looks like a YQL query.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._createYQLSource(source);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else if (source.indexOf('{callback}') !== -1) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Contains a {callback} param and isn't a YQL query, so it must be
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // JSONP.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._createJSONPSource(source);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Not a YQL query or JSONP, so we'll assume it's an XHR URL.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._createIOSource(source);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Creates a DataSource-like object that uses the specified YQL query string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * to create a YQL-based source. See the <code>source</code> attribute for
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * details. If no <code>resultListLocator</code> is defined, this method
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * will set a best-guess locator that might work for many typical YQL
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * queries.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _createYQLSource
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} source YQL query.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} DataSource-like object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createYQLSource: function (source) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var cache = {},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlSource = {type: 'yql'},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that = this,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass lastRequest, loading, yqlRequest;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (!this.get(RESULT_LIST_LOCATOR)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.set(RESULT_LIST_LOCATOR, this._defaultYQLLocator);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass function _sendRequest(request) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var query = request.query,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass callback, env, maxResults, opts, yqlQuery;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (cache[query]) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](cache[query], request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass callback = function (data) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass cache[query] = data;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](data, request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass env = that.get('yqlEnv');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass maxResults = that.get(MAX_RESULTS);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass opts = {proto: that.get('yqlProtocol')};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlQuery = Lang.sub(source, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass maxResults: maxResults > 0 ? maxResults : 1000,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass query : query
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Only create a new YQLRequest instance if this is the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // first request. For subsequent requests, we'll reuse the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // original instance.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (yqlRequest) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlRequest._callback = callback;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlRequest._opts = opts;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlRequest._params.q = yqlQuery;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (env) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlRequest._params.env = env;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlRequest = new Y.YQLRequest(yqlQuery, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass on: {success: callback},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass allowCache: false // temp workaround until JSONP has per-URL callback proxies
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }, env ? {env: env} : null, opts);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlRequest.send();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlSource.sendRequest = function (request) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Keep track of the most recent request in case there are multiple
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // requests while we're waiting for the YQL module to load. Only the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // most recent request will be sent.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass lastRequest = request;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (!loading) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Lazy-load the YQL module if necessary, then overwrite the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // sendRequest method to bypass this check in the future.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass loading = true;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.use('yql', function () {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlSource.sendRequest = _sendRequest;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _sendRequest(lastRequest);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return yqlSource;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Default resultListLocator used when a string-based YQL source is set and
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the implementer hasn't already specified one.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _defaultYQLLocator
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} response YQL response object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Array}
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _defaultYQLLocator: function (response) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var results = response && response.query && response.query.results,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass values;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (results && Lang.isObject(results)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // If there's only a single value on YQL's results object, that
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // value almost certainly contains the array of results we want. If
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // there are 0 or 2+ values, then the values themselves are most
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // likely the results we want.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass values = Y.Object.values(results) || [];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass results = values.length === 1 ? values[0] : values;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (!Lang.isArray(results)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass results = [results];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass results = [];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return results;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns a formatted XHR URL based on the specified base <i>url</i>,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <i>query</i>, and the current <i>requestTemplate</i> if any.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _getXHRUrl
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} url Base URL.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} query AutoComplete query.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {String} Formatted URL.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _getXHRUrl: function (url, query) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var maxResults = this.get(MAX_RESULTS),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass requestTemplate = this.get(REQUEST_TEMPLATE);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (requestTemplate) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass url += requestTemplate(query);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Lang.sub(url, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass maxResults: maxResults > 0 ? maxResults : 1000,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass query : encodeURIComponent(query)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * URL formatter passed to <code>JSONPRequest</code> instances.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _jsonpFormatter
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} url
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} proxy
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} query
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {String} Formatted URL
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _jsonpFormatter: function (url, proxy, query) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var maxResults = this.get(MAX_RESULTS),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass requestTemplate = this.get(REQUEST_TEMPLATE);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (requestTemplate) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass url += requestTemplate(query);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Lang.sub(url, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass callback : proxy,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass maxResults: maxResults > 0 ? maxResults : 1000,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass query : encodeURIComponent(query)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// Add attributes to AutoCompleteBase.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.mix(ACBase.ATTRS, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YQL environment file URL to load when the <code>source</code> is set to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * a YQL query. Set this to <code>null</code> to use the default Open Data
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Tables environment file (http://datatables.org/alltables.env).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @attribute yqlEnv
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default null
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlEnv: {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass value: null
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * URL protocol to use when the <code>source</code> is set to a YQL query.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @attribute yqlProtocol
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default 'http'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for AutoCompleteBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlProtocol: {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass value: 'http'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// Tell AutoCompleteBase about the new source types it can now support.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.mix(ACBase.SOURCE_TYPES, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass io : '_createIOSource',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass jsonp : '_createJSONPSource',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass object: '_beforeCreateObjectSource', // Run our version before the base version.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass select: '_createSelectSource',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass string: '_createStringSource',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yql : '_createYQLSource'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}, true);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}, '@VERSION@' ,{requires:['autocomplete-base'], optional:['io-base', 'json-parse', 'jsonp', 'yql']});