Validate xhtml of a site in development with Ajax
I like using http://validator.w3.org to test if my XHTML is valid. But validating when your work is not yet accessible via a web URL is cumbersome: you have to paste the source code in a textarea field and submit it. So I wrote a script that does that for me.
Global namespace updates
Naming my core JavaScript object 'Dom' prooved to be confusing. So I changed the name to 'Mme'. Then I add a very useful function to my object: Mme.create(tagName a, [,attributes b] [,style c] [,document]). It is a wrapper for document.createElement(), but it also sets attributes and styles when necessary.
create:function(a,b,c,d){
var o=(d||document).createElement(a);
Mme.extend(o,b);
Mme.extend(o.style,c);
return o
}
Module Mme.tools
An extension to my 'Dom' object (see previous posts) and it creates a button on the page to post the source to the validator. The returned result is shown in another window.
Mme.tools={
pattern:'#validate',
bind:function(a){
var o=Mme.create('div')
o.appendChild(Mme.create('button',{onclick:Mme.tools.validate,innerHTML:'Validate'}))
a.appendChild(o)
},
validate:function(){
var f=Mme.create('form',{method:'post',enctype:'multipart/form-data',action:'http://validator.w3.org/check',target:'_blank'},{display:'none'})
f.appendChild(Mme.create('textarea',{name:'fragment',value:Mme.request.get(location).responseText}))
document.body.appendChild(f)
f.submit()
}
}
And here's the action:
You can validate the XHTML of pages that are not online with one single click. You only need a connection to the Internet. Doesn't work for files on your filesystem. The page has to be on a local server.
Comments
To add a comment, log in or register as new user. It's free and safe.