summaryrefslogtreecommitdiff
path: root/crocoite/data/canvas-snapshot.js
blob: 239541166f6d5333fa518f16d55e7704cd70c181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*	Replace canvas with image snapshot
 */
(function(){
	var canvas = document.querySelectorAll ("canvas"); 
	for (var i = 0; i < canvas.length; i++) { 
		var c = canvas[i];
		var data = c.toDataURL ();
		var parent = c.parentNode;
		var img = document.createElement ('img');
		/* copy all attributes */
		for (var i = 0; i < c.attributes.length; i++) {
			var attr = c.attributes.item(i);
			img.setAttribute (attr.nodeName, attr.nodeValue);
		}
		img.src = data;
		parent.replaceChild (img, c);
	}
}());