-
-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented userconfig, and the ability to flip up/down counting dire…
- Loading branch information
Showing
8 changed files
with
207 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var debug = require('debug')('lib/userconfig'); | ||
var system; | ||
|
||
function userconfig(system) { | ||
var self = this; | ||
|
||
self.userconfig = {}; | ||
|
||
system.emit('db_get', 'userconfig', function(config) { | ||
self.userconfig = config; | ||
for (var key in config) { | ||
system.emit('userconfig_update', key, config[key]); | ||
} | ||
}); | ||
|
||
system.on('get_userconfig', function(cb) { | ||
cb(self.userconfig); | ||
}); | ||
|
||
system.emit('io_get', function (io) { | ||
|
||
io.on('connect', function (socket) { | ||
|
||
debug('socket ' + socket.id + ' connected'); | ||
|
||
socket.on('set_userconfig_key', function(key,value) { | ||
self.userconfig[key] = value; | ||
debug('-------------- set_userconfig_key', key, value); | ||
socket.broadcast.emit('set_userconfig_key', key, value); | ||
system.emit('userconfig_update', key, value); | ||
system.emit('db_save'); | ||
}); | ||
|
||
socket.on('get_userconfig_all', function() { | ||
socket.emit('get_userconfig_all', self.userconfig); | ||
}); | ||
|
||
|
||
|
||
socket.on('disconnect', function () { | ||
debug('socket ' + socket.id + ' disconnected'); | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
} | ||
|
||
module.exports = function (system) { | ||
return new userconfig(system); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var userconfig = {}; | ||
|
||
$(function() { | ||
|
||
|
||
var userConfigUpdate = function() { | ||
|
||
// set the page direction flipped option | ||
var state = userconfig.page_direction_flipped; | ||
var $cb = $('#userconfig_page_direction_flipped'); | ||
|
||
if (state === true) { | ||
$cb.prop('checked', true); | ||
} else { | ||
$cb.prop('checked', false); | ||
} | ||
|
||
}; | ||
|
||
// when userconfig is changed from the userconfig tab | ||
$('#userconfig_page_direction_flipped').click(function() { | ||
console.log('clicked', $(this).prop('checked') ); | ||
if ($(this).prop('checked') == true) { | ||
socket.emit('set_userconfig_key', 'page_direction_flipped', true); | ||
} else { | ||
socket.emit('set_userconfig_key', 'page_direction_flipped', false); | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// when server updates the entire config array | ||
socket.on('get_userconfig_all', function(config) { | ||
console.log('updating entire userconfig:', config) | ||
userconfig = config; | ||
userConfigUpdate(); | ||
}); | ||
|
||
// when other browsers update userconfig | ||
socket.on('set_userconfig_key', function(key, value) { | ||
userconfig[key]=value; | ||
userConfigUpdate(); | ||
}); | ||
|
||
// ask for the entire config | ||
socket.emit('get_userconfig_all'); | ||
|
||
|
||
}); |