mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-02-23 18:36:24 +00:00
Monotone-Parent: dbd490c81ea6cac4c12b2e17661e2fef43219e68 Monotone-Revision: 0801dc9f1e4fdc49ea44fc0450fb025c2639ed26 Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-06-25T19:18:02 Monotone-Branch: ca.inverse.sogo
10 lines
9.1 KiB
JavaScript
10 lines
9.1 KiB
JavaScript
/*
|
|
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
|
For licensing, see LICENSE.html or http://ckeditor.com/license
|
|
*/
|
|
|
|
CKEDITOR.plugins.add('styles',{requires:['selection']});CKEDITOR.editor.prototype.attachStyleStateChange=function(a,b){var c=this._.styleStateChangeCallbacks;if(!c){c=this._.styleStateChangeCallbacks=[];this.on('selectionChange',function(d){for(var e=0;e<c.length;e++){var f=c[e],g=f.style.checkActive(d.data.path)?CKEDITOR.TRISTATE_ON:CKEDITOR.TRISTATE_OFF;if(f.state!==g){f.fn.call(this,g);f.state!==g;}}});}c.push({style:a,fn:b});};CKEDITOR.STYLE_BLOCK=1;CKEDITOR.STYLE_INLINE=2;CKEDITOR.STYLE_OBJECT=3;(function(){var a={address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1},b={a:1,embed:1,hr:1,img:1,li:1,object:1,ol:1,table:1,td:1,tr:1,ul:1},c=/\s*(?:;\s*|$)/;CKEDITOR.style=function(u,v){if(v){u=CKEDITOR.tools.clone(u);p(u.attributes,v);p(u.styles,v);}var w=this.element=(u.element||'*').toLowerCase();this.type=w=='#'||a[w]?CKEDITOR.STYLE_BLOCK:b[w]?CKEDITOR.STYLE_OBJECT:CKEDITOR.STYLE_INLINE;this._={definition:u};};CKEDITOR.style.prototype={apply:function(u){t.call(this,u,false);},remove:function(u){t.call(this,u,true);},applyToRange:function(u){var v=this;return(v.applyToRange=v.type==CKEDITOR.STYLE_INLINE?d:v.type==CKEDITOR.STYLE_BLOCK?f:null).call(v,u);},removeFromRange:function(u){return(this.removeFromRange=this.type==CKEDITOR.STYLE_INLINE?e:null).call(this,u);},applyToObject:function(u){n(u,this);},checkActive:function(u){switch(this.type){case CKEDITOR.STYLE_BLOCK:return this.checkElementRemovable(u.block||u.blockLimit,true);case CKEDITOR.STYLE_INLINE:var v=u.elements;for(var w=0,x;w<v.length;w++){x=v[w];if(x==u.block||x==u.blockLimit)continue;if(this.checkElementRemovable(x,true))return true;}}return false;},checkElementRemovable:function(u,v){if(!u)return false;var w=this._.definition,x;if(u.getName()==this.element){if(!v&&!u.hasAttributes())return true;x=q(w);if(x._length){for(var y in x){if(y=='_length')continue;if(x[y]==u.getAttribute(y)){if(!v)return true;}else if(v)return false;}if(v)return true;}else return true;}var z=r(this)[u.getName()];if(z){if(!(x=z.attributes))return true;for(var A=0;A<x.length;A++){y=x[A][0];var B=u.getAttribute(y);if(B){var C=x[A][1];if(C===null||typeof C=='string'&&B==C||C.test(B))return true;}}}return false;}};CKEDITOR.style.getStyleText=function(u){var v=u._ST;if(v)return v;v=u.styles;var w=u.attributes&&u.attributes.style||'';if(w.length)w=w.replace(c,';');for(var x in v)w+=x+':'+v[x]+';';if(w.length)w=s(w);return u._ST=w;};function d(u){var T=this;var v=u.document;if(u.collapsed){var w=m(T,v);u.insertNode(w);u.moveToPosition(w,CKEDITOR.POSITION_BEFORE_END);
|
|
return;}var x=T.element,y=T._.definition,z,A=CKEDITOR.dtd[x]||(z=true,CKEDITOR.dtd.span),B=u.createBookmark();u.enlarge(CKEDITOR.ENLARGE_ELEMENT);u.trim();var C=u.getBoundaryNodes(),D=C.startNode,E=C.endNode.getNextSourceNode(true);if(!E){E=v.createText('');E.insertAfter(u.endContainer);}var F=E.getParent();if(F&&F.getAttribute('_fck_bookmark'))E=F;if(E.equals(D)){E=E.getNextSourceNode(true);if(!E){E=v.createText('');E.insertAfter(D);}}var G=D,H,I;while(G){var J=false;if(G.equals(E)){G=null;J=true;}else{var K=G.type,L=K==CKEDITOR.NODE_ELEMENT?G.getName():null;if(L&&G.getAttribute('_fck_bookmark')){G=G.getNextSourceNode(true);continue;}if(!L||A[L]&&(G.getPosition(E)|CKEDITOR.POSITION_PRECEDING|CKEDITOR.POSITION_IDENTICAL|CKEDITOR.POSITION_IS_CONTAINED)==(CKEDITOR.POSITION_PRECEDING+CKEDITOR.POSITION_IDENTICAL+CKEDITOR.POSITION_IS_CONTAINED)){var M=G.getParent();if(M&&((M.getDtd()||CKEDITOR.dtd.span)[x]||z)){if(!H&&(!L||!CKEDITOR.dtd.$removeEmpty[L]||(G.getPosition(E)|CKEDITOR.POSITION_PRECEDING|CKEDITOR.POSITION_IDENTICAL|CKEDITOR.POSITION_IS_CONTAINED)==(CKEDITOR.POSITION_PRECEDING+CKEDITOR.POSITION_IDENTICAL+CKEDITOR.POSITION_IS_CONTAINED))){H=new CKEDITOR.dom.range(v);H.setStartBefore(G);}if(K==CKEDITOR.NODE_TEXT||K==CKEDITOR.NODE_ELEMENT&&!G.getChildCount()){var N=G,O;while(!N.$.nextSibling&&(O=N.getParent(),A[O.getName()])&&((O.getPosition(D)|CKEDITOR.POSITION_FOLLOWING|CKEDITOR.POSITION_IDENTICAL|CKEDITOR.POSITION_IS_CONTAINED)==(CKEDITOR.POSITION_FOLLOWING+CKEDITOR.POSITION_IDENTICAL+CKEDITOR.POSITION_IS_CONTAINED)))N=O;H.setEndAfter(N);if(!N.$.nextSibling)J=true;if(!I)I=K!=CKEDITOR.NODE_TEXT||/[^\s\ufeff]/.test(G.getText());}}else J=true;}else J=true;G=G.getNextSourceNode();}if(J&&I&&H&&!H.collapsed){var P=m(T,v),Q=H.getCommonAncestor();while(P&&Q){if(Q.getName()==x){for(var R in y.attribs)if(P.getAttribute(R)==Q.getAttribute(R))P.removeAttribute(R);for(var S in y.styles)if(P.getStyle(S)==Q.getStyle(S))P.removeStyle(S);if(!P.hasAttributes()){P=null;break;}}Q=Q.getParent();}if(P){H.extractContents().appendTo(P);h(T,P);H.insertNode(P);k(P);if(!CKEDITOR.env.ie)P.$.normalize();}H=null;}}u.moveToBookmark(B);};function e(u){u.enlarge(CKEDITOR.ENLARGE_ELEMENT);var v=u.createBookmark(),w=v.startNode;if(u.collapsed){var x=new CKEDITOR.dom.elementPath(w.getParent()),y;for(var z=0,A;z<x.elements.length&&(A=x.elements[z]);z++){if(A==x.block||A==x.blockLimit)break;if(this.checkElementRemovable(A)){var B=u.checkBoundaryOfElement(A,CKEDITOR.END),C=!B&&u.checkBoundaryOfElement(A,CKEDITOR.START);
|
|
if(C||B){y=A;y.match=C?'start':'end';}else{k(A);g(this,A);}}}if(y){var D=w;for(z=0;true;z++){var E=x.elements[z];if(E.equals(y))break;else if(E.match)continue;else E=E.clone();E.append(D);D=E;}D[y.match=='start'?'insertBefore':'insertAfter'](y);}}else{var F=v.endNode,G=this;function H(){var K=new CKEDITOR.dom.elementPath(w.getParent()),L=new CKEDITOR.dom.elementPath(F.getParent()),M=null,N=null;for(var O=0;O<K.elements.length;O++){var P=K.elements[O];if(P==K.block||P==K.blockLimit)break;if(G.checkElementRemovable(P))M=P;}for(O=0;O<L.elements.length;O++){P=L.elements[O];if(P==L.block||P==L.blockLimit)break;if(G.checkElementRemovable(P))N=P;}if(N)F.breakParent(N);if(M)w.breakParent(M);};H();var I=w.getNext();while(!I.equals(F)){var J=I.getNextSourceNode();if(I.type==CKEDITOR.NODE_ELEMENT&&this.checkElementRemovable(I)){if(I.getName()==this.element)g(this,I);else i(I,r(this)[I.getName()]);if(J.type==CKEDITOR.NODE_ELEMENT&&J.contains(w)){H();J=w.getNext();}}I=J;}}u.moveToBookmark(v);};function f(u){var v=u.createBookmark(),w=u.createIterator();w.enforceRealBlocks=true;var x,y=u.document,z;while(x=w.getNextParagraph()){var A=m(this,y);x.moveChildren(A);A.insertBefore(x);x.remove();}u.moveToBookmark(v);};function g(u,v){var w=u._.definition,x=w.attributes,y=w.styles,z=r(u);function A(){for(var C in x){if(C=='class'&&v.getAttribute(C)!=x[C])continue;v.removeAttribute(C);}};A();for(var B in y)v.removeStyle(B);x=z[v.getName()];if(x)A();j(v);};function h(u,v){var w=u._.definition,x=w.attributes,y=w.styles,z=r(u),A=v.getElementsByTag(u.element);for(var B=A.count();--B>=0;)g(u,A.getItem(B));for(var C in z)if(C!=u.element){A=v.getElementsByTag(C);for(B=A.count()-1;B>=0;B--){var D=A.getItem(B);i(D,z[C]);}}};function i(u,v){var w=v&&v.attributes;if(w)for(var x=0;x<w.length;x++){var y=w[x][0],z;if(z=u.getAttribute(y)){var A=w[x][1];if(A===null||A.test&&A.test(z)||typeof A=='string'&&z==A)u.removeAttribute(y);}}j(u);};function j(u){if(!u.hasAttributes()){var v=u.getFirst(),w=u.getLast();u.remove(true);if(v){k(v);if(w&&!v.equals(w))k(w);}}};function k(u){if(!u||u.type!=CKEDITOR.NODE_ELEMENT||!CKEDITOR.dtd.$removeEmpty[u.getName()])return;l(u,u.getNext(),true);l(u,u.getPrevious());};function l(u,v,w){if(v&&v.type==CKEDITOR.NODE_ELEMENT){var x=v.getAttribute('_fck_bookmark');if(x)v=w?v.getNext():v.getPrevious();if(v&&v.type==CKEDITOR.NODE_ELEMENT&&u.isIdentical(v)){var y=w?u.getLast():u.getFirst();if(x)(w?v.getPrevious():v.getNext()).move(u,!w);v.moveChildren(u,!w);v.remove();
|
|
if(y)k(y);}}};function m(u,v){var w,x=u._.definition,y=u.element;if(y=='*')y='span';w=new CKEDITOR.dom.element(y,v);return n(w,u);};function n(u,v){var w=v._.definition,x=w.attributes,y=CKEDITOR.style.getStyleText(w);if(x)for(var z in x)u.setAttribute(z,x[z]);if(y)u.setAttribute('style',y);return u;};var o=/#\((.+?)\)/g;function p(u,v){for(var w in u)u[w]=u[w].replace(o,function(x,y){return v[y];});};function q(u){var v=u._AC;if(v)return v;v={};var w=0,x=u.attributes;if(x)for(var y in x){w++;v[y]=x[y];}var z=CKEDITOR.style.getStyleText(u);if(z){if(!v.style)w++;v.style=z;}v._length=w;return u._AC=v;};function r(u){if(u._.overrides)return u._.overrides;var v=u._.overrides={},w=u._.definition.overrides;if(w){if(!CKEDITOR.tools.isArray(w))w=[w];for(var x=0;x<w.length;x++){var y=w[x],z,A,B;if(typeof y=='string')z=y.toLowerCase();else{z=y.element?y.element.toLowerCase():u.element;B=y.attributes;}A=v[z]||(v[z]={});if(B){var C=A.attributes=A.attributes||[];for(var D in B)C.push([D.toLowerCase(),B[D]]);}}}return v;};function s(u){var v=new CKEDITOR.dom.element('span');v.setAttribute('style',u);return v.getAttribute('style');};function t(u,v){var w=u.getSelection(),x=w.getRanges(),y=v?this.removeFromRange:this.applyToRange;for(var z=0;z<x.length;z++)y.call(this,x[z]);w.selectRanges(x);};})();CKEDITOR.styleCommand=function(a){this.style=a;};CKEDITOR.styleCommand.prototype.exec=function(a){var c=this;a.focus();var b=a.document;if(b)if(c.state==CKEDITOR.TRISTATE_OFF)c.style.apply(b);else if(c.state==CKEDITOR.TRISTATE_ON)c.style.remove(b);return!!b;};
|