2 * The "blockprotect" plugin. Adapted from the "placeholder" plugin.
9 var create_block = function(content) {
11 content = content.replace(/ /gi, ' ');
13 var el = document.createElement('SPAN');
15 if( typeof(el.textContent) != 'undefined' ) {
16 el.textContent = content;
17 } else if( typeof(el.innerText) != 'undefined' ) {
18 el.innerText = content;
20 el.setAttribute('class', 'cke_blockprotect');
23 var block_writeHtml = function( element ) {
24 // to unescape the element contents, write it out as HTML,
25 // stick that into a SPAN element, and then extract the text
27 var inner_writer = new CKEDITOR.htmlParser.basicWriter;
28 element.writeChildrenHtml(inner_writer);
30 var el = document.createElement('SPAN');
31 el.innerHTML = inner_writer.getHtml();
32 if( typeof(el.textContent) != 'undefined' ) {
33 return el.textContent;
34 } else if( typeof(el.innerText) != 'undefined' ) {
38 var to_protected_html = function(data) {
42 var p = 0; // position in the string
44 // find the next delimiter of either kind
45 var i = data.indexOf(delim_o, p);
46 var j = data.indexOf(delim_c, p);
47 if (i == -1 && j == -1) {
48 // then there are no more delimiters
50 } else if ((i < j || j == -1) && i != -1) {
51 // next delimiter is an open
52 // push everything from current position to
54 if ( i > p ) chunk += data.substr(p, i - p);
57 // start of a protected block
63 } else if ((j < i || i == -1) && j != -1) {
64 // next delimiter is a close
65 if ( j > p ) chunk += data.substr(p, j - p);
70 // end of a protected block
71 out += create_block(chunk);
73 } else if ( depth < 0 ) {
80 // append any text after the last delimiter
82 out += create_block(data.substr(p));
84 out += data.substr(p);
89 CKEDITOR.plugins.add( 'blockprotect', {
90 afterInit: function( editor ) {
91 CKEDITOR.addCss( '.cke_blockprotect' +
93 'background-color: #ffff88;' +
94 ( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) +
98 // keep these from getting stripped out
99 editor.filter.allow('span(cke_blockprotect)',
100 'blockprotect', true);
102 // add filter at the front of toHtml
106 to_protected_html(evt.data.dataValue);
112 editor.dataProcessor.htmlFilter.addRules({
114 span: function( element ) {
115 if ( element.className = 'cke_blockprotect' ) {
116 // defeat HTML escaping
117 var content = block_writeHtml(element);
118 element.writeHtml = function(writer, filter) {
119 writer.text(content);