(function() { jQuery(function($) { /* --------------------[ Initialize ] # shortlinks */ var alarm, alarmId, alarmId_, alarmPlay, initInput, sec, timer, timer_, toHHMMSS, _this = this; alarmId_ = $("#alarmId")[0]; alarmId = $("#alarmId"); timer = $("#timer"); timer_ = $("#timer")[0]; window.timerPause = "0"; timer.focusin((function() { return window.timerPause = "1"; })); timer.focusout((function() { return window.timerPause = "0"; })); $(".clearTimer").click(function() { timer.val("00:00:00"); console.log ("clear timer to 00:00:00"); return setCookie("timer", "00:00:00"); }); // инициализируем таймер console.log ("COOK is: "+getCookie("timer")+"!!!"); if (getCookie("timer") == undefined) { console.log ("1setcookie to 00:00:00"); timer.val("00:00:00"); } else { console.log ("2setcookie to "+getCookie("timer")); timer.val(getCookie("timer")); } /* # check Permission for HTML5 notifications*/ if (window.Notification) { $.notification.requestPermission(function() { return console.log('Notifications ' + $.notification.permissionLevel()); }); } /* # --------------------[ Initialization for Inputs ]*/ $('.addTimer').click(function() { var h, m; h = '00'; m = '00'; if (($(this).attr('h') != null)) { h = $(this).attr('h'); } if (($(this).attr('m') != null)) { m = $(this).attr('m'); } $('#timer').val("" + h + ":" + m + ":00"); return console.log("add timer: " + h + ":" + m + ":00"); }); // маска для ввода таймера $('#timer').mask('99:99:99', { completed: function() { return $('#timer').delay(100).fadeOut(100).fadeIn(100); } }); // Будильник alarm = function(text) { jNote(text); navigator.vibrate(1000); alarmId.attr('src', "sound/alarm/49166__gmtechb__4beeps-01.mp3"); alarmId_.play(); }; /* # 301 -> 00:05:01*/ toHHMMSS = function(s) { var hours, minutes, sec_num, seconds, time; sec_num = parseInt(s, 10); hours = Math.floor(sec_num / 3600); minutes = Math.floor((sec_num - (hours * 3600)) / 60); seconds = sec_num - (hours * 3600) - (minutes * 60); return time = zero(hours) + ':' + zero(minutes) + ':' + zero(seconds); }; // sec - Выполняется кажую секунду sec = function() { var HHMMSS, currentTime, days, hours, minutes, monthss, seconds, timerSecond, v, years, zero, _i, _j, _len, _len1, _ref, _ref1, _results; if ( $("#paused").val() == '' ){ now = new moment().subtract( window.diff , 'hours' ) } else{ now = new moment.unix( $("#paused").val() ) } moment.locale("en") $("time").html( now.format("HH:mm:ss") ); $("date").html( now.format("D MMMM YYYY") ); $("time").css("font-size", ($('body').width() / 4) + "px"); if (window.timerPause === "0") { if (timer.val() === '00:00:01') { alarm( 'Triggering timer: '+now.format("HH:mm:ss") ); } if (timer.val() !== '00:00:00') { HHMMSS = timer.val().split(':'); timerSecond = parseInt(HHMMSS[2], 10) + parseInt(HHMMSS[1] * 60, 10) + parseInt(HHMMSS[0] * 60 * 60, 10); timerSecond--; timerSecond = toHHMMSS(timerSecond); timer.val(timerSecond); document.title = timerSecond; console.log ("SetCookie to "+timerSecond); setCookie("timer", timerSecond); } else { document.title = now.format("HH:mm:ss - D MMMM, YYYY, Time: http://jkeks.com/Time"); } } delete now }; if ($("#paused").val()==''){ setInterval(sec, 1000); } sec(); }); //// функция Загрузки точного времяни //$.getTime = function(zone, success) { // var url = 'http://json-time.appspot.com/time.json?tz=' + zone + '&callback=?'; // $.getJSON(url, function(o){ // console.log ("o.datetime:"+o.datetime); // success && success(new Date(o.datetime), o); // }); //}; //// вычисление разницы во времени моим и настоящим //$.getTime('GMT', function(time){ // localTime = new Date(); // window.diffTime = Math.ceil((localTime.getTime() - time.getTime())/1000); // если разница 94, то это мои часы спешат на 94 секунды // window.diffTime += 3600 // в зимнее время //}); }).call(this); // //// ajax запрос на сохранение текущей даты //function copyUrl(){ // var id = Math.floor(Date.now() / 1000) ; // $('#copurl').show(); // $("#copurl").val( "http://jkeks.com/Time/"+id ); // $('#copurl').select(); // document.execCommand('copy'); // $('#copurl').hide(); // $('#buttonCopyUrl').html('Copied'); // setTimeout("$('#buttonCopyUrl').html('Copy URL');",1000); //} // //// копирование времени текущей даты и времени //function copyTime(){ // clipboard.copy( $("date").text()+', '+$("time").text() ) // var id = Math.floor(Date.now() / 1000) ; // $('#copurl').show(); // $("#copurl").val( $("date").text()+', '+$("time").text() ); // $('#copurl').select(); // document.execCommand('copy'); // $('#copurl').hide(); // $('#buttonCopyTime').html('Copied'); // setTimeout("$('#buttonCopyTime').html('Copy time');",1000); //} // 19:14:11 14 октября, 2015 function noAds(){ $(".ads").slideToggle(); }