Category Archives: Stack Overflow
Managing sessions in node.js, with socket.io & without using cookies
I have an authentication method based on socket.io and I know you can save client id in a cookie or add a hash to request url.
but I'm looking for a way of implementing sessions in nodejs that doesn't rely on storing data in client side, is that even possible?
Managing sessions in node.js, with socket.io & without using cookies
I have an authentication method based on socket.io and I know you can save client id in a cookie or add a hash to request url.
but I'm looking for a way of implementing sessions in nodejs that doesn't rely on storing data in client side, is that even possible?
Answer by Nasser Torabzade for CSS Items below Float:Left not working
the safest & most extendable way is to add a new element with clear:both; before green div.
HTML
<div id='red' class='box'></div>
<div id='blue' class='box'></div>
<div id='clear'></div>
<div id='green'></div>
CSS
#clear{
clear:both;
}
Comment by Nasser Torabzade on How to get my div boxes to go together
Answer by Nasser Torabzade for Load flexslider after a fancybox div has opened
you should avoid display:none; for fancybox, so flexslider can determine image size properly.
this trick may help you:
put fancybox div inside a parent div.
set
visibility:hidden;for fancybox div.set
display:none;for parent div.
hope that it helps.
Comment by Nasser Torabzade on How to get my div boxes to go together
Answer by Nasser Torabzade for How to get my div boxes to go together
you just need to:
use
float:leftfor your sidebar and content. this makes them go to the left side of the line. you should use this when you need two (or more) elements side by side. read this for a description on how float works.move sidebar element to before content.
also use
display:inline-blockfor your sidebar and content. so they can have width and height.add an element with
clear:bothafter them. this clears float on both sides, and allows next elements not to have float.please note that
border-widthis not counted as elementwidth, and your content no longer needs amargin-rightvalue.
=================================
<html>
<head>
<style>
@charset "utf-8";
/* CSS Document */
#header {
height: 250px;
width: 728px;
border: dashed #000;
text-align:center;
font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
font-size:12px;
}
#footer {
height: 28px;
width: 728px;
border: dashed #000;
text-align:center;
font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
font-size:12px;
}
#left-nav {
float:left;
display:inline-block;
height: 500px;
width: 150px;
border: dashed #000;
text-align: center;
font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
font-size: 14px;
position: relative;
}
#content-box {
float:left;
display:inline-block;
height: 500px;
width: 572px;
border: dashed #000;
margin-right: 0px;
margin-top: 0px;
margin-bottom: 0px;
}
#clear{
clear:both;
}
#container{
display:inline-block;
}
body{
text-align:center;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
this is the header
</div>
<div id="left-nav">
<ul id="left-nav-links">
<li> <a href="#"> Link Item #1 </a></li>
<li> <a href="#"> Link Item #2 </a></li>
<li> <a href="#"> Link Item #3 </a></li>
<li> <a href="#"> Link Item #4 </a></li>
<li> <a href="#"> Link Item #5 </a></li>
</ul>
</div>
<div id="content-box">
</div>
<div id=clear></div>
<div id="footer">
this is the footer
</div>
</div>
</body>
</html>
Comment by Nasser Torabzade on Opening popup without scrolling bar
Comment by Nasser Torabzade on socket io mouse click event
Answer by Nasser Torabzade for socket io mouse click event
Client side:
In client side, you should first define an event listener for every type of event you need (using jQuery). In that listener, simply emit an socket.io event containing ID of element that triggered the event, so server can broadcast that to all other clients.
Also, if an event received from server, you should simulate that on it's corresponding element via jQuery.
$(document).on('click', function(event){
socket.emit('myClick', {id: event.target});
}
var socket = io.connect('http://localhost');
socket.on('myClick', function (data) {
$(data.id).trigger('click');
}
Server side:
In server side, just emit whatever event that was triggered, to all other clients except sender.
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.on('myClick', function (data) {
socket.broadcast.emit('myClick', data);
});
});
Answer by Nasser Torabzade for socket io mouse click event
Client side:
In client side, you should first define an event listener for every type of event you need (using jQuery). In that listener, simply emit an socket.io event containing ID of element that triggered the event, so server can broadcast that to all other clients.
Also, if an event received from server, you should simulate that on it's corresponding element via jQuery.
$(document).on('click', function(event){
socket.emit('myClick', {id: event.target});
}
var socket = io.connect('http://localhost');
socket.on('myClick', function (data) {
$(data.id).trigger('click');
}
Server side:
In server side, just emit whatever event that was triggered, to all other clients except sender.
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.on('myClick', function (data) {
socket.broadcast.emit('myClick', data);
});
});
Answer by Nasser for socket io mouse click event
client side:
in client side, you should first define an event listener for every type of event you need (using jQuery). in that listener, simply emit an socket.io event containing ID of element that triggered the event. so server can broadcast that to all other clients.
also, if an event received from server, you should simulate that on it's corresponding element via jQuery.
$(document).on('click', function(event){
socket.emit('myClick', {id: event.target});
}
var socket = io.connect('http://localhost');
socket.on('myClick', function (data) {
$(data.id).trigger('click');
}
server side:
in server side, just emit whatever event that was triggered, to all other clients except sender.
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.on('myClick', function (data) {
socket.broadcast.emit('myClick', data);
});
});
Answer by Nasser Torabzade for Opening popup without scrolling bar
add this to your css file:
.dialog-iframe{
overflow-y: scroll;
}
Answer by Nasser Torabzade for Finding field.value in JSON array
you can do it with a simple function, no third party modules needed:
var x = [{ a: 1, b: 2}, { a: 11, b: 12}, { a: 31, b: 23}, { a: 51, b: 24}];
function getIndexOf(value){
for(var i=0; i<x.lengh; i++){
if(x[i].a == value)
return i;
}
}
alert(getIndexOf(value)); // output is: 1
