So first, I should mention my appreciation for you all being patient with me. I haven't spent a lot of time working with the new versions of CKEditor, but I hope that I can become more contributory going forward.
My issue: I'm refactoring the placeholder plugin to support dynamic select lists. I have an ajax GET call pull a json encoded list of values and populate it in the placeholder dialog. I've got most of it working (albeit might not be the most efficient way). There is one remaining issue. If editing an existing placeholder, I'm not able to get the selected element's value. When I log out to console the value of element from the setup function, it returns null.
Perhaps I'm missing something obvious, and here is my sample code. Thanks in advance for your help!
/**
* @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
(function() {
function placeholderDialog( editor, isEdit ) {
var lang = editor.lang.placeholder,
generalLabel = editor.lang.common.generalTab;
var plist = [];
console.log('set plist');
return {
title: lang.title,
minWidth: 300,
minHeight: 80,
contents: [
{
id: 'info',
label: generalLabel,
title: generalLabel,
elements: [
{
id: 'placeholder',
type: 'select',
style: 'width: 100%;',
label: lang.text,
items: plist,
'default':'',
required: true,
validate: CKEDITOR.dialog.validate.notEmpty( lang.textMissing ),
setup: function( element ) {
$.ajaxSetup({
async: false
});
$.get( "/services/get_placeholders.php", function( data ) {
plist = $.parseJSON(data);
console.log($.parseJSON(data));
console.log('ajax part completed.');
});
$.ajaxSetup({
async: true
});
var e = this;
$.each(plist,function(i,item){
e.add(item[0],item[1]);
console.log('adding '+item[0]);
});
console.log('element is:');
console.log(element); // THIS IS RETURNING NULL
if ( isEdit )
this.setValue( element.getText().slice( 2, -2 ) );
},
commit: function( element ) {
var text = '[[' + this.getValue() + ']]';
// The placeholder must be recreated.
console.log('completed placeholder');
CKEDITOR.plugins.placeholder.createPlaceholder( editor, element, text );
}
}
]
}
],
onShow: function() {
if ( isEdit )
this._element = CKEDITOR.plugins.placeholder.getSelectedPlaceHolder( editor );
this.setupContent( this._element );
},
onOk: function() {
this.commitContent( this._element );
delete this._element;
}
};
}
CKEDITOR.dialog.add( 'createplaceholder', function( editor ) {
return placeholderDialog( editor );
});
CKEDITOR.dialog.add( 'editplaceholder', function( editor ) {
return placeholderDialog( editor, 1 );
});
})();I've messed with editor.getSelection() and editor.getSelection().getSelectedElement(). They all return a null value.
