Skip to content

Instantly share code, notes, and snippets.

@feiz
Last active December 17, 2015 05:18
Show Gist options
  • Save feiz/5556650 to your computer and use it in GitHub Desktop.
Save feiz/5556650 to your computer and use it in GitHub Desktop.
$(function (){
$('tr').each(function (i, e){
var row = $(e);
var link = $(row.children()[2])
var a = link.children('a');
var url = a.attr('href');
if (!url) {return;}
url = url.split('/');
user_id = url[url.length-1];
var yasumi_key = 'yasumi_' + user_id;
var counter_key = 'counter_' + user_id;
var yasumi = link.after('<td id="' + yasumi_key + '"></td>');
var counter = link.after('<td id="' + counter_key + '"></td>');
a.click(function() {
var now = new Date();
now.setDate(now.getDate() + 1);
now.setHours(0);now.setMinutes(0);now.setSeconds(0);
$.cookie(counter_key, 1, {expire: now});
update_counter(counter_key);
return true;
});
yasumi.click(function (){
var flg = $.cookie(yasumi_key);
if (flg) {
$.removeCookie(yasumi_key);
} else {
$.cookie(yasumi_key, '1');
}
update_yasumi(yasumi_key);
});
update_counter(counter_key);
update_yasumi(yasumi_key);
});
});
function update_yasumi(key) {
var val;
if ($.cookie(key)) {
val = '休業中';
} else {
val = '営業中';
}
$('#' + key).html(val);
}
function update_counter(key){
var val;
if ($.cookie(key)) {
val = '済';
} else {
val = '';
}
$('#' + key).html(val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment