From 4c8f69b7c55f1a8ba8e8d338c2cee6bac0cc85c4 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 8 Jul 2012 18:59:46 +0200 Subject: [PATCH 01/10] Use v8 to parse settings.json --- src/node/utils/Settings.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index e60446df4..aeeb9015e 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -24,6 +24,7 @@ var os = require("os"); var path = require('path'); var argv = require('./Cli').argv; var npm = require("npm/lib/npm.js"); +var vm = require('vm'); /* Root path of the installation */ exports.root = path.normalize(path.join(npm.dir, "..")); @@ -45,6 +46,7 @@ exports.dbType = "dirty"; * This setting is passed with dbType to ueberDB to set up the database */ exports.dbSettings = { "filename" : path.join(exports.root, "dirty.db") }; + /** * The default Text of a new pad */ @@ -102,33 +104,25 @@ exports.abiwordAvailable = function() // Discover where the settings file lives var settingsFilename = argv.settings || "settings.json"; -if (settingsFilename.charAt(0) != '/') { - settingsFilename = path.normalize(path.join(root, settingsFilename)); -} +settingsFilename = path.resolve(path.join(root, settingsFilename)); -var settingsStr +var settingsStr; try{ //read the settings sync - settingsStr = fs.readFileSync(settingsFilename).toString(); + settingsStr = fs.readFileSync(settingsFilename); } catch(e){ console.warn('No settings file found. Using defaults.'); - settingsStr = '{}'; } - -//remove all comments -settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,""); -//try to parse the settings +// try to parse the settings var settings; -try -{ - settings = JSON.parse(settingsStr); -} -catch(e) -{ - console.error("There is a syntax error in your settings.json file"); - console.error(e.message); - process.exit(1); +try { + if(settingsStr) { + settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json"); + } +}catch(e){ + console.warn('There was an error processing your settings.json file. Using defaults.'); + console.warn(e.message); } //loop trough the settings From 885844667887411c8fc2822ab1914b7277bcb4ca Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 10 Jul 2012 21:38:14 +0200 Subject: [PATCH 02/10] Exit on error. --- src/node/utils/Settings.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index aeeb9015e..68e58eb22 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -111,7 +111,8 @@ try{ //read the settings sync settingsStr = fs.readFileSync(settingsFilename); } catch(e){ - console.warn('No settings file found. Using defaults.'); + console.error('No settings file found.'); + process.exit(1); } // try to parse the settings @@ -121,8 +122,8 @@ try { settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json"); } }catch(e){ - console.warn('There was an error processing your settings.json file. Using defaults.'); - console.warn(e.message); + console.error('There was an error processing your settings.json file: '+e.message); + process.exit(1); } //loop trough the settings @@ -142,8 +143,7 @@ for(var i in settings) //this setting is unkown, output a warning and throw it away else { - console.warn("Unkown Setting: '" + i + "'"); - console.warn("This setting doesn't exist or it was removed"); + console.warn("Unkown Setting: '" + i + "'. This setting doesn't exist or it was removed"); } } From 87f26334d1259f6422c3a2b7d9325b611c72316b Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 10 Jul 2012 21:55:35 +0200 Subject: [PATCH 03/10] Fix typo. --- src/node/utils/Settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 68e58eb22..205b675f2 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -143,7 +143,7 @@ for(var i in settings) //this setting is unkown, output a warning and throw it away else { - console.warn("Unkown Setting: '" + i + "'. This setting doesn't exist or it was removed"); + console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed"); } } From f09dd0f3fba8630d221dba3a652dad0a229aa509 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 11 Jul 2012 15:34:33 +0200 Subject: [PATCH 04/10] Put toString() back in. --- src/node/utils/Settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 205b675f2..1b7c3f46c 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -109,7 +109,7 @@ settingsFilename = path.resolve(path.join(root, settingsFilename)); var settingsStr; try{ //read the settings sync - settingsStr = fs.readFileSync(settingsFilename); + settingsStr = fs.readFileSync(settingsFilename).toString(); } catch(e){ console.error('No settings file found.'); process.exit(1); From dc09323d8f6ee5a65f301bb677d9e18a54672322 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 11 Jul 2012 15:36:41 +0200 Subject: [PATCH 05/10] Don't exit if no settings file was found. --- src/node/utils/Settings.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 1b7c3f46c..dd34ac5ee 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -111,8 +111,7 @@ try{ //read the settings sync settingsStr = fs.readFileSync(settingsFilename).toString(); } catch(e){ - console.error('No settings file found.'); - process.exit(1); + console.warn('No settings file found. Continuing using defaults!'); } // try to parse the settings From dc9eda9364eec93983ba95ea3560c5c72296af0b Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 12 Jul 2012 20:18:33 +0200 Subject: [PATCH 06/10] Use Tinycon to display chat mentions in favicon. --- src/static/js/chat.js | 12 +- src/static/js/tinycon.js | 237 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+), 7 deletions(-) create mode 100644 src/static/js/tinycon.js diff --git a/src/static/js/chat.js b/src/static/js/chat.js index 18904352f..9dfc9dc1f 100644 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -23,11 +23,12 @@ var padutils = require('./pad_utils').padutils; var padcookie = require('./pad_cookie').padcookie; +require('./tinycon'); + var chat = (function() { var isStuck = false; var chatMentions = 0; - var title = document.title; var self = { show: function () { @@ -35,7 +36,7 @@ var chat = (function() $("#chatbox").show(); self.scrollDown(); chatMentions = 0; - document.title = title; + Tinycon.setBubble(0); }, stickToScreen: function(fromInitialCall) // Make chat stick to right hand side of screen { @@ -126,12 +127,9 @@ var chat = (function() // chat throb stuff -- Just make it throw for twice as long if(wasMentioned && !alreadyFocused) { // If the user was mentioned show for twice as long and flash the browser window - if (chatMentions == 0){ - title = document.title; - } $('#chatthrob').html(""+authorName+"" + ": " + text).show().delay(4000).hide(400); chatMentions++; - document.title = "("+chatMentions+") " + title; + Tinycon.setBubble(chatMentions); } else { @@ -141,7 +139,7 @@ var chat = (function() // Clear the chat mentions when the user clicks on the chat input box $('#chatinput').click(function(){ chatMentions = 0; - document.title = title; + Tinycon.setBubble(0); }); self.scrollDown(); diff --git a/src/static/js/tinycon.js b/src/static/js/tinycon.js new file mode 100644 index 000000000..0e6a10a10 --- /dev/null +++ b/src/static/js/tinycon.js @@ -0,0 +1,237 @@ +/*! + * Tinycon - A small library for manipulating the Favicon + * Tom Moor, http://tommoor.com + * Copyright (c) 2012 Tom Moor + * MIT Licensed + * @version 0.2.6 +*/ + +(function(){ + + var Tinycon = {}; + var currentFavicon = null; + var originalFavicon = null; + var originalTitle = document.title; + var faviconImage = null; + var canvas = null; + var options = {}; + var defaults = { + width: 7, + height: 9, + font: '10px arial', + colour: '#ffffff', + background: '#F03D25', + fallback: true + }; + + var ua = (function () { + var agent = navigator.userAgent.toLowerCase(); + // New function has access to 'agent' via closure + return function (browser) { + return agent.indexOf(browser) !== -1; + }; + }()); + + var browser = { + ie: ua('msie'), + chrome: ua('chrome'), + webkit: ua('chrome') || ua('safari'), + safari: ua('safari') && !ua('chrome'), + mozilla: ua('mozilla') && !ua('chrome') && !ua('safari') + }; + + // private methods + var getFaviconTag = function(){ + + var links = document.getElementsByTagName('link'); + + for(var i=0, len=links.length; i < len; i++) { + if ((links[i].getAttribute('rel') || '').match(/\bicon\b/)) { + return links[i]; + } + } + + return false; + }; + + var removeFaviconTag = function(){ + + var links = document.getElementsByTagName('link'); + var head = document.getElementsByTagName('head')[0]; + + for(var i=0, len=links.length; i < len; i++) { + var exists = (typeof(links[i]) !== 'undefined'); + if (exists && links[i].getAttribute('rel') === 'icon') { + head.removeChild(links[i]); + } + } + }; + + var getCurrentFavicon = function(){ + + if (!originalFavicon || !currentFavicon) { + var tag = getFaviconTag(); + originalFavicon = currentFavicon = tag ? tag.getAttribute('href') : '/favicon.ico'; + } + + return currentFavicon; + }; + + var getCanvas = function (){ + + if (!canvas) { + canvas = document.createElement("canvas"); + canvas.width = 16; + canvas.height = 16; + } + + return canvas; + }; + + var setFaviconTag = function(url){ + removeFaviconTag(); + + var link = document.createElement('link'); + link.type = 'image/x-icon'; + link.rel = 'icon'; + link.href = url; + document.getElementsByTagName('head')[0].appendChild(link); + }; + + var log = function(message){ + if (window.console) window.console.log(message); + }; + + var drawFavicon = function(num, colour) { + + // fallback to updating the browser title if unsupported + if (!getCanvas().getContext || browser.ie || browser.safari || options.fallback === 'force') { + return updateTitle(num); + } + + var context = getCanvas().getContext("2d"); + var colour = colour || '#000000'; + var num = num || 0; + var src = getCurrentFavicon(); + + faviconImage = new Image(); + faviconImage.onload = function() { + + // clear canvas + context.clearRect(0, 0, 16, 16); + + // draw original favicon + context.drawImage(faviconImage, 0, 0, faviconImage.width, faviconImage.height, 0, 0, 16, 16); + + // draw bubble over the top + if (num > 0) drawBubble(context, num, colour); + + // refresh tag in page + refreshFavicon(); + }; + + // allow cross origin resource requests if the image is not a data:uri + // as detailed here: https://github.com/mrdoob/three.js/issues/1305 + if (!src.match(/^data/)) { + faviconImage.crossOrigin = 'anonymous'; + } + + faviconImage.src = src; + }; + + var updateTitle = function(num) { + + if (options.fallback) { + if (num > 0) { + document.title = '('+num+') ' + originalTitle; + } else { + document.title = originalTitle; + } + } + }; + + var drawBubble = function(context, num, colour) { + + // bubble needs to be larger for double digits + var len = (num+"").length-1; + var width = options.width + (6*len); + var w = 16-width; + var h = 16-options.height; + + // webkit seems to render fonts lighter than firefox + context.font = (browser.webkit ? 'bold ' : '') + options.font; + context.fillStyle = options.background; + context.strokeStyle = options.background; + context.lineWidth = 1; + + // bubble + context.fillRect(w,h,width-1,options.height); + + // rounded left + context.beginPath(); + context.moveTo(w-0.5,h+1); + context.lineTo(w-0.5,15); + context.stroke(); + + // rounded right + context.beginPath(); + context.moveTo(15.5,h+1); + context.lineTo(15.5,15); + context.stroke(); + + // bottom shadow + context.beginPath(); + context.strokeStyle = "rgba(0,0,0,0.3)"; + context.moveTo(w,16); + context.lineTo(15,16); + context.stroke(); + + // number + context.fillStyle = options.colour; + context.textAlign = "right"; + context.textBaseline = "top"; + + // unfortunately webkit/mozilla are a pixel different in text positioning + context.fillText(num, 15, browser.mozilla ? 7 : 6); + }; + + var refreshFavicon = function(){ + // check support + if (!getCanvas().getContext) return; + + setFaviconTag(getCanvas().toDataURL()); + }; + + + // public methods + Tinycon.setOptions = function(custom){ + options = {}; + + for(var key in defaults){ + options[key] = custom.hasOwnProperty(key) ? custom[key] : defaults[key]; + } + return this; + }; + + Tinycon.setImage = function(url){ + currentFavicon = url; + refreshFavicon(); + return this; + }; + + Tinycon.setBubble = function(num, colour){ + + // validate + if(isNaN(parseFloat(num)) || !isFinite(num)) return log('Bubble must be a number'); + + drawFavicon(num, colour); + return this; + }; + + Tinycon.reset = function(){ + Tinycon.setImage(originalFavicon); + }; + + Tinycon.setOptions(defaults); + window.Tinycon = Tinycon; +})(); From b1123d11b60b6325e0f3dc5cd343814cd2c264bf Mon Sep 17 00:00:00 2001 From: 0ip Date: Sat, 14 Jul 2012 20:35:26 +0300 Subject: [PATCH 07/10] Correct path --- src/templates/admin/plugins.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/admin/plugins.html b/src/templates/admin/plugins.html index 104f6b986..3dad3bd01 100644 --- a/src/templates/admin/plugins.html +++ b/src/templates/admin/plugins.html @@ -21,7 +21,7 @@

Etherpad Lite

- Technical information on installed plugins + Technical information on installed plugins

Installed plugins

From 9bd23acb3dd14e381b7c97041a2a70712890761d Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Tue, 17 Jul 2012 10:12:10 -0700 Subject: [PATCH 08/10] Add userJoinOrUpdate hook This hook fires on the client side, whenever a user joins or updates (hence the name). It will pass one thing, the user's info, into the context. This is mostly just for notification purposes. --- src/static/js/pad_userlist.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/static/js/pad_userlist.js b/src/static/js/pad_userlist.js index d83825854..474f9b0e1 100644 --- a/src/static/js/pad_userlist.js +++ b/src/static/js/pad_userlist.js @@ -21,6 +21,7 @@ */ var padutils = require('./pad_utils').padutils; +var hooks = require('./pluginfw/hooks'); var myUserInfo = {}; @@ -529,6 +530,10 @@ var paduserlist = (function() return; } + hooks.callAll('userJoinOrUpdate', { + userInfo: info + }); + var userData = {}; userData.color = typeof info.colorId == "number" ? clientVars.colorPalette[info.colorId] : info.colorId; userData.name = info.name; From 9aed433ad5947fbbeeac1bf94c0e4961f0833087 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 18 Jul 2012 15:54:53 +0200 Subject: [PATCH 09/10] Fix #880 Remove call to padsavedrevs.handleIsFullyConnected --- src/static/js/pad.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/static/js/pad.js b/src/static/js/pad.js index df6342e2d..a22e181a2 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -790,8 +790,6 @@ var pad = { }, 1000); } - padsavedrevs.handleIsFullyConnected(isConnected); - // pad.determineSidebarVisibility(isConnected && !isInitialConnect); pad.determineChatVisibility(isConnected && !isInitialConnect); pad.determineAuthorshipColorsVisibility(); From c3ddff3fa061a48ae7178c62038e143ab5304ec6 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 19 Jul 2012 11:34:14 +0200 Subject: [PATCH 10/10] Notify the user, if JavaScript is disabled. --- src/templates/pad.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/templates/pad.html b/src/templates/pad.html index 02af9b107..36d6334c2 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -148,7 +148,10 @@
-
Loading...
+
+

Loading...

+ +