X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/df341bdd09208d2b0f84060454cc0000df19deba..54612c196135c939a7d17d51b81b1357f6eac9c3:/src/redakcja/static/js/wiki/view_search.js?ds=sidebyside diff --git a/src/redakcja/static/js/wiki/view_search.js b/src/redakcja/static/js/wiki/view_search.js index e8f9e1b4..1421aa91 100644 --- a/src/redakcja/static/js/wiki/view_search.js +++ b/src/redakcja/static/js/wiki/view_search.js @@ -3,12 +3,12 @@ /* * Perspective */ - function SearchPerspective(options){ - var old_callback = options.callback || function() { }; + class SearchPerspective extends $.wiki.SidebarPerspective { + vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; + options = Array(); - this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; - - options.callback = function(){ + constructor(options) { + super(options); var self = this; this.editor = null; @@ -16,10 +16,10 @@ this.$searchInput = $('#search-input', this.$element); this.$replaceInput = $('#replace-input', this.$element); this.$searchButton = $('#search-button', this.$element); + this.$searchPrevButton = $('#search-prev-button', this.$element); this.$replaceButton = $('#replace-button', this.$element); this.$replaceButton.attr("disabled","disabled"); - this.options = Array(); // handlers this.$searchInput.change(function(event){ @@ -41,82 +41,80 @@ alert('Brak wyników.'); }); + this.$searchPrevButton.click(function(){ + if (!self.search(false)) + alert('Brak wyników.'); + }); + this.$replaceButton.click(function(){ self.replace(); }); + } - old_callback.call(this); - }; - - $.wiki.SidebarPerspective.call(this, options); - }; - - SearchPerspective.prototype = new $.wiki.SidebarPerspective(); - - SearchPerspective.prototype.search = function(){ - var self = this; - var query = self.$searchInput.val(); - - if (!self.editor) - self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror - - if (!self.searchCursor) { - var options = {}; - options.caseFold = !self.options['search-case-sensitive']; - var start = 0; - if (self.options['search-from-cursor']) { - start = self.editor.getCursor(); + search(forward=true) { + var self = this; + var query = self.$searchInput.val(); + + if (!self.editor) + self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror + + if (!self.searchCursor) { + var options = {}; + options.caseFold = !self.options['search-case-sensitive']; + var start = 0; + if (self.options['search-from-cursor']) { + start = self.editor.getCursor(); + } + self.searchCursor = self.editor.getSearchCursor( + self.$searchInput.val(), + start, + options + ); + } + if (forward ? self.searchCursor.findNext() : self.searchCursor.findPrevious()) { + self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to()); + self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20); + self.$replaceButton.removeAttr("disabled"); + return true; + } + else { + self.searchCursor = null; + this.$replaceButton.attr("disabled","disabled"); + return false; } - self.searchCursor = self.editor.getSearchCursor( - self.$searchInput.val(), - start, - options - ); - } - if (self.searchCursor.findNext()) { - self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to()); - self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20); - self.$replaceButton.removeAttr("disabled"); - return true; - } - else { - self.searchCursor = null; - this.$replaceButton.attr("disabled","disabled"); - return false; } - }; - SearchPerspective.prototype.replace = function(){ - var self = this; - var query = self.$replaceInput.val(); + replace() { + var self = this; + var query = self.$replaceInput.val(); - if (!self.searchCursor) { - self.search(); - } - else {} + if (!self.searchCursor) { + self.search(); + } + else {} - self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to()); - self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20); + self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to()); + self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20); - self.searchCursor.replace(query); - if(self.search() && self.options['replace-all']) { - self.replace(); + self.searchCursor.replace(query); + if(self.search() && self.options['replace-all']) { + self.replace(); + } } - }; - - SearchPerspective.prototype.onEnter = function(success, failure){ - var self = this; - $.wiki.SidebarPerspective.prototype.onEnter.call(this); - self.$searchCursor = null; + onEnter(success, failure) { + var self = this; - if ($.wiki.activePerspective() != 'CodeMirrorPerspective') - $.wiki.switchToTab('#CodeMirrorPerspective'); - }; + super.onEnter(); + self.$searchCursor = null; - SearchPerspective.prototype.onExit = function(success, failure) { + if ($.wiki.activePerspective() != 'CodeMirrorPerspective') + $.wiki.switchToTab('#CodeMirrorPerspective'); + } - }; + onExit(success, failure) { + } + } $.wiki.SearchPerspective = SearchPerspective;