<html>
<head>
<title>Wysiwyg - FF/IE build-in editor</title>
<style type="text/css">
.edit	{height:100%; width:100%}
#xx	{min-height:6em;}
</style>

<script type="text/javascript">
function objGet(x,doc)	{var d=(doc)?doc:document; return (d.getElementById?d.getElementById(x):d.all?d.all[x]:d.layers?d.layers[x]:null);}
var moz  = (navigator.appName=="Netscape");
var ie   = (document.all);
//var ns   = (d.layers);
//var op   = (window.opera);

function repl(str)	{return str.replace(/\n(\<\w)|(\<\w)/gi,"\n$1$2");}

function editXdocFF()	{return objGet('wwwFF').contentWindow.document;}
function editXobjFF()	{return objGet('wwwFF').contentWindow;}
function editXFF(prikaz){editXobj().focus(); var x = (prikaz=="CreateLink") ? prompt("Enter a URL:", "http://") : null; editXdoc().execCommand(prikaz,false,x); editXobj().focus();}
function text2htmlFF()	{editXdoc().open(); editXdoc().write(objGet('txt').value); editXdoc().close();}
function html2textFF()	{objGet('txt').value = repl(editXdoc().getElementsByTagName("BODY")[0].innerHTML);}

function editXdocIE()	{return document;}
function editXobjIE()	{return objGet('wwwIE');}
function editXIE(prikaz){editXobj().focus(); editXdoc().execCommand(prikaz);}
function text2htmlIE()	{editXobj().innerHTML = objGet('txt').value;}
function html2textIE()	{objGet('txt').value = repl(editXobj().innerHTML);}

var editX     = moz ? editXFF     : editXIE;
var editXdoc  = moz ? editXdocFF  : editXdocIE;
var editXobj  = moz ? editXobjFF  : editXobjIE;
var html2text = moz ? html2textFF : html2textIE;
var text2html = moz ? text2htmlFF : text2htmlIE;

var myScreen = [0,0,0,0,0];

function fullscreen()
{
var oo, nn;
oo = objGet('xx');
nn = (navigator.appName=="Netscape");
if (myScreen[0]===0)
	{
	myScreen[0] = 1;
	myScreen[1] = parseInt(oo.offsetWidth);
	myScreen[2] = parseInt(oo.offsetHeight);
	myScreen[3] = parseInt(nn ? window.innerWidth  : document.body.offsetWidth);
	myScreen[4] = parseInt(nn ? window.innerHeight : document.body.offsetHeight);
	oo.style.position  = 'absolute';
	oo.style.zIndex  = 10;
	oo.style.top  = '0';
	oo.style.backgroundColor = '#ffffff';
	oo.style.width  = myScreen[3] + 'px';
	oo.style.height = myScreen[4] + 'px';
	}
else	{
	myScreen[0] = 0;
	oo.style.position  = 'static';
	oo.style.zIndex  = 0;
	oo.style.top  = '';
	oo.style.width  = myScreen[1] + 'px';
	oo.style.height = myScreen[2] + 'px';
	}
}

function cleanPattern(name,type)
{
var pat = '';
switch (type)
  {
  case 3 : pat = '<[a-z]\\s.*?>'; break;
  case 2 : pat = '\\s'+name+'[\\s]*\=[\\s]*(?:(?:["\'].*?["\'])|(?:.*?(?=[\\s\>])))'; break;
  case 1 : pat = '<'+name+'.*?>'; break;
  default: pat = '<'+name+'.*?>(.*?)<\/'+name+'>'; break;
  }
reg = new RegExp(pat,'gi');
return reg
//alert(reg.source)
}
/*
<table class="MsoTableGrid" style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;
 mso-yfti-tbllook:1184;mso-padding-alt:0cm 5.4pt 0cm 5.4pt" border="1" cellpadding="0" cellspacing="0

<table$1$1 windowtext="" .5pt;="" mso-yfti-tbllook:1184;mso-padding-alt:0cm="" 5.4pt="" 0cm="" 5.4pt"="" border="1" cellpadding="0" cellspacing="0">

*/
 


function cleanWord()
{
var str,f,ch,i,j,params,tags;
  f   = document.form;
  str = f.htmltext.value;
  check = {
    'clbold'     : [0,['b','strong']],
    'clcursive'  : [0,['i','em']],
    'clunderline': [0,['u']],
    'clparams'   : [3,['']],
    'clborder'   : [2,['border']],
    'clsize'     : [2,['width','height']],
    'clpad'      : [2,['cellSpacing','cellPadding']],
    'clalign'    : [2,['align','valign']],
    };
  remove = [
    ['p',0],['span',0],['font',0],
    ['style',2],['class',2],['face',2],['size',2]
    ];
/*
  for (i in check)
    {
    if (f[i] && !f[i].checked)
      {
      for (j in check[i][1])
        {
        remove[remove.length] = [check[i][1][j],check[i][0]];
        }
      }
    }
*/
  for (i in remove)
    {
    str = str.replace(cleanPattern(remove[i][0],remove[i][1]),'$1');
    }
  str = str.replace(/<\?xml.*?>/gi,"");
  str = str.replace(/<\/[a-z]:.*?>/gi,"");
  str = str.replace(/<!--.*?-->/gi,"");
  f.htmltext.value = str;
  text2html();
}

function init()
{
editXdoc().open();
editXdoc().write("");
editXdoc().close();

(moz ? objGet("wwwIE") : objGet("wwwFF")).style.display="none";
if (moz) {editXdoc().designMode="on";}		//iframe.document
else	 {editXobj().contentEditable="true";}	//div
text2html();
editXobj().focus();
}
</script>
</head>

<body>

<form action="#" name="form">
  <fieldset><legend>HTML (klikni)</legend>
  <table><tr><td>
    <textarea id="txt" rows="10" cols="60" onfocus="html2text()" onblur="text2html()" name="htmltext"></textarea></fieldset>
  </td><td>
    <input type="button" value=" Word clean " onclick="cleanWord()"  title="Vycistit word smeti"/><br>
    <!--label><input type="checkbox" name="clparams"    checked="checked" title="Ohraničení tabulky"> vsechny parametry</label><br-->
    <label><input type="checkbox" name="clborder"    checked="checked" title="Ohraničení tabulky"> border</label><br>
    <label><input type="checkbox" name="clpad"       checked="checked" title="Odsazení buněk" > odsazení</label><br>
    <label><input type="checkbox" name="clsize"      checked="checked" title="Rozměry tabulky a buněk"> rozměry</label><br>
    <label><input type="checkbox" name="clalign"     checked="checked" title="Zarovnání prvků"> vodorovně</label><br>
    <label><input type="checkbox" name="clbold"      checked="checked" title="Tučné písmo"> <b>tučně</b></label><br>
    <label><input type="checkbox" name="clcursive"   checked="checked" title="Kurzíva"> <i>kurzíva</i></label><br>
    <label><input type="checkbox" name="clunderline" checked="checked" title="Podtržené písmo"> <u>podtrženě</u></label><br>
  </td></tr></table>

<fieldset id=xx>
<legend>WWW (klikni) </legend>
<div>
	<input type="button" value=" B "	onclick="editX('Bold')"		title="Tucne     ctrl+b alt+b" accesskey="B"/> 
	<input type="button" value=" I "	onclick="editX('Italic')"	title="Sikmo     ctrl+i alt+i" accesskey="I"/> 
	<input type="button" value=" U "	onclick="editX('Underline')"	title="Podtrzene ctrl+u alt+u" accesskey="U"/>
	<input type="button" value=" Link "	onclick="editX('CreateLink')"	title="Novy odkaz"/>
	<input type="button" value=" unLink "	onclick="editX('Unlink')"	title="Zrus odkaz"/>
	<input type="button" value=" screen "	onclick="fullscreen()"	title="Zrus odkaz"/>
<hr>
</div>
<iframe id="wwwFF" class="edit" frameborder="0"></iframe>
<div    id="wwwIE" class="edit"></div>
</fieldset>

<label>Mala pismena</label> <input type="text" onkeypress="this.value = this.value.toLowerCase();"/>

</fieldset>
</form>
<script type="text/javascript">init();/*IE*/</script>

<script type="text/javascript" src="view-source.js"></script>
</body>
</html>