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
4d5fc292
Commit
4d5fc292
authored
Apr 06, 2018
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `width`, `height` and `view` instance properties
parent
f333e64f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
adder.js
src/annotator/adder.js
+10
-10
No files found.
src/annotator/adder.js
View file @
4d5fc292
...
@@ -151,7 +151,7 @@ class Adder {
...
@@ -151,7 +151,7 @@ class Adder {
// so that we can compute its size in order to position it before display.
// so that we can compute its size in order to position it before display.
this
.
element
.
style
.
visibility
=
'hidden'
;
this
.
element
.
style
.
visibility
=
'hidden'
;
var
view
=
this
.
element
.
ownerDocument
.
defaultView
;
this
.
_
view
=
this
.
element
.
ownerDocument
.
defaultView
;
this
.
_enterTimeout
=
null
;
this
.
_enterTimeout
=
null
;
var
handleCommand
=
(
event
)
=>
{
var
handleCommand
=
(
event
)
=>
{
...
@@ -174,8 +174,8 @@ class Adder {
...
@@ -174,8 +174,8 @@ class Adder {
this
.
element
.
querySelector
(
HIGHLIGHT_BTN_SELECTOR
)
this
.
element
.
querySelector
(
HIGHLIGHT_BTN_SELECTOR
)
.
addEventListener
(
'click'
,
handleCommand
);
.
addEventListener
(
'click'
,
handleCommand
);
var
width
=
()
=>
this
.
element
.
getBoundingClientRect
().
width
;
this
.
_
width
=
()
=>
this
.
element
.
getBoundingClientRect
().
width
;
var
height
=
()
=>
this
.
element
.
getBoundingClientRect
().
height
;
this
.
_
height
=
()
=>
this
.
element
.
getBoundingClientRect
().
height
;
/** Hide the adder */
/** Hide the adder */
this
.
hide
=
()
=>
{
this
.
hide
=
()
=>
{
...
@@ -211,32 +211,32 @@ class Adder {
...
@@ -211,32 +211,32 @@ class Adder {
// and close to the end.
// and close to the end.
var
hMargin
=
Math
.
min
(
ARROW_H_MARGIN
,
targetRect
.
width
);
var
hMargin
=
Math
.
min
(
ARROW_H_MARGIN
,
targetRect
.
width
);
if
(
isSelectionBackwards
)
{
if
(
isSelectionBackwards
)
{
left
=
targetRect
.
left
-
width
()
/
2
+
hMargin
;
left
=
targetRect
.
left
-
this
.
_
width
()
/
2
+
hMargin
;
}
else
{
}
else
{
left
=
targetRect
.
left
+
targetRect
.
width
-
width
()
/
2
-
hMargin
;
left
=
targetRect
.
left
+
targetRect
.
width
-
this
.
_
width
()
/
2
-
hMargin
;
}
}
// Flip arrow direction if adder would appear above the top or below the
// Flip arrow direction if adder would appear above the top or below the
// bottom of the viewport.
// bottom of the viewport.
if
(
targetRect
.
top
-
height
()
<
0
&&
if
(
targetRect
.
top
-
this
.
_
height
()
<
0
&&
arrowDirection
===
ARROW_POINTING_DOWN
)
{
arrowDirection
===
ARROW_POINTING_DOWN
)
{
arrowDirection
=
ARROW_POINTING_UP
;
arrowDirection
=
ARROW_POINTING_UP
;
}
else
if
(
targetRect
.
top
+
height
()
>
view
.
innerHeight
)
{
}
else
if
(
targetRect
.
top
+
this
.
_height
()
>
this
.
_
view
.
innerHeight
)
{
arrowDirection
=
ARROW_POINTING_DOWN
;
arrowDirection
=
ARROW_POINTING_DOWN
;
}
}
if
(
arrowDirection
===
ARROW_POINTING_UP
)
{
if
(
arrowDirection
===
ARROW_POINTING_UP
)
{
top
=
targetRect
.
top
+
targetRect
.
height
+
ARROW_HEIGHT
;
top
=
targetRect
.
top
+
targetRect
.
height
+
ARROW_HEIGHT
;
}
else
{
}
else
{
top
=
targetRect
.
top
-
height
()
-
ARROW_HEIGHT
;
top
=
targetRect
.
top
-
this
.
_
height
()
-
ARROW_HEIGHT
;
}
}
// Constrain the adder to the viewport.
// Constrain the adder to the viewport.
left
=
Math
.
max
(
left
,
0
);
left
=
Math
.
max
(
left
,
0
);
left
=
Math
.
min
(
left
,
view
.
innerWidth
-
width
());
left
=
Math
.
min
(
left
,
this
.
_view
.
innerWidth
-
this
.
_
width
());
top
=
Math
.
max
(
top
,
0
);
top
=
Math
.
max
(
top
,
0
);
top
=
Math
.
min
(
top
,
view
.
innerHeight
-
height
());
top
=
Math
.
min
(
top
,
this
.
_view
.
innerHeight
-
this
.
_
height
());
return
{
top
,
left
,
arrowDirection
};
return
{
top
,
left
,
arrowDirection
};
};
};
...
...
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