diff options
-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; |