From 58c9ed0120c0d1a39508edd525b11cff64d29a62 Mon Sep 17 00:00:00 2001 From: Mathieu Sanchez Date: Fri, 2 Nov 2018 14:08:33 +0900 Subject: [PATCH] Add mimify CSS and JS + favicon + htaccess + optimize page speed load --- .htaccess | 25 +++++++++++++++++++++++++ favicon.ico | Bin 0 -> 1406 bytes index.html | 17 ++++++++++------- ressources/index.min.css | 1 + ressources/index.min.js | 29 +++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 .htaccess create mode 100644 favicon.ico create mode 100644 ressources/index.min.css create mode 100644 ressources/index.min.js diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..5330a81 --- /dev/null +++ b/.htaccess @@ -0,0 +1,25 @@ +RewriteEngine on + +RewriteCond %{SERVER_PORT} 80 +RewriteRule .* https://%{HTTP_HOST} [R=301,L] + + + ExpiresActive On + ExpiresDefault "access plus 7200 seconds" + ExpiresByType image/jpg "access plus 1 week" + ExpiresByType image/jpeg "access plus 1 week" + ExpiresByType image/png "access plus 1 week" + ExpiresByType image/gif "access plus 1 week" + ExpiresByType image/svg+xml "access plus 1 week" + AddType image/x-icon .ico + ExpiresByType image/ico "access plus 1 week" + ExpiresByType image/icon "access plus 1 week" + ExpiresByType image/x-icon "access plus 1 week" + ExpiresByType text/css "access plus 1 week" + ExpiresByType text/javascript "access plus 1 week" + ExpiresByType text/html "access plus 7200 seconds" + ExpiresByType application/xhtml+xml "access plus 7200 seconds" + ExpiresByType application/javascript "access plus 1 week" + ExpiresByType application/x-javascript "access plus 1 week" + ExpiresByType application/x-shockwave-flash "access plus 1 week" + \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..4c4c34c2982d5eeec3998ebe683506e60ea363c8 GIT binary patch literal 1406 zcmZQzU<5(|0R|w+!H~hqz#zuJz@P!dKp_SNAO?wp0V4y$XJ!Zn3W6jU#CE-AknDQP z;CK21L;LNo3<1kNGDNNZ#L$os%8HS<`0IA^QJTG zShj#+E0DkS)=!3o?B^WxN R0Zl!`M1+3qe3-qY(g5O~DU<*J literal 0 HcmV?d00001 diff --git a/index.html b/index.html index c805463..336a5cc 100644 --- a/index.html +++ b/index.html @@ -5,16 +5,14 @@ Calculator - - - - - - - + + + + + @@ -126,6 +124,11 @@ + + + + + \ No newline at end of file diff --git a/ressources/index.min.css b/ressources/index.min.css new file mode 100644 index 0000000..0ae12b6 --- /dev/null +++ b/ressources/index.min.css @@ -0,0 +1 @@ +body,html{height:100%;overscroll-behavior:contain}*{box-sizing:border-box}.button-input{position:relative;color:white;font-size:40px;display:inline-block;width:33.333333333333333%;text-align:center;height:25%;cursor:pointer}.buttons-operators .button-input{width:100%;height:20%}.button-input span{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.parenthesis{width:100%;height:20%}.parenthesis .button-input{width:50%;height:100%}.button-input.parenthesis div{display:inline-block;width:50%;position:relative;height:100%;font-size:40px}.container{height:100%;background:#1F1F1F;width:100%;z-index:0;padding:0;margin:0;max-width:none;display:block}.buttons-container{position:absolute;bottom:0;display:block;font-size:0;width:100%;height:60%;line-height:0;z-index:0}.buttons-numbers{display:inline-block;width:75%;height:100%;background:#000;vertical-align:top}.buttons-operators{display:inline-block;width:25%;height:100%;background:#232323}.display-container{height:40%;top:0;position:absolute;width:100%;z-index:0}.display{text-align:right;color:white;font-size:70px;position:absolute;width:94%;left:50%;top:50%;overflow:auto;line-height:initial;transform:translate(-50%,-50%);-webkit-transition:font 0.3s ease;-moz-transition:font 0.3s ease;-o-transition:font 0.3s ease;-ms-transition:font 0.3s ease;transition:font 0.3s ease}.error .display{color:#d00506;font-weight:600}.display.big{font-size:60px}.display.medium{font-size:50px}.display.small{font-size:40px}.clears-buttons-container{position:absolute;bottom:10px;right:10px;height:60px;width:130px;display:block;font-size:0;line-height:0}.clears-buttons-container div,.expand-buttons div{width:60px;height:60px;display:inline-block;border-radius:50%;vertical-align:top;background:#424242;font-size:16px;line-height:60px;text-align:center;color:white;font-weight:600;opacity:0;cursor:pointer;-webkit-transition:all 0.3s ease;-moz-transition:all 0.3s ease;-o-transition:all 0.3s ease;-ms-transition:all 0.3s ease;transition:all 0.3s ease}.clears-buttons-container.show div{opacity:1}#sup{margin-right:10px}.expand-buttons{position:absolute;top:calc(40% - 40px);left:50%;transform:translateX(-50%);width:35px;height:35px;z-index:2;-webkit-transition:all 0.3s ease;-moz-transition:all 0.3s ease;-o-transition:all 0.3s ease;-ms-transition:all 0.3s ease;transition:all 0.3s ease}.expand-buttons svg{-webkit-transition:all 0.3s ease;-moz-transition:all 0.3s ease;-o-transition:all 0.3s ease;-ms-transition:all 0.3s ease;transition:all 0.3s ease}.container.history .expand-buttons{top:calc(100% - 40px)}.container.history .expand-buttons svg{transform:rotate(180deg)}.main-history{width:100%;height:100%;position:absolute;background:#1F1F1F;z-index:1;top:-100%;-webkit-transition:all 0.3s ease;-moz-transition:all 0.3s ease;-o-transition:all 0.3s ease;-ms-transition:all 0.3s ease;transition:all 0.3s ease}.container.history .main-history{top:0}.day-container{color:white;border-bottom:1px solid rgba(97,97,97,.5);padding:10px;line-height:initial}.day-container:last-child{border-bottom:none}.day-container .title{color:#ffc107;font-weight:600;font-size:12px}.day-container .calcul-container{text-align:right;padding:3px 0;font-size:25px;color:white;font-family:sans-serif}.day-container .calcul-container .operation{overflow:auto}.day-container .calcul-container .result{color:#9e9e9e}.delete-history-container{background:black;height:40px;width:100%;font-size:17px;color:white;text-align:center;line-height:40px}.delete-history-container span{font-size:28px}.delete-history-container #delete-history{position:absolute;right:10px;top:0;line-height:40px;color:#9e9e9e;cursor:pointer}.history-container{height:calc(100% - 40px);overflow:auto}@media screen and (min-width:1020px){.calculator-container{display:inline-block;height:100%;width:60%;line-height:0;position:absolute;font-size:0}.main-history{display:inline-block;position:relative;width:40%;top:0;line-height:0;height:100%;vertical-align:top;font-size:0}.history-container{background-color:#161616}.expand-buttons{display:none}.container{overflow:hidden}} \ No newline at end of file diff --git a/ressources/index.min.js b/ressources/index.min.js new file mode 100644 index 0000000..21e50e0 --- /dev/null +++ b/ressources/index.min.js @@ -0,0 +1,29 @@ +let operators=['+','-','/','*','.'];let operation="";let operations=[];function calculate(){try{let result=eval(operation);operations.unshift({calcul:operation,result,date:new Date().getTime()});operation=result.toString();localStorage.setItem("operations",JSON.stringify(operations));display();insertHistory()}catch(e){$(".display-container").addClass("error")}} +function setFontSize($display){let length=operation.length;let clearsButtons=$(".clears-buttons-container");if(length>0){clearsButtons.addClass("show")}else{clearsButtons.removeClass("show")} + if(length<=10){$display.removeClass("big");$display.removeClass("medium");$display.removeClass("small")}else if(length<=12){$display.addClass("big");$display.removeClass("medium");$display.removeClass("small")}else if(length<=14){$display.addClass("medium");$display.removeClass("big");$display.removeClass("small")}else if(length<=16){$display.addClass("small");$display.removeClass("big");$display.removeClass("medium")}} +function roundDate(date){date.setHours(0);date.setMinutes(0);date.setSeconds(0);date.setMilliseconds(0);return date} +function diff2Dates(date1,date2){let one_day=1000*60*60*24;let date1_ms=date1.getTime();let date2_ms=date2.getTime();let difference_ms=date2_ms-date1_ms;return Math.round(difference_ms/one_day)} +function insertHistory(){let $html=$("
");let now=roundDate(new Date());let historyContainer=$(".history-container");if(operations.length>0){for(let operation of operations){let date=roundDate(new Date(operation.date));if($html.find(`.day-container[data-day="${ date.toDateString() }"]`).length>0){$html.find(`.day-container[data-day="${ date.toDateString() }"] .title`).after(` +
+
${ operation.calcul }
+
${ operation.result }
+
`)}else{let daysAgo="";let diff=diff2Dates(date,now);if(diff===0){daysAgo="Today"}else if(diff===1){daysAgo="Yesterday"}else{daysAgo=diff+" days ago"} + $html.prepend(` +
+
${ daysAgo }
+
+
${ operation.calcul }
+
${ operation.result }
+
+
`)}} + historyContainer.html($html.html());historyContainer.animate({scrollTop:historyContainer[0].scrollHeight},300)}else{historyContainer.empty()}} +function supp(){if(operation.length>0){let $display=$(".display");operation=operation.slice(0,-1);$display.text(operation);$display.scrollLeft(1000);setFontSize($display);$(".display-container").removeClass("error")}} +function ac(){if(operation.length>0){let $display=$(".display");operation="";$display.text(operation);$display.scrollLeft(1000);setFontSize($display)} + $(".display-container").removeClass("error")} +function display(){let $display=$(".display");$display.text(operation);$display.scrollLeft(1000);setFontSize($display);$(".display-container").removeClass("error")} +function swipedetect(el,callback){let touchsurface=el,swipedir,startX,startY,distX,distY,threshold=150,restraint=100,allowedTime=300,elapsedTime,startTime,handleswipe=callback||function(swipedir){};touchsurface.addEventListener('touchstart',function(e){var touchobj=e.changedTouches[0];swipedir='none';dist=0;startX=touchobj.pageX;startY=touchobj.pageY;startTime=new Date().getTime()},!1);touchsurface.addEventListener('touchmove',function(e){},!1);touchsurface.addEventListener('touchend',function(e){var touchobj=e.changedTouches[0];distX=touchobj.pageX-startX;distY=touchobj.pageY-startY;elapsedTime=new Date().getTime()-startTime;if(elapsedTime<=allowedTime){if(Math.abs(distX)>=threshold&&Math.abs(distY)<=restraint){swipedir=(distX<0)?'left':'right'} +else if(Math.abs(distY)>=threshold&&Math.abs(distX)<=restraint){swipedir=(distY<0)?'up':'down'}} + handleswipe(swipedir)},!1)} +$(window).on("load",function(){if(localStorage.getItem("operations")){operations=JSON.parse(localStorage.getItem("operations"));insertHistory()} + $(document).on("click","#ac",ac);$(document).on("click","#sup",supp);$(document).on("click",".button-input",function(){let $elem=$(this);let input=$elem.find("span").html();if(input==="="){calculate()}else{operation+=$elem.find("span").html();display()}});$(document).on("click",".expand-buttons",()=>$(".container").toggleClass("history"));$(document).on("click","#delete-history",function(){operations=[];localStorage.setItem("operations",JSON.stringify(operations));insertHistory()});$(window).on("keypress",function(e){e.preventDefault();let char=e.charCode;console.log(char,String.fromCharCode(char));if(char===13){calculate()}else if(operators.indexOf(String.fromCharCode(char))>=0){operation+=String.fromCharCode(char)}else if(char>=48&&char<=57){operation+=String.fromCharCode(char)}else if(char===115||char===83){supp()}else if(char===97||char===65){ac()} + display()});swipedetect(document.getElementsByClassName("display-container")[0],function(dir){if(dir==="down"){$(".container").addClass("history")}});let historyContainer=document.getElementsByClassName("history-container");swipedetect(historyContainer[0],function(dir){if(dir==="up"&&((historyContainer[0].scrollTop+historyContainer[0].offsetHeight)===historyContainer[0].scrollHeight)){$(".container").removeClass("history")}})}) \ No newline at end of file