6 class SearchPerspective extends $.wiki.SidebarPerspective {
7 vsplitbar = 'ZNAJDŹ I ZAMIEŃ';
10 constructor(options) {
15 this.$element = $("#side-search");
16 this.$searchInput = $('#search-input', this.$element);
17 this.$replaceInput = $('#replace-input', this.$element);
18 this.$searchButton = $('#search-button', this.$element);
19 this.$searchPrevButton = $('#search-prev-button', this.$element);
20 this.$replaceButton = $('#replace-button', this.$element);
22 this.$replaceButton.attr("disabled","disabled");
25 this.$searchInput.change(function(event){
26 self.searchCursor = null;
28 this.$replaceInput.change(function(event){
29 self.searchCursor = null;
32 $("#side-search input:checkbox").each(function() {
33 self.options[this.id] = this.checked;
35 self.options[this.id] = this.checked;
36 self.searchCursor = null;
39 this.$searchButton.click(function(){
41 alert('Brak wyników.');
44 this.$searchPrevButton.click(function(){
45 if (!self.search(false))
46 alert('Brak wyników.');
49 this.$replaceButton.click(function(){
54 search(forward=true) {
56 var query = self.$searchInput.val();
59 self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror
61 if (!self.searchCursor) {
63 options.caseFold = !self.options['search-case-sensitive'];
65 if (self.options['search-from-cursor']) {
66 start = self.editor.getCursor();
68 self.searchCursor = self.editor.getSearchCursor(
69 self.$searchInput.val(),
74 if (forward ? self.searchCursor.findNext() : self.searchCursor.findPrevious()) {
75 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
76 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
77 self.$replaceButton.removeAttr("disabled");
81 self.searchCursor = null;
82 this.$replaceButton.attr("disabled","disabled");
89 var query = self.$replaceInput.val();
91 if (!self.searchCursor) {
96 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
97 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
99 self.searchCursor.replace(query);
100 if(self.search() && self.options['replace-all']) {
105 onEnter(success, failure) {
109 self.$searchCursor = null;
111 if ($.wiki.activePerspective() != 'CodeMirrorPerspective')
112 $.wiki.switchToTab('#CodeMirrorPerspective');
115 onExit(success, failure) {
119 $.wiki.SearchPerspective = SearchPerspective;