From 83d8eae30035700c041997133e5c3b68fc3cb206 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Fri, 31 Mar 2017 09:53:37 +0200 Subject: [PATCH] open in a new window only the absolute paths --- .../components/wysiwyg/wysiwyg.directive.coffee | 14 +++++++++----- .../components/wysiwyg/wysiwyg.service.coffee | 8 +++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/modules/components/wysiwyg/wysiwyg.directive.coffee b/app/modules/components/wysiwyg/wysiwyg.directive.coffee index 936f2cbe..dd02c54f 100644 --- a/app/modules/components/wysiwyg/wysiwyg.directive.coffee +++ b/app/modules/components/wysiwyg/wysiwyg.directive.coffee @@ -25,7 +25,7 @@ taiga = @.taiga bindOnce = @.taiga.bindOnce -Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoader, wysiwygCodeHightlighterService, wysiwygMentionService, analytics) -> +Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoader, wysiwygCodeHightlighterService, wysiwygMentionService, analytics, $location) -> removeSelections = () -> if window.getSelection if window.getSelection().empty @@ -404,7 +404,6 @@ Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoad editorMedium.html(html) mediumInstance = new MediumEditor(editorMedium[0], { - targetBlank: true, imageDragging: false, placeholder: { text: $scope.placeholder @@ -487,10 +486,14 @@ Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoad $scope.$applyAsync(throttleChange) mediumInstance.subscribe "editableClick", (e) -> - e.stopPropagation() + r = new RegExp('^(?:[a-z]+:)?//', 'i') - if e.target.href - window.open(e.target.href) + if e.target.href + if r.test(e.target.getAttribute('href')) || e.target.getAttribute('target') == '_blank' + e.stopPropagation() + window.open(e.target.href) + else + $location.url(e.target.href) mediumInstance.subscribe 'editableDrop', (event) -> $scope.onUploadFile({files: event.dataTransfer.files, cb: uploadEnd}) @@ -593,5 +596,6 @@ angular.module("taigaComponents").directive("tgWysiwyg", [ "tgWysiwygCodeHightlighterService", "tgWysiwygMentionService", "$tgAnalytics", + "$location", Medium ]) diff --git a/app/modules/components/wysiwyg/wysiwyg.service.coffee b/app/modules/components/wysiwyg/wysiwyg.service.coffee index 7b8f7824..93af9637 100644 --- a/app/modules/components/wysiwyg/wysiwyg.service.coffee +++ b/app/modules/components/wysiwyg/wysiwyg.service.coffee @@ -84,7 +84,10 @@ class WysiwygService link = /\[[^\]]*\]\(([^\)]*)\)/g # [Title-with-spaces](Title with spaces) return text.replace link, (match, p1, offset, str) -> - return match.replace /\(.*\)/, '(' + taiga.slugify(p1) + ')' + if p1.indexOf(' ') >= 0 + return match.replace /\(.*\)/, '(' + taiga.slugify(p1) + ')' + else + return match replaceUrls: (html) -> el = document.createElement( 'html' ) @@ -182,11 +185,10 @@ class WysiwygService autoLinkHTML: (html) -> # override Autolink parser - + matchRegexStr = String(Autolinker.matcher.Mention.prototype.matcherRegexes.twitter) if matchRegexStr.indexOf('.') == -1 matchRegexStr = '@[^\s]{1,50}[^.\s]' - #Autolinker.matcher.Mention.prototype.matcherRegexes.twitter = new RegExp(matchRegexStr, 'g') autolinker = new Autolinker({ mention: 'twitter',