Commit 56ac196f authored by csillag's avatar csillag

Simplify/improve the visual diff

 * Move the calculations to the render funcion
 * Stop automatically `$sce.trust()`-ing the HTML code.
   (So now `$sanitize` is invoked automatically.)
   This also removes the need to use the `$sce` module,
   or to set the `trustedDIffHTML` flag, simplifying the code.
 * Use the `objectEquality` flag when `$watch()`ing the targets,
   so that we pick up changes in both the number and the contents
   of the targets
parent cf39c9dd
......@@ -37,8 +37,8 @@ validate = (value) ->
# {@link annotator annotator service} for persistence.
###
AnnotationController = [
'$sce', '$scope', 'annotator', 'drafts', 'flash', 'documentHelpers',
($sce, $scope, annotator, drafts, flash, documentHelpers) ->
'$scope', 'annotator', 'drafts', 'flash', 'documentHelpers',
($scope, annotator, drafts, flash, documentHelpers) ->
@annotation = {}
@action = 'view'
@document = null
......@@ -205,6 +205,10 @@ AnnotationController = [
# Form the tags for ngTagsInput.
@annotation.tags = ({text} for text in (model.tags or []))
# Calculate the visual diff flag
@annotation.target?.forEach (t) ->
t.showDiff = t.diffHTML? and not t.diffCaseOnly
# Export the baseURI for the share link
this.baseURI = documentHelpers.baseURI
......@@ -228,15 +232,7 @@ AnnotationController = [
this.render()
# Calculate things neded for the visual diff support
$scope.$watch (-> model.target), (targets) =>
for target in targets
if target.diffHTML?
target.trustedDiffHTML = $sce.trustAsHtml target.diffHTML
target.showDiff = not target.diffCaseOnly
else
delete target.trustedDiffHTML
target.showDiff = false
this.render()
$scope.$watch (-> model.target), (=> this.render()), true
$scope.$watch (=> @annotation.id), =>
vm.annotationURI = documentHelpers.absoluteURI("/a/#{@annotation.id}")
......
......@@ -50,10 +50,10 @@
| filter : {'type': 'TextQuoteSelector'}
track by $index"></blockquote>
<blockquote class="annotation-quote"
ng-bind-html="target.trustedDiffHTML"
ng-bind-html="target.diffHTML"
ng-show="target.showDiff"></blockquote>
<div class="small pull-right"
ng-show="target.trustedDiffHTML">
ng-show="target.diffHTML">
<input type="checkbox"
ng-model="target.showDiff"
ng-click="$event.stopPropagation()"> Show differences</input>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment