57u / custom-dropdown-ckeditor4

Allows you to create a custom dropdown added to the ckeditor4 toolbar, which outputs a text string (or whatever needed) to the editor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow text and HTML values

dennisverspuij opened this issue · comments

Hello, please consider the patch below to control whether a string is inserted as either text or HTML.
To indicate a string is HTML formatted you must provide a property html with value that evaluates to true in the strinsert_strings configuration object, like done in the additional example.
This implementation also transparently works around the issue that CKEditor richcombo values does not like HTML entities in its values as confirmed in https://dev.ckeditor.com/ticket/11701.

Index: plugin.js
===================================================================
--- plugin.js   (revision 25)
+++ plugin.js   (working copy)
@@ -27,6 +27,7 @@
            {'name': 'Name', 'value': '*|VALUE|*'},
            {'name': 'Group 1'},
            {'name': 'Another name', 'value': 'totally_different', 'label': 'Good looking'},
+           {'name': 'Some HTML', 'html': true, 'value': '<strong>Some &lt;HTML&gt;</strong>'},
        ];

 /**
@@ -89,7 +90,7 @@
                        if (!string.label) {
                            string.label = string.name;
                        }
-                       this.add(string.value, string.name, string.label);
+                       this.add(""+i, string.name, string.label);
                    }
                }
            },
@@ -98,7 +99,8 @@
            {
                editor.focus();
                editor.fire( 'saveSnapshot' );
-               editor.insertHtml(value);
+               var string = strings[value];
+               editor[string.html ? 'insertHtml' : 'insertText'](string.value);
                editor.fire( 'saveSnapshot' );
            },