
/**************************************
    Webutler V3.0 - www.webutler.de
    Copyright (c) 2008 - 2014
    Autor: Sven Zinke
    Free for any use
    Lizenz: GPL
**************************************/

(function()
{CKEDITOR.plugins.add('formchanges',{init:function(editor)
{CKEDITOR.addCss('img.cke_radio, img.cke_radio_checked, img.cke_checkbox, img.cke_checkbox_checked {'+'    background-position: center center;'+'    background-repeat: no-repeat;'+'    width: 16px;'+'    height: 16px;'+'}'+'img.cke_radio {'+'    background-image: url('+CKEDITOR.getUrl(this.path+'images/radio_off.png')+');'+'}'+'img.cke_radio_checked {'+'    background-image: url('+CKEDITOR.getUrl(this.path+'images/radio_on.png')+');'+'}'+'img.cke_checkbox {'+'    background-image: url('+CKEDITOR.getUrl(this.path+'images/checkbox_off.png')+');'+'}'+'img.cke_checkbox_checked {'+'    background-image: url('+CKEDITOR.getUrl(this.path+'images/checkbox_on.png')+');'+'}'+'img.cke_select, img.cke_selects, img.cke_inputtext, img.cke_textarea {'+'    background-color: #fff;'+'    background-repeat: no-repeat;'+'    outline: 1px solid #787878;'+'}'+'img.cke_select {'+'    background-image: url('+CKEDITOR.getUrl(this.path+'images/select.png')+');'+'    background-position: center right;'+'    width: 150px;'+'    height: 18px;'+'}'+'img.cke_selects {'+'    background-image: url('+CKEDITOR.getUrl(this.path+'images/selects.png')+');'+'    background-position: center right;'+'    width: 150px;'+'    height: 54px;'+'}'+'img.cke_inputtext {'+'    width: 200px;'+'    height: 18px;'+'}'+'img.cke_textarea {'+'    background-image: url('+CKEDITOR.getUrl(this.path+'images/textarea.png')+');'+'    background-position: bottom right;'+'    width: 200px;'+'    height: 72px;'+'}');editor.on('doubleclick',function(evt)
{var element=evt.data.element;if(element.hasClass('cke_radio')||element.hasClass('cke_radio_checked'))
evt.data.dialog='radio';else if(element.hasClass('cke_checkbox')||element.hasClass('cke_checkbox_checked'))
evt.data.dialog='checkbox';else if(element.hasClass('cke_select')||element.hasClass('cke_selects'))
evt.data.dialog='select';else if(element.hasClass('cke_inputtext'))
evt.data.dialog='textfield';else if(element.hasClass('cke_textarea'))
evt.data.dialog='textarea';else
return null;});if(editor.contextMenu)
{editor.contextMenu.addListener(function(element,selection)
{if(element&&element.data('cke-real-element-type')=='radiofield'&&(element.hasClass('cke_radio')||element.hasClass('cke_radio_checked')))
return{radio:CKEDITOR.TRISTATE_OFF};else if(element&&element.data('cke-real-element-type')=='checkboxfield'&&(element.hasClass('cke_checkbox')||element.hasClass('cke_checkbox_checked')))
return{checkbox:CKEDITOR.TRISTATE_OFF};else if(element&&element.data('cke-real-element-type')=='selectfield'&&(element.hasClass('cke_select')||element.hasClass('cke_selects')))
return{select:CKEDITOR.TRISTATE_OFF};else if(element&&element.data('cke-real-element-type')=='inputtextfield'&&(element.hasClass('cke_inputtext')))
return{textfield:CKEDITOR.TRISTATE_OFF};else if(element&&element.data('cke-real-element-type')=='textareafield'&&(element.hasClass('cke_textarea')))
return{textarea:CKEDITOR.TRISTATE_OFF};else
return null;});}},afterInit:function(editor)
{var dataProcessor=editor.dataProcessor,dataFilter=dataProcessor&&dataProcessor.dataFilter;if(dataFilter)
{dataFilter.addRules({elements:{input:function(element)
{var attributes=element.attributes;switch(attributes.type)
{case'radio':if(attributes.checked)
return editor.createFakeParserElement(element,'cke_radio_checked','radiofield',false);else
return editor.createFakeParserElement(element,'cke_radio','radiofield',false);break;case'checkbox':if(attributes.checked)
return editor.createFakeParserElement(element,'cke_checkbox_checked','checkboxfield',false);else
return editor.createFakeParserElement(element,'cke_checkbox','checkboxfield',false);break;case'text':case'email':case'password':case'search':case'tel':case'url':return editor.createFakeParserElement(element,'cke_inputtext','inputtextfield',false);break;}},select:function(element)
{var attributes=element.attributes;if(attributes.size>=2)
return editor.createFakeParserElement(element,'cke_selects','selectfield',false);else
return editor.createFakeParserElement(element,'cke_select','selectfield',false);},textarea:function(element)
{return editor.createFakeParserElement(element,'cke_textarea','textareafield',false);}}});}},requires:['fakeobjects']});CKEDITOR.on('dialogDefinition',function(ev)
{var dialogName=ev.data.name;var dialogDefinition=ev.data.definition;var editor=ev.editor;function checkAttrs(oldelm,element){if(oldelm.hasAttribute('id')){var value=oldelm.getAttribute('id');element.setAttribute('id',value);}
if(oldelm.hasAttribute('class')){var value=oldelm.getAttribute('class');element.setAttribute('class',value);}
if(oldelm.hasAttribute('style')){var value=oldelm.getAttribute('style');element.setAttribute('style',value);}
return element;}
if(dialogName=='radio')
{dialogDefinition.onLoad=function()
{var dialog=CKEDITOR.dialog.getCurrent();dialog.on('show',function()
{delete this.radioField;delete this.orgRadioField;var selection=editor.getSelection(),element=selection.getSelectedElement();if(element&&element.data('cke-real-element-type')&&element.data('cke-real-element-type')=='radiofield')
{this.radioField=element;element=editor.restoreRealElement(this.radioField);this.orgRadioField=element;this.setupContent(element);selection.selectElement(this.radioField);}});};dialogDefinition.onOk=function()
{var dialog=CKEDITOR.dialog.getCurrent();var element=this.radioField,isInsertMode=!element,isChecked=(dialog.getValueOf('info','checked')==true)?true:false;element=editor.document.createElement('input');element.setAttribute('type','radio');if(!isInsertMode)
element=checkAttrs(this.orgRadioField,element);var fakeType;if(!isChecked)
{fakeType='cke_radio';element.removeAttribute('checked');}
else
{fakeType='cke_radio_checked';element.setAttribute('checked','checked');}
dialog.commitContent({element:element});var fakeElement=editor.createFakeElement(element,fakeType,'radiofield',false);if(isInsertMode)
{editor.insertElement(fakeElement);}
else
{fakeElement.replace(this.radioField);editor.getSelection().selectElement(fakeElement);}
return true;};}
if(dialogName=='checkbox')
{dialogDefinition.onLoad=function()
{var dialog=CKEDITOR.dialog.getCurrent();dialog.on('show',function()
{delete this.checkboxField;delete this.orgCheckboxField;var selection=editor.getSelection(),element=selection.getSelectedElement();if(element&&element.data('cke-real-element-type')&&element.data('cke-real-element-type')=='checkboxfield')
{this.checkboxField=element;element=editor.restoreRealElement(this.checkboxField);this.orgCheckboxField=element;this.setupContent(element);selection.selectElement(this.checkboxField);}});};dialogDefinition.onOk=function()
{var dialog=CKEDITOR.dialog.getCurrent();var element=this.checkboxField,isInsertMode=!element,isChecked=(dialog.getValueOf('info','cmbSelected')==true)?true:false;element=editor.document.createElement('input');element.setAttribute('type','checkbox');if(!isInsertMode)
element=checkAttrs(this.orgCheckboxField,element);var fakeType;if(!isChecked)
{fakeType='cke_checkbox';element.removeAttribute('checked');}
else
{fakeType='cke_checkbox_checked';element.setAttribute('checked','checked');}
this.commitContent({element:element});var fakeElement=editor.createFakeElement(element,fakeType,'checkboxfield',false);if(isInsertMode)
{editor.insertElement(fakeElement);}
else
{fakeElement.replace(this.checkboxField);editor.getSelection().selectElement(fakeElement);}
return true;};}
if(dialogName=='select')
{function getOptions(combo)
{combo=getSelect(combo);return combo?combo.getChildren():false;}
function getSelect(obj)
{if(obj&&obj.domId&&obj.getInputElement().$)
return obj.getInputElement();else if(obj&&obj.$)
return obj;return false;}
dialogDefinition.onShow=function()
{delete this.selectBox;delete this.orgSelectBox;this.setupContent('clear');var selection=editor.getSelection(),element=selection.getSelectedElement();if(element&&element.data('cke-real-element-type')&&element.data('cke-real-element-type')=='selectfield')
{this.selectBox=element;element=editor.restoreRealElement(this.selectBox);this.orgSelectBox=element;this.setupContent('select',element);var objOptions=getOptions(element);for(var i=0;i<objOptions.count();i++)
this.setupContent('option',objOptions.getItem(i));selection.selectElement(this.selectBox);}};dialogDefinition.onOk=function()
{var element=this.selectBox,isInsertMode=!element;element=editor.document.createElement('select');if(!isInsertMode)
element=checkAttrs(this.orgSelectBox,element);this.commitContent(element);var fakeSelect;if(element.getAttribute('size')>=2)
{fakeSelect='cke_selects';}
else
{fakeSelect='cke_select';}
var fakeElement=editor.createFakeElement(element,fakeSelect,'selectfield',false);if(isInsertMode)
{editor.insertElement(fakeElement);}
else
{fakeElement.replace(this.selectBox);editor.getSelection().selectElement(fakeElement);}};}
if(dialogName=='textfield')
{dialogDefinition.onLoad=function()
{var dialog=CKEDITOR.dialog.getCurrent();dialog.on('show',function()
{delete this.inputtextField;delete this.orgInputtextField;var selection=editor.getSelection(),element=selection.getSelectedElement();if(element&&element.data('cke-real-element-type')&&element.data('cke-real-element-type')=='inputtextfield')
{this.inputtextField=element;element=editor.restoreRealElement(this.inputtextField);this.orgInputtextField=element;this.setupContent(element);selection.selectElement(this.inputtextField);}});};dialogDefinition.onOk=function()
{var element=this.inputtextField,isInsertMode=!element;element=editor.document.createElement('input');element.setAttribute('type','text');if(!isInsertMode)
element=checkAttrs(this.orgInputtextField,element);var data={element:element};this.commitContent(data);var fakeElement=editor.createFakeElement(data.element,'cke_inputtext','inputtextfield',false);if(isInsertMode)
{editor.insertElement(fakeElement);}
else
{fakeElement.replace(this.inputtextField);editor.getSelection().selectElement(fakeElement);}
return true;};}
if(dialogName=='textarea')
{dialogDefinition.onLoad=function()
{var dialog=CKEDITOR.dialog.getCurrent();dialog.on('show',function()
{delete this.textareaField;delete this.orgTextareaField;var selection=editor.getSelection(),element=selection.getSelectedElement();if(element&&element.data('cke-real-element-type')&&element.data('cke-real-element-type')=='textareafield')
{this.textareaField=element;element=editor.restoreRealElement(this.textareaField);this.orgTextareaField=element;this.setupContent(element);selection.selectElement(this.textareaField);}});};dialogDefinition.onOk=function()
{var element=this.textarea,isInsertMode=!element;element=editor.document.createElement('textarea');if(!isInsertMode)
element=checkAttrs(this.orgTextareaField,element);this.commitContent(element);var fakeElement=editor.createFakeElement(element,'cke_textarea','textareafield',false);if(isInsertMode)
{editor.insertElement(fakeElement);}
else
{fakeElement.replace(this.textareaField);editor.getSelection().selectElement(fakeElement);}};}});})();