Skip to content

Instantly share code, notes, and snippets.

@lsmith
lsmith / gist:1599086
Created January 12, 2012 06:39
Patch for datatable-datasource to work with gallery-datatable-350-preview
YUI.add('datatabledatasource-350-preview-patch', function (Y) {
// Or just put this in your code directly
Y.Plugin.DataTableDataSource.prototype.onDataReturnInitializeTable = function (e) {
this.get('host').set('data', (e.response && e.response.results) || []);
};
}, '0.1', { requires: ['datatable-datasource'] });
@lsmith
lsmith / A_and_B_ext.js
Created January 10, 2012 05:03
Allow class extensions to define which static properties to merge onto the built class from Y.Base.create/mix
// See ticket #2531567
// Use the current support for SuperClass._buildCfg.custom.{anyName} = handlerFunction to look for
// a new property Ext._buildCfg.buildFn on each class extension. If there, execute it. The extension
// then uses that function to manually migrate its static properties of interest.
// Two approaches are shown, but both rely on the Ext._buildCfg.buildFn static. This property and
// name are arbitrary. What matters is that the handlerFunction assigned to the superclass's
// _buildCfg.custom collection establishes the contract for where to find this attribute on each
// class extension.
@lsmith
lsmith / gist:1584942
Created January 9, 2012 21:05
Updated version of YUI 3.4.1 recordset attribute setter to support table.set('recordset', newData) without losing existing recordset plugins.
Y.DataTable.Base.ATTRS.recordset.setter = function (val) {
var current = this.get('recordset');
if (val) {
if (val instanceof Y.Recordset) {
if (current && val !== current) {
// Transfer plugins (untested, YMMV)
Y.Object.each(current._plugins || {}, function (plugin) {
val.plug(plugin.constructor, plugin.getAttrs());
});
@lsmith
lsmith / gist:1505319
Created December 21, 2011 09:04
Sortable 3.4.1 DataTable with live filtering
<!doctype html>
<!-- See http://jsfiddle.net/VYzXx/ for a live example -->
<html>
<head>
<meta charset="utf-8">
<title>Live filtering a 3.4.1 DataTable from an input field</title>
</head>
<body class="yui3-skin-sam">
<p>The following table is sortable and searchable, and will preserve sort order across filter operations.</p>

DataTable design overview

These are my early thoughts on how to structure DataTable in 3.5.0. Feedback is welcome in the comments.

Instantiable classes out of the box

new Y.DataTable({...});
new Y.DataTable.Base({...});
// For Y.Foo
// Class extensions that will be used in the base class
function ExtA() {}
...
Y.namespace('Foo').ExtA = ExtA;
// Base Class definition
function FooBase() {}
...
YUI({
modules: {
somemodule: {
fullpath: '/path/to/somemodule.js',
requires: ['somemodule-css']
},
somemodule-css: {
type: 'css',
fullpath: '/path/to/somemodule.css'
}
@lsmith
lsmith / my_my-mod_assets_skins_sam_my-mod.css
Created September 27, 2011 05:51
YUI config for a module skin
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test Page</title>
</head>
<body>
<div id="x">This is X</div>
@lsmith
lsmith / gist:1223638
Created September 17, 2011 04:54
A fragile workaround to IE event facades calculating pageX/Y, possibly triggering a premature reflow
/*
You probably shouldn't use this. It relies on no other code on the page setting the
document.(documentElement/body).onscroll property. If other code is on the page before
this patch is executed, it will be clobbered. If after this patch is executed, all
e.pageX/Y values will be wrong in IE 6-8 if the window is scrolled.
Every major library handles IE's e.pageX/Y deficiency the same way today. Yes, it might
cause a reflow, but the 90%+ case will be that the document's scrollTop/Left properties
are accessed, but no reflow is triggered. DOM access sucks and all, but it's incredibly
unlikely this will show up on your performance profiling.
@lsmith
lsmith / gist:1189270
Created September 2, 2011 17:44
YUI 3 method to calculate the width of scrollbars on the given OS
var scrollbarWidth = Y.cached(function () {
var testNode = Y.one('body').appendChild('<div style="position:absolute;visibility:hidden;overflow:scroll;width:20px;"><p style="height:1px"/></div>'),
width = testNode.get('offsetWidth') - testNode.get('clientWidth');
testNode.remove(true);
return width;
});