Allow text selection over the description

stable
David Barragán Merino 2014-10-27 18:40:22 +01:00
parent a412f5ec7b
commit 6182ef5ce9
1 changed files with 18 additions and 9 deletions

View File

@ -515,7 +515,7 @@ module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$
## Editable subject directive ## Editable subject directive
############################################################################# #############################################################################
EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading) -> EditableDescriptionDirective = ($window, $document, $rootscope, $repo, $confirm, $compile, $loading) ->
template = """ template = """
<div class="view-description"> <div class="view-description">
<section class="us-content wysiwyg" <section class="us-content wysiwyg"
@ -549,15 +549,24 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading)
isEditable = -> isEditable = ->
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1 return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1
$el.on "click", ".view-description", (event) -> 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 # We want to dettect the a inside the div so we use the target and
# not the currentTarget # not the currentTarget
return if not isEditable()
target = angular.element(event.target) target = angular.element(event.target)
if not target.is('a') return if not isEditable()
$el.find('.edit-description').show() return if target.is('a')
$el.find('.view-description').hide() return if getSelectedText()
$el.find('textarea').focus()
$el.find('.edit-description').show()
$el.find('.view-description').hide()
$el.find('textarea').focus()
$el.on "click", ".save", -> $el.on "click", ".save", ->
$model.$modelValue.description = $scope.item.description $model.$modelValue.description = $scope.item.description
@ -601,8 +610,8 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading)
template: template template: template
} }
module.directive("tgEditableDescription", ["$rootScope", "$tgRepo", "$tgConfirm", "$compile", "$tgLoading", module.directive("tgEditableDescription", ["$window", "$document", "$rootScope", "$tgRepo", "$tgConfirm",
EditableDescriptionDirective]) "$compile", "$tgLoading", EditableDescriptionDirective])
############################################################################# #############################################################################