viewing source for "prototype.lite.js"

last commit

commit d53d1f4ef49669f8295e08afbabf19eb495e80fb Author: saburo <saburo@a04a6e75-5819-0410-a511-8dafea38c924> Date: Mon Jul 24 19:12:43 2006 +0000
Added code to repository

source code

001: /*  Prototype JavaScript framework
002:  *  (c) 2005 Sam Stephenson <sam@conio.net>
003:  *  Prototype is freely distributable under the terms of an MIT-style license.
004:  *  For details, see the Prototype web site: http://prototype.conio.net/
005: /*--------------------------------------------------------------------------*/
006: 
007: //note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).
008: 
009: var Class = {
010: 	create: function() {
011: 		return function() {
012: 			this.initialize.apply(this, arguments);
013: 		}
014: 	}
015: }
016: 
017: Object.extend = function(destination, source) {
018: 	for (property in source) destination[property] = source[property];
019: 	return destination;
020: }
021: 
022: Function.prototype.bind = function(object) {
023: 	var __method = this;
024: 	return function() {
025: 		return __method.apply(object, arguments);
026: 	}
027: }
028: 
029: Function.prototype.bindAsEventListener = function(object) {
030: var __method = this;
031: 	return function(event) {
032: 		__method.call(object, event || window.event);
033: 	}
034: }
035: 
036: function $() {
037: 	if (arguments.length == 1) return get$(arguments[0]);
038: 	var elements = [];
039: 	$c(arguments).each(function(el){
040: 		elements.push(get$(el));
041: 	});
042: 	return elements;
043: 
044: 	function get$(el){
045: 		if (typeof el == 'string') el = document.getElementById(el);
046: 		return el;
047: 	}
048: }
049: 
050: if (!window.Element) var Element = new Object();
051: 
052: Object.extend(Element, {
053: 	remove: function(element) {
054: 		element = $(element);
055: 		element.parentNode.removeChild(element);
056: 	},
057: 
058: 	hasClassName: function(element, className) {
059: 		element = $(element);
060: 		if (!element) return;
061: 		var hasClass = false;
062: 		element.className.split(' ').each(function(cn){
063: 			if (cn == className) hasClass = true;
064: 		});
065: 		return hasClass;
066: 	},
067: 
068: 	addClassName: function(element, className) {
069: 		element = $(element);
070: 		Element.removeClassName(element, className);
071: 		element.className += ' ' + className;
072: 	},
073:   
074: 	removeClassName: function(element, className) {
075: 		element = $(element);
076: 		if (!element) return;
077: 		var newClassName = '';
078: 		element.className.split(' ').each(function(cn, i){
079: 			if (cn != className){
080: 				if (i > 0) newClassName += ' ';
081: 				newClassName += cn;
082: 			}
083: 		});
084: 		element.className = newClassName;
085: 	},
086: 
087: 	cleanWhitespace: function(element) {
088: 		element = $(element);
089: 		$c(element.childNodes).each(function(node){
090: 			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
091: 		});
092: 	},
093: 
094: 	find: function(element, what) {
095: 		element = $(element)[what];
096: 		while (element.nodeType != 1) element = element[what];
097: 		return element;
098: 	}
099: });
100: 
101: var Position = {
102: 	cumulativeOffset: function(element) {
103: 		var valueT = 0, valueL = 0;
104: 		do {
105: 			valueT += element.offsetTop  || 0;
106: 			valueL += element.offsetLeft || 0;
107: 			element = element.offsetParent;
108: 		} while (element);
109: 		return [valueL, valueT];
110: 	}
111: };
112: 
113: document.getElementsByClassName = function(className) {
114: 	var children = document.getElementsByTagName('*') || document.all;
115: 	var elements = [];
116: 	$c(children).each(function(child){
117: 		if (Element.hasClassName(child, className)) elements.push(child);
118: 	});  
119: 	return elements;
120: }
121: 
122: //useful array functions
123: Array.prototype.iterate = function(func){
124: 	for(var i=0;i<this.length;i++) func(this[i], i);
125: }
126: if (!Array.prototype.each) Array.prototype.each = Array.prototype.iterate;
127: 
128: function $c(array){
129: 	var nArray = [];
130: 	for (var i=0;i<array.length;i++) nArray.push(array[i]);
131: 	return nArray;
132: }