Skip to content

Instantly share code, notes, and snippets.

@satyr
Created December 6, 2009 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satyr/250170 to your computer and use it in GitHub Desktop.
Save satyr/250170 to your computer and use it in GitHub Desktop.
HTMLValidator for Jetpack
// (C) http://sites.google.com/site/kanasanjs/jetpack_work_shop#nanto_vi&satyr
// License: Creative Commons <http://creativecommons.org/licenses/by/3.0/>
var manifest = { settings: [
{name: 'auto', type: 'boolean', label: 'Auto Validation', default: true},
]},
gLogo = ''+ <a id="logo" href="/"/>.appendChild(
<img src="http://www.w3.org/2008/site/images/favicon.ico"/>),
gCache = {};
jetpack.future.import('storage.settings');
jetpack.statusBar.append({
html: ''+ <head><{'style'}><![CDATA[
body {line-height:1.8; font-family:monospace}
a {text-decoration:none} img {border:none}
#validity {cursor:pointer}
]]></{'style'}><{'base' // workaround for Jetpack Gallery stupidness
} href="http://validator.w3.org/" target="_blank"/></head>,
onReady: function hv_onStatusBarReady(widget){
$(widget).click(function hv_onStatusBarClick(){
var {url} = jetpack.tabs.focused, x = gCache[url];
if(!x || x === '\u2026') return;
jetpack.tabs.open('data:text/html;charset=utf-8,'+ encodeURI(
(<><head><{'title'}>Validation for {url}</{'title'}></head
><p>doctype: {$('m\\:doctype', x).text()}</p
><p>error count: {$('m\\:errorcount', x).text()}</p></>) +
'<dl>'+ $('m\\:error', x).map(function hv_error()(
(<dt>{('Line '+ $('m\\:line', this).text() +
', Column '+ $('m\\:col', this).text())}:
<strong>{$('m\\:message', this).text()}</strong></dt>) +
('<dd><pre>'+ $('m\\:source', this).text() +'</pre>'+
$('m\\:explanation', this).text() +'</dd>')
)).get().join('<br/>') +'</dl>'));
}).find('body').html(gLogo);
jetpack.tabs.onFocus(hv_set);
jetpack.tabs.onReady(hv_set);
function hv_set(){ widget.body.innerHTML = hv_body() }
function hv_body(){
var {url} = jetpack.tabs.focused;
if(/^(?!https?:)/.test(url)) return gLogo;
if(!jetpack.storage.settings.auto)
return 'V'.link('/check?uri='+ encodeURIComponent(url)).bold();
var x = gCache[url];
if(x === '\u2026') return x;
if(x) return <b id="validity">{
let(v = $('m\\:validity', x).text())
v === 'true' ? '\u2713' : v ? '\u00d7' : '??'
}</b>.toXMLString();
$.get('http://validator.w3.org/check', {uri: url, output: 'soap12'},
function hv_got(res){ gCache[url] = res; hv_set() }, 'xml');
return gCache[url] = '\u2026';
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment