Produced by Araxis Merge on 5/25/2018 9:22:54 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\AraxisMergeCompare\Pri_un\ZIP\DSM-cif\Direct_API\js | jquery.form.js | Tue May 22 12:02:58 2018 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\ZIP\DSM-cif\Direct_API\js | jquery.form.js | Thu May 24 22:27:33 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 2342 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /*! | |
| 2 | * jQuery Form Plugi n | |
| 3 | * version : 3.32.0-2 013.04.09 | |
| 4 | * @requir es jQuery v1.5 or la ter | |
| 5 | * Copyrig ht (c) 201 3 M. Alsup | |
| 6 | * Example s and docu mentation at: http:/ /malsup.co m/jquery/f orm/ | |
| 7 | * Project repositor y: https:/ /github.co m/malsup/f orm | |
| 8 | * Dual li censed und er the MIT and GPL l icenses. | |
| 9 | * https:/ /github.co m/malsup/f orm#copyri ght-and-li cense | |
| 10 | */ | |
| 11 | /*global A ctiveXObje ct */ | |
| 12 | ;(function ($) { | |
| 13 | "use stric t"; | |
| 14 | ||
| 15 | /* | |
| 16 | Usage Note: | |
| 17 | ------ ----- | |
| 18 | Do not use both ajaxSubmit and ajaxF orm on the same form . These | |
| 19 | functi ons are mu tually exc lusive. U se ajaxSub mit if you want | |
| 20 | to bin d your own submit ha ndler to t he form. For exampl e, | |
| 21 | ||
| 22 | $(docu ment).read y(function () { | |
| 23 | $( '#myForm') .on('submi t', functi on(e) { | |
| 24 | e.preven tDefault() ; // <-- i mportant | |
| 25 | $(this). ajaxSubmit ({ | |
| 26 | targ et: '#outp ut' | |
| 27 | }); | |
| 28 | }) ; | |
| 29 | }); | |
| 30 | ||
| 31 | Use aj axForm whe n you want the plugi n to manag e all the event bind ing | |
| 32 | for yo u. For ex ample, | |
| 33 | ||
| 34 | $(docu ment).read y(function () { | |
| 35 | $( '#myForm') .ajaxForm( { | |
| 36 | target: '#output' | |
| 37 | }) ; | |
| 38 | }); | |
| 39 | ||
| 40 | You ca n also use ajaxForm with deleg ation (req uires jQue ry v1.7+), so the | |
| 41 | form d oes not ha ve to exis t when you invoke aj axForm: | |
| 42 | ||
| 43 | $('#my Form').aja xForm({ | |
| 44 | de legation: true, | |
| 45 | ta rget: '#ou tput' | |
| 46 | }); | |
| 47 | ||
| 48 | When u sing ajaxF orm, the a jaxSubmit function w ill be inv oked for y ou | |
| 49 | at the appropria te time. | |
| 50 | */ | |
| 51 | ||
| 52 | /** | |
| 53 | * Feature detection | |
| 54 | */ | |
| 55 | var featur e = {}; | |
| 56 | feature.fi leapi = $( "<input ty pe='file'/ >").get(0) .files !== undefined ; | |
| 57 | feature.fo rmdata = w indow.Form Data !== u ndefined; | |
| 58 | ||
| 59 | var hasPro p = !!$.fn .prop; | |
| 60 | ||
| 61 | // attr2 u ses prop w hen it can but check s the retu rn type fo r | |
| 62 | // an expe cted strin g. this a ccounts fo r the case where a f orm | |
| 63 | // contain s inputs w ith names like "acti on" or "me thod"; in those | |
| 64 | // cases " prop" retu rns the el ement | |
| 65 | $.fn.attr2 = functio n() { | |
| 66 | if ( ! hasProp ) | |
| 67 | re turn this. attr.apply (this, arg uments); | |
| 68 | var va l = this.p rop.apply( this, argu ments); | |
| 69 | if ( ( val && va l.jquery ) || typeof val === ' string' ) | |
| 70 | re turn val; | |
| 71 | return this.attr .apply(thi s, argumen ts); | |
| 72 | }; | |
| 73 | ||
| 74 | /** | |
| 75 | * ajaxSub mit() prov ides a mec hanism for immediate ly submitt ing | |
| 76 | * an HTML form usin g AJAX. | |
| 77 | */ | |
| 78 | $.fn.ajaxS ubmit = fu nction(opt ions) { | |
| 79 | /*jshi nt scriptu rl:true */ | |
| 80 | ||
| 81 | // fas t fail if nothing se lected (ht tp://dev.j query.com/ ticket/275 2) | |
| 82 | if (!t his.length ) { | |
| 83 | lo g('ajaxSub mit: skipp ing submit process - no elemen t selected '); | |
| 84 | re turn this; | |
| 85 | } | |
| 86 | ||
| 87 | var me thod, acti on, url, $ form = thi s; | |
| 88 | ||
| 89 | if (ty peof optio ns == 'fun ction') { | |
| 90 | op tions = { success: o ptions }; | |
| 91 | } | |
| 92 | ||
| 93 | method = this.at tr2('metho d'); | |
| 94 | action = this.at tr2('actio n'); | |
| 95 | ||
| 96 | url = (typeof ac tion === ' string') ? $.trim(ac tion) : '' ; | |
| 97 | url = url || win dow.locati on.href || ''; | |
| 98 | if (ur l) { | |
| 99 | // clean url (don't in clude hash vaue) | |
| 100 | ur l = (url.m atch(/^([^ #]+)/)||[] )[1]; | |
| 101 | } | |
| 102 | ||
| 103 | option s = $.exte nd(true, { | |
| 104 | ur l: url, | |
| 105 | su ccess: $.a jaxSetting s.success, | |
| 106 | ty pe: method || 'GET', | |
| 107 | if rameSrc: / ^https/i.t est(window .location. href || '' ) ? 'javas cript:fals e' : 'abou t:blank' | |
| 108 | }, opt ions); | |
| 109 | ||
| 110 | // hoo k for mani pulating t he form da ta before it is extr acted; | |
| 111 | // con venient fo r use with rich edit ors like t inyMCE or FCKEditor | |
| 112 | var ve to = {}; | |
| 113 | this.t rigger('fo rm-pre-ser ialize', [ this, opti ons, veto] ); | |
| 114 | if (ve to.veto) { | |
| 115 | lo g('ajaxSub mit: submi t vetoed v ia form-pr e-serializ e trigger' ); | |
| 116 | re turn this; | |
| 117 | } | |
| 118 | ||
| 119 | // pro vide oppor tunity to alter form data befo re it is s erialized | |
| 120 | if (op tions.befo reSerializ e && optio ns.beforeS erialize(t his, optio ns) === fa lse) { | |
| 121 | lo g('ajaxSub mit: submi t aborted via before Serialize callback') ; | |
| 122 | re turn this; | |
| 123 | } | |
| 124 | ||
| 125 | var tr aditional = options. traditiona l; | |
| 126 | if ( t raditional === undef ined ) { | |
| 127 | tr aditional = $.ajaxSe ttings.tra ditional; | |
| 128 | } | |
| 129 | ||
| 130 | var el ements = [ ]; | |
| 131 | var qx , a = this .formToArr ay(options .semantic, elements) ; | |
| 132 | if (op tions.data ) { | |
| 133 | op tions.extr aData = op tions.data ; | |
| 134 | qx = $.param (options.d ata, tradi tional); | |
| 135 | } | |
| 136 | ||
| 137 | // giv e pre-subm it callbac k an oppor tunity to abort the submit | |
| 138 | if (op tions.befo reSubmit & & options. beforeSubm it(a, this , options) === false ) { | |
| 139 | lo g('ajaxSub mit: submi t aborted via before Submit cal lback'); | |
| 140 | re turn this; | |
| 141 | } | |
| 142 | ||
| 143 | // fir e vetoable 'validate ' event | |
| 144 | this.t rigger('fo rm-submit- validate', [a, this, options, veto]); | |
| 145 | if (ve to.veto) { | |
| 146 | lo g('ajaxSub mit: submi t vetoed v ia form-su bmit-valid ate trigge r'); | |
| 147 | re turn this; | |
| 148 | } | |
| 149 | ||
| 150 | var q = $.param( a, traditi onal); | |
| 151 | if (qx ) { | |
| 152 | q = ( q ? (q + '&' + q x) : qx ); | |
| 153 | } | |
| 154 | if (op tions.type .toUpperCa se() == 'G ET') { | |
| 155 | op tions.url += (option s.url.inde xOf('?') > = 0 ? '&' : '?') + q ; | |
| 156 | op tions.data = null; // data is null for 'get' | |
| 157 | } | |
| 158 | else { | |
| 159 | op tions.data = q; // d ata is the query str ing for 'p ost' | |
| 160 | } | |
| 161 | ||
| 162 | var ca llbacks = []; | |
| 163 | if (op tions.rese tForm) { | |
| 164 | ca llbacks.pu sh(functio n() { $for m.resetFor m(); }); | |
| 165 | } | |
| 166 | if (op tions.clea rForm) { | |
| 167 | ca llbacks.pu sh(functio n() { $for m.clearFor m(options. includeHid den); }); | |
| 168 | } | |
| 169 | ||
| 170 | // per form a loa d on the t arget only if dataTy pe is not provided | |
| 171 | if (!o ptions.dat aType && o ptions.tar get) { | |
| 172 | va r oldSucce ss = optio ns.success || functi on(){}; | |
| 173 | ca llbacks.pu sh(functio n(data) { | |
| 174 | var fn = options.r eplaceTarg et ? 'repl aceWith' : 'html'; | |
| 175 | $(option s.target)[ fn](data). each(oldSu ccess, arg uments); | |
| 176 | }) ; | |
| 177 | } | |
| 178 | else i f (options .success) { | |
| 179 | ca llbacks.pu sh(options .success); | |
| 180 | } | |
| 181 | ||
| 182 | option s.success = function (data, sta tus, xhr) { // jQuer y 1.4+ pas ses xhr as 3rd arg | |
| 183 | va r context = options. context || this ; // jQuery 1.4+ supp orts scope context | |
| 184 | fo r (var i=0 , max=call backs.leng th; i < ma x; i++) { | |
| 185 | callback s[i].apply (context, [data, sta tus, xhr | | $form, $ form]); | |
| 186 | } | |
| 187 | }; | |
| 188 | ||
| 189 | // are there fil es to uplo ad? | |
| 190 | ||
| 191 | // [va lue] (issu e #113), a lso see co mment: | |
| 192 | // htt ps://githu b.com/mals up/form/co mmit/58830 6aedba1de0 1388032d5f 42a60159ee a9228#comm itcomment- 2180219 | |
| 193 | var fi leInputs = $('input[ type=file] :enabled[v alue!=""]' , this); | |
| 194 | ||
| 195 | var ha sFileInput s = fileIn puts.lengt h > 0; | |
| 196 | var mp = 'multip art/form-d ata'; | |
| 197 | var mu ltipart = ($form.att r('enctype ') == mp | | $form.at tr('encodi ng') == mp ); | |
| 198 | ||
| 199 | var fi leAPI = fe ature.file api && fea ture.formd ata; | |
| 200 | log("f ileAPI :" + fileAPI) ; | |
| 201 | var sh ouldUseFra me = (hasF ileInputs || multipa rt) && !fi leAPI; | |
| 202 | ||
| 203 | var jq xhr; | |
| 204 | ||
| 205 | // opt ions.ifram e allows u ser to for ce iframe mode | |
| 206 | // 06- NOV-09: no w defaulti ng to ifra me mode if file inpu t is detec ted | |
| 207 | if (op tions.ifra me !== fal se && (opt ions.ifram e || shoul dUseFrame) ) { | |
| 208 | // hack to f ix Safari hang (than ks to Tim Molendijk for this) | |
| 209 | // see: htt p://groups .google.co m/group/jq uery-dev/b rowse_thre ad/thread/ 36395b7ab5 10dd5d | |
| 210 | if (options. closeKeepA live) { | |
| 211 | $.get(op tions.clos eKeepAlive , function () { | |
| 212 | jqxh r = fileUp loadIframe (a); | |
| 213 | }); | |
| 214 | } | |
| 215 | el se { | |
| 216 | jqxhr = fileUpload Iframe(a); | |
| 217 | } | |
| 218 | } | |
| 219 | else i f ((hasFil eInputs || multipart ) && fileA PI) { | |
| 220 | jq xhr = file UploadXhr( a); | |
| 221 | } | |
| 222 | else { | |
| 223 | jq xhr = $.aj ax(options ); | |
| 224 | } | |
| 225 | ||
| 226 | $form. removeData ('jqxhr'). data('jqxh r', jqxhr) ; | |
| 227 | ||
| 228 | // cle ar element array | |
| 229 | for (v ar k=0; k < elements .length; k ++) | |
| 230 | el ements[k] = null; | |
| 231 | ||
| 232 | // fir e 'notify' event | |
| 233 | this.t rigger('fo rm-submit- notify', [ this, opti ons]); | |
| 234 | return this; | |
| 235 | ||
| 236 | // uti lity fn fo r deep ser ialization | |
| 237 | functi on deepSer ialize(ext raData){ | |
| 238 | va r serializ ed = $.par am(extraDa ta).split( '&'); | |
| 239 | va r len = se rialized.l ength; | |
| 240 | va r result = []; | |
| 241 | va r i, part; | |
| 242 | fo r (i=0; i < len; i++ ) { | |
| 243 | // #252; undo para m space re placement | |
| 244 | serializ ed[i] = se rialized[i ].replace( /\+/g,' ') ; | |
| 245 | part = s erialized[ i].split(' ='); | |
| 246 | // #278; use array instead o f object s torage, fa voring arr ay seriali zations | |
| 247 | result.p ush([decod eURICompon ent(part[0 ]), decode URICompone nt(part[1] )]); | |
| 248 | } | |
| 249 | re turn resul t; | |
| 250 | } | |
| 251 | ||
| 252 | // XM LHttpReque st Level 2 file uplo ads (big h at tip to francois2m etz) | |
| 253 | functi on fileUpl oadXhr(a) { | |
| 254 | va r formdata = new For mData(); | |
| 255 | ||
| 256 | fo r (var i=0 ; i < a.le ngth; i++) { | |
| 257 | formdata .append(a[ i].name, a [i].value) ; | |
| 258 | } | |
| 259 | ||
| 260 | if (options. extraData) { | |
| 261 | var seri alizedData = deepSer ialize(opt ions.extra Data); | |
| 262 | for (i=0 ; i < seri alizedData .length; i ++) | |
| 263 | if ( serialized Data[i]) | |
| 264 | formdata.a ppend(seri alizedData [i][0], se rializedDa ta[i][1]); | |
| 265 | } | |
| 266 | ||
| 267 | op tions.data = null; | |
| 268 | ||
| 269 | va r s = $.ex tend(true, {}, $.aja xSettings, options, { | |
| 270 | contentT ype: false , | |
| 271 | processD ata: false , | |
| 272 | cache: f alse, | |
| 273 | type: me thod || 'P OST' | |
| 274 | }) ; | |
| 275 | ||
| 276 | if (options. uploadProg ress) { | |
| 277 | // worka round beca use jqXHR does not e xpose uplo ad propert y | |
| 278 | s.xhr = function() { | |
| 279 | var xhr = jQue ry.ajaxSet tings.xhr( ); | |
| 280 | if ( xhr.upload ) { | |
| 281 | xhr.upload .addEventL istener('p rogress', function(e vent) { | |
| 282 | var pe rcent = 0; | |
| 283 | var po sition = e vent.loade d || event .position; /*event.p osition is deprecate d*/ | |
| 284 | var to tal = even t.total; | |
| 285 | if (ev ent.length Computable ) { | |
| 286 | pe rcent = Ma th.ceil(po sition / t otal * 100 ); | |
| 287 | } | |
| 288 | option s.uploadPr ogress(eve nt, positi on, total, percent); | |
| 289 | }, false); | |
| 290 | } | |
| 291 | retu rn xhr; | |
| 292 | }; | |
| 293 | } | |
| 294 | ||
| 295 | s. data = nul l; | |
| 296 | var befo reSend = s .beforeSen d; | |
| 297 | s.before Send = fun ction(xhr, o) { | |
| 298 | o.da ta = formd ata; | |
| 299 | if(b eforeSend) | |
| 300 | beforeSend .call(this , xhr, o); | |
| 301 | }; | |
| 302 | re turn $.aja x(s); | |
| 303 | } | |
| 304 | ||
| 305 | // pri vate funct ion for ha ndling fil e uploads (hat tip t o YAHOO!) | |
| 306 | functi on fileUpl oadIframe( a) { | |
| 307 | va r form = $ form[0], e l, i, s, g , id, $io, io, xhr, sub, n, ti medOut, ti meoutHandl e; | |
| 308 | va r deferred = $.Defer red(); | |
| 309 | ||
| 310 | if (a) { | |
| 311 | // ensur e that eve ry seriali zed input is still e nabled | |
| 312 | for (i=0 ; i < elem ents.lengt h; i++) { | |
| 313 | el = $(element s[i]); | |
| 314 | if ( hasProp ) | |
| 315 | el.prop('d isabled', false); | |
| 316 | else | |
| 317 | el.removeA ttr('disab led'); | |
| 318 | } | |
| 319 | } | |
| 320 | ||
| 321 | s = $.extend (true, {}, $.ajaxSet tings, opt ions); | |
| 322 | s. context = s.context || s; | |
| 323 | id = 'jqForm IO' + (new Date().ge tTime()); | |
| 324 | if (s.iframe Target) { | |
| 325 | $io = $( s.iframeTa rget); | |
| 326 | n = $io. attr2('nam e'); | |
| 327 | if (!n) | |
| 328 | $io .attr2('na me', id); | |
| 329 | else | |
| 330 | id = n; | |
| 331 | } | |
| 332 | el se { | |
| 333 | $io = $( '<iframe n ame="' + i d + '" src ="'+ s.ifr ameSrc +'" />'); | |
| 334 | $io.css( { position : 'absolut e', top: ' -1000px', left: '-10 00px' }); | |
| 335 | } | |
| 336 | io = $io[0]; | |
| 337 | ||
| 338 | xh r = { // m ock object | |
| 339 | aborted: 0, | |
| 340 | response Text: null , | |
| 341 | response XML: null, | |
| 342 | status: 0, | |
| 343 | statusTe xt: 'n/a', | |
| 344 | getAllRe sponseHead ers: funct ion() {}, | |
| 345 | getRespo nseHeader: function( ) {}, | |
| 346 | setReque stHeader: function() {}, | |
| 347 | abort: f unction(st atus) { | |
| 348 | var e = (statu s === 'tim eout' ? 't imeout' : 'aborted') ; | |
| 349 | log( 'aborting upload... ' + e); | |
| 350 | this .aborted = 1; | |
| 351 | ||
| 352 | try { // #214, #257 | |
| 353 | if (io.con tentWindow .document. execComman d) { | |
| 354 | io.con tentWindow .document. execComman d('Stop'); | |
| 355 | } | |
| 356 | } | |
| 357 | catc h(ignore) {} | |
| 358 | ||
| 359 | $io. attr('src' , s.iframe Src); // a bort op in progress | |
| 360 | xhr. error = e; | |
| 361 | if ( s.error) | |
| 362 | s.error.ca ll(s.conte xt, xhr, e , status); | |
| 363 | if ( g) | |
| 364 | $.event.tr igger("aja xError", [ xhr, s, e] ); | |
| 365 | if ( s.complete ) | |
| 366 | s.complete .call(s.co ntext, xhr , e); | |
| 367 | } | |
| 368 | }; | |
| 369 | ||
| 370 | g = s.global ; | |
| 371 | // trigger a jax global events so that acti vity/block indicator s work lik e normal | |
| 372 | if (g && 0 = == $.activ e++) { | |
| 373 | $.event. trigger("a jaxStart") ; | |
| 374 | } | |
| 375 | if (g) { | |
| 376 | $.event. trigger("a jaxSend", [xhr, s]); | |
| 377 | } | |
| 378 | ||
| 379 | if (s.before Send && s. beforeSend .call(s.co ntext, xhr , s) === f alse) { | |
| 380 | if (s.gl obal) { | |
| 381 | $.ac tive--; | |
| 382 | } | |
| 383 | deferred .reject(); | |
| 384 | return d eferred; | |
| 385 | } | |
| 386 | if (xhr.abor ted) { | |
| 387 | deferred .reject(); | |
| 388 | return d eferred; | |
| 389 | } | |
| 390 | ||
| 391 | // add submi tting elem ent to dat a if we kn ow it | |
| 392 | su b = form.c lk; | |
| 393 | if (sub) { | |
| 394 | n = sub. name; | |
| 395 | if (n && !sub.disa bled) { | |
| 396 | s.ex traData = s.extraDat a || {}; | |
| 397 | s.ex traData[n] = sub.val ue; | |
| 398 | if ( sub.type = = "image") { | |
| 399 | s.extraDat a[n+'.x'] = form.clk _x; | |
| 400 | s.extraDat a[n+'.y'] = form.clk _y; | |
| 401 | } | |
| 402 | } | |
| 403 | } | |
| 404 | ||
| 405 | va r CLIENT_T IMEOUT_ABO RT = 1; | |
| 406 | va r SERVER_A BORT = 2; | |
| 407 | ||
| 408 | fu nction get Doc(frame) { | |
| 409 | /* it lo oks like c ontentWind ow or cont entDocumen t do not | |
| 410 | * carry the proto col proper ty in ie8, when runn ing under ssl | |
| 411 | * frame .document is the onl y valid re sponse doc ument, sin ce | |
| 412 | * the p rotocol is know but not on the other two objects. strange? | |
| 413 | * "Same origin po licy" http ://en.wiki pedia.org/ wiki/Same_ origin_pol icy | |
| 414 | */ | |
| 415 | ||
| 416 | var doc = null; | |
| 417 | ||
| 418 | // IE8 c ascading a ccess chec k | |
| 419 | try { | |
| 420 | if ( frame.cont entWindow) { | |
| 421 | doc = fram e.contentW indow.docu ment; | |
| 422 | } | |
| 423 | } catch( err) { | |
| 424 | // I E8 access denied und er ssl & m issing pro tocol | |
| 425 | log( 'cannot ge t iframe.c ontentWind ow documen t: ' + err ); | |
| 426 | } | |
| 427 | ||
| 428 | if (doc) { // succ essful get ting conte nt | |
| 429 | retu rn doc; | |
| 430 | } | |
| 431 | ||
| 432 | try { // simply ch ecking may throw in ie8 under ssl or mis matched pr otocol | |
| 433 | doc = frame.co ntentDocum ent ? fram e.contentD ocument : frame.docu ment; | |
| 434 | } catch( err) { | |
| 435 | // l ast attemp t | |
| 436 | log( 'cannot ge t iframe.c ontentDocu ment: ' + err); | |
| 437 | doc = frame.do cument; | |
| 438 | } | |
| 439 | return d oc; | |
| 440 | } | |
| 441 | ||
| 442 | // Rails CSR F hack (th anks to Yv an Barthel emy) | |
| 443 | va r csrf_tok en = $('me ta[name=cs rf-token]' ).attr('co ntent'); | |
| 444 | va r csrf_par am = $('me ta[name=cs rf-param]' ).attr('co ntent'); | |
| 445 | if (csrf_par am && csrf _token) { | |
| 446 | s.extraD ata = s.ex traData || {}; | |
| 447 | s.extraD ata[csrf_p aram] = cs rf_token; | |
| 448 | } | |
| 449 | ||
| 450 | // take a br eath so th at pending repaints get some c pu time be fore the u pload star ts | |
| 451 | fu nction doS ubmit() { | |
| 452 | // make sure form attrs are set | |
| 453 | var t = $form.attr 2('target' ), a = $fo rm.attr2(' action'); | |
| 454 | ||
| 455 | // updat e form att rs in IE f riendly wa y | |
| 456 | form.set Attribute( 'target',i d); | |
| 457 | if (!met hod) { | |
| 458 | form .setAttrib ute('metho d', 'POST' ); | |
| 459 | } | |
| 460 | if (a != s.url) { | |
| 461 | form .setAttrib ute('actio n', s.url) ; | |
| 462 | } | |
| 463 | ||
| 464 | // ie bo rks in som e cases wh en setting encoding | |
| 465 | if (! s. skipEncodi ngOverride && (!meth od || /pos t/i.test(m ethod))) { | |
| 466 | $for m.attr({ | |
| 467 | encoding: 'multipart /form-data ', | |
| 468 | enctype: 'multipart /form-data ' | |
| 469 | }); | |
| 470 | } | |
| 471 | ||
| 472 | // suppo rt timout | |
| 473 | if (s.ti meout) { | |
| 474 | time outHandle = setTimeo ut(functio n() { time dOut = tru e; cb(CLIE NT_TIMEOUT _ABORT); } , s.timeou t); | |
| 475 | } | |
| 476 | ||
| 477 | // look for server aborts | |
| 478 | function checkStat e() { | |
| 479 | try { | |
| 480 | var state = getDoc(i o).readySt ate; | |
| 481 | log('state = ' + sta te); | |
| 482 | if (state && state.t oLowerCase () == 'uni nitialized ') | |
| 483 | setTim eout(check State,50); | |
| 484 | } | |
| 485 | catc h(e) { | |
| 486 | log('Serve r abort: ' , e, ' (' , e.name, ')'); | |
| 487 | cb(SERVER_ ABORT); | |
| 488 | if (timeou tHandle) | |
| 489 | clearT imeout(tim eoutHandle ); | |
| 490 | timeoutHan dle = unde fined; | |
| 491 | } | |
| 492 | } | |
| 493 | ||
| 494 | // add " extra" dat a to form if provide d in optio ns | |
| 495 | var extr aInputs = []; | |
| 496 | try { | |
| 497 | if ( s.extraDat a) { | |
| 498 | for (var n in s.extr aData) { | |
| 499 | if (s. extraData. hasOwnProp erty(n)) { | |
| 500 | // if using t he $.param format th at allows for multip le values with the s ame name | |
| 501 | if( $.isPlainO bject(s.ex traData[n] ) && s.ext raData[n]. hasOwnProp erty('name ') && s.ex traData[n] .hasOwnPro perty('val ue')) { | |
| 502 | extraInpu ts.push( | |
| 503 | $('<input type="hid den" name= "'+s.extra Data[n].na me+'">').v al(s.extra Data[n].va lue) | |
| 504 | .appe ndTo(form) [0]); | |
| 505 | } e lse { | |
| 506 | extraInpu ts.push( | |
| 507 | $('<input type="hid den" name= "'+n+'">') .val(s.ext raData[n]) | |
| 508 | .appe ndTo(form) [0]); | |
| 509 | } | |
| 510 | } | |
| 511 | } | |
| 512 | } | |
| 513 | ||
| 514 | if ( !s.iframeT arget) { | |
| 515 | // add ifr ame to doc and submi t the form | |
| 516 | $io.append To('body') ; | |
| 517 | if (io.att achEvent) | |
| 518 | io.att achEvent(' onload', c b); | |
| 519 | else | |
| 520 | io.add EventListe ner('load' , cb, fals e); | |
| 521 | } | |
| 522 | setT imeout(che ckState,15 ); | |
| 523 | ||
| 524 | try { | |
| 525 | form.submi t(); | |
| 526 | } ca tch(err) { | |
| 527 | // just in case form has eleme nt with na me/id of ' submit' | |
| 528 | var submit Fn = docum ent.create Element('f orm').subm it; | |
| 529 | submitFn.a pply(form) ; | |
| 530 | } | |
| 531 | } | |
| 532 | finally { | |
| 533 | // r eset attrs and remov e "extra" input elem ents | |
| 534 | form .setAttrib ute('actio n',a); | |
| 535 | if(t ) { | |
| 536 | form.setAt tribute('t arget', t) ; | |
| 537 | } el se { | |
| 538 | $form.remo veAttr('ta rget'); | |
| 539 | } | |
| 540 | $(ex traInputs) .remove(); | |
| 541 | } | |
| 542 | } | |
| 543 | ||
| 544 | if (s.forceS ync) { | |
| 545 | doSubmit (); | |
| 546 | } | |
| 547 | el se { | |
| 548 | setTimeo ut(doSubmi t, 10); // this lets dom updat es render | |
| 549 | } | |
| 550 | ||
| 551 | va r data, do c, domChec kCount = 5 0, callbac kProcessed ; | |
| 552 | ||
| 553 | fu nction cb( e) { | |
| 554 | if (xhr. aborted || callbackP rocessed) { | |
| 555 | retu rn; | |
| 556 | } | |
| 557 | ||
| 558 | doc = ge tDoc(io); | |
| 559 | if(!doc) { | |
| 560 | log( 'cannot ac cess respo nse docume nt'); | |
| 561 | e = SERVER_ABO RT; | |
| 562 | } | |
| 563 | if (e == = CLIENT_T IMEOUT_ABO RT && xhr) { | |
| 564 | xhr. abort('tim eout'); | |
| 565 | defe rred.rejec t(xhr, 'ti meout'); | |
| 566 | retu rn; | |
| 567 | } | |
| 568 | else if (e == SERV ER_ABORT & & xhr) { | |
| 569 | xhr. abort('ser ver abort' ); | |
| 570 | defe rred.rejec t(xhr, 'er ror', 'ser ver abort' ); | |
| 571 | retu rn; | |
| 572 | } | |
| 573 | ||
| 574 | if (!doc || doc.lo cation.hre f == s.ifr ameSrc) { | |
| 575 | // r esponse no t received yet | |
| 576 | if ( !timedOut) | |
| 577 | return; | |
| 578 | } | |
| 579 | if (io.d etachEvent ) | |
| 580 | io.d etachEvent ('onload', cb); | |
| 581 | else | |
| 582 | io.r emoveEvent Listener(' load', cb, false); | |
| 583 | ||
| 584 | var stat us = 'succ ess', errM sg; | |
| 585 | try { | |
| 586 | if ( timedOut) { | |
| 587 | throw 'tim eout'; | |
| 588 | } | |
| 589 | ||
| 590 | var isXml = s. dataType = = 'xml' || doc.XMLDo cument || $.isXMLDoc (doc); | |
| 591 | log( 'isXml='+i sXml); | |
| 592 | if ( !isXml && window.ope ra && (doc .body === null || !d oc.body.in nerHTML)) { | |
| 593 | if (--domC heckCount) { | |
| 594 | // in some brows ers (Opera ) the ifra me DOM is not always traversab le when | |
| 595 | // the onload ca llback fir es, so we loop a bit to accomm odate | |
| 596 | log('r equeing on Load callb ack, DOM n ot availab le'); | |
| 597 | setTim eout(cb, 2 50); | |
| 598 | return ; | |
| 599 | } | |
| 600 | // let thi s fall thr ough becau se server response c ould be an empty doc ument | |
| 601 | //log('Cou ld not acc ess iframe DOM after mutiple t ries.'); | |
| 602 | //throw 'D OMExceptio n: not ava ilable'; | |
| 603 | } | |
| 604 | ||
| 605 | //lo g('respons e detected '); | |
| 606 | var docRoot = doc.body ? doc.body : doc.docu mentElemen t; | |
| 607 | xhr. responseTe xt = docRo ot ? docRo ot.innerHT ML : null; | |
| 608 | xhr. responseXM L = doc.XM LDocument ? doc.XMLD ocument : doc; | |
| 609 | if ( isXml) | |
| 610 | s.dataType = 'xml'; | |
| 611 | xhr. getRespons eHeader = function(h eader){ | |
| 612 | var header s = {'cont ent-type': s.dataTyp e}; | |
| 613 | return hea ders[heade r]; | |
| 614 | }; | |
| 615 | // s upport for XHR 'stat us' & 'sta tusText' e mulation : | |
| 616 | if ( docRoot) { | |
| 617 | xhr.status = Number( docRoot.g etAttribut e('status' ) ) || xhr .status; | |
| 618 | xhr.status Text = doc Root.getAt tribute('s tatusText' ) || xhr.s tatusText; | |
| 619 | } | |
| 620 | ||
| 621 | var dt = (s.da taType || '').toLowe rCase(); | |
| 622 | var scr = /(js on|script| text)/.tes t(dt); | |
| 623 | if ( scr || s.t extarea) { | |
| 624 | // see if user embed ded respon se in text area | |
| 625 | var ta = d oc.getElem entsByTagN ame('texta rea')[0]; | |
| 626 | if (ta) { | |
| 627 | xhr.re sponseText = ta.valu e; | |
| 628 | // sup port for X HR 'status ' & 'statu sText' emu lation : | |
| 629 | xhr.st atus = Num ber( ta.ge tAttribute ('status') ) || xhr. status; | |
| 630 | xhr.st atusText = ta.getAtt ribute('st atusText') || xhr.st atusText; | |
| 631 | } | |
| 632 | else if (s cr) { | |
| 633 | // acc ount for b rowsers in jecting pr e around j son respon se | |
| 634 | var pr e = doc.ge tElementsB yTagName(' pre')[0]; | |
| 635 | var b = doc.getE lementsByT agName('bo dy')[0]; | |
| 636 | if (pr e) { | |
| 637 | xh r.response Text = pre .textConte nt ? pre.t extContent : pre.inn erText; | |
| 638 | } | |
| 639 | else i f (b) { | |
| 640 | xh r.response Text = b.t extContent ? b.textC ontent : b .innerText ; | |
| 641 | } | |
| 642 | } | |
| 643 | } | |
| 644 | else if (dt == 'xml' && !xhr.respo nseXML && xhr.respon seText) { | |
| 645 | xhr.respon seXML = to Xml(xhr.re sponseText ); | |
| 646 | } | |
| 647 | ||
| 648 | try { | |
| 649 | data = htt pData(xhr, dt, s); | |
| 650 | } | |
| 651 | catc h (err) { | |
| 652 | status = ' parsererro r'; | |
| 653 | xhr.error = errMsg = (err || s tatus); | |
| 654 | } | |
| 655 | } | |
| 656 | catch (e rr) { | |
| 657 | log( 'error cau ght: ',err ); | |
| 658 | stat us = 'erro r'; | |
| 659 | xhr. error = er rMsg = (er r || statu s); | |
| 660 | } | |
| 661 | ||
| 662 | if (xhr. aborted) { | |
| 663 | log( 'upload ab orted'); | |
| 664 | stat us = null; | |
| 665 | } | |
| 666 | ||
| 667 | if (xhr. status) { // we've s et xhr.sta tus | |
| 668 | stat us = (xhr. status >= 200 && xhr .status < 300 || xhr .status == = 304) ? ' success' : 'error'; | |
| 669 | } | |
| 670 | ||
| 671 | // order ing of the se callbac ks/trigger s is odd, but that's how $.aja x does it | |
| 672 | if (stat us === 'su ccess') { | |
| 673 | if ( s.success) | |
| 674 | s.success. call(s.con text, data , 'success ', xhr); | |
| 675 | defe rred.resol ve(xhr.res ponseText, 'success' , xhr); | |
| 676 | if ( g) | |
| 677 | $.event.tr igger("aja xSuccess", [xhr, s]) ; | |
| 678 | } | |
| 679 | else if (status) { | |
| 680 | if ( errMsg === undefined ) | |
| 681 | errMsg = x hr.statusT ext; | |
| 682 | if ( s.error) | |
| 683 | s.error.ca ll(s.conte xt, xhr, s tatus, err Msg); | |
| 684 | defe rred.rejec t(xhr, 'er ror', errM sg); | |
| 685 | if ( g) | |
| 686 | $.event.tr igger("aja xError", [ xhr, s, er rMsg]); | |
| 687 | } | |
| 688 | ||
| 689 | if (g) | |
| 690 | $.ev ent.trigge r("ajaxCom plete", [x hr, s]); | |
| 691 | ||
| 692 | if (g && ! --$.act ive) { | |
| 693 | $.ev ent.trigge r("ajaxSto p"); | |
| 694 | } | |
| 695 | ||
| 696 | if (s.co mplete) | |
| 697 | s.co mplete.cal l(s.contex t, xhr, st atus); | |
| 698 | ||
| 699 | callback Processed = true; | |
| 700 | if (s.ti meout) | |
| 701 | clea rTimeout(t imeoutHand le); | |
| 702 | ||
| 703 | // clean up | |
| 704 | setTimeo ut(functio n() { | |
| 705 | if ( !s.iframeT arget) | |
| 706 | $io.remove (); | |
| 707 | xhr. responseXM L = null; | |
| 708 | }, 100); | |
| 709 | } | |
| 710 | ||
| 711 | va r toXml = $.parseXML || functi on(s, doc) { // use parseXML i f availabl e (jQuery 1.5+) | |
| 712 | if (wind ow.ActiveX Object) { | |
| 713 | doc = new Acti veXObject( 'Microsoft .XMLDOM'); | |
| 714 | doc. async = 'f alse'; | |
| 715 | doc. loadXML(s) ; | |
| 716 | } | |
| 717 | else { | |
| 718 | doc = (new DOM Parser()). parseFromS tring(s, ' text/xml') ; | |
| 719 | } | |
| 720 | return ( doc && doc .documentE lement && doc.docume ntElement. nodeName ! = 'parsere rror') ? d oc : null; | |
| 721 | }; | |
| 722 | va r parseJSO N = $.pars eJSON || f unction(s) { | |
| 723 | /*jslint evil:true */ | |
| 724 | return w indow['eva l']('(' + s + ')'); | |
| 725 | }; | |
| 726 | ||
| 727 | va r httpData = functio n( xhr, ty pe, s ) { // mostly lifted fro m jq1.4.4 | |
| 728 | var ct = xhr.getRe sponseHead er('conten t-type') | | '', | |
| 729 | xml = type === 'xml' || !type && c t.indexOf( 'xml') >= 0, | |
| 730 | data = xml ? x hr.respons eXML : xhr .responseT ext; | |
| 731 | ||
| 732 | if (xml && data.do cumentElem ent.nodeNa me === 'pa rsererror' ) { | |
| 733 | if ( $.error) | |
| 734 | $.error('p arsererror '); | |
| 735 | } | |
| 736 | if (s && s.dataFil ter) { | |
| 737 | data = s.dataF ilter(data , type); | |
| 738 | } | |
| 739 | if (type of data == = 'string' ) { | |
| 740 | if ( type === ' json' || ! type && ct .indexOf(' json') >= 0) { | |
| 741 | data = par seJSON(dat a); | |
| 742 | } el se if (typ e === "scr ipt" || !t ype && ct. indexOf("j avascript" ) >= 0) { | |
| 743 | $.globalEv al(data); | |
| 744 | } | |
| 745 | } | |
| 746 | return d ata; | |
| 747 | }; | |
| 748 | ||
| 749 | re turn defer red; | |
| 750 | } | |
| 751 | }; | |
| 752 | ||
| 753 | /** | |
| 754 | * ajaxFor m() provid es a mecha nism for f ully autom ating form submissio n. | |
| 755 | * | |
| 756 | * The adv antages of using thi s method i nstead of ajaxSubmit () are: | |
| 757 | * | |
| 758 | * 1: This method wi ll include coordinat es for <in put type=" image" /> elements ( if the ele ment | |
| 759 | * is u sed to sub mit the fo rm). | |
| 760 | * 2. This method wi ll include the submi t element' s name/val ue data (f or the ele ment that was | |
| 761 | * used to submit the form) . | |
| 762 | * 3. This method bi nds the su bmit() met hod to the form for you. | |
| 763 | * | |
| 764 | * The opt ions argum ent for aj axForm wor ks exactly as it doe s for ajax Submit. a jaxForm me rely | |
| 765 | * passes the option s argument along aft er properl y binding events for submit el ements and | |
| 766 | * the for m itself. | |
| 767 | */ | |
| 768 | $.fn.ajaxF orm = func tion(optio ns) { | |
| 769 | option s = option s || {}; | |
| 770 | option s.delegati on = optio ns.delegat ion && $.i sFunction( $.fn.on); | |
| 771 | ||
| 772 | // in jQuery 1.3 + we can f ix mistake s with the ready sta te | |
| 773 | if (!o ptions.del egation && this.leng th === 0) { | |
| 774 | va r o = { s: this.sele ctor, c: t his.contex t }; | |
| 775 | if (!$.isRea dy && o.s) { | |
| 776 | log('DOM not ready , queuing ajaxForm') ; | |
| 777 | $(functi on() { | |
| 778 | $(o. s,o.c).aja xForm(opti ons); | |
| 779 | }); | |
| 780 | return t his; | |
| 781 | } | |
| 782 | // is your D OM ready? http://do cs.jquery. com/Tutori als:Introd ucing_$(do cument).re ady() | |
| 783 | lo g('termina ting; zero elements found by s elector' + ($.isRead y ? '' : ' (DOM not ready)')); | |
| 784 | re turn this; | |
| 785 | } | |
| 786 | ||
| 787 | if ( o ptions.del egation ) { | |
| 788 | $( document) | |
| 789 | .off('su bmit.form- plugin', t his.select or, doAjax Submit) | |
| 790 | .off('cl ick.form-p lugin', th is.selecto r, capture Submitting Element) | |
| 791 | .on('sub mit.form-p lugin', th is.selecto r, options , doAjaxSu bmit) | |
| 792 | .on('cli ck.form-pl ugin', thi s.selector , options, captureSu bmittingEl ement); | |
| 793 | re turn this; | |
| 794 | } | |
| 795 | ||
| 796 | return this.ajax FormUnbind () | |
| 797 | .b ind('submi t.form-plu gin', opti ons, doAja xSubmit) | |
| 798 | .b ind('click .form-plug in', optio ns, captur eSubmittin gElement); | |
| 799 | }; | |
| 800 | ||
| 801 | // private event han dlers | |
| 802 | function d oAjaxSubmi t(e) { | |
| 803 | /*jshi nt validth is:true */ | |
| 804 | var op tions = e. data; | |
| 805 | if (!e .isDefault Prevented( )) { // if event has been canc eled, don' t proceed | |
| 806 | e. preventDef ault(); | |
| 807 | $( this).ajax Submit(opt ions); | |
| 808 | } | |
| 809 | } | |
| 810 | ||
| 811 | function c aptureSubm ittingElem ent(e) { | |
| 812 | /*jshi nt validth is:true */ | |
| 813 | var ta rget = e.t arget; | |
| 814 | var $e l = $(targ et); | |
| 815 | if (!( $el.is("[t ype=submit ],[type=im age]"))) { | |
| 816 | // is this a child ele ment of th e submit e l? (ex: a span with in a butto n) | |
| 817 | va r t = $el. closest('[ type=submi t]'); | |
| 818 | if (t.length === 0) { | |
| 819 | return; | |
| 820 | } | |
| 821 | ta rget = t[0 ]; | |
| 822 | } | |
| 823 | var fo rm = this; | |
| 824 | form.c lk = targe t; | |
| 825 | if (ta rget.type == 'image' ) { | |
| 826 | if (e.offset X !== unde fined) { | |
| 827 | form.clk _x = e.off setX; | |
| 828 | form.clk _y = e.off setY; | |
| 829 | } else if (t ypeof $.fn .offset == 'function ') { | |
| 830 | var offs et = $el.o ffset(); | |
| 831 | form.clk _x = e.pag eX - offse t.left; | |
| 832 | form.clk _y = e.pag eY - offse t.top; | |
| 833 | } else { | |
| 834 | form.clk _x = e.pag eX - targe t.offsetLe ft; | |
| 835 | form.clk _y = e.pag eY - targe t.offsetTo p; | |
| 836 | } | |
| 837 | } | |
| 838 | // cle ar form va rs | |
| 839 | setTim eout(funct ion() { fo rm.clk = f orm.clk_x = form.clk _y = null; }, 100); | |
| 840 | } | |
| 841 | ||
| 842 | ||
| 843 | // ajaxFor mUnbind un binds the event hand lers that were bound by ajaxFo rm | |
| 844 | $.fn.ajaxF ormUnbind = function () { | |
| 845 | return this.unbi nd('submit .form-plug in click.f orm-plugin '); | |
| 846 | }; | |
| 847 | ||
| 848 | /** | |
| 849 | * formToA rray() gat hers form element da ta into an array of objects th at can | |
| 850 | * be pass ed to any of the fol lowing aja x function s: $.get, $.post, or load. | |
| 851 | * Each ob ject in th e array ha s both a ' name' and 'value' pr operty. A n example of | |
| 852 | * an arra y for a si mple login form migh t be: | |
| 853 | * | |
| 854 | * [ { nam e: 'userna me', value : ' PW ' }, { nam e: 'passwo rd', value : ' PW ' } ] | |
| 855 | * | |
| 856 | * It is t his array that is pa ssed to pr e-submit c allback fu nctions pr ovided to the | |
| 857 | * ajaxSub mit() and ajaxForm() methods. | |
| 858 | */ | |
| 859 | $.fn.formT oArray = f unction(se mantic, el ements) { | |
| 860 | var a = []; | |
| 861 | if (th is.length === 0) { | |
| 862 | re turn a; | |
| 863 | } | |
| 864 | ||
| 865 | var fo rm = this[ 0]; | |
| 866 | var el s = semant ic ? form. getElement sByTagName ('*') : fo rm.element s; | |
| 867 | if (!e ls) { | |
| 868 | re turn a; | |
| 869 | } | |
| 870 | ||
| 871 | var i, j,n,v,el,m ax,jmax; | |
| 872 | for(i= 0, max=els .length; i < max; i+ +) { | |
| 873 | el = els[i]; | |
| 874 | n = el.name; | |
| 875 | if (!n || el .disabled) { | |
| 876 | continue ; | |
| 877 | } | |
| 878 | ||
| 879 | if (semantic && form.c lk && el.t ype == "im age") { | |
| 880 | // handl e image in puts on th e fly when semantic == true | |
| 881 | if(form. clk == el) { | |
| 882 | a.pu sh({name: n, value: $(el).val( ), type: e l.type }); | |
| 883 | a.pu sh({name: n+'.x', va lue: form. clk_x}, {n ame: n+'.y ', value: form.clk_y }); | |
| 884 | } | |
| 885 | continue ; | |
| 886 | } | |
| 887 | ||
| 888 | v = $.fieldV alue(el, t rue); | |
| 889 | if (v && v.c onstructor == Array) { | |
| 890 | if (elem ents) | |
| 891 | elem ents.push( el); | |
| 892 | for(j=0, jmax=v.le ngth; j < jmax; j++) { | |
| 893 | a.pu sh({name: n, value: v[j]}); | |
| 894 | } | |
| 895 | } | |
| 896 | el se if (fea ture.filea pi && el.t ype == 'fi le') { | |
| 897 | if (elem ents) | |
| 898 | elem ents.push( el); | |
| 899 | var file s = el.fil es; | |
| 900 | if (file s.length) { | |
| 901 | for (j=0; j < files.leng th; j++) { | |
| 902 | a.push({na me: n, val ue: files[ j], type: el.type}); | |
| 903 | } | |
| 904 | } | |
| 905 | else { | |
| 906 | // # 180 | |
| 907 | a.pu sh({ name: n, value: '', type: el.type } ); | |
| 908 | } | |
| 909 | } | |
| 910 | el se if (v ! == null && typeof v != 'undefi ned') { | |
| 911 | if (elem ents) | |
| 912 | elem ents.push( el); | |
| 913 | a.push({ name: n, v alue: v, t ype: el.ty pe, requir ed: el.req uired}); | |
| 914 | } | |
| 915 | } | |
| 916 | ||
| 917 | if (!s emantic && form.clk) { | |
| 918 | // input typ e=='image' are not f ound in el ements arr ay! handle it here | |
| 919 | va r $input = $(form.cl k), input = $input[0 ]; | |
| 920 | n = input.na me; | |
| 921 | if (n && !in put.disabl ed && inpu t.type == 'image') { | |
| 922 | a.push({ name: n, v alue: $inp ut.val()}) ; | |
| 923 | a.push({ name: n+'. x', value: form.clk_ x}, {name: n+'.y', v alue: form .clk_y}); | |
| 924 | } | |
| 925 | } | |
| 926 | return a; | |
| 927 | }; | |
| 928 | ||
| 929 | /** | |
| 930 | * Seriali zes form d ata into a 'submitta ble' strin g. This me thod will return a s tring | |
| 931 | * in the format: na me1=value1 &name2 =value2 | |
| 932 | */ | |
| 933 | $.fn.formS erialize = function( semantic) { | |
| 934 | //hand off to jQ uery.param for prope r encoding | |
| 935 | return $.param(t his.formTo Array(sema ntic)); | |
| 936 | }; | |
| 937 | ||
| 938 | /** | |
| 939 | * Seriali zes all fi eld elemen ts in the jQuery obj ect into a query str ing. | |
| 940 | * This me thod will return a s tring in t he format: name1=val ue1&na me2=value2 | |
| 941 | */ | |
| 942 | $.fn.field Serialize = function (successfu l) { | |
| 943 | var a = []; | |
| 944 | this.e ach(functi on() { | |
| 945 | va r n = this .name; | |
| 946 | if (!n) { | |
| 947 | return; | |
| 948 | } | |
| 949 | va r v = $.fi eldValue(t his, succe ssful); | |
| 950 | if (v && v.c onstructor == Array) { | |
| 951 | for (var i=0,max=v .length; i < max; i+ +) { | |
| 952 | a.pu sh({name: n, value: v[i]}); | |
| 953 | } | |
| 954 | } | |
| 955 | el se if (v ! == null && typeof v != 'undefi ned') { | |
| 956 | a.push({ name: this .name, val ue: v}); | |
| 957 | } | |
| 958 | }); | |
| 959 | //hand off to jQ uery.param for prope r encoding | |
| 960 | return $.param(a ); | |
| 961 | }; | |
| 962 | ||
| 963 | /** | |
| 964 | * Returns the value (s) of the element i n the matc hed set. For exampl e, conside r the foll owing form : | |
| 965 | * | |
| 966 | * <form> <fieldset> | |
| 967 | * <i nput name= "A" type=" text" /> | |
| 968 | * <i nput name= "A" type=" text" /> | |
| 969 | * <i nput name= "B" type=" checkbox" value="B1" /> | |
| 970 | * <i nput name= "B" type=" checkbox" value="B2" /> | |
| 971 | * <i nput name= "C" type=" radio" val ue="C1" /> | |
| 972 | * <i nput name= "C" type=" radio" val ue="C2" /> | |
| 973 | * </fiel dset></for m> | |
| 974 | * | |
| 975 | * var v = $('input [type=text ]').fieldV alue(); | |
| 976 | * // if no values are entere d into the text inpu ts | |
| 977 | * v == [ '',''] | |
| 978 | * // if values ent ered into the text i nputs are 'foo' and 'bar' | |
| 979 | * v == [ 'foo','bar '] | |
| 980 | * | |
| 981 | * var v = $('input [type=chec kbox]').fi eldValue() ; | |
| 982 | * // if neither ch eckbox is checked | |
| 983 | * v === undefined | |
| 984 | * // if both check boxes are checked | |
| 985 | * v == [ 'B1', 'B2' ] | |
| 986 | * | |
| 987 | * var v = $('input [type=radi o]').field Value(); | |
| 988 | * // if neither ra dio is che cked | |
| 989 | * v === undefined | |
| 990 | * // if first radi o is check ed | |
| 991 | * v == [ 'C1'] | |
| 992 | * | |
| 993 | * The suc cessful ar gument con trols whet her or not the field element m ust be 'su ccessful' | |
| 994 | * (per ht tp://www.w 3.org/TR/h tml4/inter act/forms. html#succe ssful-cont rols). | |
| 995 | * The def ault value of the su ccessful a rgument is true. If this valu e is false the value (s) | |
| 996 | * for eac h element is returne d. | |
| 997 | * | |
| 998 | * Note: T his method *always* returns an array. I f no valid value can be determ ined the | |
| 999 | * arra y will be empty, oth erwise it will conta in one or more value s. | |
| 1000 | */ | |
| 1001 | $.fn.field Value = fu nction(suc cessful) { | |
| 1002 | for (v ar val=[], i=0, max= this.lengt h; i < max ; i++) { | |
| 1003 | va r el = thi s[i]; | |
| 1004 | va r v = $.fi eldValue(e l, success ful); | |
| 1005 | if (v === nu ll || type of v == 'u ndefined' || (v.cons tructor == Array && !v.length) ) { | |
| 1006 | continue ; | |
| 1007 | } | |
| 1008 | if (v.constr uctor == A rray) | |
| 1009 | $.merge( val, v); | |
| 1010 | el se | |
| 1011 | val.push (v); | |
| 1012 | } | |
| 1013 | return val; | |
| 1014 | }; | |
| 1015 | ||
| 1016 | /** | |
| 1017 | * Returns the value of the fi eld elemen t. | |
| 1018 | */ | |
| 1019 | $.fieldVal ue = funct ion(el, su ccessful) { | |
| 1020 | var n = el.name, t = el.ty pe, tag = el.tagName .toLowerCa se(); | |
| 1021 | if (su ccessful = == undefin ed) { | |
| 1022 | su ccessful = true; | |
| 1023 | } | |
| 1024 | ||
| 1025 | if (su ccessful & & (!n || e l.disabled || t == ' reset' || t == 'butt on' || | |
| 1026 | (t == 'check box' || t == 'radio' ) && !el.c hecked || | |
| 1027 | (t == 'submi t' || t == 'image') && el.form && el.for m.clk != e l || | |
| 1028 | ta g == 'sele ct' && el. selectedIn dex == -1) ) { | |
| 1029 | return n ull; | |
| 1030 | } | |
| 1031 | ||
| 1032 | if (ta g == 'sele ct') { | |
| 1033 | va r index = el.selecte dIndex; | |
| 1034 | if (index < 0) { | |
| 1035 | return n ull; | |
| 1036 | } | |
| 1037 | va r a = [], ops = el.o ptions; | |
| 1038 | va r one = (t == 'selec t-one'); | |
| 1039 | va r max = (o ne ? index +1 : ops.l ength); | |
| 1040 | fo r(var i=(o ne ? index : 0); i < max; i++) { | |
| 1041 | var op = ops[i]; | |
| 1042 | if (op.s elected) { | |
| 1043 | var v = op.val ue; | |
| 1044 | if ( !v) { // e xtra pain for IE... | |
| 1045 | v = (op.at tributes & & op.attri butes['val ue'] && !( op.attribu tes['value '].specifi ed)) ? op. text : op. value; | |
| 1046 | } | |
| 1047 | if ( one) { | |
| 1048 | return v; | |
| 1049 | } | |
| 1050 | a.pu sh(v); | |
| 1051 | } | |
| 1052 | } | |
| 1053 | re turn a; | |
| 1054 | } | |
| 1055 | return $(el).val (); | |
| 1056 | }; | |
| 1057 | ||
| 1058 | /** | |
| 1059 | * Clears the form d ata. Take s the foll owing acti ons on the form's in put fields : | |
| 1060 | * - inpu t text fie lds will h ave their 'value' pr operty set to the em pty string | |
| 1061 | * - sele ct element s will hav e their 's electedInd ex' proper ty set to -1 | |
| 1062 | * - chec kbox and r adio input s will hav e their 'c hecked' pr operty set to false | |
| 1063 | * - inpu ts of type submit, b utton, res et, and hi dden will *not* be e ffected | |
| 1064 | * - butt on element s will *no t* be effe cted | |
| 1065 | */ | |
| 1066 | $.fn.clear Form = fun ction(incl udeHidden) { | |
| 1067 | return this.each (function( ) { | |
| 1068 | $( 'input,sel ect,textar ea', this) .clearFiel ds(include Hidden); | |
| 1069 | }); | |
| 1070 | }; | |
| 1071 | ||
| 1072 | /** | |
| 1073 | * Clears the select ed form el ements. | |
| 1074 | */ | |
| 1075 | $.fn.clear Fields = $ .fn.clearI nputs = fu nction(inc ludeHidden ) { | |
| 1076 | var re = /^(?:co lor|date|d atetime|em ail|month| number|pas sword|rang e|search|t el|text|ti me|url|wee k)$/i; // 'hidden' i s not in t his list | |
| 1077 | return this.each (function( ) { | |
| 1078 | va r t = this .type, tag = this.ta gName.toLo werCase(); | |
| 1079 | if (re.test( t) || tag == 'textar ea') { | |
| 1080 | this.val ue = ''; | |
| 1081 | } | |
| 1082 | el se if (t = = 'checkbo x' || t == 'radio') { | |
| 1083 | this.che cked = fal se; | |
| 1084 | } | |
| 1085 | el se if (tag == 'selec t') { | |
| 1086 | this.sel ectedIndex = -1; | |
| 1087 | } | |
| 1088 | else if (t == "file") { | |
| 1089 | if (/M SIE/.test( navigator. userAgent) ) { | |
| 1090 | $(this). replaceWit h($(this). clone(true )); | |
| 1091 | } else { | |
| 1092 | $(this). val(''); | |
| 1093 | } | |
| 1094 | } | |
| 1095 | el se if (inc ludeHidden ) { | |
| 1096 | // inclu deHidden c an be the value true , or it ca n be a sel ector stri ng | |
| 1097 | // indic ating a sp ecial test ; for exam ple: | |
| 1098 | // $('# myForm').c learForm(' .special:h idden') | |
| 1099 | // the a bove would clean hid den inputs that have the class of 'speci al' | |
| 1100 | if ( (in cludeHidde n === true && /hidde n/.test(t) ) || | |
| 1101 | (ty peof inclu deHidden = = 'string' && $(this ).is(inclu deHidden)) ) | |
| 1102 | this .value = ' '; | |
| 1103 | } | |
| 1104 | }); | |
| 1105 | }; | |
| 1106 | ||
| 1107 | /** | |
| 1108 | * Resets the form d ata. Caus es all for m elements to be res et to thei r original value. | |
| 1109 | */ | |
| 1110 | $.fn.reset Form = fun ction() { | |
| 1111 | return this.each (function( ) { | |
| 1112 | // guard aga inst an in put with t he name of 'reset' | |
| 1113 | // note that IE report s the rese t function as an 'ob ject' | |
| 1114 | if (typeof t his.reset == 'functi on' || (ty peof this. reset == ' object' && !this.res et.nodeTyp e)) { | |
| 1115 | this.res et(); | |
| 1116 | } | |
| 1117 | }); | |
| 1118 | }; | |
| 1119 | ||
| 1120 | /** | |
| 1121 | * Enables or disabl es any mat ching elem ents. | |
| 1122 | */ | |
| 1123 | $.fn.enabl e = functi on(b) { | |
| 1124 | if (b === undefi ned) { | |
| 1125 | b = true; | |
| 1126 | } | |
| 1127 | return this.each (function( ) { | |
| 1128 | th is.disable d = !b; | |
| 1129 | }); | |
| 1130 | }; | |
| 1131 | ||
| 1132 | /** | |
| 1133 | * Checks/ unchecks a ny matchin g checkbox es or radi o buttons and | |
| 1134 | * selects /deselects and match ing option elements. | |
| 1135 | */ | |
| 1136 | $.fn.selec ted = func tion(selec t) { | |
| 1137 | if (se lect === u ndefined) { | |
| 1138 | se lect = tru e; | |
| 1139 | } | |
| 1140 | return this.each (function( ) { | |
| 1141 | va r t = this .type; | |
| 1142 | if (t == 'ch eckbox' || t == 'rad io') { | |
| 1143 | this.che cked = sel ect; | |
| 1144 | } | |
| 1145 | el se if (thi s.tagName. toLowerCas e() == 'op tion') { | |
| 1146 | var $sel = $(this) .parent('s elect'); | |
| 1147 | if (sele ct && $sel [0] && $se l[0].type == 'select -one') { | |
| 1148 | // d eselect al l other op tions | |
| 1149 | $sel .find('opt ion').sele cted(false ); | |
| 1150 | } | |
| 1151 | this.sel ected = se lect; | |
| 1152 | } | |
| 1153 | }); | |
| 1154 | }; | |
| 1155 | ||
| 1156 | // expose debug var | |
| 1157 | $.fn.ajaxS ubmit.debu g = false; | |
| 1158 | ||
| 1159 | // helper fn for con sole loggi ng | |
| 1160 | function l og() { | |
| 1161 | if (!$ .fn.ajaxSu bmit.debug ) | |
| 1162 | re turn; | |
| 1163 | var ms g = '[jque ry.form] ' + Array.p rototype.j oin.call(a rguments,' '); | |
| 1164 | if (wi ndow.conso le && wind ow.console .log) { | |
| 1165 | wi ndow.conso le.log(msg ); | |
| 1166 | } | |
| 1167 | else i f (window. opera && w indow.oper a.postErro r) { | |
| 1168 | wi ndow.opera .postError (msg); | |
| 1169 | } | |
| 1170 | } | |
| 1171 | ||
| 1172 | })(jQuery) ; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.