fix #1710 select text in the wysiwyng preview actives edition mode
parent
f2fffa3235
commit
c0febab837
|
@ -23,6 +23,21 @@ taiga = @.taiga
|
|||
|
||||
module = angular.module("taigaCommon", [])
|
||||
|
||||
#############################################################################
|
||||
## Get the selected text
|
||||
#############################################################################
|
||||
SelectedText = ($window, $document) ->
|
||||
get = () ->
|
||||
if $window.getSelection
|
||||
return $window.getSelection().toString()
|
||||
else if $document.selection
|
||||
return $document.selection.createRange().text
|
||||
return ""
|
||||
|
||||
return {get: get}
|
||||
|
||||
module.factory("$selectedText", ["$window", "$document", SelectedText])
|
||||
|
||||
#############################################################################
|
||||
## Permission directive, hide elements when necessary
|
||||
#############################################################################
|
||||
|
|
|
@ -553,7 +553,7 @@ module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$
|
|||
## Editable subject directive
|
||||
#############################################################################
|
||||
|
||||
EditableDescriptionDirective = ($window, $document, $rootscope, $repo, $confirm, $compile, $loading) ->
|
||||
EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText) ->
|
||||
template = """
|
||||
<div class="view-description">
|
||||
<section class="us-content wysiwyg"
|
||||
|
@ -593,20 +593,13 @@ EditableDescriptionDirective = ($window, $document, $rootscope, $repo, $confirm,
|
|||
isEditable = ->
|
||||
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1
|
||||
|
||||
getSelectedText = ->
|
||||
if $window.getSelection
|
||||
return $window.getSelection().toString()
|
||||
else if $document.selection
|
||||
return $document.selection.createRange().text
|
||||
return null
|
||||
|
||||
$el.on "mouseup", ".view-description", (event) ->
|
||||
# We want to dettect the a inside the div so we use the target and
|
||||
# not the currentTarget
|
||||
target = angular.element(event.target)
|
||||
return if not isEditable()
|
||||
return if target.is('a')
|
||||
return if getSelectedText()
|
||||
return if $selectedText.get().length
|
||||
|
||||
$el.find('.edit-description').show()
|
||||
$el.find('.view-description').hide()
|
||||
|
@ -654,8 +647,8 @@ EditableDescriptionDirective = ($window, $document, $rootscope, $repo, $confirm,
|
|||
template: template
|
||||
}
|
||||
|
||||
module.directive("tgEditableDescription", ["$window", "$document", "$rootScope", "$tgRepo", "$tgConfirm",
|
||||
"$compile", "$tgLoading", EditableDescriptionDirective])
|
||||
module.directive("tgEditableDescription", ["$rootScope", "$tgRepo", "$tgConfirm",
|
||||
"$compile", "$tgLoading", "$selectedText", EditableDescriptionDirective])
|
||||
|
||||
|
||||
#############################################################################
|
||||
|
|
|
@ -28,7 +28,7 @@ module = angular.module("taigaCommon")
|
|||
#############################################################################
|
||||
## WYSIWYG markitup editor directive
|
||||
#############################################################################
|
||||
tgMarkitupDirective = ($rootscope, $rs, $tr) ->
|
||||
tgMarkitupDirective = ($rootscope, $rs, $tr, $selectedText) ->
|
||||
previewTemplate = _.template("""
|
||||
<div class="preview">
|
||||
<div class="actions">
|
||||
|
@ -61,10 +61,16 @@ tgMarkitupDirective = ($rootscope, $rs, $tr) ->
|
|||
markdownDomNode.append(previewTemplate({data: data.data}))
|
||||
markItUpDomNode.hide()
|
||||
|
||||
# FIXME: Really `.parents()` is need? seems `.closest`
|
||||
# function is better aproach for it
|
||||
element.parents(".markdown").one "click", ".preview", (event) ->
|
||||
markdown = element.closest(".markdown")
|
||||
|
||||
markdown.on "mouseup.preview", ".preview", (event) ->
|
||||
event.preventDefault()
|
||||
target = angular.element(event.target)
|
||||
|
||||
if !target.is('a') and $selectedText.get().length
|
||||
return
|
||||
|
||||
markdown.off(".preview")
|
||||
closePreviewMode()
|
||||
|
||||
markdownCaretPositon = false
|
||||
|
@ -277,4 +283,4 @@ tgMarkitupDirective = ($rootscope, $rs, $tr) ->
|
|||
|
||||
return {link:link, require:"ngModel"}
|
||||
|
||||
module.directive("tgMarkitup", ["$rootScope", "$tgResources", "$tgI18n", tgMarkitupDirective])
|
||||
module.directive("tgMarkitup", ["$rootScope", "$tgResources", "$tgI18n", "$selectedText", tgMarkitupDirective])
|
||||
|
|
Loading…
Reference in New Issue