This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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(), | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // old and busted | |
| var foo = $(".bar"); | |
| if( foo.length ){ | |
| foo.addClass("LOL"); | |
| } | |
| // new hotness |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A | |
| $this.find("li") | |
| .wrapInner('<a href="#" style="display:block" />') | |
| .delegate("a", "click", function(){ | |
| $this.dialog("close"); | |
| return false; | |
| }); | |
| // B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // recursive setTimeout, better than setInterval. @paul_irish | |
| (function f(){ if(condition){} else{ setTimeout(f, 1000); } })(). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($){ | |
| $.widget("ui.mywidget", { | |
| options: { | |
| autoOpen: true | |
| }, | |
| _create: function(){ | |
| // by default, consider this thing closed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // extremely basic templating with replace(). | |
| var | |
| // template | |
| template = '<div id="#{id}">#{text}</div>', | |
| // object literal of replacement values | |
| params = { id:10, text:'hi there' }, |