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
9f4ab73f
Commit
9f4ab73f
authored
Mar 17, 2017
by
Robert Knight
Committed by
GitHub
Mar 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #254 from QualitativeDataRepository/queryFromUrl
Query from url
parents
1c1d704c
2cb0ec8c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
7 deletions
+83
-7
config.js
src/annotator/config.js
+4
-4
sidebar.coffee
src/annotator/sidebar.coffee
+1
-1
extract-annotation-query.js
src/annotator/util/extract-annotation-query.js
+33
-0
extract-annotation-query-test.js
src/annotator/util/test/extract-annotation-query-test.js
+38
-0
host-config.js
src/sidebar/host-config.js
+3
-0
selection.js
src/sidebar/reducers/selection.js
+4
-2
No files found.
src/annotator/config.js
View file @
9f4ab73f
'use strict'
;
var
annotation
IDs
=
require
(
'./util/annotation-ids
'
);
var
annotation
Query
=
require
(
'./util/extract-annotation-query
'
);
var
settings
=
require
(
'../shared/settings'
);
var
docs
=
'https://h.readthedocs.io/en/latest/embedding.html'
;
...
...
@@ -33,7 +33,7 @@ function config(window_) {
}
}
// Extract the d
irect linked ID
from the URL.
// Extract the d
efault query
from the URL.
//
// The Chrome extension or proxy may already have provided this config
// via a tag injected into the DOM, which avoids the problem where the page's
...
...
@@ -41,9 +41,9 @@ function config(window_) {
//
// In environments where the config has not been injected into the DOM,
// we try to retrieve it from the URL here.
var
directLinkedID
=
annotation
IDs
.
extractIDFromURL
(
window_
.
location
.
href
);
var
directLinkedID
=
annotation
Query
.
extractAnnotationQuery
(
window_
.
location
.
href
);
if
(
directLinkedID
)
{
options
.
annotations
=
directLinkedID
;
Object
.
assign
(
options
,
directLinkedID
)
;
}
return
options
;
}
...
...
src/annotator/sidebar.coffee
View file @
9f4ab73f
...
...
@@ -27,7 +27,7 @@ module.exports = class Sidebar extends Host
super
this
.
hide
()
if
options
.
openSidebar
||
options
.
annotations
if
options
.
openSidebar
||
options
.
annotations
||
options
.
query
this
.
on
'panelReady'
,
=>
this
.
show
()
if
@
plugins
.
BucketBar
?
...
...
src/annotator/util/
annotation-ids
.js
→
src/annotator/util/
extract-annotation-query
.js
View file @
9f4ab73f
'use strict'
;
/**
* Extracts a
direct-linked annotation ID from the fragment of a URL
.
* Extracts a
n annotation selection or default filter from a url
.
*
* @param {string} url - The URL which may contain a '#annotations:<ID>'
* fragment.
* @return {
string?} The annotation ID if present
* @return {
Object} - An object with either an annotation ID or a filter string.
*/
function
extractIDFromURL
(
url
)
{
function
extractAnnotationQuery
(
url
)
{
var
filter
=
{};
try
{
// Annotation IDs are url-safe-base64 identifiers
// See https://tools.ietf.org/html/rfc4648#page-7
var
annotFragmentMatch
=
url
.
match
(
/#annotations:
([
A-Za-z0-9_-
]
+
)
$/
);
if
(
annotFragmentMatch
)
{
return
annotFragmentMatch
[
1
];
var
queryFragmentMatch
=
url
.
match
(
/#annotations:
(
query|q
)
:
(
.+
)
$/i
);
if
(
queryFragmentMatch
)
{
filter
.
query
=
decodeURI
(
queryFragmentMatch
[
2
]);
}
else
if
(
annotFragmentMatch
)
{
filter
.
annotations
=
annotFragmentMatch
[
1
];
}
else
{
return
null
;
filter
=
null
;
}
}
catch
(
err
)
{
return
null
;
// URI Error should return the page unfiltered.
filter
=
null
;
}
return
filter
;
}
module
.
exports
=
{
extract
IDFromURL
:
extractIDFromURL
,
extract
AnnotationQuery
:
extractAnnotationQuery
,
};
src/annotator/util/test/extract-annotation-query-test.js
0 → 100644
View file @
9f4ab73f
'use strict'
;
var
unroll
=
require
(
'../../../shared/test/util'
).
unroll
;
var
annotationIds
=
require
(
'../extract-annotation-query'
);
describe
(
'annotation queries'
,
function
()
{
it
(
'returns null on invalid fragment'
,
function
()
{
assert
.
equal
(
annotationIds
.
extractAnnotationQuery
(
'http://localhost:3000#annotations:
\
"TRYINGTOGETIN
\
");EVILSCRIPT()'
),
null
);
});
unroll
(
'accepts annotation fragment from urls'
,
function
(
testCase
)
{
assert
.
equal
(
annotationIds
.
extractAnnotationQuery
(
testCase
.
url
).
annotations
,
testCase
.
result
);
},
[{
url
:
'http://localhost:3000#annotations:alphanum3ric_-only'
,
result
:
'alphanum3ric_-only'
,
},
]);
unroll
(
'accepts query from annotation fragment'
,
function
(
testCase
)
{
assert
.
equal
(
annotationIds
.
extractAnnotationQuery
(
testCase
.
url
).
query
,
testCase
.
result
);
},
[{
url
:
'http://localhost:3000#annotations:q:user:USERNAME'
,
result
:
'user:USERNAME'
,
},
{
url
:
'http://localhost:3000#annotations:QuerY:user:USERNAME'
,
result
:
'user:USERNAME'
,
},
{
url
:
'http://localhost:3000#annotations:q:user:USERNAME%20tag:KEYWORD'
,
result
:
'user:USERNAME tag:KEYWORD'
,
}]);
});
src/sidebar/host-config.js
View file @
9f4ab73f
...
...
@@ -16,6 +16,9 @@ function hostPageConfig(window) {
var
paramWhiteList
=
[
// Direct-linked annotation ID
'annotations'
,
// Default query passed by url
'query'
,
// Config param added by the extension, Via etc. indicating how Hypothesis
// was added to the page.
...
...
src/sidebar/reducers/selection.js
View file @
9f4ab73f
...
...
@@ -16,6 +16,7 @@ var uiConstants = require('../ui-constants');
var
util
=
require
(
'./util'
);
/**
* Default starting tab.
*/
...
...
@@ -37,9 +38,10 @@ TAB_SORTKEYS_AVAILABLE[uiConstants.TAB_ANNOTATIONS] = ['Newest', 'Oldest', 'Loca
TAB_SORTKEYS_AVAILABLE
[
uiConstants
.
TAB_NOTES
]
=
[
'Newest'
,
'Oldest'
];
TAB_SORTKEYS_AVAILABLE
[
uiConstants
.
TAB_ORPHANS
]
=
[
'Newest'
,
'Oldest'
,
'Location'
];
function
initialSelection
(
settings
)
{
var
selection
=
{};
if
(
settings
.
annotations
)
{
if
(
settings
.
annotations
&&
!
settings
.
query
)
{
selection
[
settings
.
annotations
]
=
true
;
}
return
freeze
(
selection
);
...
...
@@ -81,7 +83,7 @@ function init(settings) {
// IDs of annotations that should be highlighted
highlighted
:
[],
filterQuery
:
null
,
filterQuery
:
settings
.
query
||
null
,
selectedTab
:
TAB_DEFAULT
,
...
...
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