summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-04-13 11:49:54 -0500
committerDouwe Maan <douwe@selenight.nl>2017-04-27 12:23:26 -0500
commit3079a2d63b54377c01ce5d09b96b3d7db20462aa (patch)
tree54632fc812dbaa103fb43a78b5b10345e7cf17af
parent121c5f66180acd78cedf18b19b0e86ee5bf1204d (diff)
downloadgitlab-ce-3079a2d63b54377c01ce5d09b96b3d7db20462aa.tar.gz
Allow LineHighlighter to be triggered by event
-rw-r--r--app/assets/javascripts/line_highlighter.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/app/assets/javascripts/line_highlighter.js b/app/assets/javascripts/line_highlighter.js
index 1821ca18053..5ffa6283a03 100644
--- a/app/assets/javascripts/line_highlighter.js
+++ b/app/assets/javascripts/line_highlighter.js
@@ -41,7 +41,6 @@ require('vendor/jquery.scrollTo');
LineHighlighter.prototype._hash = '';
function LineHighlighter(hash) {
- var range;
if (hash == null) {
// Initialize a LineHighlighter object
//
@@ -51,10 +50,21 @@ require('vendor/jquery.scrollTo');
this.setHash = bind(this.setHash, this);
this.highlightLine = bind(this.highlightLine, this);
this.clickHandler = bind(this.clickHandler, this);
+ this.highlightHash = this.highlightHash.bind(this);
this._hash = hash;
this.bindEvents();
- if (hash !== '') {
- range = this.hashToRange(hash);
+ this.highlightHash();
+ }
+
+ LineHighlighter.prototype.bindEvents = function() {
+ $('#blob-content-holder').on('click', 'a[data-line-number]', this.clickHandler);
+ $('#blob-content-holder').on('highlight:line', this.highlightHash);
+ };
+
+ LineHighlighter.prototype.highlightHash = function() {
+ var range;
+ if (this._hash !== '') {
+ range = this.hashToRange(this._hash);
if (range[0]) {
this.highlightRange(range);
$.scrollTo("#L" + range[0], {
@@ -64,10 +74,6 @@ require('vendor/jquery.scrollTo');
});
}
}
- }
-
- LineHighlighter.prototype.bindEvents = function() {
- $('#blob-content-holder').on('click', 'a[data-line-number]', this.clickHandler);
};
LineHighlighter.prototype.clickHandler = function(event) {