Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
c99dc829
Commit
c99dc829
authored
Apr 19, 2016
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3215 from hypothesis/315-page-share-visibility
Scroll share dialog into view when created
parents
005044c9
cab07fbc
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
115 additions
and
78 deletions
+115
-78
app-controller.js
h/static/scripts/app-controller.js
+17
-0
share-dialog.coffee
h/static/scripts/directive/share-dialog.coffee
+0
-35
share-dialog.js
h/static/scripts/directive/share-dialog.js
+42
-0
share-dialog-test.coffee
h/static/scripts/directive/test/share-dialog-test.coffee
+0
-36
share-dialog-test.js
h/static/scripts/directive/test/share-dialog-test.js
+32
-0
top-bar.js
h/static/scripts/directive/top-bar.js
+1
-0
app-controller-test.js
h/static/scripts/test/app-controller-test.js
+16
-0
share_dialog.html
h/templates/client/share_dialog.html
+6
-6
top_bar.html
h/templates/client/top_bar.html
+1
-1
No files found.
h/static/scripts/app-controller.js
View file @
c99dc829
'use strict'
;
var
angular
=
require
(
'angular'
);
var
scrollIntoView
=
require
(
'scroll-into-view'
);
var
annotationMetadata
=
require
(
'./annotation-metadata'
);
var
events
=
require
(
'./events'
);
...
...
@@ -102,9 +103,25 @@ module.exports = function AppController(
};
});
/** Scroll to the view to the element matching the given selector */
function
scrollToView
(
selector
)
{
// Add a timeout so that if the element has just been shown (eg. via ngIf)
// it is added to the DOM before we try to locate and scroll to it.
setTimeout
(
function
()
{
scrollIntoView
(
$document
[
0
].
querySelector
(
selector
));
},
0
);
}
// Start the login flow. This will present the user with the login dialog.
$scope
.
login
=
function
()
{
$scope
.
accountDialog
.
visible
=
true
;
scrollToView
(
'login-form'
);
};
// Display the dialog for sharing the current page
$scope
.
share
=
function
()
{
$scope
.
shareDialog
.
visible
=
true
;
scrollToView
(
'share-dialog'
);
};
// Prompt to discard any unsaved drafts.
...
...
h/static/scripts/directive/share-dialog.coffee
deleted
100644 → 0
View file @
005044c9
###*
# @ngdoc directive
# @name share-dialog
# @restrict A
# @description This dialog generates a via link to the page h is currently
# loaded on.
###
module
.
exports
=
[
'crossframe'
,
(
crossframe
)
->
link
:
(
scope
,
elem
,
attrs
,
ctrl
)
->
scope
.
viaPageLink
=
''
viaInput
=
elem
[
0
].
querySelector
(
'.js-via'
)
# Watch scope.shareDialog.visible: when it changes to true, focus input
# and selection.
scope
.
$watch
(
->
scope
.
shareDialog
?
.
visible
),
(
visible
)
->
if
visible
scope
.
$evalAsync
(
->
viaInput
.
focus
()
viaInput
.
select
()
)
scope
.
$watchCollection
(
->
crossframe
.
frames
),
(
frames
)
->
if
not
frames
.
length
return
# Check to see if we are on a via page. If so, we just return the URI.
re
=
/https:\/\/via\.hypothes\.is/
if
re
.
test
(
frames
[
0
].
uri
)
scope
.
viaPageLink
=
frames
[
0
].
uri
else
scope
.
viaPageLink
=
'https://via.hypothes.is/'
+
frames
[
0
].
uri
restrict
:
'E'
template
:
require
(
'../../../templates/client/share_dialog.html'
)
]
h/static/scripts/directive/share-dialog.js
0 → 100644
View file @
c99dc829
'use strict'
;
var
VIA_PREFIX
=
'https://via.hypothes.is/'
;
// @ngInject
function
ShareDialogController
(
$scope
,
$element
,
crossframe
)
{
var
ctrl
=
this
;
function
updateViaLink
(
frames
)
{
if
(
!
frames
.
length
)
{
ctrl
.
viaPageLink
=
''
;
return
;
}
// Check to see if we are on a via page. If so, we just return the URI.
if
(
frames
[
0
].
uri
.
indexOf
(
VIA_PREFIX
)
===
0
)
{
ctrl
.
viaPageLink
=
frames
[
0
].
uri
;
}
else
{
ctrl
.
viaPageLink
=
VIA_PREFIX
+
frames
[
0
].
uri
;
}
}
var
viaInput
=
$element
[
0
].
querySelector
(
'.js-via'
);
viaInput
.
focus
();
viaInput
.
select
();
$scope
.
$watchCollection
(
function
()
{
return
crossframe
.
frames
;
},
updateViaLink
);
}
module
.
exports
=
function
()
{
return
{
restrict
:
'E'
,
bindToController
:
true
,
controller
:
ShareDialogController
,
controllerAs
:
'vm'
,
scope
:
{
onClose
:
'&'
,
},
template
:
require
(
'../../../templates/client/share_dialog.html'
),
};
};
h/static/scripts/directive/test/share-dialog-test.coffee
deleted
100644 → 0
View file @
005044c9
{
module
,
inject
}
=
angular
.
mock
describe
'share-dialog'
,
->
$scope
=
null
$compile
=
null
fakeCrossFrame
=
null
before
->
angular
.
module
(
'h'
,
[])
.
directive
(
'shareDialog'
,
require
(
'../share-dialog'
))
beforeEach
module
(
'h'
)
beforeEach
module
(
$provide
)
->
fakeCrossFrame
=
{
frames
:
[]}
$provide
.
value
'crossframe'
,
fakeCrossFrame
return
beforeEach
inject
(
_$compile_
,
_$rootScope_
)
->
$compile
=
_$compile_
$scope
=
_$rootScope_
.
$new
()
it
'generates new via link'
,
->
$element
=
$compile
(
'<share-dialog></share-dialog>'
)(
$scope
)
fakeCrossFrame
.
frames
.
push
({
uri
:
'http://example.com'
})
$scope
.
$digest
()
assert
.
equal
(
$scope
.
viaPageLink
,
'https://via.hypothes.is/http://example.com'
)
it
'does not generate new via link if already on via'
,
->
$element
=
$compile
(
'<share-dialog></share-dialog>>'
)(
$scope
)
fakeCrossFrame
.
frames
.
push
({
uri
:
[
'https://via.hypothes.is/http://example.com'
]})
$scope
.
$digest
()
assert
.
equal
(
$scope
.
viaPageLink
,
'https://via.hypothes.is/http://example.com'
)
h/static/scripts/directive/test/share-dialog-test.js
0 → 100644
View file @
c99dc829
'use strict'
;
var
angular
=
require
(
'angular'
);
var
util
=
require
(
'./util'
);
describe
(
'shareDialog'
,
function
()
{
var
fakeCrossFrame
;
beforeEach
(
function
()
{
fakeCrossFrame
=
{
frames
:
[]
};
angular
.
module
(
'h'
,
[])
.
directive
(
'shareDialog'
,
require
(
'../share-dialog'
))
.
value
(
'crossframe'
,
fakeCrossFrame
);
angular
.
mock
.
module
(
'h'
);
});
it
(
'generates new via link'
,
function
()
{
var
element
=
util
.
createDirective
(
document
,
'shareDialog'
,
{});
fakeCrossFrame
.
frames
.
push
({
uri
:
'http://example.com'
});
element
.
scope
.
$digest
();
assert
.
equal
(
element
.
ctrl
.
viaPageLink
,
'https://via.hypothes.is/http://example.com'
);
});
it
(
'does not generate new via link if already on via'
,
function
()
{
var
element
=
util
.
createDirective
(
document
,
'shareDialog'
,
{});
fakeCrossFrame
.
frames
.
push
({
uri
:
'https://via.hypothes.is/http://example.com'
});
element
.
scope
.
$digest
();
assert
.
equal
(
element
.
ctrl
.
viaPageLink
,
'https://via.hypothes.is/http://example.com'
);
});
});
h/static/scripts/directive/top-bar.js
View file @
c99dc829
...
...
@@ -9,6 +9,7 @@ module.exports = function () {
onShowAboutVersionDialog
:
'&'
,
onLogin
:
'&'
,
onLogout
:
'&'
,
onSharePage
:
'&'
,
searchController
:
'<'
,
accountDialog
:
'<'
,
shareDialog
:
'<'
,
...
...
h/static/scripts/test/app-controller-test.js
View file @
c99dc829
...
...
@@ -210,6 +210,22 @@ describe('AppController', function () {
assert
.
calledOnce
(
fakeRoute
.
reload
);
});
describe
(
'#login()'
,
function
()
{
it
(
'shows the login dialog'
,
function
()
{
createController
();
$scope
.
login
();
assert
.
equal
(
$scope
.
accountDialog
.
visible
,
true
);
});
});
describe
(
'#share()'
,
function
()
{
it
(
'shows the share dialog'
,
function
()
{
createController
();
$scope
.
share
();
assert
.
equal
(
$scope
.
shareDialog
.
visible
,
true
);
});
});
describe
(
'logout()'
,
function
()
{
it
(
'prompts the user if there are drafts'
,
function
()
{
fakeDrafts
.
count
.
returns
(
1
);
...
...
h/templates/client/share_dialog.html
View file @
c99dc829
...
...
@@ -2,7 +2,7 @@
<i
class=
"close h-icon-close"
role=
"button"
title=
"Close"
ng-click=
"
shareDialog.visible = false
"
></i>
ng-click=
"
vm.onClose()
"
></i>
<div
class=
"form-vertical"
>
<ul
class=
"nav nav-tabs"
>
<li
class=
"active"
><a
href=
""
>
Share
</a></li>
...
...
@@ -11,22 +11,22 @@
<p>
Share the link below to show anyone these annotations and invite them to contribute their own.
</p>
<p><input
class=
"js-via form-input"
type=
"text"
ng-value=
"viaPageLink"
ng-value=
"v
m.v
iaPageLink"
readonly
/></p>
<p
class=
"share-link-icons"
>
<a
href=
"https://twitter.com/intent/tweet?url={{viaPageLink}}"
<a
href=
"https://twitter.com/intent/tweet?url={{v
m.v
iaPageLink}}"
target=
"_blank"
title=
"Tweet link"
class=
"share-link-icon h-icon-twitter"
></a>
<a
href=
"https://www.facebook.com/sharer/sharer.php?u={{viaPageLink}}"
<a
href=
"https://www.facebook.com/sharer/sharer.php?u={{v
m.v
iaPageLink}}"
target=
"_blank"
title=
"Share on Facebook"
class=
"share-link-icon h-icon-facebook"
></a>
<a
href=
"https://plus.google.com/share?url={{viaPageLink}}"
<a
href=
"https://plus.google.com/share?url={{v
m.v
iaPageLink}}"
target=
"_blank"
title=
"Post on Google Plus"
class=
"share-link-icon h-icon-google-plus"
></a>
<a
href=
"mailto:?subject=Let's%20Annotate&body={{viaPageLink}}"
<a
href=
"mailto:?subject=Let's%20Annotate&body={{v
m.v
iaPageLink}}"
title=
"Share via email"
class=
"share-link-icon h-icon-mail"
></a>
</p>
...
...
h/templates/client/top_bar.html
View file @
c99dc829
...
...
@@ -41,7 +41,7 @@
on-change-sort-by=
"onChangeSortBy({sortBy: sortBy})"
>
</sort-dropdown>
<a
class=
"top-bar__btn"
ng-click=
"
shareDialog.visible = !shareDialog.visible
"
ng-click=
"
onSharePage()
"
title=
"Share this page"
>
<i
class=
"h-icon-annotation-share"
></i>
</a>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment