6 class SearchPerspective extends $.wiki.SidebarPerspective {
8 var old_callback = options.callback || function() { };
10 options.callback = function(){
13 this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ';
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");
23 this.options = Array();
26 this.$searchInput.change(function(event){
27 self.searchCursor = null;
29 this.$replaceInput.change(function(event){
30 self.searchCursor = null;
33 $("#side-search input:checkbox").each(function() {
34 self.options[this.id] = this.checked;
36 self.options[this.id] = this.checked;
37 self.searchCursor = null;
40 this.$searchButton.click(function(){
42 alert('Brak wyników.');
45 this.$searchPrevButton.click(function(){
46 if (!self.search(false))
47 alert('Brak wyników.');
50 this.$replaceButton.click(function(){
54 old_callback.call(this);
60 search(forward=true) {
62 var query = self.$searchInput.val();
65 self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror
67 if (!self.searchCursor) {
69 options.caseFold = !self.options['search-case-sensitive'];
71 if (self.options['search-from-cursor']) {
72 start = self.editor.getCursor();
74 self.searchCursor = self.editor.getSearchCursor(
75 self.$searchInput.val(),
80 if (forward ? self.searchCursor.findNext() : self.searchCursor.findPrevious()) {
81 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
82 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
83 self.$replaceButton.removeAttr("disabled");
87 self.searchCursor = null;
88 this.$replaceButton.attr("disabled","disabled");
95 var query = self.$replaceInput.val();
97 if (!self.searchCursor) {
102 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
103 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
105 self.searchCursor.replace(query);
106 if(self.search() && self.options['replace-all']) {
111 onEnter(success, failure) {
115 self.$searchCursor = null;
117 if ($.wiki.activePerspective() != 'CodeMirrorPerspective')
118 $.wiki.switchToTab('#CodeMirrorPerspective');
121 onExit(success, failure) {
125 $.wiki.SearchPerspective = SearchPerspective;