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

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

HTML changes needed to support reordering of stages/panels, and rewriting of aspect ratio panel so it can be dynamically sized/resized

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