Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'dev-master' into Satyam-2532810

  • Loading branch information...
commit 9e579f2aee819a73505d75429cd516a271cbc5b0 2 parents b5c9a4c + 6bb7337
@ericf ericf authored
View
125 build/io-form/io-form-coverage.js
@@ -26,11 +26,11 @@ _yuitest_coverage["build/io-form/io-form.js"] = {
path: "build/io-form/io-form.js",
code: []
};
-_yuitest_coverage["build/io-form/io-form.js"].code=["YUI.add('io-form', function (Y, NAME) {","","/**","* Extends IO to enable HTML form data serialization, when specified","* in the transaction's configuration object.","* @module io","* @submodule io-form","* @for IO","*/","","var eUC = encodeURIComponent;","","Y.mix(Y.IO.prototype, {"," /**"," * Method to enumerate through an HTML form's elements collection"," * and return a string comprised of key-value pairs."," *"," * @method _serialize"," * @private"," * @static"," * @param {Object} c - YUI form node or HTML form id."," * @param {String} s - Key-value data defined in the configuration object."," * @return {String}"," */"," _serialize: function(c, s) {"," var data = [],"," df = c.useDisabled || false,"," item = 0,"," id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),"," e, f, n, v, d, i, il, j, jl, o;",""," if (!id) {"," id = Y.guid('io:');"," c.id.setAttribute('id', id);"," }",""," f = Y.config.doc.getElementById(id);",""," // Iterate over the form elements collection to construct the"," // label-value pairs."," for (i = 0, il = f.elements.length; i < il; ++i) {"," e = f.elements[i];"," d = e.disabled;"," n = e.name;",""," if (df ? n : n && !d) {"," n = eUC(n) + '=';"," v = eUC(e.value);",""," switch (e.type) {"," // Safari, Opera, FF all default options.value from .text if"," // value attribute not specified in markup"," case 'select-one':"," if (e.selectedIndex > -1) {"," o = e.options[e.selectedIndex];"," data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);"," }"," break;"," case 'select-multiple':"," if (e.selectedIndex > -1) {"," for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {"," o = e.options[j];"," if (o.selected) {"," data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);"," }"," }"," }"," break;"," case 'radio':"," case 'checkbox':"," if (e.checked) {"," data[item++] = n + v;"," }"," break;"," case 'file':"," // stub case as XMLHttpRequest will only send the file path as a string."," case undefined:"," // stub case for fieldset element which returns undefined."," case 'reset':"," // stub case for input type reset button."," case 'button':"," // stub case for input type button elements."," break;"," case 'submit':"," default:"," data[item++] = n + v;"," }"," }"," }"," return s ? data.join('&') + \"&\" + s : data.join('&');"," }","}, true);","","","}, '@VERSION@', {\"requires\": [\"io-base\", \"node-base\"]});"];
-_yuitest_coverage["build/io-form/io-form.js"].lines = {"1":0,"11":0,"13":0,"26":0,"32":0,"33":0,"34":0,"37":0,"41":0,"42":0,"43":0,"44":0,"46":0,"47":0,"48":0,"50":0,"54":0,"55":0,"56":0,"58":0,"60":0,"61":0,"62":0,"63":0,"64":0,"68":0,"71":0,"72":0,"74":0,"83":0,"86":0,"90":0};
-_yuitest_coverage["build/io-form/io-form.js"].functions = {"_serialize:25":0,"(anonymous 1):1":0};
-_yuitest_coverage["build/io-form/io-form.js"].coveredLines = 32;
-_yuitest_coverage["build/io-form/io-form.js"].coveredFunctions = 2;
+_yuitest_coverage["build/io-form/io-form.js"].code=["YUI.add('io-form', function (Y, NAME) {","","/**","* Extends IO to enable HTML form data serialization, when specified","* in the transaction's configuration object.","* @module io","* @submodule io-form","* @for IO","*/","","var eUC = encodeURIComponent;","","/**"," * Method to enumerate through an HTML form's elements collection"," * and return a string comprised of key-value pairs."," *"," * @method serialize"," * @static"," * @param {Node|String} form YUI form node or HTML form id"," * @param {Object} [options] Configuration options."," * @param {Boolean} [options.useDisabled=false] Whether to include disabled fields."," * @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs."," * @return {String}"," */","Y.IO.stringify = function(form, options) {"," options = options || {};",""," var s = Y.IO.prototype._serialize({"," id: form,"," useDisabled: options.useDisabled"," },"," options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);",""," return s;","};","","Y.mix(Y.IO.prototype, {"," /**"," * Method to enumerate through an HTML form's elements collection"," * and return a string comprised of key-value pairs."," *"," * @method _serialize"," * @private"," * @param {Object} c"," * @param {String|Element} c.id YUI form node or HTML form id"," * @param {Boolean} c.useDisabled `true` to include disabled fields"," * @param {String} s Key-value data defined in the configuration object."," * @return {String}"," */"," _serialize: function(c, s) {"," var data = [],"," df = c.useDisabled || false,"," item = 0,"," id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),"," e, f, n, v, d, i, il, j, jl, o;",""," if (!id) {"," id = Y.guid('io:');"," c.id.setAttribute('id', id);"," }",""," f = Y.config.doc.getElementById(id);",""," if (!f || !f.elements) {"," return s || '';"," }",""," // Iterate over the form elements collection to construct the"," // label-value pairs."," for (i = 0, il = f.elements.length; i < il; ++i) {"," e = f.elements[i];"," d = e.disabled;"," n = e.name;",""," if (df ? n : n && !d) {"," n = eUC(n) + '=';"," v = eUC(e.value);",""," switch (e.type) {"," // Safari, Opera, FF all default options.value from .text if"," // value attribute not specified in markup"," case 'select-one':"," if (e.selectedIndex > -1) {"," o = e.options[e.selectedIndex];"," data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);"," }"," break;"," case 'select-multiple':"," if (e.selectedIndex > -1) {"," for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {"," o = e.options[j];"," if (o.selected) {"," data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);"," }"," }"," }"," break;"," case 'radio':"," case 'checkbox':"," if (e.checked) {"," data[item++] = n + v;"," }"," break;"," case 'file':"," // stub case as XMLHttpRequest will only send the file path as a string."," case undefined:"," // stub case for fieldset element which returns undefined."," case 'reset':"," // stub case for input type reset button."," case 'button':"," // stub case for input type button elements."," break;"," case 'submit':"," default:"," data[item++] = n + v;"," }"," }"," }",""," if (s) {"," data[item++] = s;"," }",""," return data.join('&');"," }","}, true);","","","}, '@VERSION@', {\"requires\": [\"io-base\", \"node-base\"]});"];
+_yuitest_coverage["build/io-form/io-form.js"].lines = {"1":0,"11":0,"25":0,"26":0,"28":0,"34":0,"37":0,"51":0,"57":0,"58":0,"59":0,"62":0,"64":0,"65":0,"70":0,"71":0,"72":0,"73":0,"75":0,"76":0,"77":0,"79":0,"83":0,"84":0,"85":0,"87":0,"89":0,"90":0,"91":0,"92":0,"93":0,"97":0,"100":0,"101":0,"103":0,"112":0,"115":0,"120":0,"121":0,"124":0};
+_yuitest_coverage["build/io-form/io-form.js"].functions = {"stringify:25":0,"_serialize:50":0,"(anonymous 1):1":0};
+_yuitest_coverage["build/io-form/io-form.js"].coveredLines = 40;
+_yuitest_coverage["build/io-form/io-form.js"].coveredFunctions = 3;
_yuitest_coverline("build/io-form/io-form.js", 1);
YUI.add('io-form', function (Y, NAME) {
@@ -46,7 +46,36 @@ _yuitest_coverfunc("build/io-form/io-form.js", "(anonymous 1)", 1);
_yuitest_coverline("build/io-form/io-form.js", 11);
var eUC = encodeURIComponent;
-_yuitest_coverline("build/io-form/io-form.js", 13);
+/**
+ * Method to enumerate through an HTML form's elements collection
+ * and return a string comprised of key-value pairs.
+ *
+ * @method serialize
+ * @static
+ * @param {Node|String} form YUI form node or HTML form id
+ * @param {Object} [options] Configuration options.
+ * @param {Boolean} [options.useDisabled=false] Whether to include disabled fields.
+ * @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs.
+ * @return {String}
+ */
+_yuitest_coverline("build/io-form/io-form.js", 25);
+Y.IO.stringify = function(form, options) {
+ _yuitest_coverfunc("build/io-form/io-form.js", "stringify", 25);
+_yuitest_coverline("build/io-form/io-form.js", 26);
+options = options || {};
+
+ _yuitest_coverline("build/io-form/io-form.js", 28);
+var s = Y.IO.prototype._serialize({
+ id: form,
+ useDisabled: options.useDisabled
+ },
+ options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);
+
+ _yuitest_coverline("build/io-form/io-form.js", 34);
+return s;
+};
+
+_yuitest_coverline("build/io-form/io-form.js", 37);
Y.mix(Y.IO.prototype, {
/**
* Method to enumerate through an HTML form's elements collection
@@ -54,87 +83,94 @@ Y.mix(Y.IO.prototype, {
*
* @method _serialize
* @private
- * @static
- * @param {Object} c - YUI form node or HTML form id.
- * @param {String} s - Key-value data defined in the configuration object.
+ * @param {Object} c
+ * @param {String|Element} c.id YUI form node or HTML form id
+ * @param {Boolean} c.useDisabled `true` to include disabled fields
+ * @param {String} s Key-value data defined in the configuration object.
* @return {String}
*/
_serialize: function(c, s) {
- _yuitest_coverfunc("build/io-form/io-form.js", "_serialize", 25);
-_yuitest_coverline("build/io-form/io-form.js", 26);
+ _yuitest_coverfunc("build/io-form/io-form.js", "_serialize", 50);
+_yuitest_coverline("build/io-form/io-form.js", 51);
var data = [],
df = c.useDisabled || false,
item = 0,
id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
e, f, n, v, d, i, il, j, jl, o;
- _yuitest_coverline("build/io-form/io-form.js", 32);
+ _yuitest_coverline("build/io-form/io-form.js", 57);
if (!id) {
- _yuitest_coverline("build/io-form/io-form.js", 33);
+ _yuitest_coverline("build/io-form/io-form.js", 58);
id = Y.guid('io:');
- _yuitest_coverline("build/io-form/io-form.js", 34);
+ _yuitest_coverline("build/io-form/io-form.js", 59);
c.id.setAttribute('id', id);
- }
+ }
- _yuitest_coverline("build/io-form/io-form.js", 37);
+ _yuitest_coverline("build/io-form/io-form.js", 62);
f = Y.config.doc.getElementById(id);
+ _yuitest_coverline("build/io-form/io-form.js", 64);
+if (!f || !f.elements) {
+ _yuitest_coverline("build/io-form/io-form.js", 65);
+return s || '';
+ }
+
// Iterate over the form elements collection to construct the
// label-value pairs.
- _yuitest_coverline("build/io-form/io-form.js", 41);
+ _yuitest_coverline("build/io-form/io-form.js", 70);
for (i = 0, il = f.elements.length; i < il; ++i) {
- _yuitest_coverline("build/io-form/io-form.js", 42);
+ _yuitest_coverline("build/io-form/io-form.js", 71);
e = f.elements[i];
- _yuitest_coverline("build/io-form/io-form.js", 43);
+ _yuitest_coverline("build/io-form/io-form.js", 72);
d = e.disabled;
- _yuitest_coverline("build/io-form/io-form.js", 44);
+ _yuitest_coverline("build/io-form/io-form.js", 73);
n = e.name;
- _yuitest_coverline("build/io-form/io-form.js", 46);
+ _yuitest_coverline("build/io-form/io-form.js", 75);
if (df ? n : n && !d) {
- _yuitest_coverline("build/io-form/io-form.js", 47);
+ _yuitest_coverline("build/io-form/io-form.js", 76);
n = eUC(n) + '=';
- _yuitest_coverline("build/io-form/io-form.js", 48);
+ _yuitest_coverline("build/io-form/io-form.js", 77);
v = eUC(e.value);
- _yuitest_coverline("build/io-form/io-form.js", 50);
+ _yuitest_coverline("build/io-form/io-form.js", 79);
switch (e.type) {
// Safari, Opera, FF all default options.value from .text if
// value attribute not specified in markup
case 'select-one':
- _yuitest_coverline("build/io-form/io-form.js", 54);
+ _yuitest_coverline("build/io-form/io-form.js", 83);
if (e.selectedIndex > -1) {
- _yuitest_coverline("build/io-form/io-form.js", 55);
+ _yuitest_coverline("build/io-form/io-form.js", 84);
o = e.options[e.selectedIndex];
- _yuitest_coverline("build/io-form/io-form.js", 56);
+ _yuitest_coverline("build/io-form/io-form.js", 85);
data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
}
- _yuitest_coverline("build/io-form/io-form.js", 58);
+ _yuitest_coverline("build/io-form/io-form.js", 87);
break;
case 'select-multiple':
- _yuitest_coverline("build/io-form/io-form.js", 60);
+ _yuitest_coverline("build/io-form/io-form.js", 89);
if (e.selectedIndex > -1) {
- _yuitest_coverline("build/io-form/io-form.js", 61);
+ _yuitest_coverline("build/io-form/io-form.js", 90);
for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
- _yuitest_coverline("build/io-form/io-form.js", 62);
+ _yuitest_coverline("build/io-form/io-form.js", 91);
o = e.options[j];
- _yuitest_coverline("build/io-form/io-form.js", 63);
+ _yuitest_coverline("build/io-form/io-form.js", 92);
if (o.selected) {
- _yuitest_coverline("build/io-form/io-form.js", 64);
+ _yuitest_coverline("build/io-form/io-form.js", 93);
data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
}
}
}
- _yuitest_coverline("build/io-form/io-form.js", 68);
+ _yuitest_coverline("build/io-form/io-form.js", 97);
break;
case 'radio':
case 'checkbox':
- _yuitest_coverline("build/io-form/io-form.js", 71);
+ _yuitest_coverline("build/io-form/io-form.js", 100);
if (e.checked) {
- _yuitest_coverline("build/io-form/io-form.js", 72);
+ _yuitest_coverline("build/io-form/io-form.js", 101);
data[item++] = n + v;
}
- _yuitest_coverline("build/io-form/io-form.js", 74);
+ _yuitest_coverline("build/io-form/io-form.js", 103);
break;
case 'file':
// stub case as XMLHttpRequest will only send the file path as a string.
@@ -144,17 +180,24 @@ break;
// stub case for input type reset button.
case 'button':
// stub case for input type button elements.
- _yuitest_coverline("build/io-form/io-form.js", 83);
+ _yuitest_coverline("build/io-form/io-form.js", 112);
break;
case 'submit':
default:
- _yuitest_coverline("build/io-form/io-form.js", 86);
+ _yuitest_coverline("build/io-form/io-form.js", 115);
data[item++] = n + v;
}
}
}
- _yuitest_coverline("build/io-form/io-form.js", 90);
-return s ? data.join('&') + "&" + s : data.join('&');
+
+ _yuitest_coverline("build/io-form/io-form.js", 120);
+if (s) {
+ _yuitest_coverline("build/io-form/io-form.js", 121);
+data[item++] = s;
+ }
+
+ _yuitest_coverline("build/io-form/io-form.js", 124);
+return data.join('&');
}
}, true);
View
52 build/io-form/io-form-debug.js
@@ -10,6 +10,30 @@ YUI.add('io-form', function (Y, NAME) {
var eUC = encodeURIComponent;
+/**
+ * Method to enumerate through an HTML form's elements collection
+ * and return a string comprised of key-value pairs.
+ *
+ * @method serialize
+ * @static
+ * @param {Node|String} form YUI form node or HTML form id
+ * @param {Object} [options] Configuration options.
+ * @param {Boolean} [options.useDisabled=false] Whether to include disabled fields.
+ * @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs.
+ * @return {String}
+ */
+Y.IO.stringify = function(form, options) {
+ options = options || {};
+
+ var s = Y.IO.prototype._serialize({
+ id: form,
+ useDisabled: options.useDisabled
+ },
+ options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);
+
+ return s;
+};
+
Y.mix(Y.IO.prototype, {
/**
* Method to enumerate through an HTML form's elements collection
@@ -17,9 +41,10 @@ Y.mix(Y.IO.prototype, {
*
* @method _serialize
* @private
- * @static
- * @param {Object} c - YUI form node or HTML form id.
- * @param {String} s - Key-value data defined in the configuration object.
+ * @param {Object} c
+ * @param {String|Element} c.id YUI form node or HTML form id
+ * @param {Boolean} c.useDisabled `true` to include disabled fields
+ * @param {String} s Key-value data defined in the configuration object.
* @return {String}
*/
_serialize: function(c, s) {
@@ -29,12 +54,16 @@ Y.mix(Y.IO.prototype, {
id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
e, f, n, v, d, i, il, j, jl, o;
- if (!id) {
- id = Y.guid('io:');
- c.id.setAttribute('id', id);
- }
+ if (!id) {
+ id = Y.guid('io:');
+ c.id.setAttribute('id', id);
+ }
- f = Y.config.doc.getElementById(id);
+ f = Y.config.doc.getElementById(id);
+
+ if (!f || !f.elements) {
+ return s || '';
+ }
// Iterate over the form elements collection to construct the
// label-value pairs.
@@ -87,8 +116,13 @@ Y.mix(Y.IO.prototype, {
}
}
}
+
+ if (s) {
+ data[item++] = s;
+ }
+
Y.log('HTML form serialized. The value is: ' + data.join('&'), 'info', 'io');
- return s ? data.join('&') + "&" + s : data.join('&');
+ return data.join('&');
}
}, true);
View
2  build/io-form/io-form-min.js
@@ -1 +1 @@
-YUI.add("io-form",function(e,t){var n=encodeURIComponent;e.mix(e.IO.prototype,{_serialize:function(t,r){var i=[],s=t.useDisabled||!1,o=0,u=typeof t.id=="string"?t.id:t.id.getAttribute("id"),a,f,l,c,h,p,d,v,m,g;u||(u=e.guid("io:"),t.id.setAttribute("id",u)),f=e.config.doc.getElementById(u);for(p=0,d=f.elements.length;p<d;++p){a=f.elements[p],h=a.disabled,l=a.name;if(s?l:l&&!h){l=n(l)+"=",c=n(a.value);switch(a.type){case"select-one":a.selectedIndex>-1&&(g=a.options[a.selectedIndex],i[o++]=l+n(g.attributes.value&&g.attributes.value.specified?g.value:g.text));break;case"select-multiple":if(a.selectedIndex>-1)for(v=a.selectedIndex,m=a.options.length;v<m;++v)g=a.options[v],g.selected&&(i[o++]=l+n(g.attributes.value&&g.attributes.value.specified?g.value:g.text));break;case"radio":case"checkbox":a.checked&&(i[o++]=l+c);break;case"file":case undefined:case"reset":case"button":break;case"submit":default:i[o++]=l+c}}}return r?i.join("&")+"&"+r:i.join("&")}},!0)},"@VERSION@",{requires:["io-base","node-base"]});
+YUI.add("io-form",function(e,t){var n=encodeURIComponent;e.IO.stringify=function(t,n){n=n||{};var r=e.IO.prototype._serialize({id:t,useDisabled:n.useDisabled},n.extra&&typeof n.extra=="object"?e.QueryString.stringify(n.extra):n.extra);return r},e.mix(e.IO.prototype,{_serialize:function(t,r){var i=[],s=t.useDisabled||!1,o=0,u=typeof t.id=="string"?t.id:t.id.getAttribute("id"),a,f,l,c,h,p,d,v,m,g;u||(u=e.guid("io:"),t.id.setAttribute("id",u)),f=e.config.doc.getElementById(u);if(!f||!f.elements)return r||"";for(p=0,d=f.elements.length;p<d;++p){a=f.elements[p],h=a.disabled,l=a.name;if(s?l:l&&!h){l=n(l)+"=",c=n(a.value);switch(a.type){case"select-one":a.selectedIndex>-1&&(g=a.options[a.selectedIndex],i[o++]=l+n(g.attributes.value&&g.attributes.value.specified?g.value:g.text));break;case"select-multiple":if(a.selectedIndex>-1)for(v=a.selectedIndex,m=a.options.length;v<m;++v)g=a.options[v],g.selected&&(i[o++]=l+n(g.attributes.value&&g.attributes.value.specified?g.value:g.text));break;case"radio":case"checkbox":a.checked&&(i[o++]=l+c);break;case"file":case undefined:case"reset":case"button":break;case"submit":default:i[o++]=l+c}}}return r&&(i[o++]=r),i.join("&")}},!0)},"@VERSION@",{requires:["io-base","node-base"]});
View
52 build/io-form/io-form.js
@@ -10,6 +10,30 @@ YUI.add('io-form', function (Y, NAME) {
var eUC = encodeURIComponent;
+/**
+ * Method to enumerate through an HTML form's elements collection
+ * and return a string comprised of key-value pairs.
+ *
+ * @method serialize
+ * @static
+ * @param {Node|String} form YUI form node or HTML form id
+ * @param {Object} [options] Configuration options.
+ * @param {Boolean} [options.useDisabled=false] Whether to include disabled fields.
+ * @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs.
+ * @return {String}
+ */
+Y.IO.stringify = function(form, options) {
+ options = options || {};
+
+ var s = Y.IO.prototype._serialize({
+ id: form,
+ useDisabled: options.useDisabled
+ },
+ options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);
+
+ return s;
+};
+
Y.mix(Y.IO.prototype, {
/**
* Method to enumerate through an HTML form's elements collection
@@ -17,9 +41,10 @@ Y.mix(Y.IO.prototype, {
*
* @method _serialize
* @private
- * @static
- * @param {Object} c - YUI form node or HTML form id.
- * @param {String} s - Key-value data defined in the configuration object.
+ * @param {Object} c
+ * @param {String|Element} c.id YUI form node or HTML form id
+ * @param {Boolean} c.useDisabled `true` to include disabled fields
+ * @param {String} s Key-value data defined in the configuration object.
* @return {String}
*/
_serialize: function(c, s) {
@@ -29,12 +54,16 @@ Y.mix(Y.IO.prototype, {
id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
e, f, n, v, d, i, il, j, jl, o;
- if (!id) {
- id = Y.guid('io:');
- c.id.setAttribute('id', id);
- }
+ if (!id) {
+ id = Y.guid('io:');
+ c.id.setAttribute('id', id);
+ }
- f = Y.config.doc.getElementById(id);
+ f = Y.config.doc.getElementById(id);
+
+ if (!f || !f.elements) {
+ return s || '';
+ }
// Iterate over the form elements collection to construct the
// label-value pairs.
@@ -87,7 +116,12 @@ Y.mix(Y.IO.prototype, {
}
}
}
- return s ? data.join('&') + "&" + s : data.join('&');
+
+ if (s) {
+ data[item++] = s;
+ }
+
+ return data.join('&');
}
}, true);
View
2  src/color/docs/index.mustache
@@ -54,7 +54,7 @@ Y.Color.toArray('rgba(255, 0, 0, 1)'); // [255, 0, 0, 1]
<pre class="code prettyprint">
Y.Color.fromArray(['ff', '00', '00'], Y.Color.TYPES.HEX); // #ff0000
Y.Color.fromArray([255, 0, 0], Y.Color.TYPES.RGB); // rgb(255, 0, 0)
-Y.Color.fromArray([255, 0, 0, 1], Y.Color.TYPES.RGBA); // rgb(255, 0, 0, 1)
+Y.Color.fromArray([255, 0, 0, 1], Y.Color.TYPES.RGBA); // rgba(255, 0, 0, 1)
</pre>
<h2 id="hsl">HSL Color</h2>
View
10 src/io/HISTORY.md
@@ -1,10 +1,18 @@
IO Utility Change History
=========================
+@VERSION@
+-----
+
+* Exposed IO's form serialize via the new `Y.IO.stringify()` method.
+ [Ticket #2529073] [Pull Request #351] [John Lindal]
+
+
3.8.0
-----
- * No changes.
+* No changes.
+
3.7.3
-----
View
52 src/io/js/io-form.js
@@ -8,6 +8,30 @@
var eUC = encodeURIComponent;
+/**
+ * Method to enumerate through an HTML form's elements collection
+ * and return a string comprised of key-value pairs.
+ *
+ * @method serialize
+ * @static
+ * @param {Node|String} form YUI form node or HTML form id
+ * @param {Object} [options] Configuration options.
+ * @param {Boolean} [options.useDisabled=false] Whether to include disabled fields.
+ * @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs.
+ * @return {String}
+ */
+Y.IO.stringify = function(form, options) {
+ options = options || {};
+
+ var s = Y.IO.prototype._serialize({
+ id: form,
+ useDisabled: options.useDisabled
+ },
+ options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);
+
+ return s;
+};
+
Y.mix(Y.IO.prototype, {
/**
* Method to enumerate through an HTML form's elements collection
@@ -15,9 +39,10 @@ Y.mix(Y.IO.prototype, {
*
* @method _serialize
* @private
- * @static
- * @param {Object} c - YUI form node or HTML form id.
- * @param {String} s - Key-value data defined in the configuration object.
+ * @param {Object} c
+ * @param {String|Element} c.id YUI form node or HTML form id
+ * @param {Boolean} c.useDisabled `true` to include disabled fields
+ * @param {String} s Key-value data defined in the configuration object.
* @return {String}
*/
_serialize: function(c, s) {
@@ -27,12 +52,16 @@ Y.mix(Y.IO.prototype, {
id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
e, f, n, v, d, i, il, j, jl, o;
- if (!id) {
- id = Y.guid('io:');
- c.id.setAttribute('id', id);
- }
+ if (!id) {
+ id = Y.guid('io:');
+ c.id.setAttribute('id', id);
+ }
- f = Y.config.doc.getElementById(id);
+ f = Y.config.doc.getElementById(id);
+
+ if (!f || !f.elements) {
+ return s || '';
+ }
// Iterate over the form elements collection to construct the
// label-value pairs.
@@ -85,7 +114,12 @@ Y.mix(Y.IO.prototype, {
}
}
}
+
+ if (s) {
+ data[item++] = s;
+ }
+
Y.log('HTML form serialized. The value is: ' + data.join('&'), 'info', 'io');
- return s ? data.join('&') + "&" + s : data.join('&');
+ return data.join('&');
}
}, true);
View
15 src/io/tests/unit/index.html
@@ -7,6 +7,21 @@
<div id="log"></div>
+<form id="test-form" action="" method="POST">
+ <input name="name" value="eric" type="text" />
+ <input name="age" value="27" type="text" />
+ <input name="username" value="ericf" type="text" disabled="disabled" />
+ <input name="secret" value="p@55w0rd" type="hidden" />
+ <input name="save" value="Save" type="submit" />
+</form>
+
+<form id="disabled-form" action="" method="POST">
+ <input name="username" value="ericf" type="text" disabled="disabled" />
+</form>
+
+<form id="empty-form" action="" method="POST">
+</form>
+
<script type="text/javascript" src="../../../../build/yui/yui.js"></script>
<script type="text/javascript" src="modules.js"></script>
<script type="text/javascript" src="urls.js"></script>
View
61 src/io/tests/unit/js/serialize-tests.js
@@ -0,0 +1,61 @@
+YUI.add('serialize-tests', function (Y) {
+
+ var suite = new Y.Test.Suite('IO Serialize Tests'),
+ form = Y.one('#test-form').remove();
+
+ suite.add(new Y.Test.Case({
+ name: 'Form Serialization',
+
+ setUp: function () {
+ this.form = form.cloneNode(true).appendTo('body');
+ },
+
+ tearDown: function () {
+ this.form.remove();
+ delete this.form;
+ },
+
+ 'stringify should serialize the form': function () {
+ var postBody = Y.IO.stringify(this.form);
+ Y.Assert.areSame('name=eric&age=27&secret=p%4055w0rd&save=Save', postBody);
+ },
+
+ 'stringify should serialize the form by id': function () {
+ var postBody = Y.IO.stringify('test-form');
+ Y.Assert.areSame('name=eric&age=27&secret=p%4055w0rd&save=Save', postBody);
+ },
+
+ 'stringify with `useDisabled` should serialize the form including disabled fields': function () {
+ var postBody = Y.IO.stringify(this.form, {useDisabled: true});
+ Y.Assert.areSame('name=eric&age=27&username=ericf&secret=p%4055w0rd&save=Save', postBody);
+ },
+
+ 'stringify should serialize the form plus string data': function () {
+ var postBody = Y.IO.stringify(this.form, {extra: 'foo=bar'});
+ Y.Assert.areSame('name=eric&age=27&secret=p%4055w0rd&save=Save&foo=bar', postBody);
+ },
+
+ 'stringify should serialize the form plus object data': function () {
+ var postBody = Y.IO.stringify(this.form, {extra: {foo:'bar'}});
+ Y.Assert.areSame('name=eric&age=27&secret=p%4055w0rd&save=Save&foo=bar', postBody);
+ },
+
+ 'stringify should serialize empty form': function () {
+ var postBody = Y.IO.stringify('empty-form');
+ Y.Assert.areSame('', postBody);
+ },
+
+ 'stringify should serialize empty form plus data': function () {
+ var postBody = Y.IO.stringify('empty-form', {extra: 'foo=bar'});
+ Y.Assert.areSame('foo=bar', postBody);
+ },
+
+ 'stringify should serialize disabled form': function () {
+ var postBody = Y.IO.stringify('disabled-form');
+ Y.Assert.areSame('', postBody);
+ }
+ }));
+
+ Y.Test.Runner.add(suite);
+
+});
View
4 src/io/tests/unit/modules.js
@@ -34,6 +34,10 @@ var testModules = {
"transport-tests": {
"fullpath": "./js/transport-tests.js",
"requires": ["io-xdr", "test"]
+ },
+ "serialize-tests": {
+ "fullpath": "./js/serialize-tests.js",
+ "requires": ["io-form", "test"]
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.