?? dialog.js
字號:
<Script Language=Javascript>
var BrowserInfo = new Object() ;
BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;
BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1] ;
BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 && BrowserInfo.MinorVer >= 5 ) ;
var btnDatas = new Array();
var bInitialized = false;
function document.onreadystatechange()
{
if (document.readyState!="complete") return;
if (bInitialized) return;
bInitialized = true;
var i, s, curr;
if (objNowForm.ContentFlag.value=="0") {
objNowForm.ContentEdit.value = objContent.value;
objNowForm.ContentLoad.value = objContent.value;
objNowForm.ContentFlag.value = "1";
}
ifrContent.document.designMode="On";
ifrContent.document.open();
ifrContent.document.write(bodyTag+objNowForm.ContentEdit.value)
ifrContent.document.close();
setLinkedField() ;
ifrContent.document.body.onpaste = onPaste ;
ifrContent.focus();
}
function setLinkedField() {
if (! objContent) return ;
var oForm = objContent.form ;
if (!oForm) return ;
oForm.attachEvent("onsubmit", AttachSubmit) ;
if (! oForm.submitEditor) oForm.submitEditor = new Array() ;
oForm.submitEditor[oForm.submitEditor.length] = AttachSubmit ;
if (! oForm.originalSubmit) {
oForm.originalSubmit = oForm.submit ;
oForm.submit = function() {
if (this.submitEditor) {
for (var i = 0 ; i < this.submitEditor.length ; i++) {
this.submitEditor[i]() ;
}
}
this.originalSubmit() ;
}
}
oForm.attachEvent("onreset", AttachReset) ;
if (! oForm.resetEditor) oForm.resetEditor = new Array() ;
oForm.resetEditor[oForm.resetEditor.length] = AttachReset ;
if (! oForm.originalReset) {
oForm.originalReset = oForm.reset ;
oForm.reset = function() {
if (this.resetEditor) {
for (var i = 0 ; i < this.resetEditor.length ; i++) {
this.resetEditor[i]() ;
}
}
this.originalReset() ;
}
}
}
function AttachSubmit() {
if (!bEditMode) setMode('EDIT');
objNowForm.ContentEdit.value = getHTML();
objContent.value = objNowForm.ContentEdit.value;
var oForm = objContent.form ;
if (!oForm) return ;
for (var i=1;i<document.getElementsByName(sContentName).length;i++) {
document.getElementsByName(sContentName)[i].value = "";
}
}
function AttachReset() {
if (!bEditMode) setMode('EDIT');
if(bEditMode){
ifrContent.document.body.innerHTML = objNowForm.ContentLoad.value;
}else{
ifrContent.document.body.innerText = objNowForm.ContentLoad.value;
}
}
function onPaste() {
if (config.AutoDetectPasteFromWord && BrowserInfo.IsIE55OrMore) {
var sHTML = GetClipboardHTML() ;
var re = /<\w[^>]* class="?MsoNormal"?/gi ;
if ( re.test( sHTML ) )
{
if ( confirm( "你要粘貼的內容好象是從Word中拷出來的,是否要先清除Word格式再粘貼?" ) )
{
cleanAndPaste( sHTML ) ;
return false ;
}
}
}
else
return true ;
}
function GetClipboardHTML() {
var oDiv = document.getElementById("divTemp")
oDiv.innerHTML = "" ;
var oTextRange = document.body.createTextRange() ;
oTextRange.moveToElementText(oDiv) ;
oTextRange.execCommand("Paste") ;
var sData = oDiv.innerHTML ;
oDiv.innerHTML = "" ;
return sData ;
}
function cleanAndPaste( html ) {
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
html = html.replace(/ /, " " );
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
html = html.replace( re, "<span$2</span>" ) ;
insertHTML( html ) ;
}
function insertHTML(html) {
if (!validateMode()) return;
if (ifrContent.document.selection.type.toLowerCase() != "none")
ifrContent.document.selection.clear() ;
ifrContent.document.selection.createRange().pasteHTML(html) ;
}
function getHTML() {
if(bEditMode){
return ifrContent.document.body.innerHTML;
}else{
return ifrContent.document.body.innerText;
}
}
function PasteWord(){
if (!validateMode()) return;
ifrContent.focus();
if (BrowserInfo.IsIE55OrMore)
cleanAndPaste( GetClipboardHTML() ) ;
else if ( confirm( "此功能要求IE5.5版本以上,你當前的瀏覽器不支持,是否按常規粘貼進行?" ) )
format("paste") ;
ifrContent.focus();
}
function PasteText(){
if (!validateMode()) return;
ifrContent.focus();
var sText = HTMLEncode( clipboardData.getData("Text") ) ;
insertHTML(sText);
ifrContent.focus();
}
function validateMode() {
if (bEditMode) return true;
alert("需轉換為編輯狀態后再使用此功能!");
ifrContent.focus();
return false;
}
function format(what,opt) {
if (!validateMode()) return;
ifrContent.focus();
if (opt=="RemoveFormat") {
what=opt;
opt=null;
}
if (opt==null) ifrContent.document.execCommand(what);
else ifrContent.document.execCommand(what,"",opt);
ifrContent.focus();
}
function setMode(NewMode){
document.onreadystatechange();
if (NewMode!=sCurrMode){
document.all["ifrContent_CODE"].style.display = "none";
document.all["ifrContent_EDIT"].style.display = "none";
document.all["ifrContent_VIEW"].style.display = "none";
document.all["ifrContent_"+NewMode].style.display = "block";
switch (NewMode){
case "CODE":
if (ifrContent.document.designMode=="On") {
ifrContent.document.body.innerText=ifrContent.document.body.innerHTML;
}else {
var temp=ifrContent.document.body.innerHTML;
ifrContent.document.designMode="On";
ifrContent.document.open();
ifrContent.document.write(bodyTag);
ifrContent.document.body.innerText=temp;
ifrContent.document.close();
temp=null;
}
bEditMode=false;
break;
case "EDIT":
ifrContent.document.body.disabled=false;
if (ifrContent.document.designMode=="On") {
ifrContent.document.body.innerHTML=ifrContent.document.body.innerText;
}else {
var temp=ifrContent.document.body.innerHTML;
ifrContent.document.designMode="On";
ifrContent.document.open();
ifrContent.document.write(bodyTag);
ifrContent.document.body.innerHTML=temp;
ifrContent.document.close();
temp=null;
}
bEditMode=true;
break;
case "VIEW":
var temp;
if(bEditMode){
temp = ifrContent.document.body.innerHTML;
}else{
temp = ifrContent.document.body.innerText;
}
ifrContent.document.designMode="off";
ifrContent.document.open();
ifrContent.document.write(bodyTag+temp);
ifrContent.document.close();
bEditMode=false;
break;
}
sCurrMode=NewMode;
}
ifrContent.focus();
}
function ShowDialog(url, width, height, optValidate) {
if (optValidate) {
if (!validateMode()) return;
}
ifrContent.focus();
var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
ifrContent.focus();
}
function HTMLEncode(text){
text = text.replace(/&/g, "&") ;
text = text.replace(/"/g, """) ;
text = text.replace(/</g, "<") ;
text = text.replace(/>/g, ">") ;
text = text.replace(/'/g, "’") ;
text = text.replace(/\ /g," ");
text = text.replace(/\n/g,"<br>");
text = text.replace(/\t/g," ");
return text;
}
function insert(what) {
if (!validateMode()) return;
ifrContent.focus();
var sel = ifrContent.document.selection.createRange();
switch(what){
case "nowdate":
var d = new Date();
insertHTML(d.toLocaleDateString());
break;
case "nowtime":
var d = new Date();
insertHTML(d.toLocaleTimeString());
break;
case "br":
insertHTML("<br>")
break;
case "code":
insertHTML('[CODE]'+HTMLEncode(sel.text)+'[/CODE]');
break;
case "quote":
insertHTML('[QUOTE]'+HTMLEncode(sel.text)+'[/QUOTE]');
break;
case "move":
insertHTML('[MOVE]'+HTMLEncode(sel.text)+'[/MOVE]');
break;
default:
insertHTML("[face=" + what + ']' + sel.text + "[/face]");
break;
}
sel=null;
}
var bEditMode=true;
var sCurrMode = "EDIT";
var bodyTag = "<head><style type=\"text/css\">body,a,table,div,span,td,th,input,select{font-size:9pt;font-family:\"宋體,Verdana,Arial\";Color:#000000;}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE>" ;
var sContentName = "Form_Content" ;
var objContent = document.getElementsByName(sContentName)[0];
var objNowForm = document.forms[0];
var config = new Object() ;
config.Version = "1.1.3" ;
config.ReleaseDate = "2003-12-11" ;
config.StyleName = "standard";
config.AutoDetectPasteFromWord = true;
function InsDialog(a,b,c)
{
document.write("<td width=23 align=center><img src=../images/null.gif width=23 height=2<br><span TITLE=\"" + a + "\" onclick=\"" + b + "\" class=GMI><IMG SRC=Edit/pic/" + c + ".gif width=22 height=22 class=Ico onclick=\"this.style.backgroundColor='#AAAAAA';\" onmouseover=\"this.style.backgroundColor='#CCCCCC';\" onmouseout=\"this.style.backgroundColor='';\"></span></td>");
}
function InsBlank()
{
document.write("<td><img src=edit/pic/line2.gif width=10 height=16 align=absmiddle></td><td>");
}
</Script>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -