php - How to reset ckeditor save event -


on previous ajax call articles selected page. display them , bind function - on click - each of them. working 1 time.
when want change second or third article article id inside ajax call keeps holding first value.

ckeditor.replace( 'editor1' );  function editarticle(article){    // id changes each article supposed    var id = article.attr('data-id');    var text = article.html();    $('#ckmodal').modal();    $('.modal-title').text('editing article: '+id+' on page: '+pagetitle);    ckeditor.instances.editor1.setdata(text);    ckeditor.instances.editor1.resize('100%', '350', true);    ckeditor.instances.editor1.on('save', function(e){       e.cancel();     var html = ckeditor.instances.editor1.getdata();     if(html){         $.ajax({             type: 'post',             url: '/admin/nodes/edit',             cache: false,             data: {'html' : html,                     'articleid' : id }         }).done(function(msg){             // next 2 lines did not work             //ckeditor.instances.editor1.fire('save');             //ckeditor.instances.editor1.stop('save');              // id stays same             console.log(id);              // echo 'ok' string when update worked php             if(msg === 'ok'){                 article.html(html);                 $('#ckmodal').modal('hide');              }else{                 //alert(msg);             }          }).fail(function(xhr, status, error){             console.log(json.stringify(xhr));             console.log("ajax error: " + status + ' : ' + error);         });       }   }); } 

i had cancel save event , set data , perform ajax call.

but how restart or reset 'save' event - if causing problem. not shure anymore ....

got working destroying editor instance in ajax done function , creating new 1 after it.

function editarticle(article){ var id = article.attr('data-id'); var text = article.html(); //ckeditor.replace( 'editor1' ); $('#ckmodal').modal(); $('.modal-title').text('editing article: '+id+' on page: '+pagetitle); ckeditor.instances.editor1.setdata(text); ckeditor.instances.editor1.resize('100%', '350', true); ckeditor.instances.editor1.on('save', function(e){     e.cancel();     var html = ckeditor.instances.editor1.getdata();     if(html){         var title = $('.modal-title').html()         $('.modal-title').prepend(spinner);         $.ajax({             type: 'post',             url: '/admin/nodes/edit',             cache: false,             data: {'html' : html,                     'articleid' : id }         }).done(function(msg){             //console.log(id);             $('.modal-title').html(title);             if(msg === 'ok'){                 article.html(html);                 $('#ckmodal').modal('hide');                 ckeditor.instances.editor1.destroy();                 ckeditor.replace( 'editor1' );             }else{                 //alert(msg);             }          }).fail(function(xhr, status, error){             console.log(json.stringify(xhr));             console.log("ajax error: " + status + ' : ' + error);         });     } });  

}


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -