6 function SearchPerspective(options){
7 var old_callback = options.callback || function() { };
9 this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ';
11 options.callback = function(){
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);
57 $.wiki.SidebarPerspective.call(this, options);
60 SearchPerspective.prototype = new $.wiki.SidebarPerspective();
62 SearchPerspective.prototype.search = function(forward=true){
64 var query = self.$searchInput.val();
67 self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror
69 if (!self.searchCursor) {
71 options.caseFold = !self.options['search-case-sensitive'];
73 if (self.options['search-from-cursor']) {
74 start = self.editor.getCursor();
76 self.searchCursor = self.editor.getSearchCursor(
77 self.$searchInput.val(),
82 if (forward ? self.searchCursor.findNext() : self.searchCursor.findPrevious()) {
83 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
84 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
85 self.$replaceButton.removeAttr("disabled");
89 self.searchCursor = null;
90 this.$replaceButton.attr("disabled","disabled");
95 SearchPerspective.prototype.replace = function(){
97 var query = self.$replaceInput.val();
99 if (!self.searchCursor) {
104 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
105 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
107 self.searchCursor.replace(query);
108 if(self.search() && self.options['replace-all']) {
113 SearchPerspective.prototype.onEnter = function(success, failure){
116 $.wiki.SidebarPerspective.prototype.onEnter.call(this);
117 self.$searchCursor = null;
119 if ($.wiki.activePerspective() != 'CodeMirrorPerspective')
120 $.wiki.switchToTab('#CodeMirrorPerspective');
123 SearchPerspective.prototype.onExit = function(success, failure) {
127 $.wiki.SearchPerspective = SearchPerspective;