.
[hacks/simpleWebSlides.git] / simpleWebSlides.js
index 9beae05..798d2ac 100644 (file)
@@ -77,7 +77,7 @@ SWS.Templates = new function () {
 </div>\
 <div id='sws-control-panel-options'>\
 <span title='Change the aspect ratio' class='sws-symbol' >&#x1f4bb;</span><select id='sws-aspect-select' onchange='SWS.Presentation.changeAspect();'>\
-<option value='sws-aspect-4-3'>4:3</option>\
+<option value='sws-aspect-4-3' selected='selected'>4:3</option>\
 <option value='sws-aspect-16-9'>16:9</option>\
 <option value='sws-aspect-16-10'>16:10</option>\
 </select>\
@@ -722,10 +722,23 @@ SWS.Presentation = new function () {
             });
     };
     self.changeAspect = function() {
+       var newClass = $("#sws-aspect-select").val();
+       var args = newClass.split("-");
+       var targetRatio = (args[2] - 0) / (args[3] - 0);
+       var realRatio = window.innerWidth / window.innerHeight;
+       var byClass = (targetRatio > realRatio ) ? "sws-by-height" : "sws-by-width";
+       console.log(byClass);
+
+       if ($("html").hasClass(newClass)
+           && $("html").hasClass(byClass))
+           return;
+
         $("html").removeClass("sws-aspect-4-3")
             .removeClass("sws-aspect-16-9")
             .removeClass("sws-aspect-16-10")
-            .addClass($("#sws-aspect-select").val());
+           .removeClass("sws-by-width")
+           .removeClass("sws-by-height")
+            .addClass(newClass).addClass(byClass);
         self.redraw();
     };
 
@@ -921,14 +934,17 @@ SWS.Presentation = new function () {
                 }
                 else {
                    if (self.showHelpAtStartup()) $("#sws-help-panel-canvas").show().delay(5000).hide();
+                   self.changeAspect();
                     self.refresh();
                };
                 $(document).keydown(self.inputHandler);
                 document.body.addEventListener('touchstart',self.inputHandler, false);
                 document.body.addEventListener('touchend',self.inputHandler, false);
+               $(window).resize(self.changeAspect);
                 _initialized = true;
             };
-        setTimeout(f, 100);
+        //setTimeout(f, 100);
+       f();
     };
 
 };