/usr/share/javascript/yui3/datatable-column-widths/datatable-column-widths.js is in libjs-yui3-full 3.5.1-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | /*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add('datatable-column-widths', function(Y) {
/**
Adds basic, programmatic column width support to DataTable via column
configuration property `width` and method `table.setColumnWidth(id, width);`.
@module datatable
@submodule datatable-column-widths
@since 3.5.0
**/
var isNumber = Y.Lang.isNumber,
arrayIndex = Y.Array.indexOf;
Y.Features.add('table', 'badColWidth', {
test: function () {
var body = Y.one('body'),
node, broken;
if (body) {
// In modern browsers, <col style="width:X"> will make columns,
// *including padding and borders* X wide. The cell content width
// is reduced. In old browsers and all Opera versions to date, the
// col's width style is passed to the cells, which causes cell
// padding/border to bloat the rendered width.
node = body.insertBefore(
'<table style="position:absolute;visibility:hidden;border:0 none">' +
'<colgroup><col style="width:9px"></colgroup>' +
'<tbody><tr>' +
'<td style="' +
'padding:0 4px;' +
'font:normal 2px/2px arial;' +
'border:0 none">' +
'.' + // Just something to give the cell dimension
'</td></tr></tbody>' +
'</table>',
body.get('firstChild'));
broken = node.one('td').getComputedStyle('width') !== '1px';
node.remove(true);
}
return broken;
}
});
/**
_API docs for this extension are included in the DataTable class._
Adds basic, programmatic column width support to DataTable. Note, this does not
add support for truncated columns. Due to the way HTML tables render, column
width is more like a "recommended width". Column content wider than the
assigned width will cause the column to expand, despite the configured width.
Similarly if the table is too narrow to fit the column with the configured
column width, the column width will be reduced.
To set a column width, either add a `width` value to the column configuration
or call the `setColumnWidth(id, width)` method.
Note, assigning column widths is possible without this module, as each cell is
decorated with a class appropriate for that column which you can statically
target in your site's CSS.
To achieve absolute column widths, with content truncation, you can either:
1. Use this module, configure *all* columns to have `width`s, then add
`table-layout: fixed;` to your CSS for the appropriate `<table>`, or
2. Wrap the contents of all cells in the column with a `<div>` (using a
`cellTemplate` or `formatter`), assign the div's style `width`, then assign
the column `width` or add a CSS `width` to the column class created by
DataTable.
<pre><code>.yui3-datatable .yui3-datatable-col-foo {
padding: 0;
width: 125px;
}
.yui3-datatable .yui3-datatable-col-foo .yui3-datatable-liner {
overflow: hidden;
padding: 4px 10px;
width: 125px;
}
</pre></code>
<pre><code>var table = new Y.DataTable({
columns: [
{
key: 'foo',
cellTemplate:
'<td class="{className}">' +
'<div class="yui3-datatable-liner">{content}</div>' +
'</td>'
},
...
],
...
});
</code></pre>
To add a liner to all columns, either provide a custom `bodyView` to the
DataTable constructor or update the default `bodyView`'s `CELL_TEMPLATE` like
so:
<pre><code>table.on('renderBody', function (e) {
e.view.CELL_TEMPLATE = e.view.CELL_TEMPLATE.replace(/\{content\}/,
'<div class="yui3-datatable-liner">{content}</div>');
});
</code></pre>
Keep in mind that DataTable skins apply cell `padding`, so assign your CSS
`width`s accordingly or override the `padding` style for that column's `<td>`s
to 0, and add `padding` to the liner `<div>`'s styles as shown above.
@class DataTable.ColumnWidths
@for DataTable
@since 3.5.0
**/
function ColumnWidths() {}
Y.mix(ColumnWidths.prototype, {
/**
The HTML template used to create the table's `<col>`s.
@property COL_TEMPLATE
@type {HTML}
@default '<col/>'
@since 3.5.0
**/
COL_TEMPLATE: '<col/>',
/**
The HTML template used to create the table's `<colgroup>`.
@property COLGROUP_TEMPLATE
@type {HTML}
@default '<colgroup/>'
@since 3.5.0
**/
COLGROUP_TEMPLATE: '<colgroup/>',
/**
Assigns the style width of the `<col>` representing the column identifed by
`id` and updates the column configuration.
Pass the empty string for `width` to return a column to auto sizing.
This does not trigger a `columnsChange` event today, but I can be convinced
that it should.
@method setColumnWidth
@param {Number|String|Object} id The column config object or key, name, or
index of a column in the host's `_displayColumns` array.
@param {Number|String} width CSS width value. Numbers are treated as pixels
@return {DataTable}
@chainable
@since 3.5.0
**/
setColumnWidth: function (id, width) {
var col = this.getColumn(id),
index = col && arrayIndex(this._displayColumns, col);
if (index > -1) {
if (isNumber(width)) {
width += 'px';
}
col.width = width;
this._setColumnWidth(index, width);
}
return this;
},
//----------------------------------------------------------------------------
// Protected properties and methods
//----------------------------------------------------------------------------
/**
Renders the table's `<colgroup>` and populates the `_colgroupNode` property.
@method _createColumnGroup
@protected
@since 3.5.0
**/
_createColumnGroup: function () {
return Y.Node.create(this.COLGROUP_TEMPLATE);
},
/**
Hooks up to the rendering lifecycle to also render the `<colgroup>` and
subscribe to `columnChange` events.
@method initializer
@protected
@since 3.5.0
**/
initializer: function (config) {
this.after('renderTable', function (e) {
this._uiSetColumns();
this.after('columnsChange', this._uiSetColumns);
});
},
/**
Sets a columns's `<col>` element width style. This is needed to get around
browser rendering differences.
The colIndex corresponds to the item index of the `<col>` in the table's
`<colgroup>`.
To unset the width, pass a falsy value for the `width`.
@method _setColumnWidth
@param {Number} colIndex The display column index
@param {Number|String} width The desired width
@protected
@since 3.5.0
**/
// TODO: move this to a conditional module
_setColumnWidth: function (colIndex, width) {
// Opera (including Opera Next circa 1/13/2012) and IE7- pass on the
// width style to the cells directly, allowing padding and borders to
// expand the rendered width. Chrome 16, Safari 5.1.1, and FF 3.6+ all
// make the rendered width equal the col's style width, reducing the
// cells' calculated width.
var colgroup = this._colgroupNode,
col = colgroup && colgroup.all('col').item(colIndex),
firstRow, cell, getCStyle;
if (col) {
if (width && isNumber(width)) {
width += 'px';
}
col.setStyle('width', width);
// Adjust the width for browsers that make
// td.style.width === col.style.width
if (width && Y.Features.test('table', 'badColWidth')) {
firstRow = this._tbodyNode && this._tbodyNode.one('tr');
cell = firstRow && firstRow.all('td').item(colIndex);
if (cell) {
getCStyle = function (prop) {
return parseInt(cell.getComputedStyle(prop), 10)|0;
};
col.setStyle('width',
// I hate this
parseInt(width, 10) -
getCStyle('paddingLeft') -
getCStyle('paddingRight') -
getCStyle('borderLeftWidth') -
getCStyle('borderRightWidth') + 'px');
}
}
}
},
/**
Populates the table's `<colgroup>` with a `<col>` per item in the `columns`
attribute without children. It is assumed that these are the columns that
have data cells renderered for them.
@method _uiSetColumns
@protected
@since 3.5.0
**/
_uiSetColumns: function () {
var template = this.COL_TEMPLATE,
colgroup = this._colgroupNode,
columns = this._displayColumns,
i, len;
if (!colgroup) {
colgroup = this._colgroupNode = this._createColumnGroup();
this._tableNode.insertBefore(
colgroup,
this._tableNode.one('> thead, > tfoot, > tbody'));
} else {
colgroup.empty();
}
for (i = 0, len = columns.length; i < len; ++i) {
colgroup.append(template);
this._setColumnWidth(i, columns[i].width);
}
}
}, true);
Y.DataTable.ColumnWidths = ColumnWidths;
Y.Base.mix(Y.DataTable, [ColumnWidths]);
}, '3.5.1' ,{requires:['datatable-base']});
|