compass-jquery-plugin 0.3.2.3 → 0.3.2.4

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 (235) hide show
  1. data/README.md +54 -37
  2. data/VERSION.yml +1 -1
  3. data/lib/handle_attributes.rb +4 -4
  4. data/lib/handle_js_files.rb +5 -5
  5. data/lib/jqtouch_theme.rb +2 -2
  6. data/lib/jquery/dynatree.rb +2 -2
  7. data/lib/jquery/emulators.rb +1 -1
  8. data/lib/jquery/flash_messages.rb +6 -6
  9. data/lib/jquery/graphics.rb +5 -0
  10. data/lib/jquery/gridify/assertions.rb +1 -1
  11. data/lib/jquery/gridify/grid.rb +76 -59
  12. data/lib/jquery/gridify/grid_column.rb +73 -67
  13. data/lib/jquery/gridify/grid_finder.rb +79 -79
  14. data/lib/jquery/gridify/grid_options.rb +154 -149
  15. data/lib/jquery/gridify/grid_view.rb +143 -143
  16. data/lib/jquery/gridify.rb +25 -25
  17. data/lib/jquery/ical/calendar.rb +2 -2
  18. data/lib/jquery/ical/event.rb +48 -44
  19. data/lib/jquery/ical/helpers/ui_event_helper.rb +3 -3
  20. data/lib/jquery/jqgrid/jqgrid.rb +58 -58
  21. data/lib/jquery/jqgrid.rb +1 -1
  22. data/lib/jquery/jqtouch.rb +1 -1
  23. data/lib/jquery/jquery.rb +117 -117
  24. data/lib/jquery/jquery_auto_complete.rb +9 -9
  25. data/lib/jquery/jquery_json_response.rb +12 -12
  26. data/lib/jquery/jquery_selector_assertions.rb +55 -53
  27. data/lib/jquery/jstree.rb +2 -2
  28. data/lib/jquery/mobile.rb +1 -1
  29. data/lib/jquery/ribbon.rb +2 -2
  30. data/lib/jquery/secret_sauce/controller/ui_dialog_controls.rb +5 -5
  31. data/lib/jquery/secret_sauce/controller/ui_grid_controls.rb +5 -5
  32. data/lib/jquery/secret_sauce/helpers/ui_dialog_helper.rb +1 -1
  33. data/lib/jquery/secret_sauce/helpers/ui_form_helper.rb +39 -39
  34. data/lib/jquery/secret_sauce/helpers/ui_grid_helper.rb +74 -74
  35. data/lib/jquery/secret_sauce/model/find_for_grid.rb +21 -21
  36. data/lib/jquery/secret_sauce.rb +1 -1
  37. data/lib/jquery/tools.rb +1 -1
  38. data/lib/jquery_mobile_theme.rb +2 -2
  39. data/lib/jquery_ui_theme.rb +12 -12
  40. data/templates/dynatree/config/initializers/dynatree.rb +3 -3
  41. data/templates/dynatree/jquery/dynatree/aero.scss +16 -16
  42. data/templates/dynatree/jquery/dynatree/aqua.scss +16 -16
  43. data/templates/dynatree/jquery/dynatree/crystal.scss +16 -16
  44. data/templates/dynatree/jquery/dynatree/xp.scss +17 -17
  45. data/templates/dynatree/jquery.dynatree.js +2926 -2912
  46. data/templates/emulators/config/initializers/emulators.rb +6 -6
  47. data/templates/graphics/config/initializers/graphics.rb +5 -0
  48. data/templates/graphics/jquery/ganttView.scss +89 -0
  49. data/templates/graphics/jquery.ganttView.js +1669 -0
  50. data/templates/graphics/jquery.ganttView.min.js +70 -0
  51. data/templates/{jquery → graphics}/jquery.sparkline.js +466 -438
  52. data/templates/{jquery → graphics}/jquery.sparkline.min.js +0 -0
  53. data/templates/graphics/manifest.rb +9 -0
  54. data/templates/jqgrid/config/initializers/jqgrid.rb +1 -1
  55. data/templates/jqgrid/i18n/jqgrid/locale-ar.js +131 -125
  56. data/templates/jqgrid/i18n/jqgrid/locale-bg.js +135 -131
  57. data/templates/jqgrid/i18n/jqgrid/locale-bg1251.js +135 -131
  58. data/templates/jqgrid/i18n/jqgrid/locale-cat.js +132 -126
  59. data/templates/jqgrid/i18n/jqgrid/locale-cn.js +137 -131
  60. data/templates/jqgrid/i18n/jqgrid/locale-cs.js +133 -127
  61. data/templates/jqgrid/i18n/jqgrid/locale-da.js +132 -126
  62. data/templates/jqgrid/i18n/jqgrid/locale-de.js +138 -132
  63. data/templates/jqgrid/i18n/jqgrid/locale-el.js +131 -125
  64. data/templates/jqgrid/i18n/jqgrid/locale-en.js +133 -127
  65. data/templates/jqgrid/i18n/jqgrid/locale-es.js +133 -127
  66. data/templates/jqgrid/i18n/jqgrid/locale-fa.js +19 -16
  67. data/templates/jqgrid/i18n/jqgrid/locale-fi.js +132 -126
  68. data/templates/jqgrid/i18n/jqgrid/locale-fr.js +131 -125
  69. data/templates/jqgrid/i18n/jqgrid/locale-gl.js +131 -125
  70. data/templates/jqgrid/i18n/jqgrid/locale-he.js +132 -126
  71. data/templates/jqgrid/i18n/jqgrid/locale-hu.js +133 -127
  72. data/templates/jqgrid/i18n/jqgrid/locale-is.js +131 -125
  73. data/templates/jqgrid/i18n/jqgrid/locale-it.js +8 -1
  74. data/templates/jqgrid/i18n/jqgrid/locale-ja.js +139 -136
  75. data/templates/jqgrid/i18n/jqgrid/locale-nl.js +4 -1
  76. data/templates/jqgrid/i18n/jqgrid/locale-no.js +14 -1
  77. data/templates/jqgrid/i18n/jqgrid/locale-pl.js +132 -126
  78. data/templates/jqgrid/i18n/jqgrid/locale-pt-br.js +132 -126
  79. data/templates/jqgrid/i18n/jqgrid/locale-pt.js +130 -124
  80. data/templates/jqgrid/i18n/jqgrid/locale-ro.js +144 -138
  81. data/templates/jqgrid/i18n/jqgrid/locale-ru.js +132 -126
  82. data/templates/jqgrid/i18n/jqgrid/locale-sk.js +132 -126
  83. data/templates/jqgrid/i18n/jqgrid/locale-sr.js +133 -127
  84. data/templates/jqgrid/i18n/jqgrid/locale-sv.js +132 -126
  85. data/templates/jqgrid/i18n/jqgrid/locale-tr.js +131 -125
  86. data/templates/jqgrid/i18n/jqgrid/locale-ua.js +132 -126
  87. data/templates/jqgrid/jquery.jqGrid.js +12735 -10444
  88. data/templates/jqgrid/jquery.jqGrid.min.js +477 -469
  89. data/templates/jqgrid/public/stylesheets/ellipsis-xbl.xml +12 -10
  90. data/templates/jqtouch/config/initializers/jqtouch.rb +3 -3
  91. data/templates/jqtouch/jquery/touch/jqtouch.scss +1 -1
  92. data/templates/jqtouch/jquery.jqtouch.js +10025 -10043
  93. data/templates/jquery/config/initializers/jquery.rb +2 -4
  94. data/templates/jquery/history.adapter.jquery.js +71 -0
  95. data/templates/jquery/history.adapter.jquery.min.js +4 -0
  96. data/templates/jquery/history.html4.js +690 -0
  97. data/templates/jquery/history.html4.min.js +21 -0
  98. data/templates/jquery/history.js +1297 -0
  99. data/templates/jquery/history.min.js +29 -0
  100. data/templates/jquery/i18n/jquery.ui/datepicker-af.js +20 -20
  101. data/templates/jquery/i18n/jquery.ui/datepicker-ar-DZ.js +19 -19
  102. data/templates/jquery/i18n/jquery.ui/datepicker-ar.js +19 -19
  103. data/templates/jquery/i18n/jquery.ui/datepicker-az.js +19 -19
  104. data/templates/jquery/i18n/jquery.ui/datepicker-bg.js +8 -8
  105. data/templates/jquery/i18n/jquery.ui/datepicker-bs.js +20 -20
  106. data/templates/jquery/i18n/jquery.ui/datepicker-ca.js +20 -20
  107. data/templates/jquery/i18n/jquery.ui/datepicker-cs.js +20 -20
  108. data/templates/jquery/i18n/jquery.ui/datepicker-da.js +14 -14
  109. data/templates/jquery/i18n/jquery.ui/datepicker-de.js +20 -20
  110. data/templates/jquery/i18n/jquery.ui/datepicker-el.js +20 -20
  111. data/templates/jquery/i18n/jquery.ui/datepicker-en-AU.js +20 -20
  112. data/templates/jquery/i18n/jquery.ui/datepicker-en-GB.js +20 -20
  113. data/templates/jquery/i18n/jquery.ui/datepicker-en-NZ.js +20 -20
  114. data/templates/jquery/i18n/jquery.ui/datepicker-eo.js +20 -20
  115. data/templates/jquery/i18n/jquery.ui/datepicker-es.js +20 -20
  116. data/templates/jquery/i18n/jquery.ui/datepicker-et.js +20 -20
  117. data/templates/jquery/i18n/jquery.ui/datepicker-eu.js +20 -20
  118. data/templates/jquery/i18n/jquery.ui/datepicker-fa.js +18 -18
  119. data/templates/jquery/i18n/jquery.ui/datepicker-fi.js +15 -15
  120. data/templates/jquery/i18n/jquery.ui/datepicker-fo.js +20 -20
  121. data/templates/jquery/i18n/jquery.ui/datepicker-fr-CH.js +20 -20
  122. data/templates/jquery/i18n/jquery.ui/datepicker-fr.js +22 -22
  123. data/templates/jquery/i18n/jquery.ui/datepicker-gl.js +20 -20
  124. data/templates/jquery/i18n/jquery.ui/datepicker-he.js +20 -20
  125. data/templates/jquery/i18n/jquery.ui/datepicker-hr.js +20 -20
  126. data/templates/jquery/i18n/jquery.ui/datepicker-hu.js +20 -20
  127. data/templates/jquery/i18n/jquery.ui/datepicker-hu.min.js +1 -1
  128. data/templates/jquery/i18n/jquery.ui/datepicker-hy.js +20 -20
  129. data/templates/jquery/i18n/jquery.ui/datepicker-id.js +20 -20
  130. data/templates/jquery/i18n/jquery.ui/datepicker-is.js +20 -20
  131. data/templates/jquery/i18n/jquery.ui/datepicker-it.js +20 -20
  132. data/templates/jquery/i18n/jquery.ui/datepicker-ja.js +20 -20
  133. data/templates/jquery/i18n/jquery.ui/datepicker-ko.js +20 -20
  134. data/templates/jquery/i18n/jquery.ui/datepicker-kz.js +20 -20
  135. data/templates/jquery/i18n/jquery.ui/datepicker-lt.js +20 -20
  136. data/templates/jquery/i18n/jquery.ui/datepicker-lv.js +20 -20
  137. data/templates/jquery/i18n/jquery.ui/datepicker-ml.js +20 -20
  138. data/templates/jquery/i18n/jquery.ui/datepicker-ms.js +20 -20
  139. data/templates/jquery/i18n/jquery.ui/datepicker-nl.js +20 -20
  140. data/templates/jquery/i18n/jquery.ui/datepicker-no.js +16 -16
  141. data/templates/jquery/i18n/jquery.ui/datepicker-no.min.js +2 -2
  142. data/templates/jquery/i18n/jquery.ui/datepicker-pl.js +20 -20
  143. data/templates/jquery/i18n/jquery.ui/datepicker-pt-BR.js +20 -20
  144. data/templates/jquery/i18n/jquery.ui/datepicker-pt.js +20 -20
  145. data/templates/jquery/i18n/jquery.ui/datepicker-rm.js +18 -18
  146. data/templates/jquery/i18n/jquery.ui/datepicker-ro.js +20 -20
  147. data/templates/jquery/i18n/jquery.ui/datepicker-ru.js +20 -20
  148. data/templates/jquery/i18n/jquery.ui/datepicker-sk.js +20 -20
  149. data/templates/jquery/i18n/jquery.ui/datepicker-sl.js +20 -20
  150. data/templates/jquery/i18n/jquery.ui/datepicker-sq.js +20 -20
  151. data/templates/jquery/i18n/jquery.ui/datepicker-sr-SR.js +20 -20
  152. data/templates/jquery/i18n/jquery.ui/datepicker-sr.js +20 -20
  153. data/templates/jquery/i18n/jquery.ui/datepicker-sv.js +14 -14
  154. data/templates/jquery/i18n/jquery.ui/datepicker-ta.js +20 -20
  155. data/templates/jquery/i18n/jquery.ui/datepicker-th.js +20 -20
  156. data/templates/jquery/i18n/jquery.ui/datepicker-tr.js +20 -20
  157. data/templates/jquery/i18n/jquery.ui/datepicker-uk.js +20 -20
  158. data/templates/jquery/i18n/jquery.ui/datepicker-vi.js +20 -20
  159. data/templates/jquery/i18n/jquery.ui/datepicker-zh-CN.js +20 -20
  160. data/templates/jquery/i18n/jquery.ui/datepicker-zh-HK.js +20 -20
  161. data/templates/jquery/i18n/jquery.ui/datepicker-zh-TW.js +20 -20
  162. data/templates/jquery/{partials → jquery/ui}/_flash_messages.scss +0 -0
  163. data/templates/jquery/jquery/ui/_theme.scss +14 -13
  164. data/templates/jquery/jquery/ui/contextMenu/configure.png +0 -0
  165. data/templates/jquery/jquery/ui/contextMenu/copy.png +0 -0
  166. data/templates/jquery/jquery/ui/contextMenu/cut.png +0 -0
  167. data/templates/jquery/jquery/ui/contextMenu/delete.png +0 -0
  168. data/templates/jquery/jquery/ui/contextMenu/edit.png +0 -0
  169. data/templates/jquery/jquery/ui/contextMenu/exit.png +0 -0
  170. data/templates/jquery/jquery/ui/contextMenu/new.png +0 -0
  171. data/templates/jquery/jquery/ui/contextMenu/paste.png +0 -0
  172. data/templates/jquery/jquery/ui/contextMenu/rename.png +0 -0
  173. data/templates/jquery/jquery/ui/contextMenu/show.png +0 -0
  174. data/templates/jquery/jquery/ui/contextMenu/trash.png +0 -0
  175. data/templates/jquery/jquery/ui/contextMenu.scss +16 -10
  176. data/templates/jquery/jquery-ui.js +11839 -23066
  177. data/templates/jquery/jquery-ui.min.js +401 -795
  178. data/templates/jquery/jquery.bgiframe.js +27 -25
  179. data/templates/jquery/jquery.contextMenu.js +209 -196
  180. data/templates/jquery/jquery.cookie.js +3 -1
  181. data/templates/jquery/jquery.dotimeout.js +236 -228
  182. data/templates/jquery/jquery.dst.js +154 -151
  183. data/templates/jquery/jquery.farbtastic.js +293 -293
  184. data/templates/jquery/jquery.flashMessages.js +26 -0
  185. data/templates/jquery/jquery.flashMessages.min.js +1 -0
  186. data/templates/jquery/jquery.form.js +803 -786
  187. data/templates/jquery/jquery.haml.js +248 -247
  188. data/templates/jquery/jquery.hotkeys.js +89 -89
  189. data/templates/jquery/jquery.js +8141 -8106
  190. data/templates/jquery/jquery.layout.js +2451 -2415
  191. data/templates/jquery/jquery.min.js +167 -166
  192. data/templates/jquery/jquery.mousewheel.js +62 -54
  193. data/templates/jquery/jquery.offline.js +171 -171
  194. data/templates/jquery/jquery.pngFix.js +76 -76
  195. data/templates/jquery/jquery.replacetext.js +83 -83
  196. data/templates/jquery/jquery.themeswitchertool.js +202 -177
  197. data/templates/jquery/jquery.tmpl.js +478 -473
  198. data/templates/jquery/jquery.tmplPlus.js +82 -81
  199. data/templates/jquery/jrails.js +178 -175
  200. data/templates/jquery/json.js +77 -7
  201. data/templates/jquery/json2.js +480 -0
  202. data/templates/jquery/json2.min.js +7 -0
  203. data/templates/jquery/lib/tasks/haml.rake +2 -2
  204. data/templates/jquery/manifest.rb +21 -17
  205. data/templates/jstree/jquery.jstree.js +5967 -4536
  206. data/templates/mobile/config/initializers/mobile.rb +1 -1
  207. data/templates/mobile/jquery/mobile/_base.scss +944 -927
  208. data/templates/mobile/jquery/mobile/default.scss +61 -48
  209. data/templates/mobile/jquery/mobile/valencia.scss +56 -42
  210. data/templates/mobile/jquery.mobile.js +4461 -4347
  211. data/templates/mobile/jquery.mobile.min.js +11 -2
  212. data/templates/mobile/lib/tasks/jquery.mobile.rake +12 -12
  213. data/templates/ribbon/config/initializers/ribbon.rb +2 -2
  214. data/templates/ribbon/jquery.ribbon.js +50 -29
  215. data/templates/secret_sauce/secret_sauce.js +8 -8
  216. data/templates/tools/flowplayer.js +945 -1
  217. data/templates/tools/jquery.tools.js +4645 -4335
  218. data/templates/tools/jquery.tools.min.js +37 -37
  219. data/templates/tools/lib/tasks/jquery.tools.rake +4 -4
  220. data/templates/tools/swfobject.js +813 -773
  221. metadata +33 -21
  222. data/templates/jquery/haml.js +0 -506
  223. data/templates/jquery/haml.min.js +0 -5
  224. data/templates/jquery/jquery/ui/contextMenu/door.png +0 -0
  225. data/templates/jquery/jquery/ui/contextMenu/page_white_copy.png +0 -0
  226. data/templates/jquery/jquery/ui/contextMenu/page_white_delete.png +0 -0
  227. data/templates/jquery/jquery/ui/contextMenu/page_white_edit.png +0 -0
  228. data/templates/jquery/jquery/ui/contextMenu/page_white_new.png +0 -0
  229. data/templates/jquery/jquery/ui/contextMenu/page_white_paste.png +0 -0
  230. data/templates/jquery/jquery.compat-1.3.js +0 -291
  231. data/templates/jquery/jquery.compat-1.3.min.js +0 -6
  232. data/templates/jquery/jquery.flash_messages.js +0 -5
  233. data/templates/jquery/jquery.flash_messages.min.js +0 -1
  234. data/templates/jquery/jquery.history.js +0 -194
  235. data/templates/jquery/jquery.history.min.js +0 -5
@@ -0,0 +1,26 @@
1
+ //
2
+ // Adding some animation to flash messages
3
+ // Idea from http://stackoverflow.com/questions/316278/timeout-jquery-effects
4
+ //
5
+ // Copyright (c) 2011 Kosmas Schütz
6
+ //
7
+
8
+ (function($) {
9
+
10
+ // Parameters are:
11
+ // time for fadeIn
12
+ // time the message is shown
13
+ // time for fadeOut
14
+
15
+ $.fn.flashMessages = function(timeIn, timeStay, timeOut) {
16
+
17
+ var el = $(this.selector + " .success, " + this.selector + " .notice, " + this.selector + " .warning, " + this.selector + " .error");
18
+ el.fadeIn(timeIn);
19
+ el.queue(function() {
20
+ setTimeout(function() {
21
+ el.dequeue();
22
+ }, timeStay);
23
+ });
24
+ el.fadeOut(timeOut);
25
+ };
26
+ })(jQuery);
@@ -0,0 +1 @@
1
+ (function(b){b.fn.flashMessages=function(c,d,e){var a=b(this.selector+" .success, "+this.selector+" .notice, "+this.selector+" .warning, "+this.selector+" .error");a.fadeIn(c);a.queue(function(){setTimeout(function(){a.dequeue()},d)});a.fadeOut(e)}})(jQuery);
@@ -8,796 +8,813 @@
8
8
  * http://www.opensource.org/licenses/mit-license.php
9
9
  * http://www.gnu.org/licenses/gpl.html
10
10
  */
11
- ;(function($) {
12
-
13
- /*
14
- Usage Note:
15
- -----------
16
- Do not use both ajaxSubmit and ajaxForm on the same form. These
17
- functions are intended to be exclusive. Use ajaxSubmit if you want
18
- to bind your own submit handler to the form. For example,
19
-
20
- $(document).ready(function() {
21
- $('#myForm').bind('submit', function(e) {
22
- e.preventDefault(); // <-- important
23
- $(this).ajaxSubmit({
24
- target: '#output'
25
- });
26
- });
27
- });
28
-
29
- Use ajaxForm when you want the plugin to manage all the event binding
30
- for you. For example,
31
-
32
- $(document).ready(function() {
33
- $('#myForm').ajaxForm({
34
- target: '#output'
35
- });
36
- });
37
-
38
- When using ajaxForm, the ajaxSubmit function will be invoked for you
39
- at the appropriate time.
40
- */
41
-
42
- /**
43
- * ajaxSubmit() provides a mechanism for immediately submitting
44
- * an HTML form using AJAX.
45
- */
46
- $.fn.ajaxSubmit = function(options) {
47
- // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
48
- if (!this.length) {
49
- log('ajaxSubmit: skipping submit process - no element selected');
50
- return this;
51
- }
52
-
53
- if (typeof options == 'function') {
54
- options = { success: options };
55
- }
56
-
57
- var action = this.attr('action');
58
- var url = (typeof action === 'string') ? $.trim(action) : '';
59
- if (url) {
60
- // clean url (don't include hash vaue)
61
- url = (url.match(/^([^#]+)/)||[])[1];
62
- }
63
- url = url || window.location.href || '';
64
-
65
- options = $.extend(true, {
66
- url: url,
67
- type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57)
68
- iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
69
- }, options);
70
-
71
- // hook for manipulating the form data before it is extracted;
72
- // convenient for use with rich editors like tinyMCE or FCKEditor
73
- var veto = {};
74
- this.trigger('form-pre-serialize', [this, options, veto]);
75
- if (veto.veto) {
76
- log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
77
- return this;
78
- }
79
-
80
- // provide opportunity to alter form data before it is serialized
81
- if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
82
- log('ajaxSubmit: submit aborted via beforeSerialize callback');
83
- return this;
84
- }
85
-
86
- var n,v,a = this.formToArray(options.semantic);
87
- if (options.data) {
88
- options.extraData = options.data;
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
- }
100
- }
101
- }
102
-
103
- // give pre-submit callback an opportunity to abort the submit
104
- if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
105
- log('ajaxSubmit: submit aborted via beforeSubmit callback');
106
- return this;
107
- }
108
-
109
- // fire vetoable 'validate' event
110
- this.trigger('form-submit-validate', [a, this, options, veto]);
111
- if (veto.veto) {
112
- log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
113
- return this;
114
- }
115
-
116
- var q = $.param(a);
117
-
118
- if (options.type.toUpperCase() == 'GET') {
119
- options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
120
- options.data = null; // data is null for 'get'
121
- }
122
- else {
123
- options.data = q; // data is the query string for 'post'
124
- }
125
-
126
- var $form = this, callbacks = [];
127
- if (options.resetForm) {
128
- callbacks.push(function() { $form.resetForm(); });
129
- }
130
- if (options.clearForm) {
131
- callbacks.push(function() { $form.clearForm(); });
132
- }
133
-
134
- // perform a load on the target only if dataType is not provided
135
- if (!options.dataType && options.target) {
136
- var oldSuccess = options.success || function(){};
137
- callbacks.push(function(data) {
138
- var fn = options.replaceTarget ? 'replaceWith' : 'html';
139
- $(options.target)[fn](data).each(oldSuccess, arguments);
140
- });
141
- }
142
- else if (options.success) {
143
- callbacks.push(options.success);
144
- }
145
-
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
- }
151
- };
152
-
153
- // are there files to upload?
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);
157
-
158
- // options.iframe allows user to force iframe mode
159
- // 06-NOV-09: now defaulting to iframe mode if file input is detected
160
- if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
161
- // hack to fix Safari hang (thanks to Tim Molendijk for this)
162
- // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
163
- if (options.closeKeepAlive) {
164
- $.get(options.closeKeepAlive, fileUpload);
165
- }
166
- else {
167
- fileUpload();
168
- }
169
- }
170
- else {
171
- $.ajax(options);
172
- }
173
-
174
- // fire 'notify' event
175
- this.trigger('form-submit-notify', [this, options]);
176
- return this;
177
-
178
-
179
- // private function for handling file uploads (hat tip to YAHOO!)
180
- function fileUpload() {
181
- var form = $form[0];
182
-
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".');
187
- return;
188
- }
189
-
190
- var s = $.extend(true, {}, $.ajaxSettings, options);
191
- s.context = s.context || s;
192
- var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id;
193
- var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" />');
194
- var io = $io[0];
195
-
196
- $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
197
-
198
- var xhr = { // mock object
199
- aborted: 0,
200
- responseText: null,
201
- responseXML: null,
202
- status: 0,
203
- statusText: 'n/a',
204
- getAllResponseHeaders: function() {},
205
- getResponseHeader: function() {},
206
- setRequestHeader: function() {},
207
- abort: function() {
208
- this.aborted = 1;
209
- $io.attr('src', s.iframeSrc); // abort op in progress
210
- }
211
- };
212
-
213
- var g = s.global;
214
- // trigger ajax global events so that activity/block indicators work like normal
215
- if (g && ! $.active++) {
216
- $.event.trigger("ajaxStart");
217
- }
218
- if (g) {
219
- $.event.trigger("ajaxSend", [xhr, s]);
220
- }
221
-
222
- if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
223
- if (s.global) {
224
- $.active--;
225
- }
226
- return;
227
- }
228
- if (xhr.aborted) {
229
- return;
230
- }
231
-
232
- var timedOut = 0;
233
-
234
- // add submitting element to data if we know it
235
- var sub = form.clk;
236
- if (sub) {
237
- var n = sub.name;
238
- if (n && !sub.disabled) {
239
- s.extraData = s.extraData || {};
240
- s.extraData[n] = sub.value;
241
- if (sub.type == "image") {
242
- s.extraData[n+'.x'] = form.clk_x;
243
- s.extraData[n+'.y'] = form.clk_y;
244
- }
245
- }
246
- }
247
-
248
- // take a breath so that pending repaints get some cpu time before the upload starts
249
- function doSubmit() {
250
- // make sure form attrs are set
251
- var t = $form.attr('target'), a = $form.attr('action');
252
-
253
- // update form attrs in IE friendly way
254
- form.setAttribute('target',id);
255
- if (form.getAttribute('method') != 'POST') {
256
- form.setAttribute('method', 'POST');
257
- }
258
- if (form.getAttribute('action') != s.url) {
259
- form.setAttribute('action', s.url);
260
- }
261
-
262
- // ie borks in some cases when setting encoding
263
- if (! s.skipEncodingOverride) {
264
- $form.attr({
265
- encoding: 'multipart/form-data',
266
- enctype: 'multipart/form-data'
267
- });
268
- }
269
-
270
- // support timout
271
- if (s.timeout) {
272
- setTimeout(function() { timedOut = true; cb(); }, s.timeout);
273
- }
274
-
275
- // add "extra" data to form if provided in options
276
- var extraInputs = [];
277
- try {
278
- if (s.extraData) {
279
- for (var n in s.extraData) {
280
- extraInputs.push(
281
- $('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
282
- .appendTo(form)[0]);
283
- }
284
- }
285
-
286
- // add iframe to doc and submit the form
287
- $io.appendTo('body');
288
- io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
289
- form.submit();
290
- }
291
- finally {
292
- // reset attrs and remove "extra" input elements
293
- form.setAttribute('action',a);
294
- if(t) {
295
- form.setAttribute('target', t);
296
- } else {
297
- $form.removeAttr('target');
298
- }
299
- $(extraInputs).remove();
300
- }
301
- }
302
-
303
- if (s.forceSync) {
304
- doSubmit();
305
- }
306
- else {
307
- setTimeout(doSubmit, 10); // this lets dom updates render
308
- }
309
-
310
- var data, doc, domCheckCount = 50;
311
-
312
- function cb() {
313
- doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
314
- if (!doc || doc.location.href == s.iframeSrc) {
315
- // response not received yet
316
- return;
317
- }
318
- io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
319
-
320
- var ok = true;
321
- try {
322
- if (timedOut) {
323
- throw 'timeout';
324
- }
325
-
326
- var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
327
- log('isXml='+isXml);
328
- if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
329
- if (--domCheckCount) {
330
- // in some browsers (Opera) the iframe DOM is not always traversable when
331
- // the onload callback fires, so we loop a bit to accommodate
332
- log('requeing onLoad callback, DOM not available');
333
- setTimeout(cb, 250);
334
- return;
335
- }
336
- // let this fall through because server response could be an empty document
337
- //log('Could not access iframe DOM after mutiple tries.');
338
- //throw 'DOMException: not available';
339
- }
340
-
341
- //log('response detected');
342
- xhr.responseText = doc.body ? doc.body.innerHTML : doc.documentElement ? doc.documentElement.innerHTML : null;
343
- xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
344
- xhr.getResponseHeader = function(header){
345
- var headers = {'content-type': s.dataType};
346
- return headers[header];
347
- };
348
-
349
- var scr = /(json|script)/.test(s.dataType);
350
- if (scr || s.textarea) {
351
- // see if user embedded response in textarea
352
- var ta = doc.getElementsByTagName('textarea')[0];
353
- if (ta) {
354
- xhr.responseText = ta.value;
355
- }
356
- else if (scr) {
357
- // account for browsers injecting pre around json response
358
- var pre = doc.getElementsByTagName('pre')[0];
359
- var b = doc.getElementsByTagName('body')[0];
360
- if (pre) {
361
- xhr.responseText = pre.textContent;
362
- }
363
- else if (b) {
364
- xhr.responseText = b.innerHTML;
365
- }
366
- }
367
- }
368
- else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
369
- xhr.responseXML = toXml(xhr.responseText);
370
- }
371
-
372
- data = httpData(xhr, s.dataType, s);
373
- }
374
- catch(e){
375
- log('error caught:',e);
376
- ok = false;
377
- xhr.error = e;
378
- s.error.call(s.context, xhr, 'error', e);
379
- g && $.event.trigger("ajaxError", [xhr, s, e]);
380
- }
381
-
382
- if (xhr.aborted) {
383
- log('upload aborted');
384
- ok = false;
385
- }
386
-
387
- // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
388
- if (ok) {
389
- s.success.call(s.context, data, 'success', xhr);
390
- g && $.event.trigger("ajaxSuccess", [xhr, s]);
391
- }
392
-
393
- g && $.event.trigger("ajaxComplete", [xhr, s]);
394
-
395
- if (g && ! --$.active) {
396
- $.event.trigger("ajaxStop");
397
- }
398
-
399
- s.complete && s.complete.call(s.context, xhr, ok ? 'success' : 'error');
400
-
401
- // clean up
402
- setTimeout(function() {
403
- $io.removeData('form-plugin-onload');
404
- $io.remove();
405
- xhr.responseXML = null;
406
- }, 100);
407
- }
408
-
409
- var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
410
- if (window.ActiveXObject) {
411
- doc = new ActiveXObject('Microsoft.XMLDOM');
412
- doc.async = 'false';
413
- doc.loadXML(s);
414
- }
415
- else {
416
- doc = (new DOMParser()).parseFromString(s, 'text/xml');
417
- }
418
- return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
419
- };
420
- var parseJSON = $.parseJSON || function(s) {
421
- return window['eval']('(' + s + ')');
422
- };
423
-
424
- var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
425
- var ct = xhr.getResponseHeader('content-type') || '',
426
- xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
427
- data = xml ? xhr.responseXML : xhr.responseText;
428
-
429
- if (xml && data.documentElement.nodeName === 'parsererror') {
430
- $.error && $.error('parsererror');
431
- }
432
- if (s && s.dataFilter) {
433
- data = s.dataFilter(data, type);
434
- }
435
- if (typeof data === 'string') {
436
- if (type === 'json' || !type && ct.indexOf('json') >= 0) {
437
- data = parseJSON(data);
438
- } else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
439
- $.globalEval(data);
440
- }
441
- }
442
- return data;
443
- };
444
- }
445
- };
446
-
447
- /**
448
- * ajaxForm() provides a mechanism for fully automating form submission.
449
- *
450
- * The advantages of using this method instead of ajaxSubmit() are:
451
- *
452
- * 1: This method will include coordinates for <input type="image" /> elements (if the element
453
- * is used to submit the form).
454
- * 2. This method will include the submit element's name/value data (for the element that was
455
- * used to submit the form).
456
- * 3. This method binds the submit() method to the form for you.
457
- *
458
- * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
459
- * passes the options argument along after properly binding events for submit elements and
460
- * the form itself.
461
- */
462
- $.fn.ajaxForm = function(options) {
463
- // in jQuery 1.3+ we can fix mistakes with the ready state
464
- if (this.length === 0) {
465
- var o = { s: this.selector, c: this.context };
466
- if (!$.isReady && o.s) {
467
- log('DOM not ready, queuing ajaxForm');
468
- $(function() {
469
- $(o.s,o.c).ajaxForm(options);
470
- });
471
- return this;
472
- }
473
- // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
474
- log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
475
- return this;
476
- }
477
-
478
- return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
479
- if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
480
- e.preventDefault();
481
- $(this).ajaxSubmit(options);
482
- }
483
- }).bind('click.form-plugin', function(e) {
484
- var target = e.target;
485
- var $el = $(target);
486
- if (!($el.is(":submit,input:image"))) {
487
- // is this a child element of the submit el? (ex: a span within a button)
488
- var t = $el.closest(':submit');
489
- if (t.length == 0) {
490
- return;
491
- }
492
- target = t[0];
493
- }
494
- var form = this;
495
- form.clk = target;
496
- if (target.type == 'image') {
497
- if (e.offsetX != undefined) {
498
- form.clk_x = e.offsetX;
499
- form.clk_y = e.offsetY;
500
- } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
501
- var offset = $el.offset();
502
- form.clk_x = e.pageX - offset.left;
503
- form.clk_y = e.pageY - offset.top;
504
- } else {
505
- form.clk_x = e.pageX - target.offsetLeft;
506
- form.clk_y = e.pageY - target.offsetTop;
507
- }
508
- }
509
- // clear form vars
510
- setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
511
- });
512
- };
11
+ ;
12
+ (function($) {
13
+
14
+ /*
15
+ Usage Note:
16
+ -----------
17
+ Do not use both ajaxSubmit and ajaxForm on the same form. These
18
+ functions are intended to be exclusive. Use ajaxSubmit if you want
19
+ to bind your own submit handler to the form. For example,
20
+
21
+ $(document).ready(function() {
22
+ $('#myForm').bind('submit', function(e) {
23
+ e.preventDefault(); // <-- important
24
+ $(this).ajaxSubmit({
25
+ target: '#output'
26
+ });
27
+ });
28
+ });
29
+
30
+ Use ajaxForm when you want the plugin to manage all the event binding
31
+ for you. For example,
32
+
33
+ $(document).ready(function() {
34
+ $('#myForm').ajaxForm({
35
+ target: '#output'
36
+ });
37
+ });
38
+
39
+ When using ajaxForm, the ajaxSubmit function will be invoked for you
40
+ at the appropriate time.
41
+ */
42
+
43
+ /**
44
+ * ajaxSubmit() provides a mechanism for immediately submitting
45
+ * an HTML form using AJAX.
46
+ */
47
+ $.fn.ajaxSubmit = function(options) {
48
+ // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
49
+ if (!this.length) {
50
+ log('ajaxSubmit: skipping submit process - no element selected');
51
+ return this;
52
+ }
53
+
54
+ if (typeof options == 'function') {
55
+ options = { success: options };
56
+ }
57
+
58
+ var action = this.attr('action');
59
+ var url = (typeof action === 'string') ? $.trim(action) : '';
60
+ if (url) {
61
+ // clean url (don't include hash vaue)
62
+ url = (url.match(/^([^#]+)/) || [])[1];
63
+ }
64
+ url = url || window.location.href || '';
65
+
66
+ options = $.extend(true, {
67
+ url: url,
68
+ type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57)
69
+ iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
70
+ }, options);
71
+
72
+ // hook for manipulating the form data before it is extracted;
73
+ // convenient for use with rich editors like tinyMCE or FCKEditor
74
+ var veto = {};
75
+ this.trigger('form-pre-serialize', [this, options, veto]);
76
+ if (veto.veto) {
77
+ log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
78
+ return this;
79
+ }
80
+
81
+ // provide opportunity to alter form data before it is serialized
82
+ if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
83
+ log('ajaxSubmit: submit aborted via beforeSerialize callback');
84
+ return this;
85
+ }
86
+
87
+ var n,v,a = this.formToArray(options.semantic);
88
+ if (options.data) {
89
+ options.extraData = options.data;
90
+ for (n in options.data) {
91
+ if (options.data[n] instanceof Array) {
92
+ for (var k in options.data[n]) {
93
+ a.push({ name: n, value: options.data[n][k] });
94
+ }
95
+ }
96
+ else {
97
+ v = options.data[n];
98
+ v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
99
+ a.push({ name: n, value: v });
100
+ }
101
+ }
102
+ }
103
+
104
+ // give pre-submit callback an opportunity to abort the submit
105
+ if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
106
+ log('ajaxSubmit: submit aborted via beforeSubmit callback');
107
+ return this;
108
+ }
109
+
110
+ // fire vetoable 'validate' event
111
+ this.trigger('form-submit-validate', [a, this, options, veto]);
112
+ if (veto.veto) {
113
+ log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
114
+ return this;
115
+ }
116
+
117
+ var q = $.param(a);
118
+
119
+ if (options.type.toUpperCase() == 'GET') {
120
+ options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
121
+ options.data = null; // data is null for 'get'
122
+ }
123
+ else {
124
+ options.data = q; // data is the query string for 'post'
125
+ }
126
+
127
+ var $form = this, callbacks = [];
128
+ if (options.resetForm) {
129
+ callbacks.push(function() {
130
+ $form.resetForm();
131
+ });
132
+ }
133
+ if (options.clearForm) {
134
+ callbacks.push(function() {
135
+ $form.clearForm();
136
+ });
137
+ }
138
+
139
+ // perform a load on the target only if dataType is not provided
140
+ if (!options.dataType && options.target) {
141
+ var oldSuccess = options.success || function() {
142
+ };
143
+ callbacks.push(function(data) {
144
+ var fn = options.replaceTarget ? 'replaceWith' : 'html';
145
+ $(options.target)[fn](data).each(oldSuccess, arguments);
146
+ });
147
+ }
148
+ else if (options.success) {
149
+ callbacks.push(options.success);
150
+ }
151
+
152
+ options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
153
+ var context = options.context || options; // jQuery 1.4+ supports scope context
154
+ for (var i = 0, max = callbacks.length; i < max; i++) {
155
+ callbacks[i].apply(context, [data, status, xhr || $form, $form]);
156
+ }
157
+ };
158
+
159
+ // are there files to upload?
160
+ var fileInputs = $('input:file', this).length > 0;
161
+ var mp = 'multipart/form-data';
162
+ var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
163
+
164
+ // options.iframe allows user to force iframe mode
165
+ // 06-NOV-09: now defaulting to iframe mode if file input is detected
166
+ if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
167
+ // hack to fix Safari hang (thanks to Tim Molendijk for this)
168
+ // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
169
+ if (options.closeKeepAlive) {
170
+ $.get(options.closeKeepAlive, fileUpload);
171
+ }
172
+ else {
173
+ fileUpload();
174
+ }
175
+ }
176
+ else {
177
+ $.ajax(options);
178
+ }
179
+
180
+ // fire 'notify' event
181
+ this.trigger('form-submit-notify', [this, options]);
182
+ return this;
183
+
184
+
185
+ // private function for handling file uploads (hat tip to YAHOO!)
186
+ function fileUpload() {
187
+ var form = $form[0];
188
+
189
+ if ($(':input[name=submit],:input[id=submit]', form).length) {
190
+ // if there is an input with a name or id of 'submit' then we won't be
191
+ // able to invoke the submit fn on the form (at least not x-browser)
192
+ alert('Error: Form elements must not have name or id of "submit".');
193
+ return;
194
+ }
195
+
196
+ var s = $.extend(true, {}, $.ajaxSettings, options);
197
+ s.context = s.context || s;
198
+ var id = 'jqFormIO' + (new Date().getTime()), fn = '_' + id;
199
+ var $io = $('<iframe id="' + id + '" name="' + id + '" src="' + s.iframeSrc + '" />');
200
+ var io = $io[0];
201
+
202
+ $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
203
+
204
+ var xhr = { // mock object
205
+ aborted: 0,
206
+ responseText: null,
207
+ responseXML: null,
208
+ status: 0,
209
+ statusText: 'n/a',
210
+ getAllResponseHeaders: function() {
211
+ },
212
+ getResponseHeader: function() {
213
+ },
214
+ setRequestHeader: function() {
215
+ },
216
+ abort: function() {
217
+ this.aborted = 1;
218
+ $io.attr('src', s.iframeSrc); // abort op in progress
219
+ }
220
+ };
221
+
222
+ var g = s.global;
223
+ // trigger ajax global events so that activity/block indicators work like normal
224
+ if (g && ! $.active++) {
225
+ $.event.trigger("ajaxStart");
226
+ }
227
+ if (g) {
228
+ $.event.trigger("ajaxSend", [xhr, s]);
229
+ }
230
+
231
+ if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
232
+ if (s.global) {
233
+ $.active--;
234
+ }
235
+ return;
236
+ }
237
+ if (xhr.aborted) {
238
+ return;
239
+ }
240
+
241
+ var timedOut = 0;
242
+
243
+ // add submitting element to data if we know it
244
+ var sub = form.clk;
245
+ if (sub) {
246
+ var n = sub.name;
247
+ if (n && !sub.disabled) {
248
+ s.extraData = s.extraData || {};
249
+ s.extraData[n] = sub.value;
250
+ if (sub.type == "image") {
251
+ s.extraData[n + '.x'] = form.clk_x;
252
+ s.extraData[n + '.y'] = form.clk_y;
253
+ }
254
+ }
255
+ }
256
+
257
+ // take a breath so that pending repaints get some cpu time before the upload starts
258
+ function doSubmit() {
259
+ // make sure form attrs are set
260
+ var t = $form.attr('target'), a = $form.attr('action');
261
+
262
+ // update form attrs in IE friendly way
263
+ form.setAttribute('target', id);
264
+ if (form.getAttribute('method') != 'POST') {
265
+ form.setAttribute('method', 'POST');
266
+ }
267
+ if (form.getAttribute('action') != s.url) {
268
+ form.setAttribute('action', s.url);
269
+ }
270
+
271
+ // ie borks in some cases when setting encoding
272
+ if (! s.skipEncodingOverride) {
273
+ $form.attr({
274
+ encoding: 'multipart/form-data',
275
+ enctype: 'multipart/form-data'
276
+ });
277
+ }
278
+
279
+ // support timout
280
+ if (s.timeout) {
281
+ setTimeout(function() {
282
+ timedOut = true;
283
+ cb();
284
+ }, s.timeout);
285
+ }
286
+
287
+ // add "extra" data to form if provided in options
288
+ var extraInputs = [];
289
+ try {
290
+ if (s.extraData) {
291
+ for (var n in s.extraData) {
292
+ extraInputs.push(
293
+ $('<input type="hidden" name="' + n + '" value="' + s.extraData[n] + '" />')
294
+ .appendTo(form)[0]);
295
+ }
296
+ }
297
+
298
+ // add iframe to doc and submit the form
299
+ $io.appendTo('body');
300
+ io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
301
+ form.submit();
302
+ }
303
+ finally {
304
+ // reset attrs and remove "extra" input elements
305
+ form.setAttribute('action', a);
306
+ if (t) {
307
+ form.setAttribute('target', t);
308
+ } else {
309
+ $form.removeAttr('target');
310
+ }
311
+ $(extraInputs).remove();
312
+ }
313
+ }
314
+
315
+ if (s.forceSync) {
316
+ doSubmit();
317
+ }
318
+ else {
319
+ setTimeout(doSubmit, 10); // this lets dom updates render
320
+ }
321
+
322
+ var data, doc, domCheckCount = 50;
323
+
324
+ function cb() {
325
+ doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
326
+ if (!doc || doc.location.href == s.iframeSrc) {
327
+ // response not received yet
328
+ return;
329
+ }
330
+ io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
331
+
332
+ var ok = true;
333
+ try {
334
+ if (timedOut) {
335
+ throw 'timeout';
336
+ }
337
+
338
+ var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
339
+ log('isXml=' + isXml);
340
+ if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
341
+ if (--domCheckCount) {
342
+ // in some browsers (Opera) the iframe DOM is not always traversable when
343
+ // the onload callback fires, so we loop a bit to accommodate
344
+ log('requeing onLoad callback, DOM not available');
345
+ setTimeout(cb, 250);
346
+ return;
347
+ }
348
+ // let this fall through because server response could be an empty document
349
+ //log('Could not access iframe DOM after mutiple tries.');
350
+ //throw 'DOMException: not available';
351
+ }
352
+
353
+ //log('response detected');
354
+ xhr.responseText = doc.body ? doc.body.innerHTML : doc.documentElement ? doc.documentElement.innerHTML : null;
355
+ xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
356
+ xhr.getResponseHeader = function(header) {
357
+ var headers = {'content-type': s.dataType};
358
+ return headers[header];
359
+ };
360
+
361
+ var scr = /(json|script)/.test(s.dataType);
362
+ if (scr || s.textarea) {
363
+ // see if user embedded response in textarea
364
+ var ta = doc.getElementsByTagName('textarea')[0];
365
+ if (ta) {
366
+ xhr.responseText = ta.value;
367
+ }
368
+ else if (scr) {
369
+ // account for browsers injecting pre around json response
370
+ var pre = doc.getElementsByTagName('pre')[0];
371
+ var b = doc.getElementsByTagName('body')[0];
372
+ if (pre) {
373
+ xhr.responseText = pre.textContent;
374
+ }
375
+ else if (b) {
376
+ xhr.responseText = b.innerHTML;
377
+ }
378
+ }
379
+ }
380
+ else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
381
+ xhr.responseXML = toXml(xhr.responseText);
382
+ }
383
+
384
+ data = httpData(xhr, s.dataType, s);
385
+ }
386
+ catch(e) {
387
+ log('error caught:', e);
388
+ ok = false;
389
+ xhr.error = e;
390
+ s.error.call(s.context, xhr, 'error', e);
391
+ g && $.event.trigger("ajaxError", [xhr, s, e]);
392
+ }
393
+
394
+ if (xhr.aborted) {
395
+ log('upload aborted');
396
+ ok = false;
397
+ }
398
+
399
+ // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
400
+ if (ok) {
401
+ s.success.call(s.context, data, 'success', xhr);
402
+ g && $.event.trigger("ajaxSuccess", [xhr, s]);
403
+ }
404
+
405
+ g && $.event.trigger("ajaxComplete", [xhr, s]);
406
+
407
+ if (g && ! --$.active) {
408
+ $.event.trigger("ajaxStop");
409
+ }
410
+
411
+ s.complete && s.complete.call(s.context, xhr, ok ? 'success' : 'error');
412
+
413
+ // clean up
414
+ setTimeout(function() {
415
+ $io.removeData('form-plugin-onload');
416
+ $io.remove();
417
+ xhr.responseXML = null;
418
+ }, 100);
419
+ }
420
+
421
+ var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
422
+ if (window.ActiveXObject) {
423
+ doc = new ActiveXObject('Microsoft.XMLDOM');
424
+ doc.async = 'false';
425
+ doc.loadXML(s);
426
+ }
427
+ else {
428
+ doc = (new DOMParser()).parseFromString(s, 'text/xml');
429
+ }
430
+ return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
431
+ };
432
+ var parseJSON = $.parseJSON || function(s) {
433
+ return window['eval']('(' + s + ')');
434
+ };
435
+
436
+ var httpData = function(xhr, type, s) { // mostly lifted from jq1.4.4
437
+ var ct = xhr.getResponseHeader('content-type') || '',
438
+ xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
439
+ data = xml ? xhr.responseXML : xhr.responseText;
440
+
441
+ if (xml && data.documentElement.nodeName === 'parsererror') {
442
+ $.error && $.error('parsererror');
443
+ }
444
+ if (s && s.dataFilter) {
445
+ data = s.dataFilter(data, type);
446
+ }
447
+ if (typeof data === 'string') {
448
+ if (type === 'json' || !type && ct.indexOf('json') >= 0) {
449
+ data = parseJSON(data);
450
+ } else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
451
+ $.globalEval(data);
452
+ }
453
+ }
454
+ return data;
455
+ };
456
+ }
457
+ };
458
+
459
+ /**
460
+ * ajaxForm() provides a mechanism for fully automating form submission.
461
+ *
462
+ * The advantages of using this method instead of ajaxSubmit() are:
463
+ *
464
+ * 1: This method will include coordinates for <input type="image" /> elements (if the element
465
+ * is used to submit the form).
466
+ * 2. This method will include the submit element's name/value data (for the element that was
467
+ * used to submit the form).
468
+ * 3. This method binds the submit() method to the form for you.
469
+ *
470
+ * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
471
+ * passes the options argument along after properly binding events for submit elements and
472
+ * the form itself.
473
+ */
474
+ $.fn.ajaxForm = function(options) {
475
+ // in jQuery 1.3+ we can fix mistakes with the ready state
476
+ if (this.length === 0) {
477
+ var o = { s: this.selector, c: this.context };
478
+ if (!$.isReady && o.s) {
479
+ log('DOM not ready, queuing ajaxForm');
480
+ $(function() {
481
+ $(o.s, o.c).ajaxForm(options);
482
+ });
483
+ return this;
484
+ }
485
+ // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
486
+ log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
487
+ return this;
488
+ }
489
+
490
+ return this.ajaxFormUnbind().bind('submit.form-plugin',
491
+ function(e) {
492
+ if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
493
+ e.preventDefault();
494
+ $(this).ajaxSubmit(options);
495
+ }
496
+ }).bind('click.form-plugin', function(e) {
497
+ var target = e.target;
498
+ var $el = $(target);
499
+ if (!($el.is(":submit,input:image"))) {
500
+ // is this a child element of the submit el? (ex: a span within a button)
501
+ var t = $el.closest(':submit');
502
+ if (t.length == 0) {
503
+ return;
504
+ }
505
+ target = t[0];
506
+ }
507
+ var form = this;
508
+ form.clk = target;
509
+ if (target.type == 'image') {
510
+ if (e.offsetX != undefined) {
511
+ form.clk_x = e.offsetX;
512
+ form.clk_y = e.offsetY;
513
+ } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
514
+ var offset = $el.offset();
515
+ form.clk_x = e.pageX - offset.left;
516
+ form.clk_y = e.pageY - offset.top;
517
+ } else {
518
+ form.clk_x = e.pageX - target.offsetLeft;
519
+ form.clk_y = e.pageY - target.offsetTop;
520
+ }
521
+ }
522
+ // clear form vars
523
+ setTimeout(function() {
524
+ form.clk = form.clk_x = form.clk_y = null;
525
+ }, 100);
526
+ });
527
+ };
513
528
 
514
529
  // ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
515
- $.fn.ajaxFormUnbind = function() {
516
- return this.unbind('submit.form-plugin click.form-plugin');
517
- };
518
-
519
- /**
520
- * formToArray() gathers form element data into an array of objects that can
521
- * be passed to any of the following ajax functions: $.get, $.post, or load.
522
- * Each object in the array has both a 'name' and 'value' property. An example of
523
- * an array for a simple login form might be:
524
- *
525
- * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
526
- *
527
- * It is this array that is passed to pre-submit callback functions provided to the
528
- * ajaxSubmit() and ajaxForm() methods.
529
- */
530
- $.fn.formToArray = function(semantic) {
531
- var a = [];
532
- if (this.length === 0) {
533
- return a;
534
- }
535
-
536
- var form = this[0];
537
- var els = semantic ? form.getElementsByTagName('*') : form.elements;
538
- if (!els) {
539
- return a;
540
- }
541
-
542
- var i,j,n,v,el,max,jmax;
543
- for(i=0, max=els.length; i < max; i++) {
544
- el = els[i];
545
- n = el.name;
546
- if (!n) {
547
- continue;
548
- }
549
-
550
- if (semantic && form.clk && el.type == "image") {
551
- // handle image inputs on the fly when semantic == true
552
- if(!el.disabled && form.clk == el) {
553
- a.push({name: n, value: $(el).val()});
554
- a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
555
- }
556
- continue;
557
- }
558
-
559
- v = $.fieldValue(el, true);
560
- if (v && v.constructor == Array) {
561
- for(j=0, jmax=v.length; j < jmax; j++) {
562
- a.push({name: n, value: v[j]});
563
- }
564
- }
565
- else if (v !== null && typeof v != 'undefined') {
566
- a.push({name: n, value: v});
567
- }
568
- }
569
-
570
- if (!semantic && form.clk) {
571
- // input type=='image' are not found in elements array! handle it here
572
- var $input = $(form.clk), input = $input[0];
573
- n = input.name;
574
- if (n && !input.disabled && input.type == 'image') {
575
- a.push({name: n, value: $input.val()});
576
- a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
577
- }
578
- }
579
- return a;
580
- };
581
-
582
- /**
583
- * Serializes form data into a 'submittable' string. This method will return a string
584
- * in the format: name1=value1&amp;name2=value2
585
- */
586
- $.fn.formSerialize = function(semantic) {
587
- //hand off to jQuery.param for proper encoding
588
- return $.param(this.formToArray(semantic));
589
- };
590
-
591
- /**
592
- * Serializes all field elements in the jQuery object into a query string.
593
- * This method will return a string in the format: name1=value1&amp;name2=value2
594
- */
595
- $.fn.fieldSerialize = function(successful) {
596
- var a = [];
597
- this.each(function() {
598
- var n = this.name;
599
- if (!n) {
600
- return;
601
- }
602
- var v = $.fieldValue(this, successful);
603
- if (v && v.constructor == Array) {
604
- for (var i=0,max=v.length; i < max; i++) {
605
- a.push({name: n, value: v[i]});
606
- }
607
- }
608
- else if (v !== null && typeof v != 'undefined') {
609
- a.push({name: this.name, value: v});
610
- }
611
- });
612
- //hand off to jQuery.param for proper encoding
613
- return $.param(a);
614
- };
615
-
616
- /**
617
- * Returns the value(s) of the element in the matched set. For example, consider the following form:
618
- *
619
- * <form><fieldset>
620
- * <input name="A" type="text" />
621
- * <input name="A" type="text" />
622
- * <input name="B" type="checkbox" value="B1" />
623
- * <input name="B" type="checkbox" value="B2"/>
624
- * <input name="C" type="radio" value="C1" />
625
- * <input name="C" type="radio" value="C2" />
626
- * </fieldset></form>
627
- *
628
- * var v = $(':text').fieldValue();
629
- * // if no values are entered into the text inputs
630
- * v == ['','']
631
- * // if values entered into the text inputs are 'foo' and 'bar'
632
- * v == ['foo','bar']
633
- *
634
- * var v = $(':checkbox').fieldValue();
635
- * // if neither checkbox is checked
636
- * v === undefined
637
- * // if both checkboxes are checked
638
- * v == ['B1', 'B2']
639
- *
640
- * var v = $(':radio').fieldValue();
641
- * // if neither radio is checked
642
- * v === undefined
643
- * // if first radio is checked
644
- * v == ['C1']
645
- *
646
- * The successful argument controls whether or not the field element must be 'successful'
647
- * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
648
- * The default value of the successful argument is true. If this value is false the value(s)
649
- * for each element is returned.
650
- *
651
- * Note: This method *always* returns an array. If no valid value can be determined the
652
- * array will be empty, otherwise it will contain one or more values.
653
- */
654
- $.fn.fieldValue = function(successful) {
655
- for (var val=[], i=0, max=this.length; i < max; i++) {
656
- var el = this[i];
657
- var v = $.fieldValue(el, successful);
658
- if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
659
- continue;
660
- }
661
- v.constructor == Array ? $.merge(val, v) : val.push(v);
662
- }
663
- return val;
664
- };
665
-
666
- /**
667
- * Returns the value of the field element.
668
- */
669
- $.fieldValue = function(el, successful) {
670
- var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
671
- if (successful === undefined) {
672
- successful = true;
673
- }
674
-
675
- if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
676
- (t == 'checkbox' || t == 'radio') && !el.checked ||
677
- (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
678
- tag == 'select' && el.selectedIndex == -1)) {
679
- return null;
680
- }
681
-
682
- if (tag == 'select') {
683
- var index = el.selectedIndex;
684
- if (index < 0) {
685
- return null;
686
- }
687
- var a = [], ops = el.options;
688
- var one = (t == 'select-one');
689
- var max = (one ? index+1 : ops.length);
690
- for(var i=(one ? index : 0); i < max; i++) {
691
- var op = ops[i];
692
- if (op.selected) {
693
- var v = op.value;
694
- if (!v) { // extra pain for IE...
695
- v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
696
- }
697
- if (one) {
698
- return v;
699
- }
700
- a.push(v);
701
- }
702
- }
703
- return a;
704
- }
705
- return $(el).val();
706
- };
707
-
708
- /**
709
- * Clears the form data. Takes the following actions on the form's input fields:
710
- * - input text fields will have their 'value' property set to the empty string
711
- * - select elements will have their 'selectedIndex' property set to -1
712
- * - checkbox and radio inputs will have their 'checked' property set to false
713
- * - inputs of type submit, button, reset, and hidden will *not* be effected
714
- * - button elements will *not* be effected
715
- */
716
- $.fn.clearForm = function() {
717
- return this.each(function() {
718
- $('input,select,textarea', this).clearFields();
719
- });
720
- };
721
-
722
- /**
723
- * Clears the selected form elements.
724
- */
725
- $.fn.clearFields = $.fn.clearInputs = function() {
726
- return this.each(function() {
727
- var t = this.type, tag = this.tagName.toLowerCase();
728
- if (t == 'text' || t == 'password' || tag == 'textarea') {
729
- this.value = '';
730
- }
731
- else if (t == 'checkbox' || t == 'radio') {
732
- this.checked = false;
733
- }
734
- else if (tag == 'select') {
735
- this.selectedIndex = -1;
736
- }
737
- });
738
- };
739
-
740
- /**
741
- * Resets the form data. Causes all form elements to be reset to their original value.
742
- */
743
- $.fn.resetForm = function() {
744
- return this.each(function() {
745
- // guard against an input with the name of 'reset'
746
- // note that IE reports the reset function as an 'object'
747
- if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
748
- this.reset();
749
- }
750
- });
751
- };
752
-
753
- /**
754
- * Enables or disables any matching elements.
755
- */
756
- $.fn.enable = function(b) {
757
- if (b === undefined) {
758
- b = true;
759
- }
760
- return this.each(function() {
761
- this.disabled = !b;
762
- });
763
- };
764
-
765
- /**
766
- * Checks/unchecks any matching checkboxes or radio buttons and
767
- * selects/deselects and matching option elements.
768
- */
769
- $.fn.selected = function(select) {
770
- if (select === undefined) {
771
- select = true;
772
- }
773
- return this.each(function() {
774
- var t = this.type;
775
- if (t == 'checkbox' || t == 'radio') {
776
- this.checked = select;
777
- }
778
- else if (this.tagName.toLowerCase() == 'option') {
779
- var $sel = $(this).parent('select');
780
- if (select && $sel[0] && $sel[0].type == 'select-one') {
781
- // deselect all other options
782
- $sel.find('option').selected(false);
783
- }
784
- this.selected = select;
785
- }
786
- });
787
- };
530
+ $.fn.ajaxFormUnbind = function() {
531
+ return this.unbind('submit.form-plugin click.form-plugin');
532
+ };
533
+
534
+ /**
535
+ * formToArray() gathers form element data into an array of objects that can
536
+ * be passed to any of the following ajax functions: $.get, $.post, or load.
537
+ * Each object in the array has both a 'name' and 'value' property. An example of
538
+ * an array for a simple login form might be:
539
+ *
540
+ * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
541
+ *
542
+ * It is this array that is passed to pre-submit callback functions provided to the
543
+ * ajaxSubmit() and ajaxForm() methods.
544
+ */
545
+ $.fn.formToArray = function(semantic) {
546
+ var a = [];
547
+ if (this.length === 0) {
548
+ return a;
549
+ }
550
+
551
+ var form = this[0];
552
+ var els = semantic ? form.getElementsByTagName('*') : form.elements;
553
+ if (!els) {
554
+ return a;
555
+ }
556
+
557
+ var i,j,n,v,el,max,jmax;
558
+ for (i = 0,max = els.length; i < max; i++) {
559
+ el = els[i];
560
+ n = el.name;
561
+ if (!n) {
562
+ continue;
563
+ }
564
+
565
+ if (semantic && form.clk && el.type == "image") {
566
+ // handle image inputs on the fly when semantic == true
567
+ if (!el.disabled && form.clk == el) {
568
+ a.push({name: n, value: $(el).val()});
569
+ a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
570
+ }
571
+ continue;
572
+ }
573
+
574
+ v = $.fieldValue(el, true);
575
+ if (v && v.constructor == Array) {
576
+ for (j = 0,jmax = v.length; j < jmax; j++) {
577
+ a.push({name: n, value: v[j]});
578
+ }
579
+ }
580
+ else if (v !== null && typeof v != 'undefined') {
581
+ a.push({name: n, value: v});
582
+ }
583
+ }
584
+
585
+ if (!semantic && form.clk) {
586
+ // input type=='image' are not found in elements array! handle it here
587
+ var $input = $(form.clk), input = $input[0];
588
+ n = input.name;
589
+ if (n && !input.disabled && input.type == 'image') {
590
+ a.push({name: n, value: $input.val()});
591
+ a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
592
+ }
593
+ }
594
+ return a;
595
+ };
596
+
597
+ /**
598
+ * Serializes form data into a 'submittable' string. This method will return a string
599
+ * in the format: name1=value1&amp;name2=value2
600
+ */
601
+ $.fn.formSerialize = function(semantic) {
602
+ //hand off to jQuery.param for proper encoding
603
+ return $.param(this.formToArray(semantic));
604
+ };
605
+
606
+ /**
607
+ * Serializes all field elements in the jQuery object into a query string.
608
+ * This method will return a string in the format: name1=value1&amp;name2=value2
609
+ */
610
+ $.fn.fieldSerialize = function(successful) {
611
+ var a = [];
612
+ this.each(function() {
613
+ var n = this.name;
614
+ if (!n) {
615
+ return;
616
+ }
617
+ var v = $.fieldValue(this, successful);
618
+ if (v && v.constructor == Array) {
619
+ for (var i = 0,max = v.length; i < max; i++) {
620
+ a.push({name: n, value: v[i]});
621
+ }
622
+ }
623
+ else if (v !== null && typeof v != 'undefined') {
624
+ a.push({name: this.name, value: v});
625
+ }
626
+ });
627
+ //hand off to jQuery.param for proper encoding
628
+ return $.param(a);
629
+ };
630
+
631
+ /**
632
+ * Returns the value(s) of the element in the matched set. For example, consider the following form:
633
+ *
634
+ * <form><fieldset>
635
+ * <input name="A" type="text" />
636
+ * <input name="A" type="text" />
637
+ * <input name="B" type="checkbox" value="B1" />
638
+ * <input name="B" type="checkbox" value="B2"/>
639
+ * <input name="C" type="radio" value="C1" />
640
+ * <input name="C" type="radio" value="C2" />
641
+ * </fieldset></form>
642
+ *
643
+ * var v = $(':text').fieldValue();
644
+ * // if no values are entered into the text inputs
645
+ * v == ['','']
646
+ * // if values entered into the text inputs are 'foo' and 'bar'
647
+ * v == ['foo','bar']
648
+ *
649
+ * var v = $(':checkbox').fieldValue();
650
+ * // if neither checkbox is checked
651
+ * v === undefined
652
+ * // if both checkboxes are checked
653
+ * v == ['B1', 'B2']
654
+ *
655
+ * var v = $(':radio').fieldValue();
656
+ * // if neither radio is checked
657
+ * v === undefined
658
+ * // if first radio is checked
659
+ * v == ['C1']
660
+ *
661
+ * The successful argument controls whether or not the field element must be 'successful'
662
+ * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
663
+ * The default value of the successful argument is true. If this value is false the value(s)
664
+ * for each element is returned.
665
+ *
666
+ * Note: This method *always* returns an array. If no valid value can be determined the
667
+ * array will be empty, otherwise it will contain one or more values.
668
+ */
669
+ $.fn.fieldValue = function(successful) {
670
+ for (var val = [], i = 0, max = this.length; i < max; i++) {
671
+ var el = this[i];
672
+ var v = $.fieldValue(el, successful);
673
+ if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
674
+ continue;
675
+ }
676
+ v.constructor == Array ? $.merge(val, v) : val.push(v);
677
+ }
678
+ return val;
679
+ };
680
+
681
+ /**
682
+ * Returns the value of the field element.
683
+ */
684
+ $.fieldValue = function(el, successful) {
685
+ var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
686
+ if (successful === undefined) {
687
+ successful = true;
688
+ }
689
+
690
+ if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
691
+ (t == 'checkbox' || t == 'radio') && !el.checked ||
692
+ (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
693
+ tag == 'select' && el.selectedIndex == -1)) {
694
+ return null;
695
+ }
696
+
697
+ if (tag == 'select') {
698
+ var index = el.selectedIndex;
699
+ if (index < 0) {
700
+ return null;
701
+ }
702
+ var a = [], ops = el.options;
703
+ var one = (t == 'select-one');
704
+ var max = (one ? index + 1 : ops.length);
705
+ for (var i = (one ? index : 0); i < max; i++) {
706
+ var op = ops[i];
707
+ if (op.selected) {
708
+ var v = op.value;
709
+ if (!v) { // extra pain for IE...
710
+ v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
711
+ }
712
+ if (one) {
713
+ return v;
714
+ }
715
+ a.push(v);
716
+ }
717
+ }
718
+ return a;
719
+ }
720
+ return $(el).val();
721
+ };
722
+
723
+ /**
724
+ * Clears the form data. Takes the following actions on the form's input fields:
725
+ * - input text fields will have their 'value' property set to the empty string
726
+ * - select elements will have their 'selectedIndex' property set to -1
727
+ * - checkbox and radio inputs will have their 'checked' property set to false
728
+ * - inputs of type submit, button, reset, and hidden will *not* be effected
729
+ * - button elements will *not* be effected
730
+ */
731
+ $.fn.clearForm = function() {
732
+ return this.each(function() {
733
+ $('input,select,textarea', this).clearFields();
734
+ });
735
+ };
736
+
737
+ /**
738
+ * Clears the selected form elements.
739
+ */
740
+ $.fn.clearFields = $.fn.clearInputs = function() {
741
+ return this.each(function() {
742
+ var t = this.type, tag = this.tagName.toLowerCase();
743
+ if (t == 'text' || t == 'password' || tag == 'textarea') {
744
+ this.value = '';
745
+ }
746
+ else if (t == 'checkbox' || t == 'radio') {
747
+ this.checked = false;
748
+ }
749
+ else if (tag == 'select') {
750
+ this.selectedIndex = -1;
751
+ }
752
+ });
753
+ };
754
+
755
+ /**
756
+ * Resets the form data. Causes all form elements to be reset to their original value.
757
+ */
758
+ $.fn.resetForm = function() {
759
+ return this.each(function() {
760
+ // guard against an input with the name of 'reset'
761
+ // note that IE reports the reset function as an 'object'
762
+ if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
763
+ this.reset();
764
+ }
765
+ });
766
+ };
767
+
768
+ /**
769
+ * Enables or disables any matching elements.
770
+ */
771
+ $.fn.enable = function(b) {
772
+ if (b === undefined) {
773
+ b = true;
774
+ }
775
+ return this.each(function() {
776
+ this.disabled = !b;
777
+ });
778
+ };
779
+
780
+ /**
781
+ * Checks/unchecks any matching checkboxes or radio buttons and
782
+ * selects/deselects and matching option elements.
783
+ */
784
+ $.fn.selected = function(select) {
785
+ if (select === undefined) {
786
+ select = true;
787
+ }
788
+ return this.each(function() {
789
+ var t = this.type;
790
+ if (t == 'checkbox' || t == 'radio') {
791
+ this.checked = select;
792
+ }
793
+ else if (this.tagName.toLowerCase() == 'option') {
794
+ var $sel = $(this).parent('select');
795
+ if (select && $sel[0] && $sel[0].type == 'select-one') {
796
+ // deselect all other options
797
+ $sel.find('option').selected(false);
798
+ }
799
+ this.selected = select;
800
+ }
801
+ });
802
+ };
788
803
 
789
804
  // helper fn for console logging
790
805
  // set $.fn.ajaxSubmit.debug to true to enable debug logging
791
- function log() {
792
- if ($.fn.ajaxSubmit.debug) {
793
- var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
794
- if (window.console && window.console.log) {
795
- window.console.log(msg);
796
- }
797
- else if (window.opera && window.opera.postError) {
798
- window.opera.postError(msg);
799
- }
800
- }
801
- };
806
+ function log() {
807
+ if ($.fn.ajaxSubmit.debug) {
808
+ var msg = '[jquery.form] ' + Array.prototype.join.call(arguments, '');
809
+ if (window.console && window.console.log) {
810
+ window.console.log(msg);
811
+ }
812
+ else if (window.opera && window.opera.postError) {
813
+ window.opera.postError(msg);
814
+ }
815
+ }
816
+ }
817
+
818
+ ;
802
819
 
803
820
  })(jQuery);