Can anyone see what is wrong with this conversion ...
# javascript
g
Can anyone see what is wrong with this conversion of JS to to KJS? var title is where I think the problem is. JS
Copy code
// Add and beautify tooltips
      [['sw-visibility', 'Show Borders'], ['preview', 'Preview'], ['fullscreen', 'Fullscreen'],
       ['export-template', 'Export'], ['undo', 'Undo'], ['redo', 'Redo'],
       ['gjs-open-import-webpage', 'Import'], ['canvas-clear', 'Clear canvas']]
      .forEach(function(item) {
        pn.getButton('options', item[0]).set('attributes', {title: item[1], 'data-tooltip-pos': 'bottom'});
      });
      [['open-sm', 'Style Manager'], ['open-layers', 'Layers'], ['open-blocks', 'Blocks']]
      .forEach(function(item) {
        pn.getButton('views', item[0]).set('attributes', {title: item[1], 'data-tooltip-pos': 'bottom'});
      });
      var titles = document.querySelectorAll('*[title]');

      for (var i = 0; i < titles.length; i++) {
        var el = titles[i];
        var title = el.getAttribute('title');
        title = title ? title.trim(): '';
        if(!title)
          break;
        el.setAttribute('data-tooltip', title);
        el.setAttribute('title', '');
      }
KJS
Copy code
val toolTips = arrayOf(
        arrayOf("sw-visibility", "Show Borders"),
        arrayOf("preview", "Preview"),
        arrayOf("fullscreen", "Fullscreen"),
        arrayOf("export-template", "Export"),
        arrayOf("undo", "Undo"),
        arrayOf("redo", "Redo"),
        arrayOf("gjs-open-import-webpage", "Import"),
        arrayOf("canvas-clear", "Clear canvas")
    )
    toolTips.forEach {
        val openTmBtn = panels.getButton("views", "open-tm")
        openTmBtn.set("title", it[1])
        openTmBtn.set("data-tooltip-pos", "bottom")
    }
    val titles = document.querySelectorAll("*[title]")
    for(index in 0..titles.length) {
        val el = titles.item(index)
        var title = el?.parentElement?.getAttribute("title")?.trim() ?: ""
        if(title.isNotEmpty()) {
            el?.parentElement?.setAttribute("data-tooltip", title)
            el?.parentElement?.setAttribute("title", "")
        }
    }
surprisingly js() doesn't even work, webpack freaks out on it for some raisin. getAttribute doesn't seem to be implemented for KJS Node object that gets returned... hmmm. Kind of surprised they have auto converters for html to KJS but not for css or js to KJS when you paste it in IDEA... would make life much easier... 1000% easier. The error from webpack: You may need an additional loader to handle the result of these loaders.
Solved: trick was casting a Node as an Element, and other fixes. Second set of arrays doesn't work for some reason, doesn't delete the titles but the tooltip but it does add the data-tooltip attribut which is a little odd (but examples seem to have this issue too:
Copy code
val toolTipsForPanelOptions = arrayOf(
    arrayOf("sw-visibility", "Show Borders"),
    arrayOf("preview", "Preview"),
    arrayOf("fullscreen", "Fullscreen"),
    arrayOf("export-template", "Export"),
    arrayOf("undo", "Undo"),
    arrayOf("redo", "Redo"),
    arrayOf("gjs-open-import-webpage", "Import"),
    arrayOf("canvas-clear", "Clear canvas")
)
val toolTipsForPanelViews = arrayOf(
    arrayOf("open-sm", "Style Manager"),
    arrayOf("open-layers", "Layers"),
    arrayOf("open-blocks", "Blocks")
)
toolTipsForPanelOptions.forEach {
    val btn = panels.getButton("options", it[0])
    btn.set("attributes", jsObject<dynamic>{
        title = it[1]
        this["data-tooltip-pos"] = "bottom"
    })
}
toolTipsForPanelViews.forEach {
    val btn = panels.getButton("views", it[0])
    btn.set("attributes", jsObject<dynamic>{
        title = it[1]
        this["data-tooltip-pos"] = "bottom"
    })
}
val titles = document.querySelectorAll("*[title]")
for(index in 0..titles.length) {
    val el = titles.item(index) as Element
    val title = el.getAttribute("title")?.trim() ?: ""
    if(title.isNotEmpty()) {
        el.setAttribute("data-tooltip", title)
        el.setAttribute("title", "")
    }
    console.log(title)
}