Further modules included.
[yaffs-website] / web / modules / contrib / ckeditor_widgets / js / plugins / widgettemplatemenu / plugin.js
1 CKEDITOR.plugins.add( 'widgettemplatemenu', {
2     requires: 'menu',
3
4     defaults : {
5         name: 'accordion',
6         count: 3,
7         activePanel: 1,
8         multiExpand: false
9     },
10
11     init: function( editor ) {
12         
13         // Set the default button info based on installed plugins
14         var buttonData = {};
15         // @todo: make these if statement work
16         if (editor.plugins.widgetcommon != undefined) {
17             buttonData.widgetcommonBox = 'Insert box';
18             buttonData.widgetcommonQuotebox = 'Insert quote box';
19         }
20         if (editor.plugins.widgetbootstrap != undefined) {
21             buttonData.widgetbootstrapLeftCol = 'Insert left column template';
22             buttonData.widgetbootstrapRightCol = 'Insert right column template';
23             buttonData.widgetbootstrapTwoCol = 'Insert two column template';
24             buttonData.widgetbootstrapThreeCol = 'Insert three column template';
25             buttonData.widgetbootstrapAlert = 'Insert Alert box';
26         }
27         if (editor.commands.oembed != undefined) {
28             buttonData.oembed = 'Insert media';
29         }
30         if (editor.commands.codeSnippet != undefined) {
31             buttonData.codeSnippet = 'Insert code snippet';
32         }
33         if (editor.commands.leaflet != undefined) {
34             buttonData.leaflet = 'Insert map';
35         }
36
37         // Get the enabled menu items from editor.config
38         if (editor.config.widgettemplatemenuButtons != undefined) {
39             var config = editor.config.widgettemplatemenuButtons.split(',');
40             var buttons = {};
41             for (var i = 0; i < config.length; i++) {
42                 buttons[config[i]] = buttonData[config[i]];
43             }
44         }
45         else {
46             var buttons = buttonData;
47         }
48         
49         // Build the list of menu items
50         var items =  {};
51         for(var key in buttons) {
52             items[key] = {
53                 label: buttons[key],
54                 command: key,
55                 group: 'widgettemplatemenu',
56                 icon: key
57             }
58         }
59
60         // Items must belong to a group.
61         editor.addMenuGroup( 'widgettemplatemenu' );
62         editor.addMenuItems( items );
63
64         editor.ui.add( 'WidgetTemplateMenu', CKEDITOR.UI_MENUBUTTON, {
65             label: 'Insert Template',
66             icon: this.path + 'icons/widgettemplatemenu.png' ,
67             onMenu: function() {
68                 // You can control the state of your commands live, every time
69                 // the menu is opened.
70                 return {
71                     widgetcommonBox: editor.commands.widgetcommonBox == undefined ? false : editor.commands.widgetcommonBox.state,
72                     widgetcommonQuotebox: editor.commands.widgetcommonQuotebox == undefined ? false : editor.commands.widgetbootstrapLeftCol.state,
73                     widgetbootstrapLeftCol: editor.commands.widgetbootstrapLeftCol == undefined ? false : editor.commands.widgetbootstrapLeftCol.state,
74                     widgetbootstrapRightCol: editor.commands.widgetbootstrapRightCol == undefined ? false : editor.commands.widgetbootstrapRightCol.state,
75                     widgetbootstrapTwoCol: editor.commands.widgetbootstrapTwoCol == undefined ? false : editor.commands.widgetbootstrapTwoCol.state,
76                     widgetbootstrapThreeCol: editor.commands.widgetbootstrapThreeCol == undefined ? false : editor.commands.widgetbootstrapThreeCol.state,
77                     widgetbootstrapAlert: editor.commands.widgetbootstrapAlert == undefined ? false : editor.commands.widgetbootstrapAlert.state,
78                     widgetbootstrapAccordion: editor.commands.widgetbootstrapAccordion == undefined ? false : editor.commands.widgetbootstrapAccordion.state,
79                     oembed: editor.commands.oembed == undefined ? false : editor.commands.oembed.state,
80                     codeSnippet: editor.commands.codeSnippet == undefined ? false : editor.commands.codeSnippet.state,
81                     leaflet: editor.commands.leaflet == undefined ? false : editor.commands.leaflet.state,
82                     FontAwesome: editor.commands.FontAwesome == undefined ? false : editor.commands.FontAwesome.state
83                 };
84             }
85         } );
86         
87     }
88
89
90 } );