diff options
| author | hukl <contact@smyck.org> | 2009-09-09 12:07:57 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-09-09 12:07:57 +0200 |
| commit | a6292dd0fecd4482fe863ed849d126b5281b1a8a (patch) | |
| tree | 7c4c32e1a3448c5d1995a236ed01c731018da13d /public/javascripts/tiny_mce/plugins/safari | |
| parent | 83fe1b1abd7d7bb85679be3f1341e5c88db0ae83 (diff) | |
huge tiny_mce update - now using the tiny_mce jquery build which allows tiny_mce to be initialized via jquery - great!
Diffstat (limited to 'public/javascripts/tiny_mce/plugins/safari')
| -rw-r--r--[-rwxr-xr-x] | public/javascripts/tiny_mce/plugins/safari/blank.htm | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | public/javascripts/tiny_mce/plugins/safari/editor_plugin.js | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | public/javascripts/tiny_mce/plugins/safari/editor_plugin_src.js | 112 |
3 files changed, 19 insertions, 95 deletions
diff --git a/public/javascripts/tiny_mce/plugins/safari/blank.htm b/public/javascripts/tiny_mce/plugins/safari/blank.htm index 266808c..266808c 100755..100644 --- a/public/javascripts/tiny_mce/plugins/safari/blank.htm +++ b/public/javascripts/tiny_mce/plugins/safari/blank.htm | |||
diff --git a/public/javascripts/tiny_mce/plugins/safari/editor_plugin.js b/public/javascripts/tiny_mce/plugins/safari/editor_plugin.js index 4daac19..794477c 100755..100644 --- a/public/javascripts/tiny_mce/plugins/safari/editor_plugin.js +++ b/public/javascripts/tiny_mce/plugins/safari/editor_plugin.js | |||
| @@ -1 +1 @@ | |||
| (function(){var Event=tinymce.dom.Event,grep=tinymce.grep,each=tinymce.each,inArray=tinymce.inArray,isOldWebKit=tinymce.isOldWebKit;function isEmpty(d,e,f){var w,n;w=d.createTreeWalker(e,NodeFilter.SHOW_ALL,null,false);while(n=w.nextNode()){if(f){if(!f(n))return false;}if(n.nodeType==3&&n.nodeValue&&/[^\s\u00a0]+/.test(n.nodeValue))return false;if(n.nodeType==1&&/^(HR|IMG|TABLE)$/.test(n.nodeName))return false;}return true;};tinymce.create('tinymce.plugins.Safari',{init:function(ed){var t=this,dom;if(!tinymce.isWebKit)return;t.editor=ed;t.webKitFontSizes=['x-small','small','medium','large','x-large','xx-large','-webkit-xxx-large'];t.namedFontSizes=['xx-small','x-small','small','medium','large','x-large','xx-large'];ed.addCommand('CreateLink',function(u,v){var n=ed.selection.getNode(),dom=ed.dom,a;if(n&&(/^(left|right)$/i.test(dom.getStyle(n,'float',1))||/^(left|right)$/i.test(dom.getAttrib(n,'align')))){a=dom.create('a',{href:v},n.cloneNode());n.parentNode.replaceChild(a,n);ed.selection.select(a);}else ed.getDoc().execCommand("CreateLink",false,v);});ed.onPaste.add(function(ed,e){function removeStyles(e){e=e.target;if(e.nodeType==1){e.style.cssText='';each(ed.dom.select('*',e),function(e){e.style.cssText='';});}};Event.add(ed.getDoc(),'DOMNodeInserted',removeStyles);window.setTimeout(function(){Event.remove(ed.getDoc(),'DOMNodeInserted',removeStyles);},0);});ed.onKeyUp.add(function(ed,e){var h,b,r,n,s;if(e.keyCode==46||e.keyCode==8){b=ed.getBody();h=b.innerHTML;s=ed.selection;if(b.childNodes.length==1&&!/<(img|hr)/.test(h)&&tinymce.trim(h.replace(/<[^>]+>/g,'')).length==0){ed.setContent('<p><br mce_bogus="1" /></p>',{format:'raw'});n=b.firstChild;r=s.getRng();r.setStart(n,0);r.setEnd(n,0);s.setRng(r);}}});ed.addCommand('FormatBlock',function(u,v){var dom=ed.dom,e=dom.getParent(ed.selection.getNode(),dom.isBlock);if(e)dom.replace(dom.create(v),e,1);else ed.getDoc().execCommand("FormatBlock",false,v);});ed.addCommand('mceInsertContent',function(u,v){ed.getDoc().execCommand("InsertText",false,'mce_marker');ed.getBody().innerHTML=ed.getBody().innerHTML.replace(/mce_marker/g,ed.dom.processHTML(v)+'<span id="_mce_tmp">XX</span>');ed.selection.select(ed.dom.get('_mce_tmp'));ed.getDoc().execCommand("Delete",false,' ');});ed.onKeyPress.add(function(ed,e){var se,li,lic,r1,r2,n,sel,doc,be,af,pa;if(e.keyCode==13){sel=ed.selection;se=sel.getNode();if(e.shiftKey||ed.settings.force_br_newlines&&se.nodeName!='LI'){t._insertBR(ed);Event.cancel(e);}if(li=dom.getParent(se,'LI')){lic=dom.getParent(li,'OL,UL');doc=ed.getDoc();pa=dom.create('p');dom.add(pa,'br',{mce_bogus:"1"});if(isEmpty(doc,li)){if(n=dom.getParent(lic.parentNode,'LI,OL,UL'))return;n=dom.getParent(lic,'p,h1,h2,h3,h4,h5,h6,div')||lic;r1=doc.createRange();r1.setStartBefore(n);r1.setEndBefore(li);r2=doc.createRange();r2.setStartAfter(li);r2.setEndAfter(n);be=r1.cloneContents();af=r2.cloneContents();if(!isEmpty(doc,af))dom.insertAfter(af,n);dom.insertAfter(pa,n);if(!isEmpty(doc,be))dom.insertAfter(be,n);dom.remove(n);n=pa.firstChild;r1=doc.createRange();r1.setStartBefore(n);r1.setEndBefore(n);sel.setRng(r1);return Event.cancel(e);}}}});ed.onExecCommand.add(function(ed,cmd){var sel,dom,bl,bm;if(cmd=='InsertUnorderedList'||cmd=='InsertOrderedList'){sel=ed.selection;dom=ed.dom;if(bl=dom.getParent(sel.getNode(),function(n){return/^(H[1-6]|P|ADDRESS|PRE)$/.test(n.nodeName);})){bm=sel.getBookmark();dom.remove(bl,1);sel.moveToBookmark(bm);}}});ed.onClick.add(function(ed,e){e=e.target;if(e.nodeName=='IMG'){t.selElm=e;ed.selection.select(e);}else t.selElm=null;});ed.onInit.add(function(){t._fixWebKitSpans();if(isOldWebKit)t._patchSafari2x(ed);});ed.onSetContent.add(function(){dom=ed.dom;each(['strong','b','em','u','strike','sub','sup','a'],function(v){each(grep(dom.select(v)).reverse(),function(n){var nn=n.nodeName.toLowerCase(),st;if(nn=='a'){if(n.name)dom.replace(dom.create('img',{mce_name:'a',name:n.name,'class':'mceItemAnchor'}),n);return;}switch(nn){case'b':case'strong':if(nn=='b')nn='strong';st='font-weight: bold;';break;case'em':st='font-style: italic;';break;case'u':st='text-decoration: underline;';break;case'sub':st='vertical-align: sub;';break;case'sup':st='vertical-align: super;';break;case'strike':st='text-decoration: line-through;';break;}dom.replace(dom.create('span',{mce_name:nn,style:st,'class':'Apple-style-span'}),n,1);});});});ed.onPreProcess.add(function(ed,o){dom=ed.dom;each(grep(o.node.getElementsByTagName('span')).reverse(),function(n){var v,bg;if(o.get){if(dom.hasClass(n,'Apple-style-span')){bg=n.style.backgroundColor;switch(dom.getAttrib(n,'mce_name')){case'font':if(!ed.settings.convert_fonts_to_spans)dom.setAttrib(n,'style','');break;case'strong':case'em':case'sub':case'sup':dom.setAttrib(n,'style','');break;case'strike':case'u':if(!ed.settings.inline_styles)dom.setAttrib(n,'style','');else dom.setAttrib(n,'mce_name','');break;default:if(!ed.settings.inline_styles)dom.setAttrib(n,'style','');}if(bg)n.style.backgroundColor=bg;}}if(dom.hasClass(n,'mceItemRemoved'))dom.remove(n,1);});});ed.onPostProcess.add(function(ed,o){o.content=o.content.replace(/<br \/><\/(h[1-6]|div|p|address|pre)>/g,'</$1>');o.content=o.content.replace(/ id=\"undefined\"/g,'');});},getInfo:function(){return{longname:'Safari compatibility',author:'Moxiecode Systems AB',authorurl:'http://tinymce.moxiecode.com',infourl:'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/safari',version:tinymce.majorVersion+"."+tinymce.minorVersion};},_fixWebKitSpans:function(){var t=this,ed=t.editor;if(!isOldWebKit){Event.add(ed.getDoc(),'DOMNodeInserted',function(e){e=e.target;if(e&&e.nodeType==1)t._fixAppleSpan(e);});}else{ed.onExecCommand.add(function(){each(ed.dom.select('span'),function(n){t._fixAppleSpan(n);});ed.nodeChanged();});}},_fixAppleSpan:function(e){var ed=this.editor,dom=ed.dom,fz=this.webKitFontSizes,fzn=this.namedFontSizes,s=ed.settings,st,p;if(dom.getAttrib(e,'mce_fixed'))return;if(e.nodeName=='SPAN'&&e.className=='Apple-style-span'){st=e.style;if(!s.convert_fonts_to_spans){if(st.fontSize){dom.setAttrib(e,'mce_name','font');dom.setAttrib(e,'size',inArray(fz,st.fontSize)+1);}if(st.fontFamily){dom.setAttrib(e,'mce_name','font');dom.setAttrib(e,'face',st.fontFamily);}if(st.color){dom.setAttrib(e,'mce_name','font');dom.setAttrib(e,'color',dom.toHex(st.color));}if(st.backgroundColor){dom.setAttrib(e,'mce_name','font');dom.setStyle(e,'background-color',st.backgroundColor);}}else{if(st.fontSize)dom.setStyle(e,'fontSize',fzn[inArray(fz,st.fontSize)]);}if(st.fontWeight=='bold')dom.setAttrib(e,'mce_name','strong');if(st.fontStyle=='italic')dom.setAttrib(e,'mce_name','em');if(st.textDecoration=='underline')dom.setAttrib(e,'mce_name','u');if(st.textDecoration=='line-through')dom.setAttrib(e,'mce_name','strike');if(st.verticalAlign=='super')dom.setAttrib(e,'mce_name','sup');if(st.verticalAlign=='sub')dom.setAttrib(e,'mce_name','sub');dom.setAttrib(e,'mce_fixed','1');}},_patchSafari2x:function(ed){var t=this,setContent,getNode,dom=ed.dom,lr;if(ed.windowManager.onBeforeOpen){ed.windowManager.onBeforeOpen.add(function(){r=ed.selection.getRng();});}ed.selection.select=function(n){this.getSel().setBaseAndExtent(n,0,n,1);};getNode=ed.selection.getNode;ed.selection.getNode=function(){return t.selElm||getNode.call(this);};ed.selection.getRng=function(){var t=this,s=t.getSel(),d=ed.getDoc(),r,rb,ra,di;if(s.anchorNode){r=d.createRange();try{rb=d.createRange();rb.setStart(s.anchorNode,s.anchorOffset);rb.collapse(1);ra=d.createRange();ra.setStart(s.focusNode,s.focusOffset);ra.collapse(1);di=rb.compareBoundaryPoints(rb.START_TO_END,ra)<0;r.setStart(di?s.anchorNode:s.focusNode,di?s.anchorOffset:s.focusOffset);r.setEnd(di?s.focusNode:s.anchorNode,di?s.focusOffset:s.anchorOffset);lr=r;}catch(ex){}}return r||lr;};setContent=ed.selection.setContent;ed.selection.setContent=function(h,s){var r=this.getRng(),b;try{setContent.call(this,h,s);}catch(ex){b=dom.create('body');b.innerHTML=h;each(b.childNodes,function(n){r.insertNode(n.cloneNode(true));});}};},_insertBR:function(ed){var dom=ed.dom,s=ed.selection,r=s.getRng(),br;r.insertNode(br=dom.create('br'));r.setStartAfter(br);r.setEndAfter(br);s.setRng(r);if(s.getSel().focusNode==br.previousSibling){s.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'),br));s.collapse(1);}ed.getWin().scrollTo(0,dom.getPos(s.getRng().startContainer).y);}});tinymce.PluginManager.add('safari',tinymce.plugins.Safari);})(); \ No newline at end of file | (function(){var a=tinymce.dom.Event,c=tinymce.grep,d=tinymce.each,b=tinymce.inArray;function e(j,i,h){var g,k;g=j.createTreeWalker(i,NodeFilter.SHOW_ALL,null,false);while(k=g.nextNode()){if(h){if(!h(k)){return false}}if(k.nodeType==3&&k.nodeValue&&/[^\s\u00a0]+/.test(k.nodeValue)){return false}if(k.nodeType==1&&/^(HR|IMG|TABLE)$/.test(k.nodeName)){return false}}return true}tinymce.create("tinymce.plugins.Safari",{init:function(f){var g=this,h;if(!tinymce.isWebKit){return}g.editor=f;g.webKitFontSizes=["x-small","small","medium","large","x-large","xx-large","-webkit-xxx-large"];g.namedFontSizes=["xx-small","x-small","small","medium","large","x-large","xx-large"];f.addCommand("CreateLink",function(k,j){var m=f.selection.getNode(),l=f.dom,i;if(m&&(/^(left|right)$/i.test(l.getStyle(m,"float",1))||/^(left|right)$/i.test(l.getAttrib(m,"align")))){i=l.create("a",{href:j},m.cloneNode());m.parentNode.replaceChild(i,m);f.selection.select(i)}else{f.getDoc().execCommand("CreateLink",false,j)}});f.onKeyUp.add(function(j,o){var l,i,m,p,k;if(o.keyCode==46||o.keyCode==8){i=j.getBody();l=i.innerHTML;k=j.selection;if(i.childNodes.length==1&&!/<(img|hr)/.test(l)&&tinymce.trim(l.replace(/<[^>]+>/g,"")).length==0){j.setContent('<p><br mce_bogus="1" /></p>',{format:"raw"});p=i.firstChild;m=k.getRng();m.setStart(p,0);m.setEnd(p,0);k.setRng(m)}}});f.addCommand("FormatBlock",function(j,i){var l=f.dom,k=l.getParent(f.selection.getNode(),l.isBlock);if(k){l.replace(l.create(i),k,1)}else{f.getDoc().execCommand("FormatBlock",false,i)}});f.addCommand("mceInsertContent",function(j,i){f.getDoc().execCommand("InsertText",false,"mce_marker");f.getBody().innerHTML=f.getBody().innerHTML.replace(/mce_marker/g,f.dom.processHTML(i)+'<span id="_mce_tmp">XX</span>');f.selection.select(f.dom.get("_mce_tmp"));f.getDoc().execCommand("Delete",false," ")});f.onKeyPress.add(function(o,p){var q,v,r,l,j,k,i,u,m,t,s;if(p.keyCode==13){i=o.selection;q=i.getNode();if(p.shiftKey||o.settings.force_br_newlines&&q.nodeName!="LI"){g._insertBR(o);a.cancel(p)}if(v=h.getParent(q,"LI")){r=h.getParent(v,"OL,UL");u=o.getDoc();s=h.create("p");h.add(s,"br",{mce_bogus:"1"});if(e(u,v)){if(k=h.getParent(r.parentNode,"LI,OL,UL")){return}k=h.getParent(r,"p,h1,h2,h3,h4,h5,h6,div")||r;l=u.createRange();l.setStartBefore(k);l.setEndBefore(v);j=u.createRange();j.setStartAfter(v);j.setEndAfter(k);m=l.cloneContents();t=j.cloneContents();if(!e(u,t)){h.insertAfter(t,k)}h.insertAfter(s,k);if(!e(u,m)){h.insertAfter(m,k)}h.remove(k);k=s.firstChild;l=u.createRange();l.setStartBefore(k);l.setEndBefore(k);i.setRng(l);return a.cancel(p)}}}});f.onExecCommand.add(function(i,k){var j,m,n,l;if(k=="InsertUnorderedList"||k=="InsertOrderedList"){j=i.selection;m=i.dom;if(n=m.getParent(j.getNode(),function(o){return/^(H[1-6]|P|ADDRESS|PRE)$/.test(o.nodeName)})){l=j.getBookmark();m.remove(n,1);j.moveToBookmark(l)}}});f.onClick.add(function(i,j){j=j.target;if(j.nodeName=="IMG"){g.selElm=j;i.selection.select(j)}else{g.selElm=null}});f.onInit.add(function(){g._fixWebKitSpans()});f.onSetContent.add(function(){h=f.dom;d(["strong","b","em","u","strike","sub","sup","a"],function(i){d(c(h.select(i)).reverse(),function(l){var k=l.nodeName.toLowerCase(),j;if(k=="a"){if(l.name){h.replace(h.create("img",{mce_name:"a",name:l.name,"class":"mceItemAnchor"}),l)}return}switch(k){case"b":case"strong":if(k=="b"){k="strong"}j="font-weight: bold;";break;case"em":j="font-style: italic;";break;case"u":j="text-decoration: underline;";break;case"sub":j="vertical-align: sub;";break;case"sup":j="vertical-align: super;";break;case"strike":j="text-decoration: line-through;";break}h.replace(h.create("span",{mce_name:k,style:j,"class":"Apple-style-span"}),l,1)})})});f.onPreProcess.add(function(i,j){h=i.dom;d(c(j.node.getElementsByTagName("span")).reverse(),function(m){var k,l;if(j.get){if(h.hasClass(m,"Apple-style-span")){l=m.style.backgroundColor;switch(h.getAttrib(m,"mce_name")){case"font":if(!i.settings.convert_fonts_to_spans){h.setAttrib(m,"style","")}break;case"strong":case"em":case"sub":case"sup":h.setAttrib(m,"style","");break;case"strike":case"u":if(!i.settings.inline_styles){h.setAttrib(m,"style","")}else{h.setAttrib(m,"mce_name","")}break;default:if(!i.settings.inline_styles){h.setAttrib(m,"style","")}}if(l){m.style.backgroundColor=l}}}if(h.hasClass(m,"mceItemRemoved")){h.remove(m,1)}})});f.onPostProcess.add(function(i,j){j.content=j.content.replace(/<br \/><\/(h[1-6]|div|p|address|pre)>/g,"</$1>");j.content=j.content.replace(/ id=\"undefined\"/g,"")})},getInfo:function(){return{longname:"Safari compatibility",author:"Moxiecode Systems AB",authorurl:"http://tinymce.moxiecode.com",infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/safari",version:tinymce.majorVersion+"."+tinymce.minorVersion}},_fixWebKitSpans:function(){var g=this,f=g.editor;a.add(f.getDoc(),"DOMNodeInserted",function(h){h=h.target;if(h&&h.nodeType==1){g._fixAppleSpan(h)}})},_fixAppleSpan:function(l){var g=this.editor,m=g.dom,i=this.webKitFontSizes,f=this.namedFontSizes,j=g.settings,h,k;if(m.getAttrib(l,"mce_fixed")){return}if(l.nodeName=="SPAN"&&l.className=="Apple-style-span"){h=l.style;if(!j.convert_fonts_to_spans){if(h.fontSize){m.setAttrib(l,"mce_name","font");m.setAttrib(l,"size",b(i,h.fontSize)+1)}if(h.fontFamily){m.setAttrib(l,"mce_name","font");m.setAttrib(l,"face",h.fontFamily)}if(h.color){m.setAttrib(l,"mce_name","font");m.setAttrib(l,"color",m.toHex(h.color))}if(h.backgroundColor){m.setAttrib(l,"mce_name","font");m.setStyle(l,"background-color",h.backgroundColor)}}else{if(h.fontSize){m.setStyle(l,"fontSize",f[b(i,h.fontSize)])}}if(h.fontWeight=="bold"){m.setAttrib(l,"mce_name","strong")}if(h.fontStyle=="italic"){m.setAttrib(l,"mce_name","em")}if(h.textDecoration=="underline"){m.setAttrib(l,"mce_name","u")}if(h.textDecoration=="line-through"){m.setAttrib(l,"mce_name","strike")}if(h.verticalAlign=="super"){m.setAttrib(l,"mce_name","sup")}if(h.verticalAlign=="sub"){m.setAttrib(l,"mce_name","sub")}m.setAttrib(l,"mce_fixed","1")}},_insertBR:function(f){var j=f.dom,h=f.selection,i=h.getRng(),g;i.insertNode(g=j.create("br"));i.setStartAfter(g);i.setEndAfter(g);h.setRng(i);if(h.getSel().focusNode==g.previousSibling){h.select(j.insertAfter(j.doc.createTextNode("\u00a0"),g));h.collapse(1)}f.getWin().scrollTo(0,j.getPos(h.getRng().startContainer).y)}});tinymce.PluginManager.add("safari",tinymce.plugins.Safari)})(); \ No newline at end of file | ||
diff --git a/public/javascripts/tiny_mce/plugins/safari/editor_plugin_src.js b/public/javascripts/tiny_mce/plugins/safari/editor_plugin_src.js index 642d659..6667b7c 100755..100644 --- a/public/javascripts/tiny_mce/plugins/safari/editor_plugin_src.js +++ b/public/javascripts/tiny_mce/plugins/safari/editor_plugin_src.js | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | (function() { | 8 | (function() { |
| 9 | var Event = tinymce.dom.Event, grep = tinymce.grep, each = tinymce.each, inArray = tinymce.inArray, isOldWebKit = tinymce.isOldWebKit; | 9 | var Event = tinymce.dom.Event, grep = tinymce.grep, each = tinymce.each, inArray = tinymce.inArray; |
| 10 | 10 | ||
| 11 | function isEmpty(d, e, f) { | 11 | function isEmpty(d, e, f) { |
| 12 | var w, n; | 12 | var w, n; |
| @@ -55,6 +55,8 @@ | |||
| 55 | ed.getDoc().execCommand("CreateLink", false, v); | 55 | ed.getDoc().execCommand("CreateLink", false, v); |
| 56 | }); | 56 | }); |
| 57 | 57 | ||
| 58 | /* | ||
| 59 | // WebKit generates spans out of thin air this patch used to remove them but it will also remove styles we want so it's disabled for now | ||
| 58 | ed.onPaste.add(function(ed, e) { | 60 | ed.onPaste.add(function(ed, e) { |
| 59 | function removeStyles(e) { | 61 | function removeStyles(e) { |
| 60 | e = e.target; | 62 | e = e.target; |
| @@ -74,7 +76,7 @@ | |||
| 74 | Event.remove(ed.getDoc(), 'DOMNodeInserted', removeStyles); | 76 | Event.remove(ed.getDoc(), 'DOMNodeInserted', removeStyles); |
| 75 | }, 0); | 77 | }, 0); |
| 76 | }); | 78 | }); |
| 77 | 79 | */ | |
| 78 | ed.onKeyUp.add(function(ed, e) { | 80 | ed.onKeyUp.add(function(ed, e) { |
| 79 | var h, b, r, n, s; | 81 | var h, b, r, n, s; |
| 80 | 82 | ||
| @@ -116,6 +118,14 @@ | |||
| 116 | ed.selection.select(ed.dom.get('_mce_tmp')); | 118 | ed.selection.select(ed.dom.get('_mce_tmp')); |
| 117 | ed.getDoc().execCommand("Delete", false, ' '); | 119 | ed.getDoc().execCommand("Delete", false, ' '); |
| 118 | }); | 120 | }); |
| 121 | |||
| 122 | /* ed.onKeyDown.add(function(ed, e) { | ||
| 123 | // Ctrl+A select all will fail on WebKit since if you paste the contents you selected it will produce a odd div wrapper | ||
| 124 | if ((e.ctrlKey || e.metaKey) && e.keyCode == 65) { | ||
| 125 | ed.selection.select(ed.getBody(), 1); | ||
| 126 | return Event.cancel(e); | ||
| 127 | } | ||
| 128 | });*/ | ||
| 119 | 129 | ||
| 120 | ed.onKeyPress.add(function(ed, e) { | 130 | ed.onKeyPress.add(function(ed, e) { |
| 121 | var se, li, lic, r1, r2, n, sel, doc, be, af, pa; | 131 | var se, li, lic, r1, r2, n, sel, doc, be, af, pa; |
| @@ -209,9 +219,6 @@ | |||
| 209 | 219 | ||
| 210 | ed.onInit.add(function() { | 220 | ed.onInit.add(function() { |
| 211 | t._fixWebKitSpans(); | 221 | t._fixWebKitSpans(); |
| 212 | |||
| 213 | if (isOldWebKit) | ||
| 214 | t._patchSafari2x(ed); | ||
| 215 | }); | 222 | }); |
| 216 | 223 | ||
| 217 | ed.onSetContent.add(function() { | 224 | ed.onSetContent.add(function() { |
| @@ -337,24 +344,13 @@ | |||
| 337 | _fixWebKitSpans : function() { | 344 | _fixWebKitSpans : function() { |
| 338 | var t = this, ed = t.editor; | 345 | var t = this, ed = t.editor; |
| 339 | 346 | ||
| 340 | if (!isOldWebKit) { | 347 | // Use mutator events on new WebKit |
| 341 | // Use mutator events on new WebKit | 348 | Event.add(ed.getDoc(), 'DOMNodeInserted', function(e) { |
| 342 | Event.add(ed.getDoc(), 'DOMNodeInserted', function(e) { | 349 | e = e.target; |
| 343 | e = e.target; | ||
| 344 | |||
| 345 | if (e && e.nodeType == 1) | ||
| 346 | t._fixAppleSpan(e); | ||
| 347 | }); | ||
| 348 | } else { | ||
| 349 | // Do post command processing in old WebKit since the browser crashes on Mutator events :( | ||
| 350 | ed.onExecCommand.add(function() { | ||
| 351 | each(ed.dom.select('span'), function(n) { | ||
| 352 | t._fixAppleSpan(n); | ||
| 353 | }); | ||
| 354 | 350 | ||
| 355 | ed.nodeChanged(); | 351 | if (e && e.nodeType == 1) |
| 356 | }); | 352 | t._fixAppleSpan(e); |
| 357 | } | 353 | }); |
| 358 | }, | 354 | }, |
| 359 | 355 | ||
| 360 | _fixAppleSpan : function(e) { | 356 | _fixAppleSpan : function(e) { |
| @@ -414,78 +410,6 @@ | |||
| 414 | } | 410 | } |
| 415 | }, | 411 | }, |
| 416 | 412 | ||
| 417 | _patchSafari2x : function(ed) { | ||
| 418 | var t = this, setContent, getNode, dom = ed.dom, lr; | ||
| 419 | |||
| 420 | // Inline dialogs | ||
| 421 | if (ed.windowManager.onBeforeOpen) { | ||
| 422 | ed.windowManager.onBeforeOpen.add(function() { | ||
| 423 | r = ed.selection.getRng(); | ||
| 424 | }); | ||
| 425 | } | ||
| 426 | |||
| 427 | // Fake select on 2.x | ||
| 428 | ed.selection.select = function(n) { | ||
| 429 | this.getSel().setBaseAndExtent(n, 0, n, 1); | ||
| 430 | }; | ||
| 431 | |||
| 432 | getNode = ed.selection.getNode; | ||
| 433 | ed.selection.getNode = function() { | ||
| 434 | return t.selElm || getNode.call(this); | ||
| 435 | }; | ||
| 436 | |||
| 437 | // Fake range on Safari 2.x | ||
| 438 | ed.selection.getRng = function() { | ||
| 439 | var t = this, s = t.getSel(), d = ed.getDoc(), r, rb, ra, di; | ||
| 440 | |||
| 441 | // Fake range on Safari 2.x | ||
| 442 | if (s.anchorNode) { | ||
| 443 | r = d.createRange(); | ||
| 444 | |||
| 445 | try { | ||
| 446 | // Setup before range | ||
| 447 | rb = d.createRange(); | ||
| 448 | rb.setStart(s.anchorNode, s.anchorOffset); | ||
| 449 | rb.collapse(1); | ||
| 450 | |||
| 451 | // Setup after range | ||
| 452 | ra = d.createRange(); | ||
| 453 | ra.setStart(s.focusNode, s.focusOffset); | ||
| 454 | ra.collapse(1); | ||
| 455 | |||
| 456 | // Setup start/end points by comparing locations | ||
| 457 | di = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0; | ||
| 458 | r.setStart(di ? s.anchorNode : s.focusNode, di ? s.anchorOffset : s.focusOffset); | ||
| 459 | r.setEnd(di ? s.focusNode : s.anchorNode, di ? s.focusOffset : s.anchorOffset); | ||
| 460 | |||
| 461 | lr = r; | ||
| 462 | } catch (ex) { | ||
| 463 | // Sometimes fails, at least we tried to do it by the book. I hope Safari 2.x will go disappear soooon!!! | ||
| 464 | } | ||
| 465 | } | ||
| 466 | |||
| 467 | return r || lr; | ||
| 468 | }; | ||
| 469 | |||
| 470 | // Fix setContent so it works | ||
| 471 | setContent = ed.selection.setContent; | ||
| 472 | ed.selection.setContent = function(h, s) { | ||
| 473 | var r = this.getRng(), b; | ||
| 474 | |||
| 475 | try { | ||
| 476 | setContent.call(this, h, s); | ||
| 477 | } catch (ex) { | ||
| 478 | // Workaround for Safari 2.x | ||
| 479 | b = dom.create('body'); | ||
| 480 | b.innerHTML = h; | ||
| 481 | |||
| 482 | each(b.childNodes, function(n) { | ||
| 483 | r.insertNode(n.cloneNode(true)); | ||
| 484 | }); | ||
| 485 | } | ||
| 486 | }; | ||
| 487 | }, | ||
| 488 | |||
| 489 | _insertBR : function(ed) { | 413 | _insertBR : function(ed) { |
| 490 | var dom = ed.dom, s = ed.selection, r = s.getRng(), br; | 414 | var dom = ed.dom, s = ed.selection, r = s.getRng(), br; |
| 491 | 415 | ||
