Add Counter #2
@ -510,3 +510,12 @@ a[href="#"].running {
|
|||||||
background-color: rgba(255, 255, 255, 0.2);
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
.counter {
|
||||||
|
padding: 10px;
|
||||||
|
position: fixed;
|
||||||
|
left: 0px;
|
||||||
|
bottom: 0px;
|
||||||
|
}
|
||||||
|
.counter p {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>ایپسوم دسته بندی شده</title>
|
<title>ایپسوم دسته بندی شده</title>
|
||||||
<meta charset='UTF-8'>
|
<meta charset='UTF-8'>
|
||||||
<link rel='stylesheet/less' href='css/main.less'>
|
<link rel='stylesheet' href='css/main.css'>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -51,8 +51,14 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src='less.js'></script>
|
<div class="counter">
|
||||||
|
<p>تاحالا <span id="count"></span>تا حرف ساختم</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a href="https://github.com/mdibaiee/ipsum"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>
|
||||||
|
|
||||||
<script src='js/libs/zepto.js'></script>
|
<script src='js/libs/zepto.js'></script>
|
||||||
|
<script src='/socket.io/socket.io.js'></script>
|
||||||
<script src='js/main.js'></script>
|
<script src='js/main.js'></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
|
var socket = io();
|
||||||
|
|
||||||
var $run = $('h1, h3, .options, a');
|
var $run = $('h1, h3, .options, a');
|
||||||
|
|
||||||
$('li[contenteditable]').click(function(e) {
|
$('li[contenteditable]').click(function(e) {
|
||||||
if($(this).html() == 'عدد وارد کنید') $(this).html(' ');
|
if($(this).html() == 'عدد وارد کنید') $(this).html(' ');
|
||||||
})
|
});
|
||||||
|
|
||||||
$('li[contenteditable]').on('keydown', function(e) {
|
$('li[contenteditable]').on('keydown', function(e) {
|
||||||
if(e.keyCode !== 8 && isNaN(+e.key)) return e.preventDefault();
|
if(e.keyCode !== 8 && isNaN(+e.key)) return e.preventDefault();
|
||||||
})
|
});
|
||||||
$('li[contenteditable]').on('keyup', function(e) {
|
$('li[contenteditable]').on('keyup', function(e) {
|
||||||
$(this).data('val', /\d*/.exec($(this).html()));
|
$(this).data('val', /\d*/.exec($(this).html()));
|
||||||
})
|
});
|
||||||
|
|
||||||
$('a').click(function(e) {
|
$('a[href="#"]').click(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
|
|
||||||
@ -21,21 +23,28 @@ $('a').click(function(e) {
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
success: success
|
success: success
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
$('li').click(function() {
|
$('li').click(function() {
|
||||||
$(this).parent().find('li').removeClass('active');
|
$(this).parent().find('li').removeClass('active');
|
||||||
$(this).addClass('active');
|
$(this).addClass('active');
|
||||||
})
|
});
|
||||||
|
|
||||||
function success(ipsum) {
|
function success(ipsum) {
|
||||||
$('a').removeClass('running');
|
$('a').removeClass('running');
|
||||||
$('.modal').html(ipsum);
|
$('.modal').html(ipsum);
|
||||||
|
|
||||||
var range = document.createRange();
|
var range = document.createRange();
|
||||||
range.selectNodeContents($('.modal')[0]);
|
range.selectNodeContents($('.modal')[0]);
|
||||||
var selection = window.getSelection();
|
var selection = window.getSelection();
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
|
|
||||||
|
socket.emit('counter', ipsum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
socket.emit('counter');
|
||||||
|
socket.on('counter', function(count) {
|
||||||
|
$('#count').text(count);
|
||||||
|
});
|
||||||
|
1
count.json
Normal file
1
count.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
0
|
23
ipsum.js
23
ipsum.js
@ -1,7 +1,12 @@
|
|||||||
var express = require('express'),
|
var express = require('express'),
|
||||||
app = express();
|
app = express(),
|
||||||
|
server = require('http').Server(app),
|
||||||
|
io = require('socket.io')(server),
|
||||||
|
fs = require('fs');
|
||||||
|
|
||||||
app.use(express.static(__dirname + '/ipsum', {maxAge: 60*60*24*7}));
|
var count = require('./count.json');
|
||||||
|
|
||||||
|
app.use(express.static(__dirname + '/client', {maxAge: 60*60*24*7}));
|
||||||
|
|
||||||
module.exports.app = app;
|
module.exports.app = app;
|
||||||
|
|
||||||
@ -90,3 +95,17 @@ function go(url) {
|
|||||||
var req = url.split('/');
|
var req = url.split('/');
|
||||||
return loremipsum(req.slice(1));
|
return loremipsum(req.slice(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//COUNTER
|
||||||
|
io.on('connection', function(socket) {
|
||||||
|
socket.on('counter', function(data) {
|
||||||
|
if(data) {
|
||||||
|
var r = data.split(' ').join('').length + count;
|
||||||
|
fs.writeFile(__dirname + '/count.json', r, function() {
|
||||||
|
count = +(fs.readFileSync(__dirname + '/count.json', 'utf8'));
|
||||||
|
})
|
||||||
|
io.emit('counter', r);
|
||||||
|
}
|
||||||
|
else io.emit('counter', count);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user