diff options
author | Joakim Reinert <mail@jreinert.com> | 2015-04-19 01:21:28 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-05-05 12:21:27 +0200 |
commit | f0be7e7412721039cdd37798fe294dd5cb41d216 (patch) | |
tree | 7b0c731174da32296d2e061f867af0393f401a66 | |
parent | c6448f49018ba88d5b2525b224415e6d7fd2b4fe (diff) |
Refactor linewrap toggle
-rw-r--r-- | application/views/file/html_paste_header.php | 2 | ||||
-rw-r--r-- | data/js/application.js | 9 | ||||
-rw-r--r-- | data/js/script.js | 10 | ||||
-rw-r--r-- | data/js/util.js | 10 |
4 files changed, 19 insertions, 12 deletions
diff --git a/application/views/file/html_paste_header.php b/application/views/file/html_paste_header.php index ee14a70c7..c5bc396c6 100644 --- a/application/views/file/html_paste_header.php +++ b/application/views/file/html_paste_header.php @@ -25,7 +25,7 @@ <?php } ?> </ul> <div class="btn-group navbar-right" style="margin: 8px;"> - <a id="linewrap-<?=$id; ?>" class="btn btn-default" rel="tooltip" title="Toggle wrapping of long lines">Linewrap</a> + <a class="btn btn-default linewrap-toggle" rel="tooltip" title="Toggle wrapping of long lines">Linewrap</a> <div class="btn-group"> <a class="btn btn-default dropdown-toggle tabwidth-toggle" rel="tooltip" title="Set tab width in spaces" data-toggle="dropdown" href="#">Tab width: <span class="tabwidth-value"></span> <span class="caret"></span></a> <div class="dropdown-menu tabwidth-dropdown"> 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; |