// BFInsert plugin - implements an object insertion selector on the editor toolbar // (c) 2010 Open Text Corp. All rights reserved. (function() { CKEDITOR.plugins.add( 'bfinsert', { requires: ['menubutton'], init: function(editor) { var config = editor.config, topGroup = 'Insert'; // utilities var getItems = function(list) { var itemList = {}; var items = list.split(','); for (var i in items) { if (items[i].length > 0) { itemList[items[i]] = CKEDITOR.TRISTATE_OFF; } } return itemList; }; var addItem = function(name, group) { var menuitem = {}, def = {}; if (config.insertmenuitems[name]) { menuitem = config.insertmenuitems[name]; if (menuitem.command) { def = {}; def.name = name; def.label = menuitem.label; def.group = group; def.command = menuitem.command; editor.addMenuItem(name, def); } } }; var addGroup = function(name, group) { var groupDef = config.insertmenuitems[name]; editor.addMenuGroup(groupDef.name); var itemDef = { label: groupDef.label, group: group, getItems: function() { return getItems(groupDef.items); } }; editor.addMenuItem(name, itemDef); var gItems = groupDef.items.split(','); for (var gItem in gItems) { var itemName = gItems[gItem]; if (itemName.length > 0) { if (itemName.indexOf('menu') >= 0) { addGroup(itemName, name); } else { addItem(itemName, name); } } } }; // command stubs - remove as implemented var stubbed = []; var displayIt = function() { alert('Command stub: please implement!'); }; for (var j in stubbed) { if (stubbed[j].length > 0) { editor.addCommand( stubbed[j], { exec: displayIt }); } } // add the menus addGroup(topGroup, topGroup); // create the insert control editor.ui.add( topGroup, CKEDITOR.UI_MENUBUTTON, { label : 'Insert  ', className : 'cke_button_bfinsert', onMenu : function() { return getItems(config.insertmenuitems[topGroup].items); } }); } }); }());