This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
forked from linares/bigpipe
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathprototypepatch.js
executable file
·203 lines (164 loc) · 5.57 KB
/
prototypepatch.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* $Id: prototypepatch.js,v 1.20 2010/09/13 12:09:58 antti-pe Exp $
*
* Copyright © 2008 - 2009 Sulake Dynamoid Oy http://www.dynamoid.com/
*
* Patches for prototype 1.6.0.2
*/
Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;
/***** Event.observeOnce *****/
var PrototypeEventPatch = {
observeOnce: function(element, eventName, handler, predicate) {
var onceHandler = function() {
if (typeof predicate != 'function' || predicate.apply(this, arguments)) {
handler.apply(this, arguments);
Event.stopObserving(element, eventName, onceHandler);
}
}.bindAsEventListener(element);
return Event.observe(element, eventName, onceHandler);
}
};
Object.extend(window.Event, PrototypeEventPatch);
Object.extend(document, {
observeOnce: PrototypeEventPatch.observeOnce.methodize()
});
Element.addMethods({
observeOnce: PrototypeEventPatch.observeOnce
});
/***** /Event.observeOnce *****/
var PrototypeElementPatch = {
delegate: function(element, selector, eventName, callback) {
element = $(element);
element.observe(eventName, function(callback, evt) {
if (el = evt.findElement(selector)) {
callback.bind(el, evt)();
}
}.curry(callback));
return element;
},
preventTextSelection: function(element) {
if (typeof element.onselectstart != 'undefined') {
// IE
element.observe('selectstart', function(evt) {
evt.preventDefault();
});
} else if (typeof element.style.MozUserSelect != 'undefined') {
// Mozilla
element.style.MozUserSelect = 'none';
} else {
// Others
element.observe('mousedown', function(evt) {
evt.preventDefault();
});
}
}
};
Element.addMethods(PrototypeElementPatch);
function $RF(el, radioGroup) {
if($(el).type && $(el).type.toLowerCase() == 'radio') {
var radioGroup = $(el).name;
var el = $(el).form;
} else if ($(el).tagName.toLowerCase() != 'form') {
return false;
}
var checked = $(el).getInputs('radio', radioGroup).find(function(re) { return re.checked; });
return (checked) ? $F(checked) : null;
}
Object.extend(Element.Methods.ByTag, {
"FORM": Object.clone(Form.Methods),
"INPUT": Object.clone(Form.Element.Methods),
"SELECT": Object.clone(Form.Element.Methods),
"TEXTAREA": Object.clone(Form.Element.Methods),
"BUTTON": Object.clone(Form.Element.Methods)
});
Element.addMethods();
/**
* Event.simulate(@element, eventName[, options]) -> Element
*
* - @element: element to fire event on
* - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported)
* - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc.
*
* $('foo').simulate('click'); // => fires "click" event on an element with id=foo
*
* @license MIT
* @copyright (c) 2009 Juriy Zaytsev
*/
(function() {
var eventMatchers = {
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/
}
var defaultOptions = {
pointerX: 0,
pointerY: 0,
button: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
bubbles: true,
cancelable: true
}
Event.simulate = function(element, eventName) {
var options = Object.extend(defaultOptions, arguments[2] || { });
var oEvent, eventType = null;
element = $(element);
for (var name in eventMatchers) {
if (eventMatchers[name].test(eventName)) { eventType = name; break; }
}
if (!eventType)
throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
if (document.createEvent) {
oEvent = document.createEvent(eventType);
if (eventType == 'HTMLEvents') {
oEvent.initEvent(eventName, options.bubbles, options.cancelable);
} else {
oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
}
element.dispatchEvent(oEvent);
} else {
options.clientX = options.pointerX;
options.clientY = options.pointerY;
oEvent = Object.extend(document.createEventObject(), options);
element.fireEvent('on' + eventName, oEvent);
}
return element;
}
Element.addMethods({ simulate: Event.simulate });
})();
Object.extend(document, {
bufferedEvents: new Hash(),
fire: document.fire.wrap(function(proceed, eventName, memo) {
var a = document.bufferedEvents.get(eventName);
if (!a) {
a = new Array();
document.bufferedEvents.set(eventName, a);
}
a.push(proceed(eventName, memo));
}),
observe: document.observe.wrap(function(proceed, eventName, handler) {
var a = document.bufferedEvents.get(eventName);
if (a) {
a.each(function(event) {
handler(event)
});
}
proceed(eventName, handler);
})
});
Object.extend(Form.Element.Methods, {
disable: Form.Element.Methods.disable.wrap(function(proceed, element) {
element.fire('form:disable');
return proceed(element);
}),
enable: Form.Element.Methods.enable.wrap(function(proceed, element) {
element.fire('form:enable');
return proceed(element);
})
});
Element.addMethods([ 'FORM', 'INPUT', 'TEXTAREA', 'SELECT', 'BUTTON' ], { disable: Form.Element.Methods.disable, enable: Form.Element.Methods.enable });