cells 3.8.6 → 3.8.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,118 +0,0 @@
1
- document.observe("dom:loaded", function() {
2
- function handleRemote(element) {
3
- var method, url, params;
4
-
5
- if (element.tagName.toLowerCase() === 'form') {
6
- method = element.readAttribute('method') || 'post';
7
- url = element.readAttribute('action');
8
- params = element.serialize(true);
9
- } else {
10
- method = element.readAttribute('data-method') || 'get';
11
- url = element.readAttribute('href');
12
- params = {};
13
- }
14
-
15
- var event = element.fire("ajax:before");
16
- if (event.stopped) return false;
17
-
18
- new Ajax.Request(url, {
19
- method: method,
20
- parameters: params,
21
- asynchronous: true,
22
- evalScripts: true,
23
-
24
- onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
25
- onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
26
- onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
27
- onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
28
- onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
29
- onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
30
- });
31
-
32
- element.fire("ajax:after");
33
- }
34
-
35
- function handleMethod(element) {
36
- var method, url, token_name, token;
37
-
38
- method = element.readAttribute('data-method');
39
- url = element.readAttribute('href');
40
- csrf_param = $$('meta[name=csrf-param]').first();
41
- csrf_token = $$('meta[name=csrf-token]').first();
42
-
43
- var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
44
- element.parentNode.appendChild(form);
45
-
46
- if (method != 'post') {
47
- var field = new Element('input', { type: 'hidden', name: '_method', value: method });
48
- form.appendChild(field);
49
- }
50
-
51
- if (csrf_param) {
52
- var param = csrf_param.readAttribute('content');
53
- var token = csrf_token.readAttribute('content');
54
- var field = new Element('input', { type: 'hidden', name: param, value: token });
55
- form.appendChild(field);
56
- }
57
-
58
- form.submit();
59
- }
60
-
61
- $(document.body).observe("click", function(event) {
62
- var message = event.findElement().readAttribute('data-confirm');
63
- if (message && !confirm(message)) {
64
- event.stop();
65
- return false;
66
- }
67
-
68
- var element = event.findElement("a[data-remote]");
69
- if (element) {
70
- handleRemote(element);
71
- event.stop();
72
- return true;
73
- }
74
-
75
- var element = event.findElement("a[data-method]");
76
- if (element) {
77
- handleMethod(element);
78
- event.stop();
79
- return true;
80
- }
81
- });
82
-
83
- // TODO: I don't think submit bubbles in IE
84
- $(document.body).observe("submit", function(event) {
85
- var element = event.findElement(),
86
- message = element.readAttribute('data-confirm');
87
- if (message && !confirm(message)) {
88
- event.stop();
89
- return false;
90
- }
91
-
92
- var inputs = element.select("input[type=submit][data-disable-with]");
93
- inputs.each(function(input) {
94
- input.disabled = true;
95
- input.writeAttribute('data-original-value', input.value);
96
- input.value = input.readAttribute('data-disable-with');
97
- });
98
-
99
- var element = event.findElement("form[data-remote]");
100
- if (element) {
101
- handleRemote(element);
102
- event.stop();
103
- }
104
- });
105
-
106
- $(document.body).observe("ajax:after", function(event) {
107
- var element = event.findElement();
108
-
109
- if (element.tagName.toLowerCase() === 'form') {
110
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
111
- inputs.each(function(input) {
112
- input.value = input.readAttribute('data-original-value');
113
- input.writeAttribute('data-original-value', null);
114
- input.disabled = false;
115
- });
116
- }
117
- });
118
- });