19 lines
8.3 KiB
JavaScript
19 lines
8.3 KiB
JavaScript
(function(b){function g(a,c){this.T(a,c)}b.B.document=function(){var a=this.P(0);if(a.nodeName.toLowerCase()=="iframe")return a.contentWindow.document;return this};b.B.A=function(){var a=this.P(0);return a.contentWindow.document.selection?a.contentWindow.document.selection.createRange().text:a.contentWindow.getSelection().toString()};b.B.Va=function(a){if(arguments.length>0&&arguments[0].constructor==String){for(var c=arguments[0].toString(),e=[],d=1;d<arguments.length;d++)e[d-1]=arguments[d];return c in
|
|
g?this.O(function(){b.data(this,"wysiwyg").designMode();g[c].apply(this,e)}):this}d={};if(a&&a.g){d=a.g;delete a.g}a=b.extend({r:'<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">STYLE_SHEET</head><body style="margin: 0px;">INITIAL_CONTENT</body></html>',d:{},ca:false,u:true,
|
|
X:true,L:true,g:{},m:{}},a);a.m=b.extend(true,a.m,g.F);a.g=b.extend(true,a.g,g.G);for(var f in d)if(f in a.g)b.extend(a.g[f],d[f]);else a.g[f]=d[f];return this.O(function(){new g(this,a)})};b.extend(g,{V:function(a,c){var e=b.data(this,"wysiwyg");if(e.constructor==g&&a&&a.length>0){b.f.i&&e.focus();if(c){e.c.execCommand("insertImage",false,"#jwysiwyg#");if(e=e.C("img","src","#jwysiwyg#")){e.src=a;for(var d in c)e.setAttribute(d,c[d])}}else e.c.execCommand("insertImage",false,a)}},N:function(a){var c=
|
|
b.data(this,"wysiwyg");if(c.constructor==g&&a&&a.length>0)if(b(c.h).A().length>0){b.f.i&&c.focus();c.c.execCommand("unlink",false,[]);c.c.execCommand("createLink",false,a)}else c.options.m.s&&alert(c.options.m.s)},pa:function(a){var c=b.data(this,"wysiwyg");if(c.constructor==g&&a&&a.length>0){c.focus();if(b.f.i){c.c.execCommand("insertImage",false,"#jwysiwyg#");(c=c.C("img","src","#jwysiwyg#"))&&b(c).Ea(a)}else c.c.execCommand("insertHTML",false,a)}},o:function(a){var c=b.data(this,"wysiwyg");c.o(a);
|
|
c.k()},clear:function(){var a=b.data(this,"wysiwyg");a.o("");a.k()},F:{s:"select the text you wish to link"},G:{bold:{a:true,e:["b","strong"],d:{fontWeight:"bold"},b:"Bold"},sa:{a:true,e:["i","em"],d:{fontStyle:"italic"},b:"Italic"},Qa:{a:true,e:["s","strike"],d:{textDecoration:"line-through"},b:"Strike-through"},Ta:{a:true,e:["u"],d:{textDecoration:"underline"},b:"Underline"},Fa:{a:true,separator:true},va:{a:true,d:{textAlign:"left"},b:"Justify Left"},ta:{a:true,e:["center"],d:{textAlign:"center"},
|
|
b:"Justify Center"},wa:{a:true,d:{textAlign:"right"},b:"Justify Right"},ua:{a:true,d:{textAlign:"justify"},b:"Justify Full"},Ga:{a:true,separator:true},ma:{a:true,b:"Indent"},za:{a:true,b:"Outdent"},Ha:{a:false,separator:true},Ra:{a:true,e:["sub"],b:"Subscript"},Sa:{a:true,e:["sup"],b:"Superscript"},Ia:{a:true,separator:true},Ua:{a:true,b:"Undo"},Ba:{a:true,b:"Redo"},Ja:{a:true,separator:true},qa:{a:true,e:["ol"],b:"Insert Ordered List"},ra:{a:true,e:["ul"],b:"Insert Unordered List"},oa:{a:true,e:["hr"],
|
|
b:"Insert Horizontal Rule"},Ka:{separator:true},N:{a:true,exec:function(){if(b(this.h).A().length>0)if(b.f.i){this.focus();this.c.execCommand("createLink",true,null)}else{var a=prompt("URL","http://");if(a&&a.length>0){this.c.execCommand("unlink",false,[]);this.c.execCommand("createLink",false,a)}}else this.options.m.s&&alert(this.options.m.s)},e:["a"],b:"Create link"},V:{a:true,exec:function(){if(b.f.i){this.focus();this.c.execCommand("insertImage",true,null)}else{var a=prompt("URL","http://");a&&
|
|
a.length>0&&this.c.execCommand("insertImage",false,a)}},e:["img"],b:"Insert image"},La:{separator:true},fa:{a:b.f.n,className:"h1",j:"heading",arguments:["h1"],e:["h1"],b:"Header 1"},ha:{a:b.f.n,className:"h2",j:"heading",arguments:["h2"],e:["h2"],b:"Header 2"},ja:{a:b.f.n,className:"h3",j:"heading",arguments:["h3"],e:["h3"],b:"Header 3"},ea:{a:!b.f.n,className:"h1",j:"formatBlock",arguments:["<H1>"],e:["h1"],b:"Header 1"},ga:{a:!b.f.n,className:"h2",j:"formatBlock",arguments:["<H2>"],e:["h2"],b:"Header 2"},
|
|
ia:{a:!b.f.n,className:"h3",j:"formatBlock",arguments:["<H3>"],e:["h3"],b:"Header 3"},Ma:{a:false,separator:true},ba:{a:false,b:"Cut"},copy:{a:false,b:"Copy"},Aa:{a:false,b:"Paste"},Na:{separator:false},la:{a:false,e:["big"],b:"Increase font size"},da:{a:false,e:["small"],b:"Decrease font size"},Oa:{separator:true},r:{a:false,exec:function(){if(this.z){this.o(b(this.l).D());b(this.l).S()}else{this.k();b(this.l).Pa()}this.z=!this.z},b:"View source code"},Da:{a:true,exec:function(){b.f.i&&this.focus();
|
|
this.c.execCommand("removeFormat",false,[]);this.c.execCommand("unlink",false,[])},b:"Remove formatting"}}});b.extend(g.prototype,{l:null,options:{},element:null,h:null,focus:function(){b(this.c.body).focus()},T:function(a,c){var e=this;this.h=a;this.options=c||{};b.data(a,"wysiwyg",this);c=a.width||a.clientWidth||0;var d=a.height||a.clientHeight||0;if(a.nodeName.toLowerCase()=="textarea"){this.l=a;if(c==0&&a.cols)c=a.cols*8+21;if(d==0&&a.rows)d=a.rows*16+16;this.h=b('<iframe src="javascript:false;"></iframe>').d({minHeight:(d-
|
|
6).toString()+"px",width:(c-8).toString()+"px"}).p("id",b(a).p("id")+"IFrame").p("frameborder","0");this.h.p("tabindex",b(a).p("tabindex"));b.f.i&&this.h.d("height",d.toString()+"px")}var f=this.q=b('<ul role="menu" class="panel"></ul>');this.H();this.element=b("<div></div>").d({width:c>0?c.toString()+"px":"100%"}).t("wysiwyg").append(f).append(b("<div><!-- --\></div>").d({clear:"both"})).append(this.h);b(a).S().Z(this.element);this.z=false;this.na=d-8;this.w=b(a).D();this.U();this.w.length===0&&
|
|
this.o("");a=b(a).aa("form");this.options.u&&a.submit(function(){e.k()});a.$("reset",function(){e.o(e.w);e.k()})},U:function(){var a=this,c="";if(this.options.d&&this.options.d.constructor==String)c='<link rel="stylesheet" type="text/css" media="screen" href="'+this.options.d+'" />';this.c=b(this.h).document();this.v=false;try{this.c.designMode="on";this.v=true}catch(e){b(this.c).focus(function(){a.designMode()})}this.c.open();this.c.write(this.options.r.replace(/INITIAL_CONTENT/,function(){return a.w}).replace(/STYLE_SHEET/,
|
|
function(){return c}));this.c.close();this.c.contentEditable="true";b.f.i&&setTimeout(function(){b(a.c.body).d("border","none")},0);b(this.c).click(function(d){a.M(d.target?d.target:d.srcElement)});b(this.l).focus(function(){b.f.i||a.focus()});this.options.u&&b(this.c).W(function(){a.k()}).xa(function(){a.k()}).ya(function(){a.k()});this.options.d&&setTimeout(function(){a.options.d.constructor!=String&&b(a.c).find("body").d(a.options.d)},0);b(this.c).W(function(d){if(b.f.i&&a.options.L&&d.keyCode==
|
|
13){d=a.R();d.pasteHTML("<br />");d.collapse(false);d.select();return false}return true})},designMode:function(){if(!this.v)try{this.c.designMode="on";this.v=true}catch(a){}},getSelection:function(){return window.getSelection?window.getSelection():document.selection},R:function(){var a=this.getSelection();if(!a)return null;return a.rangeCount>0?a.getRangeAt(0):a.createRange()},Q:function(){return b(b(this.h).document()).find("body").r()},o:function(a){b(b(this.h).document()).find("body").r(a)},k:function(){if(this.l){var a=
|
|
this.Q();if(this.options.X)a=a.substr(-4)=="<br>"?a.substr(0,a.length-4):a;b(this.l).D(a)}},Y:function(){if(b.f.n)try{this.c.execCommand("styleWithCSS",false,false)}catch(a){try{this.c.execCommand("useCSS",false,true)}catch(c){}}},I:function(a,c,e,d,f){var h=this;c=c||[];b("<li></li>").append(b('<a role="menuitem" tabindex="-1" href="javascript:;">'+(e||a)+"</a>").t(e||a).p("title",f)).click(function(){if(d)d.apply(h);else{h.Y();h.c.execCommand(a,false,c)}h.options.u&&h.k()}).K(this.q)},J:function(){b('<li role="separator" class="separator"></li>').K(this.q)},
|
|
H:function(){for(var a in this.options.g){var c=this.options.g[a];if(c.separator)c.a!==false&&this.J();else if(c.a)this.I(c.j||a,c.arguments||[],c.className||c.j||a||"empty",c.exec,c.b||c.j||a||"")}},M:function(a){for(var c in this.options.g){var e=this.options.g[c],d=e.className||e.j||c||"empty";b("."+d,this.q).Ca("active");if(e.e){var f=a;do{if(f.nodeType!=1)break;b.ka(f.tagName.toLowerCase(),e.e)!=-1&&b("."+d,this.q).t("active")}while(f=f.parentNode)}if(e.d){f=b(a);do{if(f[0].nodeType!=1)break;
|
|
for(var h in e.d)f.d(h).toString().toLowerCase()==e.d[h]&&b("."+d,this.q).t("active")}while(f=f.parent())}}},C:function(a,c,e){a=this.c.getElementsByTagName(a);for(var d=0;d<a.length;d++){var f=a[d].getAttribute(c);if(b.f.i)f=f.substr(f.length-e.length);if(f==e)return a[d]}return false}})})(jQuery);
|
|
|