selectNode() not working in IE8 - tinymce

I need to select a node in tiny mce, I'm trying following code. It works in non-IE browsers, but on IE it gives error as -
Error: Object doesn't support this property or method
Code -
rng = ed.selection.getRng();
rng.selectNode(tn);
The second line causes the error. Is there any other IE compatible method for this ?

The reason for this is the different range object you get. In FF you get an object which offers you several functions like selectNode(). The IE range only presents you a textrange object which contains only properties.
The solution to this is easy:
// true is important here - causes getRng to return a DOM Range and not a text range (IE)
rng = ed.selection.getRng(true);
rng.selectNode(tn);

I read about TextRange object and was able to do what I intended. I wanted to set my cursor inside a span. I could do it using TextRange object properties and methods as follows -
range.moveToElementText (node); //node is the span in which I wanted to place my cursor
range.select ();
moveToElementText - Aligns the start and end points of the current TextRange object to the text content of the specified element. I added an nbsp; to the span and with the above code could replace it, by my caret.

Related

Can I get the style object and Get the property of it?

I wanted to use javascript addin's to get the style object and get some proerties of it for example maybe paragraph property and get the indentation of this specific style but I cant get to the style object and get the property of it. I know that there is a collection of every style in document but I cant get any properties of those. There is way to change style in selected range but it could be very fine if I could get style from the range maybe and like i said erlier get some properties of it.
This is code in Word VBA that is example of property i want to see value of:
documents("[file_name]").Styles([index]).ParagraphFormat.LeftIndent
We can set the value to any variable:
Dim var As Integer/Long
Let var = documents("[file_name]").Styles([index]).ParagraphFormat.LeftIndent
As far as I know the office.js API for Word does not currently (v. 1.4) provide any Style objects with the kind of properties that you are used to seeing via the Object Model that VBA uses. All it lets you do is get the style names (localized and built-in) associated with another object such as a range, a paragraph, or various style properties associated with a table.
i.e. at the moment, the only way you would be able to get detailed style information would probably be to retrieve the document's XML and interpret that. Hard, I suspect.
I think that probably answers your question but in case you were looking for code to retrieve a style, to get the style name of a range, say, is straightforward, e.g. in Script Lab you can start with one of the basic JavaScript samples and modify its run function so it looks like this:
function run() {
return Word.run(function(context) {
var range = context.document.getSelection();
range.load("style");
return context.sync().then(function() {
console.log('The selected style was "' + range.style + '".');
});
});
}
Precisely which style name you get depends on the range - if you select two paragraphs with different styles, the style name will be "", and so on.

Reaching the referenced text from a Word interop field object

I am using Word interop to build a Word plugin. In this plugin I have a case where I want to examine all
Field objects in the document and when that field is a cross-reference to another place in the same document I need to be able to capture the text in the paragraph that the field is referring to.
I was able to get the name of the field object but there were no bookmarks defined in the Document although in Word I could click on the field to get to the other location.
Example field
Example field as code
referenced text I need to get
No Bookmark objects are defined
I tried to simulate the user clicking on the field by invoking DoClick() on it and then I accessed V_V_Scalar_Document_Generic.Application.Selection.Range.Text
but it gave nothing. I also tried the GoTo approach below but still didn't reach the referenced text.
System.Collections.Generic.List<string> L_V_List_String_Fields = new System.Collections.Generic.List<string>();
foreach (Field L_V_Scalar_Field_Item in V_V_Scalar_Document_Generic.Range.Fields)
{
try
{
if (L_V_Scalar_Field_Item.Type == WdFieldType.wdFieldRef)
// L_V_Scalar_Field_Item.Data --> gives COM exception
// L_V_Scalar_Field_Item.Code.ID --> blanks
// L_V_Scalar_Field_Item.DoClick() 'will not help because fields are not always hyperlinks
// L_V_Scalar_Field_Item.Result.Text --> gives the text of the field itself
// all variations I tried for the target parameter in the line below (last param) are not working
// V_V_Scalar_Document_Generic.[GoTo](Microsoft.Office.Interop.Word.WdGoToItem.wdGoToField, System.Type.Missing, System.Type.Missing, "_Ref28680085")
// Dim L_V_Scalar_String_Source as string = V_V_Scalar_Document_Generic.Application.Selection.Range.Text
L_V_List_String_Fields.Add($"CodeText:{L_V_Scalar_Field_Item.Code.Text} |FieldType:{L_V_Scalar_Field_Item.Type} |FieldKind:{L_V_Scalar_Field_Item.Kind} |SourceText:{"source text ??"}");
}
catch (Exception L_V_Scalar_Exception_Generic)
{
}
}
The bookmarks are not listed because Word has a convention that bookmarks with names starting with an underscore ("_") are "hidden". In the Insert->Links->Bookmark dialog box, you can see them if you check the "Hidden Bookmarks" box, but in the Find and Replace box, you have to enter the name manually.
Even when Bookmarks are hidden, you can reference them. So for example you should be able to do something like this (this is VBA syntax):
Dim TargetText As String
TargetText = ActiveDocument.Bookmarks("_Ref28680085").Range.Text
to get the text "covered" by the bookmark. In theory, you could use Goto, by using wdGotoBookmark instead of wdGotoField, except that I think it will only have a chance of working with the Selection object, not a Range object.
Depending on what type of cross-reference the user inserts, Word "covers" different parts of the referenced material. So you may need to construct the Range you really need, e.g. using the Bookmark's Range.Start to tell you which paragraph the reference is pointing at.

Creating an array for multiple instances targeting IDs with non static members

I am trying to automate text boxes to fill with a certain value, however the text boxes names are not static so they will always change. I am looking to find a way to always populate them even though they do not have a static name and how to find the second, third, fourth etc instance of the boxes and be able to also fill them without overwriting the previous text boxes
i have tried using the _collect function in sahi pro but could not find how to target the class correctly
I expect to be able to populate any textbox using the same class name without overwriting the first instance of this class.
I am using Sahi pro.
The sahi documentation on _collect seems to be you exactly what you are looking for
// Collect all textboxes matching any identifier, in table "listing".
// Note the use of match all regular expression "/.*/"
var $textboxes = _collect("_textbox", "/.*/", _in(_table("listing"));
// Iterate and set values on all textboxes
for (var $i=0; $i<$textboxes.length; $i++) {
_setValue($textboxes[$i], "value");
}
If this does not solve your problem, please provide an example of the html and of your _collect code

Filters Raw value in Views on multilingual site?

On Drupal8, I have a View who filter nodes from 2 parameters (each is a Taxonomy ID from different vocabulary). So I have a path like /filter1/%/filter2/% where filter1 raw value is the path component 2 filter2 raw value is the path component 4.
It works fine on the default language on the site cause there's no langcode in the url. But when I switch to a different language the langcode is added to the path and it becomes /zh-hans/filter1/%/filter2/% or /fr/filter1/%/filter2/%.
At this point the view is not working correctly anymore cause filter1 raw value is the path component 3 and filter2 raw value is the path component 5.
Anybody knows how to solve that?
After working around I find out that my question was dumb. The view didn't worked in chinese but it was not about the thing I mentionned. I take a look to the condition with a hook_views_query_alter and saw that the arguments where retrieved correctly in the url whatever language the page is in...
My problem was a I put a filter criteria on "Content: Translation language (= Interface text language selected for page)". I usually use it to display the result in the correct language. But in this case, it avoid results to display on other language than the default one. I don't understand why but it works without it and it serves the right translated nodes.

prevObject returned when selecting an element

So I'm making some elements in my js file as follows:
grocerySpan = $("<span>").addClass("grocery").html(grocery.name).attr('id',"page"+groceriesIdCounter);
My first question is whether it is ok that I am assigning id as i did in the line above (using string concatenating)?
I have different spans made with each their own id, #page0, #page1..., now when I try selecting the a specific span as follows:
var tempGrocerySpan = $("span"+"#page"+groceriesIdCounter+".grocery");
I get a prevObject returned.
now here is a screenshot of my DOM from
chrome debugger
As I read a prevObject means that the selector can't find the current element selected, but as I can see from chrome debugger my selecter and the element selector are the same, or am I overseeing something?
Thanks for the help.