var merge_fields = ["one", "two", "three", "four"];
var buildListHasRunOnce = 0;
var buildList = function () {
console.log("buildList");
if (buildListHasRunOnce == 1) {
console.log("remove ul");
// Remove the old unordered list from the dom.
// This is just to cleanup the old list within the iframe
$(this._.panel._.iframe.$).contents().find("ul").remove();
// reset list
this._.items = {};
this._.list._.items = {};
}
for (var i in merge_fields) {
var item = merge_fields[i];
var cb = $("input[name='" + item + "']");
if (cb.is(":checked")) {
this.add(item, "<span class='mergefield listitem'>" + item + "</span>", item);
}
}
if (buildListHasRunOnce == 1) {
console.log("this._.committed = 0");
// Force CKEditor to commit the html it generates through this.add
this._.committed = 0; // We have to set to false in order to trigger a complete commit()
this.commit();
}
buildListHasRunOnce = 1;
};
$(':checkbox').change(function () {
myinstance.fire('updateList');
});
CKEDITOR.plugins.add('merge', {
requires: ['richcombo'], //, 'styles' ],
init: function (editor) {
var config = editor.config,
lang = editor.lang.format,
self = this;
editor.ui.addRichCombo('Merge', {
label: "Merge",
title: "mergefields",
id: 'mergefields',
className: 'cke_format',
multiSelect: false,
panel: {
css: [config.contentsCss, CKEDITOR.getUrl(editor.skinPath + 'editor.css')],
voiceLabel: lang.panelVoiceLabel
},
init: function () {
console.log("init()");
this.buildList();
var self = this;
editor.on("updateList", function () {
self.buildList();
});
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.