-
-
Save thingsinjars/1460798 to your computer and use it in GitHub Desktop.
Detect Doctype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function( | |
a,b // Placeholders | |
){ | |
with(document.doctype) // To save referencing it each time | |
return '<!DOCTYPE ' // Making an assumption that the doctype starts with this. | |
+ name // Usually 'html' | |
+ ((b=publicId,a=systemId) // Shorthand references, return value is systemId so we can test if there is a system definition | |
? // Then | |
(b // If this is a public standard | |
? // Then | |
' PUBLIC "'+b+'" ' // Write the type as "PUBLIC" and the ID | |
: // Else | |
' SYSTEM ' // Write the type as "SYSTEM" | |
) | |
+ '"'+a+'"' // Add on the system ID | |
: // Else | |
'' // Write nothing | |
) | |
+'>' // ...and done. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(a,b){with(document.doctype)return'<!DOCTYPE '+name+((b=publicId,a=systemId)?(b?' PUBLIC "'+b+'" ':' SYSTEM ')+'"'+a+'"':'')+'>'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Simon Madine <http://thingsinjars.com> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Detect Doctype", | |
"description": "Returns the doctype of the current page", | |
"keywords": [ | |
"html", | |
"doctype" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>Foo</title> | |
<div>Expected value: <b><!DOCTYPE html></b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
var myFunction = function(a,b){with(document.doctype)return'<!DOCTYPE '+name+((b=publicId,a=systemId)?(b?' PUBLIC "'+b+'" ':' SYSTEM ')+'"'+a+'"':'')+'>'} | |
document.getElementById( "ret" ).innerHTML = new Option(myFunction()).innerHTML //Borrowed from @jed's escapeHTML (https://gist.github.com/964847) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course. Before the reshuffle, there was nothing to be gained from shortening the variables but it makes sense now. I've updated and expanded in the annotated version.
As for the more general question of 'does this need to be wrapped in a function', I'm interested to know what others think. Keeping with the rules, yes; Keeping with the spirit, not necessarily.