Commit 30cbdbf1 authored by Randall Leeds's avatar Randall Leeds

Merge pull request #1710 from hypothesis/1673-focus-share-link

Focus share link when pop-up opens
parents f42bf08e 3485febd
......@@ -302,8 +302,8 @@ AnnotationController = [
# an embedded widget.
###
annotation = [
'annotator',
(annotator) ->
'$document', 'annotator',
($document, annotator) ->
linkFn = (scope, elem, attrs, [ctrl, thread, threadFilter, counter]) ->
# Helper function to remove the temporary thread created for a new reply.
prune = (message) ->
......@@ -327,6 +327,12 @@ annotation = [
scope.$evalAsync ->
ctrl.save()
scope.share = (event) ->
scope.$evalAsync ->
$container = angular.element(event.target).parent()
$container.addClass('open').find('input').focus().select()
$document.one('click', (event) -> $container.removeClass('open'))
# Keep track of edits going on in the thread.
if counter?
# Expand the thread if descendants are editing.
......
......@@ -117,7 +117,7 @@
ng-click="vm.reply()"
><i class="h-icon-reply"></i> Reply</a>
<span class="magicontrol share-dialog-wrapper">
<a class="small dropdown-toggle" href="" title="Share"
<a class="small" href="" title="Share" ng-click="share($event)"
><i class="h-icon-export"></i> Share</a>
<span class="share-dialog" ng-click="$event.stopPropagation()">
<a class="h-icon-export"
......
......@@ -2,6 +2,8 @@ assert = chai.assert
sandbox = sinon.sandbox.create()
describe 'h.directives.annotation', ->
$compile = null
$document = null
$scope = null
$timeout = null
annotator = null
......@@ -10,8 +12,11 @@ describe 'h.directives.annotation', ->
flash = null
beforeEach module('h')
beforeEach module('h.templates')
beforeEach inject ($controller, $rootScope, _$timeout_) ->
beforeEach inject (_$compile_, $controller, _$document_, $rootScope, _$timeout_) ->
$compile = _$compile_
$document = _$document_
$timeout = _$timeout_
$scope = $rootScope.$new()
$scope.annotationGet = (locals) -> annotation
......@@ -262,3 +267,23 @@ describe 'h.directives.annotation', ->
$scope.$destroy()
$timeout.flush()
$timeout.verifyNoPendingTasks()
describe 'share', ->
$element = null
$isolateScope = null
dialog = null
beforeEach ->
template = '<div annotation="annotation">'
$scope.annotation = annotation
$element = $compile(template)($scope)
$scope.$digest()
$isolateScope = $element.isolateScope()
dialog = $element.find('.share-dialog-wrapper')
it 'sets and unsets the open class on the share wrapper', ->
$element.find('a').filter(-> this.title == 'Share').click()
$isolateScope.$digest()
assert.ok(dialog.hasClass('open'))
$document.click()
assert.notOk(dialog.hasClass('open'))
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