Unexpected problems

Workarounds and usability notes.

Re: Unexpected problems

Postby Clifton » Mon Jul 24, 2017 10:47 am

Change:
setTimeout( fct, [200]);

To:
setTimeout( fct, 200);

(Just remove the brackets around the timeout value. I only use them to define a variable placeholder, but it can cause some confusion.)

Understanding why this may fix some things:
When the browser loads up the DOM, not all objects refresh themselves with the browser before other function begin manipulating them. Much of the time, this is fine, but when you are changing sizes, positions, and loading other iframes, there is a lot going on and the developer has to determine where load process needs a little pause to freshen the DOM.

A number of PowerPac functions include a [notifyObject] parameter to automatically allow the DOM to freshen then immediately let another object know of this so additional processing can occur in an expected way. Functions like pgExtFiles() and XMLHttpRequest() and setWebFonts() are examples of functions that do this. If you start to use XML-based scripts, you can define <config# delay="[milliseconds]"> . . . </config#> which provide lots of flexibility. The idea is to make sure that not just on your development machine, but on slower machines accessing your content on the web, the results to the user will be exactly the same.

I would recommend studying the XML section of this forum to become familiar with how to use XML scripts. I recently took a ToolBook web application with thousands of actions (an which had become somewhat unstable at author level) and stripped it down to about a dozen XML files and only a few lines of action script to load the XML's. The application exports in less then 2 minutes whereas it used to taken 20-30 minutes. Plus you can play with the XML's in the export without having to re-export the application. Once you get used to it, this is a development dream!
 
Clifton
Site Admin
 
Posts: 731
Joined: Tue Jan 14, 2014 1:04 am

Re: Unexpected problems

Postby John Robin Dove » Mon Jul 24, 2017 1:19 pm

Many thanks. I will follow your instructions.
John Robin Dove
 
Posts: 484
Joined: Thu Jan 23, 2014 4:35 am

Re: Unexpected problems

Postby John Robin Dove » Tue Jul 25, 2017 7:08 am

Hi Clifton,

I've been experimenting a little. I already use an XML file to set up my page and in particular to adapt the captions and texts to the user's language. This works well but the length of the text varies according to the language used. For example the user sees "Media file loaded" in English but "Fichier média chargé" in French. Because It's longer in French the text is no longer centered correctly.

I tried using snapObjecToCenter to deal with this but apparently this is not possible. I can do it with pgTBObjSet like this (the name of the field is "isLoaded"):

Code: Select all
<isLoaded>
    <pgTBObjSet>
      <![CDATA[
        {myObjName : "isLoaded",
        myProperty  : "text",
        myValue : "Fichier média chargé",}
        ]]>
    </pgTBObjSet>
   
    <pgTBObjSet>
      <![CDATA[
        {myObjName : "isLoaded",
        myProperty  : "left",
        myValue : "135",}
        ]]>
    </pgTBObjSet>
  </isLoaded> 



No problems but some questions:

Is it necessary to have two <pgTBObjSet> blocks or could they be merged into one?

In case changing the left property is overloading the procedure (it isn't), would it be useful to include a delay before executing this? I tried putting

Code: Select all
<config#>
  delay="100"
  </config#>


before the <isLoaded> block but this caused an error. I also tried including myDelay in the parameters which worked but is it doing anything useful?


John
John Robin Dove
 
Posts: 484
Joined: Thu Jan 23, 2014 4:35 am

Re: Unexpected problems

Postby Clifton » Tue Jul 25, 2017 7:44 am

Future note: Please post XML-related stuff in that area of the forum. This will make it easier for others to find and benefit from these discussions.

<isLoaded>
<pgTBObjSet>
    <![CDATA[
{ myProperty  : "text", //No need to use [myObjName] as it is assumed by <isLoaded>
myValue : "Fichier média chargé" } //Trailing comma will cause errors
]]>
</pgTBObjSet>

<pgTBObjSet>
<![CDATA[
{ myProperty  : "left",
myValue : "135" } //Removed trailing comma ... quotes are optional (only needed if [myProperty = "bounds", "position", "size")
]]>
</pgTBObjSet>
</isLoaded>


If you are using pgTBObjSet() this way, which is fine, you need to have two XML blocks or tags to handle each execution.

If you choose to setup a <config#> section with delay, the XML examples show it this way:
<config2 delay="100">
<snapObjectToCenter>
<![CDATA[
{ tbName : "isLoaded", //NOTE: in <config> sections you must specify object to manipulate if one is required by the function
refObj : "myOtherObject",
axis : 'vertical',
onTop : false,
offset : "0,0" }
]]>
</snapObjectToCenter>
</config2>


NOTE: You probably need to run snapObjectToCenter() in a <config# delay="#"> section because when you set the text, the field will not freshen in the DOM until the XML file has finished loaded. JavaScript is linear in how it executes. So you are probably using snapObjectToCenter() using bounds which are based on the previous text of the field. Providing a little delay solves the problem.
Here is another way to do this:
<isLoaded>
<pgStyleObject>
<![CDATA[
{ theStyle : "width",
propVals : "auto" }
]]>
</pgStyleObject>
<pgTBObjSet>
<![CDATA[
{ myProp : "text",
myVal : "Fichier média chargé" }
]]>
</pgTBObjSet>
<function name="myLoad" event="load" params="e">
<!CDATA[
var fct = function() {
tbfunction_snapObjectToCenter( this.name, "myOtherObject", "vertical", false, "0,0");
};
setTimeout( fct, 100 );
]]>
</function>
</isLoaded>
Obviously in this case, you could do all sorts of stuff with your onload function, not just run a single function. PowerPac's XML Parser is pretty robust and can handle a lot of stuff. Nearly all events in the actions editor are supported.

BTW: if all you are doing to manipulating text or html for a field, you can do this:
<isLoaded>
<text>
<![CDATA[
Fichier média chargé
]]>
</text>
</isLoaded>

OR this for html:
<isLoaded>
<htmlText>
<![CDATA[
Fichier <b>media</b> <span class="myStyle">chargé</span>
]]>
</htmlText>
</isLoaded>


It is really about preference and readability when you go back and tweak the XML files.

ENJOY!
 
Clifton
Site Admin
 
Posts: 731
Joined: Tue Jan 14, 2014 1:04 am

Re: Unexpected problems

Postby John Robin Dove » Tue Jul 25, 2017 10:15 am

Thanks for all this useful code. I'm learning a lot!
John Robin Dove
 
Posts: 484
Joined: Thu Jan 23, 2014 4:35 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron