Skip to content

Instantly share code, notes, and snippets.

@sdesai
sdesai / gist:1386836
Created November 22, 2011 20:28
WidgetStringRenderer

USE CASES

  • Render widgets on NodeJS, where DOM is absent.
  • Optimize rendering of Widgets at scale (1000s of TreeViewNodes).

GOAL

  • Avoid all Node references from Widget through the end of renderUI().
  • bindUI()/syncUI() will still have Node references (to bind events and incrementally update DOM).
@sdesai
sdesai / gist:1356718
Created November 11, 2011 00:15
Event Bubbling From Same Typed Objects
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>EventTarget And Homogeneous Bubbling</title>
<script type="text/javascript" src="/YuiWip/yui3/build/yui/yui.js"></script>
</head>
<body>
<script type="text/javascript">
@sdesai
sdesai / gist:1349528
Created November 8, 2011 22:38
Nested
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=0">
<link rel="stylesheet" href="../../../../build/cssreset/cssreset-min.css" type="text/css" charset="utf-8">
<script src="../../../../build/yui/yui.js" type="text/javascript" charset="utf-8"></script>
@sdesai
sdesai / gist:1300266
Created October 20, 2011 02:29
Multi-Inheritance?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui.js"></script>
</head>
<body>
<script type="text/javascript">
YUI({filter:"raw", combine:false}).use('base', function(Y) {
function Bar() {}
// Shorten colors from #AABBCC to #ABC. Note that we want to make sure
// the color is not preceded by either ", " or =. Indeed, the property
// filter: chroma(color="#FFFFFF");
// would become
// filter: chroma(color="#FFF");
// which makes the filter break in IE.
BEFORE:
var pattern = /([^"'=\s])(\s*)#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])/gi
_uiAddChild: function (child, parentNode) {
// Out of the box, this is never async, so things will always work, even if children are
// rendered out of order.
// The plugin modifies this code to be async (by moving the defRenderFn to an async queue).
// Since it's doing this, I think it's also appropriate for it to override any methods
// which were written based on the assumption that child.render() was always synchronous.
child.render(parentNode);
var tree = new Y.ParentWidget({
id: "tree"
});
// tree.plug(Y.SM.Plugin.WidgetParentRenderQueue, {timeout:2000});
tree.render();
tree.add({ type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" }, 1);
tree.add({ type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" }, 0);
@sdesai
sdesai / gist:1211940
Created September 12, 2011 18:02
Async Queue Usage Example
var tree = new Y.ParentWidget({
id: "tree"
});
tree.plug(Y.SM.Plugin.WidgetParentRenderQueue, {timeout:2000});
tree.add([
{ type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
{ type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
{ type: Y.ChildWidget, id: "leaf-2", label: "Leaf Three" },
@sdesai
sdesai / gist:1103272
Created July 25, 2011 00:08
Normalizing scrollWidth/scrollHeight
/**
* Utility method to obtain scrollWidth, scrollHeight,
* accounting for the impact of translate on scrollWidth, scrollHeight
* @method _getScrollDims
* @returns {Array} The scrollWidth and scrollHeight as an array: [scrollWidth, scrollHeight]
* @private
*/
_getScrollDims: function() {
var dims,
matrix,
...
var content = scrollView.get("contentBox");
// Roll my own delegate to work around Chrome 12 issue (if you need click support that is).
content.on("click", function(e) {
// For mouse based devices, we need to make sure the click isn't fired
// at the end of a drag/flick. We're use 2 as an arbitrary threshold.