Change keyboard images SVG to inline SVG. Resolves #14.

This commit is contained in:
Arpad Csanyi
2016-03-17 13:44:43 +01:00
parent 589f2455ed
commit 7be4c27ce5

39
app.js
View File

@@ -102,6 +102,45 @@ $(function() {
}
});
// Based on: http://stackoverflow.com/a/24933495
$('img.uhk').each(function(){
var $img = $(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');
var imgURL = $img.attr('src');
var imgSelector = '.' + imgClass.replace(' ', '.')
$.get(imgURL, function(data) {
// Get the SVG tag, ignore the rest
var $svg = $(data).find('svg');
// Add replaced image's ID to the new SVG
if(typeof imgID !== 'undefined') {
$svg = $svg.attr('id', imgID);
}
// Add replaced image's classes to the new SVG
if(typeof imgClass !== 'undefined') {
$svg = $svg.attr('class', imgClass+' replaced-svg');
}
// Remove any invalid XML tags as per http://validator.w3.org
$svg = $svg.removeAttr('xmlns:a');
// Check if the viewport is set, else we gonna set it if we can.
if(!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) {
$svg.attr('viewBox', '0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width'))
}
// Replace image with new SVG
$img.replaceWith($svg);
$('#left-parts rect, #right-parts rect', imgSelector).on('click', function() {
console.log('hello');
});
}, 'xml');
});
});
function _init(view) {