Fixed more formatting/tab problems.

This commit is contained in:
John Resig 2006-03-23 21:13:20 +00:00
parent 130b8a1c03
commit f0034d64e3
4 changed files with 217 additions and 211 deletions

View file

@ -3,86 +3,87 @@
// http://jquery.com/docs/ajax/ // http://jquery.com/docs/ajax/
if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'function') { if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'function') {
var XMLHttpRequest = function() { var XMLHttpRequest = function() {
return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') >= 0) ? return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') >= 0) ?
"Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"); "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
}; };
} }
$.xml = function( type, url, data, ret ) { $.xml = function( type, url, data, ret ) {
var xml = new XMLHttpRequest(); var xml = new XMLHttpRequest();
if ( xml ) { if ( xml ) {
xml.open(type || "GET", url, true); xml.open(type || "GET", url, true);
if ( data ) if ( data )
xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
if ( ret ) if ( ret )
xml.onreadystatechange = function() { xml.onreadystatechange = function() {
if ( xml.readyState == 4 ) ret(xml); if ( xml.readyState == 4 ) ret(xml);
}; };
xml.send(data) xml.send(data)
} }
}; };
$.httpData = function(r,type) { $.httpData = function(r,type) {
return r.getResponseHeader("content-type").indexOf("xml") > 0 || type == "xml" ? return r.getResponseHeader("content-type").indexOf("xml") > 0 || type == "xml" ?
r.responseXML : r.responseText; r.responseXML : r.responseText;
}; };
$.get = function( url, ret, type ) { $.get = function( url, ret, type ) {
$.xml( "GET", url, null, function(r) { $.xml( "GET", url, null, function(r) {
if ( ret ) ret( $.httpData(r,type) ); if ( ret ) ret( $.httpData(r,type) );
}); });
}; };
$.getXML = function( url, ret ) { $.getXML = function( url, ret ) {
$.get( url, ret, "xml" ); $.get( url, ret, "xml" );
}; };
$.post = function( url, data, ret, type ) { $.post = function( url, data, ret, type ) {
$.xml( "POST", url, $.param(data), function(r) { $.xml( "POST", url, $.param(data), function(r) {
if ( ret ) ret( $.httpData(r,type) ); if ( ret ) ret( $.httpData(r,type) );
}); });
}; };
$.postXML = function( url, data, ret ) { $.postXML = function( url, data, ret ) {
$.post( url, data, ret, "xml" ); $.post( url, data, ret, "xml" );
}; };
$.param = function(a) { $.param = function(a) {
var s = []; var s = [];
for ( var i in a ) for ( var i in a )
s[s.length] = i + "=" + encodeURIComponent( a[i] ); s[s.length] = i + "=" + encodeURIComponent( a[i] );
return s.join("&"); return s.join("&");
}; };
$.fn.load = function(a,o,f) { $.fn.load = function(a,o,f) {
// Arrrrghhhhhhhh!! // Arrrrghhhhhhhh!!
// I overwrote the event plugin's .load // I overwrote the event plugin's .load
// this won't happen again, I hope -John // this won't happen again, I hope -John
if ( a && a.constructor == Function ) if ( a && a.constructor == Function )
return this.bind("load", a); return this.bind("load", a);
var t = "GET"; var t = "GET";
if ( o && o.constructor == Function ) { if ( o && o.constructor == Function ) {
f = o; o = null; f = o;
} o = null;
if (o != null) { }
o = $.param(o); if (o != null) {
t = "POST"; o = $.param(o);
} t = "POST";
var self = this; }
$.xml(t,a,o,function(h){ var self = this;
var h = h.responseText; $.xml(t,a,o,function(h){
self.html(h).find("script").each(function(){ var h = h.responseText;
try { self.html(h).find("script").each(function(){
eval( this.text || this.textContent || this.innerHTML ); try {
} catch(e){} eval( this.text || this.textContent || this.innerHTML );
}); } catch(e){}
if(f)f(h); });
}); if(f)f(h);
return this; });
return this;
}; };

View file

@ -2,6 +2,7 @@ var e = ["blur","focus","contextmenu","load","resize","scroll","unload",
"click","dblclick","mousedown","mouseup","mouseenter","mouseleave", "click","dblclick","mousedown","mouseup","mouseenter","mouseleave",
"mousemove","mouseover","mouseout","change","reset","select","submit", "mousemove","mouseover","mouseout","change","reset","select","submit",
"keydown","keypress","keyup","abort","error","ready"]; "keydown","keypress","keyup","abort","error","ready"];
for ( var i = 0; i < e.length; i++ ) { for ( var i = 0; i < e.length; i++ ) {
(function(){ (function(){
var o = e[i]; var o = e[i];

176
fx/fx.js
View file

@ -1,3 +1,88 @@
$.speed = function(s,o) {
if ( o && o.constructor == Function ) o = { onComplete: o };
o = o || {};
var ss = {"crawl":1200,"xslow":850,"slow":600,"medium":400,"fast":200,"xfast":75,"normal":400};
o.duration = typeof s == "number" ? s : ss[s] || 400;
return o;
};
$.fn.hide = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.FadeSize(this,o).hide();
}) : this._hide();
};
$.fn.show = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.FadeSize(this,o).show();
}) : this._show();
};
$.fn.slideDown = function(a,o) {
o = $.speed(a,o);
return this.each(function(){
new fx.Resize(this,o).show("height");
});
};
$.fn.slideUp = function(a,o) {
o = $.speed(a,o);
return this.each(function(){
new fx.Resize(this,o).hide("height");
});
};
$.fn.fadeOut = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.Opacity(this,o).hide();
}) : this._hide();
};
$.fn.fadeIn = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.Opacity(this,o).show();
}) : this._show();
};
$.fn.center = function(f) {
return this.each(function(){
if ( !f && this.nodeName == 'IMG' &&
!this.offsetWidth && !this.offsetHeight ) {
var self = this;
setTimeout(function(){
$(self).center(true);
}, 13);
} else {
var s = this.style;
var p = this.parentNode;
if ( $.css(p,"position") == 'static' )
p.style.position = 'relative';
s.position = 'absolute';
s.left = parseInt(($.css(p,"width") - $.css(this,"width"))/2) + "px";
s.top = parseInt(($.css(p,"height") - $.css(this,"height"))/2) + "px";
}
});
};
$.setAuto = function(e,p) {
var a = e.style[p];
var o = $.css(e,p);
e.style[p] = 'auto';
var n = $.css(e,p);
if ( o != n )
e.style[p] = a;
};
/*
* I originally wrote fx() as a clone of moo.fx and in the process
* of making it small in size the code became illegible to sane
* people. You've been warned.
*/
function fx(el,op,ty,tz){ function fx(el,op,ty,tz){
var z = this; var z = this;
z.a = function(){z.el.style[ty]=z.now+z.o.unit}; z.a = function(){z.el.style[ty]=z.now+z.o.unit};
@ -11,13 +96,13 @@ function fx(el,op,ty,tz){
z.clear = function(){clearInterval(z.timer);z.timer=null}; z.clear = function(){clearInterval(z.timer);z.timer=null};
z.el = el.constructor==String?document.getElementById(el):el; z.el = el.constructor==String?document.getElementById(el):el;
var y = z.el.style; var y = z.el.style;
z.oo = y.overflow; z.oo = y.overflow;
y.overflow = "hidden"; y.overflow = "hidden";
z.o = { z.o = {
unit: "px", unit: "px",
duration: (op && op.duration) || 400, duration: (op && op.duration) || 400,
onComplete: (op && op.onComplete) || op onComplete: (op && op.onComplete) || op
}; };
z.step = function(f,tt){ z.step = function(f,tt){
var t = (new Date).getTime(); var t = (new Date).getTime();
var p = (t - z.s) / z.o.duration; var p = (t - z.s) / z.o.duration;
@ -88,83 +173,4 @@ fx.FadeSize = function(e,o){
var j = fx.fn[i]; var j = fx.fn[i];
z[j] = function(a,b){p[j]();r[j](a,b);}; z[j] = function(a,b){p[j]();r[j](a,b);};
})()} })()}
}; };
$.speed = function(s,o) {
if ( o && o.constructor == Function ) o = { onComplete: o };
o = o || {};
var ss = {"crawl":1200,"xslow":850,"slow":600,"medium":400,"fast":200,"xfast":75,"normal":400};
o.duration = typeof s == "number" ? s : ss[s] || 400;
return o;
};
$.fn.hide = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.FadeSize(this,o).hide();
}) : this._hide();
};
$.fn.show = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.FadeSize(this,o).show();
}) : this._show();
};
$.fn.slideDown = function(a,o) {
o = $.speed(a,o);
return this.each(function(){
new fx.Resize(this,o).show("height");
});
};
$.fn.slideUp = function(a,o) {
o = $.speed(a,o);
return this.each(function(){
new fx.Resize(this,o).hide("height");
});
};
$.fn.fadeOut = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.Opacity(this,o).hide();
}) : this._hide();
};
$.fn.fadeIn = function(a,o) {
o = $.speed(a,o);
return a ? this.each(function(){
new fx.Opacity(this,o).show();
}) : this._show();
};
$.fn.center = function(f) {
return this.each(function(){
if ( !f && this.nodeName == 'IMG' &&
!this.offsetWidth && !this.offsetHeight ) {
var self = this;
setTimeout(function(){
$(self).center(true);
}, 13);
} else {
var s = this.style;
var p = this.parentNode;
if ( $.css(p,"position") == 'static' )
p.style.position = 'relative';
s.position = 'absolute';
s.left = parseInt(($.css(p,"width") - $.css(this,"width"))/2) + "px";
s.top = parseInt(($.css(p,"height") - $.css(this,"height"))/2) + "px";
}
});
};
$.setAuto = function(e,p) {
var a = e.style[p];
var o = $.css(e,p);
e.style[p] = 'auto';
var n = $.css(e,p);
if ( o != n )
e.style[p] = a;
};

144
jquery/jquery.js vendored
View file

@ -214,27 +214,23 @@ function $(a,c) {
}, },
parent: function(a) { parent: function(a) {
this.cur = $.map(this.cur,function(d){ this.cur = $.map(this.cur,function(d){
return d.parentNode; return d.parentNode;
}); });
if ( a ) this.cur = $.filter(a,this.cur).r; if ( a ) this.cur = $.filter(a,this.cur).r;
return this; return this;
}, },
parents: function(a) { parents: function(a) {
this.cur = $.map(this.cur,$.parents); this.cur = $.map(this.cur,$.parents);
if ( a ) this.cur = $.filter(a,this.cur).r; if ( a ) this.cur = $.filter(a,this.cur).r;
return this; return this;
}, },
siblings: function(a) { siblings: function(a) {
// Incorrect, need to exclude current element // Incorrect, need to exclude current element
this.cur = $.map(this.cur,$.sibling); this.cur = $.map(this.cur,$.sibling);
if ( a ) this.cur = $.filter(a,this.cur).r; if ( a ) this.cur = $.filter(a,this.cur).r;
return this;
},
parents: function(a) {
return this; return this;
}, },
@ -515,22 +511,22 @@ $.tag = function(a,b){
}; };
$.attr = function(o,a,v){ $.attr = function(o,a,v){
if ( a && a.constructor == String ) { if ( a && a.constructor == String ) {
var fix = { var fix = {
'for': 'htmlFor', 'for': 'htmlFor',
'text': 'cssText', 'text': 'cssText',
'class': 'className', 'class': 'className',
'float': 'cssFloat' 'float': 'cssFloat'
}; };
a = (fix[a] && fix[a].replace && fix[a]) || a; a = (fix[a] && fix[a].replace && fix[a]) || a;
var r = new RegExp("-([a-z])","ig"); var r = new RegExp("-([a-z])","ig");
a = a.replace(r,function(z,b){return b.toUpperCase();}); a = a.replace(r,function(z,b){return b.toUpperCase();});
if ( v != null ) { if ( v != null ) {
o[a] = v; o[a] = v;
if ( o.setAttribute ) o.setAttribute(a,v); if ( o.setAttribute ) o.setAttribute(a,v);
} }
return o[a] || o.getAttribute(a) || ''; return o[a] || o.getAttribute(a) || '';
} else return ''; } else return '';
}; };
$.filter = function(t,r,not) { $.filter = function(t,r,not) {
@ -586,34 +582,36 @@ $.parents = function(a){
return b; return b;
}; };
$.cleanSpaces = function(t){return t.replace(/^\s+|\s+$/g, '')}; $.cleanSpaces = function(t){
return t.replace(/^\s+|\s+$/g, '')
};
$.ofType = function(a,n,e) { $.ofType = function(a,n,e) {
var t = $.grep($.sibling(a),function(b){return b.nodeName == a.nodeName}); var t = $.grep($.sibling(a),function(b){return b.nodeName == a.nodeName});
if ( e ) n = t.length - n - 1; if ( e ) n = t.length - n - 1;
return n != null ? t[n] == a : t.length; return n != null ? t[n] == a : t.length;
}; };
$.sibling = function(a,n,e) { $.sibling = function(a,n,e) {
var type = []; var type = [];
var tmp = a.parentNode.childNodes; var tmp = a.parentNode.childNodes;
for ( var i = 0; i < tmp.length; i++ ) { for ( var i = 0; i < tmp.length; i++ ) {
if ( tmp[i].nodeType == 1 ) if ( tmp[i].nodeType == 1 )
type[type.length] = tmp[i]; type[type.length] = tmp[i];
if ( tmp[i] == a ) if ( tmp[i] == a )
type.n = type.length - 1; type.n = type.length - 1;
} }
if ( e ) n = type.length - n - 1; if ( e ) n = type.length - n - 1;
type.cur = ( type[n] == a ); type.cur = ( type[n] == a );
type.prev = ( type.n > 0 ? type[type.n - 1] : null ); type.prev = ( type.n > 0 ? type[type.n - 1] : null );
type.next = ( type.n < type.length - 1 ? type[type.n + 1] : null ); type.next = ( type.n < type.length - 1 ? type[type.n + 1] : null );
return type; return type;
}; };
$.hasWord = function(e,a) { $.hasWord = function(e,a) {
if ( e == null ) return false; if ( e == null ) return false;
if ( e.className != null ) e = e.className; if ( e.className != null ) e = e.className;
return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e) return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e)
}; };
$.getAll = function(o,r) { $.getAll = function(o,r) {
@ -633,36 +631,36 @@ $.merge = function(a,b) {
for ( var j = 0; j < b.length; j++ ) for ( var j = 0; j < b.length; j++ )
d[j] = b[j]; d[j] = b[j];
for ( var i = 0; i < a.length; i++ ) { for ( var i = 0; i < a.length; i++ ) {
var c = true; var c = true;
for ( var j = 0; j < b.length; j++ ) for ( var j = 0; j < b.length; j++ )
if ( a[i] == b[j] ) if ( a[i] == b[j] )
c = false; c = false;
if ( c ) if ( c )
d[d.length] = a[i]; d[d.length] = a[i];
} }
return d; return d;
}; };
$.grep = function(a,f,s) { $.grep = function(a,f,s) {
var r = []; var r = [];
if ( a != null ) if ( a != null )
for ( var i = 0; i < a.length; i++ ) for ( var i = 0; i < a.length; i++ )
if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) ) if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) )
r[r.length] = a[i]; r[r.length] = a[i];
return r; return r;
}; };
$.map = function(a,f) { $.map = function(a,f) {
var r = []; var r = [];
for ( var i = 0; i < a.length; i++ ) { for ( var i = 0; i < a.length; i++ ) {
var t = f(a[i],i); var t = f(a[i],i);
if ( t != null ) { if ( t != null ) {
if ( t.constructor != Array ) t = [t]; if ( t.constructor != Array ) t = [t];
r = $.merge( t, r ); r = $.merge( t, r );
} }
} }
return r; return r;
}; };
// Bind an event to an element // Bind an event to an element
@ -700,8 +698,8 @@ function removeEvent(element, type, handler) {
}; };
function triggerEvent(element,type) { function triggerEvent(element,type) {
if ( element["on" + type] ) if ( element["on" + type] )
element["on" + type]({ type: type }); element["on" + type]({ type: type });
} }
function handleEvent(event) { function handleEvent(event) {
@ -710,7 +708,7 @@ function handleEvent(event) {
var handlers = []; var handlers = [];
for ( var i in this.events[event.type] ) for ( var i in this.events[event.type] )
handlers[handlers.length] = this.events[event.type][i]; handlers[handlers.length] = this.events[event.type][i];
for ( var i = 0; i < handlers.length; i++ ) { for ( var i = 0; i < handlers.length; i++ ) {
try { try {
if ( handlers[i].constructor == Function ) { if ( handlers[i].constructor == Function ) {
this.$$handleEvent = handlers[i]; this.$$handleEvent = handlers[i];
@ -752,6 +750,6 @@ $.fn.text = function(e) {
}; };
setTimeout(function(){ setTimeout(function(){
if ( typeof Prototype != "undefined" && $.g == null && $.clean == null ) if ( typeof Prototype != "undefined" && $.g == null && $.clean == null )
throw "Error: You are overwriting jQuery, please include jQuery last."; throw "Error: You are overwriting jQuery, please include jQuery last.";
}, 1000); }, 1000);