TinyMCE - How to get the complete markup where the cursor is - tinymce

I'm using
tinyMCE.activeEditor.selection.getNode().innerHTML;
and it gives me what I'm expecting
<li>cell number 1</li>
but sometimes it gives me only the value without the markup.
cell number 1
Is there another trick to obtain that easily? Thanks in advance !

I think this is due to the fact that the selected node is a textnode.
In this case you want the parentNode.
You may use this to get the node you want:
var node = tinyMCE.activeEditor.selection.getNode();
node = node.nodeName == "#text" ? node.parentNode : node;

Related

how to fill na with a specific value based on a condition

Still learning python, and struggling with dates and na's.. I have a situation as the image below would show
enter image description here
for the NAT values in the column EndDT_New, i would like to fill them with a specific value based on a condition, eg:
if the DATE_ACT_CLOSED = '01/01/2040' then replace just the NAT in EndDT_New with 30/03/2021 else
if the DATE_ACT_CLOSED <> '01/01/2040', then replace just the NAT in EndDT_New with the value in DATE_ACT_CLOSED .
My previous experience is in SAS, so its quite a learning curve and mind shift to python.
Any help is much appreciated.
Kind Regards,
i reckon i figured it out.
df_all_valid.loc[(np.isnat(df_all_valid['EndDT_New'])==True) & (df_all_valid['DATE_ACT_CLOSED'] == '01/01/2040'), 'EndDT_New'] = np.datetime64('2021-03-30')

Check if Matlab struct, dynamic Field Value is empty

I have a struct x, with dynamic Fields, respectively dynamic Field names. But basically, only the first Field is relevant for me.
So I want to check if the Value of the first Field is empty, speak a 1x1cell or a 0x1cell..
or
I'm experimenting e.g. with:
isempty(fieldnames(x))
isempty(x(1))
if isempty(x(1))
msgbox('empty')
else
msgbox('result')
end
but got to no solution. Does anybody have a clue?
Speak, check if the Value of the first Field of the struct is empty or not..
If only the first field is relevant to you, then you can proceed as follows :
Get the fieldnames list of your struct
names=fieldnames(x);
Get the size of the first field
SizeOfFirstField=size(x.(names{1}));
Then you can just check if the first value in SizeOfFirstField is 0 or 1 in your if condition :
if SizeOfFirstField(1)==0
msgbox('empty')
else
msgbox('result')
end
Maybe you can also try this shorter form:
isempty(fieldnames(x))
where x is your struct variable.

Traversing DOM nodes in CKEditor-4

We have a bug at this CKEditor plugin, and a generic solution is like to this, applying a generic string-filter only to terminal text nodes of the DOM.
QUESTION: how (need code example) to traverse a selection node (editor.getSelection()) by CKEditor-4 tools, like CKEDITOR.dom.range?
First step will be to get ranges from current selection. To do this just call:
var ranges = editor.getSelection().getRanges();
This gives you an array of ranges, because theoretically (and this theory is proved only by Firefox) one selection can contain many ranges. But in 99% of real world cases you can just handle the first one and ignore other. So you've got range.
Now, the easiest way to iterate over each node in this range is to use CKEDITOR.dom.walker. Use it for example this way:
var walker = new CKEDITOR.dom.walker( range ),
node;
while ( ( node = walker.next() ) ) {
// Log values of every text node in range.
console.log( node.type == CKEDITOR.NODE_TEXT && node.getText() );
}
However, there's a problem with text nodes at the range's boundaries. Consider following range:
<p>[foo<i>bar</i>bo]m</p>
This will log: foo, bar, and bom. Yes - entire bom, because it is a single node and walker does not modify DOM (there's a bug in documentation).
Therefore you should check every node you want to transform if it equals range's startContainer or endContainer and if yes - transform only that part of it which is inside range.
Note: I don't know walker's internals and I'm not sure whether you can modify DOM while iterating over it. I'd recommend first caching nodes and then making changes.

Requesting member of node_element results in "undefined"

I'm using Opa for a school project in which there has to be some synchronization of a textfield between several users. The easy way to solve this, is to transmit the complete field whenever there is a change performed by one of the users. The better way is of course to only transmit the changes.
My idea was to use the caret position in the textfield. As a user types, one can get the last typed character based on the caret position (simply the character before the caret). A DOM element has an easy-to-use field for this called selectionStart. I have this small Javascript for this:
document.getElementById('content').selectionStart
which correctly returns 5 if the caret stands at the fifth character in the field. In Opa, I cannot use selectionStart on either a DOM or a dom_element so I thought I'd write a small plugin. The result is this:
##extern-type dom_element
##register jsGetCaretPosition: dom_element -> int
##args(node)
{
return node.selectionStart;
}
This compiles with the opp-builder without any problem and when I put this small line of code in my Opa script:
#pos = %%caret.jsGetCaretPosition%%(Dom.of_selection(Dom.select_id("content")));
that also compiles without problems. However, when I run the script, it always returns "undefined" and I have no idea what I'm doing wrong. I've looked in the API and Dom.of_selection(Dom.select_id("content")) looked like the correct way to get the corresponding dom_element typed data to give to the plugin. The fact that the plugin returns "undefined" seems to suggest that the selected element does not know the member "selectionStart" eventhough my testcode in Javascript suggest otherwise. Anyone can help?
In Opa dom_element are the results of jQuery selection (i.e. an array of dom nodes). So if I well understood your program you should write something like node[0].selectionStart instead of node.selectionStart.
Moreover you should take care of empty selection and selection which doesn't contains textarea node (without selectionStart property). Perhaps the right code is tmp == undefined ? -1 : tmp = node[0].selectionStart == undefined ? -1 : tmp

Position of Range-Object in Excel

I am trying to figure out how to get the position of a selected Range in an Excel(2007)-Worksheet. Is there something similar to $self->{EXCEL}->ActiveCell->Row for Cells (self->{EXCEL} being an Excel-Object)?
I tried ->Selection->Range, ->ActiveSheet->Range, and as a workaround ->Range->Row, ->Range->Rows both with an Excel- and a Worksheet-Object with no success.
The most fancy output being two Cell-Objects, one for the start-address, the other one end-address.
Thanks for any helpful hints!
=== Update ===
I now use successfully the command $self->{EXCEL}->Selection->Address(); to retrieve the address of the selected range. By default I get the address in "A1"-format ($E$1:$G$14). Using ->Address("ToReferenceStyle:=xlR1C1") however does not return the address in "R1C1"-format as I would have expected...
Faulty command? Ignorant Excel? Thanky again on any helpful hint!
How about ->Selection->Address? I'm not sure on the format, but the address property of the selection (range object) will give you the address of the range for example. $A$1:$B$7. You would be able to parse the start and end by splitting the string on the colon.
To address your new questions... I'm not even sure if what you're using, but the third parameter of the address method is ReferenceStyle not ToReferenceStyle. So I would try either ->Address(ReferenceStyle:=xlR1C1) or ->Address(,,xlR1C1)