source: other-projects/nz-flag-design/trunk/main-form/choose-canvas.html@ 29957

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

External icon now a local resource

  • Property svn:executable set to *
File size: 15.2 KB
Line 
1<!DOCTYPE html>
2<html id="story">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
6 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
7 <meta http-equiv="Pragma" content="no-cache" />
8 <meta http-equiv="Expires" content="0" />
9
10<!--
11 <meta name="viewport" content="width=device-width, initial-scale=1"/>
12-->
13 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
14 <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
15 <meta name="apple-mobile-web-app-capable" content="yes"/>
16
17 <script src="css/source-sans-pro.js"></script>
18 <link href="css/styles.css" rel="stylesheet"/>
19 <link href="css/storystyle.css" rel="stylesheet"/>
20
21 <link rel="stylesheet" href="lib-slider/css/jquery.mobile-1.3.0.css"/>
22
23<!--
24 <link rel="stylesheet" href="lib-slider/css/jquery.mobile-1.3.2.css"/>
25-->
26 <link rel="stylesheet" href="lib-slider/css/jqm-demos.css"/>
27 <link rel="stylesheet" href="lib-slider/css/swipe-page.css"/>
28 <link rel="shortcut icon" href="lib-slider/nzflag-icon64-padded.png"/>
29
30 <!-- jQuery -->
31 <script src="lib/jquery-1.11.1.min.js"></script>
32 <script src="lib/jquery.cookie.js"></script>
33
34 <!-- page swipe -->
35<!--
36 <script src="lib-slider/js/jquery.mobile.demos.js"></script>
37-->
38 <script src="lib-slider/js/jquery.mobile-1.3.0.js"></script>
39<!--
40 <script src="lib-slider/js/jquery.mobile-1.3.2.js"></script>
41-->
42 <script src="lib-slider/js/swipe-page.js"></script>
43
44 <!-- accordion bars -->
45 <link href="css/liteaccordion.css" rel="stylesheet" />
46 <script src="js/jquery.easing.1.3.js"></script>
47 <script src="js/liteaccordion-with-resize.jquery.js"></script>
48
49 <!-- canvg library -->
50 <script type="text/javascript" src="lib/canvg/rgbcolor.js"></script>
51 <script type="text/javascript" src="lib/canvg/StackBlur.js"></script>
52 <script type="text/javascript" src="lib/canvg/canvg.js"></script>
53
54 <!-- spectrum for colour palette -->
55 <!-- For documentation see https://bgrins.github.io/spectrum -->
56 <script src='bgrins-spectrum/spectrum.js'></script>
57 <link rel='stylesheet' href='bgrins-spectrum/spectrum.css' />
58
59 <script src="../similarity-2d/js-lib/Colour.js"></script>
60 <script src="../similarity-2d/flag-processing.js"></script>
61
62 <style>
63 a[href^="http://"]:after,
64 a[href^="https://"]:after {
65 content: url(Icon_External_Link.png);
66 margin: 0 0 0 5px;
67 }
68 </style>
69
70 <script type="text/javascript">
71 // Flag settings - used to initialise the svg canvas to the user's preferences
72
73 var colourPotSwatch = [ "#00247d", "#cc142b", "#ffffff", "#29afaf", "#008000", "#800080", "#ffff15", "#ff6600" ]
74 var numColourPots = colourPotSwatch.length;
75
76
77 var flagCanvasSettings = { width: 800, height: 400,
78 backgroundColor: "#000066",
79 colourPots: colourPotSwatch.slice(0,3),
80 modified: true
81 };
82 var isoCountryCode = null;
83
84
85
86// Variable for the currently selected flag ratio
87var currentRatio = null;
88
89var aspectRatios = null;
90var aspectMaxRatio = 0;
91
92function calcMaxRatio(aspect_ratio_data)
93{
94 // work out the maximum ratio
95 var max_ratio = 0;
96
97 $.each(aspect_ratio_data, function(key, ratio_table) {
98 var ratio_array = key.split(":");
99 var ratio_x = ratio_array[0];
100 var ratio_y = ratio_array[1];
101 var ratio = ratio_y / ratio_x;
102
103 if (ratio > max_ratio) {
104 max_ratio = ratio;
105 }
106 });
107
108 return max_ratio;
109}
110
111function calcCompleteWidth(aspect_ratio_data,scale)
112{
113 // work out the maximum ratio
114 var max_width = 0;
115
116 $.each(aspect_ratio_data, function(key, ratio_table) {
117 var ratio_array = key.split(":");
118 var ratio_x = ratio_array[0];
119 var ratio_y = ratio_array[1];
120 var ratio = ratio_y / ratio_x;
121
122 max_width += (scale*ratio);
123 });
124
125 return max_width;
126}
127
128
129function scaledDivsFitInPage(aspect_ratio_data, scale_to_height, num_of_rows_allowed, la_x_dim)
130{
131 var divs_fit = true;
132
133 var row = 1;
134 var total_row_width = 0;
135 var total_height = 0;
136
137 $.each(aspect_ratio_data, function(key, ratio_table) {
138 var ratio_array = key.split(":");
139 var ratio_x = ratio_array[0];
140 var ratio_y = ratio_array[1];
141 var ratio = ratio_y / ratio_x;
142
143 var scaled_div_width = scale_to_height*ratio;
144 if (total_row_width + scaled_div_width > la_x_dim) {
145 // this div doesn't fit on the current row
146 // => start a new row
147 total_row_width = scaled_div_width;
148 row++;
149
150 if (row>num_of_rows_allowed) {
151 // blow out!
152 divs_fit = false;
153 return false; // jquery.each equivalent to 'break'
154 }
155 }
156 else {
157 total_row_width += scaled_div_width;
158 row++;
159 }
160 });
161
162 return divs_fit;
163}
164
165
166function calcScaleToHeight(aspectRatios,la_x_dim,la_y_dim)
167{
168 // determine scale factor so divs max out (as in, filling in the page) based la_y_dim height,
169
170 var num_of_rows_allowed = 1;
171 var scale_to_height = la_y_dim; // optimized version of true calcuation, la_y_dim / num_of_rows_allowed;
172
173 //var div_width = complete_width_100 * (div_height/100)
174
175 var num_flag_bins = aspectRatios.length;
176
177 while (!scaledDivsFitInPage(aspectRatios,scale_to_height,num_of_rows_allowed,la_x_dim)) {
178
179 num_of_rows_allowed++;
180
181 if (num_of_rows_allowed>num_flag_bins) {
182 // needing more rows than there are flag bins is an indication that things
183 // just don't fit, and so will need to use a scroll bar.
184 // Exiting at this point will naturally achieve this
185 break;
186 }
187
188 scale_to_height = la_y_dim/num_of_rows_allowed;
189
190 // if get to here, then need
191
192 }
193
194 console.log("**** num_of_rows = " + num_of_rows_allowed + ", scale to height = " + scale_to_height);
195 return scale_to_height;
196}
197
198
199$(function() {
200 $.getJSON( "../similarity-2d/flag-aspect-ratios-json.jsp", function(data) {
201
202 aspectRatios = data;
203
204 //var scale_to_y_dim = 130;
205
206 // express scale_to_y_dim to use relative to height of window
207
208 var window_height = $(window).height();
209 var div_top = $('#aspect-ratio-div').offset().top + 20;
210
211 var la_y_dim = (div_top>0) ? window_height - div_top : window_height * 0.6;
212 var la_x_dim = $(window).width() * 0.7;
213
214 //var scale_to_y_dim = la_y_dim/4;
215
216 //console.log("*** scale to y dim = " + la_y_dim);
217
218 //alert("scale_to_y_dim = " + scale_to_y_dim);
219
220
221 aspectMaxRatio = calcMaxRatio(aspectRatios);
222 //var complete_width_100 = calcCompleteWidth(aspectRatios,100); // as if every aspect ratio bin is scaled to 100 pixels high
223
224
225 scale_to_y_dim = calcScaleToHeight(aspectRatios,la_x_dim,la_y_dim);
226
227
228 var items = [];
229
230
231 $.each(data, function(key, ratio_table) {
232 var freq = ratio_table.freq;
233 var ratio_array = key.split(":");
234 var ratio_x = ratio_array[0];
235 var ratio_y = ratio_array[1];
236 var ratio = ratio_y / ratio_x;
237
238 var ratioScale = aspectMaxRatio/ratio;
239
240 var x_dim = Math.round(scale_to_y_dim * ratioScale);
241 var y_dim = scale_to_y_dim;
242
243 var innertext = "<div style='font-size: 180%;'>"+freq + " countries, " + key + "</div>";
244
245 var flags = [];
246
247 var nz_prioritized_flags = ratio_table.flags.sort();
248
249 // Promote NZ flag to start of array, but otherwise keep sorted
250 var p = nz_prioritized_flags.length-1;
251 var found_nz = false;
252
253 while (p>0) {
254 var curr;
255 var curr_title;
256
257 if (!found_nz) {
258 curr = ratio_table.flags[p];
259 curr_title = curr.replace(/^.*\//,"").replace(/\.(.*?)$/,"");
260 }
261
262 if (curr_title == "nz") {
263 found_nz = true;
264
265 // swap with adjacent cell
266 var tmp_m1 = nz_prioritized_flags[p-1];
267 nz_prioritized_flags[p-1] = curr;
268 nz_prioritized_flags[p] = tmp_m1;
269 }
270 p--;
271 }
272
273 $.each(nz_prioritized_flags, function(index, flag_filename) {
274 var title = flag_filename.replace(/^.*\//,"").replace(/\.(.*?)$/,"");
275
276 flags.push("<img src='../similarity-2d/"+flag_filename+"' id='aspect-ratio-"+ title +"' style='height: 70px; padding: 3px; ' title='" + title.toUpperCase() + "'/>");
277 });
278
279 innertext += flags.join("");
280
281 var ratio_id = "ratio-" + key.replace(":","_");
282 if (found_nz) {
283 currentRatio = ratio_id;
284 }
285
286 var id = " id='" + ratio_id + "'";
287
288 var style = "style='width:" + x_dim + "px; height:" + y_dim + "px;";
289 if (found_nz) {
290 style += "border-color:white; border-width:4px;"
291 }
292
293 style += " overflow-y:scroll;";
294 style += "'";
295
296 var onclick = " onclick='updateCanvasDimensions("+ratio_y + "," + ratio_x + ")'";
297
298 items.push( "<div class='ratioDiv'" + id + style + onclick + ">"+ innertext + "</div>" );
299
300 });
301
302 $('#aspect-ratio-div').append("<div class='centredDiv' style='width: 100%'>"+items.join("\n")+"</div>");
303
304
305 // now change the flag tooltip labels into their country names
306 $.getJSON( "../similarity-2d/iso-3166-keyed-by-alpha-2-countrycodes.json", function(data) {
307 isoCountryCodes = data;
308
309 $.each( data, function( iso2_key, country_name ) {
310 var $img = $('#aspect-ratio-'+iso2_key.toLowerCase());
311 var title = $img.attr("title") + ": " + country_name;
312 $img.attr("title",title);
313 }
314 )
315 });
316
317 });
318});
319
320
321
322$(window).resize(function() {
323 console.log("choose-canvas resize()");
324
325 //console.log("*** aspect ratio div position top = " + $('#aspect-ratio-div').position().top);
326
327 var window_height = $(window).height();
328 var div_top = $('#aspect-ratio-div').offset().top + 20;
329
330 //var top = 0;
331
332 var la_y_dim = window_height - div_top;
333 var la_x_dim = $(window).width() * 0.7;
334
335 var scale_to_y_dim = calcScaleToHeight(aspectRatios,la_x_dim,la_y_dim);
336
337 // (top==0) ? la_y_dim/4 : la_y_dim/2.8;
338
339 //console.log("*** scale to y dim = " + la_y_dim);
340
341 $.each(aspectRatios, function(key, ratio_table) {
342 var freq = ratio_table.freq;
343 var ratio_array = key.split(":");
344 var ratio_x = ratio_array[0];
345 var ratio_y = ratio_array[1];
346 var ratio = ratio_y / ratio_x;
347
348 var ratioScale = aspectMaxRatio/ratio;
349
350 var x_dim = Math.round(scale_to_y_dim * ratioScale);
351 var y_dim = scale_to_y_dim;
352
353 var ratio_id = "ratio-" + key.replace(":","_");
354
355 //console.log("*** ratio_id = " + ratio_id + " xdim = " + x_dim + ", ydim = " + y_dim);
356
357 $('#'+ratio_id).css("width",x_dim + "px");
358 $('#'+ratio_id).css("height",y_dim + "px");
359
360
361 });
362});
363
364
365
366function updateCanvasDimensions(height, width) {
367
368 // Show feedback by highlighting the chosen square
369 document.getElementById(currentRatio).style.borderColor = 'black';
370 document.getElementById(currentRatio).style.borderWidth = '1px';
371 currentRatio = "ratio-" + width + "_" + height;
372 document.getElementById(currentRatio).style.borderColor = 'white';
373 document.getElementById(currentRatio).style.borderWidth = '4px';
374
375 // Changing the value of sizeConstant will change the
376 // size of the svg canvas without affecting the
377 // width/height ratios
378
379 var sizeConstant = 400;
380
381 var h = sizeConstant;
382 var w = (sizeConstant / height) * width;
383
384 if (typeof flagCanvasSettings !== 'undefined') {
385 flagCanvasSettings.width = w;
386 flagCanvasSettings.height = h;
387 }
388}
389
390
391
392 </script>
393
394 <title>Canvas Size</title>
395
396 </head>
397
398 <body>
399 <div data-role="page" id="choose-canvas-page"
400 class="demo-page"
401 data-dom-cache="true"
402 data-next="choose-palette">
403
404 <div data-role="content">
405
406 <div data-role="controlgroup" class="control" data-mini="true">
407 <a href="#" class="next right-button res-fwd" style="right:1%;"></a>
408<!--
409 <a href="#" class="prev left-button gen-back" style="left:1%;"></a>
410-->
411 </div>
412
413 <a target="_parent" href="../index.html" class="back-button back-left"></a>
414
415 <div class="story-page">
416
417 <!-- put custom content here -->
418 <span class="left story-icon idea" ></span>
419 <h2>Canvas Size</h2>
420
421 <div class="dialog" id="dialog" title="Flag Aspect Ratio Selection Panel" ><!-- width="800px" -->
422 <br><br>
423 <h2>Please choose from the following aspect ratios to select the width and height of your flag.</h2>
424 <style>
425 p { margin: 10px }
426 </style>
427 <p>
428 New Zealand's current aspect ration (2:1) is selected by default. Click on one of the other
429 boxes to choose a different size.
430 </p>
431 <p>
432 Once chosen, swipe the page or click/press on the right arrow to go onto the next step.
433 You can swipe/click back to this page at any time to change your selection.
434 </p>
435
436 <div id="aspect-ratio-div">
437 </div>
438
439
440<!--
441 <div class="centredDiv">
442 <div class="ratioDiv flagHover" id="ratio23" onclick="updateCanvasDimensions(2, 3)" title="2:3"></div>
443 <div class="ratioDiv" style="border-width:2px;" id="ratio12" onclick="updateCanvasDimensions(1, 2)" title="1:2"></div>
444 <div class="ratioDiv" id="ratio35" onclick="updateCanvasDimensions(3, 5)" title="3:5"></div>
445 <div style="clear: both"></div>
446 </div>
447 <p class="optionline">2:3 1:2 3:5</p><br>
448
449 <div class="centredDiv">
450 <div class="ratioDiv" id="ratio1019" onclick="updateCanvasDimensions(10, 19)" title="10:19"></div>
451 <div class="ratioDiv" id="ratio58" onclick="updateCanvasDimensions(5, 8)" title="5:8"></div>
452 <div class="ratioDiv" id="ratio811" onclick="updateCanvasDimensions(8, 11)" title="8:11"></div>
453 <div style="clear: both"></div>
454 </div>
455 <p class="optionline">10:19 5:8 8:11</p>
456-->
457 </div>
458
459 <!-- end of putting custom content -->
460
461 </div> <!-- end story-page-->
462
463 </div><!-- /content -->
464
465<!-- make persistent?
466 <div data-role="footer" style="width:100%;">
467 COSI: Centre of Open Source Innovation @ The University of Waikato.
468 </div>
469-->
470
471 </div><!-- /page -->
472
473 </body>
474</html>
Note: See TracBrowser for help on using the repository browser.