CKEDITOR.dialog.add("twoGisLinkDialog", function(editor) { return { allowedContent: "a[href,target]", title: "Вставьте ключевое слово", minWidth: 550, minHeight: 100, resizable: CKEDITOR.DIALOG_RESIZE_NONE, contents:[{ id: "Вставьте ключевое слово", label: "", elements:[{ type: "text", label: "Ключевое слово для поиска", id: "edp-URL", validate: CKEDITOR.dialog.validate.notEmpty( "Поле с ключевым словом не может быть пустым" ), setup: function( element ) { var href = element.getAttribute("href"); var isExternalURL = /^(http|https):\/\//; if(href) { if(!isExternalURL.test(href)) { href = "http://amic.ru/spravochnik/?s=" + href; } this.setValue(href); } }, commit: function(element) { var href = this.getValue(); var isExternalURL = /^(http|https):\/\//; if(href) { if(!isExternalURL.test(href)) { href = "http://amic.ru/spravochnik/?s=" + href; } element.setAttribute("href", href); if(!element.getText()) { element.setText(this.getValue()); } } } }, { type: "text", label: "Выделенная часть текста", id: "edp-text-display", setup: function( element ) { this.setValue( element.getText() ); }, commit: function(element) { var currentValue = this.getValue(); if(currentValue !== "" && currentValue !== null) { element.setText(currentValue); } } }, { type: "html", html: "" }] }], 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' ); element.setAttribute("target","_blank"); 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.element.setAttribute('id', 'twoGis') this.commitContent(this.element); if(this.insertMode) { editor.insertElement(this.element); } } }; });