6e25bd1d7703c4520b3dbb53205240acd8c47552.svn-base
4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
* @fileOverview The "placeholder" plugin.
*
*/
(function()
{
var placeholderReplaceRegex = /\[\[[^\]]+\]\]/g;
CKEDITOR.plugins.add( 'placeholder',
{
requires : [ 'dialog' ],
lang : [ 'bg', 'cs', 'cy', 'da', 'de', 'el', 'en', 'eo', 'et', 'fa', 'fi', 'fr', 'he', 'hr', 'it', 'nb', 'nl', 'no', 'pl', 'pt-br', 'tr', 'ug', 'uk', 'vi', 'zh-cn' ],
init : function( editor )
{
var lang = editor.lang.placeholder;
editor.addCommand( 'createplaceholder', new CKEDITOR.dialogCommand( 'createplaceholder' ) );
editor.addCommand( 'editplaceholder', new CKEDITOR.dialogCommand( 'editplaceholder' ) );
editor.ui.addButton( 'CreatePlaceholder',
{
label : lang.toolbar,
command :'createplaceholder',
icon : this.path + 'placeholder.gif'
});
if ( editor.addMenuItems )
{
editor.addMenuGroup( 'placeholder', 20 );
editor.addMenuItems(
{
editplaceholder :
{
label : lang.edit,
command : 'editplaceholder',
group : 'placeholder',
order : 1,
icon : this.path + 'placeholder.gif'
}
} );
if ( editor.contextMenu )
{
editor.contextMenu.addListener( function( element, selection )
{
if ( !element || !element.data( 'cke-placeholder' ) )
return null;
return { editplaceholder : CKEDITOR.TRISTATE_OFF };
} );
}
}
editor.on( 'doubleclick', function( evt )
{
if ( CKEDITOR.plugins.placeholder.getSelectedPlaceHoder( editor ) )
evt.data.dialog = 'editplaceholder';
});
editor.addCss(
'.cke_placeholder' +
'{' +
'background-color: #ffff00;' +
( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) +
'}'
);
editor.on( 'contentDom', function()
{
editor.document.getBody().on( 'resizestart', function( evt )
{
if ( editor.getSelection().getSelectedElement().data( 'cke-placeholder' ) )
evt.data.preventDefault();
});
});
CKEDITOR.dialog.add( 'createplaceholder', this.path + 'dialogs/placeholder.js' );
CKEDITOR.dialog.add( 'editplaceholder', this.path + 'dialogs/placeholder.js' );
},
afterInit : function( editor )
{
var dataProcessor = editor.dataProcessor,
dataFilter = dataProcessor && dataProcessor.dataFilter,
htmlFilter = dataProcessor && dataProcessor.htmlFilter;
if ( dataFilter )
{
dataFilter.addRules(
{
text : function( text )
{
return text.replace( placeholderReplaceRegex, function( match )
{
return CKEDITOR.plugins.placeholder.createPlaceholder( editor, null, match, 1 );
});
}
});
}
if ( htmlFilter )
{
htmlFilter.addRules(
{
elements :
{
'span' : function( element )
{
if ( element.attributes && element.attributes[ 'data-cke-placeholder' ] )
delete element.name;
}
}
});
}
}
});
})();
CKEDITOR.plugins.placeholder =
{
createPlaceholder : function( editor, oldElement, text, isGet )
{
var element = new CKEDITOR.dom.element( 'span', editor.document );
element.setAttributes(
{
contentEditable : 'false',
'data-cke-placeholder' : 1,
'class' : 'cke_placeholder'
}
);
text && element.setText( text );
if ( isGet )
return element.getOuterHtml();
if ( oldElement )
{
if ( CKEDITOR.env.ie )
{
element.insertAfter( oldElement );
// Some time is required for IE before the element is removed.
setTimeout( function()
{
oldElement.remove();
element.focus();
}, 10 );
}
else
element.replace( oldElement );
}
else
editor.insertElement( element );
return null;
},
getSelectedPlaceHoder : function( editor )
{
var range = editor.getSelection().getRanges()[ 0 ];
range.shrink( CKEDITOR.SHRINK_TEXT );
var node = range.startContainer;
while( node && !( node.type == CKEDITOR.NODE_ELEMENT && node.data( 'cke-placeholder' ) ) )
node = node.getParent();
return node;
}
};