/*
 *  "showprotected" CKEditor plugin
 *  Created by Matthew Lieder (https://github.com/IGx89)
 *  Licensed under the MIT, GPL, LGPL and MPL licenses
 *  Icon courtesy of famfamfam: http://www.famfamfam.com/lab/icons/mini/
 */

CKEDITOR.plugins.add('showprotected',{lang:[CKEDITOR.lang.detect(CKEDITOR.config.language)],requires:'dialog,fakeobjects',onLoad:function(){var iconPath=CKEDITOR.getUrl(this.path+'/code.png'),baseStyle='background:url('+iconPath+') no-repeat %1 center;background-size:16px;';var template='.%2 img.cke_protected'+'{'+
baseStyle+'width:16px;'+'min-height:15px;'+'margin-top:-10px;'+'height:1.15em;'+'vertical-align:'+(CKEDITOR.env.opera?'middle':'text-bottom')+';'+'}';function cssWithDir(dir){return template.replace(/%1/g,dir=='rtl'?'right':'left').replace(/%2/g,'cke_contents_'+dir);}
CKEDITOR.addCss(cssWithDir('ltr')+cssWithDir('rtl'));},init:function(editor){CKEDITOR.dialog.add('showProtectedDialog',this.path+'dialogs/protected.js');editor.addCommand('editprotected',new CKEDITOR.dialogCommand('showProtectedDialog'));if(editor.addMenuItems){editor.addMenuItems({editprotected:{label:editor.lang.showprotected.editprotected,command:'editprotected',icon:this.path+'/edit.png',group:'editprotected'}});}
if(editor.contextMenu){editor.contextMenu.addListener(function(element,selection){if(element.is('img')&&element.hasClass('cke_protected')){return{editprotected:CKEDITOR.TRISTATE_OFF};}});}
editor.on('doubleclick',function(evt){var element=evt.data.element;if(element.is('img')&&element.hasClass('cke_protected')){evt.data.dialog='showProtectedDialog';editor.execCommand('enableObjectResizing',false,false);}});},afterInit:function(editor){var dataProcessor=editor.dataProcessor,dataFilter=dataProcessor&&dataProcessor.dataFilter;if(dataFilter){dataFilter.addRules({comment:function(commentText,commentElement){if(commentElement.getAscendant('head')==null&&commentText.indexOf(CKEDITOR.plugins.showprotected.protectedSourceMarker)==0){commentElement.attributes=[];var fakeElement=editor.createFakeParserElement(commentElement,'cke_protected','protected',false);return fakeElement;}
return null;}});}}});CKEDITOR.plugins.showprotected={protectedSourceMarker:'{cke_protected}',decodeProtectedSource:function(protectedSource){return decodeURIComponent(protectedSource).replace(/<!--\{cke_protected\}([\s\S]+?)-->/gi,function(match,data){return decodeURIComponent(data);});},encodeProtectedSource:function(protectedSource){return'<!--'+CKEDITOR.plugins.showprotected.protectedSourceMarker+
encodeURIComponent(protectedSource).replace(/--/g,'%2D%2D')+'-->';}};