diff --git a/src/node/hooks/express/specialpages.ts b/src/node/hooks/express/specialpages.ts index 0905abf03..11d02c001 100644 --- a/src/node/hooks/express/specialpages.ts +++ b/src/node/hooks/express/specialpages.ts @@ -98,10 +98,30 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function) })(), settings, })); + + await fsp.writeFile( + path.join(settings.root, 'var/js/timesliderBootstrap.js'), + eejs.require('ep_etherpad-lite/templates/timeSliderBootstrap.js', { + pluginModules: (() => { + const pluginModules = new Set(); + for (const part of plugins.parts) { + for (const [, hookFnName] of Object.entries(part.client_hooks || {})) { + console.log(hookFnName.split(':')[0]) + pluginModules.add(hookFnName.split(':')[0]); + } + } + return [...pluginModules]; + })(), + settings, + })); + const hash = createHash('sha256').update(fs.readFileSync(path.join(settings.root, 'var/js/padbootstrap.js'))).digest('hex'); + const hashTimeSlider = createHash('sha256').update(fs.readFileSync(path.join(settings.root, 'var/js/timeSliderBootstrap.js'))).digest('hex'); const fileName = `padbootstrap-${hash.substring(0,16)}.min.js` - const result = buildSync({ + const fileNameTimeSlider = `timeSliderBootstrap-${hash.substring(0,16)}.min.js` + + buildSync({ entryPoints: [settings.root + "/var/js/padbootstrap.js"], // Entry file(s) bundle: true, // Bundle the files together minify: false, // Minify the output @@ -114,6 +134,19 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function) outfile: settings.root + `/var/js/${fileName}`, // Output file }) + buildSync({ + entryPoints: [settings.root + "/var/js/timesliderBootstrap.js"], // Entry file(s) + bundle: true, // Bundle the files together + minify: false, // Minify the output + sourcemap: true, // Generate source maps + sourceRoot: settings.root+"/src/static/js/", + target: ['es2020'], // Target ECMAScript version + metafile: true, + + write: true, // Do not write to file system, + outfile: settings.root + `/var/js/${fileNameTimeSlider}`, // Output file + }) + args.app.get(`/${fileName}`, (req: any, res: any) => { res.sendFile(settings.root+`/var/js/${fileName}`) @@ -123,6 +156,17 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function) res.sendFile(settings.root+`/var/js/${fileName}.map`) }) + args.app.get(`/${fileNameTimeSlider}`, (req: any, res: any) => { + res.sendFile(settings.root+`/var/js/${fileNameTimeSlider}`) + }) + + args.app.get(`/${fileNameTimeSlider}.map`, (req: any, res: any) => { + res.sendFile(settings.root+`/var/js/${fileNameTimeSlider}.map`) + }) + + + + // serve pad.html under /p args.app.get('/p/:pad', (req: any, res: any, next: Function) => { @@ -153,6 +197,7 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function) res.send(eejs.require('ep_etherpad-lite/templates/timeslider.html', { req, toolbar, + entrypoint: "/"+fileNameTimeSlider })); }); diff --git a/src/static/js/vendors/html10n.js b/src/static/js/vendors/html10n.js index 1f6a11728..6fe5e307f 100644 --- a/src/static/js/vendors/html10n.js +++ b/src/static/js/vendors/html10n.js @@ -725,7 +725,7 @@ export let html10n = (function(window, document, undefined) { return; // initialize _pluralRules - if (!this._pluralRules) + if (!("_pluralRules" in this)) this._pluralRules = getPluralRules(html10n.language); var index = this._pluralRules(n); diff --git a/src/templates/timeSliderBootstrap.js b/src/templates/timeSliderBootstrap.js new file mode 100644 index 000000000..e3138cfbd --- /dev/null +++ b/src/templates/timeSliderBootstrap.js @@ -0,0 +1,37 @@ +// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt +window.clientVars = { + // This is needed to fetch /pluginfw/plugin-definitions.json, which happens before the + // server sends the CLIENT_VARS message. + randomVersionString: <%-JSON.stringify(settings.randomVersionString)%>, +}; +let BroadcastSlider; + + +(function () { + const timeSlider = require('ep_etherpad-lite/static/js/timeslider') + const pathComponents = location.pathname.split('/'); + + // Strip 'p', the padname and 'timeslider' from the pathname and set as baseURL + const baseURL = pathComponents.slice(0,pathComponents.length-3).join('/') + '/'; + require('ep_etherpad-lite/static/js/l10n') + window.$ = window.jQuery = require('ep_etherpad-lite/static/js/rjquery').jQuery; // Expose jQuery #HACK + require('ep_etherpad-lite/static/js/vendors/gritter') + + window.browser = require('ep_etherpad-lite/static/js/vendors/browser'); + + window.plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins'); + const socket = timeSlider.socket; + BroadcastSlider = timeSlider.BroadcastSlider; + plugins.baseURL = baseURL; + plugins.update(function () { + + + /* TODO: These globals shouldn't exist. */ + + }); + const padeditbar = require('ep_etherpad-lite/static/js/pad_editbar').padeditbar; + const padimpexp = require('ep_etherpad-lite/static/js/pad_impexp').padimpexp; + timeSlider.baseURL = baseURL; + timeSlider.init(); + padeditbar.init() +})(); diff --git a/src/templates/timeslider.html b/src/templates/timeslider.html index 71346f21e..e2178e54e 100644 --- a/src/templates/timeslider.html +++ b/src/templates/timeslider.html @@ -47,8 +47,6 @@ <% e.begin_block("timesliderScripts"); %> - - <% e.end_block(); %> @@ -250,58 +248,14 @@ - - - - + <% e.end_block(); %>