function() { /* code */ } )();
CKEDITOR.plugins.add( 'ymap' /* */, // { // requires: [ 'dialog', 'fakeobjects' ], // init: function( editor /* - */ ) { }, // , API afterInit: function( editor ) { } } );
this._initTranslations( editor ); // , var req = 'em' /* tag */ + '[!data-plugin,!width,!height]' /* attrs */ + '(' + ymap_class_name + ')' /* classes */ + '{width,height}' /* styles */; // editor.addCommand( 'ymap', new CKEDITOR.dialogCommand( 'ymap', { allowedContent: req } ) ); // editor.ui.addButton( 'YMap', { label: lang.button_label, command: 'ymap' } ); // CKEDITOR.dialog.add( 'ymap', add_dialog /* , */ ); // - // fakeobject - editor.on( 'doubleclick', function( evt ) { var element = evt.data.element; if( element.is('img') && element.data('cke-real-element-type') == 'ymap' ) { evt.data.dialog = 'ymap'; } } );
var translations = { ru: { fake_object_label: 'Yandex ', title: 'Yandex ', // ... }, en: { fake_object_label: 'Yandex Map', title: 'Yandex Map', // ... }, def: 'ru' }; var lang; // shotrcut // ... CKEDITOR.plugins.add( 'ymap', { // ... _initTranslations: function( editor ) { var current_lang = CKEDITOR.lang.detect(); CKEDITOR.lang[ current_lang ]['ymap'] = translations[ current_lang ] ? translations[ current_lang ] : translations[ translations.def_lang ]; lang = editor.lang.ymap; // fakeobject editor.lang.fakeobjects.ymap = lang.fake_object_label; }, // ... } );
afterInit: function( editor ) { // var dataProcessor = editor.dataProcessor, dataFilter = dataProcessor && dataProcessor.dataFilter; if( dataFilter ) { // dataFilter.addRules ( { // elements: { // em. // , inline-, // CKEditor- // P- 'em': function( el ) { // em - Ymap, if( ! is_plugin_node( el ) ) { for( var i = 0 ; i < el.children.length; ++ i ) { if( el.children[ i ].name === 'cke:ymap' ) { if( ! is_plugin_node( el.children[ i ] ) ) { return null; // } // fakeobject return create_fake_element( editor, el ); } } return null; // } // - fakeobject return create_fake_element( editor, el ); } } }, 1 /* */ ) } // if dataFilter }
var is_plugin_node = function( el ) { return el.attributes['class'] === ymap_class_name; };
var create_fake_element = function( editor, real_el ) { // , IMG, , return editor.createFakeParserElement( real_el, 'cke_ymap', 'ymap', true ); };
var add_dialog = function( editor ) { var dialog = { title: lang.title, // // width: 300, height: 100, // — , , … contents: [ ], // onShow: function(){}, onOk: function(){} }; return dialog; };
{ // , , 1, id: 'tab_info', expand: true, padding: 0, elements: [ { // id: 'name', type: 'text', label: lang.f_name, commit: commit, setup: load }, { // id: 'label', type: 'text', label: lang.f_label, commit: commit, setup: load }, { // . type: 'hbox', align: 'left', children: [ { // latitude id: 'lon', type: 'text', label: lang.f_lat, commit: commit, validate: CKEDITOR.dialog.validate .regex( /^[\d\,\.]+$/, lang.inc_coord ), setup: load, 'default': '43.2503' }, // …
// this.fake_image = this.ymap_node = null; // - var fake_image = this.getSelectedElement(); // ... if( fake_image && fake_image.data( 'cke-real-element-type' ) === 'ymap' ) { this.fake_image = fake_image; // EM- ( , // ) this.ymap_node = editor.restoreRealElement( fake_image ); // .. JSON "data-plugin", // cfg var cfg = JSON.parse( this.ymap_node.getAttribute('data-plugin') ) // setup . // setup- , // . cfg this.setupContent( cfg ); }
var load = function( cfg ) { // - cfg // data-plugin // ( :) ) this.setValue( cfg[ '_' + this.id ] ); };
// this.fake_image onShow, // fakeobject // , // if( ! this.fake_image ) { // EM- var node = CKEDITOR.dom.element .createFromHtml( '<cke:em>MAP</cke:em>', editor.document ); // node.addClass( ymap_class_name ); } else { // // EM- , // onShow // restoreRealElement var node = this.ymap_node; } // var extra_styles = {}, extra_attributes = {}; // commit // load. // , // this.commitContent( node, extra_styles, extra_attributes ); // EM- node.setStyles( extra_styles ); // - node.$.setAttribute( 'data-plugin', JSON.stringify( extra_attributes ) ); // fakeobject- // - , // - , IMG // - // - var new_fake_image = editor.createFakeElement( node, 'cke_ymap', 'ymap', true ); new_fake_image.setAttributes( extra_attributes ); new_fake_image.setStyles( extra_styles ); // fakeobject if( this.fake_image ) { // new_fake_image.replace( this.fake_image ); // editor.getSelection().selectElement( new_fake_image ); } else { // // - // editor.insertElement( new_fake_image ); }
var commit = function( ymap, styles, attrs ) { var value = this.getValue(); if( this.id === 'width' || this.id === 'height' ) { // // styles[ this.id ] = value; } else if( this.id === 'lat' || this.id === 'lon' ) { // - value = value.replace( ',', '.' ); } // , // onOk data-plugin attrs[ '_' + this.id ] = value; };
CKEDITOR.addCss( 'img.cke_ymap { /* css */ }' );
Source: https://habr.com/ru/post/204176/
All Articles