Javascript help required
Posted: Sun Oct 28, 2018 3:11 am
In compiling the livecode docset for DASH I need to link items provided in the list of associations with the relevant page in the docs.
I didn't think this would be too difficult and the current version of the docset works fine in most cases.
However there are some entries which fail my code for parsing the correct link.
Rather than hard code the exceptions I thought I would try to decipher what LC's dictionary does when it loads a page from the api database given this is the same raw info I have to use.
Unfortunately my knowledge of javascript is less than zero and am asking for some help in deciphering some code.
Rather than risk email mangling of the code I am asking on the forum for help.
I am looking at this file on git:
livecode-ide/Documentation/html_viewer/js/dictionary_functions.js
And in it there is the following construction which I haven't been able to find info on.
I figure it is a loop construction and it will step through each item retrieved by the "dataGet()" function.
Now following the comma there is "function(index,value)"
I don't know how to interpret this.
Is it a function call (if so to what?)
Is it a function definition (meaning?)
the full block is...
Given this is representative could someone rewrite this in english for me
?
Also,
does...
mean
if (lowercase of name does not equal pName) AND (lowercase of display name does not equal pName)
All this to to ultimately decipher what I think are the two main functions I need to understand...
James
I didn't think this would be too difficult and the current version of the docset works fine in most cases.
However there are some entries which fail my code for parsing the correct link.
Rather than hard code the exceptions I thought I would try to decipher what LC's dictionary does when it loads a page from the api database given this is the same raw info I have to use.
Unfortunately my knowledge of javascript is less than zero and am asking for some help in deciphering some code.
Rather than risk email mangling of the code I am asking on the forum for help.
I am looking at this file on git:
livecode-ide/Documentation/html_viewer/js/dictionary_functions.js
And in it there is the following construction which I haven't been able to find info on.
Code: Select all
$.each(dataGet(), function(index, value) {
Now following the comma there is "function(index,value)"
I don't know how to interpret this.
Is it a function call (if so to what?)
Is it a function definition (meaning?)
the full block is...
Code: Select all
function entryIdToIndex(pId){
var tIndex = 0;
$.each(dataGet(), function(index, value) {
if(value.id == pId){
tIndex = index;
return false;
}
});
return tIndex;
}

Also,
does...
Code: Select all
if (value.name.toLowerCase() != pName
&& value["display name"].toLowerCase() != pName)
mean
if (lowercase of name does not equal pName) AND (lowercase of display name does not equal pName)
All this to to ultimately decipher what I think are the two main functions I need to understand...
Code: Select all
//first block
case "associations":
if($.isArray(value)){
tHTML += '<div class="col-md-2 lcdoc_section_title">'+index+'</div><div class="col-md-10" style="margin-bottom:10px">';
var association_html = "";
$.each(value, function(index2, value2)
{
var tIndex = resolve_association_index(value2, tEntryObject.library);
var tAssociation;
if (isDefined(tIndex))
{
var tName = value2;
if (tState.data[tIndex].hasOwnProperty("display name"))
tName = tState.data[tIndex]["display name"];
tAssociation = click_text_from_index(tName, tIndex);
}
else
tAssociation = value2;
if (association_html == "")
association_html = tAssociation;
else
association_html += ',' + tAssociation;
});
tHTML += association_html+'</div>';
}
break;
// second block
// Associations must be one of the following:
const s_association_types = ["object","library","glossary","module","widget"];
function resolve_association_index(pName, pAPI)
{
var tIndex;
$.each(s_association_types, function(tTypeIndex, tType) {
tIndex = entryNameToIndex(pName, tType, pAPI)
if (isDefined(tIndex))
return false;
});
return tIndex;
}
James