summaryrefslogtreecommitdiffstats
path: root/user_guide/nav/prototype.lite.js
blob: e6c362279cc66d7767fed6978dd0fd6c17907846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/


//note: this is a stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
  create: function() {
	return function() {
	  this.initialize.apply(this, arguments);
	}
  }
}

Object.extend = function(destination, source) {
  for (property in source) {
	destination[property] = source[property];
  }
  return destination;
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
	return __method.apply(object, arguments);
  }
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
	var element = arguments[i];
	if (typeof element == 'string')
	  element = document.getElementById(element);

	if (arguments.length == 1)
	  return element;

	elements.push(element);
  }

  return elements;
}

//-------------------------

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();

  for (var i = 0; i < children.length; i++) {
	var child = children[i];
	var classNames = child.className.split(' ');
	for (var j = 0; j < classNames.length; j++) {
	  if (classNames[j] == className) {
		elements.push(child);
		break;
	  }
	}
  }

  return elements;
}

//-------------------------

if (!window.Element) {
  var Element = new Object();
}

Object.extend(Element, {
  remove: function(element) {
	element = $(element);
	element.parentNode.removeChild(element);
  },

  hasClassName: function(element, className) {
	element = $(element);
	if (!element)
	  return;
	var a = element.className.split(' ');
	for (var i = 0; i < a.length; i++) {
	  if (a[i] == className)
		return true;
	}
	return false;
  },

  addClassName: function(element, className) {
	element = $(element);
	Element.removeClassName(element, className);
	element.className += ' ' + className;
  },

  removeClassName: function(element, className) {
	element = $(element);
	if (!element)
	  return;
	var newClassName = '';
	var a = element.className.split(' ');
	for (var i = 0; i < a.length; i++) {
	  if (a[i] != className) {
		if (i > 0)
		  newClassName += ' ';
		newClassName += a[i];
	  }
	}
	element.className = newClassName;
  },

  // removes whitespace-only text node children
  cleanWhitespace: function(element) {
	element = $(element);
	for (var i = 0; i < element.childNodes.length; i++) {
	  var node = element.childNodes[i];
	  if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
		Element.remove(node);
	}
  }
});