Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
15582293
Commit
15582293
authored
Jun 15, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `pushState` instead of the temporary div hack
parent
b3f9be06
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
36 deletions
+10
-36
app/assets/javascripts/blob/blob.js.coffee
app/assets/javascripts/blob/blob.js.coffee
+10
-36
No files found.
app/assets/javascripts/blob/blob.js.coffee
View file @
15582293
...
...
@@ -64,12 +64,11 @@ class @BlobView
clickHandler
:
(
event
)
=>
event
.
preventDefault
()
@
clearHighlight
()
lineNumber
=
$
(
event
.
target
).
data
(
'line-number'
)
current
=
@
hashToRange
(
@
_hash
)
# Unhighlight previously highlighted lines
$
(
'.hll'
).
removeClass
(
'hll'
)
if
isNaN
(
current
[
0
])
or
!
event
.
shiftKey
# If there's no current selection, or there is but Shift wasn't held,
# treat this like a single-line selection.
...
...
@@ -84,6 +83,10 @@ class @BlobView
@
setHash
(
range
[
0
],
range
[
1
])
@
highlightRange
(
range
)
# Unhighlight previously highlighted lines
clearHighlight
:
->
$
(
'.hll'
).
removeClass
(
'hll'
)
# Convert a URL hash String into line numbers
#
# hash - Hash String
...
...
@@ -145,42 +148,13 @@ class @BlobView
else
hash
=
"#L
#{
firstLineNumber
}
-
#{
lastLineNumber
}
"
@
setHashWithoutScroll
(
hash
)
# Prevents the page from scrolling when `location.hash` is set
#
# This is accomplished by removing the `id` attribute of the matching element,
# creating a temporary div at the top of the current viewport, setting the
# hash, and then removing the div and restoring the `id` attribute.
#
# See http://stackoverflow.com/a/1489802/223897
#
# FIXME (rspeicher): This is still super buggy for me.
setHashWithoutScroll
:
(
hash
)
->
@
_hash
=
hash
# Extract the first ID, in case we were given a range
firstID
=
hash
.
replace
(
/-\d+$/
,
''
)
$node
=
$
(
firstID
)
$node
.
removeAttr
(
'id'
)
$tmp
=
$
(
'<div></div>'
)
.
css
(
position
:
'absolute'
top
:
"
#{
$
(
window
).
scrollTop
()
}
px"
visibility
:
'hidden'
)
.
attr
(
'id'
,
firstID
)
.
appendTo
(
$
(
'body'
))
@
__setLocationHash__
(
hash
)
$tmp
.
remove
()
$node
.
attr
(
'id'
,
firstID
)
# Make the actual `location.hash` change
# Make the actual hash change in the browser
#
# This method is stubbed in tests.
__setLocationHash__
:
(
value
)
->
location
.
hash
=
value
# We're using pushState instead of assigning location.hash directly to
# prevent the page from scrolling on the hashchange event
history
.
pushState
({
turbolinks
:
false
,
url
:
value
},
document
.
title
,
value
)
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