Field text substring to mimic hotword in XML

Using XMLHttpRequest() to configure entire ToolBook pages.

Field text substring to mimic hotword in XML

Postby Andy » Mon Feb 10, 2020 9:32 am

I have a text field to which I have added html span tags. They are used to provide object IDs for substrings of the text so the substrings can be styled dynamically. Now I need certain other substrings of that text to be clickable, like hotwords. In the post, "Events supported in XML documents", I saw how a click event can be defined in XML for a field.
I would like to do this for my substrings but have not had any luck. I tried using ID attributes in both span tags and anchor tags but I can't get either of them to accept a click. I think I might need to provide an href attribute to the anchor but I don't know what the target would need to be. Is there a way to achieve this kind of functionality?
Thanks, Andy
Andy
 
Posts: 47
Joined: Tue Sep 09, 2014 3:40 pm

Re: Field text substring to mimic hotword in XML

Postby Clifton » Mon Feb 10, 2020 10:32 pm

This is where the real power of XML files start to benefit developers. There is literally nothing your cannot do in ToolBook when paired with XML configuration files.
Consider this ToolBook page with a single field drawn named "myField":
    Image 1.png
    ToolBook page with a single field.
    Image 1.png (1.32 KiB) Viewed 5808 times

To create an example that may simulate in principle what you are trying to do:
  1. I created this CSS file to establish effects when the <a> link is clicked:
  2. I created this XML file which contains everything else required for this example:
  3. I added the CSS and XML files to the DHTML export tree of the TBK file.
    Image 2.png
    Add CSS & XML to Export Tree List
    Image 2.png (82.75 KiB) Viewed 5808 times
  4. Finally, I added a single action to the on load page event of the ToolBook page. The XMLHttpRequest() loads the XML file and processes the configuration.
    Image 3.png
    Add XMLHttpRequest() action on load page.
    Image 3.png (13.68 KiB) Viewed 5808 times
After exporting the TBK, I got this result:

The key to this is the XML tag <showMsg>. This tag tells PowerPac's XML Interpreter to locate the element whose id is "showMsg" and style the font-weight to normal and then add an onclick function to toggle the styling for the contents of the span element whose id is "userid".

Except for the XMLHttpRequest() action in ToolBook, no other actions are used. Everything is included in the XML file. This makes exporting your TBK file very fast and you can just edit your XML files after export to get everything to work as expected. This beats using actions and waiting for ToolBook to re-export the file only to find out more edits are required.

Finally, the CSS stylesheet was used only to create an effect when the <a> link is hovered and clicked.
 
Attachments
fieldXML.zip
ToolBook source with XML, CSS (v11.5)
(114.79 KiB) Downloaded 643 times
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Field text substring to mimic hotword in XML

Postby Andy » Thu Feb 13, 2020 1:34 pm

Yes, that's just what I need. Thanks!
Andy
 
Posts: 47
Joined: Tue Sep 09, 2014 3:40 pm


Return to XML Configurations – Plugin Examples

Who is online

Users browsing this forum: No registered users and 3 guests

cron