fix #1710 select text in the wysiwyng preview actives edition mode

stable
Juanfran 2014-11-28 09:00:04 +01:00
parent f2fffa3235
commit c0febab837
3 changed files with 30 additions and 16 deletions

View File

@ -23,6 +23,21 @@ taiga = @.taiga
module = angular.module("taigaCommon", []) 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 ## Permission directive, hide elements when necessary
############################################################################# #############################################################################

View File

@ -553,7 +553,7 @@ module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$
## Editable subject directive ## Editable subject directive
############################################################################# #############################################################################
EditableDescriptionDirective = ($window, $document, $rootscope, $repo, $confirm, $compile, $loading) -> EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText) ->
template = """ template = """
<div class="view-description"> <div class="view-description">
<section class="us-content wysiwyg" <section class="us-content wysiwyg"
@ -593,20 +593,13 @@ EditableDescriptionDirective = ($window, $document, $rootscope, $repo, $confirm,
isEditable = -> isEditable = ->
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1 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) -> $el.on "mouseup", ".view-description", (event) ->
# We want to dettect the a inside the div so we use the target and # We want to dettect the a inside the div so we use the target and
# not the currentTarget # not the currentTarget
target = angular.element(event.target) target = angular.element(event.target)
return if not isEditable() return if not isEditable()
return if target.is('a') return if target.is('a')
return if getSelectedText() return if $selectedText.get().length
$el.find('.edit-description').show() $el.find('.edit-description').show()
$el.find('.view-description').hide() $el.find('.view-description').hide()
@ -654,8 +647,8 @@ EditableDescriptionDirective = ($window, $document, $rootscope, $repo, $confirm,
template: template template: template
} }
module.directive("tgEditableDescription", ["$window", "$document", "$rootScope", "$tgRepo", "$tgConfirm", module.directive("tgEditableDescription", ["$rootScope", "$tgRepo", "$tgConfirm",
"$compile", "$tgLoading", EditableDescriptionDirective]) "$compile", "$tgLoading", "$selectedText", EditableDescriptionDirective])
############################################################################# #############################################################################

View File

@ -28,7 +28,7 @@ module = angular.module("taigaCommon")
############################################################################# #############################################################################
## WYSIWYG markitup editor directive ## WYSIWYG markitup editor directive
############################################################################# #############################################################################
tgMarkitupDirective = ($rootscope, $rs, $tr) -> tgMarkitupDirective = ($rootscope, $rs, $tr, $selectedText) ->
previewTemplate = _.template(""" previewTemplate = _.template("""
<div class="preview"> <div class="preview">
<div class="actions"> <div class="actions">
@ -61,10 +61,16 @@ tgMarkitupDirective = ($rootscope, $rs, $tr) ->
markdownDomNode.append(previewTemplate({data: data.data})) markdownDomNode.append(previewTemplate({data: data.data}))
markItUpDomNode.hide() markItUpDomNode.hide()
# FIXME: Really `.parents()` is need? seems `.closest` markdown = element.closest(".markdown")
# function is better aproach for it
element.parents(".markdown").one "click", ".preview", (event) -> markdown.on "mouseup.preview", ".preview", (event) ->
event.preventDefault() event.preventDefault()
target = angular.element(event.target)
if !target.is('a') and $selectedText.get().length
return
markdown.off(".preview")
closePreviewMode() closePreviewMode()
markdownCaretPositon = false markdownCaretPositon = false
@ -277,4 +283,4 @@ tgMarkitupDirective = ($rootscope, $rs, $tr) ->
return {link:link, require:"ngModel"} return {link:link, require:"ngModel"}
module.directive("tgMarkitup", ["$rootScope", "$tgResources", "$tgI18n", tgMarkitupDirective]) module.directive("tgMarkitup", ["$rootScope", "$tgResources", "$tgI18n", "$selectedText", tgMarkitupDirective])