Kendo UI Editor - Change default colors of font color picker and background color picker

3.7k views Asked by At

I am using the Kendo UI Editor and I want to choose which color will appear in the font and background color palettes. Or another alternative is letting the user choose from a custom color picker.

I found examples on forums, but they all use older version of Kendo 2012. The latest version 2016 R3 does not know such a definition: kendo.ui.editor.ColorPicker.fn.options.colors It says it is undefined:

Uncaught TypeError: Cannot read property 'fn' of undefined

Is there a way to do this? I looked in the forums and saw this answer but this isn't working.

  kendo.ui.editor.ColorPicker.fn.options.colors = ["c3c3c3", "b97a57", "ffaec9", "ffc90e", "efe4b0", "b5e61d", "99d9ea", "7092be", "c8bfe7"];
1

There are 1 answers

3
Sean Ch On BEST ANSWER

Update: The solution work with latest version of kendo UI after user question was modified
I have discussed the solution using latest version of kendo on this blog . Please click on link below to navigate to solution.

Kendo UI Editor - Change default colors of font color picker and background color picker

In brief the soultion in the link is this code:

<script>
$("#editor").kendoEditor({
    tools: [{
        name: "backColor",
        palette: ["#f0d0c9", "#e2a293", "#d4735e", "#65281a"]
       },
       { 
           name: "foreColor",
           palette: ["red", "green", "#d47eee", "#65281a"]
       }
   }]
});
</script>

Old : This Solution works but only with kendo 2012 version.

Here is the working live demo link - Editor color picker

HTML

<!DOCTYPE html>
<html>
<head>
<link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://cdn.kendostatic.com/2012.3.1315/js/kendo.all.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
   <textarea id="textarea" rows="10" cols="30" style="width:100%;height:400px">
            &lt;p&gt;&lt;img src=&quot;http://www.kendoui.com/Image/kendo-logo.png&quot; alt=&quot;Editor for ASP.NET MVC logo&quot; style=&quot;display:block;margin-left:auto;margin-right:auto;&quot; /&gt;&lt;/p&gt;
            &lt;p&gt;
                Kendo UI Editor allows your users to edit HTML in a familiar, user-friendly way.&lt;br /&gt;
                In this version, the Editor provides the core HTML editing engine, which includes basic text formatting, hyperlinks, lists,
                and image handling. The widget &lt;strong&gt;outputs identical HTML&lt;/strong&gt; across all major browsers, follows
                accessibility standards and provides API for content manipulation.
            &lt;/p&gt;
            &lt;p&gt;Features include:&lt;/p&gt;
            &lt;ul&gt;
                &lt;li&gt;Text formatting &amp; alignment&lt;/li&gt;
                &lt;li&gt;Bulleted and numbered lists&lt;/li&gt;
                &lt;li&gt;Hyperlink and image dialogs&lt;/li&gt;
                &lt;li&gt;Cross-browser support&lt;/li&gt;
                &lt;li&gt;Identical HTML output across browsers&lt;/li&gt;
                &lt;li&gt;Gracefully degrades to a &lt;code&gt;textarea&lt;/code&gt; when JavaScript is turned off&lt;/li&gt;
            &lt;/ul&gt;
            &lt;p&gt;
                Read &lt;a href=&quot;http://docs.kendoui.com&quot;&gt;more details&lt;/a&gt; or send us your
                &lt;a href=&quot;http://www.kendoui.com/forums.aspx&quot;&gt;feedback&lt;/a&gt;!
            &lt;/p&gt;
    </textarea>

</body>
</html>

JavaScript File

kendo.ui.editor.ColorPicker.fn.options.colors = ["c3c3c3"];       
$("textarea#editor").kendoEditor();

$('textarea').kendoEditor({
  encoded: false,
  tools: [
    "bold",
    "italic",
    "underline",
    "strikethrough",
    "fontName",
    "fontSize",
    "foreColor",
    "backColor",
    "justifyLeft",
    "justifyCenter",
    "justifyRight",
    "justifyFull",
    "insertUnorderedList",
    "insertOrderedList",
    "indent",
    "outdent",
    "formatBlock",
    "createLink",
    "unlink",
    "insertImage",
    "viewHtml"
  ]
});

enter image description here