2 * The "blockprotect" plugin. Adapted from the "placeholder" plugin.
9 var create_block = function(content, inside) {
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');
22 return el.innerHTML; // escapes the contents but doesn't wrap
28 var block_writeHtml = function( element ) {
29 // to unescape the element contents, write it out as HTML,
30 // stick that into a SPAN element, and then extract the text
32 var inner_writer = new CKEDITOR.htmlParser.basicWriter;
33 element.writeChildrenHtml(inner_writer);
35 var el = document.createElement('SPAN');
36 el.innerHTML = inner_writer.getHtml();
37 if( typeof(el.textContent) != 'undefined' ) {
38 return el.textContent;
39 } else if( typeof(el.innerText) != 'undefined' ) {
43 var to_protected_html = function(data) {
48 var p = 0; // position in the string
50 // find the next delimiter of either kind
51 var i = data.indexOf(delim_o, p);
52 var j = data.indexOf(delim_c, p);
53 if (i == -1 && j == -1) {
54 // then there are no more delimiters
56 } else if ((i < j || j == -1) && i != -1) {
57 // next delimiter is an open
58 // push everything from current position to
60 if ( i > p ) chunk += data.substr(p, i - p);
63 // we're in document text. find whether an HTML tag starts,
64 // or ends, before the next delimiter, so that we know whether
65 // to output the next block in a SPAN or just as escaped text
66 for(var q = 0; q < chunk.length; q++ ) {
67 if (chunk[q] == '<') in_tag = true;
68 if (chunk[q] == '>') in_tag = false;
71 // then output the chunk, and go to the start of the
78 } else if ((j < i || i == -1) && j != -1) {
79 // next delimiter is a close
80 if ( j > p ) chunk += data.substr(p, j - p);
85 // end of a protected block
86 out += create_block(chunk, in_tag);
88 } else if ( depth < 0 ) {
95 // append any text after the last delimiter
97 out += create_block(data.substr(p), in_tag);
99 out += data.substr(p);
104 CKEDITOR.plugins.add( 'blockprotect', {
105 afterInit: function( editor ) {
106 CKEDITOR.addCss( '.cke_blockprotect' +
108 'background-color: #ffff88;' +
109 ( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) +
113 // keep these from getting stripped out
114 editor.filter.allow('span(cke_blockprotect)',
115 'blockprotect', true);
117 // add filter at the front of toHtml
121 to_protected_html(evt.data.dataValue);
127 editor.dataProcessor.htmlFilter.addRules({
129 span: function( element ) {
130 if ( element.className = 'cke_blockprotect' ) {
131 // defeat HTML escaping
132 var content = block_writeHtml(element);
133 element.writeHtml = function(writer, filter) {
134 writer.text(content);