357. File Comparison Report

Produced on Mon May 12 13:05:52 2008 UTC. This report uses XHTML and CSS2, and is best viewed with a reasonably standards compliant browser such as the latest version of Firefox or Internet Explorer. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

357.1 Files compared

# Location File Last Modified
1 Mon May 12 13:05:52 2008 UTC
2 Dolphin-v.6.1.0\plugins\jquery jquery.form.js Thu Mar 27 04:17:54 2008 UTC

357.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 1 869
Removed 0 0

357.3 Comparison options

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

357.4 Active regular expressions

No regular expressions were active.

357.5 Comparison detail

    1   /*
    2    * jQuery  Form Plugi n
    3    * version : 2.07 (03 /04/2008)
    4    * @requir es jQuery  v1.2.2 or  later
    5    *
    6    * Example s at: http ://malsup. com/jquery /form/
    7    * Dual li censed und er the MIT  and GPL l icenses:
    8    *   http: //www.open source.org /licenses/ mit-licens e.php
    9    *   http: //www.gnu. org/licens es/gpl.htm l
    10    *
    11    * Revisio n: $Id$
    12    */
    13    (function ($) {
    14   /**
    15    * ajaxSub mit() prov ides a mec hanism for  submittin g an HTML  form using  AJAX.
    16    *
    17    * ajaxSub mit accept s a single  argument  which can  be either  a success  callback f unction
    18    * or an o ptions Obj ect.  If a  function  is provide d it will  be invoked  upon succ essful
    19    * complet ion of the  submit an d will be  passed the  response  from the s erver.
    20    * If an o ptions Obj ect is pro vided, the  following  attribute s are supp orted:
    21    *
    22    *  target :   Identi fies the e lement(s)  in the pag e to be up dated with  the serve r response .
    23    *             This v alue may b e specifie d as a jQu ery select ion string , a jQuery  object,
    24    *             or a D OM element .
    25    *             defaul t value: n ull
    26    *
    27    *  url:       URL to  which the  form data  will be s ubmitted.
    28    *             defaul t value: v alue of fo rm's 'acti on' attrib ute
    29    *
    30    *  type:      The me thod in wh ich the fo rm data sh ould be su bmitted, ' GET' or 'P OST'.
    31    *             defaul t value: v alue of fo rm's 'meth od' attrib ute (or 'G ET' if non e found)
    32    *
    33    *  data:      Additi onal data  to add to  the reques t, specifi ed as key/ value pair s (see $.a jax).
    34    *
    35    *  before Submit:  C allback me thod to be  invoked b efore the  form is su bmitted.
    36    *             defaul t value: n ull
    37    *
    38    *  succes s:  Callba ck method  to be invo ked after  the form h as been su ccessfully  submitted
    39    *             and th e response  has been  returned f rom the se rver
    40    *             defaul t value: n ull
    41    *
    42    *  dataTy pe: Expect ed dataTyp e of the r esponse.   One of: nu ll, 'xml',  'script',  or 'json'
    43    *             defaul t value: n ull
    44    *
    45    *  semant ic: Boolea n flag ind icating wh ether data  must be s ubmitted i n semantic  order (sl ower).
    46    *             defaul t value: f alse
    47    *
    48    *  resetF orm: Boole an flag in dicating w hether the  form shou ld be rese t if the s ubmit is s uccessful
    49    *
    50    *  clearF orm: Boole an flag in dicating w hether the  form shou ld be clea red if the  submit is  successfu l
    51    *
    52    *
    53    * The 'be foreSubmit ' callback  can be pr ovided as  a hook for  running p re-submit  logic or f or
    54    * validat ing the fo rm data.   If the 'be foreSubmit ' callback  returns f alse then  the form w ill
    55    * not be  submitted.  The 'befo reSubmit'  callback i s invoked  with three  arguments : the form  data
    56    * in arra y format,  the jQuery  object, a nd the opt ions objec t passed i nto ajaxSu bmit.
    57    * The for m data arr ay takes t he followi ng form:
    58    *
    59    *     [ {  name: 'us ername', v alue: 'jre sig' }, {  name: 'pas sword', va lue: 'secr et' } ]
    60    *
    61    * If a 's uccess' ca llback met hod is pro vided it i s invoked  after the  response h as been re turned
    62    * from th e server.   It is pas sed the re sponseText  or respon seXML valu e (dependi ng on data Type).
    63    * See jQu ery.ajax f or further  details.
    64    *
    65    *
    66    * The dat aType opti on provide s a means  for specif ying how t he server  response s hould be h andled.
    67    * This ma ps directl y to the j Query.http Data metho d.  The fo llowing va lues are s upported:
    68    *
    69    *      'x ml':    if  dataType  == 'xml' t he server  response i s treated  as XML and  the 'succ ess'
    70    *                     callback  method, if  specified , will be  passed the  responseX ML value
    71    *      'j son':   if  dataType  == 'json'  the server  response  will be ev aluted and  passed to
    72    *                     the 'succ ess' callb ack, if sp ecified
    73    *      's cript': if  dataType  == 'script ' the serv er respons e is evalu ated in th e global c ontext
    74    *
    75    *
    76    * Note th at it does  not make  sense to u se both th e 'target'  and 'data Type' opti ons.  If b oth
    77    * are pro vided the  target wil l be ignor ed.
    78    *
    79    * The sem antic argu ment can b e used to  force form  serializa tion in se mantic ord er.
    80    * This is  normally  true anywa y, unless  the form c ontains in put elemen ts of type ='image'.
    81    * If your  form must  be submit ted with n ame/value  pairs in s emantic or der and yo ur form
    82    * contain s an input  of type=' image" the n pass tru e for this  arg, othe rwise pass  false
    83    * (or not hing) to a void the o verhead fo r this log ic.
    84    *
    85    *
    86    * When us ed on its  own, ajaxS ubmit() is  typically  bound to  a form's s ubmit even t like thi s:
    87    *
    88    * $("#for m-id").sub mit(functi on() {
    89    *     $(t his).ajaxS ubmit(opti ons);
    90    *     ret urn false;  // cancel  conventio nal submit
    91    * });
    92    *
    93    * When us ing ajaxFo rm(), howe ver, this  is done fo r you.
    94    *
    95    * @exampl e
    96    * $('#myF orm').ajax Submit(fun ction(data ) {
    97    *     ale rt('Form s ubmit succ eeded! Ser ver return ed: ' + da ta);
    98    * });
    99    * @desc S ubmit form  and alert  server re sponse
    100    *
    101    *
    102    * @exampl e
    103    * var opt ions = {
    104    *     tar get: '#myT argetDiv'
    105    * };
    106    * $('#myF orm').ajax Submit(opt ions);
    107    * @desc S ubmit form  and updat e page ele ment with  server res ponse
    108    *
    109    *
    110    * @exampl e
    111    * var opt ions = {
    112    *     suc cess: func tion(respo nseText) {
    113    *          alert(res ponseText) ;
    114    *     }
    115    * };
    116    * $('#myF orm').ajax Submit(opt ions);
    117    * @desc S ubmit form  and alert  the serve r response
    118    *
    119    *
    120    * @exampl e
    121    * var opt ions = {
    122    *     bef oreSubmit:  function( formArray,  jqForm) {
    123    *          if (formA rray.lengt h == 0) {
    124    *              alert ('Please e nter data. ');
    125    *              retur n false;
    126    *          }
    127    *     }
    128    * };
    129    * $('#myF orm').ajax Submit(opt ions);
    130    * @desc P re-submit  validation  which abo rts the su bmit opera tion if fo rm data is  empty
    131    *
    132    *
    133    * @exampl e
    134    * var opt ions = {
    135    *     url : myJsonUr l.php,
    136    *     dat aType: 'js on',
    137    *     suc cess: func tion(data)  {
    138    *         // 'data'  is an obje ct represe nting the  the evalua ted json d ata
    139    *     }
    140    * };
    141    * $('#myF orm').ajax Submit(opt ions);
    142    * @desc j son data r eturned an d evaluate d
    143    *
    144    *
    145    * @exampl e
    146    * var opt ions = {
    147    *     url : myXmlUrl .php,
    148    *     dat aType: 'xm l',
    149    *     suc cess: func tion(respo nseXML) {
    150    *         // respons eXML is XM L document  object
    151    *         var data =  $('myElem ent', resp onseXML).t ext();
    152    *     }
    153    * };
    154    * $('#myF orm').ajax Submit(opt ions);
    155    * @desc X ML data re turned fro m server
    156    *
    157    *
    158    * @exampl e
    159    * var opt ions = {
    160    *     res etForm: tr ue
    161    * };
    162    * $('#myF orm').ajax Submit(opt ions);
    163    * @desc s ubmit form  and reset  it if suc cessful
    164    *
    165    * @exampl e
    166    * $('#myF orm).submi t(function () {
    167    *    $(th is).ajaxSu bmit();
    168    *    retu rn false;
    169    * });
    170    * @desc B ind form's  submit ev ent to use  ajaxSubmi t
    171    *
    172    *
    173    * @name a jaxSubmit
    174    * @type j Query
    175    * @param  options  o bject lite ral contai ning optio ns which c ontrol the  form subm ission pro cess
    176    * @cat Pl ugins/Form
    177    * @return  jQuery
    178    */
    179   $.fn.ajaxS ubmit = fu nction(opt ions) {
    180       if (ty peof optio ns == 'fun ction')
    181           op tions = {  success: o ptions };
    182  
    183       option s = $.exte nd({
    184           ur l:  this.a ttr('actio n') || win dow.locati on.toStrin g(),
    185           ty pe: this.a ttr('metho d') || 'GE T'
    186       }, opt ions || {} );
    187  
    188       // hoo k for mani pulating t he form da ta before  it is extr acted;
    189       // con venient fo r use with  rich edit ors like t inyMCE or  FCKEditor
    190       var ve to = {};
    191       this.t rigger('fo rm-pre-ser ialize', [ this, opti ons, veto] );
    192       if (ve to.veto) r eturn this ;
    193  
    194       var a  = this.for mToArray(o ptions.sem antic);
    195       if (op tions.data ) {
    196           op tions.extr aData = op tions.data ;
    197           fo r (var n i n options. data)
    198                a.push(  { name: n,  value: op tions.data [n] } );
    199       }
    200  
    201       // giv e pre-subm it callbac k an oppor tunity to  abort the  submit
    202       if (op tions.befo reSubmit & & options. beforeSubm it(a, this , options)  === false ) return t his;
    203  
    204       // fir e vetoable  'validate ' event
    205       this.t rigger('fo rm-submit- validate',  [a, this,  options,  veto]);
    206       if (ve to.veto) r eturn this ;
    207  
    208       var q  = $.param( a);
    209  
    210       if (op tions.type .toUpperCa se() == 'G ET') {
    211           op tions.url  += (option s.url.inde xOf('?') > = 0 ? '&'  : '?') + q ;
    212           op tions.data  = null;   // data is  null for  'get'
    213       }
    214       else
    215           op tions.data  = q; // d ata is the  query str ing for 'p ost'
    216  
    217       var $f orm = this , callback s = [];
    218       if (op tions.rese tForm) cal lbacks.pus h(function () { $form .resetForm (); });
    219       if (op tions.clea rForm) cal lbacks.pus h(function () { $form .clearForm (); });
    220  
    221       // per form a loa d on the t arget only  if dataTy pe is not  provided
    222       if (!o ptions.dat aType && o ptions.tar get) {
    223           va r oldSucce ss = optio ns.success  || functi on(){};
    224           ca llbacks.pu sh(functio n(data) {
    225                $(option s.target). html(data) .each(oldS uccess, ar guments);
    226           }) ;
    227       }
    228       else i f (options .success)
    229           ca llbacks.pu sh(options .success);
    230  
    231       option s.success  = function (data, sta tus) {
    232           fo r (var i=0 , max=call backs.leng th; i < ma x; i++)
    233                callback s[i](data,  status, $ form);
    234       };
    235  
    236       // are  there fil es to uplo ad?
    237       var fi les = $('i nput:file' , this).fi eldValue() ;
    238       var fo und = fals e;
    239       for (v ar j=0; j  < files.le ngth; j++)
    240           if  (files[j] )
    241                found =  true;
    242  
    243       // opt ions.ifram e allows u ser to for ce iframe  mode
    244      if (opt ions.ifram e || found ) { 
    245          //  hack to fi x Safari h ang (thank s to Tim M olendijk f or this)
    246          //  see:  http ://groups. google.com /group/jqu ery-dev/br owse_threa d/thread/3 6395b7ab51 0dd5d
    247          if  ($.browser .safari &&  options.c loseKeepAl ive)
    248               $.get(opt ions.close KeepAlive,  fileUploa d);
    249          els e
    250               fileUploa d();
    251          }
    252      else
    253          $.a jax(option s);
    254  
    255       // fir e 'notify'  event
    256       this.t rigger('fo rm-submit- notify', [ this, opti ons]);
    257       return  this;
    258  
    259  
    260       // pri vate funct ion for ha ndling fil e uploads  (hat tip t o YAHOO!)
    261       functi on fileUpl oad() {
    262           va r form = $ form[0];
    263           va r opts = $ .extend({} , $.ajaxSe ttings, op tions);
    264  
    265           va r id = 'jq FormIO' +  (new Date( ).getTime( ));
    266           va r $io = $( '<iframe i d="' + id  + '" name= "' + id +  '" />');
    267           va r io = $io [0];
    268           va r op8 = $. browser.op era && win dow.opera. version()  < 9;
    269           if  ($.browse r.msie ||  op8) io.sr c = 'javas cript:fals e;document .write("") ;';
    270           $i o.css({ po sition: 'a bsolute',  top: '-100 0px', left : '-1000px ' });
    271  
    272           va r xhr = {  // mock ob ject
    273                response Text: null ,
    274                response XML: null,
    275                status:  0,
    276                statusTe xt: 'n/a',
    277                getAllRe sponseHead ers: funct ion() {},
    278                getRespo nseHeader:  function( ) {},
    279                setReque stHeader:  function()  {}
    280           };
    281  
    282           va r g = opts .global;
    283           //  trigger a jax global  events so  that acti vity/block  indicator s work lik e normal
    284           if  (g && ! $ .active++)  $.event.t rigger("aj axStart");
    285           if  (g) $.eve nt.trigger ("ajaxSend ", [xhr, o pts]);
    286  
    287           va r cbInvoke d = 0;
    288           va r timedOut  = 0;
    289  
    290           //  take a br eath so th at pending  repaints  get some c pu time be fore the u pload star ts
    291           se tTimeout(f unction()  {
    292                // make  sure form  attrs are  set
    293                var t =  $form.attr ('target') , a = $for m.attr('ac tion');
    294                $form.at tr({
    295                    targ et:   id,
    296                    enco ding: 'mul tipart/for m-data',
    297                    enct ype:  'mul tipart/for m-data',
    298                    meth od:   'POS T',
    299                    acti on:   opts .url
    300                });
    301  
    302                // suppo rt timout
    303                if (opts .timeout)
    304                    setT imeout(fun ction() {  timedOut =  true; cb( ); }, opts .timeout);
    305  
    306                // add " extra" dat a to form  if provide d in optio ns
    307                var extr aInputs =  [];
    308                try {
    309                    if ( options.ex traData)
    310                         for (var n  in option s.extraDat a)
    311                             extraI nputs.push (
    312                                 $( '<input ty pe="hidden " name="'+ n+'" value ="'+option s.extraDat a[n]+'" /> ')
    313                                      .appendT o(form)[0] );
    314                
    315                    // a dd iframe  to doc and  submit th e form
    316                    $io. appendTo(' body');
    317                    io.a ttachEvent  ? io.atta chEvent('o nload', cb ) : io.add EventListe ner('load' , cb, fals e);
    318                    form .submit();
    319                }
    320                finally  {
    321                    // r eset attrs  and remov e "extra"  input elem ents
    322                    $for m.attr('ac tion', a);
    323                    t ?  $form.attr ('target',  t) : $for m.removeAt tr('target ');
    324                    $(ex traInputs) .remove();
    325                }
    326           },  10);
    327  
    328           fu nction cb( ) {
    329                if (cbIn voked++) r eturn;
    330  
    331                io.detac hEvent ? i o.detachEv ent('onloa d', cb) :  io.removeE ventListen er('load',  cb, false );
    332  
    333                var ok =  true;
    334                try {
    335                    if ( timedOut)  throw 'tim eout';
    336                    // e xtract the  server re sponse fro m the ifra me
    337                    var  data, doc;
    338                    doc  = io.conte ntWindow ?  io.conten tWindow.do cument : i o.contentD ocument ?  io.content Document :  io.docume nt;
    339                    xhr. responseTe xt = doc.b ody ? doc. body.inner HTML : nul l;
    340                    xhr. responseXM L = doc.XM LDocument  ? doc.XMLD ocument :  doc;
    341                    xhr. getRespons eHeader =  function(h eader){
    342                         var header s = {'cont ent-type':  opts.data Type};
    343                         return hea ders[heade r];
    344                    };
    345  
    346                    if ( opts.dataT ype == 'js on' || opt s.dataType  == 'scrip t') {
    347                         var ta = d oc.getElem entsByTagN ame('texta rea')[0];
    348                         xhr.respon seText = t a ? ta.val ue : xhr.r esponseTex t;
    349                    }
    350                    else  if (opts. dataType = = 'xml' &&  !xhr.resp onseXML &&  xhr.respo nseText !=  null) {
    351                         xhr.respon seXML = to Xml(xhr.re sponseText );
    352                    }
    353                    data  = $.httpD ata(xhr, o pts.dataTy pe);
    354                }
    355                catch(e) {
    356                    ok =  false;
    357                    $.ha ndleError( opts, xhr,  'error',  e);
    358                }
    359  
    360                // order ing of the se callbac ks/trigger s is odd,  but that's  how $.aja x does it
    361                if (ok)  {
    362                    opts .success(d ata, 'succ ess');
    363                    if ( g) $.event .trigger(" ajaxSucces s", [xhr,  opts]);
    364                }
    365                if (g) $ .event.tri gger("ajax Complete",  [xhr, opt s]);
    366                if (g &&  ! --$.act ive) $.eve nt.trigger ("ajaxStop ");
    367                if (opts .complete)  opts.comp lete(xhr,  ok ? 'succ ess' : 'er ror');
    368  
    369                // clean  up
    370                setTimeo ut(functio n() {
    371                    $io. remove();
    372                    xhr. responseXM L = null;
    373                }, 100);
    374           };
    375  
    376           fu nction toX ml(s, doc)  {
    377                if (wind ow.ActiveX Object) {
    378                    doc  = new Acti veXObject( 'Microsoft .XMLDOM');
    379                    doc. async = 'f alse';
    380                    doc. loadXML(s) ;
    381                }
    382                else
    383                    doc  = (new DOM Parser()). parseFromS tring(s, ' text/xml') ;
    384                return ( doc && doc .documentE lement &&  doc.docume ntElement. tagName !=  'parserer ror') ? do c : null;
    385           };
    386       };
    387   };
    388  
    389   /**
    390    * ajaxFor m() provid es a mecha nism for f ully autom ating form  submissio n.
    391    *
    392    * The adv antages of  using thi s method i nstead of  ajaxSubmit () are:
    393    *
    394    * 1: This  method wi ll include  coordinat es for <in put type=" image" />  elements ( if the ele ment
    395    *    is u sed to sub mit the fo rm).
    396    * 2. This  method wi ll include  the submi t element' s name/val ue data (f or the ele ment that  was
    397    *    used  to submit  the form) .
    398    * 3. This  method bi nds the su bmit() met hod to the  form for  you.
    399    *
    400    * Note th at for acc urate x/y  coordinate s of image  submit el ements in  all browse rs
    401    * you nee d to also  use the "d imensions"  plugin (t his method  will auto -detect it s presence ).
    402    *
    403    * The opt ions argum ent for aj axForm wor ks exactly  as it doe s for ajax Submit.  a jaxForm me rely
    404    * passes  the option s argument  along aft er properl y binding  events for  submit el ements and
    405    * the for m itself.   See ajaxS ubmit for  a full des cription o f the opti ons argume nt.
    406    *
    407    *
    408    * @exampl e
    409    * var opt ions = {
    410    *     tar get: '#myT argetDiv'
    411    * };
    412    * $('#myF orm').ajax SForm(opti ons);
    413    * @desc B ind form's  submit ev ent so tha t 'myTarge tDiv' is u pdated wit h the serv er respons e
    414    *       w hen the fo rm is subm itted.
    415    *
    416    *
    417    * @exampl e
    418    * var opt ions = {
    419    *     suc cess: func tion(respo nseText) {
    420    *          alert(res ponseText) ;
    421    *     }
    422    * };
    423    * $('#myF orm').ajax Submit(opt ions);
    424    * @desc B ind form's  submit ev ent so tha t server r esponse is  alerted a fter the f orm is sub mitted.
    425    *
    426    *
    427    * @exampl e
    428    * var opt ions = {
    429    *     bef oreSubmit:  function( formArray,  jqForm) {
    430    *          if (formA rray.lengt h == 0) {
    431    *              alert ('Please e nter data. ');
    432    *              retur n false;
    433    *          }
    434    *     }
    435    * };
    436    * $('#myF orm').ajax Submit(opt ions);
    437    * @desc B ind form's  submit ev ent so tha t pre-subm it callbac k is invok ed before  the form
    438    *       i s submitte d.
    439    *
    440    *
    441    * @name    ajaxForm
    442    * @param   options   object lit eral conta ining opti ons which  control th e form sub mission pr ocess
    443    * @return  jQuery
    444    * @cat     Plugins/F orm
    445    * @type    jQuery
    446    */
    447   $.fn.ajaxF orm = func tion(optio ns) {
    448       return  this.ajax FormUnbind ().bind('s ubmit.form -plugin',f unction()  {
    449           $( this).ajax Submit(opt ions);
    450           re turn false ;
    451       }).eac h(function () {
    452           //  store opt ions in ha sh
    453           $( ":submit,i nput:image ", this).b ind('click .form-plug in',functi on(e) {
    454                var $for m = this.f orm;
    455                $form.cl k = this;
    456                if (this .type == ' image') {
    457                    if ( e.offsetX  != undefin ed) {
    458                         $form.clk_ x = e.offs etX;
    459                         $form.clk_ y = e.offs etY;
    460                    } el se if (typ eof $.fn.o ffset == ' function')  { // try  to use dim ensions pl ugin
    461                         var offset  = $(this) .offset();
    462                         $form.clk_ x = e.page X - offset .left;
    463                         $form.clk_ y = e.page Y - offset .top;
    464                    } el se {
    465                         $form.clk_ x = e.page X - this.o ffsetLeft;
    466                         $form.clk_ y = e.page Y - this.o ffsetTop;
    467                    }
    468                }
    469                // clear  form vars
    470                setTimeo ut(functio n() { $for m.clk = $f orm.clk_x  = $form.cl k_y = null ; }, 10);
    471           }) ;
    472       });
    473   };
    474  
    475  
    476   /**
    477    * ajaxFor mUnbind un binds the  event hand lers that  were bound  by ajaxFo rm
    478    *
    479    * @name    ajaxFormU nbind
    480    * @return  jQuery
    481    * @cat     Plugins/F orm
    482    * @type    jQuery
    483    */
    484   $.fn.ajaxF ormUnbind  = function () {
    485       this.u nbind('sub mit.form-p lugin');
    486       return  this.each (function( ) {
    487           $( ":submit,i nput:image ", this).u nbind('cli ck.form-pl ugin');
    488       });
    489  
    490   };
    491  
    492   /**
    493    * formToA rray() gat hers form  element da ta into an  array of  objects th at can
    494    * be pass ed to any  of the fol lowing aja x function s: $.get,  $.post, or  load.
    495    * Each ob ject in th e array ha s both a ' name' and  'value' pr operty.  A n example  of
    496    * an arra y for a si mple login  form migh t be:
    497    *
    498    * [ { nam e: 'userna me', value : 'jresig'  }, { name : 'passwor d', value:  'secret'  } ]
    499    *
    500    * It is t his array  that is pa ssed to pr e-submit c allback fu nctions pr ovided to  the
    501    * ajaxSub mit() and  ajaxForm()  methods.
    502    *
    503    * The sem antic argu ment can b e used to  force form  serializa tion in se mantic ord er.
    504    * This is  normally  true anywa y, unless  the form c ontains in put elemen ts of type ='image'.
    505    * If your  form must  be submit ted with n ame/value  pairs in s emantic or der and yo ur form
    506    * contain s an input  of type=' image" the n pass tru e for this  arg, othe rwise pass  false
    507    * (or not hing) to a void the o verhead fo r this log ic.
    508    *
    509    * @exampl e var data  = $("#myF orm").form ToArray();
    510    * $.post(  "myscript .cgi", dat a );
    511    * @desc C ollect all  the data  from a for m and subm it it to t he server.
    512    *
    513    * @name f ormToArray
    514    * @param  semantic t rue if ser ialization  must main tain stric t semantic  ordering  of element s (slower)
    515    * @type A rray<Objec t>
    516    * @cat Pl ugins/Form
    517    */
    518   $.fn.formT oArray = f unction(se mantic) {
    519       var a  = [];
    520       if (th is.length  == 0) retu rn a;
    521  
    522       var fo rm = this[ 0];
    523       var el s = semant ic ? form. getElement sByTagName ('*') : fo rm.element s;
    524       if (!e ls) return  a;
    525       for(va r i=0, max =els.lengt h; i < max ; i++) {
    526           va r el = els [i];
    527           va r n = el.n ame;
    528           if  (!n) cont inue;
    529  
    530           if  (semantic  && form.c lk && el.t ype == "im age") {
    531                // handl e image in puts on th e fly when  semantic  == true
    532                if(!el.d isabled &&  form.clk  == el)
    533                    a.pu sh({name:  n+'.x', va lue: form. clk_x}, {n ame: n+'.y ', value:  form.clk_y });
    534                continue ;
    535           }
    536  
    537           va r v = $.fi eldValue(e l, true);
    538           if  (v && v.c onstructor  == Array)  {
    539                for(var  j=0, jmax= v.length;  j < jmax;  j++)
    540                    a.pu sh({name:  n, value:  v[j]});
    541           }
    542           el se if (v ! == null &&  typeof v  != 'undefi ned')
    543                a.push({ name: n, v alue: v});
    544       }
    545  
    546       if (!s emantic &&  form.clk)  {
    547           //  input typ e=='image'  are not f ound in el ements arr ay! handle  them here
    548           va r inputs =  form.getE lementsByT agName("in put");
    549           fo r(var i=0,  max=input s.length;  i < max; i ++) {
    550                var inpu t = inputs [i];
    551                var n =  input.name ;
    552                if(n &&  !input.dis abled && i nput.type  == "image"  && form.c lk == inpu t)
    553                    a.pu sh({name:  n+'.x', va lue: form. clk_x}, {n ame: n+'.y ', value:  form.clk_y });
    554           }
    555       }
    556       return  a;
    557   };
    558  
    559  
    560   /**
    561    * Seriali zes form d ata into a  'submitta ble' strin g. This me thod will  return a s tring
    562    * in the  format: na me1=value1 &amp;name2 =value2
    563    *
    564    * The sem antic argu ment can b e used to  force form  serializa tion in se mantic ord er.
    565    * If your  form must  be submit ted with n ame/value  pairs in s emantic or der then p ass
    566    * true fo r this arg , otherwis e pass fal se (or not hing) to a void the o verhead fo r
    567    * this lo gic (which  can be si gnificant  for very l arge forms ).
    568    *
    569    * @exampl e var data  = $("#myF orm").form Serialize( );
    570    * $.ajax( 'POST', "m yscript.cg i", data);
    571    * @desc C ollect all  the data  from a for m into a s ingle stri ng
    572    *
    573    * @name f ormSeriali ze
    574    * @param  semantic t rue if ser ialization  must main tain stric t semantic  ordering  of element s (slower)
    575    * @type S tring
    576    * @cat Pl ugins/Form
    577    */
    578   $.fn.formS erialize =  function( semantic)  {
    579       //hand  off to jQ uery.param  for prope r encoding
    580       return  $.param(t his.formTo Array(sema ntic));
    581   };
    582  
    583  
    584   /**
    585    * Seriali zes all fi eld elemen ts in the  jQuery obj ect into a  query str ing.
    586    * This me thod will  return a s tring in t he format:  name1=val ue1&amp;na me2=value2
    587    *
    588    * The suc cessful ar gument con trols whet her or not  serializa tion is li mited to
    589    * 'succes sful' cont rols (per  http://www .w3.org/TR /html4/int eract/form s.html#suc cessful-co ntrols).
    590    * The def ault value  of the su ccessful a rgument is  true.
    591    *
    592    * @exampl e var data  = $("inpu t").fieldS erialize() ;
    593    * @desc C ollect the  data from  all succe ssful inpu t elements  into a qu ery string
    594    *
    595    * @exampl e var data  = $(":rad io").field Serialize( );
    596    * @desc C ollect the  data from  all succe ssful radi o input el ements int o a query  string
    597    *
    598    * @exampl e var data  = $("#myF orm :check box").fiel dSerialize ();
    599    * @desc C ollect the  data from  all succe ssful chec kbox input  elements  in myForm  into a que ry string
    600    *
    601    * @exampl e var data  = $("#myF orm :check box").fiel dSerialize (false);
    602    * @desc C ollect the  data from  all check box elemen ts in myFo rm (even t he uncheck ed ones) i nto a quer y string
    603    *
    604    * @exampl e var data  = $(":inp ut").field Serialize( );
    605    * @desc C ollect the  data from  all succe ssful inpu t, select,  textarea  and button  elements  into a que ry string
    606    *
    607    * @name f ieldSerial ize
    608    * @param  successful  true if o nly succes sful contr ols should  be serial ized (defa ult is tru e)
    609    * @type S tring
    610    * @cat Pl ugins/Form
    611    */
    612   $.fn.field Serialize  = function (successfu l) {
    613       var a  = [];
    614       this.e ach(functi on() {
    615           va r n = this .name;
    616           if  (!n) retu rn;
    617           va r v = $.fi eldValue(t his, succe ssful);
    618           if  (v && v.c onstructor  == Array)  {
    619                for (var  i=0,max=v .length; i  < max; i+ +)
    620                    a.pu sh({name:  n, value:  v[i]});
    621           }
    622           el se if (v ! == null &&  typeof v  != 'undefi ned')
    623                a.push({ name: this .name, val ue: v});
    624       });
    625       //hand  off to jQ uery.param  for prope r encoding
    626       return  $.param(a );
    627   };
    628  
    629  
    630   /**
    631    * Returns  the value (s) of the  element i n the matc hed set.   For exampl e, conside r the foll owing form :
    632    *
    633    *  <form> <fieldset>
    634    *      <i nput name= "A" type=" text" />
    635    *      <i nput name= "A" type=" text" />
    636    *      <i nput name= "B" type=" checkbox"  value="B1"  />
    637    *      <i nput name= "B" type=" checkbox"  value="B2" />
    638    *      <i nput name= "C" type=" radio" val ue="C1" />
    639    *      <i nput name= "C" type=" radio" val ue="C2" />
    640    *  </fiel dset></for m>
    641    *
    642    *  var v  = $(':text ').fieldVa lue();
    643    *  // if  no values  are entere d into the  text inpu ts
    644    *  v == [ '','']
    645    *  // if  values ent ered into  the text i nputs are  'foo' and  'bar'
    646    *  v == [ 'foo','bar ']
    647    *
    648    *  var v  = $(':chec kbox').fie ldValue();
    649    *  // if  neither ch eckbox is  checked
    650    *  v ===  undefined
    651    *  // if  both check boxes are  checked
    652    *  v == [ 'B1', 'B2' ]
    653    *
    654    *  var v  = $(':radi o').fieldV alue();
    655    *  // if  neither ra dio is che cked
    656    *  v ===  undefined
    657    *  // if  first radi o is check ed
    658    *  v == [ 'C1']
    659    *
    660    * The suc cessful ar gument con trols whet her or not  the field  element m ust be 'su ccessful'
    661    * (per ht tp://www.w 3.org/TR/h tml4/inter act/forms. html#succe ssful-cont rols).
    662    * The def ault value  of the su ccessful a rgument is  true.  If  this valu e is false  the value (s)
    663    * for eac h element  is returne d.
    664    *
    665    * Note: T his method  *always*  returns an  array.  I f no valid  value can  be determ ined the
    666    *       a rray will  be empty,  otherwise  it will co ntain one  or more va lues.
    667    *
    668    * @exampl e var data  = $("#myP asswordEle ment").fie ldValue();
    669    * alert(d ata[0]);
    670    * @desc A lerts the  current va lue of the  myPasswor dElement e lement
    671    *
    672    * @exampl e var data  = $("#myF orm :input ").fieldVa lue();
    673    * @desc G et the val ue(s) of t he form el ements in  myForm
    674    *
    675    * @exampl e var data  = $("#myF orm :check box").fiel dValue();
    676    * @desc G et the val ue(s) for  the succes sful check box elemen t(s) in th e jQuery o bject.
    677    *
    678    * @exampl e var data  = $("#myS ingleSelec t").fieldV alue();
    679    * @desc G et the val ue(s) of t he select  control
    680    *
    681    * @exampl e var data  = $(':tex t').fieldV alue();
    682    * @desc G et the val ue(s) of t he text in put or tex tarea elem ents
    683    *
    684    * @exampl e var data  = $("#myM ultiSelect ").fieldVa lue();
    685    * @desc G et the val ues for th e select-m ultiple co ntrol
    686    *
    687    * @name f ieldValue
    688    * @param  Boolean su ccessful t rue if onl y the valu es for suc cessful co ntrols sho uld be ret urned (def ault is tr ue)
    689    * @type A rray<Strin g>
    690    * @cat Pl ugins/Form
    691    */
    692   $.fn.field Value = fu nction(suc cessful) {
    693       for (v ar val=[],  i=0, max= this.lengt h; i < max ; i++) {
    694           va r el = thi s[i];
    695           va r v = $.fi eldValue(e l, success ful);
    696           if  (v === nu ll || type of v == 'u ndefined'  || (v.cons tructor ==  Array &&  !v.length) )
    697                continue ;
    698           v. constructo r == Array  ? $.merge (val, v) :  val.push( v);
    699       }
    700       return  val;
    701   };
    702  
    703   /**
    704    * Returns  the value  of the fi eld elemen t.
    705    *
    706    * The suc cessful ar gument con trols whet her or not  the field  element m ust be 'su ccessful'
    707    * (per ht tp://www.w 3.org/TR/h tml4/inter act/forms. html#succe ssful-cont rols).
    708    * The def ault value  of the su ccessful a rgument is  true.  If  the given  element i s not
    709    * success ful and th e successf ul arg is  not false  then the r eturned va lue will b e null.
    710    *
    711    * Note: I f the succ essful fla g is true  (default)  but the el ement is n ot success ful, the r eturn will  be null
    712    * Note: T he value r eturned fo r a succes sful selec t-multiple  element w ill always  be an arr ay.
    713    * Note: I f the elem ent has no  value the  return va lue will b e undefine d.
    714    *
    715    * @exampl e var data  = jQuery. fieldValue ($("#myPas swordEleme nt")[0]);
    716    * @desc G ets the cu rrent valu e of the m yPasswordE lement ele ment
    717    *
    718    * @name f ieldValue
    719    * @param  Element el  The DOM e lement for  which the  value wil l be retur ned
    720    * @param  Boolean su ccessful t rue if val ue returne d must be  for a succ essful con trols (def ault is tr ue)
    721    * @type S tring or A rray<Strin g> or null  or undefi ned
    722    * @cat Pl ugins/Form
    723    */
    724   $.fieldVal ue = funct ion(el, su ccessful)  {
    725       var n  = el.name,  t = el.ty pe, tag =  el.tagName .toLowerCa se();
    726       if (ty peof succe ssful == ' undefined' ) successf ul = true;
    727  
    728       if (su ccessful & & (!n || e l.disabled  || t == ' reset' ||  t == 'butt on' ||
    729           (t  == 'check box' || t  == 'radio' ) && !el.c hecked ||
    730           (t  == 'submi t' || t ==  'image')  && el.form  && el.for m.clk != e l ||
    731           ta g == 'sele ct' && el. selectedIn dex == -1) )
    732                return n ull;
    733  
    734       if (ta g == 'sele ct') {
    735           va r index =  el.selecte dIndex;
    736           if  (index <  0) return  null;
    737           va r a = [],  ops = el.o ptions;
    738           va r one = (t  == 'selec t-one');
    739           va r max = (o ne ? index +1 : ops.l ength);
    740           fo r(var i=(o ne ? index  : 0); i <  max; i++)  {
    741                var op =  ops[i];
    742                if (op.s elected) {
    743                    // e xtra pain  for IE...
    744                    var  v = $.brow ser.msie & & !(op.att ributes['v alue'].spe cified) ?  op.text :  op.value;
    745                    if ( one) retur n v;
    746                    a.pu sh(v);
    747                }
    748           }
    749           re turn a;
    750       }
    751       return  el.value;
    752   };
    753  
    754  
    755   /**
    756    * Clears  the form d ata.  Take s the foll owing acti ons on the  form's in put fields :
    757    *  - inpu t text fie lds will h ave their  'value' pr operty set  to the em pty string
    758    *  - sele ct element s will hav e their 's electedInd ex' proper ty set to  -1
    759    *  - chec kbox and r adio input s will hav e their 'c hecked' pr operty set  to false
    760    *  - inpu ts of type  submit, b utton, res et, and hi dden will  *not* be e ffected
    761    *  - butt on element s will *no t* be effe cted
    762    *
    763    * @exampl e $('form' ).clearFor m();
    764    * @desc C lears all  forms on t he page.
    765    *
    766    * @name c learForm
    767    * @type j Query
    768    * @cat Pl ugins/Form
    769    */
    770   $.fn.clear Form = fun ction() {
    771       return  this.each (function( ) {
    772           $( 'input,sel ect,textar ea', this) .clearFiel ds();
    773       });
    774   };
    775  
    776   /**
    777    * Clears  the select ed form el ements.  T akes the f ollowing a ctions on  the matche d elements :
    778    *  - inpu t text fie lds will h ave their  'value' pr operty set  to the em pty string
    779    *  - sele ct element s will hav e their 's electedInd ex' proper ty set to  -1
    780    *  - chec kbox and r adio input s will hav e their 'c hecked' pr operty set  to false
    781    *  - inpu ts of type  submit, b utton, res et, and hi dden will  *not* be e ffected
    782    *  - butt on element s will *no t* be effe cted
    783    *
    784    * @exampl e $('.myIn puts').cle arFields() ;
    785    * @desc C lears all  inputs wit h class my Inputs
    786    *
    787    * @name c learFields
    788    * @type j Query
    789    * @cat Pl ugins/Form
    790    */
    791   $.fn.clear Fields = $ .fn.clearI nputs = fu nction() {
    792       return  this.each (function( ) {
    793           va r t = this .type, tag  = this.ta gName.toLo werCase();
    794           if  (t == 'te xt' || t = = 'passwor d' || tag  == 'textar ea')
    795                this.val ue = '';
    796           el se if (t = = 'checkbo x' || t ==  'radio')
    797                this.che cked = fal se;
    798           el se if (tag  == 'selec t')
    799                this.sel ectedIndex  = -1;
    800       });
    801   };
    802  
    803  
    804   /**
    805    * Resets  the form d ata.  Caus es all for m elements  to be res et to thei r original  value.
    806    *
    807    * @exampl e $('form' ).resetFor m();
    808    * @desc R esets all  forms on t he page.
    809    *
    810    * @name r esetForm
    811    * @type j Query
    812    * @cat Pl ugins/Form
    813    */
    814   $.fn.reset Form = fun ction() {
    815       return  this.each (function( ) {
    816           //  guard aga inst an in put with t he name of  'reset'
    817           //  note that  IE report s the rese t function  as an 'ob ject'
    818           if  (typeof t his.reset  == 'functi on' || (ty peof this. reset == ' object' &&  !this.res et.nodeTyp e))
    819                this.res et();
    820       });
    821   };
    822  
    823  
    824   /**
    825    * Enables  or disabl es any mat ching elem ents.
    826    *
    827    * @exampl e $(':radi o').enable d(false);
    828    * @desc D isables al l radio bu ttons
    829    *
    830    * @name s elect
    831    * @type j Query
    832    * @cat Pl ugins/Form
    833    */
    834   $.fn.enabl e = functi on(b) { 
    835       if (b  == undefin ed) b = tr ue;
    836       return  this.each (function( ) { 
    837           th is.disable d = !b 
    838       });
    839   };
    840  
    841   /**
    842    * Checks/ unchecks a ny matchin g checkbox es or radi o buttons  and
    843    * selects /deselects  and match ing option  elements.
    844    *
    845    * @exampl e $(':chec kbox').sel ect();
    846    * @desc C hecks all  checkboxes
    847    *
    848    * @name s elect
    849    * @type j Query
    850    * @cat Pl ugins/Form
    851    */
    852   $.fn.selec t = functi on(select)  {
    853       if (se lect == un defined) s elect = tr ue;
    854       return  this.each (function( ) { 
    855           va r t = this .type;
    856           if  (t == 'ch eckbox' ||  t == 'rad io')
    857                this.che cked = sel ect;
    858           el se if (thi s.tagName. toLowerCas e() == 'op tion') {
    859                var $sel  = $(this) .parent('s elect');
    860                if (sele ct && $sel [0] && $se l[0].type  == 'select -one') {
    861                    // d eselect al l other op tions
    862                    $sel .find('opt ion').sele ct(false);
    863                }
    864                this.sel ected = se lect;
    865           }
    866       });
    867   };
    868  
    869   })(jQuery) ;