Ticket #5654: 5654_3.patch
File 5654_3.patch, 10.2 KB (added by , 14 years ago) |
---|
-
_samples/index.html
42 42 <li><a href="output_xhtml.html">Output XHTML</a></li> 43 43 <li><a href="output_html.html">Output HTML</a></li> 44 44 <li><a href="autogrow.html">AutoGrow plugin</a></li> 45 <li><a href="placeholder.html">Placeholder plugin</a></li> 45 46 </ul> 46 47 <div id="footer"> 47 48 <hr /> -
_samples/placeholder.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <!-- 3 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 4 For licensing, see LICENSE.html or http://ckeditor.com/license 5 --> 6 <html xmlns="http://www.w3.org/1999/xhtml"> 7 <head> 8 <title>Placeholder Plugin - CKEditor Sample</title> 9 <meta content="text/html; charset=utf-8" http-equiv="content-type" /> 10 <!-- CKReleaser %REMOVE_LINE% 11 <script type="text/javascript" src="../ckeditor.js"></script> 12 CKReleaser %REMOVE_START% --> 13 <script type="text/javascript" src="../ckeditor_source.js"></script> 14 <!-- CKReleaser %REMOVE_END% --> 15 <script src="sample.js" type="text/javascript"></script> 16 <link href="sample.css" rel="stylesheet" type="text/css" /> 17 </head> 18 <body> 19 <h1> 20 CKEditor Sample 21 </h1> 22 <!-- This <div> holds alert messages to be display in the sample page. --> 23 <div id="alerts"> 24 <noscript> 25 <p> 26 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript 27 support, like yours, you should still see the contents (HTML data) and you should 28 be able to edit it normally, without a rich editor interface. 29 </p> 30 </noscript> 31 </div> 32 <form action="sample_posteddata.php" method="post"> 33 <p> 34 In this sample the Placeholder plugin is available.<br /> 35 It replaces text in the format of <code>[[text]]</code> to uneditable sections, and lets the user edit them and create new ones using a dialog.</p> 36 <p> 37 <label for="editor1"> 38 With default configuration:</label><br /> 39 <textarea cols="80" id="editor1" name="editor1" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>. [[This is a placeholder]]</p></textarea> 40 <script type="text/javascript"> 41 //<![CDATA[ 42 43 CKEDITOR.replace( 'editor1', { 44 extraPlugins : 'placeholder', 45 toolbar : [ [ 'Source', 'CreatePlaceholder' ] ] 46 }); 47 48 //]]> 49 </script> 50 </p> 51 <p> 52 <input type="submit" value="Submit" /> 53 </p> 54 </form> 55 <div id="footer"> 56 <hr /> 57 <p> 58 CKEditor - The text editor for Internet - <a href="http://ckeditor.com/">http://ckeditor.com</a> 59 </p> 60 <p id="copy"> 61 Copyright © 2003-2010, <a href="http://cksource.com/">CKSource</a> - Frederico 62 Knabben. All rights reserved. 63 </p> 64 </div> 65 </body> 66 </html> 67 No newline at end of file -
_source/plugins/placeholder/dialogs/placeholder.js
1 /* 2 * Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 * For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 (function() 7 { 8 function placeholderDialog( editor, isEdit ) 9 { 10 11 var lang = editor.lang.placeholder, 12 generalLabel = editor.lang.common.generalTab; 13 return { 14 title : lang.title, 15 minWidth : 300, 16 minHeight : 80, 17 contents : 18 [ 19 { 20 id : 'info', 21 label : generalLabel, 22 title : generalLabel, 23 elements : 24 [ 25 { 26 id : 'text', 27 type : 'text', 28 style : 'width: 100%;', 29 label : lang.text, 30 'default' : '', 31 required : true, 32 validate : CKEDITOR.dialog.validate.notEmpty( lang.textMissing ), 33 setup : function( element ) 34 { 35 if ( isEdit ) 36 this.setValue( element.getText().slice( 2, -2 ) ); 37 }, 38 commit : function( element ) 39 { 40 var text = '[[' + this.getValue() + ']]'; 41 // The placeholder must be recreated. 42 CKEDITOR.plugins.placeholder.createPlaceholder( editor, element, text ); 43 } 44 } 45 ] 46 } 47 ], 48 onShow : function() 49 { 50 this._element = isEdit && editor.getSelection().getRanges()[0].getTouchedStartNode(); 51 this.setupContent( this._element ); 52 }, 53 onOk : function() 54 { 55 this.commitContent( this._element ); 56 delete this._element; 57 } 58 }; 59 } 60 61 CKEDITOR.dialog.add( 'createplaceholder', function( editor ) 62 { 63 return placeholderDialog( editor ); 64 }); 65 CKEDITOR.dialog.add( 'editplaceholder', function( editor ) 66 { 67 return placeholderDialog( editor, 1 ); 68 }); 69 } )(); -
_source/plugins/placeholder/lang/en.js
1 /* 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 CKEDITOR.plugins.setLang( 'placeholder', 'en', 7 { 8 placeholder : 9 { 10 title : 'Placeholder Properties', 11 toolbar : 'Create Placeholder', 12 text : 'Placeholder Text', 13 edit : 'Edit Placeholder', 14 textMissing : 'The placeholder must contain text.' 15 } 16 }); -
_source/plugins/placeholder/plugin.js
1 /* 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 /** 7 * @fileOverview The "placeholder" plugin. 8 * 9 */ 10 11 (function() 12 { 13 var placeholderReplaceRegex = /\[\[[^\]]+\]\]/g; 14 CKEDITOR.plugins.add( 'placeholder', 15 { 16 requires : [ 'dialog' ], 17 18 availableLangs : { en:1 }, 19 init : function( editor ) 20 { 21 var langCode = editor.langCode, 22 plugin = this; 23 langCode = plugin.availableLangs[ langCode ] ? langCode : 'en'; 24 25 CKEDITOR.scriptLoader.load( 26 CKEDITOR.getUrl( plugin.path + 'lang/' + langCode + '.js' ), 27 function() 28 { 29 var lang = CKEDITOR.tools.extend( editor.lang, plugin.lang[ langCode ] ).placeholder; 30 31 editor.addCommand( 'createplaceholder', new CKEDITOR.dialogCommand( 'createplaceholder' ) ); 32 editor.addCommand( 'editplaceholder', new CKEDITOR.dialogCommand( 'editplaceholder' ) ); 33 34 editor.ui.addButton( 'CreatePlaceholder', 35 { 36 label : lang.toolbar, 37 command :'createplaceholder', 38 icon : this.path + 'placeholder.gif' 39 }); 40 41 if ( editor.addMenuItems ) 42 { 43 editor.addMenuGroup( 'placeholder', 20 ); 44 editor.addMenuItems( 45 { 46 editplaceholder : 47 { 48 label : lang.edit, 49 command : 'editplaceholder', 50 group : 'placeholder', 51 order : 1, 52 icon : this.path + 'placeholder.gif' 53 } 54 }); 55 56 if ( editor.contextMenu ) 57 { 58 editor.contextMenu.addListener( function( element, selection ) 59 { 60 if ( !element || !element.hasAttribute( '_cke_placeholder' ) ) 61 return null; 62 63 return { editplaceholder : CKEDITOR.TRISTATE_OFF }; 64 }); 65 } 66 } 67 }); 68 69 editor.addCss( 70 '.cke_placeholder' + 71 '{' + 72 'background-color: #ffff00;' + 73 ( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) + 74 '}' 75 ); 76 77 editor.on( 'contentDom', function() 78 { 79 editor.document.getBody().on( 'resizestart', function( evt ) 80 { 81 if ( editor.getSelection().getSelectedElement().hasAttribute( '_cke_placeholder' ) ) 82 evt.data.preventDefault(); 83 }); 84 }); 85 86 CKEDITOR.dialog.add( 'createplaceholder', this.path + 'dialogs/placeholder.js' ); 87 CKEDITOR.dialog.add( 'editplaceholder', this.path + 'dialogs/placeholder.js' ); 88 }, 89 afterInit : function( editor ) 90 { 91 var dataProcessor = editor.dataProcessor, 92 dataFilter = dataProcessor && dataProcessor.dataFilter; 93 htmlFilter = dataProcessor && dataProcessor.htmlFilter; 94 95 if ( dataFilter ) 96 { 97 dataFilter.addRules( 98 { 99 text : function( text ) 100 { 101 return text.replace( placeholderReplaceRegex, function( match ) 102 { 103 return CKEDITOR.plugins.placeholder.createPlaceholder( editor, null, match, 1 ); 104 }); 105 } 106 }); 107 } 108 109 if ( htmlFilter ) 110 { 111 htmlFilter.addRules( 112 { 113 elements : 114 { 115 'span' : function( element ) 116 { 117 if ( element.attributes && element.attributes._cke_placeholder ) 118 delete element.name; 119 } 120 } 121 }); 122 } 123 } 124 }); 125 })(); 126 127 CKEDITOR.plugins.placeholder = 128 { 129 createPlaceholder : function( editor, oldElement, text, isGet ) 130 { 131 var element = new CKEDITOR.dom.element( 'span', editor.document ); 132 element.setAttributes( 133 { 134 contentEditable : 'false', 135 _cke_placeholder : 1, 136 'class' : 'cke_placeholder' 137 } 138 ); 139 140 text && element.setText( text ); 141 142 if ( isGet ) 143 return element.getOuterHtml(); 144 145 if ( oldElement ) 146 { 147 if ( CKEDITOR.env.ie ) 148 { 149 element.insertAfter( oldElement ); 150 // Some time is required for IE before the element is removed. 151 setTimeout( function() 152 { 153 oldElement.remove(); 154 element.focus(); 155 }, 10 ); 156 } 157 else 158 element.replace( oldElement ); 159 } 160 else 161 editor.insertElement( element ); 162 } 163 };