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.$replaceButton = $('#replace-button', this.$element);
21 this.$replaceButton.attr("disabled","disabled");
22 this.options = Array();
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.$replaceButton.click(function(){
48 old_callback.call(this);
51 $.wiki.SidebarPerspective.call(this, options);
54 SearchPerspective.prototype = new $.wiki.SidebarPerspective();
56 SearchPerspective.prototype.search = function(){
58 var query = self.$searchInput.val();
61 self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror
63 if (!self.searchCursor) {
65 options.caseFold = !self.options['search-case-sensitive'];
67 if (self.options['search-from-cursor']) {
68 start = self.editor.getCursor();
70 self.searchCursor = self.editor.getSearchCursor(
71 self.$searchInput.val(),
76 if (self.searchCursor.findNext()) {
77 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
78 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
79 self.$replaceButton.removeAttr("disabled");
83 self.searchCursor = null;
84 this.$replaceButton.attr("disabled","disabled");
89 SearchPerspective.prototype.replace = function(){
91 var query = self.$replaceInput.val();
93 if (!self.searchCursor) {
98 self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
99 self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
101 self.searchCursor.replace(query);
102 if(self.search() && self.options['replace-all']) {
107 SearchPerspective.prototype.onEnter = function(success, failure){
110 $.wiki.SidebarPerspective.prototype.onEnter.call(this);
111 self.$searchCursor = null;
113 if ($.wiki.activePerspective() != 'CodeMirrorPerspective')
114 $.wiki.switchToTab('#CodeMirrorPerspective');
117 SearchPerspective.prototype.onExit = function(success, failure) {
121 $.wiki.SearchPerspective = SearchPerspective;