6 function SearchPerspective(options){
7 var old_callback = options.callback || function() { };
9 this.noupdate_hash_onenter = true;
10 this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ';
12 options.callback = function(){
16 this.$element = $("#side-search");
17 this.$searchInput = $('#search-input', this.$element);
18 this.$replaceInput = $('#replace-input', this.$element);
19 this.$searchButton = $('#search-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.$replaceButton.click(function(){
49 old_callback.call(this);
52 $.wiki.Perspective.call(this, options);
55 SearchPerspective.prototype = new $.wiki.Perspective();
57 SearchPerspective.prototype.search = function(){
59 var query = self.$searchInput.val();
62 self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror
64 if (!self.searchCursor) {
65 self.searchCursor = self.editor.getSearchCursor(
66 self.$searchInput.val(),
67 self.options['search-from-cursor'],
68 !self.options['search-case-sensitive']
71 if (self.searchCursor.findNext()) {
72 self.searchCursor.select();
73 self.$replaceButton.removeAttr("disabled");
77 self.searchCursor = null;
78 this.$replaceButton.attr("disabled","disabled");
83 SearchPerspective.prototype.replace = function(){
85 var query = self.$replaceInput.val();
87 if (!self.searchCursor) {
91 self.searchCursor.select();
92 self.searchCursor.replace(query);
93 var found = self.search();
94 if(self.options['replace-all']) {
97 found = self.search();
102 SearchPerspective.prototype.onEnter = function(success, failure){
105 $.wiki.Perspective.prototype.onEnter.call(this);
106 self.$searchCursor = null;
108 $('.vsplitbar').not('.active').trigger('click');
109 $(".vsplitbar-title").html("↓ ZNAJDŹ I ZAMIEŃ ↓");
111 if ($.wiki.activePerspective() != 'CodeMirrorPerspective')
112 $.wiki.switchToTab('#CodeMirrorPerspective');
115 SearchPerspective.prototype.onExit = function(success, failure) {
119 $.wiki.SearchPerspective = SearchPerspective;