Touch UI RTE is the always challenging topic because of a lack of documentation to create or customize plugins, There are great articles at http://experience-aem.blogspot.com/2013/08/in-blog-experiencing-adobe-experience.html which talk about RTE plugins. I got the idea from ColorPicker plugin and tried to create a new Style Picker plugin which may help AEM community to achieve more from RTE.
This blog covers :
HTML DOM Navigation and HTML element selector inside RTE Editor
Custom Style(Style Picker) Plugins
Color Picker Plugin
When selected item already has existing styles, the style will be pre-selected in the dropdown, If another style is chosen, the new class will be added and existing class will also remain, this will allow applying multiple styles to a single element.
In case of applying a different style or a single style to an element then an existing style should be chosen and removed using the Remove Style button.
If only a text is selected for applying the style using this custom style picker plugin, the style will be added to its parent's node. If you want to apply a style to text using a span tag, use OOTB style plugin.
Packages contain:
RTE Navigation will only be shown for the RTE which has showBreadcrumb property with true.
Although navigation can be enable for all the RTEs by changing below line in /apps/commons/rte/rte-breadcrumb/js/rte-breadcrumb.js file
replace
$('.coral-RichText[data-showbreadcrumb="true"]').each(function() {
$(this).parent().find(".rte-sourceEditor").after(breadcrumbItem);
});
with
$('.coral-RichText').each(function() {
$(this).parent().find(".rte-sourceEditor").after(breadcrumbItem);
});
After installing the package you can find the Style Picker Plugins files at:
Plugins JS and CSS at
/apps/commons/rte/plugins/clientlibs/js/style-picker.js
/apps/commons/rte/plugins/clientlibs/css/style-picker.css
Plugins popover dialogs
/apps/commons/rte/plugins/popovers/style-picker
Plugin Popover Dialog - dropdown option datasource and JSON at
Datasource is a JSP file which read json specified in options property and populates dropdown option for Style Picker plugin.
JSON file should have an array of elements in below format:
If want to show as Heading/Category use below format(value could be anything)
{"text": "Background Color","value": "BTC","heading": "true"}
If Option
{"text": "White","value": "white"}
Example : /apps/commons/rte/plugins/popovers/style-picker/options.json
[
{"text": "Background Color","value": "BTC","heading": "true"},
{"text": "White","value": "white"},
{"text": "Black","value": "black"},
{"text": "Green","value": "green"},
{"text": "Orange","value": "orange"},
{"text": "Light Grey","value": "lightgrey"},
{"text": "List Style","value": "LS","heading": "true"},
{"text": "Check","value": "list-checked"},
{"text": "Cross","value": "list-crossed"},
{"text": "Link Style","value": "LS","heading": "true"},
{"text": "Primary","value": "btn-primary"},
{"text": "Secondary","value": "btn-secondary"}
]
Plugin configuration in RTE
create 'styleformat' child node of rtePlugins node and create features property in it with * value as shown in below screenshot.
Add 'styleformat#styles' in toolbar property on inline node as shown in below screenshot.
After installing the package you can find the ColorPicker Plugins files at :
Plugins JS and CSS at
/apps/commons/rte/plugins/clientlibs/js/color-picker.js
/apps/commons/rte/plugins/clientlibs/css/color-picker.css
Plugins popover dialogs
/apps/commons/rte/plugins/popovers/color-picker
Plugin configuration in RTE
create 'colorformat' child node of rtePlugins node and create features property in it with * value as shown in below screenshot.
Add 'colorformat#colorPicker' in toolbar property on inline node as shown in below screenshot.
This component can be referred for ColorPicker and StylePicker Plugins configurations.
This blog covers :
HTML DOM Navigation and HTML element selector inside RTE Editor
Custom Style(Style Picker) Plugins
Color Picker Plugin
- HTML DOM Elements Navigator extension:
- Shows selected/current HTML element's DOM structure in RTE
- Allows selecting an exact HTML element in RTE to apply settings using RTE plugins.
- Style Picker Plugins apply a class attribute to selected HTML elements unlike OOTB style plugin create span tag. The exact HTML element can be selected from DOM navigator e.g. ul, ol, hr, p, div, img etc. These elements can be selected by DOM Element Navigator and class can be applied to them.
- The Color Picker Plugin as same as ColorPicker Plugin from http://experience-aem.blogspot.com but I modified it to work with all AEM version from 6.3+
Color Picker, Style Picker Plugins and HTML DOM navigation |
RTE Element Selection from DOM navigation |
Applying class to ul element using Style Picker |
When selected item already has existing styles, the style will be pre-selected in the dropdown, If another style is chosen, the new class will be added and existing class will also remain, this will allow applying multiple styles to a single element.
In case of applying a different style or a single style to an element then an existing style should be chosen and removed using the Remove Style button.
Pre-selected style |
Applying another style to list |
Removing style from the list |
If only a text is selected for applying the style using this custom style picker plugin, the style will be added to its parent's node. If you want to apply a style to text using a span tag, use OOTB style plugin.
Style is added to P tag |
OOTB style plugin, style added with a span tag |
Note: If multiple HTML items are selected then the style will be applied to only one element.
Code
You can install below packages from GitHub to use these plugins in AEM 6.3+Packages contain:
AEM 6.5 - aem-rte-plugins-1.4.zip
AEMaaCS version - aem-rte-plugins-1.5.zipDetails
1. DOM Elements Navigation and Selector inside RTE Editor
In RTE, the element tree breadcrumb is created at the bottom section of RTE, which shows the DOM navigation and allow a user to select a particular HTML element in RTE by clicking on breadcrumb items.RTE Navigation will only be shown for the RTE which has showBreadcrumb property with true.
ShowBreadcrumb property in RTE item node |
RTE DOM Tree |
Although navigation can be enable for all the RTEs by changing below line in /apps/commons/rte/rte-breadcrumb/js/rte-breadcrumb.js file
replace
$('.coral-RichText[data-showbreadcrumb="true"]').each(function() {
$(this).parent().find(".rte-sourceEditor").after(breadcrumbItem);
});
with
$('.coral-RichText').each(function() {
$(this).parent().find(".rte-sourceEditor").after(breadcrumbItem);
});
The DOM navigation extension is independent to style plugin and can be used with other plugins as well to select, cut, copy etc.
2. Custom Style Picker Plugins
StylePicker Plugin in RTE toolbar |
Plugins JS and CSS at
/apps/commons/rte/plugins/clientlibs/js/style-picker.js
/apps/commons/rte/plugins/clientlibs/css/style-picker.css
Plugins popover dialogs
/apps/commons/rte/plugins/popovers/style-picker
Plugin Popover Dialog - dropdown option datasource and JSON at
- /apps/commons/rte/plugins/popovers/style-picker/datasource
- /apps/commons/rte/plugins/popovers/style-picker/options.json
Datasource is a JSP file which read json specified in options property and populates dropdown option for Style Picker plugin.
JSON file should have an array of elements in below format:
If want to show as Heading/Category use below format(value could be anything)
{"text": "Background Color","value": "BTC","heading": "true"}
If Option
{"text": "White","value": "white"}
Example : /apps/commons/rte/plugins/popovers/style-picker/options.json
[
{"text": "Background Color","value": "BTC","heading": "true"},
{"text": "White","value": "white"},
{"text": "Black","value": "black"},
{"text": "Green","value": "green"},
{"text": "Orange","value": "orange"},
{"text": "Light Grey","value": "lightgrey"},
{"text": "List Style","value": "LS","heading": "true"},
{"text": "Check","value": "list-checked"},
{"text": "Cross","value": "list-crossed"},
{"text": "Link Style","value": "LS","heading": "true"},
{"text": "Primary","value": "btn-primary"},
{"text": "Secondary","value": "btn-secondary"}
]
List Style and List Style are the Category and can't be selected |
Plugin configuration in RTE
create 'styleformat' child node of rtePlugins node and create features property in it with * value as shown in below screenshot.
Add 'styleformat#styles' in toolbar property on inline node as shown in below screenshot.
3. Color Picker Plugin
ColorPicker Plugin in RTE toolbar |
Plugins JS and CSS at
/apps/commons/rte/plugins/clientlibs/js/color-picker.js
/apps/commons/rte/plugins/clientlibs/css/color-picker.css
Plugins popover dialogs
/apps/commons/rte/plugins/popovers/color-picker
Plugin configuration in RTE
create 'colorformat' child node of rtePlugins node and create features property in it with * value as shown in below screenshot.
Add 'colorformat#colorPicker' in toolbar property on inline node as shown in below screenshot.
Sample Components
Sample Test Component package contains a sample component (/apps/mfHTL63/components/content/simple-rte)
This component can be referred for ColorPicker and StylePicker Plugins configurations.
References
http://experience-aem.blogspot.com/2017/06/aem-63-touch-ui-rte-rich-text-editor-color-picker-plugin-inplace-dialog-edit.html
This comment has been removed by a blog administrator.
ReplyDeletegreat blog !!
ReplyDeleteoracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
hadoop training in chennai
hadoop training in bangalore
Thanks a lot for this blog!!
DeleteThis comment has been removed by the author.
ReplyDeleteHi Arun, Thanks for this post. Just wanted to update you that This is not working on 6.4.8 service package. It is working fine on 6.4.2 service package. I have upgraded the service pack from 6.4.2 to 6.4.8. I can see the both plugins in richtext and whenever i click on any one of style/color icon then blank popup is opening.I see the below error in the console.
ReplyDeleteVM21086 clientlibs.min.49f63fbc84fedf84417f20f67f1ee090.js:7 Uncaught ReferenceError: _ is not defined
at clientlibs.min.49f63fbc84fedf84417f20f67f1ee090.js:7
at Array.forEach ()
at l (clientlibs.min.49f63fbc84fedf84417f20f67f1ee090.js:7)
at clientlibs.min.49f63fbc84fedf84417f20f67f1ee090.js:9
at clientlibs.min.49f63fbc84fedf84417f20f67f1ee090.js:9
Hi Arun , I think it is not able to find the "underscore dependency" in the AEM (Service pack 6.4.8) that 'y it throwing error. I tried to add same dependency directly in the style-picker.js and its working as expected but the behavior is not consistent, So whenever i am closing the style dialog it's throwing error apart from this it is working expected.
ReplyDeleteDid you get a chance to look on this. Thank You. Good day..!!
Thanks for the feedback Keshav. I will try this in 6.4.8 and fix if something is missing.
DeleteHi Arun, Thanks for the response. I have fixed it , Actually underscore dependency was not loading in AEM 6.4.8, So i have added the underscores.js from https://underscorejs.org/ and added in the style-plugins and rte breadcrumbs js file, After doing, its working fine. Thank You.
DeleteCan you add the updated style-plugins js with dependency for underscore js added here? my dialog appears blank as of now due to this dependency issue
DeleteNice knowledge gaining article. This post is really the best on this valuable topic. mailto link generator
ReplyDeleteI'm trying to use this in AEMaaCS and is not working, dialog appears blank (more specific, gray). Is there anything I need to change?
ReplyDeleteHi Gonzalo,
DeleteI need to check this for AEMaaCS.
I have found that removing the underscore dependency is the most reliable long term solution to some of these issues. Simple remove all occurrences of _. from color-picker.js and add the following functions starting on line 2:
ReplyDeleteisEmpty = function(item) {
console.log('item = ',item);
if(!item) { return true; }
var len;
if(item.length || item.length === 0){
len = item.length;
} else {
if(typeof item === 'object') {
len = Object.keys(item).length;
}
}
return len === 0;
}
isUndefined = function(item) {
if(item === undefined) {
return true;
} else {
return false;
}
}
defer = function(item) {
setTimeout(() => {item()})
}
Thanks for sharing
DeleteHi Arun, nice post. For us the issue is that the plugin takes lot more time to load. On edit, only text is displayed first and after 12/13 seconds the RTE icons show up. Is there any way it can be made faster to load?
ReplyDeleteHi,
DeleteCould you please check without custom plugin, the custom plugin loaded with other plugins, there should not be any delay. Please let me know, I will have a look if you can find something but as far as from code side the delay can be caused when you click on icon to fetch plugin dialog.
Used with AACS, removed underscore dependency too; it works fine when there is single instance of RTE but as soon as two are added on the page the dialog breadcrumb comes only in 1st RTE component and not in second one. Anyone else faced this issue ?
ReplyDeleteActually the breadcrumb is getting added only first time when we open the dialog and not the second time.
DeleteTo resolve _ is not defined issue
ReplyDeleteTry changing dependency from underscore to lodash.underscore
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/rte-color-picker-not-working/m-p/446636/highlight/true#M127756
Hello Arun,
ReplyDeleteI tried the plugin with latest SDK - Aem as a cloud service, it is not working.
Hi Sonia,
DeleteI need to check this for ACS Common, I will be let you know
AEMaaCS version is at https://github.com/arunpatidar02/aem63app-repo/blob/master/packages/rte/aem-rte-plugins-1.5.zip
ReplyDeleteIt still has some dialog overlay issue but plugins are in working state
Hi Arun Patidar,
ReplyDeleteFirstly thank you for the awesome post, trying to implement the same in my local.
AEM Version: 6.5.14
I have started learning creation of aem components recently. Created a text component and want to activate the RTEPlugins for the textarea component.
I am able to see the plugins in inline mode but not able to find the maximize and done buttons. When I went inside the component by clicking on the configure mode, the plugins itself are not getting displayed.
Please help me where I went wrong! and It would be more helpful. if you can provide me an example with complete rte plugins. (Basic one and the custom rte plugins one)
Thanks everyone
Shiva
Hi,
ReplyDeleteThe reason could be that the plugin is not added in fullscreen mode.
You can check below example for dialog
https://experienceleague.adobe.com/docs/experience-manager-64/administering/operations/rich-text-editor.html?lang=en#dialogfullscreen
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHello Arun, First of all thanks a lot for your selfless service towards AEM community.
ReplyDeleteAEM : 6.5.13
A)In Style Picker, close (x) and tick (✓) button does not work. When we try to click, it gives below error:
"Resource at '/apps/commons/rte/plugins/popovers/style-picker/undefined' not found: No resource found"
B) Remove style button: After we add a style using "Add property" button.next time, if we want to remove this style from same text, It does not pre-select style in dropdown that was selected while using "Add styles button".
Thanks a lot in advance.
popovers/style-picker/cq:dialog/cq:dialog.html' not found: No resource found
ReplyDeleteI have downloaded all the folders but I don't see cq:dialog.html in popover folder. could you please help me with this issue?
@Arun @Arvind Were you able to resolve this issue with "Style Picker, close (x) and tick (✓) button does not work." ? Thanks
ReplyDelete