Skip to content
Browse files

Clean up ajax.serialize

  • Loading branch information...
1 parent a37869b commit 9538f8778780bfac6636ebfc87442676991b56d6 @seven1m committed Dec 21, 2008
Showing with 4 additions and 4 deletions.
  1. +1 −1 pkg/ajax.js
  2. +1 −2 src/ajax.js
  3. +1 −1 test/public/js/ajax.js
  4. +1 −0 test/tests/ajax_test.rb
View
2 pkg/ajax.js
@@ -2,7 +2,7 @@ if(!window.mini)mini={};if(!mini.form)mini.form={};if(!mini.ajax)mini.ajax={};
if(!window.$)$=function(e){if(typeof e=='string')e=document.getElementById(e);return e}
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n}
mini.ajax.bustcache='nocache';
-mini.form.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return null};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&')}
+mini.form.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value)};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&')}
mini.ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}}
mini.ajax.send=function(u,f,m,a){var x=mini.ajax.x();if(mini.ajax.bustcache){var c=mini.ajax.bustcache+'='+new Date().getTime();if(m=='GET')u+=u.indexOf('?')==-1?'?':'&'+c;else if(a&&a!='')a+='&'+c;else a=c};x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)}
mini.ajax.get=function(url,func){mini.ajax.send(url,func,'GET')}
View
3 src/ajax.js
@@ -27,8 +27,7 @@ mini.form.serialize=function(f){
return f.getElementsByTagName(n)
};
var nv=function(e){
- if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);
- else return null
+ if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value)
};
var i=collect(
g('input'),
View
2 test/public/js/ajax.js
@@ -2,7 +2,7 @@ if(!window.mini)mini={};if(!mini.form)mini.form={};if(!mini.ajax)mini.ajax={};
if(!window.$)$=function(e){if(typeof e=='string')e=document.getElementById(e);return e}
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n}
mini.ajax.bustcache='nocache';
-mini.form.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return null};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&')}
+mini.form.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value)};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&')}
mini.ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}}
mini.ajax.send=function(u,f,m,a){var x=mini.ajax.x();if(mini.ajax.bustcache){var c=mini.ajax.bustcache+'='+new Date().getTime();if(m=='GET')u+=u.indexOf('?')==-1?'?':'&'+c;else if(a&&a!='')a+='&'+c;else a=c};x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)}
mini.ajax.get=function(url,func){mini.ajax.send(url,func,'GET')}
View
1 test/tests/ajax_test.rb
@@ -33,6 +33,7 @@ def test_serialize
assert_no_match /radio_input=value 1/, unescaped
assert_match /select_input=value 1/, unescaped
assert_no_match /select_input=value 2/, unescaped
+ assert_no_match /test serialize/, unescaped
assert_match /textarea_input=here is some text\s*with\s*a line break or two/, unescaped
end

0 comments on commit 9538f87

Please sign in to comment.
Something went wrong with that request. Please try again.