diff options
Diffstat (limited to 'data')
-rw-r--r-- | data/js/application.js | 18 | ||||
-rw-r--r-- | data/js/script.js | 15 | ||||
-rw-r--r-- | data/js/util.js | 34 |
3 files changed, 51 insertions, 16 deletions
diff --git a/data/js/application.js b/data/js/application.js index 9cb1a050f..d0e7c649f 100644 --- a/data/js/application.js +++ b/data/js/application.js @@ -1,6 +1,22 @@ (function () { 'use strict'; -define(['require', 'vendor'], function (require) { +define(['require', 'util', 'vendor'], function (require, Util) { require(['script']); + var App = { + // Gets called for every request + initialize: function () { + this.setupLineHighlight(); + }, + // Gets called for every request on page load + onPageLoaded: function () { + Util.highlightLineFromHash(); + }, + + setupLineHighlight: function () { + $(window).on('hashchange', Util.highlightLineFromHash); + } + }; + + return App; }); })(); diff --git a/data/js/script.js b/data/js/script.js index 9b8319b14..91df1b786 100644 --- a/data/js/script.js +++ b/data/js/script.js @@ -4,21 +4,6 @@ function fixedEncodeURIComponent (str) { (function($) { $(function() { - $(window).bind('hashchange', function(e) { - var hash = window.location.hash; - - $('.highlight_line').removeClass("highlight_line"); - - if (hash.match(/^#n(?:-.+-)?\d+$/) === null) { - return; - } - - var line = $(hash).parent().parent(); - line.addClass("highlight_line"); - }); - - $(window).trigger('hashchange'); - var lexer_source = []; for (var key in window.lexers) { lexer_source.push({ label: window.lexers[key], value: key }); 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; +}); +})(); |