diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6939c020..1a785a62 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - visibility-option-feature pull_request: branches: - main @@ -198,4 +199,4 @@ jobs: uses: coverallsapp/github-action@1.1.3 with: github-token: ${{ secrets.GITHUB_TOKEN }} - parallel-finished: true + parallel-finished: true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5a176ec4..1200b713 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ dist/ yarn.lock npm-debug.log -node_modules/ +node_modules/* +!node_modules/nodebb-plugin-composer-default sftp-config.json config.json jsconfig.json diff --git a/install/data/footer.json b/install/data/footer.json index 53b2176a..2479c373 100644 --- a/install/data/footer.json +++ b/install/data/footer.json @@ -2,7 +2,7 @@ { "widget": "html", "data" : { - "html": "", + "html": "", "title":"", "container":"" } diff --git a/node_modules/nodebb-plugin-composer-default/.eslintrc b/node_modules/nodebb-plugin-composer-default/.eslintrc new file mode 100644 index 00000000..74e8dc06 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "nodebb/lib" +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/.gitattributes b/node_modules/nodebb-plugin-composer-default/.gitattributes new file mode 100644 index 00000000..412eeda7 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/node_modules/nodebb-plugin-composer-default/.jshintrc b/node_modules/nodebb-plugin-composer-default/.jshintrc new file mode 100644 index 00000000..1981c254 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/.jshintrc @@ -0,0 +1,86 @@ +{ + // JSHint Default Configuration File (as on JSHint website) + // See http://jshint.com/docs/ for more details + + "maxerr" : 50, // {int} Maximum error before stopping + + // Enforcing + "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) + "camelcase" : false, // true: Identifiers must be in camelCase + "curly" : true, // true: Require {} for every new block or scope + "eqeqeq" : true, // true: Require triple equals (===) for comparison + "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() + "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` + "indent" : 4, // {int} Number of spaces to use for indentation + "latedef" : false, // true: Require variables/functions to be defined before being used + "newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()` + "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` + "noempty" : true, // true: Prohibit use of empty blocks + "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) + "plusplus" : false, // true: Prohibit use of `++` & `--` + "quotmark" : false, // Quotation mark consistency: + // false : do nothing (default) + // true : ensure whatever is used is consistent + // "single" : require single quotes + // "double" : require double quotes + "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) + "unused" : true, // true: Require all defined variables be used + "strict" : true, // true: Requires all functions run in ES5 Strict Mode + "trailing" : false, // true: Prohibit trailing whitespaces + "maxparams" : false, // {int} Max number of formal params allowed per function + "maxdepth" : false, // {int} Max depth of nested blocks (within functions) + "maxstatements" : false, // {int} Max number statements per function + "maxcomplexity" : false, // {int} Max cyclomatic complexity per function + "maxlen" : false, // {int} Max number of characters per line + + // Relaxing + "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) + "boss" : false, // true: Tolerate assignments where comparisons would be expected + "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. + "eqnull" : false, // true: Tolerate use of `== null` + "es5" : false, // true: Allow ES5 syntax (ex: getters and setters) + "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) + "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) + // (ex: `for each`, multiple try/catch, function expression…) + "evil" : false, // true: Tolerate use of `eval` and `new Function()` + "expr" : false, // true: Tolerate `ExpressionStatement` as Programs + "funcscope" : false, // true: Tolerate defining variables inside control statements" + "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') + "iterator" : false, // true: Tolerate using the `__iterator__` property + "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block + "laxbreak" : false, // true: Tolerate possibly unsafe line breakings + "laxcomma" : false, // true: Tolerate comma-first style coding + "loopfunc" : false, // true: Tolerate functions being defined in loops + "multistr" : false, // true: Tolerate multi-line strings + "proto" : false, // true: Tolerate using the `__proto__` property + "scripturl" : false, // true: Tolerate script-targeted URLs + "smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment + "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` + "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation + "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` + "validthis" : false, // true: Tolerate using this in a non-constructor function + + // Environments + "browser" : true, // Web Browser (window, document, etc) + "couch" : false, // CouchDB + "devel" : true, // Development/debugging (alert, confirm, etc) + "dojo" : false, // Dojo Toolkit + "jquery" : true, // jQuery + "mootools" : false, // MooTools + "node" : true, // Node.js + "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) + "prototypejs" : false, // Prototype and Scriptaculous + "rhino" : false, // Rhino + "worker" : false, // Web Workers + "wsh" : false, // Windows Scripting Host + "yui" : false, // Yahoo User Interface + + // Legacy + "nomen" : false, // true: Prohibit dangling `_` in variables + "onevar" : false, // true: Allow only one `var` statement per function + "passfail" : false, // true: Stop on first error + "white" : false, // true: Check against strict whitespace and indentation rules + + // Custom Globals + "globals" : {} // additional predefined global variables +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/LICENSE b/node_modules/nodebb-plugin-composer-default/LICENSE new file mode 100644 index 00000000..b8658d3a --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2016 NodeBB Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/README.md b/node_modules/nodebb-plugin-composer-default/README.md new file mode 100644 index 00000000..7bcfff9a --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/README.md @@ -0,0 +1,11 @@ +# Default Composer for NodeBB + +This plugin activates the default composer for NodeBB. It is activated by default, but can be swapped out as necessary. + +## Screenshots + +### Desktop +![Desktop Composer](screenshots/desktop.png?raw=true) + +### Mobile Devices +![Mobile Composer](screenshots/mobile.png?raw=true) \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/controllers.js b/node_modules/nodebb-plugin-composer-default/controllers.js new file mode 100644 index 00000000..ef76d10c --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/controllers.js @@ -0,0 +1,9 @@ +'use strict'; + +const Controllers = {}; + +Controllers.renderAdminPage = function (req, res) { + res.render('admin/plugins/composer-default', {}); +}; + +module.exports = Controllers; diff --git a/node_modules/nodebb-plugin-composer-default/library.js b/node_modules/nodebb-plugin-composer-default/library.js new file mode 100644 index 00000000..a635ee11 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/library.js @@ -0,0 +1,330 @@ +'use strict'; + +const url = require('url'); + +const nconf = require.main.require('nconf'); +const winston = require.main.require('winston'); +const validator = require('validator'); + +const plugins = require.main.require('./src/plugins'); +const topics = require.main.require('./src/topics'); +const categories = require.main.require('./src/categories'); +const posts = require.main.require('./src/posts'); +const user = require.main.require('./src/user'); +const meta = require.main.require('./src/meta'); +const privileges = require.main.require('./src/privileges'); +const translator = require.main.require('./src/translator'); +const helpers = require.main.require('./src/controllers/helpers'); +const SocketPlugins = require.main.require('./src/socket.io/plugins'); +const socketMethods = require('./websockets'); + +const plugin = module.exports; + +plugin.socketMethods = socketMethods; + +plugin.init = async function (data) { + const controllers = require('./controllers'); + SocketPlugins.composer = socketMethods; + + data.router.get('/admin/plugins/composer-default', data.middleware.admin.buildHeader, controllers.renderAdminPage); + data.router.get('/api/admin/plugins/composer-default', controllers.renderAdminPage); +}; + +plugin.appendConfig = async function (config) { + config['composer-default'] = await meta.settings.get('composer-default'); + return config; +}; + +plugin.addAdminNavigation = async function (header) { + header.plugins.push({ + route: '/plugins/composer-default', + icon: 'fa-edit', + name: 'Composer (Default)', + }); + return header; +}; + +plugin.addPrefetchTags = async function (hookData) { + const prefetch = [ + '/assets/src/modules/composer.js', '/assets/src/modules/composer/uploads.js', '/assets/src/modules/composer/drafts.js', + '/assets/src/modules/composer/tags.js', '/assets/src/modules/composer/categoryList.js', '/assets/src/modules/composer/resize.js', + '/assets/src/modules/composer/autocomplete.js', '/assets/templates/composer.tpl', + `/assets/language/${meta.config.defaultLang || 'en-GB'}/topic.json`, + `/assets/language/${meta.config.defaultLang || 'en-GB'}/modules.json`, + `/assets/language/${meta.config.defaultLang || 'en-GB'}/tags.json`, + ]; + + hookData.links = hookData.links.concat(prefetch.map(path => ({ + rel: 'prefetch', + href: `${nconf.get('relative_path') + path}?${meta.config['cache-buster']}`, + }))); + + return hookData; +}; + +plugin.getFormattingOptions = async function () { + const defaultVisibility = { + mobile: true, + desktop: true, + + // op or reply + main: true, + reply: true, + }; + let payload = { + defaultVisibility, + options: [ + { + name: 'tags', + title: '[[global:tags.tags]]', + className: 'fa fa-tags', + visibility: { + ...defaultVisibility, + desktop: false, + }, + }, + { + name: 'zen', + title: '[[modules:composer.zen_mode]]', + className: 'fa fa-arrows-alt', + visibility: defaultVisibility, + }, + ], + }; + if (parseInt(meta.config.allowTopicsThumbnail, 10) === 1) { + payload.options.push({ + name: 'thumbs', + title: '[[topic:composer.thumb_title]]', + className: 'fa fa-address-card-o', + visibility: { + ...defaultVisibility, + reply: false, + }, + }); + } + + payload = await plugins.hooks.fire('filter:composer.formatting', payload); + + // TODO: Backwards compatibility -- remove in v1.16.0 + payload.options = payload.options.map((option) => { + option.visibility = { + ...defaultVisibility, + ...option.visibility || {}, + }; + if (option.hasOwnProperty('mobile')) { + winston.warn('[composer/formatting] `mobile` is no longer supported as a formatting option, use `visibility` instead (default values are passed in payload)'); + option.visibility.mobile = option.mobile; + option.visibility.desktop = !option.mobile; + } + + return option; + }); + // end + + return payload ? payload.options : null; +}; + +plugin.filterComposerBuild = async function (hookData) { + const { req } = hookData; + const { res } = hookData; + + if (req.query.p) { + if (!res.locals.isAPI) { + let a; + try { + a = url.parse(req.query.p, true, true); + } catch (e) { + return helpers.redirect(res, '/'); + } + return helpers.redirect(res, `/${(a.path || '').replace(/^\/*/, '')}`); + } + res.render('', {}); + return; + } else if (!req.query.pid && !req.query.tid && !req.query.cid) { + return helpers.redirect(res, '/'); + } + const [ + isMainPost, + postData, + topicData, + categoryData, + isAdmin, + isMod, + formatting, + tagWhitelist, + globalPrivileges, + canTagTopics, + canScheduleTopics, + ] = await Promise.all([ + posts.isMain(req.query.pid), + getPostData(req), + getTopicData(req), + categories.getCategoryFields(req.query.cid, [ + 'name', 'icon', 'color', 'bgColor', 'backgroundImage', 'imageClass', 'minTags', 'maxTags', + ]), + user.isAdministrator(req.uid), + isModerator(req), + plugin.getFormattingOptions(), + getTagWhitelist(req.query, req.uid), + privileges.global.get(req.uid), + canTag(req), + canSchedule(req), + ]); + + const isEditing = !!req.query.pid; + const isGuestPost = postData && parseInt(postData.uid, 10) === 0; + const save_id = generateSaveId(req); + const discardRoute = generateDiscardRoute(req, topicData); + const body = await generateBody(req, postData); + + let action = 'topics.post'; + let isMain = isMainPost; + if (req.query.tid) { + action = 'posts.reply'; + } else if (req.query.pid) { + action = 'posts.edit'; + } else { + isMain = true; + } + globalPrivileges['topics:tag'] = canTagTopics; + const cid = parseInt(req.query.cid, 10); + const topicTitle = topicData && topicData.title ? topicData.title.replace(/%/g, '%').replace(/,/g, ',') : validator.escape(String(req.query.title || '')); + return { + req: req, + res: res, + templateData: { + disabled: !req.query.pid && !req.query.tid && !req.query.cid, + pid: parseInt(req.query.pid, 10), + tid: parseInt(req.query.tid, 10), + cid: cid || (topicData ? topicData.cid : null), + action: action, + toPid: parseInt(req.query.toPid, 10), + discardRoute: discardRoute, + + resizable: false, + allowTopicsThumbnail: parseInt(meta.config.allowTopicsThumbnail, 10) === 1 && isMain, + + // can't use title property as that is used for page title + topicTitle: topicTitle, + titleLength: topicTitle ? topicTitle.length : 0, + topic: topicData, + thumb: topicData ? topicData.thumb : '', + body: body, + + isMain: isMain, + isTopicOrMain: !!req.query.cid || isMain, + maximumTitleLength: meta.config.maximumTitleLength, + maximumPostLength: meta.config.maximumPostLength, + minimumTagLength: meta.config.minimumTagLength || 3, + maximumTagLength: meta.config.maximumTagLength || 15, + tagWhitelist: tagWhitelist, + selectedCategory: cid ? categoryData : null, + minTags: categoryData.minTags, + maxTags: categoryData.maxTags, + + isTopic: !!req.query.cid, + isEditing: isEditing, + canSchedule: canScheduleTopics, + showHandleInput: meta.config.allowGuestHandles === 1 && + (req.uid === 0 || (isEditing && isGuestPost && (isAdmin || isMod))), + handle: postData ? postData.handle || '' : undefined, + formatting: formatting, + isAdminOrMod: isAdmin || isMod, + save_id: save_id, + privileges: globalPrivileges, + }, + }; +}; + +function generateDiscardRoute(req, topicData) { + if (req.query.cid) { + return `${nconf.get('relative_path')}/category/${validator.escape(String(req.query.cid))}`; + } else if ((req.query.tid || req.query.pid)) { + if (topicData) { + return `${nconf.get('relative_path')}/topic/${topicData.slug}`; + } + return `${nconf.get('relative_path')}/`; + } +} + +async function generateBody(req, postData) { + // Quoted reply + if (req.query.toPid && parseInt(req.query.quoted, 10) === 1 && postData) { + const username = await user.getUserField(postData.uid, 'username'); + const translated = await translator.translate(`[[modules:composer.user_said, ${username}]]`); + return `${translated}\n` + + `> ${postData ? `${postData.content.replace(/\n/g, '\n> ')}\n\n` : ''}`; + } else if (req.query.body || req.query.content) { + return validator.escape(String(req.query.body || req.query.content)); + } + return postData ? postData.content : ''; +} + +function generateSaveId(req) { + if (req.query.cid) { + return ['composer', req.uid, 'cid', req.query.cid].join(':'); + } else if (req.query.tid) { + return ['composer', req.uid, 'tid', req.query.tid].join(':'); + } else if (req.query.pid) { + return ['composer', req.uid, 'pid', req.query.pid].join(':'); + } +} + +async function getPostData(req) { + if (!req.query.pid && !req.query.toPid) { + return null; + } + + return await posts.getPostData(req.query.pid || req.query.toPid); +} + +async function getTopicData(req) { + if (req.query.tid) { + return await topics.getTopicData(req.query.tid); + } else if (req.query.pid) { + return await topics.getTopicDataByPid(req.query.pid); + } + return null; +} + +async function isModerator(req) { + if (!req.loggedIn) { + return false; + } + const cid = cidFromQuery(req.query); + return await user.isModerator(req.uid, cid); +} + +async function canTag(req) { + if (parseInt(req.query.cid, 10)) { + return await privileges.categories.can('topics:tag', req.query.cid, req.uid); + } + return true; +} + +async function canSchedule(req) { + if (parseInt(req.query.cid, 10)) { + return await privileges.categories.can('topics:schedule', req.query.cid, req.uid); + } + return false; +} + +async function getTagWhitelist(query, uid) { + const cid = await cidFromQuery(query); + const [tagWhitelist, isAdminOrMod] = await Promise.all([ + categories.getTagWhitelist([cid]), + privileges.categories.isAdminOrMod(cid, uid), + ]); + return categories.filterTagWhitelist(tagWhitelist[0], isAdminOrMod); +} + +async function cidFromQuery(query) { + if (query.cid) { + return query.cid; + } else if (query.tid) { + return await topics.getTopicField(query.tid, 'cid'); + } else if (query.pid) { + return await posts.getCidByPid(query.pid); + } + return null; +} diff --git a/node_modules/nodebb-plugin-composer-default/package.json b/node_modules/nodebb-plugin-composer-default/package.json new file mode 100644 index 00000000..85300c75 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/package.json @@ -0,0 +1,43 @@ +{ + "name": "nodebb-plugin-composer-default", + "version": "9.2.4", + "description": "Default composer for NodeBB", + "main": "library.js", + "repository": { + "type": "git", + "url": "https://github.com/NodeBB/nodebb-plugin-composer-default" + }, + "scripts": { + "lint": "eslint ." + }, + "keywords": [ + "nodebb", + "plugin", + "composer", + "markdown" + ], + "author": { + "name": "NodeBB Team", + "email": "sales@nodebb.org" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/NodeBB/nodebb-plugin-composer-default/issues" + }, + "readmeFilename": "README.md", + "nbbpm": { + "compatibility": "^2.5.0" + }, + "dependencies": { + "@textcomplete/contenteditable": "^0.1.12", + "@textcomplete/core": "^0.1.12", + "@textcomplete/textarea": "^0.1.12", + "screenfull": "^5.0.2", + "validator": "^13.7.0" + }, + "devDependencies": { + "eslint": "^7.32.0", + "eslint-config-nodebb": "^0.0.1", + "eslint-plugin-import": "^2.23.4" + } +} diff --git a/node_modules/nodebb-plugin-composer-default/plugin.json b/node_modules/nodebb-plugin-composer-default/plugin.json new file mode 100644 index 00000000..1c793c57 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/plugin.json @@ -0,0 +1,34 @@ +{ + "id": "nodebb-plugin-composer-default", + "url": "https://github.com/NodeBB/nodebb-plugin-composer-default", + "library": "library.js", + "hooks": [ + { "hook": "static:app.load", "method": "init" }, + { "hook": "filter:config.get", "method": "appendConfig" }, + { "hook": "filter:composer.build", "method": "filterComposerBuild" }, + { "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, + { "hook": "filter:meta.getLinkTags", "method": "addPrefetchTags" } + ], + "less": [ + "./static/less/composer.less" + ], + "scripts": [ + "./static/lib/client.js", + "./node_modules/screenfull/dist/screenfull.js" + ], + "modules": { + "composer.js": "./static/lib/composer.js", + "composer/categoryList.js": "./static/lib/composer/categoryList.js", + "composer/controls.js": "./static/lib/composer/controls.js", + "composer/drafts.js": "./static/lib/composer/drafts.js", + "composer/formatting.js": "./static/lib/composer/formatting.js", + "composer/preview.js": "./static/lib/composer/preview.js", + "composer/resize.js": "./static/lib/composer/resize.js", + "composer/scheduler.js": "./static/lib/composer/scheduler.js", + "composer/tags.js": "./static/lib/composer/tags.js", + "composer/uploads.js": "./static/lib/composer/uploads.js", + "composer/autocomplete.js": "./static/lib/composer/autocomplete.js", + "../admin/plugins/composer-default.js": "./static/lib/admin.js" + }, + "templates": "static/templates" +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/screenshots/desktop.png b/node_modules/nodebb-plugin-composer-default/screenshots/desktop.png new file mode 100644 index 00000000..880af955 Binary files /dev/null and b/node_modules/nodebb-plugin-composer-default/screenshots/desktop.png differ diff --git a/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png b/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png new file mode 100644 index 00000000..1776f4df Binary files /dev/null and b/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png differ diff --git a/node_modules/nodebb-plugin-composer-default/static/less/composer.less b/node_modules/nodebb-plugin-composer-default/static/less/composer.less new file mode 100644 index 00000000..e9a8ca66 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/less/composer.less @@ -0,0 +1,573 @@ +.define-if-not-set() { + @btn-primary-bg: darken(#428bca, 6.5%); + @btn-primary-color: #fff; + @gray-light: lighten(#000, 46.7%); + @padding-large-vertical: 10px; + @padding-large-horizontal: 16px; +} + +.define-if-not-set(); + +.composer { + .no-select; + + z-index: @zindex-modal; + + background: #fff; + visibility: hidden; + + padding: 0; + + position: fixed; + bottom: 0; + top: 0; + right: 0; + left: 0; + + .composer-container { + height: 100%; + display: flex; + flex-direction: column; + } + + .mobile-navbar { + position: static; + background: @btn-primary-bg; + color: @btn-primary-color; + min-height: 40px; + margin: 0; + + .btn-group { + flex-shrink: 0; + } + + button { + font-size: 20px; + } + + display: flex; + + .category-name-container, .title { + text-align: center; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + flex-grow: 2; + font-size: 16px; + line-height: inherit; + padding: 9px 5px; + margin: 0; + } + } + + .title-container { + display: flex; + border-bottom: 1px solid #eee; + margin: 0; + + > div[data-component="composer/title"] { + flex: 1; + } + + > div[data-component="composer/handle"] { + flex: 0.33; + } + + .title, .handle { + display: block; + margin: 0; + padding: 8px; + font-size: 18px; + border: 0; + .box-shadow(none); + overflow: hidden; + } + + .category-list-container { + + [component="category-selector"] { + margin-right: 0.5em; + + .category-dropdown-menu { + max-height: 300px; + } + } + } + + .category-list { + padding: 0 2rem; + } + + .quick-search-container { + top: 70px; + right: auto; + margin-bottom: 0px; + } + + .composer-submit, .composer-discard { + min-width: 106px; + } + + .action-bar { + .dropdown-menu:empty { + & ~ .dropdown-toggle { + display: none; + } + } + } + } + + .display-scheduler { + display: flex; + align-items: center; + margin-right: 1em; + + > i { + font-size: 30px; + display: inline-block; + cursor: pointer; + + &.active { + animation: 300ms ease forwards pulse; + } + } + } + + .category-tag-row { + margin: 0; + } + + .formatting-bar { + margin: 0; + + span { + color: #000; + } + + .spacer { + &:before { + content: ' | '; + color: @gray-light; + } + } + + .formatting-group { + padding: 0; + margin: 0; + overflow-x: auto; + white-space: nowrap; + display: block; + list-style: none; + + li { + display: inline-block; + padding: 10px 15px; + cursor: pointer; + color: #333; + position: relative; + + &:focus, &:hover { + outline: none; + background-color: darken(#fff, 10%); + } + + &[data-format="thumbs"][data-count]:after { + content: attr(data-count); + background: @brand-info; + color: white; + font-weight: 600; + position: absolute; + top: 5px; + left: 2.5em; + padding: 0px 5px; + border-radius: 5px; + font-size: 0.75em; + } + } + } + } + + .write-preview-container { + flex: 2; + display: flex; + overflow: hidden; + } + + .write-container, .preview-container { + display: flex; + flex: 1; + margin: 0 15px; + position: relative; + + .help-text { + text-transform: uppercase; + position: absolute; + right: 35px; + top: 8px; + font-size: 10px; + color: #999; + z-index: 1; + } + } + + .write-container { + &.maximized { + width: 100%; + } + } + + .preview-container { + word-wrap: break-word; + max-width: 50%; + max-width: ~"calc(50% - 30px)"; + } + + .write, .preview { + width: 100%; + font-size: 16px; + .border-radius(0); + resize: none; + overflow: auto; + padding: 25px 10px; + margin: 0; + } + + .write { + border: none; + border-top: 1px solid #EDEDED; + border-bottom: 1px solid #EDEDED; + .box-shadow(inset 0 1px 1px rgba(0, 0, 0, 0.05)); + } + + .preview { + -webkit-touch-callout: default; + user-select: text; + + p { + margin: 0 0 18px; + } + } + + .help { + .pointer; + } + + .toggle-preview { + margin-left: 20px; + .pointer; + } + + .tags-container { + [component="composer/tag/dropdown"] { + display: inherit; + top: -8px; + left: -8px; + .dropdown-menu { + max-height: 400px; + overflow-y: auto; + } + + > button { + border: 0; + } + } + + .bootstrap-tagsinput { + border: 0; + padding: 4px 6px; + box-shadow: none; + display: block; + max-height: 80px; + overflow: auto; + + input { + font-size: 16px; + width: 50%; + height: 28px; + padding: 4px 6px; + } + + .label { + color: white; + font-size: 13px; + } + } + } + + .category-selector { + display: block; + visibility: hidden; + + position: fixed; + left: 0; + right: 0; + bottom: 0; + + margin: 0; + padding: 0 5px; + max-height: ~"calc(100% - 86px)"; + + background: #fff; + box-shadow: 0 2px 6px rgba(0,0,0,0.35); + overflow: auto; + -webkit-overflow-scrolling: touch; + transform: translate3d(0, 350px, 0); + transition: transform 0.3s, visibility 0s 0.3s; + z-index: 2; + + &.open { + transform: none; + visibility: visible; + transition-delay: 0s; + } + + li { + padding: 10px; + color: #333; + + &.active { + background-color: @btn-primary-bg; + color: @btn-primary-color; + } + } + } + + .resizer { + display: none; + position: absolute; + left: 10%; + width: 80%; + top: 0px; + height: 0; + + .pointer; + + .trigger { + position: relative; + display: block; + top: -20px; + margin: 0 auto; + margin-left: 20px; + line-height: 26px; + .transition(filter .15s linear); + + &:hover { + filter: invert(100%); + cursor: ns-resize; + } + + i { + width: 32px; + height: 32px; + background: #333; + border: 1px solid #333; + .border-radius(50%); + + position: relative; + + color: #FFF; + font-size: 16px; + + &:before { + content: @fa-var-arrows-v; + position: relative; + top: 25%; + } + } + } + } + + .minimize { + display: none; + position: absolute; + top: 0px; + right: 10px; + height: 0; + + .pointer; + + .trigger { + position: relative; + display: block; + top: -20px; + right: 0px; + margin: 0 auto; + margin-left: 20px; + line-height: 26px; + .transition(filter .15s linear); + + &:hover { + filter: invert(100%); + } + + i { + width: 32px; + height: 32px; + background: #333; + border: 1px solid #333; + .border-radius(50%); + + position: relative; + + color: #FFF; + font-size: 16px; + + &:before { + position: relative; + top: 25%; + } + } + } + } + + &.reply { + .title-container { + display: none; + } + } + + &.resizable.maximized { + .resizer .trigger i { + &:before { + content: @fa-var-chevron-down; + } + } + + box-shadow: none; + } + + .draft-icon { + font-family: 'FontAwesome'; + color: @state-success-text; + margin: 0 1em; + opacity: 0; + + &::before { + content: @fa-var-save; + position: relative; + top: 25%; + } + + &::after { + content: @fa-var-check; + position: relative; + top: 18px; + font-size: 0.7em; + left: -15%; + } + + &.active { + animation: draft-saved 3s ease; + } + } +} + +.datetime-picker { + display: flex; + justify-content: center; + flex-direction: row; + min-width: 310px; + max-width: 310px; + margin: 0 auto; + + input { + flex: 3; + line-height: inherit; + } + + input + input { + border-left: none; + flex: 2; + } +} + +.modal.topic-scheduler { + z-index: 1070; + & + .modal-backdrop { + z-index: 1060; + } +} + +@keyframes draft-saved { + 0%, 100% { + opacity: 0; + } + + 15% { + opacity: 1; + } + + 30% { + opacity: 0.5; + } + + 45% { + opacity: 1; + } + + 85% { + opacity: 1; + } +} + +@keyframes pulse { + from { + transform: scale(1); + color: inherit; + } + 50% { + transform: scale(.9); + } + to { + transform: scale(1); + color: #00adff; + } +} + +@media (min-width: @screen-md-max) { + html.composing { + .composer { + left: 15%; + width: 70%; + } + } +} + +@media (max-width: @screen-sm-max) { + html.composing { + .composer { + height: 100%; + z-index: @zindex-modal; + + .draft-icon { + position: absolute; + bottom: 1em; + right: 0em; + + &::after { + top: 7px; + } + } + + .toggle-preview.hide { + display: inline-block !important; + } + + .preview-container { + max-width: initial; + } + } + + body { + padding-bottom: 0 !important; + } + } +} + +@media (min-width: @screen-md-min) { + @import './medium.less'; +} + +@import './zen-mode.less'; +@import './page-compose.less'; +@import './textcomplete.less'; \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/less/medium.less b/node_modules/nodebb-plugin-composer-default/static/less/medium.less new file mode 100644 index 00000000..b2856fba --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/less/medium.less @@ -0,0 +1,66 @@ +.composer { + min-height: 400px; + + .resizer { + display: block; + } + + .minimize { + display: block; + } + + &.reply .title-container { + display: flex; + } + + .title-container { + border: 0; + + .title, .handle { + font-size: 22px; + padding: 4px 18px; + } + } + + .formatting-bar .formatting-group { + display: inline-block; + } + + &.resizable { + .box-shadow(0px 6px 12px rgba(0, 0, 0, 0.5)); + + padding-top: 30px; + padding-left: 15px; + padding-right: 15px; + } + + .category-tag-row { + margin-top: 5px; + margin-bottom: 8px; + } + + .write-preview-container { + margin-bottom: 15px; + } + + .write, .preview { + padding: 20px; + } + + .write { + border: 1px solid #EDEDED; + } + + .tags-container { + margin-top: 8px - 15px; + margin-bottom: 8px; + + .bootstrap-tagsinput { + padding: 0; + + input { + margin-left: -6px; + } + } + } +} diff --git a/node_modules/nodebb-plugin-composer-default/static/less/page-compose.less b/node_modules/nodebb-plugin-composer-default/static/less/page-compose.less new file mode 100644 index 00000000..e223c7f1 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/less/page-compose.less @@ -0,0 +1,24 @@ +html, +body.page-compose, +.page-compose #content, +.page-compose #panel { + height: 100%; +} + +body.page-compose { + padding-bottom: 0 !important; +} + +.page-compose .composer { + height: 100%; + z-index: initial; + position: static; + + .display-scheduler { + margin: 0 0 0 .6em; + } +} + +.zen-mode .page-compose .composer { + position: absolute; +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/less/textcomplete.less b/node_modules/nodebb-plugin-composer-default/static/less/textcomplete.less new file mode 100644 index 00000000..8e9a8731 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/less/textcomplete.less @@ -0,0 +1,24 @@ +.textcomplete-dropdown { + border: 1px solid #ddd; + background-color: white; + list-style: none; + padding: 0; + margin: 0; + + li { + margin: 0; + } + + .textcomplete-footer, .textcomplete-item { + border-top: 1px solid #ddd; + } + + .textcomplete-item { + padding: 2px 5px; + cursor: pointer; + + &:hover, &.active { + background-color: rgb(110, 183, 219); + } + } +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/less/zen-mode.less b/node_modules/nodebb-plugin-composer-default/static/less/zen-mode.less new file mode 100644 index 00000000..a1408eb4 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/less/zen-mode.less @@ -0,0 +1,55 @@ +html.zen-mode { + overflow: hidden; +} + +.zen-mode .composer { + &.resizable { + padding-top: 0; + } + + .composer-container { + padding-top: 5px; + } + + .tag-row { + display: none; + } + + .title-container .category-list-container { + margin-top: 3px; + } + + .write, .preview { + border: none; + outline: none; + } + + .resizer { + display: none; + } + + &.reply { + .title-container { + display: none; + } + + .category-tag-row { + margin-top: 3px; + } + } + + @media (min-width: @screen-md-min) { + & { + padding-left: 15px; + padding-right: 15px; + } + .write-preview-container { + margin-bottom: 0; + + > div { + padding: 0; + margin: 0; + } + } + } +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc b/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc new file mode 100644 index 00000000..9fc9d47e --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc @@ -0,0 +1,6 @@ +{ + "extends": "nodebb/public", + "rules": { + "no-cond-assign": ["error", "except-parens"] + } +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/admin.js b/node_modules/nodebb-plugin-composer-default/static/lib/admin.js new file mode 100644 index 00000000..eccc801f --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/admin.js @@ -0,0 +1,25 @@ +'use strict'; + +define('admin/plugins/composer-default', ['settings', 'alerts'], function (Settings, alerts) { + var ACP = {}; + + ACP.init = function () { + Settings.load('composer-default', $('.composer-default-settings')); + + $('#save').on('click', function () { + Settings.save('composer-default', $('.composer-default-settings'), function () { + alerts.alert({ + type: 'success', + alert_id: 'composer-default-saved', + title: 'Settings Saved', + message: 'Please reload your NodeBB to apply these settings', + clickfn: function () { + socket.emit('admin.reload'); + }, + }); + }); + }); + }; + + return ACP; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/client.js b/node_modules/nodebb-plugin-composer-default/static/lib/client.js new file mode 100644 index 00000000..3cc41b9b --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/client.js @@ -0,0 +1,71 @@ +'use strict'; + +$(document).ready(function () { + $(window).on('action:app.load', function () { + require(['composer/drafts'], function (drafts) { + drafts.migrateGuest(); + drafts.loadOpen(); + }); + }); + + $(window).on('action:composer.topic.new', function (ev, data) { + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + composer.newTopic({ + cid: data.cid, + title: data.title || '', + body: data.body || '', + tags: data.tags || [], + }); + }); + } else { + ajaxify.go( + 'compose?cid=' + data.cid + + (data.title ? '&title=' + encodeURIComponent(data.title) : '') + + (data.body ? '&body=' + encodeURIComponent(data.body) : '') + ); + } + }); + + $(window).on('action:composer.post.edit', function (ev, data) { + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + composer.editPost(data.pid); + }); + } else { + ajaxify.go('compose?pid=' + data.pid); + } + }); + + $(window).on('action:composer.post.new', function (ev, data) { + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + composer.newReply(data.tid, data.pid, data.topicName, data.text); + }); + } else { + ajaxify.go( + 'compose?tid=' + data.tid + + (data.pid ? '&toPid=' + data.pid : '') + + (data.topicName ? '&title=' + encodeURIComponent(data.topicName) : '') + + (data.text ? '&body=' + encodeURIComponent(data.text) : '') + ); + } + }); + + $(window).on('action:composer.addQuote', function (ev, data) { + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + var topicUUID = composer.findByTid(data.tid); + composer.addQuote(data.tid, data.pid, data.selectedPid, data.topicName, data.username, data.text, topicUUID); + }); + } else { + ajaxify.go('compose?tid=' + data.tid + '&toPid=' + data.pid + '"ed=1&username=' + data.username); + } + }); + + $(window).on('action:composer.enhance', function (ev, data) { + require(['composer'], function (composer) { + composer.enhance(data.container); + }); + }); +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer.js new file mode 100644 index 00000000..66d74361 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer.js @@ -0,0 +1,877 @@ +'use strict'; + +define('composer', [ + 'taskbar', + 'translator', + 'composer/uploads', + 'composer/formatting', + 'composer/drafts', + 'composer/tags', + 'composer/categoryList', + 'composer/preview', + 'composer/resize', + 'composer/autocomplete', + 'composer/scheduler', + 'scrollStop', + 'topicThumbs', + 'api', + 'bootbox', + 'alerts', + 'hooks', + 'messages', + 'search', + 'screenfull', +], function (taskbar, translator, uploads, formatting, drafts, tags, + categoryList, preview, resize, autocomplete, scheduler, scrollStop, + topicThumbs, api, bootbox, alerts, hooks, messagesModule, search, screenfull) { + var composer = { + active: undefined, + posts: {}, + bsEnvironment: undefined, + formatting: undefined, + }; + + $(window).off('resize', onWindowResize).on('resize', onWindowResize); + onWindowResize(); + + $(window).on('action:composer.topics.post', function (ev, data) { + localStorage.removeItem('category:' + data.data.cid + ':bookmark'); + localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked'); + }); + + $(window).on('popstate', function () { + var env = utils.findBootstrapEnvironment(); + if (composer.active && (env === 'xs' || env === 'sm')) { + if (!composer.posts[composer.active].modified) { + composer.discard(composer.active); + if (composer.discardConfirm && composer.discardConfirm.length) { + composer.discardConfirm.modal('hide'); + delete composer.discardConfirm; + } + return; + } + + translator.translate('[[modules:composer.discard]]', function (translated) { + composer.discardConfirm = bootbox.confirm(translated, function (confirm) { + if (confirm) { + composer.discard(composer.active); + } else { + composer.posts[composer.active].modified = true; + } + }); + composer.posts[composer.active].modified = false; + }); + } + }); + + function removeComposerHistory() { + var env = composer.bsEnvironment; + if (ajaxify.data.template.compose === true || env === 'xs' || env === 'sm') { + history.back(); + } + } + + function onWindowResize() { + var env = utils.findBootstrapEnvironment(); + var isMobile = env === 'xs' || env === 'sm'; + + if (preview.toggle) { + if (preview.env !== env && isMobile) { + preview.env = env; + preview.toggle(false); + } + preview.env = env; + } + + if (composer.active !== undefined) { + resize.reposition($('.composer[data-uuid="' + composer.active + '"]')); + + if (!isMobile && window.location.pathname.startsWith(config.relative_path + '/compose')) { + /* + * If this conditional is met, we're no longer in mobile/tablet + * resolution but we've somehow managed to have a mobile + * composer load, so let's go back to the topic + */ + history.back(); + } else if (isMobile && !window.location.pathname.startsWith(config.relative_path + '/compose')) { + /* + * In this case, we're in mobile/tablet resolution but the composer + * that loaded was a regular composer, so let's fix the address bar + */ + mobileHistoryAppend(); + } + } + composer.bsEnvironment = env; + } + + function alreadyOpen(post) { + // If a composer for the same cid/tid/pid is already open, return the uuid, else return bool false + var type; + var id; + + if (post.hasOwnProperty('cid')) { + type = 'cid'; + } else if (post.hasOwnProperty('tid')) { + type = 'tid'; + } else if (post.hasOwnProperty('pid')) { + type = 'pid'; + } + + id = post[type]; + + // Find a match + for (var uuid in composer.posts) { + if (composer.posts[uuid].hasOwnProperty(type) && id === composer.posts[uuid][type]) { + return uuid; + } + } + + // No matches... + return false; + } + + function push(post) { + var uuid = utils.generateUUID(); + var existingUUID = alreadyOpen(post); + + if (existingUUID) { + taskbar.updateActive(existingUUID); + return composer.load(existingUUID); + } + + var actionText = '[[topic:composer.new_topic]]'; + if (post.action === 'posts.reply') { + actionText = '[[topic:composer.replying_to]]'; + } else if (post.action === 'posts.edit') { + actionText = '[[topic:composer.editing]]'; + } + + translator.translate(actionText, function (translatedAction) { + taskbar.push('composer', uuid, { + title: translatedAction.replace('%1', '"' + post.title + '"'), + }); + }); + + // Construct a save_id + if (post.hasOwnProperty('cid')) { + post.save_id = ['composer', app.user.uid, 'cid', post.cid].join(':'); + } else if (post.hasOwnProperty('tid')) { + post.save_id = ['composer', app.user.uid, 'tid', post.tid].join(':'); + } else if (post.hasOwnProperty('pid')) { + post.save_id = ['composer', app.user.uid, 'pid', post.pid].join(':'); + } + + composer.posts[uuid] = post; + composer.load(uuid); + } + + async function composerAlert(post_uuid, message) { + $('.composer[data-uuid="' + post_uuid + '"]').find('.composer-submit').removeAttr('disabled'); + + const { showAlert } = await hooks.fire('filter:composer.error', { post_uuid, message, showAlert: true }); + + if (showAlert) { + alerts.alert({ + type: 'danger', + timeout: 10000, + title: '', + message: message, + alert_id: 'post_error', + }); + } + } + + composer.findByTid = function (tid) { + // Iterates through the initialised composers and returns the uuid of the matching composer + for (var uuid in composer.posts) { + if (composer.posts.hasOwnProperty(uuid) && composer.posts[uuid].hasOwnProperty('tid') && parseInt(composer.posts[uuid].tid, 10) === parseInt(tid, 10)) { + return uuid; + } + } + + return null; + }; + + composer.addButton = function (iconClass, onClick, title) { + formatting.addButton(iconClass, onClick, title); + }; + + composer.newTopic = async (data) => { + var pushData = { + action: 'topics.post', + cid: data.cid, + handle: data.handle, + title: data.title || '', + body: data.body || '', + tags: data.tags || [], + modified: !!((data.title && data.title.length) || (data.body && data.body.length)), + isMain: true, + }; + + ({ pushData } = await hooks.fire('filter:composer.topic.push', { + data: data, + pushData: pushData, + })); + + push(pushData); + }; + + composer.addQuote = function (tid, toPid, selectedPid, title, username, text, uuid) { + uuid = uuid || composer.active; + + var escapedTitle = (title || '') + .replace(/([\\`*_{}[\]()#+\-.!])/g, '\\$1') + .replace(/\[/g, '[') + .replace(/\]/g, ']') + .replace(/%/g, '%') + .replace(/,/g, ','); + + if (text) { + text = '> ' + text.replace(/\n/g, '\n> ') + '\n\n'; + } + var link = '[' + escapedTitle + '](' + config.relative_path + '/post/' + (selectedPid || toPid) + ')'; + if (uuid === undefined) { + if (title && (selectedPid || toPid)) { + composer.newReply(tid, toPid, title, '[[modules:composer.user_said_in, ' + username + ', ' + link + ']]\n' + text); + } else { + composer.newReply(tid, toPid, title, '[[modules:composer.user_said, ' + username + ']]\n' + text); + } + return; + } else if (uuid !== composer.active) { + // If the composer is not currently active, activate it + composer.load(uuid); + } + + var postContainer = $('.composer[data-uuid="' + uuid + '"]'); + var bodyEl = postContainer.find('textarea'); + var prevText = bodyEl.val(); + if (title && (selectedPid || toPid)) { + translator.translate('[[modules:composer.user_said_in, ' + username + ', ' + link + ']]\n', config.defaultLang, onTranslated); + } else { + translator.translate('[[modules:composer.user_said, ' + username + ']]\n', config.defaultLang, onTranslated); + } + + function onTranslated(translated) { + composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + translated + text; + bodyEl.val(composer.posts[uuid].body); + focusElements(postContainer); + preview.render(postContainer); + } + }; + + composer.newReply = function (tid, toPid, title, text) { + translator.translate(text, config.defaultLang, function (translated) { + push({ + action: 'posts.reply', + tid: tid, + toPid: toPid, + title: title, + body: translated, + modified: !!((title && title.length) || (translated && translated.length)), + isMain: false, + }); + }); + }; + + composer.editPost = function (pid) { + socket.emit('plugins.composer.push', pid, function (err, threadData) { + if (err) { + return alerts.error(err); + } + threadData.action = 'posts.edit'; + threadData.pid = pid; + threadData.modified = false; + push(threadData); + }); + }; + + composer.load = function (post_uuid) { + var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); + if (postContainer.length) { + activate(post_uuid); + resize.reposition(postContainer); + focusElements(postContainer); + onShow(); + } else if (composer.formatting) { + createNewComposer(post_uuid); + } else { + socket.emit('plugins.composer.getFormattingOptions', function (err, options) { + if (err) { + return alerts.error(err); + } + composer.formatting = options; + createNewComposer(post_uuid); + }); + } + }; + + composer.enhance = function (postContainer, post_uuid, postData) { + /* + This method enhances a composer container with client-side sugar (preview, etc) + Everything in here also applies to the /compose route + */ + + if (!post_uuid && !postData) { + post_uuid = utils.generateUUID(); + composer.posts[post_uuid] = ajaxify.data; + postData = ajaxify.data; + postContainer.attr('data-uuid', post_uuid); + } + + var bodyEl = postContainer.find('textarea'); + var submitBtn = postContainer.find('.composer-submit'); + + categoryList.init(postContainer, composer.posts[post_uuid]); + scheduler.init(postContainer, composer.posts); + + formatting.addHandler(postContainer); + formatting.addComposerButtons(); + preview.handleToggler(postContainer); + + uploads.initialize(post_uuid); + tags.init(postContainer, composer.posts[post_uuid]); + autocomplete.init(postContainer, post_uuid); + + postContainer.on('change', 'input, textarea', function () { + composer.posts[post_uuid].modified = true; + + // Post is modified, save to list of opened drafts + drafts.updateVisibility('available', composer.posts[post_uuid].save_id, true); + drafts.updateVisibility('open', composer.posts[post_uuid].save_id, true); + }); + + submitBtn.on('click', function (e) { + e.preventDefault(); + e.stopPropagation(); // Other click events bring composer back to active state which is undesired on submit + + $(this).attr('disabled', true); + post(post_uuid); + }); + + require(['mousetrap'], function (mousetrap) { + mousetrap(postContainer.get(0)).bind('mod+enter', function () { + submitBtn.attr('disabled', true); + post(post_uuid); + }); + }); + + postContainer.find('.composer-discard').on('click', function (e) { + e.preventDefault(); + + if (!composer.posts[post_uuid].modified) { + composer.discard(post_uuid); + return removeComposerHistory(); + } + + formatting.exitFullscreen(); + + var btn = $(this).prop('disabled', true); + translator.translate('[[modules:composer.discard]]', function (translated) { + bootbox.confirm(translated, function (confirm) { + if (confirm) { + composer.discard(post_uuid); + removeComposerHistory(); + } + btn.prop('disabled', false); + }); + }); + }); + + postContainer.find('.composer-minimize, .minimize .trigger').on('click', function (e) { + e.preventDefault(); + e.stopPropagation(); + composer.minimize(post_uuid); + }); + + bodyEl.on('input propertychange', utils.debounce(function () { + preview.render(postContainer); + }, 250)); + + bodyEl.on('scroll', function () { + preview.matchScroll(postContainer); + }); + + drafts.init(postContainer, postData); + const draft = drafts.get(postData.save_id); + + preview.render(postContainer, function () { + preview.matchScroll(postContainer); + }); + + handleHelp(postContainer); + handleSearch(postContainer); + focusElements(postContainer); + if (postData.action === 'posts.edit') { + composer.updateThumbCount(post_uuid, postContainer); + } + + // Hide "zen mode" if fullscreen API is not enabled/available (ahem, iOS...) + if (!screenfull.isEnabled) { + $('[data-format="zen"]').addClass('hidden'); + } + + hooks.fire('action:composer.enhanced', { postContainer, postData, draft }); + }; + + async function getSelectedCategory(postData) { + if (ajaxify.data.template.category) { + // no need to load data if we are already on the category page + return ajaxify.data; + } else if (parseInt(postData.cid, 10)) { + return await api.get(`/api/category/${postData.cid}`, {}); + } + return null; + } + + async function createNewComposer(post_uuid) { + var postData = composer.posts[post_uuid]; + + var isTopic = postData ? postData.hasOwnProperty('cid') : false; + var isMain = postData ? !!postData.isMain : false; + var isEditing = postData ? !!postData.pid : false; + var isGuestPost = postData ? parseInt(postData.uid, 10) === 0 : false; + const isScheduled = postData.timestamp > Date.now(); + + // see + // https://github.com/NodeBB/NodeBB/issues/2994 and + // https://github.com/NodeBB/NodeBB/issues/1951 + // remove when 1951 is resolved + + var title = postData.title.replace(/%/g, '%').replace(/,/g, ','); + postData.category = await getSelectedCategory(postData); + const privileges = postData.category ? postData.category.privileges : ajaxify.data.privileges; + var data = { + title: title, + titleLength: title.length, + body: postData.body, + mobile: composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm', + resizable: true, + thumb: postData.thumb, + isTopicOrMain: isTopic || isMain, + maximumTitleLength: config.maximumTitleLength, + maximumPostLength: config.maximumPostLength, + minimumTagLength: config.minimumTagLength, + maximumTagLength: config.maximumTagLength, + isTopic: isTopic, + isEditing: isEditing, + canSchedule: !!(isMain && privileges && + ((privileges['topics:schedule'] && !isEditing) || (isScheduled && privileges.view_scheduled))), + showHandleInput: config.allowGuestHandles && + (app.user.uid === 0 || (isEditing && isGuestPost && app.user.isAdmin)), + handle: postData ? postData.handle || '' : undefined, + formatting: composer.formatting, + tagWhitelist: postData.category ? postData.category.tagWhitelist : ajaxify.data.tagWhitelist, + privileges: app.user.privileges, + selectedCategory: postData.category, + submitOptions: [ + // Add items using `filter:composer.create`, or just add them to the