1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | setToolbar: function(editorToolbar){ ... var tb = this._frToolbar = ... // Connect methods to the onClick events of the buttons. this.connect(tb.findButton, "onClick", "_find"); this.connect(tb.replaceButton, "onClick", "_replace"); this.connect(tb.replaceAllButton, "onClick", "_replaceAll"); // Make the ENTER key work for the "Find" text field. this.connect(tb.findField, "onKeyDown", function(evt){ if(evt.keyCode == dojo.keys.ENTER){ this._find(); dojo.stopEvent(evt); } }); ... } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | // An adapter function to make all browsers look the same. _findText: function(txt, isCaseSensitive, isBackwards){ if(!txt){ return false; } var ed = this.editor, win = ed.window, doc = ed.document; var found = false; if(win.find){ found = win.find(txt, isCaseSensitive, isBackwards, false, false, false, false); }else if(doc.selection){ /* IE */ // Focus to restore position/selection, // then shift to search from current position. ed.focus(); var txtRg = doc.body.createTextRange(); var curPos = doc.selection ? doc.selection.createRange() : null; if(curPos){ txtRg.setEndPoint(isBackwards ? "EndToStart" : "StartToEnd", curPos); } var flags = isCaseSensitive ? 4 : 0; if(backwards){ flags = flags | 1; } found = txtRg.findText(txt, txtRg.text.length, flags); if(found){ txtRg.select(); } } return found; }, _find: function(){ var tb = this._frToolbar; return this._findText(tb.findField.get("value"), tb.matchCase.get("value"), tb.backwards.get("value")); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | _replace: function(){ var tb = this._frToolbar; var txt = tb.findField.get("value"); if(!txt){ return false; } var repTxt = tb.replaceField.get("value") || ""; var isCaseSensitive = tb.caseSensitive.get("value"); var isBackwards = tb.backwards.get("value"); var ed = this.editor; ed.focus(); //Replace the current selected text if it matches the find field. var selected = dojo.withGlobal(ed.window, "getSelectedText", dijit._editor.selection, [null]); if(selected && (isCaseSensitive ? (selected === txt) : (selected.toLowerCase() === txt.toLowerCase()))){ ed.execCommand("inserthtml", repTxt); return true; } return false; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |