nodebb-plugin-composer-default 10.3.10 → 10.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/library.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const url = require('url');
4
3
 
5
4
  const nconf = require.main.require('nconf');
6
5
  const validator = require('validator');
@@ -103,8 +102,9 @@ plugin.filterComposerBuild = async function (hookData) {
103
102
 
104
103
  if (req.query.p) {
105
104
  try {
106
- const a = url.parse(req.query.p, true, true);
107
- return helpers.redirect(res, `/${(a.path || '').replace(/^\/*/, '')}`);
105
+ const a = new URL(req.query.p, 'http://localhost.com');
106
+ const path = (a.pathname + a.search).replace(/^\/+/, '');
107
+ return helpers.redirect(res, `/${path}`);
108
108
  } catch (e) {
109
109
  return helpers.redirect(res, '/');
110
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-composer-default",
3
- "version": "10.3.10",
3
+ "version": "10.3.12",
4
4
  "description": "Default composer for NodeBB",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -63,6 +63,7 @@ define('composer/preview', ['hooks'], function (hooks) {
63
63
  }
64
64
 
65
65
  function togglePreview(show) {
66
+ const isMobile = ['xs', 'sm'].includes(preview.env);
66
67
  if (isMobile) {
67
68
  previewContainer.classList.toggle('hide', false);
68
69
  writeContainer.classList.toggle('maximized', false);
@@ -40,7 +40,7 @@ define('composer', [
40
40
  localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked');
41
41
  });
42
42
 
43
- $(window).on('popstate', function () {
43
+ window.addEventListener('popstate', function () {
44
44
  var env = utils.findBootstrapEnvironment();
45
45
  if (composer.active && (env === 'xs' || env === 'sm')) {
46
46
  if (!composer.posts[composer.active].modified) {
@@ -74,29 +74,17 @@ define('composer', [
74
74
  var env = utils.findBootstrapEnvironment();
75
75
  var isMobile = env === 'xs' || env === 'sm';
76
76
 
77
- if (preview.toggle) {
78
- if (preview.env !== env && isMobile) {
79
- preview.env = env;
80
- preview.toggle(false);
81
- }
77
+ if (preview.toggle && preview.env !== env) {
82
78
  preview.env = env;
79
+ preview.toggle(!isMobile);
83
80
  }
84
81
 
85
82
  if (composer.active !== undefined) {
86
83
  resize.reposition($('.composer[data-uuid="' + composer.active + '"]'));
87
84
 
88
- if (!isMobile && window.location.pathname.startsWith(config.relative_path + '/compose')) {
89
- /*
90
- * If this conditional is met, we're no longer in mobile/tablet
91
- * resolution but we've somehow managed to have a mobile
92
- * composer load, so let's go back to the topic
93
- */
85
+ if (!isMobile && window.history.state && window.history.state.composerBackState) {
94
86
  history.back();
95
- } else if (isMobile && !window.location.pathname.startsWith(config.relative_path + '/compose')) {
96
- /*
97
- * In this case, we're in mobile/tablet resolution but the composer
98
- * that loaded was a regular composer, so let's fix the address bar
99
- */
87
+ } else if (isMobile) {
100
88
  mobileHistoryAppend();
101
89
  }
102
90
  }
@@ -562,24 +550,22 @@ define('composer', [
562
550
  }
563
551
 
564
552
  function mobileHistoryAppend() {
565
- var path = 'compose?p=' + window.location.pathname;
566
- var returnPath = window.location.pathname.slice(1) + window.location.search;
567
-
568
- // Remove relative path from returnPath
569
- if (returnPath.startsWith(config.relative_path.slice(1))) {
570
- returnPath = returnPath.slice(config.relative_path.length);
553
+ // add a fake entry to the browser history so that the user can
554
+ // press back to return to where they were before opening the composer
555
+ // popstate listener in this file closes the composer on mobile,
556
+ // browser automatically removes the fake entry when user presses back
557
+ if (window.history.state && !window.history.state.composerBackState) {
558
+ // modify current state so that ajaxify.go doesn't
559
+ // trigger when user presses back from composer
560
+ window.history.replaceState({
561
+ url: null,
562
+ returnPath: history.state.url,
563
+ }, ''); // 3rd param optional url, we dont change it
564
+
565
+ window.history.pushState({
566
+ composerBackState: true,
567
+ }, ''); // 3rd param optional url, we dont change it
571
568
  }
572
-
573
- // Add in return path to be caught by ajaxify when post is completed, or if back is pressed
574
- window.history.replaceState({
575
- url: null,
576
- returnPath: returnPath,
577
- }, returnPath, config.relative_path + '/' + returnPath);
578
-
579
- // Update address bar in case f5 is pressed
580
- window.history.pushState({
581
- url: path,
582
- }, path, `${config.relative_path}/${returnPath}`);
583
569
  }
584
570
 
585
571
  function handleRemotePid(postContainer) {