compass-jquery-plugin 0.3.2.pre.2 → 0.3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/LICENSE.md +20 -20
  2. data/README.md +7 -2
  3. data/VERSION.yml +2 -2
  4. data/lib/jquery/gridify/grid.rb +1 -1
  5. data/lib/jquery/gridify/grid_column.rb +1 -1
  6. data/lib/jquery/gridify/grid_finder.rb +16 -1
  7. data/lib/jquery/gridify/grid_view.rb +1 -1
  8. data/lib/jquery/jqgrid.rb +4 -4
  9. data/lib/jquery/jqtouch.rb +3 -3
  10. data/lib/jquery/jquery.rb +431 -431
  11. data/lib/jquery/jquery_json_response.rb +28 -0
  12. data/lib/jquery/secret_sauce.rb +8 -8
  13. data/lib/jquery/secret_sauce/controller/ui_dialog_controls.rb +13 -13
  14. data/lib/jquery/secret_sauce/controller/ui_grid_controls.rb +18 -18
  15. data/lib/jquery/secret_sauce/helpers/ui_dialog_helper.rb +5 -5
  16. data/lib/jquery/secret_sauce/model/find_for_grid.rb +41 -41
  17. data/templates/dynatree/jquery.dynatree.js +111 -110
  18. data/templates/dynatree/jquery.dynatree.min.js +75 -77
  19. data/templates/dynatree/jquery/dynatree/aero.scss +1 -3
  20. data/templates/dynatree/jquery/dynatree/aqua.scss +1 -3
  21. data/templates/dynatree/jquery/dynatree/crystal.scss +1 -3
  22. data/templates/dynatree/jquery/dynatree/xp.scss +1 -3
  23. data/templates/emulators/emulators/iphone.landscape.png +0 -0
  24. data/templates/emulators/emulators/iphone.landscape.scss +4 -4
  25. data/templates/emulators/emulators/palm.landscape.scss +6 -6
  26. data/templates/emulators/emulators/palm.pre.landscape.png +0 -0
  27. data/templates/ical/jquery.ical.js +3202 -3197
  28. data/templates/ical/jquery.ical.min.js +185 -184
  29. data/templates/ical/jquery/ical.scss +3 -3
  30. data/templates/jqgrid/i18n/jqgrid/locale-ar.js +126 -0
  31. data/templates/jqgrid/i18n/jqgrid/locale-ar.min.js +6 -0
  32. data/templates/jqgrid/i18n/jqgrid/locale-fi.js +45 -47
  33. data/templates/jqgrid/i18n/jqgrid/locale-fi.min.js +6 -6
  34. data/templates/jqgrid/jquery.jqGrid.js +2047 -2036
  35. data/templates/jqgrid/jquery.jqGrid.min.js +48 -48
  36. data/templates/jqgrid/manifest.rb +2 -0
  37. data/templates/jqtouch/jquery.jqtouch.js +122 -113
  38. data/templates/jqtouch/jquery.jqtouch.min.js +1 -1
  39. data/templates/jquery/config/initializers/jquery.rb +4 -2
  40. data/templates/jquery/i18n/jquery.ui/datepicker-ar-DZ.js +23 -0
  41. data/templates/jquery/i18n/jquery.ui/datepicker-ar-DZ.min.js +2 -0
  42. data/templates/jquery/i18n/jquery.ui/datepicker-en-AU.js +23 -0
  43. data/templates/jquery/i18n/jquery.ui/datepicker-en-AU.min.js +2 -0
  44. data/templates/jquery/i18n/jquery.ui/datepicker-en-NZ.js +23 -0
  45. data/templates/jquery/i18n/jquery.ui/datepicker-en-NZ.min.js +2 -0
  46. data/templates/jquery/i18n/jquery.ui/datepicker-ml.js +23 -0
  47. data/templates/jquery/i18n/jquery.ui/datepicker-ml.min.js +2 -0
  48. data/templates/jquery/jquery-ui.js +354 -316
  49. data/templates/jquery/jquery-ui.min.js +544 -544
  50. data/templates/jquery/jquery.cookie.js +3 -3
  51. data/templates/jquery/jquery.form.js +271 -140
  52. data/templates/jquery/jquery.form.min.js +19 -17
  53. data/templates/jquery/jquery.layout.js +2435 -2437
  54. data/templates/jquery/jquery.layout.min.js +4 -3
  55. data/templates/jquery/jquery.mousewheel.js +78 -0
  56. data/templates/jquery/jquery.mousewheel.min.js +2 -0
  57. data/templates/jquery/jquery.offline.js +212 -0
  58. data/templates/jquery/jquery.offline.min.js +4 -0
  59. data/templates/jquery/jquery.tmpl.js +15 -22
  60. data/templates/jquery/jquery.tmpl.min.js +12 -12
  61. data/templates/jquery/jquery.tmplPlus.js +1 -0
  62. data/templates/jquery/jquery/ui/_theme.scss +27 -27
  63. data/templates/jquery/json.js +7 -0
  64. data/templates/jquery/json.min.js +7 -0
  65. data/templates/jquery/manifest.rb +14 -2
  66. data/templates/mobile/glyphish/{Read me first - license.txt → License.txt} +0 -0
  67. data/templates/mobile/jquery.mobile.js +1583 -1408
  68. data/templates/mobile/jquery.mobile.min.js +5 -5
  69. data/templates/mobile/jquery/mobile/_base.scss +938 -1038
  70. data/templates/mobile/jquery/mobile/default.scss +25 -26
  71. data/templates/mobile/jquery/mobile/valencia.scss +0 -1
  72. data/templates/mobile/manifest.rb +1 -1
  73. data/templates/tools/config/initializers/tools.rb +2 -0
  74. data/templates/tools/flowplayer.js +24 -0
  75. data/templates/tools/flowplayer.min.js +30 -0
  76. data/templates/tools/jquery.tools.js +4 -3
  77. data/templates/tools/jquery.tools.min.js +1 -1
  78. data/templates/tools/manifest.rb +4 -0
  79. data/templates/tools/swfobject.js +777 -0
  80. data/templates/tools/swfobject.min.js +19 -0
  81. metadata +31 -15
  82. data/templates/jquery/jquery.metadata.js +0 -122
  83. data/templates/jquery/jquery.metadata.min.js +0 -2
@@ -1,6 +1,6 @@
1
1
  /*jslint browser: true */ /*global jQuery: true */
2
2
 
3
- /**
3
+ /*
4
4
  * jQuery Cookie plugin
5
5
  *
6
6
  * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
@@ -10,9 +10,9 @@
10
10
  *
11
11
  */
12
12
 
13
- // TODO JsDoc
14
13
 
15
- /**
14
+
15
+ /*
16
16
  * Create a cookie with the given key and value and other optional parameters.
17
17
  *
18
18
  * @example $.cookie('the_cookie', 'the_value');
@@ -1,7 +1,7 @@
1
- /*
1
+ /*!
2
2
  * jQuery Form Plugin
3
- * version: 2.36 (07-NOV-2009)
4
- * @requires jQuery v1.2.6 or later
3
+ * version: 2.52 (07-DEC-2010)
4
+ * @requires jQuery v1.3.2 or later
5
5
  *
6
6
  * Examples and documentation at: http://malsup.com/jquery/form/
7
7
  * Dual licensed under the MIT and GPL licenses:
@@ -18,11 +18,11 @@
18
18
  to bind your own submit handler to the form. For example,
19
19
 
20
20
  $(document).ready(function() {
21
- $('#myForm').bind('submit', function() {
21
+ $('#myForm').bind('submit', function(e) {
22
+ e.preventDefault(); // <-- important
22
23
  $(this).ajaxSubmit({
23
24
  target: '#output'
24
25
  });
25
- return false; // <-- important!
26
26
  });
27
27
  });
28
28
 
@@ -50,21 +50,23 @@ $.fn.ajaxSubmit = function(options) {
50
50
  return this;
51
51
  }
52
52
 
53
- if (typeof options == 'function')
53
+ if (typeof options == 'function') {
54
54
  options = { success: options };
55
+ }
55
56
 
56
- var url = $.trim(this.attr('action'));
57
+ var action = this.attr('action');
58
+ var url = (typeof action === 'string') ? $.trim(action) : '';
57
59
  if (url) {
58
60
  // clean url (don't include hash vaue)
59
61
  url = (url.match(/^([^#]+)/)||[])[1];
60
- }
61
- url = url || window.location.href || '';
62
+ }
63
+ url = url || window.location.href || '';
62
64
 
63
- options = $.extend({
65
+ options = $.extend(true, {
64
66
  url: url,
65
67
  type: this.attr('method') || 'GET',
66
68
  iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
67
- }, options || {});
69
+ }, options);
68
70
 
69
71
  // hook for manipulating the form data before it is extracted;
70
72
  // convenient for use with rich editors like tinyMCE or FCKEditor
@@ -81,16 +83,20 @@ $.fn.ajaxSubmit = function(options) {
81
83
  return this;
82
84
  }
83
85
 
84
- var a = this.formToArray(options.semantic);
86
+ var n,v,a = this.formToArray(options.semantic);
85
87
  if (options.data) {
86
88
  options.extraData = options.data;
87
- for (var n in options.data) {
88
- if(options.data[n] instanceof Array) {
89
- for (var k in options.data[n])
90
- a.push( { name: n, value: options.data[n][k] } );
91
- }
92
- else
93
- a.push( { name: n, value: options.data[n] } );
89
+ for (n in options.data) {
90
+ if(options.data[n] instanceof Array) {
91
+ for (var k in options.data[n]) {
92
+ a.push( { name: n, value: options.data[n][k] } );
93
+ }
94
+ }
95
+ else {
96
+ v = options.data[n];
97
+ v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
98
+ a.push( { name: n, value: v } );
99
+ }
94
100
  }
95
101
  }
96
102
 
@@ -113,51 +119,57 @@ $.fn.ajaxSubmit = function(options) {
113
119
  options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
114
120
  options.data = null; // data is null for 'get'
115
121
  }
116
- else
122
+ else {
117
123
  options.data = q; // data is the query string for 'post'
124
+ }
118
125
 
119
126
  var $form = this, callbacks = [];
120
- if (options.resetForm) callbacks.push(function() { $form.resetForm(); });
121
- if (options.clearForm) callbacks.push(function() { $form.clearForm(); });
127
+ if (options.resetForm) {
128
+ callbacks.push(function() { $form.resetForm(); });
129
+ }
130
+ if (options.clearForm) {
131
+ callbacks.push(function() { $form.clearForm(); });
132
+ }
122
133
 
123
134
  // perform a load on the target only if dataType is not provided
124
135
  if (!options.dataType && options.target) {
125
136
  var oldSuccess = options.success || function(){};
126
137
  callbacks.push(function(data) {
127
- $(options.target).html(data).each(oldSuccess, arguments);
138
+ var fn = options.replaceTarget ? 'replaceWith' : 'html';
139
+ $(options.target)[fn](data).each(oldSuccess, arguments);
128
140
  });
129
141
  }
130
- else if (options.success)
142
+ else if (options.success) {
131
143
  callbacks.push(options.success);
144
+ }
132
145
 
133
- options.success = function(data, status) {
134
- for (var i=0, max=callbacks.length; i < max; i++)
135
- callbacks[i].apply(options, [data, status, $form]);
146
+ options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
147
+ var context = options.context || options; // jQuery 1.4+ supports scope context
148
+ for (var i=0, max=callbacks.length; i < max; i++) {
149
+ callbacks[i].apply(context, [data, status, xhr || $form, $form]);
150
+ }
136
151
  };
137
152
 
138
153
  // are there files to upload?
139
- var files = $('input:file', this).fieldValue();
140
- var found = false;
141
- for (var j=0; j < files.length; j++)
142
- if (files[j])
143
- found = true;
144
-
145
- var multipart = false;
146
- // var mp = 'multipart/form-data';
147
- // multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
154
+ var fileInputs = $('input:file', this).length > 0;
155
+ var mp = 'multipart/form-data';
156
+ var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
148
157
 
149
158
  // options.iframe allows user to force iframe mode
150
159
  // 06-NOV-09: now defaulting to iframe mode if file input is detected
151
- if ((files.length && options.iframe !== false) || options.iframe || found || multipart) {
160
+ if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
152
161
  // hack to fix Safari hang (thanks to Tim Molendijk for this)
153
162
  // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
154
- if (options.closeKeepAlive)
163
+ if (options.closeKeepAlive) {
155
164
  $.get(options.closeKeepAlive, fileUpload);
156
- else
165
+ }
166
+ else {
157
167
  fileUpload();
158
- }
159
- else
168
+ }
169
+ }
170
+ else {
160
171
  $.ajax(options);
172
+ }
161
173
 
162
174
  // fire 'notify' event
163
175
  this.trigger('form-submit-notify', [this, options]);
@@ -168,16 +180,25 @@ $.fn.ajaxSubmit = function(options) {
168
180
  function fileUpload() {
169
181
  var form = $form[0];
170
182
 
171
- if ($(':input[name=submit]', form).length) {
172
- alert('Error: Form elements must not be named "submit".');
183
+ if ($(':input[name=submit],:input[id=submit]', form).length) {
184
+ // if there is an input with a name or id of 'submit' then we won't be
185
+ // able to invoke the submit fn on the form (at least not x-browser)
186
+ alert('Error: Form elements must not have name or id of "submit".');
173
187
  return;
174
188
  }
175
-
176
- var opts = $.extend({}, $.ajaxSettings, options);
177
- var s = $.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);
178
-
179
- var id = 'jqFormIO' + (new Date().getTime());
180
- var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ opts.iframeSrc +'" />');
189
+
190
+ var s = $.extend(true, {}, $.ajaxSettings, options);
191
+ s.context = s.context || s;
192
+ var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id;
193
+ window[fn] = function() {
194
+ var f = $io.data('form-plugin-onload');
195
+ if (f) {
196
+ f();
197
+ window[fn] = undefined;
198
+ try { delete window[fn]; } catch(e){}
199
+ }
200
+ }
201
+ var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" onload="window[\'_\'+this.id]()" />');
181
202
  var io = $io[0];
182
203
 
183
204
  $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
@@ -193,23 +214,30 @@ $.fn.ajaxSubmit = function(options) {
193
214
  setRequestHeader: function() {},
194
215
  abort: function() {
195
216
  this.aborted = 1;
196
- $io.attr('src', opts.iframeSrc); // abort op in progress
217
+ $io.attr('src', s.iframeSrc); // abort op in progress
197
218
  }
198
219
  };
199
220
 
200
- var g = opts.global;
221
+ var g = s.global;
201
222
  // trigger ajax global events so that activity/block indicators work like normal
202
- if (g && ! $.active++) $.event.trigger("ajaxStart");
203
- if (g) $.event.trigger("ajaxSend", [xhr, opts]);
223
+ if (g && ! $.active++) {
224
+ $.event.trigger("ajaxStart");
225
+ }
226
+ if (g) {
227
+ $.event.trigger("ajaxSend", [xhr, s]);
228
+ }
204
229
 
205
- if (s.beforeSend && s.beforeSend(xhr, s) === false) {
206
- s.global && $.active--;
230
+ if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
231
+ if (s.global) {
232
+ $.active--;
233
+ }
207
234
  return;
208
235
  }
209
- if (xhr.aborted)
236
+ if (xhr.aborted) {
210
237
  return;
238
+ }
211
239
 
212
- var cbInvoked = 0;
240
+ var cbInvoked = false;
213
241
  var timedOut = 0;
214
242
 
215
243
  // add submitting element to data if we know it
@@ -217,29 +245,31 @@ $.fn.ajaxSubmit = function(options) {
217
245
  if (sub) {
218
246
  var n = sub.name;
219
247
  if (n && !sub.disabled) {
220
- options.extraData = options.extraData || {};
221
- options.extraData[n] = sub.value;
248
+ s.extraData = s.extraData || {};
249
+ s.extraData[n] = sub.value;
222
250
  if (sub.type == "image") {
223
- options.extraData[name+'.x'] = form.clk_x;
224
- options.extraData[name+'.y'] = form.clk_y;
251
+ s.extraData[n+'.x'] = form.clk_x;
252
+ s.extraData[n+'.y'] = form.clk_y;
225
253
  }
226
254
  }
227
255
  }
228
256
 
229
257
  // take a breath so that pending repaints get some cpu time before the upload starts
230
- setTimeout(function() {
258
+ function doSubmit() {
231
259
  // make sure form attrs are set
232
260
  var t = $form.attr('target'), a = $form.attr('action');
233
261
 
234
262
  // update form attrs in IE friendly way
235
263
  form.setAttribute('target',id);
236
- if (form.getAttribute('method') != 'POST')
264
+ if (form.getAttribute('method') != 'POST') {
237
265
  form.setAttribute('method', 'POST');
238
- if (form.getAttribute('action') != opts.url)
239
- form.setAttribute('action', opts.url);
266
+ }
267
+ if (form.getAttribute('action') != s.url) {
268
+ form.setAttribute('action', s.url);
269
+ }
240
270
 
241
271
  // ie borks in some cases when setting encoding
242
- if (! options.skipEncodingOverride) {
272
+ if (! s.skipEncodingOverride) {
243
273
  $form.attr({
244
274
  encoding: 'multipart/form-data',
245
275
  enctype: 'multipart/form-data'
@@ -247,104 +277,146 @@ $.fn.ajaxSubmit = function(options) {
247
277
  }
248
278
 
249
279
  // support timout
250
- if (opts.timeout)
251
- setTimeout(function() { timedOut = true; cb(); }, opts.timeout);
280
+ if (s.timeout) {
281
+ setTimeout(function() { timedOut = true; cb(); }, s.timeout);
282
+ }
252
283
 
253
284
  // add "extra" data to form if provided in options
254
285
  var extraInputs = [];
255
286
  try {
256
- if (options.extraData)
257
- for (var n in options.extraData)
287
+ if (s.extraData) {
288
+ for (var n in s.extraData) {
258
289
  extraInputs.push(
259
- $('<input type="hidden" name="'+n+'" value="'+options.extraData[n]+'" />')
290
+ $('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
260
291
  .appendTo(form)[0]);
292
+ }
293
+ }
261
294
 
262
295
  // add iframe to doc and submit the form
263
296
  $io.appendTo('body');
264
- io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
297
+ $io.data('form-plugin-onload', cb);
265
298
  form.submit();
266
299
  }
267
300
  finally {
268
301
  // reset attrs and remove "extra" input elements
269
302
  form.setAttribute('action',a);
270
- t ? form.setAttribute('target', t) : $form.removeAttr('target');
303
+ if(t) {
304
+ form.setAttribute('target', t);
305
+ } else {
306
+ $form.removeAttr('target');
307
+ }
271
308
  $(extraInputs).remove();
272
309
  }
273
- }, 10);
310
+ }
274
311
 
275
- var domCheckCount = 50;
312
+ if (s.forceSync) {
313
+ doSubmit();
314
+ }
315
+ else {
316
+ setTimeout(doSubmit, 10); // this lets dom updates render
317
+ }
318
+
319
+ var data, doc, domCheckCount = 50;
276
320
 
277
321
  function cb() {
278
- if (cbInvoked++) return;
279
-
280
- io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
322
+ if (cbInvoked) {
323
+ return;
324
+ }
281
325
 
326
+ $io.removeData('form-plugin-onload');
327
+
282
328
  var ok = true;
283
329
  try {
284
- if (timedOut) throw 'timeout';
330
+ if (timedOut) {
331
+ throw 'timeout';
332
+ }
285
333
  // extract the server response from the iframe
286
- var data, doc;
287
-
288
334
  doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
289
335
 
290
- var isXml = opts.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
336
+ var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
291
337
  log('isXml='+isXml);
292
- if (!isXml && (doc.body == null || doc.body.innerHTML == '')) {
293
- if (--domCheckCount) {
338
+ if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
339
+ if (--domCheckCount) {
294
340
  // in some browsers (Opera) the iframe DOM is not always traversable when
295
341
  // the onload callback fires, so we loop a bit to accommodate
296
- cbInvoked = 0;
297
- setTimeout(cb, 100);
342
+ log('requeing onLoad callback, DOM not available');
343
+ setTimeout(cb, 250);
298
344
  return;
299
345
  }
300
- log('Could not access iframe DOM after 50 tries.');
301
- return;
346
+ // let this fall through because server response could be an empty document
347
+ //log('Could not access iframe DOM after mutiple tries.');
348
+ //throw 'DOMException: not available';
302
349
  }
303
350
 
304
- xhr.responseText = doc.body ? doc.body.innerHTML : null;
351
+ //log('response detected');
352
+ cbInvoked = true;
353
+ xhr.responseText = doc.documentElement ? doc.documentElement.innerHTML : null;
305
354
  xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
306
355
  xhr.getResponseHeader = function(header){
307
- var headers = {'content-type': opts.dataType};
356
+ var headers = {'content-type': s.dataType};
308
357
  return headers[header];
309
358
  };
310
359
 
311
- if (opts.dataType == 'json' || opts.dataType == 'script') {
360
+ var scr = /(json|script)/.test(s.dataType);
361
+ if (scr || s.textarea) {
312
362
  // see if user embedded response in textarea
313
363
  var ta = doc.getElementsByTagName('textarea')[0];
314
- if (ta)
364
+ if (ta) {
315
365
  xhr.responseText = ta.value;
316
- else {
366
+ }
367
+ else if (scr) {
317
368
  // account for browsers injecting pre around json response
318
369
  var pre = doc.getElementsByTagName('pre')[0];
319
- if (pre)
320
- xhr.responseText = pre.innerHTML;
370
+ var b = doc.getElementsByTagName('body')[0];
371
+ if (pre) {
372
+ xhr.responseText = pre.textContent;
373
+ }
374
+ else if (b) {
375
+ xhr.responseText = b.innerHTML;
376
+ }
321
377
  }
322
378
  }
323
- else if (opts.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
379
+ else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
324
380
  xhr.responseXML = toXml(xhr.responseText);
325
381
  }
326
- data = $.httpData(xhr, opts.dataType);
382
+ data = $.httpData(xhr, s.dataType);
327
383
  }
328
384
  catch(e){
385
+ log('error caught:',e);
386
+ ok = false;
387
+ xhr.error = e;
388
+ $.handleError(s, xhr, 'error', e);
389
+ }
390
+
391
+ if (xhr.aborted) {
392
+ log('upload aborted');
329
393
  ok = false;
330
- $.handleError(opts, xhr, 'error', e);
331
394
  }
332
395
 
333
396
  // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
334
397
  if (ok) {
335
- opts.success(data, 'success');
336
- if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
398
+ s.success.call(s.context, data, 'success', xhr);
399
+ if (g) {
400
+ $.event.trigger("ajaxSuccess", [xhr, s]);
401
+ }
402
+ }
403
+ if (g) {
404
+ $.event.trigger("ajaxComplete", [xhr, s]);
405
+ }
406
+ if (g && ! --$.active) {
407
+ $.event.trigger("ajaxStop");
408
+ }
409
+ if (s.complete) {
410
+ s.complete.call(s.context, xhr, ok ? 'success' : 'error');
337
411
  }
338
- if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
339
- if (g && ! --$.active) $.event.trigger("ajaxStop");
340
- if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
341
412
 
342
413
  // clean up
343
414
  setTimeout(function() {
415
+ $io.removeData('form-plugin-onload');
344
416
  $io.remove();
345
417
  xhr.responseXML = null;
346
418
  }, 100);
347
- };
419
+ }
348
420
 
349
421
  function toXml(s, doc) {
350
422
  if (window.ActiveXObject) {
@@ -352,11 +424,12 @@ $.fn.ajaxSubmit = function(options) {
352
424
  doc.async = 'false';
353
425
  doc.loadXML(s);
354
426
  }
355
- else
427
+ else {
356
428
  doc = (new DOMParser()).parseFromString(s, 'text/xml');
429
+ }
357
430
  return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
358
- };
359
- };
431
+ }
432
+ }
360
433
  };
361
434
 
362
435
  /**
@@ -375,17 +448,35 @@ $.fn.ajaxSubmit = function(options) {
375
448
  * the form itself.
376
449
  */
377
450
  $.fn.ajaxForm = function(options) {
378
- return this.ajaxFormUnbind().bind('submit.form-plugin', function() {
379
- $(this).ajaxSubmit(options);
380
- return false;
451
+ // in jQuery 1.3+ we can fix mistakes with the ready state
452
+ if (this.length === 0) {
453
+ var o = { s: this.selector, c: this.context };
454
+ if (!$.isReady && o.s) {
455
+ log('DOM not ready, queuing ajaxForm');
456
+ $(function() {
457
+ $(o.s,o.c).ajaxForm(options);
458
+ });
459
+ return this;
460
+ }
461
+ // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
462
+ log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
463
+ return this;
464
+ }
465
+
466
+ return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
467
+ if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
468
+ e.preventDefault();
469
+ $(this).ajaxSubmit(options);
470
+ }
381
471
  }).bind('click.form-plugin', function(e) {
382
472
  var target = e.target;
383
473
  var $el = $(target);
384
474
  if (!($el.is(":submit,input:image"))) {
385
475
  // is this a child element of the submit el? (ex: a span within a button)
386
476
  var t = $el.closest(':submit');
387
- if (t.length == 0)
477
+ if (t.length == 0) {
388
478
  return;
479
+ }
389
480
  target = t[0];
390
481
  }
391
482
  var form = this;
@@ -426,15 +517,23 @@ $.fn.ajaxFormUnbind = function() {
426
517
  */
427
518
  $.fn.formToArray = function(semantic) {
428
519
  var a = [];
429
- if (this.length == 0) return a;
520
+ if (this.length === 0) {
521
+ return a;
522
+ }
430
523
 
431
524
  var form = this[0];
432
525
  var els = semantic ? form.getElementsByTagName('*') : form.elements;
433
- if (!els) return a;
434
- for(var i=0, max=els.length; i < max; i++) {
435
- var el = els[i];
436
- var n = el.name;
437
- if (!n) continue;
526
+ if (!els) {
527
+ return a;
528
+ }
529
+
530
+ var i,j,n,v,el,max,jmax;
531
+ for(i=0, max=els.length; i < max; i++) {
532
+ el = els[i];
533
+ n = el.name;
534
+ if (!n) {
535
+ continue;
536
+ }
438
537
 
439
538
  if (semantic && form.clk && el.type == "image") {
440
539
  // handle image inputs on the fly when semantic == true
@@ -445,18 +544,21 @@ $.fn.formToArray = function(semantic) {
445
544
  continue;
446
545
  }
447
546
 
448
- var v = $.fieldValue(el, true);
547
+ v = $.fieldValue(el, true);
449
548
  if (v && v.constructor == Array) {
450
- for(var j=0, jmax=v.length; j < jmax; j++)
549
+ for(j=0, jmax=v.length; j < jmax; j++) {
451
550
  a.push({name: n, value: v[j]});
551
+ }
452
552
  }
453
- else if (v !== null && typeof v != 'undefined')
553
+ else if (v !== null && typeof v != 'undefined') {
454
554
  a.push({name: n, value: v});
555
+ }
455
556
  }
456
557
 
457
558
  if (!semantic && form.clk) {
458
559
  // input type=='image' are not found in elements array! handle it here
459
- var $input = $(form.clk), input = $input[0], n = input.name;
560
+ var $input = $(form.clk), input = $input[0];
561
+ n = input.name;
460
562
  if (n && !input.disabled && input.type == 'image') {
461
563
  a.push({name: n, value: $input.val()});
462
564
  a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
@@ -482,14 +584,18 @@ $.fn.fieldSerialize = function(successful) {
482
584
  var a = [];
483
585
  this.each(function() {
484
586
  var n = this.name;
485
- if (!n) return;
587
+ if (!n) {
588
+ return;
589
+ }
486
590
  var v = $.fieldValue(this, successful);
487
591
  if (v && v.constructor == Array) {
488
- for (var i=0,max=v.length; i < max; i++)
592
+ for (var i=0,max=v.length; i < max; i++) {
489
593
  a.push({name: n, value: v[i]});
594
+ }
490
595
  }
491
- else if (v !== null && typeof v != 'undefined')
596
+ else if (v !== null && typeof v != 'undefined') {
492
597
  a.push({name: this.name, value: v});
598
+ }
493
599
  });
494
600
  //hand off to jQuery.param for proper encoding
495
601
  return $.param(a);
@@ -537,8 +643,9 @@ $.fn.fieldValue = function(successful) {
537
643
  for (var val=[], i=0, max=this.length; i < max; i++) {
538
644
  var el = this[i];
539
645
  var v = $.fieldValue(el, successful);
540
- if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
646
+ if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
541
647
  continue;
648
+ }
542
649
  v.constructor == Array ? $.merge(val, v) : val.push(v);
543
650
  }
544
651
  return val;
@@ -549,17 +656,22 @@ $.fn.fieldValue = function(successful) {
549
656
  */
550
657
  $.fieldValue = function(el, successful) {
551
658
  var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
552
- if (typeof successful == 'undefined') successful = true;
659
+ if (successful === undefined) {
660
+ successful = true;
661
+ }
553
662
 
554
663
  if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
555
664
  (t == 'checkbox' || t == 'radio') && !el.checked ||
556
665
  (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
557
- tag == 'select' && el.selectedIndex == -1))
666
+ tag == 'select' && el.selectedIndex == -1)) {
558
667
  return null;
668
+ }
559
669
 
560
670
  if (tag == 'select') {
561
671
  var index = el.selectedIndex;
562
- if (index < 0) return null;
672
+ if (index < 0) {
673
+ return null;
674
+ }
563
675
  var a = [], ops = el.options;
564
676
  var one = (t == 'select-one');
565
677
  var max = (one ? index+1 : ops.length);
@@ -567,15 +679,18 @@ $.fieldValue = function(el, successful) {
567
679
  var op = ops[i];
568
680
  if (op.selected) {
569
681
  var v = op.value;
570
- if (!v) // extra pain for IE...
682
+ if (!v) { // extra pain for IE...
571
683
  v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
572
- if (one) return v;
684
+ }
685
+ if (one) {
686
+ return v;
687
+ }
573
688
  a.push(v);
574
689
  }
575
690
  }
576
691
  return a;
577
692
  }
578
- return el.value;
693
+ return $(el).val();
579
694
  };
580
695
 
581
696
  /**
@@ -598,12 +713,15 @@ $.fn.clearForm = function() {
598
713
  $.fn.clearFields = $.fn.clearInputs = function() {
599
714
  return this.each(function() {
600
715
  var t = this.type, tag = this.tagName.toLowerCase();
601
- if (t == 'text' || t == 'password' || tag == 'textarea')
716
+ if (t == 'text' || t == 'password' || tag == 'textarea') {
602
717
  this.value = '';
603
- else if (t == 'checkbox' || t == 'radio')
718
+ }
719
+ else if (t == 'checkbox' || t == 'radio') {
604
720
  this.checked = false;
605
- else if (tag == 'select')
721
+ }
722
+ else if (tag == 'select') {
606
723
  this.selectedIndex = -1;
724
+ }
607
725
  });
608
726
  };
609
727
 
@@ -614,8 +732,9 @@ $.fn.resetForm = function() {
614
732
  return this.each(function() {
615
733
  // guard against an input with the name of 'reset'
616
734
  // note that IE reports the reset function as an 'object'
617
- if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
735
+ if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
618
736
  this.reset();
737
+ }
619
738
  });
620
739
  };
621
740
 
@@ -623,7 +742,9 @@ $.fn.resetForm = function() {
623
742
  * Enables or disables any matching elements.
624
743
  */
625
744
  $.fn.enable = function(b) {
626
- if (b == undefined) b = true;
745
+ if (b === undefined) {
746
+ b = true;
747
+ }
627
748
  return this.each(function() {
628
749
  this.disabled = !b;
629
750
  });
@@ -634,11 +755,14 @@ $.fn.enable = function(b) {
634
755
  * selects/deselects and matching option elements.
635
756
  */
636
757
  $.fn.selected = function(select) {
637
- if (select == undefined) select = true;
758
+ if (select === undefined) {
759
+ select = true;
760
+ }
638
761
  return this.each(function() {
639
762
  var t = this.type;
640
- if (t == 'checkbox' || t == 'radio')
763
+ if (t == 'checkbox' || t == 'radio') {
641
764
  this.checked = select;
765
+ }
642
766
  else if (this.tagName.toLowerCase() == 'option') {
643
767
  var $sel = $(this).parent('select');
644
768
  if (select && $sel[0] && $sel[0].type == 'select-one') {
@@ -653,8 +777,15 @@ $.fn.selected = function(select) {
653
777
  // helper fn for console logging
654
778
  // set $.fn.ajaxSubmit.debug to true to enable debug logging
655
779
  function log() {
656
- if ($.fn.ajaxSubmit.debug && window.console && window.console.log)
657
- window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
780
+ if ($.fn.ajaxSubmit.debug) {
781
+ var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
782
+ if (window.console && window.console.log) {
783
+ window.console.log(msg);
784
+ }
785
+ else if (window.opera && window.opera.postError) {
786
+ window.opera.postError(msg);
787
+ }
788
+ }
658
789
  };
659
790
 
660
791
  })(jQuery);