From 9f1fb6e1c8fbe2c54b5d9a7f0755557acd7ea84a Mon Sep 17 00:00:00 2001 From: Joakim Reinert Date: Sat, 18 Apr 2015 23:09:44 +0200 Subject: Refactor line higlighting functionality --- data/js/util.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 data/js/util.js (limited to 'data/js/util.js') diff --git a/data/js/util.js b/data/js/util.js new file mode 100644 index 000000000..810bc4167 --- /dev/null +++ b/data/js/util.js @@ -0,0 +1,34 @@ +(function () { +'use strict'; +define(['jquery'], function () { + var PrivateFunctions = { + highlightLine: function (id) { + this.clearLineHighlights(); + var line = $(id).parents('.table-row'); + line.addClass("highlight_line"); + }, + clearLineHighlights: function () { + $('.highlight_line').removeClass('highlight_line'); + } + }; + var Util = { + fixedEncodeURIComponent: function (string) { + var encodedString = encodeURIComponent(string); + encodedString = encodedString.replace(/[!'()]/g, escape); + encodedString = encodedString.replace(/\*/g, "%2A"); + + return encodedString; + }, + highlightLineFromHash: function () { + var hash = window.location.hash; + if (hash.match(/^#n(?:-.+-)?\d+$/) === null) { + PrivateFunctions.clearLineHighlights(); + return; + } + + PrivateFunctions.highlightLine(hash); + } + }; + return Util; +}); +})(); -- cgit v1.2.3-24-g4f1b