76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassYUI.add('autocomplete-sources', function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan GroveMixes support for JSONP and YQL result sources into AutoCompleteBase.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove@module autocomplete
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove@submodule autocomplete-sources
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove**/
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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Regular expression used to determine whether a String source is a YQL query.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @property _YQL_SOURCE_REGEX
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @type RegExp
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _YQL_SOURCE_REGEX: /^(?:select|set|use)\s+/i,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Runs before AutoCompleteBase's `_createObjectSource()` method and augments
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove it to support additional object-based source types.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _beforeCreateObjectSource
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} source
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Creates a DataSource-like object that uses `Y.io` as a source. See the
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove `source` attribute for more details.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _createIOSource
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} source URL.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {Object} DataSource-like object.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createIOSource: function (source) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove var 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) {
753ef90e92d428310b4a07006e8850639c6faaadRyan Grove var cacheKey = request.request,
753ef90e92d428310b4a07006e8850639c6faaadRyan Grove query = request.query;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Return immediately on a cached response.
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove if (that._cache && cacheKey in that._cache) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove that[_SOURCE_SUCCESS](that._cache[cacheKey], 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
20ec7ff76cf1e295267fb55bb238bd8894b08188Ryan Grove ioRequest = Y.io(that._getXHRUrl(source, request), {
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) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove that._cache && (that._cache[cacheKey] = 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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Creates a DataSource-like object that uses the specified JSONPRequest
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove instance as a source. See the `source` attribute for more details.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _createJSONPSource
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {JSONPRequest|String} source URL string or JSONPRequest instance.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {Object} DataSource-like object.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createJSONPSource: function (source) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove var jsonpSource = {type: 'jsonp'},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that = this,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass lastRequest, loading;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass function _sendRequest(request) {
753ef90e92d428310b4a07006e8850639c6faaadRyan Grove var cacheKey = request.request,
753ef90e92d428310b4a07006e8850639c6faaadRyan Grove query = request.query;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove if (that._cache && cacheKey in that._cache) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove that[_SOURCE_SUCCESS](that._cache[cacheKey], 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) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove that._cache && (that._cache[cacheKey] = 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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Creates a DataSource-like object that uses the specified `<select>` node as
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove a source.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _createSelectSource
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {Node} source YUI Node instance wrapping a `<select>` node.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {Object} DataSource-like object.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Creates a DataSource-like object that calls the specified URL or executes
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove the specified YQL query for results. If the string starts with "select ",
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove "use ", or "set " (case-insensitive), it's assumed to be a YQL query;
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove otherwise, it's assumed to be a URL (which may be absolute or relative).
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove URLs containing a "{callback}" placeholder are assumed to be JSONP URLs; all
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove others will use XHR. See the `source` attribute for more details.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _createStringSource
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} source URL or YQL query.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {Object} DataSource-like object.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Creates a DataSource-like object that uses the specified YQL query string to
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove create a YQL-based source. See the `source` attribute for details. If no
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove `resultListLocator` is defined, this method will set a best-guess locator
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove that might work for many typical YQL queries.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _createYQLSource
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} source YQL query.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {Object} DataSource-like object.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _createYQLSource: function (source) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove var that = this,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlSource = {type: 'yql'},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass lastRequest, loading, yqlRequest;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove if (!that.get(RESULT_LIST_LOCATOR)) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove that.set(RESULT_LIST_LOCATOR, that._defaultYQLLocator);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass function _sendRequest(request) {
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove var query = request.query,
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove env = that.get('yqlEnv'),
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove maxResults = that.get(MAX_RESULTS),
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove callback, opts, yqlQuery;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove yqlQuery = Lang.sub(source, {
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove maxResults: maxResults > 0 ? maxResults : 1000,
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove request : request.request,
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove query : query
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove });
ccca2ecca341ffc5373997aa8deee5e70677dbfdRyan Grove
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove if (that._cache && yqlQuery in that._cache) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove that[_SOURCE_SUCCESS](that._cache[yqlQuery], request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass callback = function (data) {
6506cffe711cef12e98d0096a15b9de5ca07931bRyan Grove that._cache && (that._cache[yqlQuery] = data);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass that[_SOURCE_SUCCESS](data, request);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass opts = {proto: that.get('yqlProtocol')};
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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Default resultListLocator used when a string-based YQL source is set and the
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove implementer hasn't already specified one.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _defaultYQLLocator
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {Object} response YQL response object.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {Array}
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Returns a formatted XHR URL based on the specified base _url_, _query_, and
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove the current _requestTemplate_ if any.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _getXHRUrl
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} url Base URL.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {Object} request Request object containing `query` and `request`
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove properties.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {String} Formatted URL.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
20ec7ff76cf1e295267fb55bb238bd8894b08188Ryan Grove _getXHRUrl: function (url, request) {
20ec7ff76cf1e295267fb55bb238bd8894b08188Ryan Grove var maxResults = this.get(MAX_RESULTS);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
20ec7ff76cf1e295267fb55bb238bd8894b08188Ryan Grove if (request.query !== request.request) {
20ec7ff76cf1e295267fb55bb238bd8894b08188Ryan Grove // Append the request template to the URL.
20ec7ff76cf1e295267fb55bb238bd8894b08188Ryan Grove url += request.request;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Lang.sub(url, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass maxResults: maxResults > 0 ? maxResults : 1000,
20ec7ff76cf1e295267fb55bb238bd8894b08188Ryan Grove query : encodeURIComponent(request.query)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove URL formatter passed to `JSONPRequest` instances.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @method _jsonpFormatter
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} url
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} proxy
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @param {String} query
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @return {String} Formatted URL
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @protected
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
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 /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove YQL environment file URL to load when the `source` is set to a YQL query.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove Set this to `null` to use the default Open Data Tables environment file
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove (http://datatables.org/alltables.env).
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @attribute yqlEnv
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @type String
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @default null
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yqlEnv: {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass value: null
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove URL protocol to use when the `source` is set to a YQL query.
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @attribute yqlProtocol
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @type String
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @default 'http'
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove @for AutoCompleteBase
4bc090583f2a5d4fee80ca7a79a993d4e5ac14ecRyan Grove **/
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
c0486d6f93858a5de5737e65f736d40e4b0feed5Ryan Grove}, '@VERSION@' ,{requires:['autocomplete-base'], optional:['io-base', 'json-parse', 'jsonp', 'yql']});