source: other-projects/nz-flag-design/trunk/main-form/iterative-design.html@ 29773

Last change on this file since 29773 was 29773, checked in by davidb, 9 years ago

Changes so i) the choose-palette is a single interactive SVG csurface; 2) the JS runs more smoothly when 'started' at one of the later pages; and 3) changes to remove many of the warnings browsers produce when loading the page

  • Property svn:executable set to *
File size: 12.7 KB
Line 
1<!DOCTYPE html>
2<html id="story">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5 <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
7 <!-- jQuery -->
8 <script src="lib/jquery-1.11.1.min.js"></script>
9
10 <title>Iterative Design</title>
11 </head>
12
13 <body>
14 <div data-role="page" id="iterative-design-page"
15 class="demo-page"
16 data-dom-cache="true"
17 data-prev="choose-palette">
18
19 <div data-role="content">
20 <div data-role="controlgroup" class="control" data-mini="true">
21 <a href="#" class="next right-button test-fwd" style="right:1%;"></a>
22 <a href="#" class="prev left-button idea-back" style="left:1%;"></a>
23 </div>
24
25 <div class="story-page">
26
27 <!-- put custom content here -->
28 <span class="left story-icon research" ></span>
29 <h2 id="iterative-design-header">Iterative Design</h2>
30
31 <div>
32 <div id="side-by-side">
33 <ol>
34
35 <li>
36 <h2><span>2D Design</span></h2>
37 <div id="design-2d-div" >
38 <iframe style="width: 100%; height: 100%"
39 id="design-2d-iframe" ></iframe>
40 </div>
41 </li>
42
43 <li>
44 <h2><span title="Click to Open/Close">Flag Similarity</span></h2>
45
46 <div id="similarity-2d-div">
47 <iframe src="../similarity-2d/display-flags.jsp"
48 style="width: 100%; height: 100%"
49 id="similarity-2d-iframe" ></iframe>
50 </div>
51 </li>
52 <li>
53 <h2><span title="Click to Open/Close">Render 3D</span></h2>
54 <div id="render-3d-div">
55 <iframe src="../render-3d/flag.html"
56 style="width: 100%; height: 100%; overflow: hidden;"
57 id="render-3d-iframe" ></iframe>
58 </div>
59 </li>
60
61 </ol>
62 </div>
63 </div>
64
65 <!-- end of putting custom content -->
66
67 </div> <!-- end story-page-->
68 </div><!-- /content -->
69
70 <script>
71 var activatedAccordion = false;
72 var activatedSVGEditorFrame = false;
73
74 function savePNGAsFile(imgType, quality) {
75 var design_frame = document.getElementById('design-2d-iframe');
76 var svgCanvas = design_frame.contentWindow.svgCanvas;
77 var svgedit = design_frame.contentWindow.svgedit;
78
79 var mimeType = 'image/' + imgType.toLowerCase();
80 var svg_str = svgCanvas.svgCanvasToString();
81
82 var type = imgType || 'PNG';
83 if (!$('#export_canvas').length) {
84 $('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');
85 }
86 var c = $('#export_canvas')[0];
87 c.width = svgCanvas.contentW;
88 c.height = svgCanvas.contentH;
89
90 canvg(c, svg_str, {renderCallback: function() {
91 var dataURLType = (type === 'ICO' ? 'BMP' : type).toLowerCase();
92 var datauri = quality ? c.toDataURL('image/' + dataURLType, quality) : c.toDataURL('image/' + dataURLType);
93
94 // Look up jsession id; if not present fall back to use a timestamp
95 //var jsession_id = $.cookie('JSESSIONID') || new Date().getTime();
96 var jsession_id = $.cookie('JSESSIONID') + "-" + new Date().getTime();
97 console.log("jsession id = " + jsession_id);
98 var imageFilename = "flag-" + jsession_id + ".png";
99
100 $.ajax({
101 type: "POST",
102 url: "../design-2d/image-data-to-file.jsp",
103 data: { imageData: datauri, imageFilename: imageFilename },
104 success: function() {
105 console.log("Exported PNG data to file ");
106 var render_frame = document.getElementById('render-3d-iframe');
107 // trigger a reload in the 3D Flag Renderer
108 render_frame.contentWindow.createFlag(imageFilename);
109 }
110 });
111 }});
112 }
113
114 function exportPNG() {
115 var design_frame = document.getElementById('design-2d-iframe')
116 var str = design_frame.contentWindow.svgEditor.uiStrings.notification.loadingImage;
117
118 var exportWindow = window.open(
119 'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'),
120 'svg-edit-exportWindow'
121 );
122
123 design_frame.contentWindow.svgCanvas.rasterExport("PNG", null, exportWindow.name);
124 }
125
126 function reconfigureSvgCanvas(settings) {
127 console.log("*** entered reconfigureSvgCanvas");
128 console.log("*** settings: background=" + settings.backgroundColor);
129 console.log("*** settings: w x h = " + settings.width + " x " + settings.height);
130
131 var design_frame = document.getElementById('design-2d-iframe');
132 var svgCanvas = design_frame.contentWindow.svgCanvas;
133 var svgedit = design_frame.contentWindow.svgedit;
134
135 // Set the new canvas size
136 svgCanvas.setResolution(settings.width, settings.height);
137
138 var widthVar = settings.width;
139 var heightVar = settings.height;
140
141 var canvasWidth = svgCanvas.getResolution().w;
142 var canvasHeight = svgCanvas.getResolution().h;
143
144 var userBackground = settings.backgroundColor;
145
146 // decide if this is the first time we're looking to set the background colour
147 // or not. If it is, then use svgCanvas API to create a suitable layer
148
149 var backRectSvg = svgCanvas.getElem('backgroundRectangle');
150
151 if (backRectSvg == null) {
152 svgCanvas.createLayer("background");
153
154 svgCanvas.addSvgElementFromJson({
155 "element": "rect",
156 "attr": {
157 "id": "backgroundRectangle",
158 "width": canvasWidth,
159 "height": canvasHeight,
160 "x": "0",
161 "y": "0",
162 "fill": userBackground,
163 "opacity": "1.0",
164 "stroke-opacity": "0",
165 "stroke-linecap": "null",
166 "stroke-linejoin": "null",
167 "stroke-dasharray": "null",
168 "stroke-width": "5",
169 "stroke": "#000000"
170 },
171 "curStyles": true
172 });
173 svgCanvas.setCurrentLayerPosition(0);
174
175 // Refresh the canvas layers
176 svgCanvas.identifyLayers();
177 }
178 else {
179 console.log("Background to flag already exists -- changing colour to: " + userBackground);
180 backRectSvg.setAttributeNS(null,"fill",userBackground);
181 // find out how to change width and height directly also?
182
183 console.log("Setting background width and height to: " + widthVar + " and " + heightVar);
184
185 backRectSvg.setAttributeNS(null,"width",canvasWidth);
186 backRectSvg.setAttributeNS(null,"height",canvasHeight);
187
188 //svgCanvas.setResolution(backgroundWidth, backgroundHeight);
189 }
190 // Centres the canvas (somewhat)
191 //svgCanvas.updateCanvas(100, 100);
192
193 }
194
195
196 function activateAccordion() {
197 console.log("activateAccordion()");
198
199 var la_x_dim = $(window).width() * 0.70;
200 var la_y_dim = $(window).height() * 0.67;
201
202 $('#side-by-side').show(10,
203 function() {
204 $('#side-by-side')
205 .liteAccordion({ theme : 'stitch', // 'light',
206 rounded : true,
207 //responsive : true,
208 containerWidth : la_x_dim,
209 containerHeight : la_y_dim,
210 onTriggerSlide : function() {
211 console.log("onTriggerSlide: this = " + this);
212 console.log("onTriggerSlide: id = " + this[0].id);
213 if (this[0].id == "render-3d-div") {
214 console.log("Triggering SVG-Editor exportPNG()");
215 savePNGAsFile("PNG",null);
216 }
217 }
218 });
219 });
220 }
221
222 function activateSVGEditor() {
223 console.log("activateSVGEditor()");
224 $('#design-2d-iframe').attr("src","svg-edit-trunk2/editor/svg-editor.html?noStorageOnLoad=1");
225 $('#design-2d-iframe').load(function() {
226 console.log("*** loaded sgv iframe: " + this);
227
228 var design_frame = document.getElementById('design-2d-iframe');
229 var svgCanvas = design_frame.contentWindow.svgCanvas;
230
231 console.log("*** svgCanvas should now be initialised: " + svgCanvas);
232 //don't load the previous drawing!
233 reconfigureSvgCanvas(flagCanvasSettings);
234 });
235 }
236
237 $(document).on("pageload",function(event,data){
238 console.log( "Iterative Design Page: jquerymobile pageload()");
239 if (!activatedAccordion) {
240 activateAccordion();
241 activatedAccordion = true;
242 }
243 });
244
245 $(window).resize(function() {
246 var la_x_dim = $(window).width() * 0.70;
247 var la_y_dim = $(window).height() * 0.67;
248
249 $('#side-by-side')
250 .liteAccordion('resize', {
251 containerWidth : la_x_dim,
252 containerHeight : la_y_dim
253 });
254
255 });
256
257 $(document).on("pagebeforeshow",function(event,data) {
258 var active_page = $.mobile.activePage.attr("id");
259 console.log("Iterative-Design fielding Event: pagebeforeshow() for page " + active_page);
260
261 if (active_page == "iterative-design-page") {
262 if (!activatedSVGEditorFrame) {
263 activateSVGEditor();
264 activatedSVGEditorFrame = true;
265 }
266 else {
267 reconfigureSvgCanvas(flagCanvasSettings);
268 }
269 }
270 });
271 </script>
272
273 </div><!-- /page -->
274 </body>
275</html>
Note: See TracBrowser for help on using the repository browser.