pe.js revision 0e7d399f99fcb097a927af7e6588f393740585a2
273e421813f295d65aab512f508e8fb575d997d4gouldtjvar getClassName = Y.ClassNameManager.getClassName,
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtj DOT = '.',
273e421813f295d65aab512f508e8fb575d997d4gouldtj DATATABLE = 'datatable',
273e421813f295d65aab512f508e8fb575d997d4gouldtj CN_TABLE = getClassName(DATATABLE, 'table'),
273e421813f295d65aab512f508e8fb575d997d4gouldtj CN_THEAD = getClassName(DATATABLE, 'head'),
273e421813f295d65aab512f508e8fb575d997d4gouldtj CN_TFOOT = getClassName(DATATABLE, 'foot'),
273e421813f295d65aab512f508e8fb575d997d4gouldtj CN_TBODY = getClassName(DATATABLE, 'data'),
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjfunction EnhanceMarkup() {}
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjY.mix(EnhanceMarkup, {
273e421813f295d65aab512f508e8fb575d997d4gouldtj HTML_PARSER: {
273e421813f295d65aab512f508e8fb575d997d4gouldtj _tableNode : '_findHTMLTableNode',
273e421813f295d65aab512f508e8fb575d997d4gouldtj _captionNode: '_findHTMLCaptionNode',
273e421813f295d65aab512f508e8fb575d997d4gouldtj _theadNode : '_findHTMLTheadNode',
273e421813f295d65aab512f508e8fb575d997d4gouldtj _tfootNode : '_findHTMLTfootNode',
273e421813f295d65aab512f508e8fb575d997d4gouldtj _tbodyNode : '_findHTMLTbodyNode',
273e421813f295d65aab512f508e8fb575d997d4gouldtj columns: '_parseHTMLColumns',
273e421813f295d65aab512f508e8fb575d997d4gouldtj caption: '_parseHTMLCaption',
273e421813f295d65aab512f508e8fb575d997d4gouldtj summary: '_parseHTMLSummary'
273e421813f295d65aab512f508e8fb575d997d4gouldtj }
273e421813f295d65aab512f508e8fb575d997d4gouldtj});
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjY.mix(EnhanceMarkup.prototype, {
273e421813f295d65aab512f508e8fb575d997d4gouldtj // -- Instance properties -------------------------------------------------
273e421813f295d65aab512f508e8fb575d997d4gouldtj RE_COLUMN_ATTR: /data-yui3-column-(.*)/,
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtj // -- Public methods ------------------------------------------------------
initializer: function (config) {
if (config) {
// Node references from HTML_PARSER to support progressive
// enhancement, but aren't stored as attributes.
this._tableNode = config._tableNode;
this._captionNode = config._captionNode;
this._theadNode = config._theadNode;
this._tfootNode = config._tfootNode;
this._tbodyNode = config._tbodyNode;
}
},
// -- Protected and private methods ---------------------------------------
_findHTMLCaptionNode: function (srcNode) {
return srcNode.one(DOT + this.getClassName('table') + ' > caption');
},
_findHTMLTableNode: function (srcNode) {
return (srcNode.get('tagName') === 'table') ?
srcNode :
srcNode.one(DOT + this.getClassName('table'));
},
_findHTMLTbodyNode: function (srcNode) {
return srcNode.one(DOT + this.getClassName('data'));
},
_findHTMLTfootNode: function (srcNode) {
return srcNode.one(DOT + this.getClassName('foot'));
},
_findHTMLTheadNode: function (srcNode) {
return srcNode.one(DOT + this.getClassName('head'));
},
_parseHTMLCaption: function (srcNode) {
var caption = this._findHTMLCaptionNode(srcNode);
return caption && caption.getContent();
},
_parseHTMLColumns: function (srcNode) {
var self = this,
ths = srcNode.all('> .' + CN_THEAD + ' th'),
columns = [];
ths.each(function (th) {
// TODO: if (th.get('colspan')) { => children }
// TODO: use dataset shim when it becomes available
var attributes = th.getDOMNode().attributes,
dataAttrRE = self.RE_COLUMN_ATTR,
col = {
key: th.get('text'),
label: th.getContent()
},
i, match;
if (attributes) {
for (i = attributes.length - 1; i >= 0; --i) {
match = attributes[i].name.match(dataAttrRE);
if (match) {
// Attributes and dataset differ in that data-foo-bar
// and data-fooBar will both become dataset.fooBar.
// Assume the implementer will use the correct casing.
col[match[1]] = attributes[i].value;
}
}
}
columns.push(col);
});
return (columns.length) ? columns : null;
},
_parseHTMLSummary: function (srcNode) {
var table = (srcNode.test('table')) ? srcNode : srcNode.one('table');
return table && table.getAttribute('summary');
}
});
Y.DataTable.EnhanceMarkup = EnhanceMarkup;
Y.Base.mix(Y.DataTable, [EnhanceMarkup]);