Right mousedown

Workarounds and usability notes.

Right mousedown

Postby John Robin Dove » Wed Nov 04, 2020 5:36 am

Hi Cliffton,
I have a problem with detecting right or left button down. On a single object there is no problem:

Code: Select all
 <function name="myMouseDown" event="mousedown" params="e" useTB="true">
    <![CDATA[
    sharedActions.down = false;
    sharedActions.counterNo = 1;
      if (e.button == 0)
      {
      sharedActions.startTimer();
      }
      else
      {
      sharedActions.insertTime();
      }
    ]]>
    </function>


but the same code won't work on a group. And unfortunately it's a big group (60 objects).
Any suggestions please?

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

Re: Right mousedown

Postby Clifton » Wed Nov 04, 2020 1:08 pm

As it turns out you can use XML to make a function for the mousedown event on a group.
ToolBook supports this, but does not expose all of the information that you are looking for.
However, the following example will provide everything you need and much more.

Example:
  • Created a ToolBook single page file with one group of two objects ... rectangles.
  • Created the following XML file to completely configure the page.
  • Added the XML to the export files of the project by using the DHTML Export Tree Manager.
  • Here is actual exported result:
    (click a rectangle to view information about the object and which button was used)
Enjoy!
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Right mousedown

Postby John Robin Dove » Thu Nov 05, 2020 5:29 am

Thank you very much!

I guess I could have settled for click + control but I always try to reproduce all aspects of the original VB program. So far every little detail has been possible thanks to your Powerpac functions.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Right mousedown

Postby John Robin Dove » Sun Nov 08, 2020 11:16 am

Hi Clifton,
New problem: I applied your code to my program and I thought it worked. So either it has just stopped working (unlikely) or I didn't test it enough. Either way it no longer does what I want. However reassuringly your original code still works exactly as planned so it must be something to do with my code. It is pretty long-winded.
Code: Select all
 <function name="myMouse" event="mousedown" params="evt,undef,target,mX,mY,isShift,isCntrl" useTB="true">
  <![CDATA[
  dObj = gTBo(target.id, 'objRef'), //Get the DOM object
  event = getToolBookFrame().parent.event || getToolBookFrame().event;
  tbfunction_pgTBObjSet("infoGroup", "visible", false);
    if (event.button == 0)  //left button
    {
    sharedActions.triggerMarker(target.name);
    }
    else if (event.button == 2)  //right button
    {
    var nameDetail = target.name.split("");
    var ANumber;
      if (nameDetail[2])
      {
      ANumber = nameDetail [1] + nameDetail[2];
      }
      else
      {
      ANumber = nameDetail [1]
      }
    var triggerLine = keys.triggers[ANumber];
    var triggerDetail = tbfunction_pgSplitToArray(triggerLine, ",", true);
    var myColor = tbfunction_pgGetStyle(target.name, "background-color");
    var myType;
    var txt;
      if (myColor == "#ffff40")
      {
      myType = 1;
      txt = triggerDetail[3];
      }
      else if (myColor == "#ffbfff")
      {
      myType = 3;
      txt = triggerDetail[5];
      }
      else if (myColor == "#bfbfff")
      {
      myType = 7;
      txt = triggerDetail[3];
      }
      else
      {
      var myClass = tbfunction_userProperty(target.name, "class", "", "get");
        if (myClass == "pause1")
        {
          if (triggerDetail[5])
          {
          myType = 2;
          }
          else
          {
          sharedActions.showRequest("395`1", "1"); //This type of action does not display text.
          return;
          }
        }
        else if (myClass == "record1" || myClass == "write1")
        {
        sharedActions.showRequest("395`1", "1"); //This type of action does not display text.
        return;
        }
        else if (myClass == "pause3")
        {
        myType = 6;
        }
      }
     var itemNo;   
      if (myType == 1 || myType == 7)
      {
      txt = triggerDetail[3];
      itemNo = 3;
      }
      else if (myType == 2 || myType == 3 || myType == 6)
      {
      txt = triggerDetail[5];
      itemNo = 5;
      }
      else
      {
      sharedActions.showRequest("395`1", "1"); //This type of action does not display text.
      return;
      }
    txt = tbfunction_pgReplace("¤", ",", txt, true);
    txt = tbfunction_pgReplace("##", "\n", txt, true);
    tbfunction_pgTBObjSet("teacherPad", "visible", true);
    tbfunction_pgTBObjSet("teacherPad", "text", txt);
    sharedActions.showPad(0);
    tbfunction_pgTBObjSet("holdInfo", "text", "text:," + itemNo + "," + ANumber);  //THIS NEEDS FIXING !!??
    sharedActions.showRequest("396`1", "1"); //Change the text then click on the button below.
    }
  ]]>     
  </function>

Strangely it will work correctly only once. The first time it works correctly. The result is either 0 or 2. Thereafter it is stuck on whatever the first result was (0 or 2). If I reload the page the error disappears. This suggests that something needs refreshing. Why does your code not produce the same effect? I have tried isolating my code in an var fct block and setting a timeout but it makes no difference. Maybe there something badly wrong in my code. It wouldn't be the first time. :)
John

UPDATE

I have just discovered that if I put the whole lot of you code before mine it works!?
Code: Select all
var msg = '',
  dObj = gTBo(target.id, 'objRef'), //Get the DOM object
  event = getToolBookFrame().parent.event || getToolBookFrame().event;
  for (var i = 0; i < arguments.length; i++)
  {
  //Collect the parameter values from ToolBook event
  msg += 'param ' + i + ':   ' + arguments[i] + '\n';
  }

  msg += 'button:   ' + event.button + '\n';
  msg += 'TB Object name:   ' + target.name + '\n';
  msg += 'TB Object id:   ' + target.id + '\n';
  msg += 'DOM id:   ' + dObj.id + '\n';
  msg += 'DOM tag:   ' + dObj.tagName + '\n';
  msg += 'DOM html:   ' + dObj.innerHTML;
    if (event.button == 0)  //left button
    {
    sharedActions.triggerMarker(target.name);
    }
    else if (event.button == 2)  //right button
    {
etc ...
}

I have a feeling it's something to do with the lines ending with commas:
var msg = '',
dObj = gTBo(target.id, 'objRef'),
//Get the DOM object
I don't understand this structure.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Right mousedown

Postby Clifton » Sun Nov 08, 2020 2:10 pm

This code:
var msg = "", dObj = gTBo(target.name, "objRef");


. . . is exactly the same as . . .
var msg = "";
var dObj = gTBo(target.name, "objRef");


The comma merely allows setting multiple local variables on the same line, at least in this case.

In your code, I think the real problem is you are not using local variables.
var event = getToolBookFrame().parent.event || getToolBookFrame().event;

. . . results in a local variable.
However, your code ...
event = getToolBookFrame().parent.event || getToolBookFrame().event;

. . . sets a global variable which essentially keeps destroying the window.event thus making your code work only once, which is the first time the global is set. After that, a conflict will occur between the window.event system and your code.

So just make sure you are using local variables to avoid a conflict with what the DOM event system is actually trying to accomplish.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Right mousedown

Postby John Robin Dove » Mon Nov 09, 2020 4:54 am

Many thanks. I understand now, I think. event is the third item in a stack so it is a var like the other two. By taking it out of the stack I turned it into a global variable (without the usual preceeding var). I had noticed that this can happen before now. These undeclared global variables are somewhat surprising and also very dangerous from my point of view but no doubt they make Javascript even more flexible for experts

I am currently converting all my program to empty'Toolbook + XML only because the existing version, Toolbok + extra js + XML is just too complex to debug if anything unforeseen happens. It's taking rather longer than I had hoped.

I was not surprised that you found the event.button property for groups because this was already functioning in my Toolbook actions version.

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


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron