Merge pull request #1004 from yourcelf/develop

Add `userColor` query param to set initial color
pull/1034/merge
John McLear 2012-10-04 10:57:16 -07:00
commit a1280fd917
3 changed files with 31 additions and 0 deletions

View File

@ -358,6 +358,14 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
{ {
var userInfo = msg.userInfo; var userInfo = msg.userInfo;
var id = userInfo.userId; var id = userInfo.userId;
// Avoid a race condition when setting colors. If our color was set by a
// query param, ignore our own "new user" message's color value.
if (id === initialUserInfo.userId && initialUserInfo.globalUserColor)
{
msg.userInfo.colorId = initialUserInfo.globalUserColor;
}
if (userSet[id]) if (userSet[id])
{ {

View File

@ -24,6 +24,13 @@
var colorutils = {}; var colorutils = {};
// Check that a given value is a css hex color value, e.g.
// "#ffffff" or "#fff"
colorutils.isCssHex = function(cssColor)
{
return /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(cssColor);
}
// "#ffffff" or "#fff" or "ffffff" or "fff" to [1.0, 1.0, 1.0] // "#ffffff" or "#fff" or "ffffff" or "fff" to [1.0, 1.0, 1.0]
colorutils.css2triple = function(cssColor) colorutils.css2triple = function(cssColor)
{ {

View File

@ -43,6 +43,7 @@ var padmodals = require('./pad_modals').padmodals;
var padsavedrevs = require('./pad_savedrevs'); var padsavedrevs = require('./pad_savedrevs');
var paduserlist = require('./pad_userlist').paduserlist; var paduserlist = require('./pad_userlist').paduserlist;
var padutils = require('./pad_utils').padutils; var padutils = require('./pad_utils').padutils;
var colorutils = require('./colorutils').colorutils;
var createCookie = require('./pad_utils').createCookie; var createCookie = require('./pad_utils').createCookie;
var readCookie = require('./pad_utils').readCookie; var readCookie = require('./pad_utils').readCookie;
@ -114,6 +115,7 @@ function getParams()
var showControls = params["showControls"]; var showControls = params["showControls"];
var showChat = params["showChat"]; var showChat = params["showChat"];
var userName = params["userName"]; var userName = params["userName"];
var userColor = params["userColor"];
var showLineNumbers = params["showLineNumbers"]; var showLineNumbers = params["showLineNumbers"];
var useMonospaceFont = params["useMonospaceFont"]; var useMonospaceFont = params["useMonospaceFont"];
var IsnoColors = params["noColors"]; var IsnoColors = params["noColors"];
@ -162,6 +164,11 @@ function getParams()
// If the username is set as a parameter we should set a global value that we can call once we have initiated the pad. // If the username is set as a parameter we should set a global value that we can call once we have initiated the pad.
settings.globalUserName = decodeURIComponent(userName); settings.globalUserName = decodeURIComponent(userName);
} }
if(userColor)
// If the userColor is set as a parameter, set a global value to use once we have initiated the pad.
{
settings.globalUserColor = decodeURIComponent(userColor);
}
if(rtl) if(rtl)
{ {
if(rtl == "true") if(rtl == "true")
@ -363,6 +370,14 @@ function handshake()
pad.myUserInfo.name = settings.globalUserName; pad.myUserInfo.name = settings.globalUserName;
$('#myusernameedit').attr({"value":settings.globalUserName}); // Updates the current users UI $('#myusernameedit').attr({"value":settings.globalUserName}); // Updates the current users UI
} }
if (settings.globalUserColor !== false && colorutils.isCssHex(settings.globalUserColor))
{
// Add a 'globalUserColor' property to myUserInfo, so collabClient knows we have a query parameter.
pad.myUserInfo.globalUserColor = settings.globalUserColor;
pad.notifyChangeColor(settings.globalUserColor); // Updates pad.myUserInfo.colorId
paduserlist.setMyUserInfo(pad.myUserInfo);
}
} }
//This handles every Message after the clientVars //This handles every Message after the clientVars
else else
@ -1025,6 +1040,7 @@ var settings = {
, noColors: false , noColors: false
, useMonospaceFontGlobal: false , useMonospaceFontGlobal: false
, globalUserName: false , globalUserName: false
, globalUserColor: false
, rtlIsTrue: false , rtlIsTrue: false
}; };