source: other-projects/nz-flag-design/trunk/design-2d/Original editor.method.ac/method-draw/extensions/imagelib/index.html@ 29468

Last change on this file since 29468 was 29468, checked in by sjs49, 9 years ago

Initial commit for editor.method.ac for flag design

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1<!doctype html>
2<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
3
4
5<body>
6
7<h1>Select an image:</h1>
8<a href="smiley.svg">smiley.svg</a>
9<br>
10<a href="../../images/logo.png">logo.png</a>
11</body>
12
13<script>
14
15$('a').click(function() {
16 var href = this.href;
17 var target = window.parent;
18 // Convert Non-SVG images to data URL first
19 // (this could also have been done server-side by the library)
20 if(this.href.indexOf('.svg') === -1) {
21
22 var meta_str = JSON.stringify({
23 name: $(this).text(),
24 id: href
25 });
26 target.postMessage(meta_str, "*");
27
28 var img = new Image();
29 img.onload = function() {
30 var canvas = document.createElement("canvas");
31 canvas.width = this.width;
32 canvas.height = this.height;
33 // load the raster image into the canvas
34 canvas.getContext("2d").drawImage(this,0,0);
35 // retrieve the data: URL
36 try {
37 var dataurl = canvas.toDataURL();
38 } catch(err) {
39 // This fails in Firefox with file:// URLs :(
40 alert("Data URL conversion failed: " + err);
41 var dataurl = "";
42 }
43 target.postMessage('|' + href + '|' + dataurl, "*");
44 }
45 img.src = href;
46 } else {
47 // Send metadata (also indicates file is about to be sent)
48 var meta_str = JSON.stringify({
49 name: $(this).text(),
50 id: href
51 });
52 target.postMessage(meta_str, "*");
53 // Do ajax request for image's href value
54 $.get(href, function(data) {
55 data = '|' + href + '|' + data;
56 // This is where the magic happens!
57 target.postMessage(data, "*");
58
59 }, 'html'); // 'html' is necessary to keep returned data as a string
60 }
61 return false;
62});
63
64</script>
Note: See TracBrowser for help on using the repository browser.