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 if(self.search() && self.options['replace-all']) {
98 SearchPerspective.prototype.onEnter = function(success, failure){
101 $.wiki.Perspective.prototype.onEnter.call(this);
102 self.$searchCursor = null;
104 $('.vsplitbar').not('.active').trigger('click');
105 $(".vsplitbar-title").html("↓ ZNAJDŹ I ZAMIEŃ ↓");
107 if ($.wiki.activePerspective() != 'CodeMirrorPerspective')
108 $.wiki.switchToTab('#CodeMirrorPerspective');
111 SearchPerspective.prototype.onExit = function(success, failure) {
115 $.wiki.SearchPerspective = SearchPerspective;