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


CKEDITOR.plugins.addExternal( 'savetemppage', 'wb_ckeplugins/savetemppage/' );
CKEDITOR.plugins.addExternal( 'closeeditor', 'wb_ckeplugins/closeeditor/' );
CKEDITOR.plugins.addExternal( 'insertscript', 'wb_ckeplugins/insertscript/' );
CKEDITOR.plugins.addExternal( 'browser', 'wb_ckeplugins/browser/' );
CKEDITOR.plugins.addExternal( 'lightbox', 'wb_ckeplugins/lightbox/' );
CKEDITOR.plugins.addExternal( 'flashplayer', 'wb_ckeplugins/flashplayer/' );
CKEDITOR.plugins.addExternal( 'formchanges', 'wb_ckeplugins/formchanges/' );
CKEDITOR.plugins.addExternal( 'formfields', 'wb_ckeplugins/formfields/' );
CKEDITOR.plugins.addExternal( 'formsendto', 'wb_ckeplugins/formsendto/' );
CKEDITOR.plugins.addExternal( 'internpage', 'wb_ckeplugins/internpage/' );
CKEDITOR.plugins.addExternal( 'googlemap', 'wb_ckeplugins/googlemap/' );
CKEDITOR.plugins.addExternal( 'imageedit', 'wb_ckeplugins/imageedit/' );
CKEDITOR.plugins.addExternal( 'disabletoolbar', 'wb_ckeplugins/disabletoolbar/' );
CKEDITOR.plugins.addExternal( 'measuretool', 'wb_ckeplugins/measuretool/' );
CKEDITOR.plugins.addExternal( 'sortmenu', 'wb_ckeplugins/sortmenu/' );

CKEDITOR.plugins.addExternal( 'divarea', 'wb_ckeplugins/divarea/' );
CKEDITOR.plugins.addExternal( 'dragresize', 'wb_ckeplugins/dragresize/' );
CKEDITOR.plugins.addExternal( 'showprotected', 'wb_ckeplugins/showprotected/' );
CKEDITOR.plugins.addExternal( 'sourcedialog', 'wb_ckeplugins/sourcedialog/' );


CKEDITOR.editorConfig = function( config )
{
	config.docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	config.skin = 'wbmoono,wb_ckeskin/wbmoono/';
	config.title = false;
	config.disableAutoInline = true;
	config.allowedContent = true;
	config.dialog_noConfirmCancel = true;
	config.toolbarCanCollapse = false;
	config.baseFloatZIndex = 9000;
	config.entities = false;
	config.startupShowBorders = true;
	config.emailProtection = 'encode';
	config.stylesSet = [];
	
	//config.disableObjectResizing = true;
	//config.disableNativeTableHandles = true;
	
	config.fillEmptyBlocks = true;
	config.autoParagraph = false;
	config.ignoreEmptyParagraph = true;
	config.forceEnterMode = true; // p on enter inside div
	
	//config.pasteFromWordRemoveStyles = true;
	//config.pasteFromWordRemoveFontStyles = true;
	config.forcePasteAsPlainText = true;
	
    config.templates = 'usertemplates';
    config.templates_files = [ 'content/pattern/js/cketemplates.js' ];
	
	config.protectedSource.push( /<\?[\s\S]*?\?>/gi );
	config.protectedSource.push( /<script[\s\S]*?\/script>/gi );
	
	config.format_tags = 'p;div;h1;h2;h3;h4;h5;h6';
	config.fontSize_sizes = '7 Pixel/7px;8 Pixel/8px;9 Pixel/9px;10 Pixel/10px;11 Pixel/11px;12 Pixel/12px;13 Pixel/13px;14 Pixel/14px;15 Pixel/15px;16 Pixel/16px;17 Pixel/17px;18 Pixel/18px;19 Pixel/19px;20 Pixel/20px;21 Pixel/21px;22 Pixel/22px;23 Pixel/23px;24 Pixel/24px;25 Pixel/25px;26 Pixel/26px;27 Pixel/27px;28 Pixel/28px;29 Pixel/29px;30 Pixel/30px;31 Pixel/31px;32 Pixel/32px';
	config.font_style =
    {
        element : 'span',
        styles : { 'font-family': '#(family)' },
        overrides : [ { element: 'font', attributes: { 'face': null } } ]
    };
	
	config.menu_groups = 'clipboard,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,imgedit,editprotected,flash,inscode,div,form,formfelder,googlemaps,textfield,textarea,select,checkbox,radio,hiddenfield,button,imagebutton,sendtofield';
	
    config.filebrowserBrowseUrl = 'admin/browser/index.php';
    config.filebrowserImageBrowseUrl = 'admin/browser/index.php?type=image&actualfolder=%2F';
    config.filebrowserImageBrowseLinkUrl = 'admin/browser/index.php?types=image&actualfolder=%2F';
    config.filebrowserFlashBrowseUrl = 'admin/browser/index.php?type=flash&actualfolder=%2F';
	config.filebrowserWindowFeatures = 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes';
    
    config.toolbar_EditPage =
    [
    	['Savetemp','Save','Closer','DocProps','InsertScript','Templates'],
    	['Cut','Copy','Paste'],
    	['Undo','Redo','Find','Replace','SelectAll','RemoveFormat'],
    	['Bold','Italic','Underline','Strike','Subscript','Superscript'],
    	['NumberedList','BulletedList','Outdent','Indent','BidiLtr', 'BidiRtl','Blockquote'],
    	['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    	['TextColor','BGColor'],
    	['Link','Unlink','Anchor'],
    	['Media','Image','Flash','Iframe','gMap'],
    	['Table','CreateDiv','Form','HorizontalRule','ShowBlocks','SpecialChar'],
    	['Styles','Format','Font','FontSize'],
    	['Sourcedialog']
    ] ;
    
    config.toolbar_EditMenu =
    [
    	['Save','Closer'],
    	['SortMenu'],
    	['Cut','Copy','Paste'],
    	['Undo','Redo','RemoveFormat'],
    	['Bold','Italic','Underline','Strike'],
    	['BulletedList','Outdent','Indent','BidiLtr', 'BidiRtl'],
    	['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    	['TextColor','BGColor'],
    	['Link','Unlink'],
    	['Image','ShowBlocks','SpecialChar'],
    	['Sourcedialog']
    ] ;
    
    config.toolbar_EditBlock =
    [
    	['Save','Closer','Templates'],
    	['Cut','Copy','Paste'],
    	['Undo','Redo','Find','Replace','SelectAll','RemoveFormat'],
    	['Bold','Italic','Underline','Strike','Subscript','Superscript'],
    	['NumberedList','BulletedList','Outdent','Indent','BidiLtr', 'BidiRtl','Blockquote'],
    	['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    	['TextColor','BGColor'],
    	['Link','Unlink','Anchor'],
    	['Media','Image','Flash','Iframe','gMap'],
    	['Table','CreateDiv','Form','HorizontalRule','ShowBlocks','SpecialChar'],
    	['Styles','Format','Font','FontSize'],
    	['Sourcedialog']
    ] ;

    config.toolbar_EditContent =
    [
    	['Savetemp','Save','Closer','DocProps','InsertScript','Templates'],
    	['Cut','Copy','Paste'],
    	['Undo','Redo','Find','Replace','SelectAll','RemoveFormat','Measure'],
    	['Bold','Italic','Underline','Strike','Subscript','Superscript'],
    	['NumberedList','BulletedList','Outdent','Indent','BidiLtr', 'BidiRtl','Blockquote'],
    	['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    	['TextColor','BGColor'],
    	['Link','Unlink','Anchor'],
    	['Media','Image','Flash','Iframe','gMap'],
    	['Table','CreateDiv','Form','HorizontalRule','ShowBlocks','SpecialChar'],
    	['Styles','Format','Font','FontSize'],
    	['Sourcedialog']
    ] ;
};

CKEDITOR.on('dialogDefinition', function( ev )
{
    var dialogName = ev.data.name;
    var dialogDefinition = ev.data.definition;
    var editor = ev.editor;
    
	dialogDefinition.resizable = CKEDITOR.DIALOG_RESIZE_NONE;
    
    if(dialogName === 'table')
    {
        var infoTab = dialogDefinition.getContents('info');
        var cellSpacing = infoTab.get('txtCellSpace');
        cellSpacing['default'] = "0";
        var cellPadding = infoTab.get('txtCellPad');
        cellPadding['default'] = "0";
        var border = infoTab.get('txtBorder');
        border['default'] = "0";
    }
    
    if(dialogName === 'flash')
    {
        var infoTab = dialogDefinition.getContents('info');
        var browseButton = infoTab.get('browse');
        browseButton['style'] = 'margin-top: 15px;';
        var previewField = infoTab.get('preview');
        previewField['style'] = 'width: 420px;';
        
        var propertiesTab = dialogDefinition.getContents('properties');
		var menuField = propertiesTab.get( 'menu' );
		menuField['default'] = false;
		var playField = propertiesTab.get( 'play' );
		playField['default'] = false;
		var loopField = propertiesTab.get( 'loop' );
		loopField['default'] = false;
		var allowFullScreenField = propertiesTab.get( 'allowFullScreen' );
		allowFullScreenField['default'] = true;
    }
    
    if(dialogName === 'image')
    {
        var infoTab = dialogDefinition.getContents('info');
        var browseButton = infoTab.get('browse');
        browseButton['style'] = 'margin-top: 15px;';
		
        var linkTab = dialogDefinition.getContents('Link');
        var browseButton = linkTab.get('browse');
        browseButton['style'] = 'float: right; margin: 10px 0px;';
    }
    
    if(dialogName === 'link')
    {
        var infoTab = dialogDefinition.getContents('info');
        var browseButton = infoTab.get('browse');
        browseButton['style'] = 'float: right;';
    }
    
    if(dialogName === 'templates')
    {
        var selTplTab = dialogDefinition.getContents('selectTpl');
		var chkInsertOptField = selTplTab.get( 'chkInsertOpt' );
        chkInsertOptField['default'] = false;
        chkInsertOptField['style'] = 'display: none;';
    }
    
    if(dialogName === 'docProps')
    {
		dialogDefinition.minHeight = 325;
		dialogDefinition.minWidth = 400;
		dialogDefinition.removeContents( 'design' );
		dialogDefinition.removeContents( 'preview' );
    }
    
    if(dialogName === 'form')
    {
        var url = window.location.href;
        var query = url.substring(url.indexOf('\?'), url.length);
        
        var infoTab = dialogDefinition.getContents('info');
        
		var actionField = infoTab.get( 'action' );
        actionField['default'] = 'index.php' + query;
		var dataField = infoTab.get( 'enctype' );
        dataField['default'] = 'multipart/form-data';
		var methodField = infoTab.get( 'method' );
        methodField['default'] = 'post';
    }
});














