Send this to a friend
1 function getElementsByClassName(node,classname) {
2 if (node.getElementsByClassName) {
3 return node.getElementsByClassName(classname);
4 } else {
5 return (function getElementsByClass(searchClass,node) {
6 if ( node == null )
7 node = document;
8 var classElements = [],
9 els = node.getElementsByTagName("*"),
10 elsLen = els.length,
11 pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"), i, j;
12
13 for (i = 0, j = 0; i < elsLen; i++) {
14 if ( pattern.test(els[i].className) ) {
15 classElements[j] = els[i];
16 j++;
17 }
18 }
19 return classElements;
20 })(classname, node);
21 }
22 }
23
24 var elements = getElementsByClassName(document, "myclass");
function getElementsByClassName(node,classname) {
if (node.getElementsByClassName) {
return node.getElementsByClassName(classname);
} else {
return (function getElementsByClass(searchClass,node) {
if ( node == null )
node = document;
var classElements = [],
els = node.getElementsByTagName("*"),
elsLen = els.length,
pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"), i, j;
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
})(classname, node);
}
}
var elements = getElementsByClassName(document, "myclass");
Send this to a friend
1 var win = window.open(...);
2 if(win == null || typeof(win) == "undefined" || (win == null && win.outerWidth == 0) || (win != null && win.outerHeight == 0) || win.test == "undefined") {
3
4 }
var win = window.open(...);
if(win == null || typeof(win) == "undefined" || (win == null && win.outerWidth == 0) || (win != null && win.outerHeight == 0) || win.test == "undefined") {
}
Send this to a friend
1 function dateValidation() {
2
3 var obj = document.getElementById("my_field");
4 var day = obj.value.split("/")[0];
5
6 var month = obj.value.split("/")[1];
7 var year = obj.value.split("/")[2];
8
9 if ((day<1 || day >31) || (month<1&&month>12)&&(year.length != 4)) {
10 alert("Invalid format");
11 return false;
12 } else {
13
14 var dt = new Date(year, month-1, day);
15 var today = new Date();
16
17 if((dt.getDate() != day) || (dt.getMonth() != month-1) || (dt.getFullYear()!=year) || (dt>today)) {
18 alert("Invalid date");
19 return false;
20 }
21 }
22 }
function dateValidation() {
var obj = document.getElementById("my_field");
var day = obj.value.split("/")[0];
var month = obj.value.split("/")[1];
var year = obj.value.split("/")[2];
if ((day<1 || day >31) || (month<1&&month>12)&&(year.length != 4)) {
alert("Invalid format");
return false;
} else {
var dt = new Date(year, month-1, day);
var today = new Date();
if((dt.getDate() != day) || (dt.getMonth() != month-1) || (dt.getFullYear()!=year) || (dt>today)) {
alert("Invalid date");
return false;
}
}
}
Send this to a friend
requires jquery.ui or jquery.color (https://github.com/jquery/jquery-color)
1 $.fn.backgroundAnimation : function(bgcolor, fgcolor, duration) {
2 $(this).animate({ backgroundColor: bgcolor }, duration).css('color', fgcolor);
3 }
$.fn.backgroundAnimation : function(bgcolor, fgcolor, duration) {
$(this).animate({ backgroundColor: bgcolor }, duration).css('color', fgcolor);
}
Send this to a friend
requires jquery.ui or jquery.color (https://github.com/jquery/jquery-color)
1 $.fn.highlight : function (highlightColor, duration) {
2 var highlightBg = highlightColor || "#FFFF9C";
3 var animateMs = duration || 2000;
4 var originalBg = this.css("background-color");
5
6 if (!originalBg || originalBg == highlightBg)
7 originalBg = "#FFFFFF";
8
9 $(this).css("backgroundColor", highlightBg).animate({ backgroundColor: originalBg }, animateMs, null, function () { $(this).css("backgroundColor", originalBg); });
10 }
$.fn.highlight : function (highlightColor, duration) {
var highlightBg = highlightColor || "#FFFF9C";
var animateMs = duration || 2000;
var originalBg = this.css("background-color");
if (!originalBg || originalBg == highlightBg)
originalBg = "#FFFFFF";
$(this).css("backgroundColor", highlightBg).animate({ backgroundColor: originalBg }, animateMs, null, function () { $(this).css("backgroundColor", originalBg); });
}
Send this to a friend
1 $.fn.center = function (relation) {
2 var center_in = (relation) ? $(relation) : $(window);
3
4 this.css("position","absolute");
5 this.css("top", ( center_in.height() - this.height() ) / 2+center_in.scrollTop() + "px");
6 this.css("left", ( center_in.width() - this.width() ) / 2+center_in.scrollLeft() + "px");
7 return this;
8 };
$.fn.center = function (relation) {
var center_in = (relation) ? $(relation) : $(window);
this.css("position","absolute");
this.css("top", ( center_in.height() - this.height() ) / 2+center_in.scrollTop() + "px");
this.css("left", ( center_in.width() - this.width() ) / 2+center_in.scrollLeft() + "px");
return this;
};
Send this to a friend
1 break
2 case
3 catch
4 continue
5 default
6 delete
7 do
8 else
9 finally
10 for
11 function
12 if
13 in
14 instanceof
15 new
16 return
17 switch
18 this
19 throw
20 try
21 typeof
22 var
23 void
24 while
25 with
26 abstract
27 boolean
28 byte
29 char
30 class
31 const
32 debugger
33 double
34 enum
35 export
36 extends
37 final
38 float
39 goto
40 implements
41 import
42 int
43 interface
44 long
45 native
46 package
47 private
48 protected
49 public
50 short
51 static
52 super
53 synchronized
54 throws
55 transient
56 volatile
break
case
catch
continue
default
delete
do
else
finally
for
function
if
in
instanceof
new
return
switch
this
throw
try
typeof
var
void
while
with
abstract
boolean
byte
char
class
const
debugger
double
enum
export
extends
final
float
goto
implements
import
int
interface
long
native
package
private
protected
public
short
static
super
synchronized
throws
transient
volatile
Send this to a friend
1 $("a#bookmark").click(function(){
2 var bookmarkUrl = this.href;
3 var bookmarkTitle = this.title;
4
5 if ($.browser.mozilla)
6 {
7 window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
8 }
9 else if($.browser.msie || $.browser.webkit)
10 {
11 window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
12 }
13 else if($.browser.opera )
14 {
15 $(this).attr("href",bookmarkUrl);
16 $(this).attr("title",bookmarkTitle);
17 $(this).attr("rel","sidebar");
18 $(this).click();
19 }
20 else
21 {
22 alert('Please hold CTRL+D and click the link to bookmark it in your browser.');
23 }
24 return false;
25 });
$("a#bookmark").click(function(){
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
if ($.browser.mozilla)
{
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
}
else if($.browser.msie || $.browser.webkit)
{
window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
}
else if($.browser.opera )
{
$(this).attr("href",bookmarkUrl);
$(this).attr("title",bookmarkTitle);
$(this).attr("rel","sidebar");
$(this).click();
}
else
{
alert('Please hold CTRL+D and click the link to bookmark it in your browser.');
}
return false;
});
Send this to a friend
1 var IE = $.browser.msie, IEv = $.browser.version;
2
3 if (IE) {
4 var IE6 = parseInt(IEv) == 6,
5 IE7 = parseInt(IEv) == 7,
6 IE8 = parseInt(IEv) == 8,
7 IE9 = parseInt(IEv) == 9;
8 }
9
10
11
12 if (IE) {
13
14 }
15 if (IE7) {
16
17 }
18 if (IE7 || IE8) {
19
20 }
21 if (!IE6) {
22
23 }
var IE = $.browser.msie, IEv = $.browser.version;
if (IE) {
var IE6 = parseInt(IEv) == 6,
IE7 = parseInt(IEv) == 7,
IE8 = parseInt(IEv) == 8,
IE9 = parseInt(IEv) == 9;
}
if (IE) {
}
if (IE7) {
}
if (IE7 || IE8) {
}
if (!IE6) {
}
Send this to a friend
requires jquery.sortElements.js (https://github.com/jamespadolsey/jQuery-Plugins/blob/master/sortElements/jquery.sortElements.js)
via http://stackoverflow.com/questions/3160277/jquery-table-sort
1 var table = $('table');
2
3 $('th').wrapInner('<span title="Sort this column"/>').each(function(){
4 var th = $(this), thIndex = th.index(), inverse = false;
5 th.click(function(){
6 table.find('td').filter(function(){
7 return $(this).index() === thIndex;
8 }).sortElements(function(a, b){
9 return $.text([a]) > $.text([b]) ?
10 inverse ? -1 : 1
11 : inverse ? 1 : -1;
12 }, function(){
13 return this.parentNode;
14 });
15 inverse = !inverse;
16 });
17 });
var table = $('table');
$('th').wrapInner('<span title="Sort this column"/>').each(function(){
var th = $(this), thIndex = th.index(), inverse = false;
th.click(function(){
table.find('td').filter(function(){
return $(this).index() === thIndex;
}).sortElements(function(a, b){
return $.text([a]) > $.text([b]) ?
inverse ? -1 : 1
: inverse ? 1 : -1;
}, function(){
return this.parentNode;
});
inverse = !inverse;
});
});