From 631235e269a0e913207cf17f38855eb156e21f75 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sat, 10 Apr 2010 23:15:43 +0200 Subject: Generalized the page.ejs a bit more so that it can be used by all pages for real --- etherpad/src/etherpad/control/pad/pad_control.js | 34 +++----------------- etherpad/src/etherpad/helpers.js | 4 +++ etherpad/src/etherpad/pad/padutils.js | 37 ++++++++++++++++++++++ .../src/themes/default/templates/pad/pad_body2.ejs | 10 ++++-- etherpad/src/themes/default/templates/page.ejs | 8 ++--- 5 files changed, 55 insertions(+), 38 deletions(-) diff --git a/etherpad/src/etherpad/control/pad/pad_control.js b/etherpad/src/etherpad/control/pad/pad_control.js index 3d32355..2a6a1be 100644 --- a/etherpad/src/etherpad/control/pad/pad_control.js +++ b/etherpad/src/etherpad/control/pad/pad_control.js @@ -331,15 +331,6 @@ function render_pad(localPadId) { var specialKey = request.params.specialKey || (sessions.isAnEtherpadAdmin() ? collab_server.getSpecialKey('invisible') : null); - if (request.params.fullScreen) { // tokbox, embedding - opts.fullScreen = true; - } - if (request.params.tokbox) { - opts.tokbox = true; - } - if (request.params.sidebar) { - opts.sidebar = Boolean(Number(request.params.sidebar)); - } helpers.addClientVars({ padId: localPadId, @@ -365,34 +356,17 @@ function render_pad(localPadId) { userColor: assignColorId(pad, userId), specialKey: specialKey, specialKeyTranslation: collab_server.translateSpecialKey(specialKey), - opts: opts }); }); var isProUser = (isPro && ! padusers.isGuest(userId)); - var isFullWidth = false; - var hideSidebar = false; - var cookiePrefs = padutils.getPrefsCookieData(); - if (cookiePrefs) { - isFullWidth = !! cookiePrefs.fullWidth; - hideSidebar = !! cookiePrefs.hideSidebar; - } - if (opts.fullScreen) { - isFullWidth = true; - if (opts.tokbox) { - hideSidebar = true; - } - } - if ('sidebar' in opts) { - hideSidebar = ! opts.sidebar; - } - var bodyClass = (isFullWidth ? "fullwidth" : "limwidth")+ + padutils.setOptsAndCookiePrefs(request); + var prefs = helpers.getClientVar('cookiePrefsToSet'); + var bodyClass = (prefs.isFullWidth ? "fullwidth" : "limwidth") + " "+(isPro ? "propad" : "nonpropad")+" "+ (isProUser ? "prouser" : "nonprouser"); - var cookiePrefsToSet = {fullWidth:isFullWidth, hideSidebar:hideSidebar}; - helpers.addClientVars({cookiePrefsToSet: cookiePrefsToSet}); renderHtml("pad/pad_body2.ejs", {localPadId:localPadId, @@ -404,7 +378,7 @@ function render_pad(localPadId) { isProAccountHolder: isProUser, account: getSessionProAccount(), // may be falsy toHTML: toHTML, - prefs: {isFullWidth:isFullWidth, hideSidebar:hideSidebar}, + prefs: prefs, signinUrl: '/ep/account/sign-in?cont='+ encodeURIComponent(request.url), fullSuperdomain: pro_utils.getFullSuperdomainHost() diff --git a/etherpad/src/etherpad/helpers.js b/etherpad/src/etherpad/helpers.js index e16c2f7..aec3bc3 100644 --- a/etherpad/src/etherpad/helpers.js +++ b/etherpad/src/etherpad/helpers.js @@ -77,6 +77,10 @@ function addClientVars(vars) { }); } +function getClientVar(name) { + return _hd().clientVars[name]; +} + function addToHead(stuff) { _hd().headExtra += stuff; } diff --git a/etherpad/src/etherpad/pad/padutils.js b/etherpad/src/etherpad/pad/padutils.js index 2fdf579..dc4c9ab 100644 --- a/etherpad/src/etherpad/pad/padutils.js +++ b/etherpad/src/etherpad/pad/padutils.js @@ -25,6 +25,7 @@ import("etherpad.pro.pro_accounts"); import("etherpad.pro.pro_padmeta"); import("etherpad.pad.model"); import("etherpad.sessions.getSession"); +import("etherpad.helpers"); jimport("java.lang.System.out.println"); @@ -152,3 +153,39 @@ function getProDisplayTitle(localPadId, title) { } } + +function setOptsAndCookiePrefs(request) { + opts = {}; + if (request.params.fullScreen) { // tokbox, embedding + opts.fullScreen = true; + } + if (request.params.tokbox) { + opts.tokbox = true; + } + if (request.params.sidebar) { + opts.sidebar = Boolean(Number(request.params.sidebar)); + } + helpers.addClientVars({opts: opts}); + + + var prefs = getPrefsCookieData(); + + var prefsToSet = { + fullWidth:false, + hideSidebar:false + }; + if (prefs) { + prefsToSet.isFullWidth = !! prefs.fullWidth; + prefsToSet.hideSidebar = !! prefs.hideSidebar; + } + if (opts.fullScreen) { + prefsToSet.isFullWidth = true; + if (opts.tokbox) { + prefsToSet.hideSidebar = true; + } + } + if ('sidebar' in opts) { + prefsToSet.hideSidebar = ! opts.sidebar; + } + helpers.addClientVars({cookiePrefsToSet: prefsToSet}); +} diff --git a/etherpad/src/themes/default/templates/pad/pad_body2.ejs b/etherpad/src/themes/default/templates/pad/pad_body2.ejs index a19e685..5c886fb 100644 --- a/etherpad/src/themes/default/templates/pad/pad_body2.ejs +++ b/etherpad/src/themes/default/templates/pad/pad_body2.ejs @@ -14,9 +14,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ %> -<% template.inherit('page.ejs') %> - <% + template.inherit('page.ejs'); + helpers.setHtmlTitle("EtherPad: "+pageTitle); helpers.includeJs("ace.js"); helpers.includeJs("collab_client.js"); @@ -54,6 +54,11 @@ limitations under the License. */ %> %> +<% template.define('docBarTitle', function() { var ejs_data=''; %> + <%= initialTitle %> +<% return ejs_data; }); %> + + <% template.define('docBarTitleEditor', function() { var ejs_data=''; %> <% if (isProAccountHolder) { %>
- <%: template.use('docBarTitle'); %> - + <%: template.use('docBarTitle'); %> - <% - plugins.callHookStr('docbarItemsAll', {}, '', ''); - plugins.callHookStr('docbarItemsPad', {}, '', ''); - %> + <%: plugins.callHookStr('docbarItemsAll', {}, '', ''); %> <%: template.use('docBarItems'); %> -- cgit v1.2.3
<%= initialTitle %> ', '', '', '