diff options
Diffstat (limited to 'data/js')
-rw-r--r-- | data/js/application.js | 9 | ||||
-rw-r--r-- | data/js/script.js | 10 | ||||
-rw-r--r-- | data/js/util.js | 10 |
3 files changed, 18 insertions, 11 deletions
diff --git a/data/js/application.js b/data/js/application.js index ef520be65..a82c193c8 100644 --- a/data/js/application.js +++ b/data/js/application.js @@ -28,6 +28,7 @@ define( LexerInput.initialize(config.lexers); this.configureTooltips(); this.setupToggleSelectAllEvent(); + this.setupLineWrapToggle(); }, setupLineHighlight: function () { @@ -50,8 +51,14 @@ define( var checked = $(event.target).prop('checked'); $('.delete-history').prop('checked', checked); }); - } + }, + setupLineWrapToggle: function () { + var linesWrapped = localStorage.getItem('lines_wrapped') || 'true'; + Util.setLineWrap(linesWrapped === 'true'); + + $('.linewrap-toggle').on('click', _.bind(Util.toggleLineWrap, Util)); + } }; return App; diff --git a/data/js/script.js b/data/js/script.js index f0ab3cc94..5c509c41a 100644 --- a/data/js/script.js +++ b/data/js/script.js @@ -1,15 +1,5 @@ (function($) { $(function() { - window.lines_wrapped = true; - $('[id^=linewrap-]').click(function() { - if (window.lines_wrapped == true) { - $(".highlight > pre").css("white-space", "pre"); - } else { - $(".highlight > pre").css("white-space", "pre-wrap"); - } - window.lines_wrapped = !window.lines_wrapped; - }); - $('.upload_thumbnails a').popover({ trigger: "hover", placement: "bottom", diff --git a/data/js/util.js b/data/js/util.js index 6c88edb2d..af3635673 100644 --- a/data/js/util.js +++ b/data/js/util.js @@ -43,6 +43,16 @@ define(['jquery'], function () { }, setTabwidthFromLocalStorage: function () { this.setTabwidth(localStorage.getItem('tabwidth')); + }, + setLineWrap: function (lines_wrapped) { + var whitespaceMode = lines_wrapped ? 'pre-wrap' : 'pre'; + $('.highlight > pre').css('white-space', whitespaceMode); + localStorage.setItem('lines_wrapped', lines_wrapped); + }, + toggleLineWrap: function() { + this.setLineWrap( + localStorage.getItem('lines_wrapped') !== 'true' + ); } }; return Util; |