This file contains 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
// Sold on jQuery - just re-wrote the following Prototype code: | |
Element.observe(window, 'load', function(){ | |
// This is for slow forms (like the signup one), | |
// so the user doesn't click 'Submit' twice. | |
$$('form.slow').each(function(frm){ | |
var sub = frm.down("input[type='submit']"); | |
if(sub) sub.disabled = ''; | |
$(frm).observe('submit', function(e){ | |
var sub = frm.down("input[type='submit']"); |
This file contains 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($){ | |
$.PicasaWebViewer = { | |
jQuery : $, | |
defaultOptions : { | |
albumClass: "albumClass", | |
photoClass: "photoClass", | |
urlFormat: "http://picasaweb.google.com/data/feed/api/user/{0}?alt=json-in-script", | |
userName: "elijah.manor" | |
}, |
This file contains 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
//Quick Element Contruction Syntax | |
//Instead of concatenating strings together to build up new HTML elements, | |
//you can now utilize a new feature inside of jQuery 1.4 for quick element construction. | |
//You can pass a map of properties as the second parameter to set attributes and wire-up event handlers | |
//Keep in mind certain elements cannot be created this way due to limitations in some browsers (Internet | |
//Explorer for example). Elements you will have trouble with include `input` and `button` elements. | |
$("<a />", { | |
id: "companyLink", |
This file contains 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
//Using Namespaced Events | |
//When writing jQuery Plugins it is helpful to add a namespace when binding to native or custom events. | |
//You can unbind all events associated with your plugin without affecting other events. | |
//The namespace will not affect triggering custom events. They will work as you would expect. | |
//Use a namespace with your plugin events | |
$("div").bind("click.myPlugin", func1); | |
$("div").bind("keydown.myPlugin", func2); | |
$("div").unbind(".myPlugin"); |
This file contains 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
//Changing Event Handler Context | |
//You can access the context by using the "this" pseudo parameter. The context of most jQuery Event Handler's | |
//is the DOM element that caused the event. There may be times when you want to change the context (the value | |
//of "this") inside of your event handler. In that case, you should use the $.proxy() method. The $.proxy() | |
//method allows you to manually define what you want the context to be inside your event handler. | |
//Utilizing the $.proxy() method to change context | |
var contact = { | |
name: "jQuery", |
This file contains 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
// Use === and !== | |
// It is often better to use the === and !== operators | |
// rather than == and != operators. The reason for this | |
// is that === and !== (also known as the identity operators) | |
// check for the type as well as the value when being compared | |
// whereas the == and != will try to coerce the two values | |
// into the same type before the comparison is made, which | |
// may lead to some very unexpected results. |
This file contains 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
// Check hasOwnProperty in for...in | |
// When you are using the for...in loop in JavaScript | |
// you must be careful to also check the object | |
// you are enumerating to see if it contains | |
// the property before proceeding. The reason for | |
// this is that the for...in loop also iterates | |
// over the prototype's properties as well */ | |
var Person = function( firstName, lastName ) { |
This file contains 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
// Prevent Default Behavior | |
// 'return false' stops the default behavior of the event | |
// and prevents it from bubbling up DOM, which kills | |
// event delegation and may not be what you indented. | |
// You might consider using e.preventDefault() or | |
// e.stopPropagation() instead | |
//event.preventDefault() | |
//Event Delegation Friendly |
This file contains 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
//http://userjs.up.seesaa.net/js/bookmarklet.html | |
(function() { | |
var location = document.location.href, | |
newLocation = null; | |
if ( ~location.indexOf( "gist.github.com" ) ) { | |
console.log( "Switching from gist to jsbin..." ); | |
newLocation = location.replace( /https:\/\/gist.github.com\/(\d+)/, function( str, group1 ) { |
This file contains 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
var valueImLookingFor = "myvalue"; | |
//The string concatenation just feels wrong to me... | |
$( "p[data-mytype" + "='" + valueImLookingFor + "']" ) | |
.doSomething(); |
OlderNewer