Skip to content

Instantly share code, notes, and snippets.

View crossai-2033's full-sized avatar
😇
I may be slow to respond.

LC crossai-2033

😇
I may be slow to respond.
View GitHub Profile

#Four Ways To Do Pub/Sub With jQuery and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

// Note that this uses my Pub/Sub implementation, which is slightly different than
// phiggins' in that jQuery custom events are used, and as such the first event handler
// argument passed is the event object.
//
// jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery
// https://gist.github.com/661855
// The "traditional" way.
@crossai-2033
crossai-2033 / appCache_LRU
Created December 15, 2013 15:41
webCache LRU
var _store = {
removeItem : function(k) {
delete this[k];
}
};
try {
if ("localStorage" in window && window["localStorage"])
_store = window["localStorage"];
} catch (e) { }
@crossai-2033
crossai-2033 / build-nginx.sh
Created December 10, 2013 16:10
mac nginx conf
#!/bin/bash
## DOWNLOADS http://inikolaev.blogspot.com/2013/08/installing-nginx-on-mac-os-x.html
sudo curl -OL h ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz > /usr/local/src/pcre-8.13.tar.gz
sudo curl -OL h http://nginx.org/download/nginx-1.1.4.tar.gz > /usr/local/src/nginx-1.1.4.tar.gz
## Install PCRE
sudo mkdir -p /usr/local/src
cd /usr/local/src
tar xvzf pcre-8.13.tar.gz
@crossai-2033
crossai-2033 / casperscreens.js
Last active December 23, 2015 10:49
javascript:screencapture
var moment = require('moment');
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
var viewportSizes = [
// [320,480],
// [320,568],
// [600,1024],
@crossai-2033
crossai-2033 / canvas_frozen.js
Created September 17, 2013 12:20
javascript:google-frazon
(function() {
var canvas = document.getElementById('theme-canvas');
var container = document.getElementById('doc-view');
var ctx = canvas.getContext('2d');
var clearArray = [];
var paintFlag = false;
function Frozen(x, y, w, h, count, radius) {
this.x = x;
this.y = y;
this.width = w;
@crossai-2033
crossai-2033 / konami.js
Created September 16, 2013 02:24
javascript:Konami
(function() {
var EventTargetH = QW.EventTargetH,
on = EventTargetH.on,
mix = QW.ObjectH.mix,
isFunction = QW.ObjectH.isFunction,
filter = QW.Selector.filter,
keys = QW.ObjectH.keys,
forEach = QW.ArrayH.forEach;
// 事件队列
@crossai-2033
crossai-2033 / aop.js
Created August 17, 2013 05:04
simple aop..
// AOP简易模型
function Ting() {}
Thing.prototype.doSomething = function(x, y) {
var result;
return result;
};
var thing = new Thing;
@crossai-2033
crossai-2033 / parallax
Created August 13, 2013 03:44
Parallax Scrolling Demo
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Parallax</title>
<style>
/**
* HTML5 ✰ Boilerplate
*
* style.css contains a reset, font normalization and some base styles.
@crossai-2033
crossai-2033 / noscript
Created August 6, 2013 11:24
noscript adapter
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>NoScript</title>
</head>
<body>
<script>
document.write("<\!--");
</script>