/*
* @title Show chord diagrams on j-total
* @description マウスオーバーでコード表示
* @include http://music.j-total.net/data/*
* @license MIT License
* @require
*/
(function(){
var chords = document.querySelectorAll('a[href]');
Array.prototype.forEach.call(chords, function(elm){
elm.addEventListener('mouseover', function(){
showchord(elm, elm.href);
}, false);
elm.addEventListener('mouseleave', function(){
setTimeout(function(){
if (elm.hasChildNodes()){
for (var i = 1; i < (elm.childNodes.length); i++) {
elm.removeChild(elm.childNodes[i]);
}
}
}, 1500);
}, false);
});
function showchord(e, c){
var x = new XMLHttpRequest();
var this_chord = c.replace(/.+\/(.*)\.html\'\);$/, '/cd/img/$1.gif');
console.log(this_chord);
x.open('GET', this_chord);
x.responseType = 'blob';
x.onload = function(){
if (this.status == 200){
var blob = this.response;
var img = document.createElement('img');
img.onload = function(){
window.URL.revokeObjectURL(img.src);
};
img.src = window.URL.createObjectURL(blob);
if(e.childNodes.length<2){
e.appendChild(img);
}
}
};
x.send();
}
})();