X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/ab3c4f696564e0f8cad64ff3f3123d4f6fac4361..cb900d10b9d0d42b0b6aa035be45dcbaa2f61af6:/src/redakcja/static/js/wiki/view_search.js?ds=inline diff --git a/src/redakcja/static/js/wiki/view_search.js b/src/redakcja/static/js/wiki/view_search.js index 09f64dab..cad64fba 100644 --- a/src/redakcja/static/js/wiki/view_search.js +++ b/src/redakcja/static/js/wiki/view_search.js @@ -3,126 +3,124 @@ /* * Perspective */ - function SearchPerspective(options){ - var old_callback = options.callback || function() { }; - - this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; + class SearchPerspective extends $.wiki.SidebarPerspective { + constructor(options) { + var old_callback = options.callback || function() { }; + + options.callback = function(){ + var self = this; + + this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; + this.editor = null; + this.$element = $("#side-search"); + 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){ + self.searchCursor = null; + }); + this.$replaceInput.change(function(event){ + self.searchCursor = null; + }); + + $("#side-search input:checkbox").each(function() { + self.options[this.id] = this.checked; + }).change(function(){ + self.options[this.id] = this.checked; + self.searchCursor = null; + }); + + this.$searchButton.click(function(){ + if (!self.search()) + 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); + }; + + super(options); + } - options.callback = function(){ + search(forward=true) { var self = this; - - this.editor = null; - this.$element = $("#side-search"); - 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){ - self.searchCursor = null; - }); - this.$replaceInput.change(function(event){ + 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; + } + } - $("#side-search input:checkbox").each(function() { - self.options[this.id] = this.checked; - }).change(function(){ - self.options[this.id] = this.checked; - self.searchCursor = null; - }); + replace() { + var self = this; + var query = self.$replaceInput.val(); - this.$searchButton.click(function(){ - if (!self.search()) - alert('Brak wyników.'); - }); + if (!self.searchCursor) { + self.search(); + } + else {} - this.$searchPrevButton.click(function(){ - if (!self.search(false)) - alert('Brak wyników.'); - }); + self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to()); + self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20); - this.$replaceButton.click(function(){ + self.searchCursor.replace(query); + if(self.search() && self.options['replace-all']) { self.replace(); - }); - - old_callback.call(this); - }; - - $.wiki.SidebarPerspective.call(this, options); - }; - - SearchPerspective.prototype = new $.wiki.SidebarPerspective(); - - SearchPerspective.prototype.search = function(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; } - }; - SearchPerspective.prototype.replace = function(){ - var self = this; - var query = self.$replaceInput.val(); - - if (!self.searchCursor) { - self.search(); - } - else {} + onEnter(success, failure) { + var self = this; - self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to()); - self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20); + super.onEnter(); + self.$searchCursor = null; - self.searchCursor.replace(query); - if(self.search() && self.options['replace-all']) { - self.replace(); + if ($.wiki.activePerspective() != 'CodeMirrorPerspective') + $.wiki.switchToTab('#CodeMirrorPerspective'); } - }; - - SearchPerspective.prototype.onEnter = function(success, failure){ - var self = this; - $.wiki.SidebarPerspective.prototype.onEnter.call(this); - self.$searchCursor = null; - - if ($.wiki.activePerspective() != 'CodeMirrorPerspective') - $.wiki.switchToTab('#CodeMirrorPerspective'); - }; - - SearchPerspective.prototype.onExit = function(success, failure) { - - }; + onExit(success, failure) { + } + } $.wiki.SearchPerspective = SearchPerspective;