From cbeaa8d60947aed8d8b572c4828f31a9a7801174 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 8 Jul 2016 16:45:48 +0200 Subject: [PATCH] major refactoring for toolbar. CAN HAZ LESS --- www/common/toolbar.js | 228 ++++++++++++++++-------------------------- 1 file changed, 85 insertions(+), 143 deletions(-) diff --git a/www/common/toolbar.js b/www/common/toolbar.js index a86cb102b..212480710 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -1,160 +1,88 @@ define([ - '/common/messages.js' + '/common/messages.js', + '/bower_components/jquery/dist/jquery.min.js', ], function (Messages) { + var $ = window.jQuery; - /** Id of the element for getting debug info. */ - var DEBUG_LINK_CLS = 'rtwysiwyg-debug-link'; + var Bar = { + constants: {}, + }; /** Id of the div containing the user list. */ - var USER_LIST_CLS = 'rtwysiwyg-user-list'; + var USER_LIST_CLS = Bar.constants.userlist = 'cryptpad-user-list'; /** Id of the button to change my username. */ - var USERNAME_BUTTON_GROUP = 'cryptpad-changeName'; + var USERNAME_BUTTON_GROUP = Bar.constants.changeName = 'cryptpad-changeName'; /** Id of the div containing the lag info. */ - var LAG_ELEM_CLS = 'rtwysiwyg-lag'; + var LAG_ELEM_CLS = Bar.constants.lag = 'cryptpad-lag'; /** The toolbar class which contains the user list, debug link and lag. */ - var TOOLBAR_CLS = 'rtwysiwyg-toolbar'; + var TOOLBAR_CLS = Bar.constants.toolbar = 'cryptpad-toolbar'; + + var LEFTSIDE_CLS = Bar.constants.leftside = 'cryptpad-toolbar-leftside'; + var RIGHTSIDE_CLS = Bar.constants.rightside = 'cryptpad-toolbar-rightside'; + + var BACK_CLS = Bar.constants.back = 'cryptpad-back'; + + var SPINNER_CLS = Bar.constants.spinner = 'cryptpad-spinner'; /** Key in the localStore which indicates realtime activity should be disallowed. */ - var LOCALSTORAGE_DISALLOW = 'rtwysiwyg-disallow'; + // TODO remove? will never be used in cryptpad + var LOCALSTORAGE_DISALLOW = Bar.constants.localstorageDisallow = 'cryptpad-disallow'; var SPINNER_DISAPPEAR_TIME = 3000; var SPINNER = [ '-', '\\', '|', '/' ]; var uid = function () { - return 'rtwysiwyg-uid-' + String(Math.random()).substring(2); + return 'cryptpad-uid-' + String(Math.random()).substring(2); }; - var createRealtimeToolbar = function ($container) { - var id = uid(); - $container.prepend( - '
' + - '
' + - '
' + - '
' - ); - var toolbar = $container.find('#'+id); - - var swap = function (str, dict) { - return str.replace(/\{\{(.*?)\}\}/g, function (all, block) { - //console.log(block); - return dict[block] || block; - }); - }; + var $style; + + var styleToolbar = function ($container, href) { + href = href || '/customize/toolbar.css'; + + $.ajax({ + url: href, + dataType: 'text', + success: function (data) { + $container.append($(' - */}.toString().slice(14,-3), { - TOOLBAR_CLS: TOOLBAR_CLS, - USERNAME_BUTTON_GROUP: USERNAME_BUTTON_GROUP, - DEBUG_LINK_CLS: DEBUG_LINK_CLS, - }).trim(); - - toolbar.append(css); - return toolbar; + var createRealtimeToolbar = function ($container) { + var $toolbar = $('
', { + 'class': TOOLBAR_CLS, + id: uid(), + }) + .append($('
', {'class': LEFTSIDE_CLS})) + .append($('
', {'class': RIGHTSIDE_CLS})); + + $container.prepend($toolbar); + styleToolbar($container); + return $toolbar; }; var createEscape = function ($container) { - var id = uid(); - $container.append('
⇐ Back
'); - var $ret = $container.find('#'+id); - $ret.on('click', function () { + var $back = $('
', { + 'class': BACK_CLS, + id: uid(), + }).html('⇐ Back').click(function () { window.location.href = '/'; }); - return $ret[0]; + $container.append($back); + return $back[0]; }; var createSpinner = function ($container) { - var id = uid(); - $container.append('
'); - return $container.find('#'+id)[0]; + var $spinner = $('
', { + id: uid(), + 'class': SPINNER_CLS, + }); + $container.append($spinner); + return $spinner[0]; }; var kickSpinner = function (spinnerElement, reversed) { @@ -168,9 +96,12 @@ define([ }; var createUserList = function ($container) { - var id = uid(); - $container.append('
'); - return $container.find('#'+id)[0]; + var $userlist = $('
', { + 'class': USER_LIST_CLS, + id: uid(), + }); + $container.append($userlist); + return $userlist[0]; }; var getOtherUsers = function(myUserName, userList, userData) { @@ -191,9 +122,17 @@ define([ }; var createChangeName = function($container, userList, buttonID) { - var id = uid(); - userList.innerHTML = ''; - return $container.find('#'+id)[0]; + var $span = $('', { + id: uid(), + }); + var $button = $('