Changeset 982
- Timestamp:
- 03/21/08 19:55:25 (5 years ago)
- Files:
-
- 1 modified
-
trunk/plugins/SmartReplace/smart-replace.js (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/SmartReplace/smart-replace.js
r974 r982 2 2 SmartReplace for Xinha 3 3 _______________________ 4 4 5 5 \*------------------------------------------*/ 6 6 … … 38 38 39 39 SmartReplace.prototype._lc = function(string) { 40 return Xinha._lc(string, 'SmartReplace');40 return Xinha._lc(string, 'SmartReplace'); 41 41 }; 42 42 … … 69 69 var self = this; 70 70 Xinha._addEvent( 71 self.editor._doc,72 "keypress",73 function (event)74 {75 return self.keyEvent(Xinha.is_ie ? self.editor._iframe.contentWindow.event : event);76 });77 78 var quotes = this.editor.config.SmartReplace.quotes;71 self.editor._doc, 72 "keypress", 73 function (event) 74 { 75 return self.keyEvent(Xinha.is_ie ? self.editor._iframe.contentWindow.event : event); 76 }); 77 78 var quotes = this.editor.config.SmartReplace.quotes; 79 79 80 if (quotes && typeof quotes == 'object')81 {82 this.openingQuotes = quotes[0];80 if (quotes && typeof quotes == 'object') 81 { 82 this.openingQuotes = quotes[0]; 83 83 this.closingQuotes = quotes[1]; 84 84 this.openingQuote = quotes[2]; 85 85 this.closingQuote = quotes[3]; 86 }87 else88 {89 this.openingQuotes = this._lc("OpeningDoubleQuotes");86 } 87 else 88 { 89 this.openingQuotes = this._lc("OpeningDoubleQuotes"); 90 90 this.closingQuote = this._lc("ClosingSingleQuote"); 91 91 this.closingQuotes = this._lc("ClosingDoubleQuotes"); 92 92 this.openingQuote = this._lc("OpeningSingleQuote"); 93 }94 93 } 94 95 95 if (this.openingQuotes == 'OpeningDoubleQuotes') //If nothing else is defined, English style as default 96 96 { … … 110 110 var key = String.fromCharCode(charCode); 111 111 112 if (charCode == 32) //space bar113 {114 return this.smartDash(ev)115 }116 112 if ( key == '"' || key == "'") 117 113 { 118 114 Xinha._stopEvent(ev); 119 115 return this.smartQuotes(key); 116 } 117 if (charCode == 32) //space bar 118 { 119 return this.smartReplace(ev, 2, /^\s-/, ' â', false); // space-space -> dash 120 } 121 if ( key == '.' ) // ... -> ellipsis 122 { 123 return this.smartReplace(ev, 2, /\.\./, 'âŠ', true); 120 124 } 121 125 return true; … … 185 189 } 186 190 187 SmartReplace.prototype.smart Dash = function(ev)191 SmartReplace.prototype.smartReplace = function(ev, lookback, re, replace, stopEvent) 188 192 { 189 193 var editor = this.editor; … … 193 197 if (Xinha.is_ie) 194 198 { 195 r.moveStart('character', - 2);199 r.moveStart('character', -lookback); 196 200 197 if(r.text.match(/\s-/)) 198 { 199 r.text = ' '+ String.fromCharCode(8211); 200 } 201 } 202 else 203 { 204 if (r.startOffset > 1) r.setStart(r.startContainer, r.startOffset -2); 205 206 if(r.toString().match(/^ -/)) 207 { 201 if(r.text.match(re)) 202 { 203 r.text = replace; 204 if (stopEvent) 205 { 206 Xinha._stopEvent(ev); 207 return false 208 } 209 } 210 } 211 else 212 { 213 if (r.startOffset > 1) r.setStart(r.startContainer, r.startOffset -lookback); 214 215 if(r.toString().match(re)) 216 { 217 this.editor.insertNodeAtSelection(document.createTextNode(replace)); 208 218 r.deleteContents(); 209 this.editor.insertNodeAtSelection(document.createTextNode(' ' + String.fromCharCode(8211))); 219 r.collapse(true); 220 if (stopEvent) 221 { 222 Xinha._stopEvent(ev); 223 return false 224 } 210 225 } 211 226 editor.getSelection().collapseToEnd(); … … 213 228 return true; 214 229 } 230 215 231 216 232 SmartReplace.prototype.replaceAll = function() … … 298 314 if( !this._dialog) 299 315 { 300 this._dialog = new SmartReplace.Dialog(this);316 this._dialog = new SmartReplace.Dialog(this); 301 317 } 302 318 }; … … 324 340 if(this.html == false) 325 341 { 326 Xinha._getback(_editor_url + 'plugins/SmartReplace/dialog.html', function(getback) { pluginDialogObject.html = getback; pluginDialogObject._prepareDialog(); });327 return;342 Xinha._getback(_editor_url + 'plugins/SmartReplace/dialog.html', function(getback) { pluginDialogObject.html = getback; pluginDialogObject._prepareDialog(); }); 343 return; 328 344 } 329 345 … … 340 356 if(!this.ready) 341 357 { 342 var pluginDialogObject = this;343 window.setTimeout(function() {pluginDialogObject.show(inputs,ok,cancel);},100);344 return;358 var pluginDialogObject = this; 359 window.setTimeout(function() {pluginDialogObject.show(inputs,ok,cancel);},100); 360 return; 345 361 } 346 362 … … 350 366 if(ok) 351 367 { 352 this.dialog.getElementById('ok').onclick = ok;368 this.dialog.getElementById('ok').onclick = ok; 353 369 } 354 370 else 355 371 { 356 this.dialog.getElementById('ok').onclick = function() {pluginDialogObject.hide();};372 this.dialog.getElementById('ok').onclick = function() {pluginDialogObject.hide();}; 357 373 } 358 374 359 375 if(cancel) 360 376 { 361 this.dialog.getElementById('cancel').onclick = cancel;377 this.dialog.getElementById('cancel').onclick = cancel; 362 378 } 363 379 else 364 380 { 365 this.dialog.getElementById('cancel').onclick = function() { pluginDialogObject.hide()};381 this.dialog.getElementById('cancel').onclick = function() { pluginDialogObject.hide()}; 366 382 } 367 383
