From 6926d42292037ad6728a39209c8a5fbc4d9c8172 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 12 Oct 2017 18:18:01 +0200 Subject: [PATCH] Autoload template picker to make it faster to appear when used --- www/common/sframe-common-interface.js | 13 ++++++++----- www/common/sframe-common-outer.js | 26 +++++++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/www/common/sframe-common-interface.js b/www/common/sframe-common-interface.js index 422b76bfe..884f1b65c 100644 --- a/www/common/sframe-common-interface.js +++ b/www/common/sframe-common-interface.js @@ -587,11 +587,18 @@ define([ var sframeChan = common.getSframeChannel(); var focus; + var pickerCfg = { + types: [type], + where: ['template'], + hidden: true + }; var onConfirm = function (yes) { if (!yes) { if (focus) { focus.focus(); } return; } + delete pickerCfg.hidden; + common.openFilePicker(pickerCfg); var first = true; // We can only pick a template once (for a new document) var fileDialogCfg = { onSelect: function (data) { @@ -608,15 +615,11 @@ define([ } }; common.initFilePicker(fileDialogCfg); - var pickerCfg = { - types: [type], - where: ['template'] - }; - common.openFilePicker(pickerCfg); }; sframeChan.query("Q_TEMPLATE_EXIST", type, function (err, data) { if (data) { + common.openFilePicker(pickerCfg); focus = document.activeElement; Cryptpad.confirm(Messages.useTemplate, onConfirm, { ok: Messages.useTemplateOK, diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 46534fe9d..2daa275f7 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -362,22 +362,26 @@ define([ // File picker var FP = {}; - var initFilePicker = function (types) { - var config = {}; - config.onFilePicked = function (data) { - sframeChan.event('EV_FILE_PICKED', data); - }; - config.onClose = function () { - FP.$iframe.hide(); - }; - config.onFileUpload = onFileUpload; - config.types = types; + var initFilePicker = function (cfg) { if (!FP.$iframe) { + var config = {}; + config.onFilePicked = function (data) { + sframeChan.event('EV_FILE_PICKED', data); + }; + config.onClose = function () { + FP.$iframe.hide(); + }; + config.onFileUpload = onFileUpload; + config.types = cfg; FP.$iframe = $('