Monthly Archives: مهر 1392
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
Answer by Nasser for jQuery click event not firing for anchor when contained within slickgrid cell
$('PARENT_ELEMENT').on('click','a[rel=XYZ]',function (e) {
$(this).replaceWith('some html');
});
Just make sure that 'PARENT_ELEMENT'
exist when you bind your event. Safest way is to use 'body'
or document
as 'PARENT_ELEMENT'
.
Answer by Nasser Torabzade for How to increment variable by 1 to limit, then rewind and repeat increment – jQuery
for(i=0,a=1; i<20; i++,a++){
//do something with var
a==10 ? a=1 : null ;
}
Answer by Nasser Torabzade for 100% width Background Image
this excellent blog post explains exactly what you need, without any third party tools:
http://css-tricks.com/perfect-full-page-background-image
also, there are some jQuery plugins for that, including:
nasser-torabzade opened issue LearnBoost/socket.io#1331
Comment by Nasser on How to access cookie data inside a socket.io connection?
Comment by Nasser Torabzade on How to access cookie data inside a socket.io connection?
socketPort
and httpPort
are different. and no your gist didn't work for me. can you please check my code in this gist? thanks for your time. :) Comment by Nasser Torabzade on How to access cookie data inside a socket.io connection?
http.createServer(onRequest).listen(httpPort);
function onRequest (request, response) {
// stuff for serving files
}
and another function for serving socket.io:
io.sockets.on('connection', function (socket) {
// stuff for handling events
}
and these two are called in my index.js , Do you think I need to change this architecture?