[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/jquery/ -> jquery.form.js (source)

   1  /*!
   2   * jQuery Form Plugin
   3   * version: 4.4.0
   4   * Requires jQuery v1.7.2 or later
   5   * Project repository: https://github.com/jquery-form/form
   6  
   7   * Copyright 2017 Kevin Morris
   8   * Copyright 2006 M. Alsup
   9  
  10   * Dual licensed under the LGPL-2.1+ or MIT licenses
  11   * https://github.com/jquery-form/form#license
  12  
  13   * This library is free software; you can redistribute it and/or
  14   * modify it under the terms of the GNU Lesser General Public
  15   * License as published by the Free Software Foundation; either
  16   * version 2.1 of the License, or (at your option) any later version.
  17   * This library is distributed in the hope that it will be useful,
  18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20   * Lesser General Public License for more details.
  21   */
  22  import jQuery from "jquery";
  23  
  24  (function ($) {
  25    "use strict";
  26  
  27    /*
  28          Usage Note:
  29          -----------
  30          Do not use both ajaxSubmit and ajaxForm on the same form. These
  31          functions are mutually exclusive. Use ajaxSubmit if you want
  32          to bind your own submit handler to the form. For example,
  33  
  34          $(document).ready(function() {
  35              $('#myForm').on('submit', function(e) {
  36                  e.preventDefault(); // <-- important
  37                  $(this).ajaxSubmit({
  38                      target: '#output'
  39                  });
  40              });
  41          });
  42  
  43          Use ajaxForm when you want the plugin to manage all the event binding
  44          for you. For example,
  45  
  46          $(document).ready(function() {
  47              $('#myForm').ajaxForm({
  48                  target: '#output'
  49              });
  50          });
  51  
  52          You can also use ajaxForm with delegation (requires jQuery v1.7+), so the
  53          form does not have to exist when you invoke ajaxForm:
  54  
  55          $('#myForm').ajaxForm({
  56              delegation: true,
  57              target: '#output'
  58          });
  59  
  60          When using ajaxForm, the ajaxSubmit function will be invoked for you
  61          at the appropriate time.
  62      */
  63  
  64    var rCRLF = /\r?\n/g;
  65  
  66    /**
  67     * Feature detection
  68     */
  69    var feature = {};
  70  
  71    feature.fileapi = $('<input type="file">').get(0).files !== undefined;
  72    feature.formdata = typeof window.FormData !== "undefined";
  73  
  74    var hasProp = !!$.fn.prop;
  75    // Called through the prototype: an extraData key or a form field may be named hasOwnProperty.
  76    var hasOwn = Object.prototype.hasOwnProperty;
  77  
  78    // A control named like a form member (elements, setAttribute) shadows that member on the form,
  79    // so forms are read and changed through members a control cannot shadow.
  80    var plainForm = document.createElement("form");
  81  
  82    // Resolves both URLs through anchors, as jQuery does for crossDomain, so IE's anchor quirks
  83    // apply to both sides of the comparison.
  84    function isSameOrigin(url) {
  85      var origin = document.createElement("a");
  86      var target = document.createElement("a");
  87  
  88      origin.href = window.location.href;
  89      target.href = url;
  90      // IE fills in the host of a relative URL only once the resolved href is assigned back
  91      target.href = target.href; // eslint-disable-line no-self-assign
  92  
  93      return origin.protocol + "//" + origin.host === target.protocol + "//" + target.host;
  94    }
  95  
  96    // Nodes such as the document and text nodes have no tag name (#600).
  97    function tagName(el) {
  98      return typeof el.tagName === "string" ? el.tagName.toLowerCase() : "";
  99    }
 100  
 101    function formElements(form) {
 102      var proto = window.HTMLFormElement && window.HTMLFormElement.prototype;
 103      var descriptor = proto && Object.getOwnPropertyDescriptor(proto, "elements");
 104  
 105      try {
 106        return descriptor.get.call(form);
 107      } catch (e) {
 108        // no DOM prototype accessors, or another element with controls such as a fieldset
 109        return form.elements;
 110      }
 111    }
 112  
 113    // attr2 uses prop when it can but checks the return type for
 114    // an expected string. This accounts for the case where a form
 115    // contains inputs with names like "action" or "method"; in those
 116    // cases "prop" returns the element
 117    $.fn.attr2 = function () {
 118      if (!hasProp) {
 119        return this.attr.apply(this, arguments);
 120      }
 121  
 122      var val = this.prop.apply(this, arguments);
 123  
 124      if ((val && val.jquery) || typeof val === "string") {
 125        return val;
 126      }
 127  
 128      return this.attr.apply(this, arguments);
 129    };
 130  
 131    /**
 132     * ajaxSubmit() provides a mechanism for immediately submitting
 133     * an HTML form using AJAX.
 134     *
 135     * @param    {object|string}    options        jquery.form.js parameters or custom url for submission
 136     * @param    {object}        data        extraData
 137     * @param    {string}        dataType    ajax dataType
 138     * @param    {function}        onSuccess    ajax success callback function
 139     */
 140    $.fn.ajaxSubmit = function (options, data, dataType, onSuccess) {
 141      // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
 142      if (!this.length) {
 143        log("ajaxSubmit: skipping submit process - no element selected");
 144  
 145        return this;
 146      }
 147  
 148      var method,
 149        action,
 150        url,
 151        isMsie,
 152        iframeSrc,
 153        $form = this;
 154  
 155      if (typeof options === "function") {
 156        options = { success: options };
 157      } else if (typeof options === "string" || (options === false && arguments.length > 0)) {
 158        options = {
 159          url: options,
 160          data: data,
 161          dataType: dataType,
 162        };
 163  
 164        if (typeof onSuccess === "function") {
 165          options.success = onSuccess;
 166        }
 167      } else if (typeof options === "undefined") {
 168        options = {};
 169      }
 170  
 171      method = options.method || options.type || this.attr2("method");
 172      action = options.url || this.attr2("action");
 173  
 174      url = typeof action === "string" ? action.trim() : "";
 175      // clean url (don't include hash value); an action that is only a fragment means this page
 176      url = url.split("#")[0] || window.location.href.split("#")[0];
 177      // IE requires javascript:false in https, but this breaks chrome >83 and goes against spec.
 178      // Instead of using javascript:false always, let's only apply it for IE.
 179      isMsie = /(MSIE|Trident)/.test(navigator.userAgent || "");
 180      iframeSrc = isMsie && /^https/i.test(document.URL) ? "javascript:false" : "about:blank"; // eslint-disable-line no-script-url
 181  
 182      options = $.extend(
 183        true,
 184        {
 185          url: url,
 186          success: $.ajaxSettings.success,
 187          type: method || $.ajaxSettings.type,
 188          iframeSrc: iframeSrc,
 189        },
 190        options
 191      );
 192  
 193      // hook for manipulating the form data before it is extracted;
 194      // convenient for use with rich editors like tinyMCE or FCKEditor
 195      var veto = {};
 196  
 197      this.trigger("form-pre-serialize", [this, options, veto]);
 198  
 199      if (veto.veto) {
 200        log("ajaxSubmit: submit vetoed via form-pre-serialize trigger");
 201  
 202        return this;
 203      }
 204  
 205      // provide opportunity to alter form data before it is serialized
 206      if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
 207        log("ajaxSubmit: submit aborted via beforeSerialize callback");
 208  
 209        return this;
 210      }
 211  
 212      var traditional = options.traditional;
 213  
 214      if (typeof traditional === "undefined") {
 215        traditional = $.ajaxSettings.traditional;
 216      }
 217  
 218      var elements = [];
 219      var qx,
 220        a = this.formToArray(options.semantic, elements, options.filtering);
 221  
 222      if (options.data) {
 223        var optionsData = typeof options.data === "function" ? options.data(a) : options.data;
 224  
 225        options.extraData = optionsData;
 226        qx = $.param(optionsData, traditional);
 227      }
 228  
 229      // give pre-submit callback an opportunity to abort the submit
 230      if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
 231        log("ajaxSubmit: submit aborted via beforeSubmit callback");
 232  
 233        return this;
 234      }
 235  
 236      // fire vetoable 'validate' event
 237      this.trigger("form-submit-validate", [a, this, options, veto]);
 238      if (veto.veto) {
 239        log("ajaxSubmit: submit vetoed via form-submit-validate trigger");
 240  
 241        return this;
 242      }
 243  
 244      var q = $.param(a, traditional);
 245  
 246      if (qx) {
 247        q = q ? q + "&" + qx : qx;
 248      }
 249  
 250      if (options.type.toUpperCase() === "GET") {
 251        // the query goes before any fragment in the url option
 252        var hashAt = options.url.indexOf("#");
 253        var base = hashAt < 0 ? options.url : options.url.slice(0, hashAt);
 254  
 255        options.url =
 256          base + (base.indexOf("?") >= 0 ? "&" : "?") + q + options.url.slice(base.length);
 257        options.data = null; // data is null for 'get'
 258      } else {
 259        options.data = q; // data is the query string for 'post'
 260      }
 261  
 262      var callbacks = [];
 263  
 264      if (options.resetForm) {
 265        callbacks.push(function () {
 266          $form.resetForm();
 267        });
 268      }
 269  
 270      if (options.clearForm) {
 271        callbacks.push(function () {
 272          $form.clearForm(options.includeHidden);
 273        });
 274      }
 275  
 276      // perform a load on the target only if dataType is not provided
 277      if (!options.dataType && options.target) {
 278        var oldSuccess = options.success || function () {};
 279  
 280        callbacks.push(function (data, textStatus, jqXHR) {
 281          var successArguments = arguments,
 282            fn = options.replaceTarget ? "replaceWith" : "html",
 283            $target = $(options.target);
 284  
 285          // Only a string response is inserted. jQuery has already parsed a JSON or XML response,
 286          // and inserting it would parse each of its strings as HTML.
 287          if (typeof data === "string") {
 288            $target[fn](data);
 289          } else {
 290            log("target: the response was parsed by jQuery, so it is not inserted");
 291          }
 292  
 293          $target.each(function () {
 294            oldSuccess.apply(this, successArguments);
 295          });
 296        });
 297      } else if (options.success) {
 298        if (Array.isArray(options.success)) {
 299          $.merge(callbacks, options.success);
 300        } else {
 301          callbacks.push(options.success);
 302        }
 303      }
 304  
 305      options.success = function (data, status, xhr) {
 306        // jQuery 1.4+ passes xhr as 3rd arg
 307        var context = options.context || this; // jQuery 1.4+ supports scope context
 308  
 309        for (var i = 0, max = callbacks.length; i < max; i++) {
 310          callbacks[i].apply(context, [data, status, xhr || $form, $form]);
 311        }
 312      };
 313  
 314      if (options.error) {
 315        var oldError = options.error;
 316  
 317        options.error = function (xhr, status, error) {
 318          var context = options.context || this;
 319  
 320          oldError.apply(context, [xhr, status, error, $form]);
 321        };
 322      }
 323  
 324      if (options.complete) {
 325        var oldComplete = options.complete;
 326  
 327        options.complete = function (xhr, status) {
 328          var context = options.context || this;
 329  
 330          oldComplete.apply(context, [xhr, status, $form]);
 331        };
 332      }
 333  
 334      // are there files to upload?
 335  
 336      // [value] (issue #113), also see comment:
 337      // https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219
 338      var fileInputs = $("input[type=file]:enabled", this).filter(function () {
 339        return $(this).val() !== "";
 340      });
 341      var hasFileInputs = fileInputs.length > 0;
 342      var mp = "multipart/form-data";
 343      var multipart = $form.attr("enctype") === mp || $form.attr("encoding") === mp;
 344      var fileAPI = feature.fileapi && feature.formdata;
 345  
 346      log("fileAPI :" + fileAPI);
 347  
 348      var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
 349      var jqxhr;
 350  
 351      // options.iframe allows user to force iframe mode
 352      // 06-NOV-09: now defaulting to iframe mode if file input is detected
 353      if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
 354        // hack to fix Safari hang (thanks to Tim Molendijk for this)
 355        // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
 356        if (options.closeKeepAlive) {
 357          $.get(options.closeKeepAlive, function () {
 358            jqxhr = fileUploadIframe(a);
 359          });
 360        } else {
 361          jqxhr = fileUploadIframe(a);
 362        }
 363      } else if ((hasFileInputs || multipart) && fileAPI) {
 364        jqxhr = fileUploadXhr(a);
 365      } else {
 366        jqxhr = $.ajax(options);
 367      }
 368  
 369      $form.removeData("jqxhr").data("jqxhr", jqxhr);
 370  
 371      // clear element array
 372      for (var k = 0; k < elements.length; k++) {
 373        elements[k] = null;
 374      }
 375  
 376      // fire 'notify' event
 377      this.trigger("form-submit-notify", [this, options]);
 378  
 379      return this;
 380  
 381      // utility fn for deep serialization
 382      function deepSerialize(extraData) {
 383        var param = $.param(extraData, traditional);
 384        var serialized = param ? param.split("&") : [];
 385        var len = serialized.length;
 386        var result = [];
 387        var i, part;
 388  
 389        for (i = 0; i < len; i++) {
 390          // #252; undo param space replacement
 391          serialized[i] = serialized[i].replace(/\+/g, " ");
 392          part = serialized[i].split("=");
 393          // #278; use array instead of object storage, favoring array serializations
 394          result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]);
 395        }
 396  
 397        return result;
 398      }
 399  
 400      // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
 401      function fileUploadXhr(a) {
 402        var formdata = new FormData();
 403  
 404        for (var i = 0; i < a.length; i++) {
 405          formdata.append(a[i].name, a[i].value);
 406        }
 407  
 408        if (options.extraData) {
 409          var serializedData = deepSerialize(options.extraData);
 410  
 411          for (i = 0; i < serializedData.length; i++) {
 412            formdata.append(serializedData[i][0], serializedData[i][1]);
 413          }
 414        }
 415  
 416        options.data = null;
 417  
 418        var s = $.extend(true, {}, $.ajaxSettings, options, {
 419          contentType: false,
 420          processData: false,
 421          cache: false,
 422          type: method || "POST",
 423        });
 424  
 425        if (options.uploadProgress) {
 426          // workaround because jqXHR does not expose upload property
 427          s.xhr = function () {
 428            var xhr = $.ajaxSettings.xhr();
 429  
 430            if (xhr.upload) {
 431              xhr.upload.addEventListener(
 432                "progress",
 433                function (event) {
 434                  var percent = 0;
 435                  var position = event.loaded || event.position; /* event.position is deprecated */
 436                  var total = event.total;
 437  
 438                  if (event.lengthComputable) {
 439                    percent = Math.ceil((position / total) * 100);
 440                  }
 441  
 442                  options.uploadProgress(event, position, total, percent);
 443                },
 444                false
 445              );
 446            }
 447  
 448            return xhr;
 449          };
 450        }
 451  
 452        s.data = null;
 453  
 454        var beforeSend = s.beforeSend;
 455  
 456        s.beforeSend = function (xhr, o) {
 457          // Send FormData() provided by user
 458          if (options.formData) {
 459            o.data = options.formData;
 460          } else {
 461            o.data = formdata;
 462          }
 463  
 464          if (beforeSend) {
 465            beforeSend.call(this, xhr, o);
 466          }
 467        };
 468  
 469        return $.ajax(s);
 470      }
 471  
 472      // private function for handling file uploads (hat tip to YAHOO!)
 473      function fileUploadIframe(a) {
 474        var form = $form[0],
 475          el,
 476          i,
 477          s,
 478          g,
 479          id,
 480          $io,
 481          io,
 482          xhr,
 483          sub,
 484          n,
 485          timeoutHandle,
 486          callbackProcessed;
 487        var deferred = $.Deferred();
 488  
 489        // #341
 490        deferred.abort = function (status) {
 491          xhr.abort(status);
 492        };
 493  
 494        // ensure that every serialized input is still enabled
 495        for (i = 0; i < elements.length; i++) {
 496          el = $(elements[i]);
 497          if (hasProp) {
 498            el.prop("disabled", false);
 499          } else {
 500            el.removeAttr("disabled");
 501          }
 502        }
 503  
 504        s = $.extend(true, {}, $.ajaxSettings, options);
 505        s.context = s.context || s;
 506        id = "jqFormIO" + new Date().getTime();
 507        var ownerDocument = form.ownerDocument;
 508        var $body = $form.closest("body");
 509  
 510        if (s.iframeTarget) {
 511          $io = $(s.iframeTarget, ownerDocument);
 512          n = $io.attr2("name");
 513          if (!n) {
 514            $io.attr2("name", id);
 515          } else {
 516            id = n;
 517          }
 518        } else {
 519          io = ownerDocument.createElement("iframe");
 520          io.setAttribute("name", id);
 521          io.setAttribute("src", s.iframeSrc);
 522          $io = $(io);
 523          $io.css({ position: "absolute", top: "-1000px", left: "-1000px" });
 524        }
 525        io = $io[0];
 526  
 527        xhr = {
 528          // mock object
 529          aborted: 0,
 530          responseText: null,
 531          responseXML: null,
 532          status: 0,
 533          statusText: "n/a",
 534          getAllResponseHeaders: function () {},
 535          getResponseHeader: function () {},
 536          setRequestHeader: function () {},
 537          abort: function (status) {
 538            abortUpload(status, [xhr, "aborted", status]);
 539          },
 540        };
 541  
 542        // Completes an aborted upload once and rejects the Deferred with `rejection`.
 543        function abortUpload(status, rejection) {
 544          var e = status === "timeout" ? "timeout" : "aborted";
 545  
 546          if (xhr.aborted || callbackProcessed) {
 547            return;
 548          }
 549  
 550          log("aborting upload... " + e);
 551          xhr.aborted = 1;
 552  
 553          try {
 554            // #214, #257
 555            if (io.contentWindow.document.execCommand) {
 556              io.contentWindow.document.execCommand("Stop");
 557            }
 558          } catch (ignore) {}
 559  
 560          $io.attr("src", s.iframeSrc); // abort op in progress
 561          xhr.error = e;
 562          if (s.error) {
 563            s.error.call(s.context, xhr, e, status);
 564          }
 565          deferred.reject.apply(deferred, rejection);
 566  
 567          if (g) {
 568            $.event.trigger("ajaxError", [xhr, s, e]);
 569          }
 570  
 571          complete(e);
 572        }
 573  
 574        // The steps every finished or aborted upload ends with, in $.ajax order.
 575        function complete(status) {
 576          if (g) {
 577            $.event.trigger("ajaxComplete", [xhr, s]);
 578          }
 579  
 580          if (g && !--$.active) {
 581            $.event.trigger("ajaxStop");
 582          }
 583  
 584          if (s.complete) {
 585            s.complete.call(s.context, xhr, status);
 586          }
 587  
 588          if (s.timeout) {
 589            clearTimeout(timeoutHandle);
 590          }
 591  
 592          // clean up
 593          setTimeout(function () {
 594            if (!s.iframeTarget) {
 595              $io.remove();
 596            } else {
 597              // adding else to clean up existing iframe response.
 598              $io.attr("src", s.iframeSrc);
 599            }
 600            xhr.responseXML = null;
 601          }, 100);
 602        }
 603  
 604        g = s.global;
 605        // trigger ajax global events so that activity/block indicators work like normal
 606        if (g && $.active++ === 0) {
 607          $.event.trigger("ajaxStart");
 608        }
 609        if (g) {
 610          $.event.trigger("ajaxSend", [xhr, s]);
 611        }
 612  
 613        if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
 614          if (s.global) {
 615            $.active--;
 616          }
 617          deferred.reject();
 618  
 619          return deferred;
 620        }
 621  
 622        if (xhr.aborted) {
 623          // abort() in beforeSend already rejected the Deferred
 624          return deferred;
 625        }
 626  
 627        // add submitting element to data if we know it
 628        sub = form.clk;
 629        if (sub) {
 630          n = sub.name;
 631          if (n && !sub.disabled) {
 632            s.extraData = s.extraData || {};
 633            s.extraData[n] = sub.value;
 634            if (sub.type === "image") {
 635              s.extraData[n + ".x"] = form.clk_x;
 636              s.extraData[n + ".y"] = form.clk_y;
 637            }
 638          }
 639        }
 640  
 641        var CLIENT_TIMEOUT_ABORT = 1;
 642        var SERVER_ABORT = 2;
 643  
 644        function getDoc(frame) {
 645          /* it looks like contentWindow or contentDocument do not
 646           * carry the protocol property in ie8, when running under ssl
 647           * frame.document is the only valid response document, since
 648           * the protocol is know but not on the other two objects. strange?
 649           * "Same origin policy" http://en.wikipedia.org/wiki/Same_origin_policy
 650           */
 651  
 652          var doc = null;
 653  
 654          // IE8 cascading access check
 655          try {
 656            if (frame.contentWindow) {
 657              doc = frame.contentWindow.document;
 658            }
 659          } catch (err) {
 660            // IE8 access denied under ssl & missing protocol
 661            log("cannot get iframe.contentWindow document: " + err);
 662          }
 663  
 664          if (doc) {
 665            // successful getting content
 666            return doc;
 667          }
 668  
 669          try {
 670            // simply checking may throw in ie8 under ssl or mismatched protocol
 671            doc = frame.contentDocument ? frame.contentDocument : frame.document;
 672          } catch (err) {
 673            // last attempt
 674            log("cannot get iframe.contentDocument: " + err);
 675            doc = frame.document;
 676          }
 677  
 678          return doc;
 679        }
 680  
 681        // Rails CSRF hack (thanks to Yvan Barthelemy); like jquery-ujs, only for the page's origin and
 682        // only when the form is posted, since a get form would put the token in the url
 683        var csrf_token = $("meta[name=csrf-token]").attr("content");
 684        var csrf_param = $("meta[name=csrf-param]").attr("content");
 685        var posts = !method || /post/i.test(method) || /post/i.test($form.attr2("method"));
 686  
 687        if (csrf_param && csrf_token && posts && isSameOrigin(s.url)) {
 688          s.extraData = s.extraData || {};
 689          s.extraData[csrf_param] = csrf_token;
 690        }
 691  
 692        function setFormAttribute(name, value) {
 693          plainForm.setAttribute.call(form, name, value);
 694        }
 695  
 696        // take a breath so that pending repaints get some cpu time before the upload starts
 697        function doSubmit() {
 698          // make sure form attrs are set
 699          var t = $form.attr2("target"),
 700            a = $form.attr2("action"),
 701            mp = "multipart/form-data",
 702            et = $form.attr("enctype") || $form.attr("encoding") || mp;
 703  
 704          // update form attrs in IE friendly way
 705          setFormAttribute("target", id);
 706          if (!method || /post/i.test(method)) {
 707            setFormAttribute("method", "POST");
 708          }
 709          if (a !== s.url) {
 710            setFormAttribute("action", s.url);
 711          }
 712  
 713          // ie borks in some cases when setting encoding
 714          if (!s.skipEncodingOverride && (!method || /post/i.test(method))) {
 715            setFormAttribute("encoding", mp);
 716            setFormAttribute("enctype", mp);
 717          }
 718  
 719          // support timout
 720          if (s.timeout) {
 721            timeoutHandle = setTimeout(function () {
 722              cb(CLIENT_TIMEOUT_ABORT);
 723            }, s.timeout);
 724          }
 725  
 726          // look for server aborts
 727          function checkState() {
 728            try {
 729              var state = getDoc(io).readyState;
 730  
 731              log("state = " + state);
 732              if (state && state.toLowerCase() === "uninitialized") {
 733                setTimeout(checkState, 50);
 734              }
 735            } catch (e) {
 736              log("Server abort: ", e, " (", e.name, ")");
 737              cb(SERVER_ABORT);
 738              if (timeoutHandle) {
 739                clearTimeout(timeoutHandle);
 740              }
 741              timeoutHandle = undefined;
 742            }
 743          }
 744  
 745          // add "extra" data to form if provided in options
 746          var extraInputs = [];
 747  
 748          // Builds the input with DOM properties: a name is never parsed as HTML.
 749          function addHiddenInput(name, value) {
 750            var input = ownerDocument.createElement("input");
 751  
 752            input.type = "hidden";
 753            input.name = name;
 754            extraInputs.push($(input).val(value).appendTo(form)[0]);
 755          }
 756  
 757          try {
 758            if (s.extraData) {
 759              for (var n in s.extraData) {
 760                if (hasOwn.call(s.extraData, n)) {
 761                  // if using the $.param format that allows for multiple values with the same name
 762                  if (
 763                    $.isPlainObject(s.extraData[n]) &&
 764                    hasOwn.call(s.extraData[n], "name") &&
 765                    hasOwn.call(s.extraData[n], "value")
 766                  ) {
 767                    addHiddenInput(s.extraData[n].name, s.extraData[n].value);
 768                  } else {
 769                    // arrays and objects become one field per value, as $.param sends them (#597)
 770                    var single = {};
 771  
 772                    single[n] = s.extraData[n];
 773                    var fields = deepSerialize(single);
 774  
 775                    for (var f = 0; f < fields.length; f++) {
 776                      addHiddenInput(fields[f][0], fields[f][1]);
 777                    }
 778                  }
 779                }
 780              }
 781            }
 782  
 783            if (!s.iframeTarget) {
 784              // add iframe to doc and submit the form
 785              $io.appendTo($body);
 786            }
 787  
 788            if (io.attachEvent) {
 789              io.attachEvent("onload", cb);
 790            } else {
 791              io.addEventListener("load", cb, false);
 792            }
 793  
 794            setTimeout(checkState, 15);
 795  
 796            try {
 797              form.submit();
 798            } catch (err) {
 799              // just in case form has element with name/id of 'submit'
 800              plainForm.submit.call(form);
 801            }
 802          } finally {
 803            // reset attrs and remove "extra" input elements
 804            if (typeof a === "string") {
 805              setFormAttribute("action", a);
 806            } else {
 807              // a control named action hid a missing action attribute
 808              plainForm.removeAttribute.call(form, "action");
 809            }
 810            setFormAttribute("enctype", et); // #380
 811            if (t) {
 812              setFormAttribute("target", t);
 813            } else {
 814              plainForm.removeAttribute.call(form, "target");
 815            }
 816            $(extraInputs).remove();
 817          }
 818        }
 819  
 820        if (s.forceSync) {
 821          doSubmit();
 822        } else {
 823          setTimeout(doSubmit, 10); // this lets dom updates render
 824        }
 825  
 826        var data,
 827          doc,
 828          domCheckCount = 50;
 829  
 830        function cb(e) {
 831          if (xhr.aborted || callbackProcessed) {
 832            return;
 833          }
 834  
 835          doc = getDoc(io);
 836          if (!doc) {
 837            log("cannot access response document");
 838            e = SERVER_ABORT;
 839          }
 840          if (e === CLIENT_TIMEOUT_ABORT && xhr) {
 841            abortUpload("timeout", [xhr, "timeout"]);
 842  
 843            return;
 844          }
 845          if (e === SERVER_ABORT && xhr) {
 846            abortUpload("server abort", [xhr, "error", "server abort"]);
 847  
 848            return;
 849          }
 850  
 851          if (doc.location.href === s.iframeSrc) {
 852            // response not received yet
 853            return;
 854          }
 855  
 856          if (io.detachEvent) {
 857            io.detachEvent("onload", cb);
 858          } else {
 859            io.removeEventListener("load", cb, false);
 860          }
 861  
 862          var status = "success",
 863            errMsg;
 864  
 865          try {
 866            var isXml = s.dataType === "xml" || doc.XMLDocument || $.isXMLDoc(doc);
 867  
 868            log("isXml=" + isXml);
 869  
 870            if (!isXml && window.opera && (doc.body === null || !doc.body.innerHTML)) {
 871              if (--domCheckCount) {
 872                // in some browsers (Opera) the iframe DOM is not always traversable when
 873                // the onload callback fires, so we loop a bit to accommodate
 874                log("requeing onLoad callback, DOM not available");
 875                setTimeout(cb, 250);
 876  
 877                return;
 878              }
 879              // let this fall through because server response could be an empty document
 880              // log('Could not access iframe DOM after mutiple tries.');
 881              // throw 'DOMException: not available';
 882            }
 883  
 884            // log('response detected');
 885            var docRoot = doc.body ? doc.body : doc.documentElement;
 886  
 887            xhr.responseText = docRoot ? docRoot.innerHTML : null;
 888            xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
 889            if (isXml) {
 890              s.dataType = "xml";
 891            }
 892            xhr.getResponseHeader = function (header) {
 893              var headers = { "content-type": s.dataType };
 894  
 895              return headers[header.toLowerCase()];
 896            };
 897            // support for XHR 'status' & 'statusText' emulation :
 898            if (docRoot) {
 899              xhr.status = Number(docRoot.getAttribute("status")) || xhr.status;
 900              xhr.statusText = docRoot.getAttribute("statusText") || xhr.statusText;
 901            }
 902  
 903            var dt = (s.dataType || "").toLowerCase();
 904            var scr = /(json|script|text)/.test(dt);
 905  
 906            if (scr || s.textarea) {
 907              // see if user embedded response in textarea
 908              var ta = doc.getElementsByTagName("textarea")[0];
 909  
 910              if (ta) {
 911                xhr.responseText = ta.value;
 912                // support for XHR 'status' & 'statusText' emulation :
 913                xhr.status = Number(ta.getAttribute("status")) || xhr.status;
 914                xhr.statusText = ta.getAttribute("statusText") || xhr.statusText;
 915              } else if (scr) {
 916                // account for browsers injecting pre around json response
 917                var pre = doc.getElementsByTagName("pre")[0];
 918                var b = doc.getElementsByTagName("body")[0];
 919  
 920                if (pre) {
 921                  xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
 922                } else if (b) {
 923                  xhr.responseText = b.textContent ? b.textContent : b.innerText;
 924                }
 925              }
 926            }
 927  
 928            try {
 929              data = httpData(xhr, dt, s); // eslint-disable-line no-use-before-define
 930            } catch (err) {
 931              status = "parsererror";
 932              xhr.error = errMsg = err || status;
 933            }
 934          } catch (err) {
 935            log("error caught: ", err);
 936            status = "error";
 937            xhr.error = errMsg = err;
 938          }
 939  
 940          if (xhr.aborted) {
 941            // abort() completed the upload while its response was processed
 942            log("upload aborted");
 943  
 944            return;
 945          }
 946  
 947          // an emulated HTTP error status wins, as in $.ajax; a parse error is kept otherwise
 948          if (xhr.status && !((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304)) {
 949            status = "error";
 950          }
 951  
 952          callbackProcessed = true;
 953  
 954          // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
 955          if (status === "success") {
 956            s.success.call(s.context, data, "success", xhr);
 957  
 958            deferred.resolve(xhr.responseText, "success", xhr);
 959  
 960            if (g) {
 961              $.event.trigger("ajaxSuccess", [xhr, s]);
 962            }
 963          } else {
 964            if (typeof errMsg === "undefined") {
 965              errMsg = xhr.statusText;
 966            }
 967            if (s.error) {
 968              s.error.call(s.context, xhr, status, errMsg);
 969            }
 970            deferred.reject(xhr, "error", errMsg);
 971            if (g) {
 972              $.event.trigger("ajaxError", [xhr, s, errMsg]);
 973            }
 974          }
 975  
 976          complete(status);
 977        }
 978  
 979        var httpData = function (xhr, type, s) {
 980          // mostly lifted from jq1.4.4
 981  
 982          var ct = xhr.getResponseHeader("content-type") || "",
 983            xml = (type === "xml" || !type) && ct.indexOf("xml") >= 0,
 984            data = xml ? xhr.responseXML : xhr.responseText;
 985  
 986          if (xml && data.documentElement.nodeName === "parsererror") {
 987            if ($.error) {
 988              $.error("parsererror");
 989            }
 990          }
 991          if (s && s.dataFilter) {
 992            data = s.dataFilter(data, type);
 993          }
 994          if (typeof data === "string") {
 995            if ((type === "json" || !type) && ct.indexOf("json") >= 0) {
 996              data = JSON.parse(data);
 997            } else if (type === "script") {
 998              $.globalEval(data);
 999            }
1000          }
1001  
1002          return data;
1003        };
1004  
1005        return deferred;
1006      }
1007    };
1008  
1009    /**
1010     * ajaxForm() provides a mechanism for fully automating form submission.
1011     *
1012     * The advantages of using this method instead of ajaxSubmit() are:
1013     *
1014     * 1: This method will include coordinates for <input type="image"> elements (if the element
1015     *    is used to submit the form).
1016     * 2. This method will include the submit element's name/value data (for the element that was
1017     *    used to submit the form).
1018     * 3. This method binds the submit() method to the form for you.
1019     *
1020     * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
1021     * passes the options argument along after properly binding events for submit elements and
1022     * the form itself.
1023     */
1024    $.fn.ajaxForm = function (options, data, dataType, onSuccess) {
1025      if (typeof options === "string" || (options === false && arguments.length > 0)) {
1026        options = {
1027          url: options,
1028          data: data,
1029          dataType: dataType,
1030        };
1031  
1032        if (typeof onSuccess === "function") {
1033          options.success = onSuccess;
1034        }
1035      }
1036  
1037      options = options || {};
1038      options.delegation = options.delegation && typeof $.fn.on === "function";
1039  
1040      // in jQuery 1.3+ we can fix mistakes with the ready state
1041      if (!options.delegation && this.length === 0) {
1042        var o = { s: this.selector, c: this.context };
1043  
1044        if (!$.isReady && o.s) {
1045          log("DOM not ready, queuing ajaxForm");
1046          $(function () {
1047            $(o.s, o.c).ajaxForm(options);
1048          });
1049  
1050          return this;
1051        }
1052  
1053        // is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
1054        log("terminating; zero elements found by selector" + ($.isReady ? "" : " (DOM not ready)"));
1055  
1056        return this;
1057      }
1058  
1059      if (options.delegation) {
1060        $(document)
1061          .off("submit.form-plugin", this.selector, doAjaxSubmit)
1062          .off("click.form-plugin", this.selector, captureSubmittingElement)
1063          .on("submit.form-plugin", this.selector, options, doAjaxSubmit)
1064          .on("click.form-plugin", this.selector, options, captureSubmittingElement);
1065  
1066        return this;
1067      }
1068  
1069      if (options.beforeFormUnbind) {
1070        options.beforeFormUnbind(this, options);
1071      }
1072  
1073      return this.ajaxFormUnbind()
1074        .on("submit.form-plugin", options, doAjaxSubmit)
1075        .on("click.form-plugin", options, captureSubmittingElement);
1076    };
1077  
1078    // private event handlers
1079    function doAjaxSubmit(e) {
1080      /* jshint validthis:true */
1081      var options = e.data;
1082  
1083      if (!e.isDefaultPrevented()) {
1084        // if event has been canceled, don't proceed
1085        e.preventDefault();
1086        $(e.target).closest("form").ajaxSubmit(options); // #365
1087      }
1088    }
1089  
1090    function captureSubmittingElement(e) {
1091      /* jshint validthis:true */
1092      // the clicked control, or the button around the clicked content (ex: a span within a button)
1093      var $el = $(e.target).closest("button,input");
1094      var target = $el[0];
1095  
1096      // the type property, unlike the attribute, is "submit" for a button without a type (#588)
1097      if (!target || (target.type !== "submit" && target.type !== "image")) {
1098        return;
1099      }
1100  
1101      var form = target.form;
1102  
1103      if (!form) {
1104        // a submit control that belongs to no form
1105        return;
1106      }
1107  
1108      form.clk = target;
1109  
1110      if (target.type === "image") {
1111        if (typeof e.offsetX !== "undefined") {
1112          form.clk_x = e.offsetX;
1113          form.clk_y = e.offsetY;
1114        } else if (typeof $.fn.offset === "function") {
1115          var offset = $el.offset();
1116  
1117          form.clk_x = e.pageX - offset.left;
1118          form.clk_y = e.pageY - offset.top;
1119        } else {
1120          form.clk_x = e.pageX - target.offsetLeft;
1121          form.clk_y = e.pageY - target.offsetTop;
1122        }
1123      }
1124      // clear form vars
1125      setTimeout(function () {
1126        form.clk = form.clk_x = form.clk_y = null;
1127      }, 100);
1128    }
1129  
1130    // ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
1131    $.fn.ajaxFormUnbind = function () {
1132      return this.off("submit.form-plugin click.form-plugin");
1133    };
1134  
1135    /**
1136     * formToArray() gathers form element data into an array of objects that can
1137     * be passed to any of the following ajax functions: $.get, $.post, or load.
1138     * Each object in the array has both a 'name' and 'value' property. An example of
1139     * an array for a simple login form might be:
1140     *
1141     * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
1142     *
1143     * It is this array that is passed to pre-submit callback functions provided to the
1144     * ajaxSubmit() and ajaxForm() methods.
1145     */
1146    $.fn.formToArray = function (semantic, elements, filtering) {
1147      var a = [];
1148  
1149      if (this.length === 0) {
1150        return a;
1151      }
1152  
1153      var form = this[0];
1154      var formId = this.attr("id");
1155      var els =
1156        semantic || typeof form.elements === "undefined"
1157          ? form.getElementsByTagName("*")
1158          : formElements(form);
1159      var els2;
1160  
1161      if (els) {
1162        els = $.makeArray(els); // convert to standard array
1163      }
1164  
1165      // #386; account for inputs outside the form which use the 'form' attribute
1166      // FinesseRus: in non-IE browsers outside fields are already included in form.elements.
1167      if (formId && (semantic || /(Edge|Trident)\//.test(navigator.userAgent))) {
1168        // hat tip @thet; the id is compared, never built into a selector
1169        els2 = $(":input[form]")
1170          .filter(function () {
1171            return this.getAttribute("form") === formId;
1172          })
1173          .get();
1174        if (els2.length) {
1175          els = els.concat(els2);
1176        }
1177      }
1178  
1179      if (!els || !els.length) {
1180        return a;
1181      }
1182  
1183      if (typeof filtering === "function") {
1184        els = $.map(els, filtering);
1185      }
1186  
1187      var i, j, n, v, el, max, jmax;
1188  
1189      for (i = 0, max = els.length; i < max; i++) {
1190        el = els[i];
1191        n = el.name;
1192        if (!n || el.disabled) {
1193          continue;
1194        }
1195  
1196        if (semantic && form.clk && el.type === "image") {
1197          // handle image inputs on the fly when semantic == true
1198          if (form.clk === el) {
1199            a.push({ name: n, value: $(el).val(), type: el.type });
1200            a.push({ name: n + ".x", value: form.clk_x }, { name: n + ".y", value: form.clk_y });
1201          }
1202          continue;
1203        }
1204  
1205        v = $.fieldValue(el, true);
1206        if (v && v.constructor === Array) {
1207          if (elements) {
1208            elements.push(el);
1209          }
1210          for (j = 0, jmax = v.length; j < jmax; j++) {
1211            a.push({ name: n, value: v[j] });
1212          }
1213        } else if (feature.fileapi && el.type === "file") {
1214          if (elements) {
1215            elements.push(el);
1216          }
1217  
1218          var files = el.files;
1219  
1220          if (files.length) {
1221            for (j = 0; j < files.length; j++) {
1222              a.push({ name: n, value: files[j], type: el.type });
1223            }
1224          } else {
1225            // #180
1226            a.push({ name: n, value: "", type: el.type });
1227          }
1228        } else if (v !== null && typeof v !== "undefined") {
1229          if (elements) {
1230            elements.push(el);
1231          }
1232          a.push({ name: n, value: v, type: el.type, required: el.required });
1233        }
1234      }
1235  
1236      if (!semantic && form.clk) {
1237        // input type=='image' are not found in elements array! handle it here
1238        var $input = $(form.clk),
1239          input = $input[0];
1240  
1241        n = input.name;
1242  
1243        if (n && !input.disabled && input.type === "image") {
1244          a.push({ name: n, value: $input.val() });
1245          a.push({ name: n + ".x", value: form.clk_x }, { name: n + ".y", value: form.clk_y });
1246        }
1247      }
1248  
1249      return a;
1250    };
1251  
1252    /**
1253     * Serializes form data into a 'submittable' string. This method will return a string
1254     * in the format: name1=value1&amp;name2=value2
1255     */
1256    $.fn.formSerialize = function (semantic) {
1257      // hand off to jQuery.param for proper encoding
1258      return $.param(this.formToArray(semantic));
1259    };
1260  
1261    /**
1262     * Serializes all field elements in the jQuery object into a query string.
1263     * This method will return a string in the format: name1=value1&amp;name2=value2
1264     */
1265    $.fn.fieldSerialize = function (successful) {
1266      var a = [];
1267  
1268      this.each(function () {
1269        var n = this.name;
1270  
1271        if (!n) {
1272          return;
1273        }
1274  
1275        var v = $.fieldValue(this, successful);
1276  
1277        if (v && v.constructor === Array) {
1278          for (var i = 0, max = v.length; i < max; i++) {
1279            a.push({ name: n, value: v[i] });
1280          }
1281        } else if (v !== null && typeof v !== "undefined") {
1282          a.push({ name: this.name, value: v });
1283        }
1284      });
1285  
1286      // hand off to jQuery.param for proper encoding
1287      return $.param(a);
1288    };
1289  
1290    /**
1291     * Returns the value(s) of the element in the matched set. For example, consider the following form:
1292     *
1293     *    <form><fieldset>
1294     *        <input name="A" type="text">
1295     *        <input name="A" type="text">
1296     *        <input name="B" type="checkbox" value="B1">
1297     *        <input name="B" type="checkbox" value="B2">
1298     *        <input name="C" type="radio" value="C1">
1299     *        <input name="C" type="radio" value="C2">
1300     *    </fieldset></form>
1301     *
1302     *    var v = $('input[type=text]').fieldValue();
1303     *    // if no values are entered into the text inputs
1304     *    v === ['','']
1305     *    // if values entered into the text inputs are 'foo' and 'bar'
1306     *    v === ['foo','bar']
1307     *
1308     *    var v = $('input[type=checkbox]').fieldValue();
1309     *    // if neither checkbox is checked
1310     *    v === undefined
1311     *    // if both checkboxes are checked
1312     *    v === ['B1', 'B2']
1313     *
1314     *    var v = $('input[type=radio]').fieldValue();
1315     *    // if neither radio is checked
1316     *    v === undefined
1317     *    // if first radio is checked
1318     *    v === ['C1']
1319     *
1320     * The successful argument controls whether or not the field element must be 'successful'
1321     * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
1322     * The default value of the successful argument is true. If this value is false the value(s)
1323     * for each element is returned.
1324     *
1325     * Note: This method *always* returns an array. If no valid value can be determined the
1326     *    array will be empty, otherwise it will contain one or more values.
1327     */
1328    $.fn.fieldValue = function (successful) {
1329      for (var val = [], i = 0, max = this.length; i < max; i++) {
1330        var el = this[i];
1331        var v = $.fieldValue(el, successful);
1332  
1333        if (v === null || typeof v === "undefined" || (v.constructor === Array && !v.length)) {
1334          continue;
1335        }
1336  
1337        if (v.constructor === Array) {
1338          $.merge(val, v);
1339        } else {
1340          val.push(v);
1341        }
1342      }
1343  
1344      return val;
1345    };
1346  
1347    /**
1348     * Returns the value of the field element.
1349     */
1350    $.fieldValue = function (el, successful) {
1351      var n = el.name,
1352        t = el.type,
1353        tag = tagName(el);
1354  
1355      if (typeof successful === "undefined") {
1356        successful = true;
1357      }
1358  
1359      if (
1360        successful &&
1361        (!n ||
1362          el.disabled ||
1363          t === "reset" ||
1364          t === "button" ||
1365          ((t === "checkbox" || t === "radio") && !el.checked) ||
1366          ((t === "submit" || t === "image") && el.form && el.form.clk !== el) ||
1367          (tag === "select" && el.selectedIndex === -1))
1368      ) {
1369        return null;
1370      }
1371  
1372      if (tag === "select") {
1373        var index = el.selectedIndex;
1374  
1375        if (index < 0) {
1376          return null;
1377        }
1378  
1379        var a = [],
1380          ops = el.options;
1381        var one = t === "select-one";
1382        var max = one ? index + 1 : ops.length;
1383  
1384        for (var i = one ? index : 0; i < max; i++) {
1385          var op = ops[i];
1386  
1387          if (op.selected && !op.disabled) {
1388            var v = op.value;
1389  
1390            if (!v) {
1391              // extra pain for IE...
1392              v =
1393                op.attributes && op.attributes.value && !op.attributes.value.specified
1394                  ? op.text
1395                  : op.value;
1396            }
1397  
1398            if (one) {
1399              return v;
1400            }
1401  
1402            a.push(v);
1403          }
1404        }
1405  
1406        return a;
1407      }
1408  
1409      return $(el).val().replace(rCRLF, "\r\n");
1410    };
1411  
1412    /**
1413     * Clears the form data. Takes the following actions on the form's input fields:
1414     *  - input text fields will have their 'value' property set to the empty string
1415     *  - select elements will have their 'selectedIndex' property set to -1
1416     *  - checkbox and radio inputs will have their 'checked' property set to false
1417     *  - inputs of type submit, button, reset, and hidden will *not* be effected
1418     *  - button elements will *not* be effected
1419     */
1420    $.fn.clearForm = function (includeHidden) {
1421      return this.each(function () {
1422        $("input,select,textarea", this).clearFields(includeHidden);
1423      });
1424    };
1425  
1426    /**
1427     * Clears the selected form elements.
1428     */
1429    $.fn.clearFields = $.fn.clearInputs = function (includeHidden) {
1430      var re =
1431        /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
1432  
1433      return this.each(function () {
1434        var t = this.type,
1435          tag = tagName(this);
1436  
1437        if (re.test(t) || tag === "textarea") {
1438          this.value = "";
1439        } else if (t === "checkbox" || t === "radio") {
1440          this.checked = false;
1441        } else if (tag === "select") {
1442          this.selectedIndex = -1;
1443        } else if (t === "file") {
1444          if (/MSIE/.test(navigator.userAgent)) {
1445            $(this).replaceWith($(this).clone(true));
1446          } else {
1447            $(this).val("");
1448          }
1449        } else if (includeHidden) {
1450          // includeHidden can be the value true, or it can be a selector string
1451          // indicating a special test; for example:
1452          // $('#myForm').clearForm('.special:hidden')
1453          // the above would clean hidden inputs that have the class of 'special'
1454          if (
1455            (includeHidden === true && /hidden/.test(t)) ||
1456            (typeof includeHidden === "string" && $(this).is(includeHidden))
1457          ) {
1458            this.value = "";
1459          }
1460        }
1461      });
1462    };
1463  
1464    /**
1465     * Resets the form data or individual elements. Takes the following actions
1466     * on the selected tags:
1467     * - all fields within form elements will be reset to their original value
1468     * - input / textarea / select fields will be reset to their original value
1469     * - option / optgroup fields (for multi-selects) will defaulted individually
1470     * - non-multiple options will find the right select to default
1471     * - label elements will be searched against its 'for' attribute
1472     * - all others will be searched for appropriate children to default
1473     */
1474    $.fn.resetForm = function () {
1475      return this.each(function () {
1476        var el = $(this);
1477        var tag = tagName(this);
1478  
1479        switch (tag) {
1480          case "input":
1481            this.checked = this.defaultChecked;
1482          // fall through
1483  
1484          case "textarea":
1485            this.value = this.defaultValue;
1486  
1487            return true;
1488  
1489          case "option":
1490          case "optgroup":
1491            var select = el.parents("select");
1492  
1493            if (select.length && select[0].multiple) {
1494              if (tag === "option") {
1495                this.selected = this.defaultSelected;
1496              } else {
1497                el.find("option").resetForm();
1498              }
1499            } else {
1500              select.resetForm();
1501            }
1502  
1503            return true;
1504  
1505          case "select":
1506            // eslint-disable-next-line consistent-return -- jQuery .each() break semantics
1507            el.find("option").each(function (i) {
1508              this.selected = this.defaultSelected;
1509              if (this.defaultSelected && !el[0].multiple) {
1510                el[0].selectedIndex = i;
1511  
1512                return false;
1513              }
1514            });
1515  
1516            return true;
1517  
1518          case "label":
1519            // The control whose id the for attribute names, and the controls inside the label. The
1520            // filter keeps a for that names an ancestor from resetting the label again.
1521            var forEl = this.htmlFor && this.ownerDocument.getElementById(this.htmlFor);
1522  
1523            el.find("input,select,textarea").add(forEl).filter("input,select,textarea").resetForm();
1524  
1525            return true;
1526  
1527          case "form":
1528            // guard against an input with the name of 'reset'
1529            // note that IE reports the reset function as an 'object'
1530            if (
1531              typeof this.reset === "function" ||
1532              (typeof this.reset === "object" && !this.reset.nodeType)
1533            ) {
1534              this.reset();
1535            }
1536  
1537            return true;
1538  
1539          default:
1540            el.find("form,input,label,select,textarea").resetForm();
1541  
1542            return true;
1543        }
1544      });
1545    };
1546  
1547    /**
1548     * Enables or disables any matching elements.
1549     */
1550    $.fn.enable = function (b) {
1551      if (typeof b === "undefined") {
1552        b = true;
1553      }
1554  
1555      return this.each(function () {
1556        this.disabled = !b;
1557      });
1558    };
1559  
1560    /**
1561     * Checks/unchecks any matching checkboxes or radio buttons and
1562     * selects/deselects and matching option elements.
1563     */
1564    $.fn.selected = function (select) {
1565      if (typeof select === "undefined") {
1566        select = true;
1567      }
1568  
1569      return this.each(function () {
1570        var t = this.type;
1571  
1572        if (t === "checkbox" || t === "radio") {
1573          this.checked = select;
1574        } else if (tagName(this) === "option") {
1575          var $sel = $(this).parent("select");
1576  
1577          if (select && $sel[0] && $sel[0].type === "select-one") {
1578            // deselect all other options
1579            $sel.find("option").selected(false);
1580          }
1581  
1582          this.selected = select;
1583        }
1584      });
1585    };
1586  
1587    // expose debug var
1588    $.fn.ajaxSubmit.debug = false;
1589  
1590    // helper fn for console logging
1591    function log() {
1592      if (!$.fn.ajaxSubmit.debug) {
1593        return;
1594      }
1595  
1596      var msg = "[jquery.form] " + Array.prototype.join.call(arguments, "");
1597  
1598      if (window.console && window.console.log) {
1599        window.console.log(msg);
1600      } else if (window.opera && window.opera.postError) {
1601        window.opera.postError(msg);
1602      }
1603    }
1604  })(jQuery);
1605  
1606  export default jQuery;


Generated : Thu Nov 19 08:20:01 2026 Cross-referenced by PHPXref