2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The "placeholder" plugin.
\r
13 var placeholderReplaceRegex = /\[\[[^\]]+\]\]/g;
\r
14 CKEDITOR.plugins.add( 'placeholder',
\r
16 requires : [ 'dialog' ],
\r
17 lang : [ 'bg', 'cs', 'cy', 'da', 'de', 'el', 'en', 'eo', 'et', 'fa', 'fi', 'fr', 'he', 'hr', 'it', 'ku', 'nb', 'nl', 'no', 'pl', 'pt-br', 'sk', 'tr', 'ug', 'uk', 'vi', 'zh-cn' ],
\r
18 init : function( editor )
\r
20 var lang = editor.lang.placeholder;
\r
22 editor.addCommand( 'createplaceholder', new CKEDITOR.dialogCommand( 'createplaceholder' ) );
\r
23 editor.addCommand( 'editplaceholder', new CKEDITOR.dialogCommand( 'editplaceholder' ) );
\r
25 editor.ui.addButton( 'CreatePlaceholder',
\r
27 label : lang.toolbar,
\r
28 command :'createplaceholder',
\r
29 icon : this.path + 'placeholder.gif'
\r
32 if ( editor.addMenuItems )
\r
34 editor.addMenuGroup( 'placeholder', 20 );
\r
35 editor.addMenuItems(
\r
40 command : 'editplaceholder',
\r
41 group : 'placeholder',
\r
43 icon : this.path + 'placeholder.gif'
\r
47 if ( editor.contextMenu )
\r
49 editor.contextMenu.addListener( function( element, selection )
\r
51 if ( !element || !element.data( 'cke-placeholder' ) )
\r
54 return { editplaceholder : CKEDITOR.TRISTATE_OFF };
\r
59 editor.on( 'doubleclick', function( evt )
\r
61 if ( CKEDITOR.plugins.placeholder.getSelectedPlaceHoder( editor ) )
\r
62 evt.data.dialog = 'editplaceholder';
\r
66 '.cke_placeholder' +
\r
68 'background-color: #ffff00;' +
\r
69 ( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) +
\r
73 editor.on( 'contentDom', function()
\r
75 editor.document.getBody().on( 'resizestart', function( evt )
\r
77 if ( editor.getSelection().getSelectedElement().data( 'cke-placeholder' ) )
\r
78 evt.data.preventDefault();
\r
82 CKEDITOR.dialog.add( 'createplaceholder', this.path + 'dialogs/placeholder.js' );
\r
83 CKEDITOR.dialog.add( 'editplaceholder', this.path + 'dialogs/placeholder.js' );
\r
85 afterInit : function( editor )
\r
87 var dataProcessor = editor.dataProcessor,
\r
88 dataFilter = dataProcessor && dataProcessor.dataFilter,
\r
89 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
93 dataFilter.addRules(
\r
95 text : function( text )
\r
97 return text.replace( placeholderReplaceRegex, function( match )
\r
99 return CKEDITOR.plugins.placeholder.createPlaceholder( editor, null, match, 1 );
\r
107 htmlFilter.addRules(
\r
111 'span' : function( element )
\r
113 if ( element.attributes && element.attributes[ 'data-cke-placeholder' ] )
\r
114 delete element.name;
\r
123 CKEDITOR.plugins.placeholder =
\r
125 createPlaceholder : function( editor, oldElement, text, isGet )
\r
127 var element = new CKEDITOR.dom.element( 'span', editor.document );
\r
128 element.setAttributes(
\r
130 contentEditable : 'false',
\r
131 'data-cke-placeholder' : 1,
\r
132 'class' : 'cke_placeholder'
\r
136 text && element.setText( text );
\r
139 return element.getOuterHtml();
\r
143 if ( CKEDITOR.env.ie )
\r
145 element.insertAfter( oldElement );
\r
146 // Some time is required for IE before the element is removed.
\r
147 setTimeout( function()
\r
149 oldElement.remove();
\r
154 element.replace( oldElement );
\r
157 editor.insertElement( element );
\r
162 getSelectedPlaceHoder : function( editor )
\r
164 var range = editor.getSelection().getRanges()[ 0 ];
\r
165 range.shrink( CKEDITOR.SHRINK_TEXT );
\r
166 var node = range.startContainer;
\r
167 while( node && !( node.type == CKEDITOR.NODE_ELEMENT && node.data( 'cke-placeholder' ) ) )
\r
168 node = node.getParent();
\r