├── .gitattributes ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── controllers.js ├── eslint.config.mjs ├── library.js ├── package.json ├── plugin.json ├── screenshots ├── desktop.png └── mobile.png ├── static ├── lib │ ├── admin.js │ ├── client.js │ ├── composer.js │ └── composer │ │ ├── autocomplete.js │ │ ├── categoryList.js │ │ ├── controls.js │ │ ├── drafts.js │ │ ├── formatting.js │ │ ├── post-queue.js │ │ ├── preview.js │ │ ├── resize.js │ │ ├── scheduler.js │ │ ├── tags.js │ │ └── uploads.js ├── scss │ ├── composer.scss │ ├── page-compose.scss │ ├── textcomplete.scss │ └── zen-mode.scss └── templates │ ├── admin │ └── plugins │ │ └── composer-default.tpl │ ├── compose.tpl │ ├── composer.tpl │ ├── modals │ └── topic-scheduler.tpl │ └── partials │ ├── composer-formatting.tpl │ ├── composer-tags.tpl │ ├── composer-title-container.tpl │ └── composer-write-preview.tpl └── websockets.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | .vscode 37 | 38 | ## Ignore Visual Studio temporary files, build results, and 39 | ## files generated by popular Visual Studio add-ons. 40 | 41 | # User-specific files 42 | *.suo 43 | *.user 44 | *.sln.docstates 45 | 46 | # Build results 47 | 48 | [Dd]ebug/ 49 | [Rr]elease/ 50 | x64/ 51 | build/ 52 | [Bb]in/ 53 | [Oo]bj/ 54 | 55 | # MSTest test Results 56 | [Tt]est[Rr]esult*/ 57 | [Bb]uild[Ll]og.* 58 | 59 | *_i.c 60 | *_p.c 61 | *.ilk 62 | *.meta 63 | *.obj 64 | *.pch 65 | *.pdb 66 | *.pgc 67 | *.pgd 68 | *.rsp 69 | *.sbr 70 | *.tlb 71 | *.tli 72 | *.tlh 73 | *.tmp 74 | *.tmp_proj 75 | *.log 76 | *.vspscc 77 | *.vssscc 78 | .builds 79 | *.pidb 80 | *.log 81 | *.scc 82 | 83 | # Visual C++ cache files 84 | ipch/ 85 | *.aps 86 | *.ncb 87 | *.opensdf 88 | *.sdf 89 | *.cachefile 90 | 91 | # Visual Studio profiler 92 | *.psess 93 | *.vsp 94 | *.vspx 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | 103 | # TeamCity is a build add-in 104 | _TeamCity* 105 | 106 | # DotCover is a Code Coverage Tool 107 | *.dotCover 108 | 109 | # NCrunch 110 | *.ncrunch* 111 | .*crunch*.local.xml 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.Publish.xml 131 | *.pubxml 132 | 133 | # NuGet Packages Directory 134 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 135 | #packages/ 136 | 137 | # Windows Azure Build Output 138 | csx 139 | *.build.csdef 140 | 141 | # Windows Store app package directory 142 | AppPackages/ 143 | 144 | # Others 145 | sql/ 146 | *.Cache 147 | ClientBin/ 148 | [Ss]tyle[Cc]op.* 149 | ~$* 150 | *~ 151 | *.dbmdl 152 | *.[Pp]ublish.xml 153 | *.pfx 154 | *.publishsettings 155 | 156 | # RIA/Silverlight projects 157 | Generated_Code/ 158 | 159 | # Backup & report files from converting an old project file to a newer 160 | # Visual Studio version. Backup files are not needed, because we have git ;-) 161 | _UpgradeReport_Files/ 162 | Backup*/ 163 | UpgradeLog*.XML 164 | UpgradeLog*.htm 165 | 166 | # SQL Server files 167 | App_Data/*.mdf 168 | App_Data/*.ldf 169 | 170 | ############# 171 | ## Windows detritus 172 | ############# 173 | 174 | # Windows image file caches 175 | Thumbs.db 176 | ehthumbs.db 177 | 178 | # Folder config file 179 | Desktop.ini 180 | 181 | # Recycle Bin used on file shares 182 | $RECYCLE.BIN/ 183 | 184 | # Mac crap 185 | .DS_Store 186 | 187 | # can't have it committed because it interferes with the package-lock.json 188 | # generated by each individual install 189 | package-lock.json 190 | yarn.lock 191 | 192 | 193 | ############# 194 | ## Python 195 | ############# 196 | 197 | *.py[co] 198 | 199 | # Packages 200 | *.egg 201 | *.egg-info 202 | dist/ 203 | build/ 204 | eggs/ 205 | parts/ 206 | var/ 207 | sdist/ 208 | develop-eggs/ 209 | .installed.cfg 210 | 211 | # Installer logs 212 | pip-log.txt 213 | 214 | # Unit test / coverage reports 215 | .coverage 216 | .tox 217 | 218 | #Translations 219 | *.mo 220 | 221 | #Mr Developer 222 | .mr.developer.cfg 223 | 224 | sftp-config.json 225 | node_modules/ 226 | 227 | *.sublime-project 228 | *.sublime-workspace -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | sftp-config.json 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 NodeBB Inc. 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Default Composer for NodeBB 2 | 3 | This plugin activates the default composer for NodeBB. It is activated by default, but can be swapped out as necessary. 4 | 5 | ## Screenshots 6 | 7 | ### Desktop 8 | ![Desktop Composer](screenshots/desktop.png?raw=true) 9 | 10 | ### Mobile Devices 11 | ![Mobile Composer](screenshots/mobile.png?raw=true) -------------------------------------------------------------------------------- /controllers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Controllers = {}; 4 | 5 | Controllers.renderAdminPage = function (req, res) { 6 | res.render('admin/plugins/composer-default', { 7 | title: 'Composer (Default)', 8 | }); 9 | }; 10 | 11 | module.exports = Controllers; 12 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import serverConfig from 'eslint-config-nodebb'; 4 | import publicConfig from 'eslint-config-nodebb/public'; 5 | 6 | export default [ 7 | ...publicConfig, 8 | ...serverConfig, 9 | ]; 10 | 11 | -------------------------------------------------------------------------------- /library.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const url = require('url'); 4 | 5 | const nconf = require.main.require('nconf'); 6 | const validator = require('validator'); 7 | 8 | const plugins = require.main.require('./src/plugins'); 9 | const topics = require.main.require('./src/topics'); 10 | const categories = require.main.require('./src/categories'); 11 | const posts = require.main.require('./src/posts'); 12 | const user = require.main.require('./src/user'); 13 | const meta = require.main.require('./src/meta'); 14 | const privileges = require.main.require('./src/privileges'); 15 | const translator = require.main.require('./src/translator'); 16 | const utils = require.main.require('./src/utils'); 17 | const helpers = require.main.require('./src/controllers/helpers'); 18 | const SocketPlugins = require.main.require('./src/socket.io/plugins'); 19 | const socketMethods = require('./websockets'); 20 | 21 | const plugin = module.exports; 22 | 23 | plugin.socketMethods = socketMethods; 24 | 25 | plugin.init = async function (data) { 26 | const { router } = data; 27 | const routeHelpers = require.main.require('./src/routes/helpers'); 28 | const controllers = require('./controllers'); 29 | SocketPlugins.composer = socketMethods; 30 | routeHelpers.setupAdminPageRoute(router, '/admin/plugins/composer-default', controllers.renderAdminPage); 31 | }; 32 | 33 | plugin.appendConfig = async function (config) { 34 | config['composer-default'] = await meta.settings.get('composer-default'); 35 | return config; 36 | }; 37 | 38 | plugin.addAdminNavigation = async function (header) { 39 | header.plugins.push({ 40 | route: '/plugins/composer-default', 41 | icon: 'fa-edit', 42 | name: 'Composer (Default)', 43 | }); 44 | return header; 45 | }; 46 | 47 | plugin.addPrefetchTags = async function (hookData) { 48 | const prefetch = [ 49 | '/assets/src/modules/composer.js', '/assets/src/modules/composer/uploads.js', '/assets/src/modules/composer/drafts.js', 50 | '/assets/src/modules/composer/tags.js', '/assets/src/modules/composer/categoryList.js', '/assets/src/modules/composer/resize.js', 51 | '/assets/src/modules/composer/autocomplete.js', '/assets/templates/composer.tpl', 52 | `/assets/language/${meta.config.defaultLang || 'en-GB'}/topic.json`, 53 | `/assets/language/${meta.config.defaultLang || 'en-GB'}/modules.json`, 54 | `/assets/language/${meta.config.defaultLang || 'en-GB'}/tags.json`, 55 | ]; 56 | 57 | hookData.links = hookData.links.concat(prefetch.map(path => ({ 58 | rel: 'prefetch', 59 | href: `${nconf.get('relative_path') + path}?${meta.config['cache-buster']}`, 60 | }))); 61 | 62 | return hookData; 63 | }; 64 | 65 | plugin.getFormattingOptions = async function () { 66 | const defaultVisibility = { 67 | mobile: true, 68 | desktop: true, 69 | 70 | // op or reply 71 | main: true, 72 | reply: true, 73 | }; 74 | let payload = { 75 | defaultVisibility, 76 | options: [ 77 | { 78 | name: 'tags', 79 | title: '[[global:tags.tags]]', 80 | className: 'fa fa-tags', 81 | visibility: { 82 | ...defaultVisibility, 83 | desktop: false, 84 | }, 85 | }, 86 | { 87 | name: 'zen', 88 | title: '[[modules:composer.zen-mode]]', 89 | className: 'fa fa-arrows-alt', 90 | visibility: defaultVisibility, 91 | }, 92 | ], 93 | }; 94 | if (parseInt(meta.config.allowTopicsThumbnail, 10) === 1) { 95 | payload.options.push({ 96 | name: 'thumbs', 97 | title: '[[topic:composer.thumb-title]]', 98 | className: 'fa fa-address-card-o', 99 | badge: true, 100 | visibility: { 101 | ...defaultVisibility, 102 | reply: false, 103 | }, 104 | }); 105 | } 106 | 107 | payload = await plugins.hooks.fire('filter:composer.formatting', payload); 108 | 109 | payload.options.forEach((option) => { 110 | option.visibility = { 111 | ...defaultVisibility, 112 | ...option.visibility || {}, 113 | }; 114 | }); 115 | 116 | return payload ? payload.options : null; 117 | }; 118 | 119 | plugin.filterComposerBuild = async function (hookData) { 120 | const { req } = hookData; 121 | const { res } = hookData; 122 | 123 | if (req.query.p) { 124 | try { 125 | const a = url.parse(req.query.p, true, true); 126 | return helpers.redirect(res, `/${(a.path || '').replace(/^\/*/, '')}`); 127 | } catch (e) { 128 | return helpers.redirect(res, '/'); 129 | } 130 | } else if (!req.query.pid && !req.query.tid && !req.query.cid) { 131 | return helpers.redirect(res, '/'); 132 | } 133 | 134 | await checkPrivileges(req, res); 135 | 136 | const [ 137 | isMainPost, 138 | postData, 139 | topicData, 140 | categoryData, 141 | isAdmin, 142 | isMod, 143 | formatting, 144 | tagWhitelist, 145 | globalPrivileges, 146 | canTagTopics, 147 | canScheduleTopics, 148 | ] = await Promise.all([ 149 | posts.isMain(req.query.pid), 150 | getPostData(req), 151 | getTopicData(req), 152 | categories.getCategoryFields(req.query.cid, [ 153 | 'name', 'icon', 'color', 'bgColor', 'backgroundImage', 'imageClass', 'minTags', 'maxTags', 154 | ]), 155 | user.isAdministrator(req.uid), 156 | isModerator(req), 157 | plugin.getFormattingOptions(), 158 | getTagWhitelist(req.query, req.uid), 159 | privileges.global.get(req.uid), 160 | canTag(req), 161 | canSchedule(req), 162 | ]); 163 | 164 | const isEditing = !!req.query.pid; 165 | const isGuestPost = postData && parseInt(postData.uid, 10) === 0; 166 | const save_id = utils.generateSaveId(req.uid); 167 | const discardRoute = generateDiscardRoute(req, topicData); 168 | const body = await generateBody(req, postData); 169 | 170 | let action = 'topics.post'; 171 | let isMain = isMainPost; 172 | if (req.query.tid) { 173 | action = 'posts.reply'; 174 | } else if (req.query.pid) { 175 | action = 'posts.edit'; 176 | } else { 177 | isMain = true; 178 | } 179 | globalPrivileges['topics:tag'] = canTagTopics; 180 | const cid = parseInt(req.query.cid, 10); 181 | const topicTitle = topicData && topicData.title ? topicData.title.replace(/%/g, '%').replace(/,/g, ',') : validator.escape(String(req.query.title || '')); 182 | return { 183 | req: req, 184 | res: res, 185 | templateData: { 186 | disabled: !req.query.pid && !req.query.tid && !req.query.cid, 187 | pid: parseInt(req.query.pid, 10), 188 | tid: parseInt(req.query.tid, 10), 189 | cid: cid || (topicData ? topicData.cid : null), 190 | action: action, 191 | toPid: parseInt(req.query.toPid, 10), 192 | discardRoute: discardRoute, 193 | 194 | resizable: false, 195 | allowTopicsThumbnail: parseInt(meta.config.allowTopicsThumbnail, 10) === 1 && isMain, 196 | 197 | // can't use title property as that is used for page title 198 | topicTitle: topicTitle, 199 | titleLength: topicTitle ? topicTitle.length : 0, 200 | topic: topicData, 201 | thumb: topicData ? topicData.thumb : '', 202 | body: body, 203 | 204 | isMain: isMain, 205 | isTopicOrMain: !!req.query.cid || isMain, 206 | maximumTitleLength: meta.config.maximumTitleLength, 207 | maximumPostLength: meta.config.maximumPostLength, 208 | minimumTagLength: meta.config.minimumTagLength || 3, 209 | maximumTagLength: meta.config.maximumTagLength || 15, 210 | tagWhitelist: tagWhitelist, 211 | selectedCategory: cid ? categoryData : null, 212 | minTags: categoryData.minTags, 213 | maxTags: categoryData.maxTags, 214 | 215 | isTopic: !!req.query.cid, 216 | isEditing: isEditing, 217 | canSchedule: canScheduleTopics, 218 | showHandleInput: meta.config.allowGuestHandles === 1 && 219 | (req.uid === 0 || (isEditing && isGuestPost && (isAdmin || isMod))), 220 | handle: postData ? postData.handle || '' : undefined, 221 | formatting: formatting, 222 | isAdminOrMod: isAdmin || isMod, 223 | save_id: save_id, 224 | privileges: globalPrivileges, 225 | 'composer:showHelpTab': meta.config['composer:showHelpTab'] === 1, 226 | }, 227 | }; 228 | }; 229 | 230 | async function checkPrivileges(req, res) { 231 | const notAllowed = ( 232 | (req.query.cid && !await privileges.categories.can('topics:create', req.query.cid, req.uid)) || 233 | (req.query.tid && !await privileges.topics.can('topics:reply', req.query.tid, req.uid)) || 234 | (req.query.pid && !await privileges.posts.can('posts:edit', req.query.pid, req.uid)) 235 | ); 236 | 237 | if (notAllowed) { 238 | await helpers.notAllowed(req, res); 239 | } 240 | } 241 | 242 | function generateDiscardRoute(req, topicData) { 243 | if (req.query.cid) { 244 | return `${nconf.get('relative_path')}/category/${validator.escape(String(req.query.cid))}`; 245 | } else if ((req.query.tid || req.query.pid)) { 246 | if (topicData) { 247 | return `${nconf.get('relative_path')}/topic/${topicData.slug}`; 248 | } 249 | return `${nconf.get('relative_path')}/`; 250 | } 251 | } 252 | 253 | async function generateBody(req, postData) { 254 | let body = ''; 255 | // Quoted reply 256 | if (req.query.toPid && parseInt(req.query.quoted, 10) === 1 && postData) { 257 | const username = await user.getUserField(postData.uid, 'username'); 258 | const translated = await translator.translate(`[[modules:composer.user-said, ${username}]]`); 259 | body = `${translated}\n` + 260 | `> ${postData ? `${postData.content.replace(/\n/g, '\n> ')}\n\n` : ''}`; 261 | } else if (req.query.body || req.query.content) { 262 | body = validator.escape(String(req.query.body || req.query.content)); 263 | } 264 | body = postData ? postData.content : ''; 265 | return translator.escape(body); 266 | } 267 | 268 | async function getPostData(req) { 269 | if (!req.query.pid && !req.query.toPid) { 270 | return null; 271 | } 272 | 273 | return await posts.getPostData(req.query.pid || req.query.toPid); 274 | } 275 | 276 | async function getTopicData(req) { 277 | if (req.query.tid) { 278 | return await topics.getTopicData(req.query.tid); 279 | } else if (req.query.pid) { 280 | return await topics.getTopicDataByPid(req.query.pid); 281 | } 282 | return null; 283 | } 284 | 285 | async function isModerator(req) { 286 | if (!req.loggedIn) { 287 | return false; 288 | } 289 | const cid = cidFromQuery(req.query); 290 | return await user.isModerator(req.uid, cid); 291 | } 292 | 293 | async function canTag(req) { 294 | if (parseInt(req.query.cid, 10)) { 295 | return await privileges.categories.can('topics:tag', req.query.cid, req.uid); 296 | } 297 | return true; 298 | } 299 | 300 | async function canSchedule(req) { 301 | if (parseInt(req.query.cid, 10)) { 302 | return await privileges.categories.can('topics:schedule', req.query.cid, req.uid); 303 | } 304 | return false; 305 | } 306 | 307 | async function getTagWhitelist(query, uid) { 308 | const cid = await cidFromQuery(query); 309 | const [tagWhitelist, isAdminOrMod] = await Promise.all([ 310 | categories.getTagWhitelist([cid]), 311 | privileges.categories.isAdminOrMod(cid, uid), 312 | ]); 313 | return categories.filterTagWhitelist(tagWhitelist[0], isAdminOrMod); 314 | } 315 | 316 | async function cidFromQuery(query) { 317 | if (query.cid) { 318 | return query.cid; 319 | } else if (query.tid) { 320 | return await topics.getTopicField(query.tid, 'cid'); 321 | } else if (query.pid) { 322 | return await posts.getCidByPid(query.pid); 323 | } 324 | return null; 325 | } 326 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodebb-plugin-composer-default", 3 | "version": "10.2.50", 4 | "description": "Default composer for NodeBB", 5 | "main": "library.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/NodeBB/nodebb-plugin-composer-default" 9 | }, 10 | "scripts": { 11 | "lint": "eslint ." 12 | }, 13 | "keywords": [ 14 | "nodebb", 15 | "plugin", 16 | "composer", 17 | "markdown" 18 | ], 19 | "author": { 20 | "name": "NodeBB Team", 21 | "email": "sales@nodebb.org" 22 | }, 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/NodeBB/nodebb-plugin-composer-default/issues" 26 | }, 27 | "readmeFilename": "README.md", 28 | "nbbpm": { 29 | "compatibility": "^4.0.0" 30 | }, 31 | "dependencies": { 32 | "screenfull": "^5.0.2", 33 | "validator": "^13.7.0" 34 | }, 35 | "devDependencies": { 36 | "eslint": "^9.25.1", 37 | "eslint-config-nodebb": "^1.1.4", 38 | "eslint-plugin-import": "^2.31.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nodebb-plugin-composer-default", 3 | "url": "https://github.com/NodeBB/nodebb-plugin-composer-default", 4 | "library": "library.js", 5 | "hooks": [ 6 | { "hook": "static:app.load", "method": "init" }, 7 | { "hook": "filter:config.get", "method": "appendConfig" }, 8 | { "hook": "filter:composer.build", "method": "filterComposerBuild" }, 9 | { "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, 10 | { "hook": "filter:meta.getLinkTags", "method": "addPrefetchTags" } 11 | ], 12 | "scss": [ 13 | "./static/scss/composer.scss" 14 | ], 15 | "scripts": [ 16 | "./static/lib/client.js", 17 | "./node_modules/screenfull/dist/screenfull.js" 18 | ], 19 | "modules": { 20 | "composer.js": "./static/lib/composer.js", 21 | "composer/categoryList.js": "./static/lib/composer/categoryList.js", 22 | "composer/controls.js": "./static/lib/composer/controls.js", 23 | "composer/drafts.js": "./static/lib/composer/drafts.js", 24 | "composer/formatting.js": "./static/lib/composer/formatting.js", 25 | "composer/preview.js": "./static/lib/composer/preview.js", 26 | "composer/resize.js": "./static/lib/composer/resize.js", 27 | "composer/scheduler.js": "./static/lib/composer/scheduler.js", 28 | "composer/tags.js": "./static/lib/composer/tags.js", 29 | "composer/uploads.js": "./static/lib/composer/uploads.js", 30 | "composer/autocomplete.js": "./static/lib/composer/autocomplete.js", 31 | "composer/post-queue.js": "./static/lib/composer/post-queue.js", 32 | "../admin/plugins/composer-default.js": "./static/lib/admin.js" 33 | }, 34 | "templates": "static/templates" 35 | } -------------------------------------------------------------------------------- /screenshots/desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NodeBB/nodebb-plugin-composer-default/6c5c0f50abfd12d32bd349ccd3c31b1f95006578/screenshots/desktop.png -------------------------------------------------------------------------------- /screenshots/mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NodeBB/nodebb-plugin-composer-default/6c5c0f50abfd12d32bd349ccd3c31b1f95006578/screenshots/mobile.png -------------------------------------------------------------------------------- /static/lib/admin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | define('admin/plugins/composer-default', ['settings'], function (Settings) { 4 | const ACP = {}; 5 | 6 | ACP.init = function () { 7 | Settings.load('composer-default', $('.composer-default-settings')); 8 | 9 | $('#save').on('click', function () { 10 | Settings.save('composer-default', $('.composer-default-settings')); 11 | }); 12 | }; 13 | 14 | return ACP; 15 | }); 16 | -------------------------------------------------------------------------------- /static/lib/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | $(document).ready(function () { 4 | $(window).on('action:app.load', function () { 5 | require(['composer/drafts'], function (drafts) { 6 | drafts.migrateGuest(); 7 | drafts.loadOpen(); 8 | }); 9 | }); 10 | 11 | $(window).on('action:composer.topic.new', function (ev, data) { 12 | if (config['composer-default'].composeRouteEnabled !== 'on') { 13 | require(['composer'], function (composer) { 14 | composer.newTopic({ 15 | cid: data.cid, 16 | title: data.title || '', 17 | body: data.body || '', 18 | tags: data.tags || [], 19 | }); 20 | }); 21 | } else { 22 | ajaxify.go( 23 | 'compose?cid=' + data.cid + 24 | (data.title ? '&title=' + encodeURIComponent(data.title) : '') + 25 | (data.body ? '&body=' + encodeURIComponent(data.body) : '') 26 | ); 27 | } 28 | }); 29 | 30 | $(window).on('action:composer.post.edit', function (ev, data) { 31 | if (config['composer-default'].composeRouteEnabled !== 'on') { 32 | require(['composer'], function (composer) { 33 | composer.editPost({ pid: data.pid }); 34 | }); 35 | } else { 36 | ajaxify.go('compose?pid=' + data.pid); 37 | } 38 | }); 39 | 40 | $(window).on('action:composer.post.new', function (ev, data) { 41 | // backwards compatibility 42 | data.body = data.body || data.text; 43 | data.title = data.title || data.topicName; 44 | if (config['composer-default'].composeRouteEnabled !== 'on') { 45 | require(['composer'], function (composer) { 46 | composer.newReply({ 47 | tid: data.tid, 48 | toPid: data.pid, 49 | title: data.title, 50 | body: data.body, 51 | }); 52 | }); 53 | } else { 54 | ajaxify.go( 55 | 'compose?tid=' + data.tid + 56 | (data.pid ? '&toPid=' + data.pid : '') + 57 | (data.title ? '&title=' + encodeURIComponent(data.title) : '') + 58 | (data.body ? '&body=' + encodeURIComponent(data.body) : '') 59 | ); 60 | } 61 | }); 62 | 63 | $(window).on('action:composer.addQuote', function (ev, data) { 64 | data.body = data.body || data.text; 65 | data.title = data.title || data.topicName; 66 | if (config['composer-default'].composeRouteEnabled !== 'on') { 67 | require(['composer'], function (composer) { 68 | var topicUUID = composer.findByTid(data.tid); 69 | composer.addQuote({ 70 | tid: data.tid, 71 | toPid: data.pid, 72 | selectedPid: data.selectedPid, 73 | title: data.title, 74 | username: data.username, 75 | body: data.body, 76 | uuid: topicUUID, 77 | }); 78 | }); 79 | } else { 80 | ajaxify.go('compose?tid=' + data.tid + '&toPid=' + data.pid + '"ed=1&username=' + data.username); 81 | } 82 | }); 83 | 84 | $(window).on('action:composer.enhance', function (ev, data) { 85 | require(['composer'], function (composer) { 86 | composer.enhance(data.container); 87 | }); 88 | }); 89 | }); 90 | -------------------------------------------------------------------------------- /static/lib/composer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | define('composer', [ 4 | 'taskbar', 5 | 'translator', 6 | 'composer/uploads', 7 | 'composer/formatting', 8 | 'composer/drafts', 9 | 'composer/tags', 10 | 'composer/categoryList', 11 | 'composer/preview', 12 | 'composer/resize', 13 | 'composer/autocomplete', 14 | 'composer/scheduler', 15 | 'composer/post-queue', 16 | 'scrollStop', 17 | 'topicThumbs', 18 | 'api', 19 | 'bootbox', 20 | 'alerts', 21 | 'hooks', 22 | 'messages', 23 | 'search', 24 | 'screenfull', 25 | ], function (taskbar, translator, uploads, formatting, drafts, tags, 26 | categoryList, preview, resize, autocomplete, scheduler, postQueue, scrollStop, 27 | topicThumbs, api, bootbox, alerts, hooks, messagesModule, search, screenfull) { 28 | var composer = { 29 | active: undefined, 30 | posts: {}, 31 | bsEnvironment: undefined, 32 | formatting: undefined, 33 | }; 34 | 35 | $(window).off('resize', onWindowResize).on('resize', onWindowResize); 36 | onWindowResize(); 37 | 38 | $(window).on('action:composer.topics.post', function (ev, data) { 39 | localStorage.removeItem('category:' + data.data.cid + ':bookmark'); 40 | localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked'); 41 | }); 42 | 43 | $(window).on('popstate', function () { 44 | var env = utils.findBootstrapEnvironment(); 45 | if (composer.active && (env === 'xs' || env === 'sm')) { 46 | if (!composer.posts[composer.active].modified) { 47 | composer.discard(composer.active); 48 | if (composer.discardConfirm && composer.discardConfirm.length) { 49 | composer.discardConfirm.modal('hide'); 50 | delete composer.discardConfirm; 51 | } 52 | return; 53 | } 54 | 55 | translator.translate('[[modules:composer.discard]]', function (translated) { 56 | composer.discardConfirm = bootbox.confirm(translated, function (confirm) { 57 | if (confirm) { 58 | composer.discard(composer.active); 59 | } else { 60 | composer.posts[composer.active].modified = true; 61 | } 62 | }); 63 | composer.posts[composer.active].modified = false; 64 | }); 65 | } 66 | }); 67 | 68 | function removeComposerHistory() { 69 | var env = composer.bsEnvironment; 70 | if (ajaxify.data.template.compose === true || env === 'xs' || env === 'sm') { 71 | history.back(); 72 | } 73 | } 74 | 75 | function onWindowResize() { 76 | var env = utils.findBootstrapEnvironment(); 77 | var isMobile = env === 'xs' || env === 'sm'; 78 | 79 | if (preview.toggle) { 80 | if (preview.env !== env && isMobile) { 81 | preview.env = env; 82 | preview.toggle(false); 83 | } 84 | preview.env = env; 85 | } 86 | 87 | if (composer.active !== undefined) { 88 | resize.reposition($('.composer[data-uuid="' + composer.active + '"]')); 89 | 90 | if (!isMobile && window.location.pathname.startsWith(config.relative_path + '/compose')) { 91 | /* 92 | * If this conditional is met, we're no longer in mobile/tablet 93 | * resolution but we've somehow managed to have a mobile 94 | * composer load, so let's go back to the topic 95 | */ 96 | history.back(); 97 | } else if (isMobile && !window.location.pathname.startsWith(config.relative_path + '/compose')) { 98 | /* 99 | * In this case, we're in mobile/tablet resolution but the composer 100 | * that loaded was a regular composer, so let's fix the address bar 101 | */ 102 | mobileHistoryAppend(); 103 | } 104 | } 105 | composer.bsEnvironment = env; 106 | } 107 | 108 | function alreadyOpen(post) { 109 | // If a composer for the same cid/tid/pid is already open, return the uuid, else return bool false 110 | var type; 111 | var id; 112 | 113 | if (post.hasOwnProperty('cid')) { 114 | type = 'cid'; 115 | } else if (post.hasOwnProperty('tid')) { 116 | type = 'tid'; 117 | } else if (post.hasOwnProperty('pid')) { 118 | type = 'pid'; 119 | } 120 | 121 | id = post[type]; 122 | 123 | // Find a match 124 | for (const uuid of Object.keys(composer.posts)) { 125 | if (composer.posts[uuid].hasOwnProperty(type) && id === composer.posts[uuid][type]) { 126 | return uuid; 127 | } 128 | } 129 | 130 | // No matches... 131 | return false; 132 | } 133 | 134 | function push(post) { 135 | if (!post) { 136 | return; 137 | } 138 | 139 | var uuid = utils.generateUUID(); 140 | var existingUUID = alreadyOpen(post); 141 | 142 | if (existingUUID) { 143 | taskbar.updateActive(existingUUID); 144 | return composer.load(existingUUID); 145 | } 146 | 147 | var actionText = '[[topic:composer.new-topic]]'; 148 | if (post.action === 'posts.reply') { 149 | actionText = '[[topic:composer.replying-to]]'; 150 | } else if (post.action === 'posts.edit') { 151 | actionText = '[[topic:composer.editing-in]]'; 152 | } 153 | 154 | translator.translate(actionText, function (translatedAction) { 155 | taskbar.push('composer', uuid, { 156 | title: translatedAction.replace('%1', '"' + post.title + '"'), 157 | }); 158 | }); 159 | 160 | composer.posts[uuid] = post; 161 | composer.load(uuid); 162 | } 163 | 164 | async function composerAlert(post_uuid, message) { 165 | $('.composer[data-uuid="' + post_uuid + '"]').find('.composer-submit').removeAttr('disabled'); 166 | 167 | const { showAlert } = await hooks.fire('filter:composer.error', { post_uuid, message, showAlert: true }); 168 | 169 | if (showAlert) { 170 | alerts.alert({ 171 | type: 'danger', 172 | timeout: 10000, 173 | title: '', 174 | message: message, 175 | alert_id: 'post_error', 176 | }); 177 | } 178 | } 179 | 180 | composer.findByTid = function (tid) { 181 | // Iterates through the initialised composers and returns the uuid of the matching composer 182 | for (const uuid of Object.keys(composer.posts)) { 183 | if (composer.posts[uuid].hasOwnProperty('tid') && String(composer.posts[uuid].tid) === String(tid)) { 184 | return uuid; 185 | } 186 | } 187 | 188 | return null; 189 | }; 190 | 191 | composer.addButton = function (iconClass, onClick, title) { 192 | formatting.addButton(iconClass, onClick, title); 193 | }; 194 | 195 | composer.newTopic = async (data) => { 196 | let pushData = { 197 | save_id: data.save_id, 198 | action: 'topics.post', 199 | cid: data.cid, 200 | handle: data.handle, 201 | title: data.title || '', 202 | body: data.body || '', 203 | tags: data.tags || [], 204 | modified: !!((data.title && data.title.length) || (data.body && data.body.length)), 205 | isMain: true, 206 | }; 207 | 208 | ({ pushData } = await hooks.fire('filter:composer.topic.push', { 209 | data: data, 210 | pushData: pushData, 211 | })); 212 | 213 | push(pushData); 214 | }; 215 | 216 | composer.addQuote = function (data) { 217 | // tid, toPid, selectedPid, title, username, text, uuid 218 | data.uuid = data.uuid || composer.active; 219 | 220 | var escapedTitle = (data.title || '') 221 | .replace(/([\\`*_{}[\]()#+\-.!])/g, '\\$1') 222 | .replace(/\[/g, '[') 223 | .replace(/\]/g, ']') 224 | .replace(/%/g, '%') 225 | .replace(/,/g, ','); 226 | 227 | if (data.body) { 228 | data.body = '> ' + data.body.replace(/\n/g, '\n> ') + '\n\n'; 229 | } 230 | var link = '[' + escapedTitle + '](' + config.relative_path + '/post/' + encodeURIComponent(data.selectedPid || data.toPid) + ')'; 231 | if (data.uuid === undefined) { 232 | if (data.title && (data.selectedPid || data.toPid)) { 233 | composer.newReply({ 234 | tid: data.tid, 235 | toPid: data.toPid, 236 | title: data.title, 237 | body: '[[modules:composer.user-said-in, ' + data.username + ', ' + link + ']]\n' + data.body, 238 | }); 239 | } else { 240 | composer.newReply({ 241 | tid: data.tid, 242 | toPid: data.toPid, 243 | title: data.title, 244 | body: '[[modules:composer.user-said, ' + data.username + ']]\n' + data.body, 245 | }); 246 | } 247 | return; 248 | } else if (data.uuid !== composer.active) { 249 | // If the composer is not currently active, activate it 250 | composer.load(data.uuid); 251 | } 252 | 253 | var postContainer = $('.composer[data-uuid="' + data.uuid + '"]'); 254 | var bodyEl = postContainer.find('textarea'); 255 | var prevText = bodyEl.val(); 256 | if (data.title && (data.selectedPid || data.toPid)) { 257 | translator.translate('[[modules:composer.user-said-in, ' + data.username + ', ' + link + ']]\n', config.defaultLang, onTranslated); 258 | } else { 259 | translator.translate('[[modules:composer.user-said, ' + data.username + ']]\n', config.defaultLang, onTranslated); 260 | } 261 | 262 | function onTranslated(translated) { 263 | composer.posts[data.uuid].body = (prevText.length ? prevText + '\n\n' : '') + translated + data.body; 264 | bodyEl.val(composer.posts[data.uuid].body); 265 | focusElements(postContainer); 266 | preview.render(postContainer); 267 | } 268 | }; 269 | 270 | composer.newReply = function (data) { 271 | translator.translate(data.body, config.defaultLang, function (translated) { 272 | push({ 273 | save_id: data.save_id, 274 | action: 'posts.reply', 275 | tid: data.tid, 276 | toPid: data.toPid, 277 | title: data.title, 278 | body: translated, 279 | modified: !!(translated && translated.length), 280 | isMain: false, 281 | }); 282 | }); 283 | }; 284 | 285 | composer.editPost = function (data) { 286 | // pid, text 287 | socket.emit('plugins.composer.push', data.pid, function (err, postData) { 288 | if (err) { 289 | return alerts.error(err); 290 | } 291 | postData.save_id = data.save_id; 292 | postData.action = 'posts.edit'; 293 | postData.pid = data.pid; 294 | postData.modified = false; 295 | if (data.body) { 296 | postData.body = data.body; 297 | postData.modified = true; 298 | } 299 | if (data.title) { 300 | postData.title = data.title; 301 | postData.modified = true; 302 | } 303 | push(postData); 304 | }); 305 | }; 306 | 307 | composer.load = function (post_uuid) { 308 | var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); 309 | if (postContainer.length) { 310 | activate(post_uuid); 311 | resize.reposition(postContainer); 312 | focusElements(postContainer); 313 | onShow(); 314 | } else if (composer.formatting) { 315 | createNewComposer(post_uuid); 316 | } else { 317 | socket.emit('plugins.composer.getFormattingOptions', function (err, options) { 318 | if (err) { 319 | return alerts.error(err); 320 | } 321 | composer.formatting = options; 322 | createNewComposer(post_uuid); 323 | }); 324 | } 325 | }; 326 | 327 | composer.enhance = function (postContainer, post_uuid, postData) { 328 | /* 329 | This method enhances a composer container with client-side sugar (preview, etc) 330 | Everything in here also applies to the /compose route 331 | */ 332 | 333 | if (!post_uuid && !postData) { 334 | post_uuid = utils.generateUUID(); 335 | composer.posts[post_uuid] = ajaxify.data; 336 | postData = ajaxify.data; 337 | postContainer.attr('data-uuid', post_uuid); 338 | } 339 | 340 | categoryList.init(postContainer, composer.posts[post_uuid]); 341 | scheduler.init(postContainer, composer.posts); 342 | 343 | formatting.addHandler(postContainer); 344 | formatting.addComposerButtons(); 345 | preview.handleToggler(postContainer); 346 | postQueue.showAlert(postContainer, postData); 347 | uploads.initialize(post_uuid); 348 | tags.init(postContainer, composer.posts[post_uuid]); 349 | autocomplete.init(postContainer, post_uuid); 350 | 351 | postContainer.on('change', 'input, textarea', function () { 352 | composer.posts[post_uuid].modified = true; 353 | }); 354 | 355 | postContainer.on('click', '.composer-submit', function (e) { 356 | e.preventDefault(); 357 | e.stopPropagation(); // Other click events bring composer back to active state which is undesired on submit 358 | 359 | $(this).attr('disabled', true); 360 | post(post_uuid); 361 | }); 362 | 363 | require(['mousetrap'], function (mousetrap) { 364 | mousetrap(postContainer.get(0)).bind('mod+enter', function () { 365 | postContainer.find('.composer-submit').attr('disabled', true); 366 | post(post_uuid); 367 | }); 368 | }); 369 | 370 | postContainer.find('.composer-discard').on('click', function (e) { 371 | e.preventDefault(); 372 | 373 | if (!composer.posts[post_uuid].modified) { 374 | composer.discard(post_uuid); 375 | return removeComposerHistory(); 376 | } 377 | 378 | formatting.exitFullscreen(); 379 | 380 | var btn = $(this).prop('disabled', true); 381 | translator.translate('[[modules:composer.discard]]', function (translated) { 382 | bootbox.confirm(translated, function (confirm) { 383 | if (confirm) { 384 | composer.discard(post_uuid); 385 | removeComposerHistory(); 386 | } 387 | btn.prop('disabled', false); 388 | }); 389 | }); 390 | }); 391 | 392 | postContainer.find('.composer-minimize, .minimize .trigger').on('click', function (e) { 393 | e.preventDefault(); 394 | e.stopPropagation(); 395 | composer.minimize(post_uuid); 396 | }); 397 | 398 | const textareaEl = postContainer.find('textarea'); 399 | textareaEl.on('input propertychange', utils.debounce(function () { 400 | preview.render(postContainer); 401 | }, 250)); 402 | 403 | textareaEl.on('scroll', function () { 404 | preview.matchScroll(postContainer); 405 | }); 406 | 407 | drafts.init(postContainer, postData); 408 | const draft = drafts.get(postData.save_id); 409 | 410 | preview.render(postContainer, function () { 411 | preview.matchScroll(postContainer); 412 | }); 413 | 414 | if (postData.action === 'posts.edit' && !utils.isNumber(postData.pid)) { 415 | handleRemotePid(postContainer); 416 | } 417 | handleHelp(postContainer); 418 | handleSearch(postContainer); 419 | focusElements(postContainer); 420 | if (postData.action === 'posts.edit') { 421 | composer.updateThumbCount(post_uuid, postContainer); 422 | } 423 | 424 | // Hide "zen mode" if fullscreen API is not enabled/available (ahem, iOS...) 425 | if (!screenfull.isEnabled) { 426 | $('[data-format="zen"]').parent().addClass('hidden'); 427 | } 428 | 429 | hooks.fire('action:composer.enhanced', { postContainer, postData, draft }); 430 | }; 431 | 432 | async function getSelectedCategory(postData) { 433 | const { template } = ajaxify.data; 434 | const { cid } = postData; 435 | if ((template.category || template.world) && String(cid) === String(ajaxify.data.cid)) { 436 | // no need to load data if we are already on the category page 437 | return ajaxify.data; 438 | } else if (cid) { 439 | const categoryUrl = cid !== -1 ? `/api/category/${encodeURIComponent(postData.cid)}` : `/api/world`; 440 | return await api.get(categoryUrl, {}); 441 | } 442 | return null; 443 | } 444 | 445 | async function createNewComposer(post_uuid) { 446 | var postData = composer.posts[post_uuid]; 447 | 448 | var isTopic = postData ? postData.hasOwnProperty('cid') : false; 449 | var isMain = postData ? !!postData.isMain : false; 450 | var isEditing = postData ? !!postData.pid : false; 451 | var isGuestPost = postData ? parseInt(postData.uid, 10) === 0 : false; 452 | const isScheduled = postData.timestamp > Date.now(); 453 | 454 | // see 455 | // https://github.com/NodeBB/NodeBB/issues/2994 and 456 | // https://github.com/NodeBB/NodeBB/issues/1951 457 | // remove when 1951 is resolved 458 | 459 | var title = postData.title.replace(/%/g, '%').replace(/,/g, ','); 460 | postData.category = await getSelectedCategory(postData); 461 | const privileges = postData.category ? postData.category.privileges : ajaxify.data.privileges; 462 | var data = { 463 | topicTitle: title, 464 | titleLength: title.length, 465 | body: translator.escape(utils.escapeHTML(postData.body)), 466 | mobile: composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm', 467 | resizable: true, 468 | thumb: postData.thumb, 469 | isTopicOrMain: isTopic || isMain, 470 | maximumTitleLength: config.maximumTitleLength, 471 | maximumPostLength: config.maximumPostLength, 472 | minimumTagLength: config.minimumTagLength, 473 | maximumTagLength: config.maximumTagLength, 474 | 'composer:showHelpTab': config['composer:showHelpTab'], 475 | isTopic: isTopic, 476 | isEditing: isEditing, 477 | canSchedule: !!(isMain && privileges && 478 | ((privileges['topics:schedule'] && !isEditing) || (isScheduled && privileges.view_scheduled))), 479 | canUploadImage: app.user.privileges['upload:post:image'] && (config.maximumFileSize > 0 || app.user.isAdmin), 480 | canUploadFile: app.user.privileges['upload:post:file'] && (config.maximumFileSize > 0 || app.user.isAdmin), 481 | showHandleInput: config.allowGuestHandles && 482 | (app.user.uid === 0 || (isEditing && isGuestPost && app.user.isAdmin)), 483 | handle: postData ? postData.handle || '' : undefined, 484 | formatting: composer.formatting, 485 | tagWhitelist: postData.category ? postData.category.tagWhitelist : ajaxify.data.tagWhitelist, 486 | privileges: app.user.privileges, 487 | selectedCategory: postData.category, 488 | submitOptions: [ 489 | // Add items using `filter:composer.create`, or just add them to the