Skip to content

Instantly share code, notes, and snippets.

View juandopazo's full-sized avatar

Juan Dopazo juandopazo

View GitHub Profile
<span id="yui_3_3_0_1_129815707302415" class="yui3-widget yui3-combobox yui3-combobox-focused">
<input type="text" class="yui3-combobox-input" role="combobox" aria-expanded="true" aria-autocomplete="list"
aria-owns="yui_3_3_0_1_129815707302418" style="width: 106px; "/>
<ul class="yui3-combobox yui3-combobox-content" id="yui_3_3_0_1_129815707302418" role="listbox">
<li class="yui3-combobox-option yui3-widget yui3-option yui3-option-content yui3-combobox-option-selected
yui3-option-selected" id="yui_3_3_0_1_129815707302446" role="option" tabindex="0">hello</li>
<li class="yui3-combobox-option yui3-widget yui3-option yui3-option-content" id="yui_3_3_0_1_129815707302466"
role="option" tabindex="-1">world</li>
</ul>
</span>
<!DOCTYPE html>
<html>
<head>
<title>ScrollView With Pagination</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>
/* Avoid resource latency for these, since they hide unenhanced content */
.yui3-js-enabled .yui3-scrollview-loading {
visibility:hidden;
function createElement(tag) {
return document.createElement(tag);
}
var addOption = function (combo, text, value) {
/* Note by jdopazo:
Lazy initialization for the function _add()
I create a <select> element that I never attach to the dom
and try to attach an <'option'> element to it with try...catch
This way I avoid using try...catch every time this function is called */
@juandopazo
juandopazo / gist:892470
Created March 29, 2011 14:44
Classes in JavaScript draft
/*
* GOALS:
*
* - Properties/methods should be either public or private by default. They've been public since the
* begining of JS, so maybe they should stay that way and a "private" keyword should be added.
* Otherwise, they could be private by default and have a "public" keyword
* - Avoid the "var" keyword in object initializer extensions
* - Provide a shorter version to be used by compilers or to be mixed by developers
*
*/
@juandopazo
juandopazo / gist:894335
Created March 30, 2011 13:01
Class definition example
class Point {
<closed, prototype: Object.prototype>,
class method fromString(s) {
return new Point(parse(s));
},
private method repaint() {
console.log('moved!');
},
@juandopazo
juandopazo / gist:912689
Created April 10, 2011 20:15
Something similar to a Strategy pattern?
/*
Let's say I want to create an object using different constructors according
to some environmental condition (browser, available API, etc).
So I have two constructors, for instance for an Ajax object:
*/
function AjaxXMLHTTPRequest() {}
AjaxXMLHTTPRequest.prototype = {
// some methods
};
@juandopazo
juandopazo / gist:968484
Created May 12, 2011 13:30
Differences between AsyncQueue and Deferreds
/*
IIRC AsyncQueue is designed for splitting cpu intensive code into chunks and run them sequentially separated by small timeouts.
Deferreds are a way of rewriting async calls without callbacks or events. They are probably more useful in Node.js.
For example, when normally you'd get a lot of callbacks connecting to a db...
*/
mysql_connect('user', 'pwd', function (err) {
if (err) throw new err;
@juandopazo
juandopazo / gist:991736
Created May 25, 2011 19:41
Building a layout for YUI3 CSS Grids from JS with WidgetParent/WidgetChild
YUI.add('jsgrids', function (Y) {
Y.Grid = Y.Base.create('g', Y.Widget, [Y.WidgetParent, Y.WidgetChild], {
CONTENT_TEMPLATE: null
}, {
ATTRS: {
defaultChildType: {
value: 'Unit'
}
}
@juandopazo
juandopazo / gist:999644
Created May 30, 2011 23:50
Math.random()
/*
It has always bugged me that every other language except Java returns an integer and JavaScript returns [0,1).
So, how about standarizing this?
*/
(function () {
var oldRandom = Math.random;
Object.defineProperty(Math, 'random', {
value: function random(n) {
return typeof n === 'undefined' ? oldRandom() :