1 | // Register the plugin within the editor. |
---|
2 | CKEDITOR.plugins.add( 'contentTable', { |
---|
3 | // This plugin requires the Widgets System defined in the 'widget' plugin. |
---|
4 | requires: 'widget', |
---|
5 | |
---|
6 | // Register the icon used for the toolbar button. It must be the same |
---|
7 | // as the name of the widget. |
---|
8 | icons: 'contentTable', |
---|
9 | |
---|
10 | // The plugin initialization logic goes inside this method. |
---|
11 | init: function( editor ) { |
---|
12 | // Register the editing dialog. |
---|
13 | |
---|
14 | CKEDITOR.dialog.add( 'contentTable', this.path + 'dialogs/contentTable.js' ); |
---|
15 | |
---|
16 | // Register the contentTable widget. |
---|
17 | editor.widgets.add( 'contentTable', { |
---|
18 | // Allow all HTML elements, classes, and styles that this widget requires. |
---|
19 | // Read more about the Advanced Content Filter here: |
---|
20 | // * http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter |
---|
21 | // * http://docs.ckeditor.com/#!/guide/plugin_sdk_integration_with_acf |
---|
22 | allowedContent: |
---|
23 | 'div(!contentTable);table;tbody;tr;td;div(!ckw_Div_content)', |
---|
24 | |
---|
25 | // Minimum HTML which is required by this widget to work. |
---|
26 | requiredContent: 'div(contentTable)', |
---|
27 | |
---|
28 | // Define two nested editable areas. |
---|
29 | editables: { |
---|
30 | content: { |
---|
31 | selector: '.ckw_Div_content', |
---|
32 | allowedContent: 'p br ul ol li strong em' |
---|
33 | } |
---|
34 | }, |
---|
35 | |
---|
36 | // Define the template of a new Simple Box widget. |
---|
37 | // The template will be used when creating new instances of the Simple Box widget. |
---|
38 | template: |
---|
39 | '<div class="contentTable"></div>', |
---|
40 | |
---|
41 | // Define the label for a widget toolbar button which will be automatically |
---|
42 | // created by the Widgets System. This button will insert a new widget instance |
---|
43 | // created from the template defined above, or will edit selected widget |
---|
44 | // (see second part of this tutorial to learn about editing widgets). |
---|
45 | // |
---|
46 | // Note: In order to be able to translate your widget you should use the |
---|
47 | // editor.lang.contentTable.* property. A string was used directly here to simplify this tutorial. |
---|
48 | button: 'Create a simple box', |
---|
49 | |
---|
50 | // Set the widget dialog window name. This enables the automatic widget-dialog binding. |
---|
51 | // This dialog window will be opened when creating a new widget or editing an existing one. |
---|
52 | dialog: 'contentTable', |
---|
53 | |
---|
54 | // Check the elements that need to be converted to widgets. |
---|
55 | // |
---|
56 | // Note: The "element" argument is an instance of http://docs.ckeditor.com/#!/api/CKEDITOR.htmlParser.element |
---|
57 | // so it is not a real DOM element yet. This is caused by the fact that upcasting is performed |
---|
58 | // during data processing which is done on DOM represented by JavaScript objects. |
---|
59 | upcast: function( element ) { |
---|
60 | // Return "true" (that element needs to converted to a Simple Box widget) |
---|
61 | // for all <div> elements with a "simplebox" class. |
---|
62 | return element.name == 'div' && element.hasClass( 'contentTable' ); |
---|
63 | }, |
---|
64 | |
---|
65 | // When a widget is being initialized, we need to read the data ("align" and "width") |
---|
66 | // from DOM and set it by using the widget.setData() method. |
---|
67 | // More code which needs to be executed when DOM is available may go here. |
---|
68 | init: function() { |
---|
69 | var rows = this.element.getStyle( 'rows' ); |
---|
70 | var columns = this.element.getStyle( 'columns' ); |
---|
71 | alert(rows); |
---|
72 | alert(columns); |
---|
73 | |
---|
74 | }, |
---|
75 | |
---|
76 | // Listen on the widget#data event which is fired every time the widget data changes |
---|
77 | // and updates the widget's view. |
---|
78 | // Data may be changed by using the widget.setData() method, which we use in the |
---|
79 | // Simple Box dialog window. |
---|
80 | data: function() { |
---|
81 | var tblStr='<table border="0" cellpadding="0" cellspacing="0" align="center" style="table-layout:fixed; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-collapse: collapse; border-left-style:solid; border-left-width: 0px; border-left-color: #ffffff; border-top-style:solid; border-top-width: 0px; border-top-color: #ffffff; border-right-style:solid; border-right-width: 0px; border-right-color: #ffffff; border-bottom-style:solid; border-bottom-width: 0px; border-bottom-color: #ffffff;">'; |
---|
82 | |
---|
83 | for(var i=0;i<this.data.rows;i++){ |
---|
84 | tblStr += '<tr>'; |
---|
85 | for(var j=0;j<this.data.columns;j++){ |
---|
86 | tblStr += '<td valign="top" bgcolor="#FFFFFF" style="background-color:#ffffff; border-left-style:solid; border-left-width: 0px; border-left-color: #ffffff; border-top-style:solid; border-top-width: 0px; border-top-color: #ffffff; border-right-style:solid; border-right-width: 0px; border-right-color: #ffffff; border-bottom-style:solid; border-bottom-width: 0px; border-bottom-color: #ffffff; padding-top:6px; padding-right:6px; padding-bottom:6px; padding-left:6px; border-collapse: collapse;"><div class="ckw_Div_content">text goes here... <br> <br> </div></td>'; |
---|
87 | } |
---|
88 | tblStr += '</tr>'; |
---|
89 | } |
---|
90 | tblStr += '</table>'; |
---|
91 | this.element.setHtml(tblStr); |
---|
92 | } |
---|
93 | } ); |
---|
94 | } |
---|
95 | } ); |
---|