2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('datasource-jsonschema', function (Y, NAME) {
11 * Extends DataSource with schema-parsing on JSON data.
14 * @submodule datasource-jsonschema
18 * Adds schema-parsing to the DataSource Utility.
19 * @class DataSourceJSONSchema
20 * @extends Plugin.Base
22 var DataSourceJSONSchema = function() {
23 DataSourceJSONSchema.superclass.constructor.apply(this, arguments);
26 Y.mix(DataSourceJSONSchema, {
28 * The namespace for the plugin. This will be the property on the host which
29 * references the plugin instance.
46 * @value "dataSourceJSONSchema"
48 NAME: "dataSourceJSONSchema",
50 /////////////////////////////////////////////////////////////////////////////
52 // DataSourceJSONSchema Attributes
54 /////////////////////////////////////////////////////////////////////////////
63 Y.extend(DataSourceJSONSchema, Y.Plugin.Base, {
65 * Internal init() handler.
68 * @param config {Object} Config object.
71 initializer: function(config) {
72 this.doBefore("_defDataFn", this._beforeDefDataFn);
76 * Parses raw data into a normalized response. To accommodate XHR responses,
77 * will first look for data in data.responseText. Otherwise will just work
80 * @method _beforeDefDataFn
81 * @param tId {Number} Unique transaction ID.
82 * @param request {Object} The request.
83 * @param callback {Object} The callback object with the following properties:
85 * <dt>success (Function)</dt> <dd>Success handler.</dd>
86 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
88 * @param data {Object} Raw data.
91 _beforeDefDataFn: function(e) {
92 var data = e.data && (e.data.responseText || e.data),
93 schema = this.get('schema'),
94 payload = e.details[0];
96 payload.response = Y.DataSchema.JSON.apply.call(this, schema, data) || {
101 this.get("host").fire("response", payload);
103 return new Y.Do.Halt("DataSourceJSONSchema plugin halted _defDataFn");
107 Y.namespace('Plugin').DataSourceJSONSchema = DataSourceJSONSchema;
110 }, '3.13.0', {"requires": ["datasource-local", "plugin", "dataschema-json"]});