Skip to content

Instantly share code, notes, and snippets.

@lsmith
lsmith / datatable-events.js
Created July 8, 2011 00:12
A Plugin to create cellClick, rowMousedown, etc events on DataTable
YUI.add('datatable-events', function (Y) {
Y.Plugin.DataTableEvents = Y.Base.create('dtevents', Y.Plugin.Base, [], {
initializer: function (config) {
this.afterHostMethod('bindUI', function () {
this._bindEvents(this.get('events'));
this.after('eventsChange', this._afterEventsChange);
});
},
@lsmith
lsmith / gist:2244450
Created March 29, 2012 22:38
Keyboard navigable DataTable rows with selection
/*
This code should allow users to tab to the first row in the table, which will "select" it by
adding a class to it and storing a reference to the row node. Alternately, users can click
on a row to select it. Selection can be shifted to the next or previous row with the up and down arrow keys. The 'enter' key will fire a 'rowAction' custom event.
*/
table.getRow(0).setAttribute('tabindex', table.get('tabIndex') || 0);
table.delegate('keydown', function (e) {
var selected = this._selectedRow,
tbody = this._tbodyNode,
YUITest.TestCase.prototype = {
// ...
wait: function (segment, timeout) {
var delay = (typeof segment === 'number') ? segment :
(typeof timeout === 'number') ? timeout :
YUITest.MAX_WAIT;
throw new YUITest.Wait((typeof segment === 'function' ? segment : YUITest._waitTimeout), delay);
},
@lsmith
lsmith / gist:6664382
Last active December 23, 2015 16:49
Custom event hacked up to support defaultFn that can return a promise to delay after subscribers. POC, mostly untested, so YMMV.
/*global SM:true*/
'use strict';
// Publish a very special, promise-compatible event that supports the default
// function behavior to chain on internally created promises before executing
// the after() subs. on() subs can still e.preventDefault(), which will
// reject the promise and thus skip the default behavior and after() subs.
var asyncEvent = eventTarget.publish('foo');
asyncEvent._firing = new Y.Promise(function (resolve) { resolve(); });
@lsmith
lsmith / gist:6440659
Created September 4, 2013 18:13
Adds a `Y.DOM.formToObject(identifier)` method.
/**
Adds a `Y.DOM.formToObject(identifier)` method to extract the values from a
`<form>` element and return an object map of element name to value(s).
@module dom
@submodule dom-form-values
@since @SINCE@
**/
var isArray = Y.Lang.isArray;
@lsmith
lsmith / gist:6393024
Created August 30, 2013 18:41
Fix for a bug in YUI 3 focus synthetic event when e.stopPropagation() is called between two delegate subscribers. Fix is on line 218.
/**
* Adds bubbling and delegation support to DOM events focus and blur.
*
* @module event
* @submodule event-focus
*/
var Event = Y.Event,
YLang = Y.Lang,
Notifier.prototype.fire = function () {
// first arg to delegate notifier should be an object with currentTarget
var args = toArray(arguments, 0, true),
handle = this.handle,
ce = handle.evt,
sub = handle.sub,
thisObj = sub.context,
delegate = sub.filter,
event = e || {},
ret;
var ops = [], i, len;
for (i = 0, len = models.length; i < len; ++i) {
ops.push(new Y.Promise(function (resolve, reject) {
Y.io('save-my-stuff.php', {
data: models[i].toJSON(),
on: {
success: function (id, xhr) {
// Maybe you want to JSON parse the responseText first?
// Maybe you don't care about the response beyond it being 200?
_toggleStripes: function (index) {
var task = this._toggleStripesTask,
self;
// index|0 to force int, avoid NaN. Math.max() to avoid neg indexes.
index = Math.max((index|0), 0);
if (!task) {
self = this;
lookup: function (col) {
var className = cName('lookup'),
lookup = col.lookupTable || {},
entries, i, len;
if (isArray(lookup)) {
entries = lookup;
lookup = {};
for (i = 0, len = entries.length; i < len; ++i) {