Skip to content

Instantly share code, notes, and snippets.

Avatar

Juan Dopazo juandopazo

View GitHub Profile
@juandopazo
juandopazo / gist:8068955
Created Dec 21, 2013
Panel focus patch
View gist:8068955
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();
View gist:8028026
'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 Dec 18, 2013
CancellablePromise implementation
View cancellable.js
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 Dec 21, 2015
Uploader queue fix
View gist:6384086
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;
}
View gist:6174389
//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 Jul 18, 2013
DOM Promises are read only
View gist:6032051
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.'));
}
View gist:5715451
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 Sep 8, 2020
Validator jQuery plugin
View gist:5620611
/*
* 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
DataTableDataSource polling
View gist:5541166
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
Something that I keep writing for asynchronous tests
View gist:5505936
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);