From 9a4bf8971864378b67dae6ad727f5218d31c1a25 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Sun, 14 Feb 2021 13:39:01 +1300 Subject: [PATCH] BUG Allow external link anchor fiel to work even if the user provides a hash mark --- client/dist/js/TinyMCE_sslink.js | 2 +- client/src/legacy/TinyMCE_sslink.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/client/dist/js/TinyMCE_sslink.js b/client/dist/js/TinyMCE_sslink.js index 486fb9b38..c01182e4e 100644 --- a/client/dist/js/TinyMCE_sslink.js +++ b/client/dist/js/TinyMCE_sslink.js @@ -1 +1 @@ -!function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s="./client/src/legacy/TinyMCE_sslink.js")}({"./client/src/components/TinymceInlineToolbar/TinymceInlineToolbar.js":function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e,n){var o=Array.isArray(n)?n:[n||""];return!(!t||!e)&&(o=o.map(function(t){return String(t)}).map(function(t){return t.toLowerCase()}),o.filter(function(e){if(e.indexOf("[")>-1&&e.indexOf("]")>-1){var n=e.substring(0,e.indexOf("[")),o=e.substring(e.indexOf("[")+1,e.indexOf("]"));if(n===t.tagName.toLowerCase()&&t.getAttribute(o))return!0}else if(t.tagName&&e===t.tagName.toLowerCase())return!0;return!1}).length>0)}function r(t,e){function n(){i(l,s,o)&&(r.hide(),clearTimeout(a),a=setTimeout(function(){r.show(),r.reposition(l)},300))}var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:["a"],r=new c(t,e),l=null,a=null,s=!1;return r.hide().renderTo(window.document.body),t.on("remove",function(){r.remove()}),t.on("focus",function(){s=!0}),t.on("blur hide",function(){r.hide(),s=!1}),t.on("nodechange",function(e){var n={element:e.element,parents:e.parents,collapsed:t.selection.isCollapsed()};l=n.selection||n.element,i(l,s,o)?(r.show(),r.reposition(l)):r.hide()}),window.addEventListener("scroll",function(e){e.target.contains(document.querySelector("#"+t.id))&&n()},!0),t.contentDocument.addEventListener("scroll",n),r}Object.defineProperty(e,"__esModule",{value:!0});var l=function(){function t(t,e){for(var n=0;n=k||b>=k?this.hide():(this.bottom?b>=f?(y=" mce-arrow-up",v=s.bottom+r.top+n+10):g>=f&&(y=" mce-arrow-down",v=s.top+r.top+n-a-8):g>=f?(y=" mce-arrow-down",v=s.top+r.top+n-a-8):b>=f&&k/2>s.bottom+r.top-h&&(y=" mce-arrow-up",v=s.bottom+r.top+n+10),0===v&&(v=n+h+5),w=u-c/2+r.left+e,s.left<0||s.right>r.width?w=r.left+e+(r.width-c)/2:c>=o?(y+=" mce-arrow-full",w=0):w<0&&s.left+c>o||w+c>o&&s.right-c<0?w=(o-c)/2:wr.width+r.left+e&&(y+=" mce-arrow-right",w=s.right-c+r.left+e),l.className=l.className.replace(/ ?mce-arrow-[\w]+/g,"")+y,this.setStyles({left:w,top:v}),this)}}]),t}();e.default=c,e.setupTinyMceInlineToolbar=r,e.shouldShowToolbar=i},"./client/src/legacy/TinyMCE_sslink.js":function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),r=o(i),l=n(0),c=o(l),a=n(3),s=o(a),u=n("./client/src/components/TinymceInlineToolbar/TinymceInlineToolbar.js"),f=n(7),d=n(2),m=o(d),h={init:function(t){function e(){var e=tinymce.activeEditor.selection.getNode(),n=e.getAttribute("href");n&&t.execCommand(r.default.getEditorCommandFromUrl(n))}var n=this,o=navigator.platform.toUpperCase().includes("MAC")?"⌘":"Ctrl",i=m.default._t("Admin.INSERT_LINK","Insert link"),l=m.default.inject(m.default._t("Admin.INSERT_LINK_WITH_SHORTCUT","Insert link {shortcut}"),{shortcut:"["+o+"+K]"}),c=r.default.getSortedActions("sslink",t.settings.editorIdentifier,!0).map(function(e){return Object.assign({},e,{onclick:function(){return e.onclick(t)}})});t.addButton("sslink",{icon:"link",title:l,type:"menubutton",menu:c}),t.addMenuItem("sslink",{icon:"link",text:i,menu:c}),t.addShortcut("Meta+k","Open link menu",function(){(0,s.default)('[aria-label^="'+i+'"] > button',t.container).first().click()}),t.on("preinit",function(){(0,u.setupTinyMceInlineToolbar)(t,[{type:"button",onClick:e,text:"Edit link"},{type:"button",onClick:function(){return n.handleRemoveLinkClick(t)},text:"Remove link"}],["a[href]"])})},handleRemoveLinkClick:function(t){var e=t.execCommand("unlink"),n=t.selection.getNode();return n&&void 0!==n.normalize&&n.normalize(),e}};s.default.entwine("ss",function(t){t(".insert-link__dialog-wrapper").entwine({Element:null,Data:{},Bookmark:null,onunmatch:function(){this._clearModal()},_clearModal:function(){c.default.unmountComponentAtNode(this[0])},open:function(){var t=this.getElement().getEditor().getInstance();this.setBookmark(t.selection.getBookmark(2,!0)),this.renderModal(!0)},close:function(){this.setData({}),this.renderModal(!1)},renderModal:function(){},handleInsert:function(t){this.getElement().getEditor().getInstance().selection.moveToBookmark(this.getBookmark());var e=this.buildAttributes(t),n=(0,f.createHTMLSanitiser)(),o=n(t.Text);return this.insertLinkInEditor(e,o),this.close(),Promise.resolve()},buildAttributes:function(t){var e=t.Anchor&&t.Anchor.length?"#"+t.Anchor:"";return{href:""+t.Link+e,target:t.TargetBlank?"_blank":"",title:t.Description}},insertLinkInEditor:function(t,e){var n=this.getElement().getEditor();n.insertLink(t,null,e),n.addUndo(),n.repaint();var o=n.getInstance(),i=o.selection;setTimeout(function(){return i&&i.collapse()},0)},getOriginalAttributes:function(){var e=this.getElement().getEditor(),n=t(e.getSelectedNode()),o=(n.attr("href")||"").split("#");return{Link:o[0]||"",Anchor:o[1]||"",Description:n.attr("title"),TargetBlank:!!n.attr("target")}}})}),tinymce.PluginManager.add("sslink",function(t){return h.init(t)}),e.default=h},0:function(t,e){t.exports=ReactDom},1:function(t,e){t.exports=TinyMCEActionRegistrar},2:function(t,e){t.exports=i18n},3:function(t,e){t.exports=jQuery},7:function(t,e){t.exports=ShortcodeSerialiser}}); \ No newline at end of file +!function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s="./client/src/legacy/TinyMCE_sslink.js")}({"./client/src/components/TinymceInlineToolbar/TinymceInlineToolbar.js":function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e,n){var o=Array.isArray(n)?n:[n||""];return!(!t||!e)&&(o=o.map(function(t){return String(t)}).map(function(t){return t.toLowerCase()}),o.filter(function(e){if(e.indexOf("[")>-1&&e.indexOf("]")>-1){var n=e.substring(0,e.indexOf("[")),o=e.substring(e.indexOf("[")+1,e.indexOf("]"));if(n===t.tagName.toLowerCase()&&t.getAttribute(o))return!0}else if(t.tagName&&e===t.tagName.toLowerCase())return!0;return!1}).length>0)}function r(t,e){function n(){i(l,s,o)&&(r.hide(),clearTimeout(c),c=setTimeout(function(){r.show(),r.reposition(l)},300))}var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:["a"],r=new a(t,e),l=null,c=null,s=!1;return r.hide().renderTo(window.document.body),t.on("remove",function(){r.remove()}),t.on("focus",function(){s=!0}),t.on("blur hide",function(){r.hide(),s=!1}),t.on("nodechange",function(e){var n={element:e.element,parents:e.parents,collapsed:t.selection.isCollapsed()};l=n.selection||n.element,i(l,s,o)?(r.show(),r.reposition(l)):r.hide()}),window.addEventListener("scroll",function(e){e.target.contains(document.querySelector("#"+t.id))&&n()},!0),t.contentDocument.addEventListener("scroll",n),r}Object.defineProperty(e,"__esModule",{value:!0});var l=function(){function t(t,e){for(var n=0;n=k||b>=k?this.hide():(this.bottom?b>=f?(y=" mce-arrow-up",v=s.bottom+r.top+n+10):g>=f&&(y=" mce-arrow-down",v=s.top+r.top+n-c-8):g>=f?(y=" mce-arrow-down",v=s.top+r.top+n-c-8):b>=f&&k/2>s.bottom+r.top-h&&(y=" mce-arrow-up",v=s.bottom+r.top+n+10),0===v&&(v=n+h+5),w=u-a/2+r.left+e,s.left<0||s.right>r.width?w=r.left+e+(r.width-a)/2:a>=o?(y+=" mce-arrow-full",w=0):w<0&&s.left+a>o||w+a>o&&s.right-a<0?w=(o-a)/2:wr.width+r.left+e&&(y+=" mce-arrow-right",w=s.right-a+r.left+e),l.className=l.className.replace(/ ?mce-arrow-[\w]+/g,"")+y,this.setStyles({left:w,top:v}),this)}}]),t}();e.default=a,e.setupTinyMceInlineToolbar=r,e.shouldShowToolbar=i},"./client/src/legacy/TinyMCE_sslink.js":function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),r=o(i),l=n(0),a=o(l),c=n(3),s=o(c),u=n("./client/src/components/TinymceInlineToolbar/TinymceInlineToolbar.js"),f=n(7),d=n(2),m=o(d),h={init:function(t){function e(){var e=tinymce.activeEditor.selection.getNode(),n=e.getAttribute("href");n&&t.execCommand(r.default.getEditorCommandFromUrl(n))}var n=this,o=navigator.platform.toUpperCase().includes("MAC")?"⌘":"Ctrl",i=m.default._t("Admin.INSERT_LINK","Insert link"),l=m.default.inject(m.default._t("Admin.INSERT_LINK_WITH_SHORTCUT","Insert link {shortcut}"),{shortcut:"["+o+"+K]"}),a=r.default.getSortedActions("sslink",t.settings.editorIdentifier,!0).map(function(e){return Object.assign({},e,{onclick:function(){return e.onclick(t)}})});t.addButton("sslink",{icon:"link",title:l,type:"menubutton",menu:a}),t.addMenuItem("sslink",{icon:"link",text:i,menu:a}),t.addShortcut("Meta+k","Open link menu",function(){(0,s.default)('[aria-label^="'+i+'"] > button',t.container).first().click()}),t.on("preinit",function(){(0,u.setupTinyMceInlineToolbar)(t,[{type:"button",onClick:e,text:"Edit link"},{type:"button",onClick:function(){return n.handleRemoveLinkClick(t)},text:"Remove link"}],["a[href]"])})},handleRemoveLinkClick:function(t){var e=t.execCommand("unlink"),n=t.selection.getNode();return n&&void 0!==n.normalize&&n.normalize(),e}};s.default.entwine("ss",function(t){t(".insert-link__dialog-wrapper").entwine({Element:null,Data:{},Bookmark:null,onunmatch:function(){this._clearModal()},_clearModal:function(){a.default.unmountComponentAtNode(this[0])},open:function(){var t=this.getElement().getEditor().getInstance();this.setBookmark(t.selection.getBookmark(2,!0)),this.renderModal(!0)},close:function(){this.setData({}),this.renderModal(!1)},renderModal:function(){},handleInsert:function(t){this.getElement().getEditor().getInstance().selection.moveToBookmark(this.getBookmark());var e=this.buildAttributes(t),n=(0,f.createHTMLSanitiser)(),o=n(t.Text);return this.insertLinkInEditor(e,o),this.close(),Promise.resolve()},buildAttributes:function(t){var e=t.Anchor,n=t.Link,o=t.TargetBlank,i=t.Description,r=e&&e.length?"#"+e:"";return r=r.replace(/^#+/,"#"),{href:""+n+r,target:o?"_blank":"",title:i}},insertLinkInEditor:function(t,e){var n=this.getElement().getEditor();n.insertLink(t,null,e),n.addUndo(),n.repaint();var o=n.getInstance(),i=o.selection;setTimeout(function(){return i&&i.collapse()},0)},getOriginalAttributes:function(){var e=this.getElement().getEditor(),n=t(e.getSelectedNode()),o=(n.attr("href")||"").split("#");return{Link:o[0]||"",Anchor:o[1]||"",Description:n.attr("title"),TargetBlank:!!n.attr("target")}}})}),tinymce.PluginManager.add("sslink",function(t){return h.init(t)}),e.default=h},0:function(t,e){t.exports=ReactDom},1:function(t,e){t.exports=TinyMCEActionRegistrar},2:function(t,e){t.exports=i18n},3:function(t,e){t.exports=jQuery},7:function(t,e){t.exports=ShortcodeSerialiser}}); \ No newline at end of file diff --git a/client/src/legacy/TinyMCE_sslink.js b/client/src/legacy/TinyMCE_sslink.js index b036af893..52c35293d 100644 --- a/client/src/legacy/TinyMCE_sslink.js +++ b/client/src/legacy/TinyMCE_sslink.js @@ -131,14 +131,24 @@ jQuery.entwine('ss', ($) => { return Promise.resolve(); }, - buildAttributes(data) { - const anchor = data.Anchor && data.Anchor.length ? `#${data.Anchor}` : ''; - const href = `${data.Link}${anchor}`; + /** + * + * @param {string|undefined} Anchor + * @param {string} Link + * @param {boolean} TargetBlank + * @param {string} Description + * @returns {{href: string, title: string, target: string}} + */ + buildAttributes({ Anchor, Link, TargetBlank, Description }) { + let anchor = Anchor && Anchor.length ? `#${Anchor}` : ''; + // Make sure, there's no more than one # character at the start of the anchor + anchor = anchor.replace(/^#+/, '#'); + const href = `${Link}${anchor}`; return { href, - target: data.TargetBlank ? '_blank' : '', - title: data.Description, + target: TargetBlank ? '_blank' : '', + title: Description, }; },