forked from cowboy/jquery-misc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
/*! | |||
* cond - v0.1 - 6/10/2009 | |||
* http://benalman.com/projects/jquery-cond-plugin/ | |||
* | |||
* Copyright (c) 2009 "Cowboy" Ben Alman | |||
* Licensed under the MIT license | |||
* http://benalman.com/about/license/ | |||
* | |||
* Based on suggestions and sample code by Stephen Band and DBJDBJ in the | |||
* jquery-dev Google group: http://bit.ly/jqba1 | |||
*/ | |||
|
|||
jQuery.fn.cond = function() { | |||
var undefined, | |||
args = arguments, | |||
i = 0, | |||
test, | |||
callback, | |||
result; | |||
|
|||
while ( !test && i < args.length ) { | |||
test = args[ i++ ]; | |||
callback = args[ i++ ]; | |||
|
|||
test = jQuery.isFunction( test ) ? test.call( this ) : test; | |||
|
|||
result = !callback ? test | |||
: test ? callback.call( this, test ) | |||
: undefined; | |||
} | |||
|
|||
return result !== undefined ? result : this; | |||
}; | |||
|
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
/*! | |||
* emailSpammerize - v1.1 - 3/14/2009 | |||
* http://benalman.com/ | |||
* | |||
* Copyright (c) 2009 "Cowboy" Ben Alman | |||
* Licensed under the MIT license | |||
* http://benalman.com/about/license/ | |||
*/ | |||
|
|||
(function($) { | |||
'$:nomunge'; // Used by YUI compressor. | |||
|
|||
var str_emailSpammerize = 'emailSpammerize', | |||
replaces = { | |||
at: '@', dot: '.', plus: '+', dash: '-', underscore: '_', bang: '!', | |||
hash: '#', dollar: '$', percent: '%', ampersand: '&', quote: "'", | |||
asterisk: '*', slash: '/', equals: '=', question: '?', caret: '^', | |||
backtick: '`', pipe: '|', tilde: '~' | |||
}; | |||
|
|||
$[ str_emailSpammerize ] = function( email, linkify ) { | |||
var re; | |||
|
|||
$.each( replaces, function(k,v){ | |||
re = new RegExp( '\\s+' + k + '\\s+', 'gi' ); | |||
email = email.replace( re, v ); | |||
}); | |||
|
|||
email = email.replace( /(\s+|\[|\])/g, '' ); | |||
|
|||
email = $.map( email, function(v){ | |||
return '&#' + v.charCodeAt() + ';'; | |||
}).join(''); | |||
|
|||
if ( linkify ) { | |||
email = '<a href="mailto:' + email + '">' + email + '<\/a>'; | |||
} | |||
|
|||
return email; | |||
}; | |||
|
|||
$.fn[ str_emailSpammerize ] = function( linkify ) { | |||
return this.each(function(){ | |||
var email = $(this).text(); | |||
|
|||
$(this).html( $[ str_emailSpammerize ]( email, linkify ) ); | |||
}); | |||
}; | |||
|
|||
})(jQuery); | |||
|
|||
// About: | |||
// | |||
// "With a little help from Randal Schwartz, who held my nose to the web standards" | |||
// | |||
// Convert your anti-spammerized links (like "foo at bar dot com") to their | |||
// proper format, which spammers theoretically shouldn't be able to harvest | |||
// since this all happens via JavaScript after page load, and all text is | |||
// encoded into numeric entities. If an email address contains a part that is | |||
// also the name of a replace, like "dot" or "at", just surround it with []. | |||
// | |||
// Sample Usage: | |||
// | |||
// Initial HTML: | |||
// <span>foo ampersand bar at example dot com</span> | |||
// | |||
// $('span').emailSpammerize(true); | |||
// | |||
// Resulting HTML: | |||
// <span><a href="mailto:foo&bar@e | |||
// xample.com">fo | |||
// o&bar@example | |||
// .com</a></span> | |||
// | |||
// Which renders just like this would, were you to code it by hand: | |||
// <span><a href="mailto:foo&bar@example.com">foo&bar@example.com</a></span> | |||
|
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
/*! | |||
* getClassData - v1.1 - 3/30/2009 | |||
* http://benalman.com/ | |||
* | |||
* Copyright (c) 2009 "Cowboy" Ben Alman | |||
* Licensed under the MIT license | |||
* http://benalman.com/about/license/ | |||
*/ | |||
|
|||
(function($) { | |||
'$:nomunge'; // Used by YUI compressor. | |||
|
|||
var jq_getClassData, | |||
str_getClassData = 'getClassData'; | |||
|
|||
$[ str_getClassData ] = jq_getClassData = function( class_string, prefix, delimiter ) { | |||
var re, | |||
arr, | |||
data = []; | |||
|
|||
delimiter = delimiter || '-'; | |||
|
|||
re = new RegExp( '(?:^|\\s)' + prefix + delimiter + '(\\S+)', 'g' ); | |||
while ( arr = re.exec(class_string) ) { | |||
data.push( arr[1] ); | |||
} | |||
|
|||
return data.join(' '); | |||
}; | |||
|
|||
$.fn[ str_getClassData ] = function( prefix, delimiter ) { | |||
return jq_getClassData( $(this).attr('class'), prefix, delimiter ); | |||
}; | |||
|
|||
})(jQuery); | |||
|
|||
// About: | |||
// | |||
// If you're not yet using HTML 5 data- attributes, you can store basic data | |||
// in an element's class attribute for easy retrieval. Just give each datum a | |||
// prefix, which you can then use to select it. | |||
// | |||
// Note: data can't contain spaces, and prefix is case-sensitive. | |||
// | |||
// Sample Usage: | |||
// | |||
// <div id="foo" class="bar-123 baz.test baz.xyz">Look, I'm a div!</div> | |||
// | |||
// $('#foo').getClassData('bar'); // returns '123' | |||
// $('#foo').getClassData('baz', '.'); // returns 'test xyz' | |||
|
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
/*! | |||
* getUniqueClass - v1.0 - 1/27/2009 | |||
* http://benalman.com/ | |||
* | |||
* Copyright (c) 2009 "Cowboy" Ben Alman | |||
* Licensed under the MIT license | |||
* http://benalman.com/about/license/ | |||
*/ | |||
|
|||
jQuery.getUniqueClass = function() { | |||
var name, i = 0; | |||
while ( $('.' + (name = 'BA-' + (+new Date) + (i++))).length ) { }; | |||
return name; | |||
} | |||
|
|||
// About: | |||
// | |||
// For when you really need a unique classname, (like when you're cloning a | |||
// whole bunch of elements and don't exactly know where they're going, but | |||
// need to do something with them after they've gotten there). | |||
// | |||
// Sample Usage: | |||
// | |||
// var c = $.getUniqueClass(); // c set to 'BA-12352576545660' or so | |||
// $('p').addClass(c); | |||
// .. haphazardly clone a bunch of <p> elements .. | |||
// $('.' + c).removeClass(c).doSomething(); |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
/*! | |||
* iff - v0.2 - 6/3/2009 | |||
* http://benalman.com/projects/jquery-iff-plugin/ | |||
* | |||
* Copyright (c) 2009 "Cowboy" Ben Alman | |||
* Licensed under the MIT license | |||
* http://benalman.com/about/license/ | |||
*/ | |||
|
|||
jQuery.fn.iff = function( test ) { | |||
var elems = !test || jQuery.isFunction( test ) | |||
&& !test.apply( this, Array.prototype.slice.call(arguments, 1) ) | |||
? [] | |||
: this; | |||
return this.pushStack( elems, 'iff', test ); | |||
}; | |||
|
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,38 @@ | |||
/*! | |||
* nth-last-child - v0.1 - 5/5/2009 | |||
* http://benalman.com/ | |||
* | |||
* Copyright (c) 2009 "Cowboy" Ben Alman | |||
* Licensed under the MIT license | |||
* http://benalman.com/about/license/ | |||
*/ | |||
|
|||
(function($) { | |||
'$:nomunge'; // Used by YUI compressor. | |||
|
|||
$.expr[':']['nth-last-child'] = function( elem, i, match ) { | |||
var count = 0, | |||
node = elem.parentNode.firstChild; | |||
|
|||
if ( elem.nodeIndex ) { | |||
count = $.sibling( node, elem ).length; | |||
} else { | |||
do { | |||
if ( node && node.nodeType === 1 ) { | |||
node.nodeIndex = ++count; | |||
} | |||
} while ( node = node.nextSibling ); | |||
} | |||
|
|||
return elem.nodeIndex === count + 2 - (match[3] || 0); | |||
}; | |||
|
|||
})(jQuery); | |||
|
|||
// About: | |||
// | |||
// Like :nth-child(N) but counts from the end, not the beginning. | |||
// | |||
// Sample Usage: | |||
// | |||
// $('ul li:nth-last-child(2)').addClass( 'penultimate-listitem' ); |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
/*! | |||
* unwrap - v0.1 - 7/18/2009 | |||
* http://benalman.com/projects/jquery-unwrap-plugin/ | |||
* | |||
* Copyright (c) 2009 "Cowboy" Ben Alman | |||
* Licensed under the MIT license | |||
* http://benalman.com/about/license/ | |||
*/ | |||
|
|||
jQuery.fn.unwrap = function() { | |||
this.parent(':not(body)') | |||
.each(function(){ | |||
jQuery(this).replaceWith( this.childNodes ); | |||
}); | |||
|
|||
return this; | |||
}; | |||
|