CKEDITOR.plugins.add( 'cmslinkarticle', { init: function( editor ) { CKEDITOR.dialog.add( 'cmsLinkArticleDialog', function ( editor ) { return { title : 'Wstaw/Edytuj odnośnik do artykułu', minWidth : 400, minHeight : 200, resizable: CKEDITOR.DIALOG_RESIZE_NONE, contents : [ { id : 'tab1', label : 'Adres url:', elements : [ { type : 'text', id : 'url', label : 'Adres url:', validate : CKEDITOR.dialog.validate.notEmpty( "Adres url nie może być pusty." ), commit: function( element ) { var href = this.getValue(); if ( href ) { element.setAttribute("href", href); if ( !element.getText() ) { element.setText( this.getValue() ); } } } }, { type : 'text', id : 'text', label : 'Tekst odnośnika:', setup: function( element ) { this.setValue( element.getText() ); }, commit: function(element) { var currentValue = this.getValue(); if(currentValue !== "" && currentValue !== null) { element.setText(currentValue); } } }, { type : 'button', hidden : true, id : 'id0', label : editor.lang.common.browseServer, filebrowser : { action : 'Browse', url: '/admin/articles/browse_list/', onSelect : function( url ) { var dialog = this.getDialog(); dialog.getContentElement( 'tab1', 'url' ).setValue( url ); return false; } } } ] } ], onShow: function() { var selection = editor.getSelection(); var selector = selection.getStartElement(); var element; if ( selector ) { element = selector.getAscendant( 'a', true ); } if ( !element || element.getName() != 'a' ) { element = editor.document.createElement( 'a' ); if( selection ) { element.setText(selection.getSelectedText()); } this.insertMode = true; } else { this.insertMode = false; } this.element = element; this.setupContent(this.element); }, onOk : function() { var dialog = this; var anchorElement = this.element; this.commitContent(this.element); if(this.insertMode) { editor.insertElement(this.element); } } }; } ); editor.addCommand( 'cmsLinkArticleDialog',new CKEDITOR.dialogCommand( 'cmsLinkArticleDialog' ) ); editor.ui.addButton( 'cmslinkarticle', { label: 'Wstaw/Edytuj odnośnik do artykułu', command: 'cmsLinkArticleDialog', icon: this.path + 'images/icon.png' } ); } } );