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