actionpack 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +309 -16
- data/README +1 -1
- data/lib/action_controller.rb +5 -0
- data/lib/action_controller/assertions.rb +57 -12
- data/lib/action_controller/auto_complete.rb +47 -0
- data/lib/action_controller/base.rb +288 -258
- data/lib/action_controller/benchmarking.rb +8 -3
- data/lib/action_controller/caching.rb +88 -42
- data/lib/action_controller/cgi_ext/cgi_ext.rb +1 -1
- data/lib/action_controller/cgi_ext/cgi_methods.rb +41 -11
- data/lib/action_controller/cgi_ext/multipart_progress.rb +169 -0
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +30 -12
- data/lib/action_controller/cgi_process.rb +39 -11
- data/lib/action_controller/code_generation.rb +235 -0
- data/lib/action_controller/cookies.rb +14 -8
- data/lib/action_controller/deprecated_renders_and_redirects.rb +76 -0
- data/lib/action_controller/filters.rb +8 -7
- data/lib/action_controller/helpers.rb +41 -6
- data/lib/action_controller/layout.rb +45 -16
- data/lib/action_controller/request.rb +86 -23
- data/lib/action_controller/rescue.rb +1 -0
- data/lib/action_controller/response.rb +1 -1
- data/lib/action_controller/routing.rb +536 -272
- data/lib/action_controller/scaffolding.rb +30 -25
- data/lib/action_controller/session/active_record_store.rb +251 -50
- data/lib/action_controller/streaming.rb +133 -0
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/edit.rhtml +2 -2
- data/lib/action_controller/templates/scaffolds/layout.rhtml +22 -18
- data/lib/action_controller/templates/scaffolds/list.rhtml +3 -3
- data/lib/action_controller/templates/scaffolds/new.rhtml +2 -2
- data/lib/action_controller/templates/scaffolds/show.rhtml +1 -1
- data/lib/action_controller/test_process.rb +68 -47
- data/lib/action_controller/upload_progress.rb +421 -0
- data/lib/action_controller/url_rewriter.rb +8 -11
- data/lib/action_controller/vendor/html-scanner/html/document.rb +6 -5
- data/lib/action_controller/vendor/html-scanner/html/node.rb +70 -14
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +17 -10
- data/lib/action_controller/vendor/html-scanner/html/version.rb +3 -3
- data/lib/action_controller/vendor/xml_simple.rb +1019 -0
- data/lib/action_controller/verification.rb +36 -30
- data/lib/action_view/base.rb +21 -14
- data/lib/action_view/helpers/active_record_helper.rb +15 -13
- data/lib/action_view/helpers/asset_tag_helper.rb +26 -9
- data/lib/action_view/helpers/benchmark_helper.rb +24 -0
- data/lib/action_view/helpers/capture_helper.rb +7 -5
- data/lib/action_view/helpers/date_helper.rb +63 -46
- data/lib/action_view/helpers/form_helper.rb +7 -1
- data/lib/action_view/helpers/form_options_helper.rb +19 -11
- data/lib/action_view/helpers/form_tag_helper.rb +5 -1
- data/lib/action_view/helpers/javascript_helper.rb +403 -35
- data/lib/action_view/helpers/javascripts/controls.js +261 -0
- data/lib/action_view/helpers/javascripts/dragdrop.js +476 -0
- data/lib/action_view/helpers/javascripts/effects.js +570 -0
- data/lib/action_view/helpers/javascripts/prototype.js +633 -371
- data/lib/action_view/helpers/number_helper.rb +11 -13
- data/lib/action_view/helpers/tag_helper.rb +1 -2
- data/lib/action_view/helpers/text_helper.rb +69 -6
- data/lib/action_view/helpers/upload_progress_helper.rb +433 -0
- data/lib/action_view/helpers/url_helper.rb +98 -3
- data/lib/action_view/partials.rb +14 -8
- data/lib/action_view/vendor/builder/xmlmarkup.rb +11 -0
- data/rakefile +13 -5
- data/test/abstract_unit.rb +1 -1
- data/test/controller/action_pack_assertions_test.rb +52 -9
- data/test/controller/active_record_assertions_test.rb +119 -120
- data/test/controller/active_record_store_test.rb +111 -0
- data/test/controller/addresses_render_test.rb +45 -0
- data/test/controller/caching_filestore.rb +92 -0
- data/test/controller/capture_test.rb +39 -0
- data/test/controller/cgi_test.rb +40 -3
- data/test/controller/helper_test.rb +65 -13
- data/test/controller/multipart_progress_testx.rb +365 -0
- data/test/controller/new_render_test.rb +263 -0
- data/test/controller/redirect_test.rb +64 -0
- data/test/controller/render_test.rb +20 -21
- data/test/controller/request_test.rb +83 -3
- data/test/controller/routing_test.rb +702 -0
- data/test/controller/send_file_test.rb +2 -0
- data/test/controller/test_test.rb +44 -8
- data/test/controller/upload_progress_testx.rb +89 -0
- data/test/controller/verification_test.rb +94 -29
- data/test/fixtures/addresses/list.rhtml +1 -0
- data/test/fixtures/test/capturing.rhtml +4 -0
- data/test/fixtures/test/list.rhtml +1 -1
- data/test/fixtures/test/update_element_with_capture.rhtml +9 -0
- data/test/template/active_record_helper_test.rb +30 -15
- data/test/template/asset_tag_helper_test.rb +12 -5
- data/test/template/benchmark_helper_test.rb +72 -0
- data/test/template/date_helper_test.rb +69 -0
- data/test/template/form_helper_test.rb +18 -10
- data/test/template/form_options_helper_test.rb +40 -5
- data/test/template/javascript_helper.rb +149 -2
- data/test/template/number_helper_test.rb +2 -0
- data/test/template/tag_helper_test.rb +4 -0
- data/test/template/text_helper_test.rb +36 -0
- data/test/template/upload_progress_helper_testx.rb +272 -0
- data/test/template/url_helper_test.rb +30 -0
- metadata +30 -6
- data/test/controller/layout_test.rb +0 -49
- data/test/controller/routing_tests.rb +0 -543
@@ -0,0 +1,261 @@
|
|
1
|
+
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
// a copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
// permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
// the following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be
|
12
|
+
// included in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
|
24
|
+
var children = $(element).childNodes;
|
25
|
+
var text = "";
|
26
|
+
var classtest = new RegExp("^([^ ]+ )*" + ignoreclass+ "( [^ ]+)*$","i");
|
27
|
+
|
28
|
+
for (var i = 0; i < children.length; i++) {
|
29
|
+
if(children[i].nodeType==3) {
|
30
|
+
text+=children[i].nodeValue;
|
31
|
+
} else {
|
32
|
+
if((!children[i].className.match(classtest)) && children[i].hasChildNodes())
|
33
|
+
text += Element.collectTextNodesIgnoreClass(children[i], ignoreclass);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
return text;
|
38
|
+
}
|
39
|
+
|
40
|
+
Ajax.Autocompleter = Class.create();
|
41
|
+
Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
|
42
|
+
initialize: function(element, update, url, options) {
|
43
|
+
this.element = $(element);
|
44
|
+
this.update = $(update);
|
45
|
+
this.has_focus = false;
|
46
|
+
this.changed = false;
|
47
|
+
this.active = false;
|
48
|
+
this.index = 0;
|
49
|
+
this.entry_count = 0;
|
50
|
+
this.url = url;
|
51
|
+
|
52
|
+
this.setOptions(options);
|
53
|
+
this.options.asynchronous = true;
|
54
|
+
this.options.onComplete = this.onComplete.bind(this)
|
55
|
+
this.options.frequency = this.options.frequency || 0.4;
|
56
|
+
this.options.min_chars = this.options.min_chars || 1;
|
57
|
+
this.options.method = 'post';
|
58
|
+
|
59
|
+
this.options.onShow = this.options.onShow ||
|
60
|
+
function(element, update){
|
61
|
+
if(!update.style.position || update.style.position=='absolute') {
|
62
|
+
update.style.position = 'absolute';
|
63
|
+
var offsets = Position.cumulativeOffset(element);
|
64
|
+
update.style.left = offsets[0] + 'px';
|
65
|
+
update.style.top = (offsets[1] + element.offsetHeight) + 'px';
|
66
|
+
update.style.width = element.offsetWidth + 'px';
|
67
|
+
}
|
68
|
+
new Effect.Appear(update,{duration:0.3});
|
69
|
+
};
|
70
|
+
this.options.onHide = this.options.onHide ||
|
71
|
+
function(element, update){ new Effect.Fade(update,{duration:0.3}) };
|
72
|
+
|
73
|
+
|
74
|
+
if(this.options.indicator)
|
75
|
+
this.indicator = $(this.options.indicator);
|
76
|
+
|
77
|
+
this.observer = null;
|
78
|
+
|
79
|
+
Element.hide(this.update);
|
80
|
+
|
81
|
+
Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this));
|
82
|
+
Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this));
|
83
|
+
},
|
84
|
+
|
85
|
+
show: function() {
|
86
|
+
if(this.update.style.display=='none') this.options.onShow(this.element, this.update);
|
87
|
+
if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && this.update.style.position=='absolute') {
|
88
|
+
new Insertion.After(this.update,
|
89
|
+
'<iframe id="' + this.update.id + '_iefix" '+
|
90
|
+
'style="display:none;filter:progid:DXImageTransform.Microsoft.Alpha(apacity=0);" ' +
|
91
|
+
'src="javascript:;" frameborder="0" scrolling="no"></iframe>');
|
92
|
+
this.iefix = $(this.update.id+'_iefix');
|
93
|
+
}
|
94
|
+
if(this.iefix) {
|
95
|
+
Position.clone(this.update, this.iefix);
|
96
|
+
this.iefix.style.zIndex = 1;
|
97
|
+
this.update.style.zIndex = 2;
|
98
|
+
Element.show(this.iefix);
|
99
|
+
}
|
100
|
+
},
|
101
|
+
|
102
|
+
hide: function() {
|
103
|
+
if(this.update.style.display=='') this.options.onHide(this.element, this.update);
|
104
|
+
if(this.iefix) Element.hide(this.iefix);
|
105
|
+
},
|
106
|
+
|
107
|
+
startIndicator: function() {
|
108
|
+
if(this.indicator) Element.show(this.indicator);
|
109
|
+
},
|
110
|
+
|
111
|
+
stopIndicator: function() {
|
112
|
+
if(this.indicator) Element.hide(this.indicator);
|
113
|
+
},
|
114
|
+
|
115
|
+
onObserverEvent: function() {
|
116
|
+
this.changed = false;
|
117
|
+
if(this.element.value.length>=this.options.min_chars) {
|
118
|
+
this.startIndicator();
|
119
|
+
this.options.parameters = this.options.callback ?
|
120
|
+
this.options.callback(this.element, Form.Element.getValue(this.element)) :
|
121
|
+
Form.Element.serialize(this.element);
|
122
|
+
new Ajax.Request(this.url, this.options);
|
123
|
+
} else {
|
124
|
+
this.active = false;
|
125
|
+
this.hide();
|
126
|
+
}
|
127
|
+
},
|
128
|
+
|
129
|
+
addObservers: function(element) {
|
130
|
+
Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
|
131
|
+
Event.observe(element, "click", this.onClick.bindAsEventListener(this));
|
132
|
+
},
|
133
|
+
|
134
|
+
onComplete: function(request) {
|
135
|
+
if(!this.changed && this.has_focus) {
|
136
|
+
this.update.innerHTML = request.responseText;
|
137
|
+
Element.cleanWhitespace(this.update);
|
138
|
+
Element.cleanWhitespace(this.update.firstChild);
|
139
|
+
|
140
|
+
if(this.update.firstChild && this.update.firstChild.childNodes) {
|
141
|
+
this.entry_count =
|
142
|
+
this.update.firstChild.childNodes.length;
|
143
|
+
for (var i = 0; i < this.entry_count; i++) {
|
144
|
+
entry = this.get_entry(i);
|
145
|
+
entry.autocompleteIndex = i;
|
146
|
+
this.addObservers(entry);
|
147
|
+
}
|
148
|
+
} else {
|
149
|
+
this.entry_count = 0;
|
150
|
+
}
|
151
|
+
|
152
|
+
this.stopIndicator();
|
153
|
+
|
154
|
+
this.index = 0;
|
155
|
+
this.render();
|
156
|
+
}
|
157
|
+
},
|
158
|
+
|
159
|
+
onKeyPress: function(event) {
|
160
|
+
if(this.active)
|
161
|
+
switch(event.keyCode) {
|
162
|
+
case Event.KEY_TAB:
|
163
|
+
case Event.KEY_RETURN:
|
164
|
+
this.select_entry();
|
165
|
+
Event.stop(event);
|
166
|
+
case Event.KEY_ESC:
|
167
|
+
this.hide();
|
168
|
+
this.active = false;
|
169
|
+
return;
|
170
|
+
case Event.KEY_LEFT:
|
171
|
+
case Event.KEY_RIGHT:
|
172
|
+
return;
|
173
|
+
case Event.KEY_UP:
|
174
|
+
this.mark_previous();
|
175
|
+
this.render();
|
176
|
+
if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
|
177
|
+
return;
|
178
|
+
case Event.KEY_DOWN:
|
179
|
+
this.mark_next();
|
180
|
+
this.render();
|
181
|
+
if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
else
|
185
|
+
if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN)
|
186
|
+
return;
|
187
|
+
|
188
|
+
this.changed = true;
|
189
|
+
this.has_focus = true;
|
190
|
+
|
191
|
+
if(this.observer) clearTimeout(this.observer);
|
192
|
+
this.observer =
|
193
|
+
setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
|
194
|
+
},
|
195
|
+
|
196
|
+
onHover: function(event) {
|
197
|
+
var element = Event.findElement(event, 'LI');
|
198
|
+
if(this.index != element.autocompleteIndex)
|
199
|
+
{
|
200
|
+
this.index = element.autocompleteIndex;
|
201
|
+
this.render();
|
202
|
+
}
|
203
|
+
Event.stop(event);
|
204
|
+
},
|
205
|
+
|
206
|
+
onClick: function(event) {
|
207
|
+
var element = Event.findElement(event, 'LI');
|
208
|
+
this.index = element.autocompleteIndex;
|
209
|
+
this.select_entry();
|
210
|
+
Event.stop(event);
|
211
|
+
},
|
212
|
+
|
213
|
+
onBlur: function(event) {
|
214
|
+
// needed to make click events working
|
215
|
+
setTimeout(this.hide.bind(this), 250);
|
216
|
+
this.has_focus = false;
|
217
|
+
this.active = false;
|
218
|
+
},
|
219
|
+
|
220
|
+
render: function() {
|
221
|
+
if(this.entry_count > 0) {
|
222
|
+
for (var i = 0; i < this.entry_count; i++)
|
223
|
+
this.index==i ?
|
224
|
+
Element.addClassName(this.get_entry(i),"selected") :
|
225
|
+
Element.removeClassName(this.get_entry(i),"selected");
|
226
|
+
|
227
|
+
if(this.has_focus) {
|
228
|
+
if(this.get_current_entry().scrollIntoView)
|
229
|
+
this.get_current_entry().scrollIntoView(false);
|
230
|
+
|
231
|
+
this.show();
|
232
|
+
this.active = true;
|
233
|
+
}
|
234
|
+
} else this.hide();
|
235
|
+
},
|
236
|
+
|
237
|
+
mark_previous: function() {
|
238
|
+
if(this.index > 0) this.index--
|
239
|
+
else this.index = this.entry_count-1;
|
240
|
+
},
|
241
|
+
|
242
|
+
mark_next: function() {
|
243
|
+
if(this.index < this.entry_count-1) this.index++
|
244
|
+
else this.index = 0;
|
245
|
+
},
|
246
|
+
|
247
|
+
get_entry: function(index) {
|
248
|
+
return this.update.firstChild.childNodes[index];
|
249
|
+
},
|
250
|
+
|
251
|
+
get_current_entry: function() {
|
252
|
+
return this.get_entry(this.index);
|
253
|
+
},
|
254
|
+
|
255
|
+
select_entry: function() {
|
256
|
+
this.active = false;
|
257
|
+
value = Element.collectTextNodesIgnoreClass(this.get_current_entry(), 'informal').unescapeHTML();
|
258
|
+
this.element.value = value;
|
259
|
+
this.element.focus();
|
260
|
+
}
|
261
|
+
});
|
@@ -0,0 +1,476 @@
|
|
1
|
+
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
2
|
+
//
|
3
|
+
// Element.Class part Copyright (c) 2005 by Rick Olson
|
4
|
+
//
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
// a copy of this software and associated documentation files (the
|
7
|
+
// "Software"), to deal in the Software without restriction, including
|
8
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
// distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
// permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
// the following conditions:
|
12
|
+
//
|
13
|
+
// The above copyright notice and this permission notice shall be
|
14
|
+
// included in all copies or substantial portions of the Software.
|
15
|
+
//
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
Element.Class = {
|
25
|
+
// Element.toggleClass(element, className) toggles the class being on/off
|
26
|
+
// Element.toggleClass(element, className1, className2) toggles between both classes,
|
27
|
+
// defaulting to className1 if neither exist
|
28
|
+
toggle: function(element, className) {
|
29
|
+
if(Element.Class.has(element, className)) {
|
30
|
+
Element.Class.remove(element, className);
|
31
|
+
if(arguments.length == 3) Element.Class.add(element, arguments[2]);
|
32
|
+
} else {
|
33
|
+
Element.Class.add(element, className);
|
34
|
+
if(arguments.length == 3) Element.Class.remove(element, arguments[2]);
|
35
|
+
}
|
36
|
+
},
|
37
|
+
|
38
|
+
// gets space-delimited classnames of an element as an array
|
39
|
+
get: function(element) {
|
40
|
+
element = $(element);
|
41
|
+
return element.className.split(' ');
|
42
|
+
},
|
43
|
+
|
44
|
+
// functions adapted from original functions by Gavin Kistner
|
45
|
+
remove: function(element) {
|
46
|
+
element = $(element);
|
47
|
+
var regEx;
|
48
|
+
for(var i = 1; i < arguments.length; i++) {
|
49
|
+
regEx = new RegExp("^" + arguments[i] + "\\b\\s*|\\s*\\b" + arguments[i] + "\\b", 'g');
|
50
|
+
element.className = element.className.replace(regEx, '')
|
51
|
+
}
|
52
|
+
},
|
53
|
+
|
54
|
+
add: function(element) {
|
55
|
+
element = $(element);
|
56
|
+
for(var i = 1; i < arguments.length; i++) {
|
57
|
+
Element.Class.remove(element, arguments[i]);
|
58
|
+
element.className += (element.className.length > 0 ? ' ' : '') + arguments[i];
|
59
|
+
}
|
60
|
+
},
|
61
|
+
|
62
|
+
// returns true if all given classes exist in said element
|
63
|
+
has: function(element) {
|
64
|
+
element = $(element);
|
65
|
+
if(!element || !element.className) return false;
|
66
|
+
var regEx;
|
67
|
+
for(var i = 1; i < arguments.length; i++) {
|
68
|
+
regEx = new RegExp("\\b" + arguments[i] + "\\b");
|
69
|
+
if(!regEx.test(element.className)) return false;
|
70
|
+
}
|
71
|
+
return true;
|
72
|
+
},
|
73
|
+
|
74
|
+
// expects arrays of strings and/or strings as optional paramters
|
75
|
+
// Element.Class.has_any(element, ['classA','classB','classC'], 'classD')
|
76
|
+
has_any: function(element) {
|
77
|
+
element = $(element);
|
78
|
+
if(!element || !element.className) return false;
|
79
|
+
var regEx;
|
80
|
+
for(var i = 1; i < arguments.length; i++) {
|
81
|
+
if((typeof arguments[i] == 'object') &&
|
82
|
+
(arguments[i].constructor == Array)) {
|
83
|
+
for(var j = 0; j < arguments[i].length; j++) {
|
84
|
+
regEx = new RegExp("\\b" + arguments[i][j] + "\\b");
|
85
|
+
if(regEx.test(element.className)) return true;
|
86
|
+
}
|
87
|
+
} else {
|
88
|
+
regEx = new RegExp("\\b" + arguments[i] + "\\b");
|
89
|
+
if(regEx.test(element.className)) return true;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
return false;
|
93
|
+
},
|
94
|
+
|
95
|
+
childrenWith: function(element, className) {
|
96
|
+
var children = $(element).getElementsByTagName('*');
|
97
|
+
var elements = new Array();
|
98
|
+
|
99
|
+
for (var i = 0; i < children.length; i++) {
|
100
|
+
if (Element.Class.has(children[i], className)) {
|
101
|
+
elements.push(children[i]);
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
return elements;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
/*--------------------------------------------------------------------------*/
|
111
|
+
|
112
|
+
var Droppables = {
|
113
|
+
drops: false,
|
114
|
+
|
115
|
+
add: function(element) {
|
116
|
+
var element = $(element);
|
117
|
+
var options = {
|
118
|
+
greedy: true,
|
119
|
+
hoverclass: null
|
120
|
+
}.extend(arguments[1] || {});
|
121
|
+
|
122
|
+
// cache containers
|
123
|
+
if(options.containment) {
|
124
|
+
options._containers = new Array();
|
125
|
+
var containment = options.containment;
|
126
|
+
if((typeof containment == 'object') &&
|
127
|
+
(containment.constructor == Array)) {
|
128
|
+
for(var i=0; i<containment.length; i++)
|
129
|
+
options._containers.push($(containment[i]));
|
130
|
+
} else {
|
131
|
+
options._containers.push($(containment));
|
132
|
+
}
|
133
|
+
options._containers_length =
|
134
|
+
options._containers.length-1;
|
135
|
+
}
|
136
|
+
|
137
|
+
if(element.style.position=='') //fix IE
|
138
|
+
element.style.position = 'relative';
|
139
|
+
|
140
|
+
// activate the droppable
|
141
|
+
element.droppable = options;
|
142
|
+
|
143
|
+
if(!this.drops) this.drops = [];
|
144
|
+
this.drops.push(element);
|
145
|
+
},
|
146
|
+
|
147
|
+
is_contained: function(element, drop) {
|
148
|
+
var containers = drop.droppable._containers;
|
149
|
+
var parentNode = element.parentNode;
|
150
|
+
var i = drop.droppable._containers_length;
|
151
|
+
do { if(parentNode==containers[i]) return true; } while (i--);
|
152
|
+
return false;
|
153
|
+
},
|
154
|
+
|
155
|
+
is_affected: function(pX, pY, element, drop) {
|
156
|
+
return (
|
157
|
+
(drop!=element) &&
|
158
|
+
((!drop.droppable._containers) ||
|
159
|
+
this.is_contained(element, drop)) &&
|
160
|
+
((!drop.droppable.accept) ||
|
161
|
+
(Element.Class.has_any(element, drop.droppable.accept))) &&
|
162
|
+
Position.within(drop, pX, pY) );
|
163
|
+
},
|
164
|
+
|
165
|
+
deactivate: function(drop) {
|
166
|
+
Element.Class.remove(drop, drop.droppable.hoverclass);
|
167
|
+
this.last_active = null;
|
168
|
+
},
|
169
|
+
|
170
|
+
activate: function(drop) {
|
171
|
+
if(this.last_active) this.deactivate(this.last_active);
|
172
|
+
if(drop.droppable.hoverclass) {
|
173
|
+
Element.Class.add(drop, drop.droppable.hoverclass);
|
174
|
+
this.last_active = drop;
|
175
|
+
}
|
176
|
+
},
|
177
|
+
|
178
|
+
show: function(event, element) {
|
179
|
+
if(!this.drops) return;
|
180
|
+
var pX = Event.pointerX(event);
|
181
|
+
var pY = Event.pointerY(event);
|
182
|
+
Position.prepare();
|
183
|
+
|
184
|
+
var i = this.drops.length-1; do {
|
185
|
+
var drop = this.drops[i];
|
186
|
+
if(this.is_affected(pX, pY, element, drop)) {
|
187
|
+
if(drop.droppable.onHover)
|
188
|
+
drop.droppable.onHover(
|
189
|
+
element, drop, Position.overlap(drop.droppable.overlap, drop));
|
190
|
+
if(drop.droppable.greedy) {
|
191
|
+
this.activate(drop);
|
192
|
+
return;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
} while (i--);
|
196
|
+
},
|
197
|
+
|
198
|
+
fire: function(event, element) {
|
199
|
+
if(!this.drops) return;
|
200
|
+
var pX = Event.pointerX(event);
|
201
|
+
var pY = Event.pointerY(event);
|
202
|
+
Position.prepare();
|
203
|
+
|
204
|
+
var i = this.drops.length-1; do {
|
205
|
+
var drop = this.drops[i];
|
206
|
+
if(this.is_affected(pX, pY, element, drop))
|
207
|
+
if(drop.droppable.onDrop)
|
208
|
+
drop.droppable.onDrop(element);
|
209
|
+
} while (i--);
|
210
|
+
},
|
211
|
+
|
212
|
+
reset: function() {
|
213
|
+
if(this.last_active)
|
214
|
+
this.deactivate(this.last_active);
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
Draggables = {
|
219
|
+
observers: new Array(),
|
220
|
+
addObserver: function(observer) {
|
221
|
+
this.observers.push(observer);
|
222
|
+
},
|
223
|
+
notify: function(eventName, draggable) { // 'onStart', 'onEnd'
|
224
|
+
for(var i = 0; i < this.observers.length; i++)
|
225
|
+
this.observers[i][eventName](draggable);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
/*--------------------------------------------------------------------------*/
|
230
|
+
|
231
|
+
Draggable = Class.create();
|
232
|
+
Draggable.prototype = {
|
233
|
+
initialize: function(element) {
|
234
|
+
var options = {
|
235
|
+
handle: false,
|
236
|
+
starteffect: function(element) {
|
237
|
+
new Effect.Opacity(element, {duration:0.2, from:1.0, to:0.7});
|
238
|
+
},
|
239
|
+
reverteffect: function(element, top_offset, left_offset) {
|
240
|
+
new Effect.MoveBy(element, -top_offset, -left_offset, {duration:0.4});
|
241
|
+
},
|
242
|
+
endeffect: function(element) {
|
243
|
+
new Effect.Opacity(element, {duration:0.2, from:0.7, to:1.0});
|
244
|
+
},
|
245
|
+
zindex: 1000,
|
246
|
+
revert: false
|
247
|
+
}.extend(arguments[1] || {});
|
248
|
+
|
249
|
+
this.element = $(element);
|
250
|
+
this.element.drag = this;
|
251
|
+
this.handle = options.handle ? $(options.handle) : this.element;
|
252
|
+
|
253
|
+
// fix IE
|
254
|
+
if(!this.element.style.position)
|
255
|
+
this.element.style.position = 'relative';
|
256
|
+
|
257
|
+
this.offsetX = 0;
|
258
|
+
this.offsetY = 0;
|
259
|
+
this.originalLeft = this.currentLeft();
|
260
|
+
this.originalTop = this.currentTop();
|
261
|
+
this.originalX = this.element.offsetLeft;
|
262
|
+
this.originalY = this.element.offsetTop;
|
263
|
+
this.originalZ = parseInt(this.element.style.zIndex || "0");
|
264
|
+
|
265
|
+
this.options = options;
|
266
|
+
|
267
|
+
this.active = false;
|
268
|
+
this.dragging = false;
|
269
|
+
|
270
|
+
Event.observe(this.handle, "mousedown", this.startDrag.bindAsEventListener(this));
|
271
|
+
Event.observe(document, "mouseup", this.endDrag.bindAsEventListener(this));
|
272
|
+
Event.observe(document, "mousemove", this.update.bindAsEventListener(this));
|
273
|
+
},
|
274
|
+
currentLeft: function() {
|
275
|
+
return parseInt(this.element.style.left || '0');
|
276
|
+
},
|
277
|
+
currentTop: function() {
|
278
|
+
return parseInt(this.element.style.top || '0')
|
279
|
+
},
|
280
|
+
startDrag: function(event) {
|
281
|
+
if(Event.isLeftClick(event)) {
|
282
|
+
this.active = true;
|
283
|
+
|
284
|
+
var style = this.element.style;
|
285
|
+
this.originalY = this.element.offsetTop - this.currentTop() - this.originalTop;
|
286
|
+
this.originalX = this.element.offsetLeft - this.currentLeft() - this.originalLeft;
|
287
|
+
this.offsetY = event.clientY - this.originalY - this.originalTop;
|
288
|
+
this.offsetX = event.clientX - this.originalX - this.originalLeft;
|
289
|
+
|
290
|
+
Event.stop(event);
|
291
|
+
}
|
292
|
+
},
|
293
|
+
endDrag: function(event) {
|
294
|
+
if(this.active && this.dragging) {
|
295
|
+
this.active = false;
|
296
|
+
this.dragging = false;
|
297
|
+
|
298
|
+
Droppables.fire(event, this.element);
|
299
|
+
Draggables.notify('onEnd', this);
|
300
|
+
|
301
|
+
var revert = this.options.revert;
|
302
|
+
if(revert && typeof revert == 'function') revert = revert(this.element);
|
303
|
+
|
304
|
+
if(revert && this.options.reverteffect) {
|
305
|
+
this.options.reverteffect(this.element,
|
306
|
+
this.currentTop()-this.originalTop,
|
307
|
+
this.currentLeft()-this.originalLeft);
|
308
|
+
} else {
|
309
|
+
this.originalLeft = this.currentLeft();
|
310
|
+
this.originalTop = this.currentTop();
|
311
|
+
}
|
312
|
+
this.element.style.zIndex = this.originalZ;
|
313
|
+
|
314
|
+
if(this.options.endeffect)
|
315
|
+
this.options.endeffect(this.element);
|
316
|
+
|
317
|
+
Droppables.reset();
|
318
|
+
Event.stop(event);
|
319
|
+
}
|
320
|
+
this.active = false;
|
321
|
+
this.dragging = false;
|
322
|
+
},
|
323
|
+
draw: function(event) {
|
324
|
+
var style = this.element.style;
|
325
|
+
this.originalX = this.element.offsetLeft - this.currentLeft() - this.originalLeft;
|
326
|
+
this.originalY = this.element.offsetTop - this.currentTop() - this.originalTop;
|
327
|
+
if((!this.options.constraint) || (this.options.constraint=='horizontal'))
|
328
|
+
style.left = ((event.clientX - this.originalX) - this.offsetX) + "px";
|
329
|
+
if((!this.options.constraint) || (this.options.constraint=='vertical'))
|
330
|
+
style.top = ((event.clientY - this.originalY) - this.offsetY) + "px";
|
331
|
+
if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
|
332
|
+
},
|
333
|
+
update: function(event) {
|
334
|
+
if(this.active) {
|
335
|
+
if(!this.dragging) {
|
336
|
+
var style = this.element.style;
|
337
|
+
this.dragging = true;
|
338
|
+
if(style.position=="") style.position = "relative";
|
339
|
+
style.zIndex = this.options.zindex;
|
340
|
+
Draggables.notify('onStart', this);
|
341
|
+
if(this.options.starteffect) this.options.starteffect(this.element);
|
342
|
+
}
|
343
|
+
|
344
|
+
Droppables.show(event, this.element);
|
345
|
+
this.draw(event);
|
346
|
+
if(this.options.change) this.options.change(this);
|
347
|
+
|
348
|
+
// fix AppleWebKit rendering
|
349
|
+
if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
|
350
|
+
|
351
|
+
Event.stop(event);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
/*--------------------------------------------------------------------------*/
|
357
|
+
|
358
|
+
SortableObserver = Class.create();
|
359
|
+
SortableObserver.prototype = {
|
360
|
+
initialize: function(element, observer) {
|
361
|
+
this.element = $(element);
|
362
|
+
this.observer = observer;
|
363
|
+
this.lastValue = Sortable.serialize(this.element);
|
364
|
+
},
|
365
|
+
onStart: function() {
|
366
|
+
this.lastValue = Sortable.serialize(this.element);
|
367
|
+
},
|
368
|
+
onEnd: function() {
|
369
|
+
if(this.lastValue != Sortable.serialize(this.element))
|
370
|
+
this.observer(this.element)
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
Sortable = {
|
375
|
+
create: function(element) {
|
376
|
+
var element = $(element);
|
377
|
+
var options = {
|
378
|
+
tag: 'li', // assumes li children, override with tag: 'tagname'
|
379
|
+
overlap: 'vertical', // one of 'vertical', 'horizontal'
|
380
|
+
constraint: 'vertical', // one of 'vertical', 'horizontal', false
|
381
|
+
containment: element, // also takes array of elements (or id's); or false
|
382
|
+
handle: false, // or a CSS class
|
383
|
+
only: false,
|
384
|
+
hoverclass: null,
|
385
|
+
onChange: function() {},
|
386
|
+
onUpdate: function() {}
|
387
|
+
}.extend(arguments[1] || {});
|
388
|
+
element.sortable = options;
|
389
|
+
|
390
|
+
// build options for the draggables
|
391
|
+
var options_for_draggable = {
|
392
|
+
revert: true,
|
393
|
+
constraint: options.constraint,
|
394
|
+
handle: handle };
|
395
|
+
if(options.starteffect)
|
396
|
+
options_for_draggable.starteffect = options.starteffect;
|
397
|
+
if(options.reverteffect)
|
398
|
+
options_for_draggable.reverteffect = options.reverteffect;
|
399
|
+
if(options.endeffect)
|
400
|
+
options_for_draggable.endeffect = options.endeffect;
|
401
|
+
if(options.zindex)
|
402
|
+
options_for_draggable.zindex = options.zindex;
|
403
|
+
|
404
|
+
// build options for the droppables
|
405
|
+
var options_for_droppable = {
|
406
|
+
overlap: options.overlap,
|
407
|
+
containment: options.containment,
|
408
|
+
hoverclass: options.hoverclass,
|
409
|
+
onHover: function(element, dropon, overlap) {
|
410
|
+
if(overlap>0.5) {
|
411
|
+
if(dropon.previousSibling != element) {
|
412
|
+
var oldParentNode = element.parentNode;
|
413
|
+
element.style.visibility = "hidden"; // fix gecko rendering
|
414
|
+
dropon.parentNode.insertBefore(element, dropon);
|
415
|
+
if(dropon.parentNode!=oldParentNode && oldParentNode.sortable)
|
416
|
+
oldParentNode.sortable.onChange(element);
|
417
|
+
if(dropon.parentNode.sortable)
|
418
|
+
dropon.parentNode.sortable.onChange(element);
|
419
|
+
}
|
420
|
+
} else {
|
421
|
+
var nextElement = dropon.nextSibling || null;
|
422
|
+
if(nextElement != element) {
|
423
|
+
var oldParentNode = element.parentNode;
|
424
|
+
element.style.visibility = "hidden"; // fix gecko rendering
|
425
|
+
dropon.parentNode.insertBefore(element, nextElement);
|
426
|
+
if(dropon.parentNode!=oldParentNode && oldParentNode.sortable)
|
427
|
+
oldParentNode.sortable.onChange(element);
|
428
|
+
if(dropon.parentNode.sortable)
|
429
|
+
dropon.parentNode.sortable.onChange(element);
|
430
|
+
}
|
431
|
+
}
|
432
|
+
}
|
433
|
+
}
|
434
|
+
|
435
|
+
// fix for gecko engine
|
436
|
+
Element.cleanWhitespace(element);
|
437
|
+
|
438
|
+
// for onupdate
|
439
|
+
Draggables.addObserver(new SortableObserver(element, options.onUpdate));
|
440
|
+
|
441
|
+
// make it so
|
442
|
+
var elements = element.childNodes;
|
443
|
+
for (var i = 0; i < elements.length; i++)
|
444
|
+
if(elements[i].tagName && elements[i].tagName==options.tag.toUpperCase() &&
|
445
|
+
(!options.only || (Element.Class.has(elements[i], options.only)))) {
|
446
|
+
|
447
|
+
// handles are per-draggable
|
448
|
+
var handle = options.handle ?
|
449
|
+
Element.Class.childrenWith(elements[i], options.handle)[0] : elements[i];
|
450
|
+
|
451
|
+
new Draggable(elements[i], options_for_draggable.extend({ handle: handle }));
|
452
|
+
Droppables.add(elements[i], options_for_droppable);
|
453
|
+
}
|
454
|
+
|
455
|
+
},
|
456
|
+
serialize: function(element) {
|
457
|
+
var element = $(element);
|
458
|
+
var options = {
|
459
|
+
tag: element.sortable.tag,
|
460
|
+
only: element.sortable.only,
|
461
|
+
name: element.id
|
462
|
+
}.extend(arguments[1] || {});
|
463
|
+
|
464
|
+
var items = $(element).childNodes;
|
465
|
+
var queryComponents = new Array();
|
466
|
+
|
467
|
+
for(var i=0; i<items.length; i++)
|
468
|
+
if(items[i].tagName && items[i].tagName==options.tag.toUpperCase() &&
|
469
|
+
(!options.only || (Element.Class.has(items[i], options.only))))
|
470
|
+
queryComponents.push(
|
471
|
+
encodeURIComponent(options.name) + "[]=" +
|
472
|
+
encodeURIComponent(items[i].id.split("_")[1]));
|
473
|
+
|
474
|
+
return queryComponents.join("&");
|
475
|
+
}
|
476
|
+
}
|