TinyMCE (or JCE) - How to get current node name and html content - tinymce

I am trying to check at which node the cursor / selection is.
I want to get the
node name
html inside the node

The node can be accessed using:
tinyMCE.activeEditor.selection.getNode()
And there are 2 properties that will return the wanted values: nodeName and innerHTML
tinyMCE.activeEditor.selection.getNode().nodeName
tinyMCE.activeEditor.selection.getNode().innerHTML

Related

create dynamic dashboard of singlestat panel based on template variable

I would like to create a dynamic dashboard of my cluster nodes. this dashboard will be composed of multiple single state panels. each one shows the status and name of a node
So this what I have done:
create a template variable list_of_vm = label_values(up{job="node_exporter"},instance) by checking multi-value combo
the result of this is something like ip1:port, ip2:port, ... , ip7:port
create un single state panel with repeat panel set to list_of_vm. And in metrics I set up{instance="$list_of_vm",job="node_exporter"}
After checking all instances in the template variable, the panels are correctly duplicated, but their value is wrong because in metric the query is evaluated as : up{instance="$list_of_vm",job="node_exporter"}
when list_of_vm = "ip1:port+ip2:port+..+ip7:port"
And I am expecting to have ip1:port for the first panel, ip2:port for the second one...
Do you have any idea to fix this problem

AEM DefaultValue written to JCR

I noticed that when I set my defaultValue for a dropdown, altho it is correctly selected in the drop down when I first add my component to the page it does not write the defaultValue to the corresponding JCR until I edit the component and save it. Even if I just open the corresponding dialog and click OK now my component works as expected because the values have been added to the JCR.
I am sure there is an important piece that I am missing here, does anyone knows how defaultValues that are required in order for the component to render properly can be added to the JCR when they are first added to the page?
Like Shwan say's that's the way it works. The default values or empty texts are only for the dialog. They aren't persisted until the dialog is authored. The properties have to be set by a different method. CQ already ships with this feature and you can do it without any custom code.
Under your component , create a node called cq:template[nt:unstructured] . If all the data is stored on the component node itself , add the default values as properties to cq:template node with name same as the ones in your dialog. In case the data is stored in a child node add a similar node under cq:template node.
Source : http://blogs.adobe.com/experiencedelivers/experience-management/defaults-in-your-component/
I believe that is simply the way it works. The default value specified in a dialog does not get used until the dialog is loaded/saved, so until that happens the node on the JCR repository that is being authored won't have the default value.
We got around this on a project by adding back-end code that was tied to the component (a tag) so that when the component was loaded, if the property did not exist, it would be written with the default the first time. Ex:
if (wcmMode == WCMMode.EDIT )
{
if(!currentNode.hasProperty("SomePropertyThatWillAlwaysExistIfTheDialogHasBeenSaved")) {
currentNode.setProperty("PropertyThatShouldHaveDefault", GlobalConstants.TRUE);
currentNode.getSession().save();
}
}
Like Sharath Madappa say's that's the way it works fine if component name and jsp name same. If you dont have componentname.jsp under component or page, cq:template won't work.(Reference:http://labs.6dglobal.com/blog/2014-07-08/using-the-cq-template/)
If you hava componentname.html under your component, changed the node [cq:template] type to [cq:Template] instead of [nt:unstructured]. In this case, defaultValues can be added to the JCR when they are first added to the page.

Access jcr:content propeties from page node

I have dropdown where the values of options are like jcr:content/jcr:title, jcr:content/jcr:description, /jcr:content/par/entry/text etc. Here the last one is the property of parent, like jcr:title is the property of jcr:content node & text is the property of entry node, but entry has parent par and par has parent jcr:content. I am at the page node and using the below code to fetch such values which doesn't work :
Node n = (Node)nodeIter.next();
log.info(n.getProperty("/jcr:content/par/entry/text"));
Any Idea how to get values in such a way.
Thanks
Remove the starting slash from the property path. It makes the path absolute while you are interested in the relative one (as in other examples you've described):
n.getProperty("jcr:content/par/entry/text");

Get parent element name in XPath

I am trying to figure out how to get the name of the parent from a text node's scope.
//text()[name(parent)='p']
How can you get the name of the current node's parent?
If you're trying to test the name, you almost had it:
//text()[name(parent::*)='p']
If you're trying to return the name:
name(//text()/parent::*)
FYI, point of terminology: a text node is not an element.
Anyway, the most succinct way to select the parent of the current node is ..
So, the name of the parent element of the current node (which could be a text node) is name(..)
Substituting that into your XPath expression:
//text()[name(..)='p']
But a less roundabout way to write that would be
//p/text()
(assuming the p elements in the document have no namespace prefix). Either way, you're selecting all text nodes that are children of elements named p.
//text/..[#name='p']
This will get all parents of <text> nodes as long as the parent has a name attribute of p.

how to get id of a node in TinyMCE?

I want to get the id of a node inside TinyMCE.
I searched in the documentation, but could not find this.
How can this be done?
First, it is important which node you want to get the id from.
If you want to get the if of the parent node of your selection in TinyMCE use
tinymce.activeEditor.selection.getNode().id;
EDIT: In case you have a single node in your editor you can access this node id using
tinymce.activeEditor.getBody().firstChild.id;
let say if you have id as txtatinyID
<textarea class="editorHtml" id="txtatinyID"></textarea>
so following will return txtatinyID in tinyMCE V4
$(tinymce.activeEditor.selection.getNode()).closest('body').data('id')
So it will find the body of the current active editor and on the base of it will look for body and in it will get the value of data-id.