Make WordPress Core

Ticket #5048: jquery.form.diff

File jquery.form.diff, 26.4 KB (added by filosofo, 17 years ago)
  • wp-includes/js/jquery/jquery.form.js

     
    11/*
    2  * jQuery form plugin
    3  * @requires jQuery v1.0.3
     2 * jQuery Form Plugin
     3 * version: 2.02 (12/16/2007)
     4 * @requires jQuery v1.1 or later
    45 *
     6 * Examples at: http://malsup.com/jquery/form/
    57 * Dual licensed under the MIT and GPL licenses:
    68 *   http://www.opensource.org/licenses/mit-license.php
    79 *   http://www.gnu.org/licenses/gpl.html
    810 *
    911 * Revision: $Id$
    10  * Version: 0.9
    1112 */
    12 
     13 (function($) {
    1314/**
    1415 * ajaxSubmit() provides a mechanism for submitting an HTML form using AJAX.
    1516 *
     
    2627 *  url:      URL to which the form data will be submitted.
    2728 *            default value: value of form's 'action' attribute
    2829 *
    29  *  method:   @deprecated use 'type'
    3030 *  type:     The method in which the form data should be submitted, 'GET' or 'POST'.
    3131 *            default value: value of form's 'method' attribute (or 'GET' if none found)
    3232 *
    33  *  before:   @deprecated use 'beforeSubmit'
     33 *  data:     Additional data to add to the request, specified as key/value pairs (see $.ajax).
     34 *
    3435 *  beforeSubmit:  Callback method to be invoked before the form is submitted.
    3536 *            default value: null
    3637 *
    37  *  after:    @deprecated use 'success'
    3838 *  success:  Callback method to be invoked after the form has been successfully submitted
    3939 *            and the response has been returned from the server
    4040 *            default value: null
     
    6666 * The dataType option provides a means for specifying how the server response should be handled.
    6767 * This maps directly to the jQuery.httpData method.  The following values are supported:
    6868 *
    69  *      'xml':    if dataType == 'xml' the server response is treated as XML and the 'after'
     69 *      'xml':    if dataType == 'xml' the server response is treated as XML and the 'success'
    7070 *                   callback method, if specified, will be passed the responseXML value
    7171 *      'json':   if dataType == 'json' the server response will be evaluted and passed to
    72  *                   the 'after' callback, if specified
     72 *                   the 'success' callback, if specified
    7373 *      'script': if dataType == 'script' the server response is evaluated in the global context
    7474 *
    7575 *
     
    175175 * @param options  object literal containing options which control the form submission process
    176176 * @cat Plugins/Form
    177177 * @return jQuery
    178  * @see formToArray
    179  * @see ajaxForm
    180  * @see $.ajax
    181  * @author jQuery Community
    182178 */
    183 jQuery.fn.ajaxSubmit = function(options) {
     179$.fn.ajaxSubmit = function(options) {
    184180    if (typeof options == 'function')
    185181        options = { success: options };
    186182
    187     options = jQuery.extend({
    188         url:    this.attr('action') || '',
    189         method: this.attr('method') || 'GET'
     183    options = $.extend({
     184        url:  this.attr('action') || window.location.toString(),
     185        type: this.attr('method') || 'GET'
    190186    }, options || {});
    191187
    192     // remap deprecated options (temporarily)
    193     options.success = options.success || options.after;
    194     options.beforeSubmit = options.beforeSubmit || options.before;
    195     options.type = options.type || options.method;
     188    // hook for manipulating the form data before it is extracted;
     189    // convenient for use with rich editors like tinyMCE or FCKEditor
     190    var veto = {};
     191    $.event.trigger('form.pre.serialize', [this, options, veto]);
     192    if (veto.veto) return this;
    196193
    197194    var a = this.formToArray(options.semantic);
     195        if (options.data) {
     196            for (var n in options.data)
     197                a.push( { name: n, value: options.data[n] } );
     198        }
    198199
    199200    // give pre-submit callback an opportunity to abort the submit
    200201    if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) return this;
    201202
    202     var q = jQuery.param(a);
     203    // fire vetoable 'validate' event
     204    $.event.trigger('form.submit.validate', [a, this, options, veto]);
     205    if (veto.veto) return this;
    203206
     207    var q = $.param(a);//.replace(/%20/g,'+');
     208
    204209    if (options.type.toUpperCase() == 'GET') {
    205         // if url already has a '?' then append args after '&'
    206210        options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
    207211        options.data = null;  // data is null for 'get'
    208212    }
     
    216220    // perform a load on the target only if dataType is not provided
    217221    if (!options.dataType && options.target) {
    218222        var oldSuccess = options.success || function(){};
    219         callbacks.push(function(data, status) {
    220             jQuery(options.target).attr("innerHTML", data).evalScripts().each(oldSuccess, [data, status]);
     223        callbacks.push(function(data) {
     224            if (this.evalScripts)
     225                $(options.target).attr("innerHTML", data).evalScripts().each(oldSuccess, arguments);
     226            else // jQuery v1.1.4
     227                $(options.target).html(data).each(oldSuccess, arguments);
    221228        });
    222229    }
    223230    else if (options.success)
     
    225232
    226233    options.success = function(data, status) {
    227234        for (var i=0, max=callbacks.length; i < max; i++)
    228             callbacks[i](data, status);
     235            callbacks[i](data, status, $form);
    229236    };
    230237
    231     jQuery.ajax(options);
     238    // are there files to upload?
     239    var files = $('input:file', this).fieldValue();
     240    var found = false;
     241    for (var j=0; j < files.length; j++)
     242        if (files[j])
     243            found = true;
     244
     245    // options.iframe allows user to force iframe mode
     246   if (options.iframe || found) {
     247       // hack to fix Safari hang (thanks to Tim Molendijk for this)
     248       // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
     249       if ($.browser.safari && options.closeKeepAlive)
     250           $.get(options.closeKeepAlive, fileUpload);
     251       else
     252           fileUpload();
     253       }
     254   else
     255       $.ajax(options);
     256
     257    // fire 'notify' event
     258    $.event.trigger('form.submit.notify', [this, options]);
    232259    return this;
     260
     261
     262    // private function for handling file uploads (hat tip to YAHOO!)
     263    function fileUpload() {
     264        var form = $form[0];
     265        var opts = $.extend({}, $.ajaxSettings, options);
     266
     267        var id = 'jqFormIO' + $.fn.ajaxSubmit.counter++;
     268        var $io = $('<iframe id="' + id + '" name="' + id + '" />');
     269        var io = $io[0];
     270        var op8 = $.browser.opera && window.opera.version() < 9;
     271        if ($.browser.msie || op8) io.src = 'javascript:false;document.write("");';
     272        $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
     273
     274        var xhr = { // mock object
     275            responseText: null,
     276            responseXML: null,
     277            status: 0,
     278            statusText: 'n/a',
     279            getAllResponseHeaders: function() {},
     280            getResponseHeader: function() {},
     281            setRequestHeader: function() {}
     282        };
     283
     284        var g = opts.global;
     285        // trigger ajax global events so that activity/block indicators work like normal
     286        if (g && ! $.active++) $.event.trigger("ajaxStart");
     287        if (g) $.event.trigger("ajaxSend", [xhr, opts]);
     288
     289        var cbInvoked = 0;
     290        var timedOut = 0;
     291
     292        // take a breath so that pending repaints get some cpu time before the upload starts
     293        setTimeout(function() {
     294            // make sure form attrs are set
     295            var encAttr = form.encoding ? 'encoding' : 'enctype';
     296            var t = $form.attr('target');
     297            $form.attr({
     298                target:   id,
     299                method:  'POST',
     300                action:   opts.url
     301            });
     302            form[encAttr] = 'multipart/form-data';
     303
     304            // support timout
     305            if (opts.timeout)
     306                setTimeout(function() { timedOut = true; cb(); }, opts.timeout);
     307
     308            // add iframe to doc and submit the form
     309            $io.appendTo('body');
     310            io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
     311            form.submit();
     312            $form.attr('target', t); // reset target
     313        }, 10);
     314
     315        function cb() {
     316            if (cbInvoked++) return;
     317
     318            io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
     319
     320            var ok = true;
     321            try {
     322                if (timedOut) throw 'timeout';
     323                // extract the server response from the iframe
     324                var data, doc;
     325                doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
     326                xhr.responseText = doc.body ? doc.body.innerHTML : null;
     327                xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
     328
     329                if (opts.dataType == 'json' || opts.dataType == 'script') {
     330                    var ta = doc.getElementsByTagName('textarea')[0];
     331                    data = ta ? ta.value : xhr.responseText;
     332                    if (opts.dataType == 'json')
     333                        eval("data = " + data);
     334                    else
     335                        $.globalEval(data);
     336                }
     337                else if (opts.dataType == 'xml') {
     338                    data = xhr.responseXML;
     339                    if (!data && xhr.responseText != null)
     340                        data = toXml(xhr.responseText);
     341                }
     342                else {
     343                    data = xhr.responseText;
     344                }
     345            }
     346            catch(e){
     347                ok = false;
     348                $.handleError(opts, xhr, 'error', e);
     349            }
     350
     351            // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
     352            if (ok) {
     353                opts.success(data, 'success');
     354                if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
     355            }
     356            if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
     357            if (g && ! --$.active) $.event.trigger("ajaxStop");
     358            if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
     359
     360            // clean up
     361            setTimeout(function() {
     362                $io.remove();
     363                xhr.responseXML = null;
     364            }, 100);
     365        };
     366
     367        function toXml(s, doc) {
     368            if (window.ActiveXObject) {
     369                doc = new ActiveXObject('Microsoft.XMLDOM');
     370                doc.async = 'false';
     371                doc.loadXML(s);
     372            }
     373            else
     374                doc = (new DOMParser()).parseFromString(s, 'text/xml');
     375            return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
     376        };
     377    };
    233378};
     379$.fn.ajaxSubmit.counter = 0; // used to create unique iframe ids
    234380
    235381/**
    236382 * ajaxForm() provides a mechanism for fully automating form submission.
     
    289435 * @return jQuery
    290436 * @cat    Plugins/Form
    291437 * @type   jQuery
    292  * @see    ajaxSubmit
    293  * @author jQuery Community
    294438 */
    295 jQuery.fn.ajaxForm = function(options) {
    296     return this.each(function() {
    297         jQuery("input:submit,input:image,button:submit", this).click(function(ev) {
    298             var $form = this.form;
    299             $form.clk = this;
    300             if (this.type == 'image') {
    301                 if (ev.offsetX != undefined) {
    302                     $form.clk_x = ev.offsetX;
    303                     $form.clk_y = ev.offsetY;
    304                 } else if (typeof jQuery.fn.offset == 'function') { // try to use dimensions plugin
    305                     var offset = jQuery(this).offset();
    306                     $form.clk_x = ev.pageX - offset.left;
    307                     $form.clk_y = ev.pageY - offset.top;
    308                 } else {
    309                     $form.clk_x = ev.pageX - this.offsetLeft;
    310                     $form.clk_y = ev.pageY - this.offsetTop;
    311                 }
    312             }
    313             // clear form vars
    314             setTimeout(function() {
    315                 $form.clk = $form.clk_x = $form.clk_y = null;
    316                 }, 10);
    317         })
    318     }).submit(function(e) {
    319         jQuery(this).ajaxSubmit(options);
    320         return false;
     439$.fn.ajaxForm = function(options) {
     440    return this.ajaxFormUnbind().submit(submitHandler).each(function() {
     441        // store options in hash
     442        this.formPluginId = $.fn.ajaxForm.counter++;
     443        $.fn.ajaxForm.optionHash[this.formPluginId] = options;
     444        $(":submit,input:image", this).click(clickHandler);
    321445    });
    322446};
    323447
     448$.fn.ajaxForm.counter = 1;
     449$.fn.ajaxForm.optionHash = {};
    324450
     451function clickHandler(e) {
     452    var $form = this.form;
     453    $form.clk = this;
     454    if (this.type == 'image') {
     455        if (e.offsetX != undefined) {
     456            $form.clk_x = e.offsetX;
     457            $form.clk_y = e.offsetY;
     458        } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
     459            var offset = $(this).offset();
     460            $form.clk_x = e.pageX - offset.left;
     461            $form.clk_y = e.pageY - offset.top;
     462        } else {
     463            $form.clk_x = e.pageX - this.offsetLeft;
     464            $form.clk_y = e.pageY - this.offsetTop;
     465        }
     466    }
     467    // clear form vars
     468    setTimeout(function() { $form.clk = $form.clk_x = $form.clk_y = null; }, 10);
     469};
     470
     471function submitHandler() {
     472    // retrieve options from hash
     473    var id = this.formPluginId;
     474    var options = $.fn.ajaxForm.optionHash[id];
     475    $(this).ajaxSubmit(options);
     476    return false;
     477};
     478
    325479/**
     480 * ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
     481 *
     482 * @name   ajaxFormUnbind
     483 * @return jQuery
     484 * @cat    Plugins/Form
     485 * @type   jQuery
     486 */
     487$.fn.ajaxFormUnbind = function() {
     488    this.unbind('submit', submitHandler);
     489    return this.each(function() {
     490        $(":submit,input:image", this).unbind('click', clickHandler);
     491    });
     492
     493};
     494
     495/**
    326496 * formToArray() gathers form element data into an array of objects that can
    327497 * be passed to any of the following ajax functions: $.get, $.post, or load.
    328498 * Each object in the array has both a 'name' and 'value' property.  An example of
     
    347517 * @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
    348518 * @type Array<Object>
    349519 * @cat Plugins/Form
    350  * @see ajaxForm
    351  * @see ajaxSubmit
    352  * @author jQuery Community
    353520 */
    354 jQuery.fn.formToArray = function(semantic) {
     521$.fn.formToArray = function(semantic) {
    355522    var a = [];
    356523    if (this.length == 0) return a;
    357524
     
    369536                a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
    370537            continue;
    371538        }
    372         var v = jQuery.fieldValue(el, true);
    373         if (v === null) continue;
    374         if (v.constructor == Array) {
     539
     540        var v = $.fieldValue(el, true);
     541        if (v && v.constructor == Array) {
    375542            for(var j=0, jmax=v.length; j < jmax; j++)
    376543                a.push({name: n, value: v[j]});
    377544        }
    378         else
     545        else if (v !== null && typeof v != 'undefined')
    379546            a.push({name: n, value: v});
    380547    }
    381548
     
    410577 * @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
    411578 * @type String
    412579 * @cat Plugins/Form
    413  * @see formToArray
    414  * @author jQuery Community
    415580 */
    416 jQuery.fn.formSerialize = function(semantic) {
     581$.fn.formSerialize = function(semantic) {
    417582    //hand off to jQuery.param for proper encoding
    418     return jQuery.param(this.formToArray(semantic));
     583    return $.param(this.formToArray(semantic));
    419584};
    420585
    421586
     
    447612 * @type String
    448613 * @cat Plugins/Form
    449614 */
    450 jQuery.fn.fieldSerialize = function(successful) {
     615$.fn.fieldSerialize = function(successful) {
    451616    var a = [];
    452617    this.each(function() {
    453618        var n = this.name;
    454619        if (!n) return;
    455         var v = jQuery.fieldValue(this, successful);
     620        var v = $.fieldValue(this, successful);
    456621        if (v && v.constructor == Array) {
    457622            for (var i=0,max=v.length; i < max; i++)
    458623                a.push({name: n, value: v[i]});
     
    461626            a.push({name: this.name, value: v});
    462627    });
    463628    //hand off to jQuery.param for proper encoding
    464     return jQuery.param(a);
     629    return $.param(a);
    465630};
    466631
    467632
    468633/**
    469  * Returns the value of the field element in the jQuery object.  If there is more than one field element
    470  * in the jQuery object the value of the first successful one is returned.
     634 * Returns the value(s) of the element in the matched set.  For example, consider the following form:
    471635 *
     636 *  <form><fieldset>
     637 *      <input name="A" type="text" />
     638 *      <input name="A" type="text" />
     639 *      <input name="B" type="checkbox" value="B1" />
     640 *      <input name="B" type="checkbox" value="B2"/>
     641 *      <input name="C" type="radio" value="C1" />
     642 *      <input name="C" type="radio" value="C2" />
     643 *  </fieldset></form>
     644 *
     645 *  var v = $(':text').fieldValue();
     646 *  // if no values are entered into the text inputs
     647 *  v == ['','']
     648 *  // if values entered into the text inputs are 'foo' and 'bar'
     649 *  v == ['foo','bar']
     650 *
     651 *  var v = $(':checkbox').fieldValue();
     652 *  // if neither checkbox is checked
     653 *  v === undefined
     654 *  // if both checkboxes are checked
     655 *  v == ['B1', 'B2']
     656 *
     657 *  var v = $(':radio').fieldValue();
     658 *  // if neither radio is checked
     659 *  v === undefined
     660 *  // if first radio is checked
     661 *  v == ['C1']
     662 *
    472663 * The successful argument controls whether or not the field element must be 'successful'
    473664 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
    474  * The default value of the successful argument is true.  If this value is false then
    475  * the value of the first field element in the jQuery object is returned.
     665 * The default value of the successful argument is true.  If this value is false the value(s)
     666 * for each element is returned.
    476667 *
    477  * Note: If no valid value can be determined the return value will be undifined.
     668 * Note: This method *always* returns an array.  If no valid value can be determined the
     669 *       array will be empty, otherwise it will contain one or more values.
    478670 *
    479  * Note: The fieldValue returned for a select-multiple element or for a checkbox input will
    480  *       always be an array if it is not undefined.
     671 * @example var data = $("#myPasswordElement").fieldValue();
     672 * alert(data[0]);
     673 * @desc Alerts the current value of the myPasswordElement element
    481674 *
     675 * @example var data = $("#myForm :input").fieldValue();
     676 * @desc Get the value(s) of the form elements in myForm
    482677 *
    483  * @example var data = $("#myPasswordElement").formValue();
    484  * @desc Gets the current value of the myPasswordElement element
     678 * @example var data = $("#myForm :checkbox").fieldValue();
     679 * @desc Get the value(s) for the successful checkbox element(s) in the jQuery object.
    485680 *
    486  * @example var data = $("#myForm :input").formValue();
    487  * @desc Get the value of the first successful control in the jQuery object.
     681 * @example var data = $("#mySingleSelect").fieldValue();
     682 * @desc Get the value(s) of the select control
    488683 *
    489  * @example var data = $("#myForm :checkbox").formValue();
    490  * @desc Get the array of values for the first set of successful checkbox controls in the jQuery object.
     684 * @example var data = $(':text').fieldValue();
     685 * @desc Get the value(s) of the text input or textarea elements
    491686 *
    492  * @example var data = $("#mySingleSelect").formValue();
    493  * @desc Get the value of the select control
     687 * @example var data = $("#myMultiSelect").fieldValue();
     688 * @desc Get the values for the select-multiple control
    494689 *
    495  * @example var data = $("#myMultiSelect").formValue();
    496  * @desc Get the array of selected values for the select-multiple control
    497  *
    498690 * @name fieldValue
    499  * @param Boolean successful true if value returned must be for a successful controls (default is true)
    500  * @type String or Array<String>
     691 * @param Boolean successful true if only the values for successful controls should be returned (default is true)
     692 * @type Array<String>
    501693 * @cat Plugins/Form
    502694 */
    503 jQuery.fn.fieldValue = function(successful) {
    504     var cbVal, cbName;
    505 
    506     // loop until we find a value
    507     for (var i=0, max=this.length; i < max; i++) {
     695$.fn.fieldValue = function(successful) {
     696    for (var val=[], i=0, max=this.length; i < max; i++) {
    508697        var el = this[i];
    509         var v = jQuery.fieldValue(el, successful);
     698        var v = $.fieldValue(el, successful);
    510699        if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
    511700            continue;
    512 
    513         // for checkboxes, consider multiple elements, for everything else just return first valid value
    514         if (el.type != 'checkbox') return v;
    515 
    516         cbName = cbName || el.name;
    517         if (cbName != el.name) // return if we hit a checkbox with a different name
    518             return cbVal;
    519         cbVal = cbVal || [];
    520         cbVal.push(v);
     701        v.constructor == Array ? $.merge(val, v) : val.push(v);
    521702    }
    522     return cbVal;
     703    return val;
    523704};
    524705
    525706/**
     
    530711 * The default value of the successful argument is true.  If the given element is not
    531712 * successful and the successful arg is not false then the returned value will be null.
    532713 *
    533  * Note: The fieldValue returned for a select-multiple element will always be an array.
     714 * Note: If the successful flag is true (default) but the element is not successful, the return will be null
     715 * Note: The value returned for a successful select-multiple element will always be an array.
     716 * Note: If the element has no value the return value will be undefined.
    534717 *
    535718 * @example var data = jQuery.fieldValue($("#myPasswordElement")[0]);
    536719 * @desc Gets the current value of the myPasswordElement element
     
    538721 * @name fieldValue
    539722 * @param Element el The DOM element for which the value will be returned
    540723 * @param Boolean successful true if value returned must be for a successful controls (default is true)
    541  * @type String or Array<String>
     724 * @type String or Array<String> or null or undefined
    542725 * @cat Plugins/Form
    543726 */
    544 jQuery.fieldValue = function(el, successful) {
     727$.fieldValue = function(el, successful) {
    545728    var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
    546729    if (typeof successful == 'undefined') successful = true;
    547730
    548     if (successful && ( !n || el.disabled || t == 'reset' ||
     731    if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
    549732        (t == 'checkbox' || t == 'radio') && !el.checked ||
    550733        (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
    551734        tag == 'select' && el.selectedIndex == -1))
     
    561744            var op = ops[i];
    562745            if (op.selected) {
    563746                // extra pain for IE...
    564                 var v = jQuery.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value;
     747                var v = $.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value;
    565748                if (one) return v;
    566749                a.push(v);
    567750            }
     
    586769 * @name clearForm
    587770 * @type jQuery
    588771 * @cat Plugins/Form
    589  * @see resetForm
    590772 */
    591 jQuery.fn.clearForm = function() {
     773$.fn.clearForm = function() {
    592774    return this.each(function() {
    593         jQuery('input,select,textarea', this).clearFields();
     775        $('input,select,textarea', this).clearFields();
    594776    });
    595777};
    596778
     
    608790 * @name clearFields
    609791 * @type jQuery
    610792 * @cat Plugins/Form
    611  * @see clearForm
    612793 */
    613 jQuery.fn.clearFields = jQuery.fn.clearInputs = function() {
     794$.fn.clearFields = $.fn.clearInputs = function() {
    614795    return this.each(function() {
    615796        var t = this.type, tag = this.tagName.toLowerCase();
    616797        if (t == 'text' || t == 'password' || tag == 'textarea')
     
    632813 * @name resetForm
    633814 * @type jQuery
    634815 * @cat Plugins/Form
    635  * @see clearForm
    636816 */
    637 jQuery.fn.resetForm = function() {
     817$.fn.resetForm = function() {
    638818    return this.each(function() {
    639819        // guard against an input with the name of 'reset'
    640820        // note that IE reports the reset function as an 'object'
     
    642822            this.reset();
    643823    });
    644824};
     825
     826
     827/**
     828 * Enables or disables any matching elements.
     829 *
     830 * @example $(':radio').enabled(false);
     831 * @desc Disables all radio buttons
     832 *
     833 * @name select
     834 * @type jQuery
     835 * @cat Plugins/Form
     836 */
     837$.fn.enable = function(b) {
     838    if (b == undefined) b = true;
     839    return this.each(function() {
     840        this.disabled = !b
     841    });
     842};
     843
     844/**
     845 * Checks/unchecks any matching checkboxes or radio buttons and
     846 * selects/deselects and matching option elements.
     847 *
     848 * @example $(':checkbox').selected();
     849 * @desc Checks all checkboxes
     850 *
     851 * @name select
     852 * @type jQuery
     853 * @cat Plugins/Form
     854 */
     855$.fn.select = function(select) {
     856    if (select == undefined) select = true;
     857    return this.each(function() {
     858        var t = this.type;
     859        if (t == 'checkbox' || t == 'radio')
     860            this.checked = select;
     861        else if (this.tagName.toLowerCase() == 'option') {
     862            var $sel = $(this).parent('select');
     863            if (select && $sel[0] && $sel[0].type == 'select-one') {
     864                // deselect all other options
     865                $sel.find('option').select(false);
     866            }
     867            this.selected = select;
     868        }
     869    });
     870};
     871
     872})(jQuery);
  • wp-includes/script-loader.php

     
    7878                $this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
    7979
    8080                $this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.2b2');
    81                 $this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '1.0.3');
     81                $this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02');
    8282                $this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' );
    8383                $this->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2');
    8484                $this->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1');