PageRenderTime 31ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/yui/3.0.0pr2/io/io-form-debug.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 88 lines | 56 code | 8 blank | 24 comment | 12 complexity | c7b2c04babc42d2b2d1af1af8ae52a2b MD5 | raw file
  1. YUI.add('io-form', function(Y) {
  2. /*
  3. * Extends the IO base class to enable HTML form data serialization, when specified
  4. * in the transaction's configuration object.
  5. * @module io-base
  6. * @submodule io-form
  7. */
  8. Y.mix(Y.io, {
  9. /**
  10. * @description Method to enumerate through an HTML form's elements collection
  11. * and return a string comprised of key-value pairs.
  12. *
  13. * @method _serialize
  14. * @private
  15. * @static
  16. * @param {object} o - HTML form object or id.
  17. * @return string
  18. */
  19. _serialize: function(o) {
  20. var f = (typeof o.id === 'object') ? o.id : Y.config.doc.getElementById(o.id),
  21. eUC = encodeURIComponent,
  22. data = [],
  23. useDf = o.useDisabled || false,
  24. item = 0,
  25. e, n, v, d, i, ilen, j, jlen, o;
  26. // Iterate over the form elements collection to construct the
  27. // label-value pairs.
  28. for (i = 0, ilen = f.elements.length; i < ilen; ++i) {
  29. e = f.elements[i];
  30. d = e.disabled;
  31. n = e.name;
  32. if ((useDf) ? n : (n && !d)) {
  33. n = encodeURIComponent(n) + '=';
  34. v = encodeURIComponent(e.value);
  35. switch (e.type) {
  36. // Safari, Opera, FF all default opt.value from .text if
  37. // value attribute not specified in markup
  38. case 'select-one':
  39. if (e.selectedIndex > -1) {
  40. o = e.options[e.selectedIndex];
  41. data[item++] = n + eUC((o.attributes.value && o.attributes.value.specified) ? o.value : o.text);
  42. }
  43. break;
  44. case 'select-multiple':
  45. if (e.selectedIndex > -1) {
  46. for (j = e.selectedIndex, jlen = e.options.length; j < jlen; ++j) {
  47. o = e.options[j];
  48. if (o.selected) {
  49. data[item++] = n + eUC((o.attributes.value && opt.attributes.value.specified) ? o.value : o.text);
  50. }
  51. }
  52. }
  53. break;
  54. case 'radio':
  55. case 'checkbox':
  56. if(e.checked){
  57. data[item++] = n + v;
  58. }
  59. break;
  60. case 'file':
  61. // stub case as XMLHttpRequest will only send the file path as a string.
  62. case undefined:
  63. // stub case for fieldset element which returns undefined.
  64. case 'reset':
  65. // stub case for input type reset button.
  66. case 'button':
  67. // stub case for input type button elements.
  68. break;
  69. case 'submit':
  70. break;
  71. default:
  72. data[item++] = n + v;
  73. }
  74. }
  75. }
  76. Y.log('HTML form serialized. The value is: ' + data.join('&'), 'info', 'io');
  77. return data.join('&');
  78. }
  79. }, true);
  80. }, '@VERSION@' ,{requires:['io-base']});