Added Canvas 1.1.0, originally not under SCM so no historical development records...
[canvas.git] / res / js / prototype.lite.js
blobf1520e2c60b8e0d1aa8fae7bdd900cb3e055764b
1 /* Prototype JavaScript framework
2 * (c) 2005 Sam Stephenson <sam@conio.net>
4 * Prototype is freely distributable under the terms of an MIT-style license.
6 * For details, see the Prototype web site: http://prototype.conio.net/
8 /*--------------------------------------------------------------------------*/
11 //note: this is a stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).
13 var Class = {
14 create: function() {
15 return function() {
16 this.initialize.apply(this, arguments);
21 Object.extend = function(destination, source) {
22 for (property in source) {
23 destination[property] = source[property];
25 return destination;
28 Function.prototype.bind = function(object) {
29 var __method = this;
30 return function() {
31 return __method.apply(object, arguments);
35 function $() {
36 var elements = new Array();
38 for (var i = 0; i < arguments.length; i++) {
39 var element = arguments[i];
40 if (typeof element == 'string')
41 element = document.getElementById(element);
43 if (arguments.length == 1)
44 return element;
46 elements.push(element);
49 return elements;
52 //-------------------------
54 document.getElementsByClassName = function(className) {
55 var children = document.getElementsByTagName('*') || document.all;
56 var elements = new Array();
58 for (var i = 0; i < children.length; i++) {
59 var child = children[i];
60 var classNames = child.className.split(' ');
61 for (var j = 0; j < classNames.length; j++) {
62 if (classNames[j] == className) {
63 elements.push(child);
64 break;
69 return elements;
72 //-------------------------
74 if (!window.Element) {
75 var Element = new Object();
78 Object.extend(Element, {
79 remove: function(element) {
80 element = $(element);
81 element.parentNode.removeChild(element);
84 hasClassName: function(element, className) {
85 element = $(element);
86 if (!element)
87 return;
88 var a = element.className.split(' ');
89 for (var i = 0; i < a.length; i++) {
90 if (a[i] == className)
91 return true;
93 return false;
96 addClassName: function(element, className) {
97 element = $(element);
98 Element.removeClassName(element, className);
99 element.className += ' ' + className;
102 removeClassName: function(element, className) {
103 element = $(element);
104 if (!element)
105 return;
106 var newClassName = '';
107 var a = element.className.split(' ');
108 for (var i = 0; i < a.length; i++) {
109 if (a[i] != className) {
110 if (i > 0)
111 newClassName += ' ';
112 newClassName += a[i];
115 element.className = newClassName;
118 // removes whitespace-only text node children
119 cleanWhitespace: function(element) {
120 element = $(element);
121 for (var i = 0; i < element.childNodes.length; i++) {
122 var node = element.childNodes[i];
123 if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
124 Element.remove(node);