Skip to content

Instantly share code, notes, and snippets.

// the correct way to use jQuery w/ XML
// also see http://gist.github.com/553364 for a normalized DOMParser
var
// XML string
xmlString = '<wu_tang><member name="Method Man" /></wu_tang>',
// DOM parsing object
parser = new DOMParser(),
// based heavily off:
// https://sites.google.com/a/van-steenbeek.net/archive/explorer_domparser_parsefromstring
if( typeof window.DOMParser === "undefined" ){
window.DOMParser = function(){};
window.DOMParser.prototype.parseFromString = function(str, contentType){
if(typeof ActiveXObject !== 'undefined'){
var xmldata = new ActiveXObject('MSXML.DomDocument');
xmldata.async = false;
xmldata.loadXML(str);
// jquery related selects plugin by eric hynds, erichynds.com
// re-write of http://github.com/ehynds/jquery-related-selects
(function($){
$.fn.relatedSelects = function( options ){
function RelatedSelect( form, options ){
var selects = this.selects = [], form = $(form);
// old and busted
var foo = $(".bar");
if( foo.length ){
foo.addClass("LOL");
}
// new hotness
// A
$this.find("li")
.wrapInner('<a href="#" style="display:block" />')
.delegate("a", "click", function(){
$this.dialog("close");
return false;
});
// B
// recursive setTimeout, better than setInterval. @paul_irish
(function f(){ if(condition){} else{ setTimeout(f, 1000); } })().
(function($){
$.widget("ui.mywidget", {
options: {
autoOpen: true
},
_create: function(){
// by default, consider this thing closed.
// accessing all OTHER instances of a widget, from within your widget.
// method one: use your own data store
var instances = [];
$.widget("ui.dialog", {
_create: function(){
instances.push(this.element);
},
// Skeleton jQuery Plugin (OO)
(function($){
$.fn.myPlugin = function( options ){
options = $.extend( {}, $.fn.myPlugin.defaults, options );
return this.each(function(){
// create a new object & store it in the element's data for easy access
$(this).data('myPlugin', new MyPlugin(this, options));
// extremely basic templating with replace().
var
// template
template = '<div id="#{id}">#{text}</div>',
// object literal of replacement values
params = { id:10, text:'hi there' },