Auto Refresh on/off

This commit is contained in:
Phyo
2017-06-21 17:01:44 +06:30
parent bd71cfd241
commit 51252b99e3

View File

@@ -94,7 +94,7 @@
<!-- tabs - End --> <!-- tabs - End -->
</div> </div>
<div class="col-lg-1 col-md-1 col-sm-1"> <div class="col-lg-1 col-md-1 col-sm-1">
<button type="button" class="btn btn-primary btn-block"> Refresh </button> <button id="refreshbutton" type="button" class="btn btn-block" style="border-radius:5px;color:#fff;background-color:red;"> Refresh off </button>
</div> </div>
</div> </div>
<!-- Column One --> <!-- Column One -->
@@ -117,4 +117,70 @@ $(document).ready(function(){
window.location.href = '/origami/order/' + order_id; window.location.href = '/origami/order/' + order_id;
}) })
}); });
$(function() {
var timer;
function start() {
timer = setTimeout(function() { console.log("refresh");window.location.reload()}, 30000); //10000
};
function stop() {
clearTimeout(timer);
};
if(localStorage.getItem("refreshflag") != null){
if (localStorage.getItem("refreshflag") == 0) {
$('#refreshbutton').html("Refresh off");
$('#refreshbutton').css("background-color","red");
stop();
}
else{
$('#refreshbutton').html("Refresh on");
$('#refreshbutton').css("background-color","green");
start();
}
}
else{
localStorage.setItem("refreshflag", 0);
}
var url = location.href;
if (location.href.slice(-1) == "/"){
url = url.substring(0, url.length - 1);
}
var arr = url.split("/");
if(arr[arr.length-1] != "origami"){
stop();
}
$('#refreshbutton').bind("click", function(){
if(localStorage.getItem("refreshflag") == "0"){
localStorage.setItem("refreshflag", 1);
$(this).html("Refresh on");
$(this).css("background-color","green");
// $(this).html("Auto Refresh on<span class='glyphicon glyphicon-ok'></span>");
start();
}
else{
stop();
localStorage.setItem("refreshflag", 0);
$(this).html("Refresh off");
$(this).css("background-color","red");
}
});
function refreshing(){
if(localStorage.getItem("refreshflag") == "0"){
localStorage.setItem("refreshflag", 1);
$(this).html("Refresh on");
$(this).css("background-color","green");
// $(this).html("Auto Refresh on<span class='glyphicon glyphicon-ok'></span>");
start();
}
else{
stop();
localStorage.setItem("refreshflag", 0);
$(this).html("Refresh off");
$(this).css("background-color","red");
}
}
});
</script> </script>