From 0d008aaa2e2c4145d67c53ca7c68441262626ee4 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 30 Aug 2017 17:57:10 +0200 Subject: [PATCH] Add indent settings to code2 --- www/code/main.js | 12 ++++++------ www/code2/inner.js | 22 +++++++++------------- www/code2/main.js | 9 --------- www/common/migrate-user-object.js | 4 ++-- www/common/sframe-common-outer.js | 7 +++++-- www/common/sframe-common.js | 4 ++-- www/common/sframe-protocol.js | 2 ++ www/pad/main.js | 9 --------- www/settings/main.js | 21 ++++++++++++--------- 9 files changed, 38 insertions(+), 52 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index 07f02e6a1..5e06572b6 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -68,21 +68,21 @@ define([ editor.setOption('indentWithTabs', useTabs); }; - var indentKey = 'cryptpad.indentUnit'; - var useTabsKey = 'cryptpad.indentWithTabs'; + var indentKey = 'indentUnit'; + var useTabsKey = 'indentWithTabs'; var proxy = Cryptpad.getProxy(); var updateIndentSettings = APP.updateIndentSettings = function () { - var indentUnit = proxy[indentKey]; - var useTabs = proxy[useTabsKey]; + var indentUnit = proxy.settings[indentKey]; + var useTabs = proxy.settings[useTabsKey]; setIndentation( typeof(indentUnit) === 'number'? indentUnit: 2, typeof(useTabs) === 'boolean'? useTabs: false); }; - proxy.on('change', [indentKey], updateIndentSettings); - proxy.on('change', [useTabsKey], updateIndentSettings); + proxy.on('change', ['settings', indentKey], updateIndentSettings); + proxy.on('change', ['settings', useTabsKey], updateIndentSettings); var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); diff --git a/www/code2/inner.js b/www/code2/inner.js index f7e045792..f59c6e8fa 100644 --- a/www/code2/inner.js +++ b/www/code2/inner.js @@ -84,7 +84,6 @@ define([ var readOnly = false; var cpNfInner; var metadataMgr; - var onLocal; var $bar = $('#cme_toolbox'); var isHistoryMode = false; @@ -110,30 +109,24 @@ define([ editor.setOption('indentWithTabs', useTabs); }; - var indentKey = 'cryptpad.indentUnit'; - var useTabsKey = 'cryptpad.indentWithTabs'; - + var indentKey = 'indentUnit'; + var useTabsKey = 'indentWithTabs'; var updateIndentSettings = function () { - var indentUnit = proxy[indentKey]; - var useTabs = proxy[useTabsKey]; + if (!metadataMgr) { return; } + var data = metadataMgr.getPrivateData().settings; + var indentUnit = data[indentKey]; + var useTabs = data[useTabsKey]; setIndentation( typeof(indentUnit) === 'number'? indentUnit: 2, typeof(useTabs) === 'boolean'? useTabs: false); }; - //proxy.on('change', [indentKey], updateIndentSettings); TODO RPC - //proxy.on('change', [useTabsKey], updateIndentSettings); TODO RPC - - - var setEditable = APP.setEditable = function (bool) { if (readOnly && bool) { return; } editor.setOption('readOnly', !bool); }; var Title; - var UserList; - var Metadata; var config = { readOnly: readOnly, @@ -260,6 +253,9 @@ define([ }; config.onInit = function (info) { + metadataMgr.onChangeLazy(updateIndentSettings); + updateIndentSettings(); + readOnly = metadataMgr.getPrivateData().readOnly; var titleCfg = { getHeadingText: CodeMirror.getHeadingText }; diff --git a/www/code2/main.js b/www/code2/main.js index cb3c22d44..9fe5a935c 100644 --- a/www/code2/main.js +++ b/www/code2/main.js @@ -9,15 +9,6 @@ define([ var requireConfig = RequireConfig(); // Loaded in load #2 - var CpNfOuter; - var Cryptpad; - var Crypto; - var Cryptget; - - var sframeChan; - var secret; - var hashes; - nThen(function (waitFor) { $(waitFor()); }).nThen(function (waitFor) { diff --git a/www/common/migrate-user-object.js b/www/common/migrate-user-object.js index 5cccd22b9..400c6489e 100644 --- a/www/common/migrate-user-object.js +++ b/www/common/migrate-user-object.js @@ -18,7 +18,7 @@ define([], function () { var key = parsed.hash + '.' + attr; var key2 = parsed.hash.slice(0,-1) + '.' + attr;// old pads not ending with / if (typeof(files[key]) !== "undefined" || typeof(files[key2]) !== "undefined") { - debug("Migrating pad attribute", attr, "for pad", id); + console.log("Migrating pad attribute", attr, "for pad", id); el[attr] = files[key] || files[key2]; delete files[key]; delete files[key2]; @@ -28,7 +28,7 @@ define([], function () { var filesData = files.filesData; if (!filesData) { return; } - var el, id, parsed; + var el, parsed; for (var id in filesData) { id = Number(id); el = filesData[id]; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 56271dec0..e96e19b0f 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -46,6 +46,7 @@ define([ var parsed = Cryptpad.parsePadUrl(window.location.href); if (!parsed.type) { throw new Error(); } var defaultTitle = Cryptpad.getDefaultName(parsed); + var proxy = Cryptpad.getProxy(); var updateMeta = function () { //console.log('EV_METADATA_UPDATE'); var name; @@ -65,7 +66,7 @@ define([ uid: Cryptpad.getUid(), avatar: Cryptpad.getAvatarUrl(), profile: Cryptpad.getProfileUrl(), - curvePublic: Cryptpad.getProxy().curvePublic, + curvePublic: proxy.curvePublic, netfluxId: Cryptpad.getNetwork().webChannels[0].myID, }, priv: { @@ -76,13 +77,15 @@ define([ availableHashes: hashes, isTemplate: Cryptpad.isTemplate(window.location.href), feedbackAllowed: Cryptpad.isFeedbackAllowed(), - friends: Cryptpad.getProxy().friends || {} + friends: proxy.friends || {}, + settings: proxy.settings || {} } }); }); }; Cryptpad.onDisplayNameChanged(updateMeta); sframeChan.onReg('EV_METADATA_UPDATE', updateMeta); + proxy.on('change', 'settings', updateMeta); Cryptpad.onError(function (info) { console.log('error'); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index f75720d7f..5e50209b6 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -286,15 +286,15 @@ define([ button.addClass('rightside-button'); } return button; - }; + /* funcs.storeLinkToClipboard = function (readOnly, cb) { ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) { if (cb) { cb(err); } }); }; */ - + Object.freeze(funcs); return { create: function (cb) { nThen(function (waitFor) { diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index f272d3743..747827316 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -82,4 +82,6 @@ define({ // Set the tab notification when the content of the pad changes 'EV_NOTIFY': true, + // Send the new settings to the inner iframe when they are changed in the proxy + 'EV_SETTINGS_UPDATE': true, }); diff --git a/www/pad/main.js b/www/pad/main.js index 7fb902b05..7484bdbdf 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -9,15 +9,6 @@ define([ var requireConfig = RequireConfig(); // Loaded in load #2 - var CpNfOuter; - var Cryptpad; - var Crypto; - var Cryptget; - - var sframeChan; - var secret; - var hashes; - nThen(function (waitFor) { $(waitFor()); }).nThen(function (waitFor) { diff --git a/www/settings/main.js b/www/settings/main.js index bc65e10fa..520f10dc8 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -131,6 +131,7 @@ define([ }; var createIndentUnitSelector = function (obj) { var proxy = obj.proxy; + proxy.settings = proxy.settings || {}; var $div = $('
', { 'class': 'indentUnit element' @@ -148,26 +149,28 @@ define([ }).on('change', function () { var val = parseInt($input.val()); if (typeof(val) !== 'number') { return; } - proxy['cryptpad.indentUnit'] = val; + proxy.settings.indentUnit = val; }).appendTo($inputBlock); - proxy.on('change', [ 'cryptpad.indentUnit', ], function (o, n) { $input.val(n); }); + proxy.on('change', [ 'settings', 'indentUnit', ], function (o, n) { $input.val(n); }); - Cryptpad.getAttribute('indentUnit', function (e, val) { - if (e) { return void console.error(e); } + //Cryptpad.getAttribute('indentUnit', function (e, val) { + //if (e) { return void console.error(e); } + var val = proxy.settings.indentUnit; if (typeof(val) !== 'number') { $input.val(2); } else { $input.val(val); } - }); + //}); return $div; }; var createIndentTypeSelector = function (obj) { var proxy = obj.proxy; + proxy.settings = proxy.settings || {}; - var key = 'cryptpad.indentWithTabs'; + var key = 'indentWithTabs'; var $div = $('
', { 'class': 'indentType element' @@ -184,11 +187,11 @@ define([ }).on('change', function () { var val = $input.is(':checked'); if (typeof(val) !== 'boolean') { return; } - proxy[key] = val; + proxy.settings[key] = val; }).appendTo($inputBlock); - $input[0].checked = !!proxy[key]; - proxy.on('change', [key], function (o, n) { $input[0].checked = !!n; }); + $input[0].checked = !!proxy.settings[key]; + proxy.on('change', ['settings', key], function (o, n) { $input[0].checked = !!n; }); return $div; };