javascript - CKEDITOR style with unique id -


i using ckeditor styles system -- i'd create style assigns unique attribute.

i have simple plugin calls style create:

     editor.addcommand( 'tag', {             exec: function( editor ) {                var randnumber = math.floor((math.random()*1000000000)+1);                var mysqldatetime = new date();                 ckeditor.config.tag = { element : 'span', attributes : { 'class': 'tag-'+randnumber, 'data-datetime' : mysqldatetime, 'data-tag': 'tag' } };                 var style = new ckeditor.style( editor.config.tag );                 editor.addcommand( 'tag', new ckeditor.stylecommand( style ) );     } }); 

but datetime , randomnumber generated once. how can attributes calculated each time command executed?

try following code (jsfiddle):

ckeditor.replace( 'editor1', {     plugins: 'wysiwygarea,sourcearea,toolbar,basicstyles,link',     on: {         pluginsloaded: function() {             var cmd = this.addcommand( 'tag', {                 canundo: true,                 modes: { wysiwyg:1 },                 // otherwise editor purge custom stuff.                 allowedcontent: 'span(*)[data-datetime,data-tag]{color}',                 exec: function( editor ) {                     var randnumber = math.floor( ( math.random() * 1000000000 ) + 1 ),                         mysqldatetime = new date();                      // alway apply different style.                     editor.applystyle( new ckeditor.style( {                         element: 'span',                         attributes: {                             'class': 'tag-' + randnumber,                             'data-datetime': mysqldatetime,                             'data-tag': 'tag'                         },                         styles: {                             color: 'red'                         }                     } ) );                 }             } );              // custom command, need register it.             this.addfeature( cmd );         }     } } ); 

some must-read info advanced content filter + editor.applystyle. consider defining requiredcontent content if may used within instances of restricted content types.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -