Commit 82325a7f authored by Sean Hammond's avatar Sean Hammond

Scroll to new annotations on creation

If necessary scroll the sidebar to show a newly created annotation (when
the user clicks the new annotation button).

Add unique ids to the <li> elements that contain the annotations, then
on creating a new annotation set the URL fragment to #<id> and scroll to
show the element.

Fixes #2053.
parent 64004257
uuid = require('node-uuid')
###* ###*
# @ngdoc type # @ngdoc type
# @name thread.ThreadController # @name thread.ThreadController
...@@ -148,6 +150,8 @@ ThreadController = [ ...@@ -148,6 +150,8 @@ ThreadController = [
else else
0 0
this.uuid = uuid.v4()
this this
] ]
...@@ -174,8 +178,8 @@ isHiddenThread = (elem) -> ...@@ -174,8 +178,8 @@ isHiddenThread = (elem) ->
# Directive that instantiates {@link thread.ThreadController ThreadController}. # Directive that instantiates {@link thread.ThreadController ThreadController}.
### ###
module.exports = [ module.exports = [
'$parse', '$window', 'pulse', 'render', '$parse', '$window', '$location', '$anchorScroll', 'pulse', 'render',
($parse, $window, pulse, render) -> ($parse, $window, $location, $anchorScroll, pulse, render) ->
linkFn = (scope, elem, attrs, [ctrl, counter, filter]) -> linkFn = (scope, elem, attrs, [ctrl, counter, filter]) ->
# We would ideally use require for this, but searching parents only for a # We would ideally use require for this, but searching parents only for a
...@@ -183,6 +187,7 @@ module.exports = [ ...@@ -183,6 +187,7 @@ module.exports = [
ctrl.parent = elem.parent().controller('thread') ctrl.parent = elem.parent().controller('thread')
ctrl.counter = counter ctrl.counter = counter
ctrl.filter = filter ctrl.filter = filter
ctrl.id = attrs.id
# Track the number of messages in the thread # Track the number of messages in the thread
if counter? if counter?
...@@ -210,6 +215,10 @@ module.exports = [ ...@@ -210,6 +215,10 @@ module.exports = [
render -> render ->
ctrl.container = thread ctrl.container = thread
scope.$digest() scope.$digest()
if (ctrl.id and not ctrl.container?.message?.id)
# Scroll the sidebar to show new annotations.
$location.hash(ctrl.id)
$anchorScroll()
controller: ThreadController controller: ThreadController
controllerAs: 'vm' controllerAs: 'vm'
......
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
</ul> </ul>
</span> </span>
</li> </li>
<li class="paper thread" <li id="{{vm.uuid}}"
class="paper thread"
ng-class="{'js-hover': hasFocus(child.message)}" ng-class="{'js-hover': hasFocus(child.message)}"
deep-count="count" deep-count="count"
thread="child" thread-filter thread="child" thread-filter
......
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