Popcorn Source Code Plugin
/** | |
* Popcorn SourceCode Plugin v0.1 | |
* http://mattwritescode.com/2011/11/popcorn-source-code-plugin/ | |
* | |
* Copyright 2011 Matthew Loberg (http://mloberg.com) | |
* Licensed under the MIT license | |
* | |
* Description: | |
* Add source code pre/code element to the page. | |
* If Google Code Prettify <http://code.google.com/p/google-code-prettify/> | |
* is available, it will style the code. | |
* | |
* Options: | |
* - Start: time you want the code to display | |
* - End: time you want the code to hide | |
* - Target: the id of the element you want the code to appear in | |
* - Code: the source code to display | |
* - Lang: the source code language (optional) | |
* | |
* Example: | |
var p = Popcorn("#video") | |
.sourceCode({ | |
start: 5, // seconds | |
end: 15, // seconds | |
target: 'codeExample', | |
code: '<?php echo "foo";?>', | |
lang: 'php' | |
}) | |
*/ | |
(function(Popcorn){ | |
Popcorn.plugin("sourceCode", { | |
_setup: function(options){ | |
var target = document.getElementById(options.target), | |
code = options.code.toString().replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); | |
options._container = document.createElement("pre"); | |
options._container.style.display = "none"; | |
options._container.innerHTML = '<code class="prettyprint ' + options.lang + '">' + code + '</code>'; | |
if(!target && Popcorn.plugin.debug){ | |
throw new Error("target container doesn't exist"); | |
} | |
target.appendChild(options._container); | |
}, | |
start: function(event, options){ | |
if(typeof prettyPrint == 'function') prettyPrint(); | |
options._container.style.display = "block"; | |
}, | |
end: function(event, options){ | |
options._container.style.display = "none"; | |
}, | |
_teardown: function(options){ | |
document.getElementById(options.target).removeChild(options._container); | |
} | |
}); | |
})(Popcorn); |
/** | |
* Popcorn SourceCode Plugin v0.1 | |
* http://mattwritescode.com/2011/11/popcorn-source-code-plugin/ | |
* | |
* Copyright 2011 Matthew Loberg (http://mloberg.com) | |
* Licensed under the MIT license | |
*/ | |
(function(x){x.plugin("sourceCode",{_setup:function(a){var b=document.getElementById(a.target),c=a.code.toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");a._container=document.createElement("pre");a._container.style.display="none";a._container.innerHTML='<code class="prettyprint '+a.lang+'">'+c+"</code>";if(!b&&Popcorn.plugin.debug){throw new Error("target container doesn't exist")}b.appendChild(a._container)},start:function(a,b){if(typeof prettyPrint=="function")prettyPrint();b._container.style.display="block"},end:function(a,b){b._container.style.display="none"},_teardown:function(a){document.getElementById(a.target).removeChild(a._container)}})})(Popcorn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment