admin_data 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/app/controllers/admin_data/public_controller.rb +14 -5
- data/lib/admin_data/version.rb +1 -1
- data/lib/admin_data.rb +1 -1
- metadata +3 -32
- data/lib/public/images/add.png +0 -0
- data/lib/public/images/no.png +0 -0
- data/lib/public/images/site.png +0 -0
- data/lib/public/javascripts/advance_search/act_on_result.js +0 -45
- data/lib/public/javascripts/advance_search/advance_search.js +0 -83
- data/lib/public/javascripts/advance_search/advance_search_structure.js +0 -79
- data/lib/public/javascripts/advance_search/ajaxify_advance_search.js +0 -28
- data/lib/public/javascripts/advance_search/build_first_row.js +0 -8
- data/lib/public/javascripts/advance_search/event_bindings.js +0 -76
- data/lib/public/javascripts/advance_search/global_ajax_setting.js +0 -10
- data/lib/public/javascripts/advance_search/trigger_submit_on_domready.js +0 -6
- data/lib/public/javascripts/misc/drop_down_change.js +0 -8
- data/lib/public/javascripts/misc/js_util.js +0 -58
- data/lib/public/javascripts/misc/quick_search_input_focus.js +0 -6
- data/lib/public/javascripts/test/act_on_result.js +0 -120
- data/lib/public/javascripts/test/advance_search.js +0 -80
- data/lib/public/javascripts/test/ajaxify_advance_search.js +0 -29
- data/lib/public/javascripts/test/build_first_row.js +0 -10
- data/lib/public/javascripts/test/event_bindings.js +0 -100
- data/lib/public/javascripts/vendor/jack.js +0 -903
- data/lib/public/javascripts/vendor/jquery-1.4.2.js +0 -6240
- data/lib/public/javascripts/vendor/jquery-ui-1.7.2.custom.min.js +0 -298
- data/lib/public/javascripts/vendor/jquery.ba-isjquery.js +0 -21
- data/lib/public/javascripts/vendor/jquery_form.js +0 -814
- data/lib/public/javascripts/vendor/log.js +0 -9
- data/lib/public/javascripts/vendor/qunit.js +0 -1043
- data/lib/public/javascripts/vendor/rails.js +0 -132
- data/lib/public/stylesheets/base.css +0 -1109
- data/lib/public/stylesheets/vendor/jquery-ui-1.7.2.custom.css +0 -406
@@ -1,814 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
*
|
3
|
-
* jQuery Form Plugin
|
4
|
-
* @requires jQuery v1.1 or later
|
5
|
-
*
|
6
|
-
* Examples at: http://malsup.com/jquery/form/
|
7
|
-
* Dual licensed under the MIT and GPL licenses:
|
8
|
-
* http://www.opensource.org/licenses/mit-license.php
|
9
|
-
* http://www.gnu.org/licenses/gpl.html
|
10
|
-
*
|
11
|
-
* Revision: $Id: jquery.form.js 2884 2007-08-24 23:13:55Z malsup $
|
12
|
-
*/
|
13
|
-
(function($) {
|
14
|
-
/**
|
15
|
-
* ajaxSubmit() provides a mechanism for submitting an HTML form using AJAX.
|
16
|
-
*
|
17
|
-
* ajaxSubmit accepts a single argument which can be either a success callback function
|
18
|
-
* or an options Object. If a function is provided it will be invoked upon successful
|
19
|
-
* completion of the submit and will be passed the response from the server.
|
20
|
-
* If an options Object is provided, the following attributes are supported:
|
21
|
-
*
|
22
|
-
* target: Identifies the element(s) in the page to be updated with the server response.
|
23
|
-
* This value may be specified as a jQuery selection string, a jQuery object,
|
24
|
-
* or a DOM element.
|
25
|
-
* default value: null
|
26
|
-
*
|
27
|
-
* url: URL to which the form data will be submitted.
|
28
|
-
* default value: value of form's 'action' attribute
|
29
|
-
*
|
30
|
-
* type: The method in which the form data should be submitted, 'GET' or 'POST'.
|
31
|
-
* default value: value of form's 'method' attribute (or 'GET' if none found)
|
32
|
-
*
|
33
|
-
* beforeSubmit: Callback method to be invoked before the form is submitted.
|
34
|
-
* default value: null
|
35
|
-
*
|
36
|
-
* success: Callback method to be invoked after the form has been successfully submitted
|
37
|
-
* and the response has been returned from the server
|
38
|
-
* default value: null
|
39
|
-
*
|
40
|
-
* dataType: Expected dataType of the response. One of: null, 'xml', 'script', or 'json'
|
41
|
-
* default value: null
|
42
|
-
*
|
43
|
-
* semantic: Boolean flag indicating whether data must be submitted in semantic order (slower).
|
44
|
-
* default value: false
|
45
|
-
*
|
46
|
-
* resetForm: Boolean flag indicating whether the form should be reset if the submit is successful
|
47
|
-
*
|
48
|
-
* clearForm: Boolean flag indicating whether the form should be cleared if the submit is successful
|
49
|
-
*
|
50
|
-
*
|
51
|
-
* The 'beforeSubmit' callback can be provided as a hook for running pre-submit logic or for
|
52
|
-
* validating the form data. If the 'beforeSubmit' callback returns false then the form will
|
53
|
-
* not be submitted. The 'beforeSubmit' callback is invoked with three arguments: the form data
|
54
|
-
* in array format, the jQuery object, and the options object passed into ajaxSubmit.
|
55
|
-
* The form data array takes the following form:
|
56
|
-
*
|
57
|
-
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
58
|
-
*
|
59
|
-
* If a 'success' callback method is provided it is invoked after the response has been returned
|
60
|
-
* from the server. It is passed the responseText or responseXML value (depending on dataType).
|
61
|
-
* See jQuery.ajax for further details.
|
62
|
-
*
|
63
|
-
*
|
64
|
-
* The dataType option provides a means for specifying how the server response should be handled.
|
65
|
-
* This maps directly to the jQuery.httpData method. The following values are supported:
|
66
|
-
*
|
67
|
-
* 'xml': if dataType == 'xml' the server response is treated as XML and the 'success'
|
68
|
-
* callback method, if specified, will be passed the responseXML value
|
69
|
-
* 'json': if dataType == 'json' the server response will be evaluted and passed to
|
70
|
-
* the 'success' callback, if specified
|
71
|
-
* 'script': if dataType == 'script' the server response is evaluated in the global context
|
72
|
-
*
|
73
|
-
*
|
74
|
-
* Note that it does not make sense to use both the 'target' and 'dataType' options. If both
|
75
|
-
* are provided the target will be ignored.
|
76
|
-
*
|
77
|
-
* The semantic argument can be used to force form serialization in semantic order.
|
78
|
-
* This is normally true anyway, unless the form contains input elements of type='image'.
|
79
|
-
* If your form must be submitted with name/value pairs in semantic order and your form
|
80
|
-
* contains an input of type='image" then pass true for this arg, otherwise pass false
|
81
|
-
* (or nothing) to avoid the overhead for this logic.
|
82
|
-
*
|
83
|
-
*
|
84
|
-
* When used on its own, ajaxSubmit() is typically bound to a form's submit event like this:
|
85
|
-
*
|
86
|
-
* $("#form-id").submit(function() {
|
87
|
-
* $(this).ajaxSubmit(options);
|
88
|
-
* return false; // cancel conventional submit
|
89
|
-
* });
|
90
|
-
*
|
91
|
-
* When using ajaxForm(), however, this is done for you.
|
92
|
-
*
|
93
|
-
* @example
|
94
|
-
* $('#myForm').ajaxSubmit(function(data) {
|
95
|
-
* alert('Form submit succeeded! Server returned: ' + data);
|
96
|
-
* });
|
97
|
-
* @desc Submit form and alert server response
|
98
|
-
*
|
99
|
-
*
|
100
|
-
* @example
|
101
|
-
* var options = {
|
102
|
-
* target: '#myTargetDiv'
|
103
|
-
* };
|
104
|
-
* $('#myForm').ajaxSubmit(options);
|
105
|
-
* @desc Submit form and update page element with server response
|
106
|
-
*
|
107
|
-
*
|
108
|
-
* @example
|
109
|
-
* var options = {
|
110
|
-
* success: function(responseText) {
|
111
|
-
* alert(responseText);
|
112
|
-
* }
|
113
|
-
* };
|
114
|
-
* $('#myForm').ajaxSubmit(options);
|
115
|
-
* @desc Submit form and alert the server response
|
116
|
-
*
|
117
|
-
*
|
118
|
-
* @example
|
119
|
-
* var options = {
|
120
|
-
* beforeSubmit: function(formArray, jqForm) {
|
121
|
-
* if (formArray.length == 0) {
|
122
|
-
* alert('Please enter data.');
|
123
|
-
* return false;
|
124
|
-
* }
|
125
|
-
* }
|
126
|
-
* };
|
127
|
-
* $('#myForm').ajaxSubmit(options);
|
128
|
-
* @desc Pre-submit validation which aborts the submit operation if form data is empty
|
129
|
-
*
|
130
|
-
*
|
131
|
-
* @example
|
132
|
-
* var options = {
|
133
|
-
* url: myJsonUrl.php,
|
134
|
-
* dataType: 'json',
|
135
|
-
* success: function(data) {
|
136
|
-
* // 'data' is an object representing the the evaluated json data
|
137
|
-
* }
|
138
|
-
* };
|
139
|
-
* $('#myForm').ajaxSubmit(options);
|
140
|
-
* @desc json data returned and evaluated
|
141
|
-
*
|
142
|
-
*
|
143
|
-
* @example
|
144
|
-
* var options = {
|
145
|
-
* url: myXmlUrl.php,
|
146
|
-
* dataType: 'xml',
|
147
|
-
* success: function(responseXML) {
|
148
|
-
* // responseXML is XML document object
|
149
|
-
* var data = $('myElement', responseXML).text();
|
150
|
-
* }
|
151
|
-
* };
|
152
|
-
* $('#myForm').ajaxSubmit(options);
|
153
|
-
* @desc XML data returned from server
|
154
|
-
*
|
155
|
-
*
|
156
|
-
* @example
|
157
|
-
* var options = {
|
158
|
-
* resetForm: true
|
159
|
-
* };
|
160
|
-
* $('#myForm').ajaxSubmit(options);
|
161
|
-
* @desc submit form and reset it if successful
|
162
|
-
*
|
163
|
-
* @example
|
164
|
-
* $('#myForm).submit(function() {
|
165
|
-
* $(this).ajaxSubmit();
|
166
|
-
* return false;
|
167
|
-
* });
|
168
|
-
* @desc Bind form's submit event to use ajaxSubmit
|
169
|
-
*
|
170
|
-
*
|
171
|
-
* @name ajaxSubmit
|
172
|
-
* @type jQuery
|
173
|
-
* @param options object literal containing options which control the form submission process
|
174
|
-
* @cat Plugins/Form
|
175
|
-
* @return jQuery
|
176
|
-
*/
|
177
|
-
$.fn.ajaxSubmit = function(options) {
|
178
|
-
if (typeof options == 'function')
|
179
|
-
options = { success: options };
|
180
|
-
|
181
|
-
options = $.extend({
|
182
|
-
url: this.attr('action') || window.location,
|
183
|
-
type: this.attr('method') || 'GET'
|
184
|
-
}, options || {});
|
185
|
-
|
186
|
-
// hook for manipulating the form data before it is extracted;
|
187
|
-
// convenient for use with rich editors like tinyMCE or FCKEditor
|
188
|
-
var veto = {};
|
189
|
-
$.event.trigger('form.pre.serialize', [this, options, veto]);
|
190
|
-
if (veto.veto) return this;
|
191
|
-
|
192
|
-
var a = this.formToArray(options.semantic);
|
193
|
-
|
194
|
-
// give pre-submit callback an opportunity to abort the submit
|
195
|
-
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) return this;
|
196
|
-
|
197
|
-
// fire vetoable 'validate' event
|
198
|
-
$.event.trigger('form.submit.validate', [a, this, options, veto]);
|
199
|
-
if (veto.veto) return this;
|
200
|
-
|
201
|
-
var q = $.param(a);//.replace(/%20/g,'+');
|
202
|
-
|
203
|
-
if (options.type.toUpperCase() == 'GET') {
|
204
|
-
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
|
205
|
-
options.data = null; // data is null for 'get'
|
206
|
-
}
|
207
|
-
else
|
208
|
-
options.data = q; // data is the query string for 'post'
|
209
|
-
|
210
|
-
var $form = this, callbacks = [];
|
211
|
-
if (options.resetForm) callbacks.push(function() { $form.resetForm(); });
|
212
|
-
if (options.clearForm) callbacks.push(function() { $form.clearForm(); });
|
213
|
-
|
214
|
-
// perform a load on the target only if dataType is not provided
|
215
|
-
if (!options.dataType && options.target) {
|
216
|
-
var oldSuccess = options.success || function(){};
|
217
|
-
callbacks.push(function(data) {
|
218
|
-
if (this.evalScripts)
|
219
|
-
$(options.target).attr("innerHTML", data).evalScripts().each(oldSuccess, arguments);
|
220
|
-
else // jQuery v1.1.4
|
221
|
-
$(options.target).html(data).each(oldSuccess, arguments);
|
222
|
-
});
|
223
|
-
}
|
224
|
-
else if (options.success)
|
225
|
-
callbacks.push(options.success);
|
226
|
-
|
227
|
-
options.success = function(data, status) {
|
228
|
-
for (var i=0, max=callbacks.length; i < max; i++)
|
229
|
-
callbacks[i](data, status, $form);
|
230
|
-
};
|
231
|
-
|
232
|
-
// are there files to upload?
|
233
|
-
var files = $('input:file', this).fieldValue();
|
234
|
-
var found = false;
|
235
|
-
for (var j=0; j < files.length; j++)
|
236
|
-
if (files[j])
|
237
|
-
found = true;
|
238
|
-
|
239
|
-
if (options.iframe || found) // options.iframe allows user to force iframe mode
|
240
|
-
fileUpload();
|
241
|
-
else
|
242
|
-
$.ajax(options);
|
243
|
-
|
244
|
-
// fire 'notify' event
|
245
|
-
$.event.trigger('form.submit.notify', [this, options]);
|
246
|
-
return this;
|
247
|
-
|
248
|
-
|
249
|
-
// private function for handling file uploads (hat tip to YAHOO!)
|
250
|
-
function fileUpload() {
|
251
|
-
var form = $form[0];
|
252
|
-
var opts = $.extend({}, $.ajaxSettings, options);
|
253
|
-
|
254
|
-
var id = 'jqFormIO' + $.fn.ajaxSubmit.counter++;
|
255
|
-
var $io = $('<iframe id="' + id + '" name="' + id + '" />');
|
256
|
-
var io = $io[0];
|
257
|
-
var op8 = $.browser.opera && window.opera.version() < 9;
|
258
|
-
if ($.browser.msie || op8) io.src = 'javascript:false;document.write("");';
|
259
|
-
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
260
|
-
|
261
|
-
var xhr = { // mock object
|
262
|
-
responseText: null,
|
263
|
-
responseXML: null,
|
264
|
-
status: 0,
|
265
|
-
statusText: 'n/a',
|
266
|
-
getAllResponseHeaders: function() {},
|
267
|
-
getResponseHeader: function() {},
|
268
|
-
setRequestHeader: function() {}
|
269
|
-
};
|
270
|
-
|
271
|
-
var g = opts.global;
|
272
|
-
// trigger ajax global events so that activity/block indicators work like normal
|
273
|
-
if (g && ! $.active++) $.event.trigger("ajaxStart");
|
274
|
-
if (g) $.event.trigger("ajaxSend", [xhr, opts]);
|
275
|
-
|
276
|
-
var cbInvoked = 0;
|
277
|
-
var timedOut = 0;
|
278
|
-
|
279
|
-
// take a breath so that pending repaints get some cpu time before the upload starts
|
280
|
-
setTimeout(function() {
|
281
|
-
$io.appendTo('body');
|
282
|
-
// jQuery's event binding doesn't work for iframe events in IE
|
283
|
-
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
|
284
|
-
|
285
|
-
// make sure form attrs are set
|
286
|
-
var encAttr = form.encoding ? 'encoding' : 'enctype';
|
287
|
-
var t = $form.attr('target');
|
288
|
-
$form.attr({
|
289
|
-
target: id,
|
290
|
-
method: 'POST',
|
291
|
-
action: opts.url
|
292
|
-
});
|
293
|
-
form[encAttr] = 'multipart/form-data';
|
294
|
-
|
295
|
-
// support timout
|
296
|
-
if (opts.timeout)
|
297
|
-
setTimeout(function() { timedOut = true; cb(); }, opts.timeout);
|
298
|
-
|
299
|
-
form.submit();
|
300
|
-
$form.attr('target', t); // reset target
|
301
|
-
}, 10);
|
302
|
-
|
303
|
-
function cb() {
|
304
|
-
if (cbInvoked++) return;
|
305
|
-
|
306
|
-
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
|
307
|
-
|
308
|
-
var ok = true;
|
309
|
-
try {
|
310
|
-
if (timedOut) throw 'timeout';
|
311
|
-
// extract the server response from the iframe
|
312
|
-
var data, doc;
|
313
|
-
doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
|
314
|
-
xhr.responseText = doc.body ? doc.body.innerHTML : null;
|
315
|
-
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
316
|
-
|
317
|
-
if (opts.dataType == 'json' || opts.dataType == 'script') {
|
318
|
-
var ta = doc.getElementsByTagName('textarea')[0];
|
319
|
-
data = ta ? ta.value : xhr.responseText;
|
320
|
-
if (opts.dataType == 'json')
|
321
|
-
eval("data = " + data);
|
322
|
-
else
|
323
|
-
$.globalEval(data);
|
324
|
-
}
|
325
|
-
else if (opts.dataType == 'xml') {
|
326
|
-
data = xhr.responseXML;
|
327
|
-
if (!data && xhr.responseText != null)
|
328
|
-
data = toXml(xhr.responseText);
|
329
|
-
}
|
330
|
-
else {
|
331
|
-
data = xhr.responseText;
|
332
|
-
}
|
333
|
-
}
|
334
|
-
catch(e){
|
335
|
-
ok = false;
|
336
|
-
$.handleError(opts, xhr, 'error', e);
|
337
|
-
}
|
338
|
-
|
339
|
-
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
340
|
-
if (ok) {
|
341
|
-
opts.success(data, 'success');
|
342
|
-
if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
|
343
|
-
}
|
344
|
-
if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
|
345
|
-
if (g && ! --$.active) $.event.trigger("ajaxStop");
|
346
|
-
if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
|
347
|
-
|
348
|
-
// clean up
|
349
|
-
setTimeout(function() {
|
350
|
-
$io.remove();
|
351
|
-
xhr.responseXML = null;
|
352
|
-
}, 100);
|
353
|
-
};
|
354
|
-
|
355
|
-
function toXml(s, doc) {
|
356
|
-
if (window.ActiveXObject) {
|
357
|
-
doc = new ActiveXObject('Microsoft.XMLDOM');
|
358
|
-
doc.async = 'false';
|
359
|
-
doc.loadXML(s);
|
360
|
-
}
|
361
|
-
else
|
362
|
-
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
363
|
-
return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
|
364
|
-
};
|
365
|
-
};
|
366
|
-
};
|
367
|
-
$.fn.ajaxSubmit.counter = 0; // used to create unique iframe ids
|
368
|
-
|
369
|
-
/**
|
370
|
-
* ajaxForm() provides a mechanism for fully automating form submission.
|
371
|
-
*
|
372
|
-
* The advantages of using this method instead of ajaxSubmit() are:
|
373
|
-
*
|
374
|
-
* 1: This method will include coordinates for <input type="image" /> elements (if the element
|
375
|
-
* is used to submit the form).
|
376
|
-
* 2. This method will include the submit element's name/value data (for the element that was
|
377
|
-
* used to submit the form).
|
378
|
-
* 3. This method binds the submit() method to the form for you.
|
379
|
-
*
|
380
|
-
* Note that for accurate x/y coordinates of image submit elements in all browsers
|
381
|
-
* you need to also use the "dimensions" plugin (this method will auto-detect its presence).
|
382
|
-
*
|
383
|
-
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
|
384
|
-
* passes the options argument along after properly binding events for submit elements and
|
385
|
-
* the form itself. See ajaxSubmit for a full description of the options argument.
|
386
|
-
*
|
387
|
-
*
|
388
|
-
* @example
|
389
|
-
* var options = {
|
390
|
-
* target: '#myTargetDiv'
|
391
|
-
* };
|
392
|
-
* $('#myForm').ajaxSForm(options);
|
393
|
-
* @desc Bind form's submit event so that 'myTargetDiv' is updated with the server response
|
394
|
-
* when the form is submitted.
|
395
|
-
*
|
396
|
-
*
|
397
|
-
* @example
|
398
|
-
* var options = {
|
399
|
-
* success: function(responseText) {
|
400
|
-
* alert(responseText);
|
401
|
-
* }
|
402
|
-
* };
|
403
|
-
* $('#myForm').ajaxSubmit(options);
|
404
|
-
* @desc Bind form's submit event so that server response is alerted after the form is submitted.
|
405
|
-
*
|
406
|
-
*
|
407
|
-
* @example
|
408
|
-
* var options = {
|
409
|
-
* beforeSubmit: function(formArray, jqForm) {
|
410
|
-
* if (formArray.length == 0) {
|
411
|
-
* alert('Please enter data.');
|
412
|
-
* return false;
|
413
|
-
* }
|
414
|
-
* }
|
415
|
-
* };
|
416
|
-
* $('#myForm').ajaxSubmit(options);
|
417
|
-
* @desc Bind form's submit event so that pre-submit callback is invoked before the form
|
418
|
-
* is submitted.
|
419
|
-
*
|
420
|
-
*
|
421
|
-
* @name ajaxForm
|
422
|
-
* @param options object literal containing options which control the form submission process
|
423
|
-
* @return jQuery
|
424
|
-
* @cat Plugins/Form
|
425
|
-
* @type jQuery
|
426
|
-
*/
|
427
|
-
$.fn.ajaxForm = function(options) {
|
428
|
-
return this.ajaxFormUnbind().submit(submitHandler).each(function() {
|
429
|
-
// store options in hash
|
430
|
-
this.formPluginId = $.fn.ajaxForm.counter++;
|
431
|
-
$.fn.ajaxForm.optionHash[this.formPluginId] = options;
|
432
|
-
$(":submit,input:image", this).click(clickHandler);
|
433
|
-
});
|
434
|
-
};
|
435
|
-
|
436
|
-
$.fn.ajaxForm.counter = 1;
|
437
|
-
$.fn.ajaxForm.optionHash = {};
|
438
|
-
|
439
|
-
function clickHandler(e) {
|
440
|
-
var $form = this.form;
|
441
|
-
$form.clk = this;
|
442
|
-
if (this.type == 'image') {
|
443
|
-
if (e.offsetX != undefined) {
|
444
|
-
$form.clk_x = e.offsetX;
|
445
|
-
$form.clk_y = e.offsetY;
|
446
|
-
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
|
447
|
-
var offset = $(this).offset();
|
448
|
-
$form.clk_x = e.pageX - offset.left;
|
449
|
-
$form.clk_y = e.pageY - offset.top;
|
450
|
-
} else {
|
451
|
-
$form.clk_x = e.pageX - this.offsetLeft;
|
452
|
-
$form.clk_y = e.pageY - this.offsetTop;
|
453
|
-
}
|
454
|
-
}
|
455
|
-
// clear form vars
|
456
|
-
setTimeout(function() { $form.clk = $form.clk_x = $form.clk_y = null; }, 10);
|
457
|
-
};
|
458
|
-
|
459
|
-
function submitHandler() {
|
460
|
-
// retrieve options from hash
|
461
|
-
var id = this.formPluginId;
|
462
|
-
var options = $.fn.ajaxForm.optionHash[id];
|
463
|
-
$(this).ajaxSubmit(options);
|
464
|
-
return false;
|
465
|
-
};
|
466
|
-
|
467
|
-
/**
|
468
|
-
* ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
|
469
|
-
*
|
470
|
-
* @name ajaxFormUnbind
|
471
|
-
* @return jQuery
|
472
|
-
* @cat Plugins/Form
|
473
|
-
* @type jQuery
|
474
|
-
*/
|
475
|
-
$.fn.ajaxFormUnbind = function() {
|
476
|
-
this.unbind('submit', submitHandler);
|
477
|
-
return this.each(function() {
|
478
|
-
$(":submit,input:image", this).unbind('click', clickHandler);
|
479
|
-
});
|
480
|
-
|
481
|
-
};
|
482
|
-
|
483
|
-
/**
|
484
|
-
* formToArray() gathers form element data into an array of objects that can
|
485
|
-
* be passed to any of the following ajax functions: $.get, $.post, or load.
|
486
|
-
* Each object in the array has both a 'name' and 'value' property. An example of
|
487
|
-
* an array for a simple login form might be:
|
488
|
-
*
|
489
|
-
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
490
|
-
*
|
491
|
-
* It is this array that is passed to pre-submit callback functions provided to the
|
492
|
-
* ajaxSubmit() and ajaxForm() methods.
|
493
|
-
*
|
494
|
-
* The semantic argument can be used to force form serialization in semantic order.
|
495
|
-
* This is normally true anyway, unless the form contains input elements of type='image'.
|
496
|
-
* If your form must be submitted with name/value pairs in semantic order and your form
|
497
|
-
* contains an input of type='image" then pass true for this arg, otherwise pass false
|
498
|
-
* (or nothing) to avoid the overhead for this logic.
|
499
|
-
*
|
500
|
-
* @example var data = $("#myForm").formToArray();
|
501
|
-
* $.post( "myscript.cgi", data );
|
502
|
-
* @desc Collect all the data from a form and submit it to the server.
|
503
|
-
*
|
504
|
-
* @name formToArray
|
505
|
-
* @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
|
506
|
-
* @type Array<Object>
|
507
|
-
* @cat Plugins/Form
|
508
|
-
*/
|
509
|
-
$.fn.formToArray = function(semantic) {
|
510
|
-
var a = [];
|
511
|
-
if (this.length == 0) return a;
|
512
|
-
|
513
|
-
var form = this[0];
|
514
|
-
var els = semantic ? form.getElementsByTagName('*') : form.elements;
|
515
|
-
if (!els) return a;
|
516
|
-
for(var i=0, max=els.length; i < max; i++) {
|
517
|
-
var el = els[i];
|
518
|
-
var n = el.name;
|
519
|
-
if (!n) continue;
|
520
|
-
|
521
|
-
if (semantic && form.clk && el.type == "image") {
|
522
|
-
// handle image inputs on the fly when semantic == true
|
523
|
-
if(!el.disabled && form.clk == el)
|
524
|
-
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
525
|
-
continue;
|
526
|
-
}
|
527
|
-
|
528
|
-
var v = $.fieldValue(el, true);
|
529
|
-
if (v && v.constructor == Array) {
|
530
|
-
for(var j=0, jmax=v.length; j < jmax; j++)
|
531
|
-
a.push({name: n, value: v[j]});
|
532
|
-
}
|
533
|
-
else if (v !== null && typeof v != 'undefined')
|
534
|
-
a.push({name: n, value: v});
|
535
|
-
}
|
536
|
-
|
537
|
-
if (!semantic && form.clk) {
|
538
|
-
// input type=='image' are not found in elements array! handle them here
|
539
|
-
var inputs = form.getElementsByTagName("input");
|
540
|
-
for(var i=0, max=inputs.length; i < max; i++) {
|
541
|
-
var input = inputs[i];
|
542
|
-
var n = input.name;
|
543
|
-
if(n && !input.disabled && input.type == "image" && form.clk == input)
|
544
|
-
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
545
|
-
}
|
546
|
-
}
|
547
|
-
return a;
|
548
|
-
};
|
549
|
-
|
550
|
-
|
551
|
-
/**
|
552
|
-
* Serializes form data into a 'submittable' string. This method will return a string
|
553
|
-
* in the format: name1=value1&name2=value2
|
554
|
-
*
|
555
|
-
* The semantic argument can be used to force form serialization in semantic order.
|
556
|
-
* If your form must be submitted with name/value pairs in semantic order then pass
|
557
|
-
* true for this arg, otherwise pass false (or nothing) to avoid the overhead for
|
558
|
-
* this logic (which can be significant for very large forms).
|
559
|
-
*
|
560
|
-
* @example var data = $("#myForm").formSerialize();
|
561
|
-
* $.ajax('POST', "myscript.cgi", data);
|
562
|
-
* @desc Collect all the data from a form into a single string
|
563
|
-
*
|
564
|
-
* @name formSerialize
|
565
|
-
* @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
|
566
|
-
* @type String
|
567
|
-
* @cat Plugins/Form
|
568
|
-
*/
|
569
|
-
$.fn.formSerialize = function(semantic) {
|
570
|
-
//hand off to jQuery.param for proper encoding
|
571
|
-
return $.param(this.formToArray(semantic));
|
572
|
-
};
|
573
|
-
|
574
|
-
|
575
|
-
/**
|
576
|
-
* Serializes all field elements in the jQuery object into a query string.
|
577
|
-
* This method will return a string in the format: name1=value1&name2=value2
|
578
|
-
*
|
579
|
-
* The successful argument controls whether or not serialization is limited to
|
580
|
-
* 'successful' controls (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
581
|
-
* The default value of the successful argument is true.
|
582
|
-
*
|
583
|
-
* @example var data = $("input").formSerialize();
|
584
|
-
* @desc Collect the data from all successful input elements into a query string
|
585
|
-
*
|
586
|
-
* @example var data = $(":radio").formSerialize();
|
587
|
-
* @desc Collect the data from all successful radio input elements into a query string
|
588
|
-
*
|
589
|
-
* @example var data = $("#myForm :checkbox").formSerialize();
|
590
|
-
* @desc Collect the data from all successful checkbox input elements in myForm into a query string
|
591
|
-
*
|
592
|
-
* @example var data = $("#myForm :checkbox").formSerialize(false);
|
593
|
-
* @desc Collect the data from all checkbox elements in myForm (even the unchecked ones) into a query string
|
594
|
-
*
|
595
|
-
* @example var data = $(":input").formSerialize();
|
596
|
-
* @desc Collect the data from all successful input, select, textarea and button elements into a query string
|
597
|
-
*
|
598
|
-
* @name fieldSerialize
|
599
|
-
* @param successful true if only successful controls should be serialized (default is true)
|
600
|
-
* @type String
|
601
|
-
* @cat Plugins/Form
|
602
|
-
*/
|
603
|
-
$.fn.fieldSerialize = function(successful) {
|
604
|
-
var a = [];
|
605
|
-
this.each(function() {
|
606
|
-
var n = this.name;
|
607
|
-
if (!n) return;
|
608
|
-
var v = $.fieldValue(this, successful);
|
609
|
-
if (v && v.constructor == Array) {
|
610
|
-
for (var i=0,max=v.length; i < max; i++)
|
611
|
-
a.push({name: n, value: v[i]});
|
612
|
-
}
|
613
|
-
else if (v !== null && typeof v != 'undefined')
|
614
|
-
a.push({name: this.name, value: v});
|
615
|
-
});
|
616
|
-
//hand off to jQuery.param for proper encoding
|
617
|
-
return $.param(a);
|
618
|
-
};
|
619
|
-
|
620
|
-
|
621
|
-
/**
|
622
|
-
* Returns the value(s) of the element in the matched set. For example, consider the following form:
|
623
|
-
*
|
624
|
-
* <form><fieldset>
|
625
|
-
* <input name="A" type="text" />
|
626
|
-
* <input name="A" type="text" />
|
627
|
-
* <input name="B" type="checkbox" value="B1" />
|
628
|
-
* <input name="B" type="checkbox" value="B2"/>
|
629
|
-
* <input name="C" type="radio" value="C1" />
|
630
|
-
* <input name="C" type="radio" value="C2" />
|
631
|
-
* </fieldset></form>
|
632
|
-
*
|
633
|
-
* var v = $(':text').fieldValue();
|
634
|
-
* // if no values are entered into the text inputs
|
635
|
-
* v == ['','']
|
636
|
-
* // if values entered into the text inputs are 'foo' and 'bar'
|
637
|
-
* v == ['foo','bar']
|
638
|
-
*
|
639
|
-
* var v = $(':checkbox').fieldValue();
|
640
|
-
* // if neither checkbox is checked
|
641
|
-
* v === undefined
|
642
|
-
* // if both checkboxes are checked
|
643
|
-
* v == ['B1', 'B2']
|
644
|
-
*
|
645
|
-
* var v = $(':radio').fieldValue();
|
646
|
-
* // if neither radio is checked
|
647
|
-
* v === undefined
|
648
|
-
* // if first radio is checked
|
649
|
-
* v == ['C1']
|
650
|
-
*
|
651
|
-
* The successful argument controls whether or not the field element must be 'successful'
|
652
|
-
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
653
|
-
* The default value of the successful argument is true. If this value is false the value(s)
|
654
|
-
* for each element is returned.
|
655
|
-
*
|
656
|
-
* Note: This method *always* returns an array. If no valid value can be determined the
|
657
|
-
* array will be empty, otherwise it will contain one or more values.
|
658
|
-
*
|
659
|
-
* @example var data = $("#myPasswordElement").fieldValue();
|
660
|
-
* alert(data[0]);
|
661
|
-
* @desc Alerts the current value of the myPasswordElement element
|
662
|
-
*
|
663
|
-
* @example var data = $("#myForm :input").fieldValue();
|
664
|
-
* @desc Get the value(s) of the form elements in myForm
|
665
|
-
*
|
666
|
-
* @example var data = $("#myForm :checkbox").fieldValue();
|
667
|
-
* @desc Get the value(s) for the successful checkbox element(s) in the jQuery object.
|
668
|
-
*
|
669
|
-
* @example var data = $("#mySingleSelect").fieldValue();
|
670
|
-
* @desc Get the value(s) of the select control
|
671
|
-
*
|
672
|
-
* @example var data = $(':text').fieldValue();
|
673
|
-
* @desc Get the value(s) of the text input or textarea elements
|
674
|
-
*
|
675
|
-
* @example var data = $("#myMultiSelect").fieldValue();
|
676
|
-
* @desc Get the values for the select-multiple control
|
677
|
-
*
|
678
|
-
* @name fieldValue
|
679
|
-
* @param Boolean successful true if only the values for successful controls should be returned (default is true)
|
680
|
-
* @type Array<String>
|
681
|
-
* @cat Plugins/Form
|
682
|
-
*/
|
683
|
-
$.fn.fieldValue = function(successful) {
|
684
|
-
for (var val=[], i=0, max=this.length; i < max; i++) {
|
685
|
-
var el = this[i];
|
686
|
-
var v = $.fieldValue(el, successful);
|
687
|
-
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
|
688
|
-
continue;
|
689
|
-
v.constructor == Array ? $.merge(val, v) : val.push(v);
|
690
|
-
}
|
691
|
-
return val;
|
692
|
-
};
|
693
|
-
|
694
|
-
/**
|
695
|
-
* Returns the value of the field element.
|
696
|
-
*
|
697
|
-
* The successful argument controls whether or not the field element must be 'successful'
|
698
|
-
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
699
|
-
* The default value of the successful argument is true. If the given element is not
|
700
|
-
* successful and the successful arg is not false then the returned value will be null.
|
701
|
-
*
|
702
|
-
* Note: If the successful flag is true (default) but the element is not successful, the return will be null
|
703
|
-
* Note: The value returned for a successful select-multiple element will always be an array.
|
704
|
-
* Note: If the element has no value the return value will be undefined.
|
705
|
-
*
|
706
|
-
* @example var data = jQuery.fieldValue($("#myPasswordElement")[0]);
|
707
|
-
* @desc Gets the current value of the myPasswordElement element
|
708
|
-
*
|
709
|
-
* @name fieldValue
|
710
|
-
* @param Element el The DOM element for which the value will be returned
|
711
|
-
* @param Boolean successful true if value returned must be for a successful controls (default is true)
|
712
|
-
* @type String or Array<String> or null or undefined
|
713
|
-
* @cat Plugins/Form
|
714
|
-
*/
|
715
|
-
$.fieldValue = function(el, successful) {
|
716
|
-
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
|
717
|
-
if (typeof successful == 'undefined') successful = true;
|
718
|
-
|
719
|
-
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
|
720
|
-
(t == 'checkbox' || t == 'radio') && !el.checked ||
|
721
|
-
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
|
722
|
-
tag == 'select' && el.selectedIndex == -1))
|
723
|
-
return null;
|
724
|
-
|
725
|
-
if (tag == 'select') {
|
726
|
-
var index = el.selectedIndex;
|
727
|
-
if (index < 0) return null;
|
728
|
-
var a = [], ops = el.options;
|
729
|
-
var one = (t == 'select-one');
|
730
|
-
var max = (one ? index+1 : ops.length);
|
731
|
-
for(var i=(one ? index : 0); i < max; i++) {
|
732
|
-
var op = ops[i];
|
733
|
-
if (op.selected) {
|
734
|
-
// extra pain for IE...
|
735
|
-
var v = $.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value;
|
736
|
-
if (one) return v;
|
737
|
-
a.push(v);
|
738
|
-
}
|
739
|
-
}
|
740
|
-
return a;
|
741
|
-
}
|
742
|
-
return el.value;
|
743
|
-
};
|
744
|
-
|
745
|
-
|
746
|
-
/**
|
747
|
-
* Clears the form data. Takes the following actions on the form's input fields:
|
748
|
-
* - input text fields will have their 'value' property set to the empty string
|
749
|
-
* - select elements will have their 'selectedIndex' property set to -1
|
750
|
-
* - checkbox and radio inputs will have their 'checked' property set to false
|
751
|
-
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
752
|
-
* - button elements will *not* be effected
|
753
|
-
*
|
754
|
-
* @example $('form').clearForm();
|
755
|
-
* @desc Clears all forms on the page.
|
756
|
-
*
|
757
|
-
* @name clearForm
|
758
|
-
* @type jQuery
|
759
|
-
* @cat Plugins/Form
|
760
|
-
*/
|
761
|
-
$.fn.clearForm = function() {
|
762
|
-
return this.each(function() {
|
763
|
-
$('input,select,textarea', this).clearFields();
|
764
|
-
});
|
765
|
-
};
|
766
|
-
|
767
|
-
/**
|
768
|
-
* Clears the selected form elements. Takes the following actions on the matched elements:
|
769
|
-
* - input text fields will have their 'value' property set to the empty string
|
770
|
-
* - select elements will have their 'selectedIndex' property set to -1
|
771
|
-
* - checkbox and radio inputs will have their 'checked' property set to false
|
772
|
-
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
773
|
-
* - button elements will *not* be effected
|
774
|
-
*
|
775
|
-
* @example $('.myInputs').clearFields();
|
776
|
-
* @desc Clears all inputs with class myInputs
|
777
|
-
*
|
778
|
-
* @name clearFields
|
779
|
-
* @type jQuery
|
780
|
-
* @cat Plugins/Form
|
781
|
-
*/
|
782
|
-
$.fn.clearFields = $.fn.clearInputs = function() {
|
783
|
-
return this.each(function() {
|
784
|
-
var t = this.type, tag = this.tagName.toLowerCase();
|
785
|
-
if (t == 'text' || t == 'password' || tag == 'textarea')
|
786
|
-
this.value = '';
|
787
|
-
else if (t == 'checkbox' || t == 'radio')
|
788
|
-
this.checked = false;
|
789
|
-
else if (tag == 'select')
|
790
|
-
this.selectedIndex = -1;
|
791
|
-
});
|
792
|
-
};
|
793
|
-
|
794
|
-
|
795
|
-
/**
|
796
|
-
* Resets the form data. Causes all form elements to be reset to their original value.
|
797
|
-
*
|
798
|
-
* @example $('form').resetForm();
|
799
|
-
* @desc Resets all forms on the page.
|
800
|
-
*
|
801
|
-
* @name resetForm
|
802
|
-
* @type jQuery
|
803
|
-
* @cat Plugins/Form
|
804
|
-
*/
|
805
|
-
$.fn.resetForm = function() {
|
806
|
-
return this.each(function() {
|
807
|
-
// guard against an input with the name of 'reset'
|
808
|
-
// note that IE reports the reset function as an 'object'
|
809
|
-
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
|
810
|
-
this.reset();
|
811
|
-
});
|
812
|
-
};
|
813
|
-
|
814
|
-
})(jQuery);
|