Всем привет есть таймер сейчас запускается таким образом
$(function () {
var timeData = {
cookieName: 'links-timers',
cookieExpires: 30, // cookie live in days
getOld: function ($link) {
var self = this,
id = $link.data('id'),
data = self.getCookie(),
storeTime = data && data[id] ? data[id] : null,
nowTime = +(new Date),
time = storeTime && storeTime > nowTime ? storeTime : null;
return time;
},
getNew: function ($link) {
var self = this,
seconds = parseInt($link.data('time')),
id = $link.data('id'),
data = self.getCookie(),
time = ( +(new Date) + (seconds * 1000) );
data[id] = time;
//$.cookie(self.cookieName, $.toJSON(data), {
// expires: self.cookieExpires,
// path: '/'
//});
localStorage.setItem(self.cookieName, $.toJSON(data));
return time;
},
getCookie: function () {
var self = this,
//cookieData = $.cookie(self.cookieName),
cookieData = localStorage.getItem(self.cookieName),
storeData = cookieData ? $.secureEvalJSON(cookieData) : {},
data = storeData ? storeData : {};
return data;
},
destroyCookie: function () {
var self = this;
//$.cookie(self.cookieName, null);
}
};
function linksTimer($link) {
this.$link = $link;
this.create();
return this;
}
linksTimer.prototype = {
create: function () {
var self = this,
$link = self.$link,
$descLink = $('<a href="' + $link.attr('href') + '" class="link-desc" target="_blank" title="Start">' + $link.text() + '</a>'),
time = timeData.getOld($link);
$link.before($descLink);
$descLink.on('click', function (e) {
//e.preventDefault();
$link.trigger('click');
});
$link.countdown({
date: +(new Date) + 0,
render: function (data) {
$(this.el).html(this.leadingZeros(data.hours, 2) + ":" + this.leadingZeros(data.min, 2) + ":" + this.leadingZeros(data.sec, 2));
},
onEnd: function () {
$(this.el).addClass('ended');
}
}).on("click", function (e) {
e.preventDefault();
var time = timeData.getNew($link);
self.setTime($link, time);
});
self.setTime($link, time);
},
setTime: function ($link, time) {
if ($link && time) {
$link.removeClass('ended')
.data('countdown')
.update(time)
.start();
}
}
};
jQuery.fn.linksTimer = function () {
return this.each(function () {
this.linksTimer = new linksTimer($(this));
});
};
});
$(document).ready(function () {
$('.countdown.callback').linksTimer();
});
, вывод на страницу
<div class="main-countr">
<div class="transdiv"></div>
<a class="link-desc" title="Start" target="_blank" href="https://mail.ru"></a><a class="countdown callback ended" data-time="660" data-title="Google" data-id="2" rel="nofollow" target="_blank"href="https://mail.ru">00:00:00</a>
</div>
.ну и сам вопрос как его запускать именно с кнопки?
P. S Я нуб и нечего не понимаю
Выглядит это все и работает
http://codepen.io/andreu666/details/rLWLEj