diff --git a/README.md b/README.md new file mode 100644 index 0000000..8839eeb --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Second web project of web development in Chung Ang University + +## Subject + +Write an interative calculator program providing the following features using HTML, CSS, and Javascript. + +- Basic arithmetic operators (+, -, *, /) +- Parenthsis +- Memory + +Submit the report including requirements, design, execution results and references. + +For try it, click [here](https://calculator.sanchez-mathieu.fr/) \ No newline at end of file diff --git a/index.html b/index.html index 336a5cc..99b8d45 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ - + @@ -126,8 +126,9 @@ + - + diff --git a/ressources/index.js b/ressources/index.js index b7c889c..1dd25b0 100644 --- a/ressources/index.js +++ b/ressources/index.js @@ -232,7 +232,8 @@ $( window ).on( "load", function () { insertHistory(); } ); - $( window ).on( "keypress", function ( e ) { + $( document ).on( "keypress", function ( e ) { + console.log( e ); e.preventDefault(); let char = e.charCode; @@ -269,4 +270,12 @@ $( window ).on( "load", function () { } } ) + if ( location.hostname === "sanchez-mathieu.fr" ) { + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + + gtag('config', 'UA-74712385-7'); + } + } ); \ No newline at end of file diff --git a/ressources/index.min.css b/ressources/index.min.css deleted file mode 100644 index 0ae12b6..0000000 --- a/ressources/index.min.css +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 21e50e0..0000000 --- a/ressources/index.min.js +++ /dev/null @@ -1,29 +0,0 @@ -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