composition.js

来自「极限OA开源系统」· JavaScript 代码 · 共 602 行 · 第 1/2 页

JS
602
字号
}

function format1(what,opt)
{
  if (opt=="removeFormat")
  {
    what=opt;
    opt=null;
  }

  if (opt==null) Composition.document.execCommand(what);
  else Composition.document.execCommand(what,"",opt);

  pureText = false;
  Composition.focus();
}

function format(what,opt)
{
  if (!validateMode()) return;

  format1(what,opt);
}

//Formats text in composition.
function format(what,opt) {
  if (!validateMode()) return;
  
  if (opt=="removeFormat") {
    what=opt;
    opt=null;
  }

  if (opt==null) Composition.document.execCommand(what);
  else {
    Composition.document.execCommand(what,"",opt);
  }
  pureText = false;
  Composition.focus();
}

function doSelectClick(str, el) {
	var Index = el.selectedIndex;
	if (Index != 0){
		el.selectedIndex = 0;
		if (el.id == "specialtype")
			specialtype(el.options[Index].value);
		else
			format(str,el.options[Index].value);
	}
}

var bIsIE5 = navigator.userAgent.indexOf("IE 5")  > -1;
var bIsIE6 = navigator.userAgent.indexOf("IE 6")  > -1;

function selectRange(){
	edit = Composition.document.selection.createRange();
	RangeType =  Composition.document.selection.type;
}

function specialtype(Mark){
	var strHTML;
	if (bIsIE5||bIsIE6) selectRange();	
	if (RangeType == "Text"){
		strHTML = "<" + Mark + ">" + edit.text + "</" + Mark + ">"; 
		edit.pasteHTML(strHTML);
		Composition.focus();
		edit.select();
	}		
}

//Finds and returns an element.
function getEl(sTag,start) {
  while ((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
  return start;
}

function createLink() {
  if (!validateMode()) return;
  
  var isA = getEl("A",Composition.document.selection.createRange().parentElement());
  var str=prompt("键入超级链接地址 (e.g. http://www.xsp.cn):", isA ? isA.href : "http:\/\/");
  
  if ((str!=null) && (str!="http://")) {
    if (Composition.document.selection.type=="None") {
      var sel=Composition.document.selection.createRange();
      sel.pasteHTML("<A HREF=\""+str+"\">"+str+"</A> ");
      sel.select();
    }
    else format("CreateLink",str);
  }
  else Composition.focus();
}

function createImage() {
  if (!validateMode()) return;
  
  var isA = getEl("A",Composition.document.selection.createRange().parentElement());
  var str=prompt("键入图象的绝对路径 (e.g. http://www.xsp.cn/images/blank.gif):", isA ? isA.href : "http:\/\/");
  
  if ((str!=null) && (str!="http://")) {
    if (Composition.document.selection.type=="None") {
      var sel=Composition.document.selection.createRange();
      sel.pasteHTML("<img src=\""+str+"\">");
      sel.select();
    }
    else format("CreateImage",str);
  }
  else Composition.focus();
}

function insertImage(){//插入图片
  if (!validateMode()) return;
  var objForm=document.forms(0);

  var sURL="./images.php";
  //sURL+="?username="+user;
  //sURL+="&imageflag="+imgFlag;
  openWindow("",430,500,sURL)
}

//弹出窗口函数
function openWindow(name,ww,wh,url){
    var wl=(screen.width) ? (screen.width-ww)/2 : 220;
    var wt=(screen.height) ? (screen.height-wh)/2 : 220;
    var features="resizable=no,scrollbars=no,top="+wt+",left="+wl+",height="+wh+",width="+ww+",status=yes,toolbar=no,menubar=no,location=no";
    window.open(url,name,features);
}

//Sets the background color.
function backColor() {
  if (!validateMode()) return;
  var arr = showModalDialog("selcolor.html", "", "font-family:Verdana; font-size:9pt; dialogWidth:30em; dialogHeight:35em");
  if (arr != null) format('backcolor', arr);
  else Composition.focus()
}

//use UserDialog
function UserDialog(what)
{
  if (!validateMode()) return;
  
  if (Composition.document.selection.type=="None")
    Composition.focus();
  Composition.document.execCommand(what, true);

  pureText = false;
  Composition.focus();
}

//Sets the text color.
function foreColor()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("document/selcolor.html", "", "dialogWidth:18em; dialogHeight:16em; status:0");
  if (arr != null) format('forecolor', arr);
  else Composition.focus();
}

function fortable()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("document/table.html", "", "dialogWidth:300px; dialogHeight:170px; status:0");
  
  if (arr != null){
  var ss;
  ss=arr.split("*")
  row=ss[0];
  col=ss[1];
  color=ss[2];
  var string;
  string="<table border=0 cellpadding='0' cellspacing='1' bgcolor='"+color+"'>";
  for(i=1;i<=row;i++){
    string=string+"<tr bgcolor='#ffffff'>";
    for(j=1;j<=col;j++){
      string=string+"<td>&nbsp;&nbsp;</td>";
    }
    string=string+"</tr>";
  }
  string=string+"</table>";
  content=Composition.document.body.innerHTML;
  content=content+string;
   Composition.document.body.innerHTML=content;
  }
  else Composition.focus();
}
function cleanHtml() {
  var fonts = Composition.document.body.all.tags("FONT");
  var curr;
  for (var i = fonts.length - 1; i >= 0; i--) {
    curr = fonts[i];
    if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;
  }
}

function getPureHtml() {
  var str = "";
  var paras = Composition.document.body.all.tags("P");
  if (paras.length > 0) {
    for (var i=paras.length-1; i >= 0; i--) str = paras[i].innerHTML + "\n" + str;
  } else {
    str = Composition.document.body.innerHTML;
  }
  return str;
}

//模式切换:DESIGN<->HTML<->PREVIEW
function swapModes(Mode) {
	switch(Mode){
		case 1:	//普通
			if (viewMode == "HTML"){
				Composition.document.body.innerHTML = Composition.document.body.innerText;
				Composition.document.body.style.fontFamily = "";
				Composition.document.body.style.fontSize ="";
			}else{
				initHTML = Composition.document.body.innerHTML;
				initEditor();
			}
			viewMode = "DESIGN";
			break;	
		case 2:	//HTML
			if (viewMode == "PREVIEW"){
				initHTML = Composition.document.body.innerHTML;
				initEditor();
			}	
			Composition.document.body.innerText = Composition.document.body.innerHTML;
			Composition.document.body.style.fontFamily = "Verdana";
			Composition.document.body.style.fontSize = "9pt";
			viewMode = "HTML";
			break;
		case 3:	//预览
			var strHTML = "";
			if(viewMode == "HTML"){
				strHTML = Composition.document.body.innerText;
				Composition.document.body.style.fontFamily = "";
				Composition.document.body.style.fontSize ="";				
			}else{
				strHTML = Composition.document.body.innerHTML;				
			}			
			Composition.document.designMode="Off";
			Composition.document.open();
			Composition.document.write(strHTML);
			Composition.document.close();
			if(Composition.document.styleSheets.length == 0){
				Composition.document.createStyleSheet();
				var oSS = Composition.document.styleSheets[0];
				oSS.addRule("IMG","border: 0");
				oSS.addRule("TABLE","font-size: 9pt;");
				oSS.addRule("BODY","font-size: 9pt;");
			}
			viewMode = "PREVIEW";
			break;
	}
	Composition.focus();
}

function initEditor() {
	Composition.document.designMode="On";
	Composition.document.open();
	Composition.document.write(initHTML);
	Composition.document.close();
	
  initHTML = "";
	if(Composition.document.styleSheets.length == 0){
		Composition.document.createStyleSheet();
		var oSS = Composition.document.styleSheets[0];
		oSS.addRule("IMG","border: 0");
		oSS.addRule("TABLE","font-size: 9pt;");
		oSS.addRule("BODY","font-size: 9pt");
	}	
  Composition.focus();
}

function switchstatus(flag){
  swapModes(flag);

  for(var i=1;i<4;i++){
    document.all["status" + i].style.display = "none";
  }
  document.all["status" + flag].style.display = "block";
}
// End:


//打开图片列表窗口
function openImageList(href) {
    var newwin=window.open(href,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=240,height=400");
    return;
}

//接收返回的图片代码,并插入图片
function receive9(which) {
Format1('pic','',which);
}


function Popupnew(href) {
	window.open(href, "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,border=0,width=269,height=230");
	
}	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?