From 7adcb81e4f83f98c468889aaa5a85558ba88c770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 25 Jan 2016 17:45:33 +0100 Subject: Initial commit --- sources/plugins/htmlwriter/plugin.js | 359 +++++++++++++++++++++ .../assets/outputforflash/outputforflash.fla | Bin 0 -> 85504 bytes .../assets/outputforflash/outputforflash.swf | Bin 0 -> 15571 bytes .../samples/assets/outputforflash/swfobject.js | 5 + .../plugins/htmlwriter/samples/outputforflash.html | 283 ++++++++++++++++ sources/plugins/htmlwriter/samples/outputhtml.html | 224 +++++++++++++ 6 files changed, 871 insertions(+) create mode 100644 sources/plugins/htmlwriter/plugin.js create mode 100644 sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.fla create mode 100644 sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.swf create mode 100644 sources/plugins/htmlwriter/samples/assets/outputforflash/swfobject.js create mode 100644 sources/plugins/htmlwriter/samples/outputforflash.html create mode 100644 sources/plugins/htmlwriter/samples/outputhtml.html (limited to 'sources/plugins/htmlwriter') diff --git a/sources/plugins/htmlwriter/plugin.js b/sources/plugins/htmlwriter/plugin.js new file mode 100644 index 00000000..687b2bf0 --- /dev/null +++ b/sources/plugins/htmlwriter/plugin.js @@ -0,0 +1,359 @@ +/** + * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or http://ckeditor.com/license + */ + +CKEDITOR.plugins.add( 'htmlwriter', { + init: function( editor ) { + var writer = new CKEDITOR.htmlWriter(); + + writer.forceSimpleAmpersand = editor.config.forceSimpleAmpersand; + writer.indentationChars = editor.config.dataIndentationChars || '\t'; + + // Overwrite default basicWriter initialized in hmtlDataProcessor constructor. + editor.dataProcessor.writer = writer; + } +} ); + +/** + * The class used to write HTML data. + * + * var writer = new CKEDITOR.htmlWriter(); + * writer.openTag( 'p' ); + * writer.attribute( 'class', 'MyClass' ); + * writer.openTagClose( 'p' ); + * writer.text( 'Hello' ); + * writer.closeTag( 'p' ); + * alert( writer.getHtml() ); // '

Hello

' + * + * @class + * @extends CKEDITOR.htmlParser.basicWriter + */ +CKEDITOR.htmlWriter = CKEDITOR.tools.createClass( { + base: CKEDITOR.htmlParser.basicWriter, + + /** + * Creates an `htmlWriter` class instance. + * + * @constructor + */ + $: function() { + // Call the base contructor. + this.base(); + + /** + * The characters to be used for each indentation step. + * + * // Use tab for indentation. + * editorInstance.dataProcessor.writer.indentationChars = '\t'; + */ + this.indentationChars = '\t'; + + /** + * The characters to be used to close "self-closing" elements, like `
` or ``. + * + * // Use HTML4 notation for self-closing elements. + * editorInstance.dataProcessor.writer.selfClosingEnd = '>'; + */ + this.selfClosingEnd = ' />'; + + /** + * The characters to be used for line breaks. + * + * // Use CRLF for line breaks. + * editorInstance.dataProcessor.writer.lineBreakChars = '\r\n'; + */ + this.lineBreakChars = '\n'; + + this.sortAttributes = 1; + + this._.indent = 0; + this._.indentation = ''; + // Indicate preformatted block context status. (#5789) + this._.inPre = 0; + this._.rules = {}; + + var dtd = CKEDITOR.dtd; + + for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { + this.setRules( e, { + indent: !dtd[ e ][ '#' ], + breakBeforeOpen: 1, + breakBeforeClose: !dtd[ e ][ '#' ], + breakAfterClose: 1, + needsSpace: ( e in dtd.$block ) && !( e in { li: 1, dt: 1, dd: 1 } ) + } ); + } + + this.setRules( 'br', { breakAfterOpen: 1 } ); + + this.setRules( 'title', { + indent: 0, + breakAfterOpen: 0 + } ); + + this.setRules( 'style', { + indent: 0, + breakBeforeClose: 1 + } ); + + this.setRules( 'pre', { + breakAfterOpen: 1, // Keep line break after the opening tag + indent: 0 // Disable indentation on
.
+		} );
+	},
+
+	proto: {
+		/**
+		 * Writes the tag opening part for an opener tag.
+		 *
+		 *		// Writes ''.
+		 *		writer.openTagClose( 'p', false );
+		 *
+		 *		// Writes ' />'.
+		 *		writer.openTagClose( 'br', true );
+		 *
+		 * @param {String} tagName The element name for this tag.
+		 * @param {Boolean} isSelfClose Indicates that this is a self-closing tag,
+		 * like `
` or ``. + */ + openTagClose: function( tagName, isSelfClose ) { + var rules = this._.rules[ tagName ]; + + if ( isSelfClose ) { + this._.output.push( this.selfClosingEnd ); + + if ( rules && rules.breakAfterClose ) + this._.needsSpace = rules.needsSpace; + } else { + this._.output.push( '>' ); + + if ( rules && rules.indent ) + this._.indentation += this.indentationChars; + } + + if ( rules && rules.breakAfterOpen ) + this.lineBreak(); + tagName == 'pre' && ( this._.inPre = 1 ); + }, + + /** + * Writes an attribute. This function should be called after opening the + * tag with {@link #openTagClose}. + * + * // Writes ' class="MyClass"'. + * writer.attribute( 'class', 'MyClass' ); + * + * @param {String} attName The attribute name. + * @param {String} attValue The attribute value. + */ + attribute: function( attName, attValue ) { + + if ( typeof attValue == 'string' ) { + this.forceSimpleAmpersand && ( attValue = attValue.replace( /&/g, '&' ) ); + // Browsers don't always escape special character in attribute values. (#4683, #4719). + attValue = CKEDITOR.tools.htmlEncodeAttr( attValue ); + } + + this._.output.push( ' ', attName, '="', attValue, '"' ); + }, + + /** + * Writes a closer tag. + * + * // Writes '

'. + * writer.closeTag( 'p' ); + * + * @param {String} tagName The element name for this tag. + */ + closeTag: function( tagName ) { + var rules = this._.rules[ tagName ]; + + if ( rules && rules.indent ) + this._.indentation = this._.indentation.substr( this.indentationChars.length ); + + if ( this._.indent ) + this.indentation(); + // Do not break if indenting. + else if ( rules && rules.breakBeforeClose ) { + this.lineBreak(); + this.indentation(); + } + + this._.output.push( '' ); + tagName == 'pre' && ( this._.inPre = 0 ); + + if ( rules && rules.breakAfterClose ) { + this.lineBreak(); + this._.needsSpace = rules.needsSpace; + } + + this._.afterCloser = 1; + }, + + /** + * Writes text. + * + * // Writes 'Hello Word'. + * writer.text( 'Hello Word' ); + * + * @param {String} text The text value + */ + text: function( text ) { + if ( this._.indent ) { + this.indentation(); + !this._.inPre && ( text = CKEDITOR.tools.ltrim( text ) ); + } + + this._.output.push( text ); + }, + + /** + * Writes a comment. + * + * // Writes "". + * writer.comment( ' My comment ' ); + * + * @param {String} comment The comment text. + */ + comment: function( comment ) { + if ( this._.indent ) + this.indentation(); + + this._.output.push( '' ); + }, + + /** + * Writes a line break. It uses the {@link #lineBreakChars} property for it. + * + * // Writes '\n' (e.g.). + * writer.lineBreak(); + */ + lineBreak: function() { + if ( !this._.inPre && this._.output.length > 0 ) + this._.output.push( this.lineBreakChars ); + this._.indent = 1; + }, + + /** + * Writes the current indentation character. It uses the {@link #indentationChars} + * property, repeating it for the current indentation steps. + * + * // Writes '\t' (e.g.). + * writer.indentation(); + */ + indentation: function() { + if ( !this._.inPre && this._.indentation ) + this._.output.push( this._.indentation ); + this._.indent = 0; + }, + + /** + * Empties the current output buffer. It also brings back the default + * values of the writer flags. + * + * writer.reset(); + */ + reset: function() { + this._.output = []; + this._.indent = 0; + this._.indentation = ''; + this._.afterCloser = 0; + this._.inPre = 0; + }, + + /** + * Sets formatting rules for a given element. Possible rules are: + * + * * `indent` – indent the element content. + * * `breakBeforeOpen` – break line before the opener tag for this element. + * * `breakAfterOpen` – break line after the opener tag for this element. + * * `breakBeforeClose` – break line before the closer tag for this element. + * * `breakAfterClose` – break line after the closer tag for this element. + * + * All rules default to `false`. Each function call overrides rules that are + * already present, leaving the undefined ones untouched. + * + * By default, all elements available in the {@link CKEDITOR.dtd#$block}, + * {@link CKEDITOR.dtd#$listItem}, and {@link CKEDITOR.dtd#$tableContent} + * lists have all the above rules set to `true`. Additionaly, the `
` + * element has the `breakAfterOpen` rule set to `true`. + * + * // Break line before and after "img" tags. + * writer.setRules( 'img', { + * breakBeforeOpen: true + * breakAfterOpen: true + * } ); + * + * // Reset the rules for the "h1" tag. + * writer.setRules( 'h1', {} ); + * + * @param {String} tagName The name of the element for which the rules are set. + * @param {Object} rules An object containing the element rules. + */ + setRules: function( tagName, rules ) { + var currentRules = this._.rules[ tagName ]; + + if ( currentRules ) + CKEDITOR.tools.extend( currentRules, rules, true ); + else + this._.rules[ tagName ] = rules; + } + } +} ); + +/** + * Whether to force using `'&'` instead of `'&'` in element attributes + * values. It is not recommended to change this setting for compliance with the + * W3C XHTML 1.0 standards ([C.12, XHTML 1.0](http://www.w3.org/TR/xhtml1/#C_12)). + * + * // Use `'&'` instead of `'&'` + * CKEDITOR.config.forceSimpleAmpersand = true; + * + * @cfg {Boolean} [forceSimpleAmpersand=false] + * @member CKEDITOR.config + */ + +/** + * The characters to be used for indenting HTML output produced by the editor. + * Using characters different from `' '` (space) and `'\t'` (tab) is not recommended + * as it will mess the code. + * + * // No indentation. + * CKEDITOR.config.dataIndentationChars = ''; + * + * // Use two spaces for indentation. + * CKEDITOR.config.dataIndentationChars = ' '; + * + * @cfg {String} [dataIndentationChars='\t'] + * @member CKEDITOR.config + */ diff --git a/sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.fla b/sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.fla new file mode 100644 index 00000000..27e68ccd Binary files /dev/null and b/sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.fla differ diff --git a/sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.swf b/sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.swf new file mode 100644 index 00000000..dbe17b6b Binary files /dev/null and b/sources/plugins/htmlwriter/samples/assets/outputforflash/outputforflash.swf differ diff --git a/sources/plugins/htmlwriter/samples/assets/outputforflash/swfobject.js b/sources/plugins/htmlwriter/samples/assets/outputforflash/swfobject.js new file mode 100644 index 00000000..90cdcc9e --- /dev/null +++ b/sources/plugins/htmlwriter/samples/assets/outputforflash/swfobject.js @@ -0,0 +1,5 @@ + +/* SWFObject v2.2 + is released under the MIT License +*/ +var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y0){for(var af=0;af0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad'}}aa.outerHTML='"+af+"";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab + + + + + Output for Flash — CKEditor Sample + + + + + + + + + + + +

+ CKEditor Samples » Producing Flash Compliant HTML Output +

+
+ This sample is not maintained anymore. Check out the brand new samples in CKEditor SDK. +
+
+

+ This sample shows how to configure CKEditor to output + HTML code that can be used with + + Adobe Flash. + The code will contain a subset of standard HTML elements like <b>, + <i>, and <p> as well as HTML attributes. +

+

+ To add a CKEditor instance outputting Flash compliant HTML code, load the editor using a standard + JavaScript call, and define CKEditor features to use HTML elements and attributes. +

+

+ For details on how to create this setup check the source code of this sample page. +

+
+

+ To see how it works, create some content in the editing area of CKEditor on the left + and send it to the Flash object on the right side of the page by using the + Send to Flash button. +

+ + + + + +
+ + +

+ +

+
+
+
+ + + diff --git a/sources/plugins/htmlwriter/samples/outputhtml.html b/sources/plugins/htmlwriter/samples/outputhtml.html new file mode 100644 index 00000000..3c584558 --- /dev/null +++ b/sources/plugins/htmlwriter/samples/outputhtml.html @@ -0,0 +1,224 @@ + + + + + + HTML Compliant Output — CKEditor Sample + + + + + + + + + +

+ CKEditor Samples » Producing HTML Compliant Output +

+
+ This sample is not maintained anymore. Check out the brand new samples in CKEditor SDK. +
+
+

+ This sample shows how to configure CKEditor to output valid + HTML 4.01 code. + Traditional HTML elements like <b>, + <i>, and <font> are used in place of + <strong>, <em>, and CSS styles. +

+

+ To add a CKEditor instance outputting legacy HTML 4.01 code, load the editor using a standard + JavaScript call, and define CKEditor features to use the HTML compliant elements and attributes. +

+

+ A snippet of the configuration code can be seen below; check the source of this page for + full definition: +

+
+CKEDITOR.replace( 'textarea_id', {
+	coreStyles_bold: { element: 'b' },
+	coreStyles_italic: { element: 'i' },
+
+	fontSize_style: {
+		element: 'font',
+		attributes: { 'size': '#(size)' }
+	}
+
+	...
+});
+
+
+

+ + + +

+

+ +

+
+ + + -- cgit v1.2.3