Created
April 3, 2017 03:38
-
-
Save iacchus/9c25a370dd533e523348d1b6fa535697 to your computer and use it in GitHub Desktop.
Embed abcjs in vanilla forums pre elements if they are ABC
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
<script src="https://rawgit.com/paulrosen/abcjs/master/bin/abcjs_plugin_3.1.1-min.js"></script> | |
<script> | |
abcjs_plugin_autostart = false; | |
window.ABCJS.plugin.auto_render = false; | |
ABCJS.plugin.hide_abc = true; | |
ABCJS.plugin.render_options = { | |
scale: 1, | |
staffwidth:700, | |
paddingtop: 0, | |
paddingbottom: 0, | |
paddingright: 0, | |
paddingleft: 0, | |
} | |
$(document).ready(function(){ | |
function is_it_abc(elem) { | |
if(window.ABCJS.plugin.getABCContainingElements(elem).length) return true; | |
else return false; | |
} | |
if($("pre").length) | |
{ | |
var tunes_code = $("pre"); | |
for(var $i=0; tunes_code[$i]; $i++) | |
{ | |
if(! is_it_abc($(tunes_code[$i]))) continue; | |
var ws_strip=""; | |
var mystr=""; | |
ws_strip = $(tunes_code[$i]).text().split('\n'); | |
for(var aaa=0; ws_strip[aaa]; aaa++) { mystr+=ws_strip[aaa].trim() + "\n"; } | |
$(tunes_code[$i]).text("%%staffsep 27pt\n"+mystr), //abctune | |
$('<div id="abctune-' + $i + '" class="abctune-rendered"></div>').insertBefore(tunes_code[$i]); | |
ABCJS.renderAbc( | |
"abctune-"+$i, //container | |
$(tunes_code[$i]).text(), //abctune | |
{}, //parserParams | |
{ staffwidth: 620 }, //engraverParams | |
{ viewportHorizontal: true } //renderParams | |
); | |
$(tunes_code[$i]).hide(); | |
} | |
} | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment