Skip to content

Instantly share code, notes, and snippets.

View juandopazo's full-sized avatar

Juan Dopazo juandopazo

View GitHub Profile
@juandopazo
juandopazo / gist:8068955
Created December 21, 2013 12:51
Panel focus patch
Y.Panel.prototype._uiSetHostVisibleModal = function (visible) {
var stack = Y.WidgetModality.STACK,
maskNode = this.get('maskNode'),
isModal = this.get('modal'),
topModal, index;
if (visible) {
Y.Array.each(stack, function (modal) {
modal._detachUIHandlesModal();
@juandopazo
juandopazo / gist:8028026
Last active December 31, 2015 18:39 — forked from ericf/gist:8026041
'use strict';
var fs = require('fs'),
path = require('path'),
parseCSS = require('css-parse'),
Promise = require('es6-promise').Promise;
module.exports = function gridUnits(pureDir, callback) {
readUnits(path.join(pureDir, 'grids-units.css'))
.then(parseCSS)
@juandopazo
juandopazo / cancellable.js
Created December 18, 2013 15:13
CancellablePromise implementation
YUI.add('cancellable-promise', function (Y) {
function CancellationError(message) {
CancellationError.superclass.constructor.apply(this, arguments);
this.message = message;
}
Y.extend(CancellationError, Error, {
name: 'cancel'
});
@juandopazo
juandopazo / gist:6384086
Last active December 21, 2015 23:39
Uploader queue fix
uploader.after('uploadcancel', function () {
// Uploader is currently only looking at two possibilities when
// calling uploadThese(): if there's no queue or if the queue is in
// progress. After cancelling if there are still items int he queue
// everything works fine, but if there aren't any the queue stays
// there stuck in an UPLOADING state. To fix that, remove the
// queue object if empty
if (this.queue && !this.queue.queuedFiles.length) {
this.queue = null;
}
@juandopazo
juandopazo / gist:6174389
Created August 7, 2013 14:09
Assignment bug
//make sure the input tag has an ID assigned, if not, assign one.
if (!input.attr('id')) input.attr('id') = 'input_' + rnd;
@juandopazo
juandopazo / gist:6032051
Created July 18, 2013 19:05
DOM Promises are read only
function ajax(url) {
return new Promise(function (resolver) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolver.resolve(xhr.responseText);
} else {
resolver.reject(new Error('There was a problem with the request.'));
}
@juandopazo
juandopazo / gist:5715451
Created June 5, 2013 16:56
Deferreds in YUI
Y.Promise.defer = function () {
var deferred = {};
deferred.promise = new Y.Promise(function (resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
return deferred;
};
@juandopazo
juandopazo / gist:5620611
Last active September 8, 2020 00:22
Validator jQuery plugin
/*
* jQuery plugin to validate forms around segurosdigitales
* requires jquery validate plugin
* */
(function($){
function Validator(options, element) {
this.options = $.extend( {}, this.options, options );
this.elem = element;
this.$elem = $(element);
@juandopazo
juandopazo / gist:5541166
Created May 8, 2013 15:17
DataTableDataSource polling
YUI().use("datatable", "datasource-io", "datasource-jsonschema", "datatable-datasource", "datasource-polling", function (Y) {
Y.mix(Y.Plugin.DataTableDataSource.prototype, {
initializer: function (config) {
this.after('datasourceChange', this._bindDataSource);
if (config.datasource) {
this._bindDataSource({
newVal: config.datasource
});
}
@juandopazo
juandopazo / gist:5505936
Created May 2, 2013 22:22
Something that I keep writing for asynchronous tests
suite.add(new Y.Test.Case({
name: 'foo',
'some test': function () {
var test = this;
Y.io('foo', function (id, response) {
// this is just boilerplate
test.resume(function () {
Y.Test.Assert.areEqual('foo', response.responseText);