open in a new window only the absolute paths

stable
Juanfran 2017-03-31 09:53:37 +02:00
parent 5b5f5408a4
commit 83d8eae300
2 changed files with 14 additions and 8 deletions

View File

@ -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
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
])

View File

@ -84,7 +84,10 @@ class WysiwygService
link = /\[[^\]]*\]\(([^\)]*)\)/g # [Title-with-spaces](Title with spaces)
return text.replace link, (match, p1, offset, str) ->
if p1.indexOf(' ') >= 0
return match.replace /\(.*\)/, '(' + taiga.slugify(p1) + ')'
else
return match
replaceUrls: (html) ->
el = document.createElement( 'html' )
@ -186,7 +189,6 @@ class WysiwygService
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',