ipsum.ir/client/js/main.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-09-16 05:50:23 +00:00
var socket = io();
2014-09-06 07:21:41 +00:00
var $run = $('h1, h3, .options, a');
$('li[contenteditable]').click(function(e) {
if($(this).html() == 'عدد وارد کنید') $(this).html(' ');
2014-09-08 11:53:24 +00:00
});
2014-09-06 07:21:41 +00:00
$('li[contenteditable]').on('keydown', function(e) {
if(e.keyCode !== 8 && e.keyCode !== 46 && isNaN(+e.key)) return e.preventDefault();
2014-09-08 11:53:24 +00:00
});
2014-09-06 07:21:41 +00:00
$('li[contenteditable]').on('keyup', function(e) {
$(this).data('val', /\d*/.exec($(this).html()));
2014-09-08 11:53:24 +00:00
});
2014-09-06 07:21:41 +00:00
2014-09-08 11:53:24 +00:00
$('a[href="#"]').click(function(e) {
2014-09-06 07:21:41 +00:00
e.preventDefault();
var $this = $(this);
$this.addClass('running');
2014-09-06 15:08:42 +00:00
var url = '/' + $('.options div:first-child li.active').data('val') + '/' + $('.options div:nth-child(2) li.active').data('val') + '/' + ($('.options div:last-child li.active').data('val') || 1);
2014-09-06 07:21:41 +00:00
$.ajax({
url: url,
success: success
2014-09-08 11:53:24 +00:00
});
});
2014-09-06 07:21:41 +00:00
$('li').click(function() {
$(this).parent().find('li').removeClass('active');
$(this).addClass('active');
2014-09-08 11:53:24 +00:00
});
2014-09-06 07:21:41 +00:00
function success(ipsum) {
2014-09-06 15:08:42 +00:00
$('a').removeClass('running');
$('.modal').html(ipsum);
2014-09-08 11:53:24 +00:00
2014-09-06 15:08:42 +00:00
var range = document.createRange();
range.selectNodeContents($('.modal')[0]);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
2014-09-06 07:21:41 +00:00
}
2014-09-16 05:50:23 +00:00
socket.on('counter', function(count) {
$('#count').text(count);
});