Page 1 of 1

Scroll my widget (='.'=)

Posted: Tue Aug 08, 2017 9:20 am
by Mariasole
Hi all brothers and sisters!
I'm doing experiments with the "browser" widget for the first time. 8)
I'm trying to control the scroll with a button.
Obviously I can not! :oops:
The code I use is this:

Code: Select all

set the vscroll of widget "Browser" to 100
I also tried to put the mouse pointer over and click on the dart at the bottom of the scroll, but there is nothing to do! :shock:
Does anyone know anything about the scroll behavior of these widgets? :roll:
Thank you all

(='.'=)
Mariasole

Re: Scroll my widget (='.'=)

Posted: Tue Aug 08, 2017 5:18 pm
by Klaus
Hi Maria,

I am afraid this is a bug, just added a comment to my bug:
http://quality.livecode.com/show_bug.cgi?id=19453


Best

Klaus

Re: Scroll my widget (='.'=)

Posted: Tue Aug 08, 2017 5:26 pm
by MaxV
If you don't use the widget, but the old style RevBrowserOpen
you can set the hscroll and vscroll with http://livecode.wikia.com/wiki/RevBrowserSet

Re: Scroll my widget (='.'=)

Posted: Tue Aug 08, 2017 9:46 pm
by [-hh]

Code: Select all

-- scrolls "to"  horizontally 0 and vertically 400 pixels
do "window.scrollTo(0,400);" in widget "browser"

-- scrolls "by" (additive) horizontally 10 and vertically 40 pixels
do "window.scrollBy(10,40);" in widget "browser"
Of course this works only if the webpage is wider and/or larger than the rect of your widget.
Also, if the webpage is "responsive" via its CSS, then only setting the vertical scroll will work and the horizontal value will be ignored.

If you wish to experiment also with javascriptHandlers you can find a more detailed answer here: phpBB2/viewtopic.php?f=7&t=28958

Re: Scroll my widget (='.'=)

Posted: Wed Aug 09, 2017 3:36 pm
by Mariasole
Thank you all for the help! :D
Thank you Klaus! It's a satisfaction for me to have "uncovered" (indirectly) a bug!
Thanks MaxV! A beautiful page I will treasure.
Thank you -hh! An interesting solution! Especially for me that I do not know anything about js!

But... I wanted to ask you... :roll:

If with a command I put the mouse pointer over the widget browser at a weblink, and I want to click, nothing happens.
This is part of Klaus's bug, or the mouse via command can not "interact" with the webpage inside widget (controlled via commands)? :shock:

I do not know if I explained it, so I'll make it better!

I say to the mouse: put on coordinates 500, 500 and click!
The mouse is placed on the coordinates above the widget that load an html page with a link placed exactly at the coordinates 500,500. And... click!
With "real mouse" everything works, with the command code nothing! :oops:

Thank you all!

(='.'=)
Mariasole

Re: Scroll my widget (='.'=)

Posted: Wed Aug 09, 2017 7:15 pm
by [-hh]
This will not work, because the browser widget isn't an ordinary LC control.
But you could try

Code: Select all

-- (x,y) is relative to the topleft of the html page
do "document.elementFromPoint(x,y).click();" in widget "browser"
So, if the topleft of the widget is (bx,by) and the scroll of the htmlpage is (sx,sy) then your card coordinate (500,500) would result in x=500-bx-sx and y=500-by-sy,

for example with a topleft of (10,20) and a scroll of (0,70)
do "document.elementFromPoint(490,410).click();" in widget "browser"

You can have info about getting some other mouseEvents from the widget here:
viewtopic.php?p=154496#p154496

Re: Scroll my widget (='.'=)

Posted: Fri Aug 11, 2017 11:03 am
by Mariasole
Thanks really -hh!
Very interesting! I'm doing tests to figure out how it works ...
It's fascinating that I can use javascript commands on the widget!
Even though I do not know anything about javascript I can play to make stuff, and maybe something works! 8)
Etiam capillus unus habet umbram suam!

Now, dear -hh, I want to ask you something, since you are a super expert in LC and Javascript.
I have tried this instruction:

Code: Select all

   do "document.characterSet;" in widget "browser"
I tried "answer it" but it does not work....

How do I pass a variable from javascript/browser widget to LC?


Exemplo plus quam ratione vivimus! :wink:

(='.'=)
Mariasole

Re: Scroll my widget (='.'=)

Posted: Fri Aug 11, 2017 1:21 pm
by [-hh]
Mariasole wrote:Since you are a super expert in LC and Javascript ...
I started to learn LC in 2013. And I started to learn javascript "by the way, as I need it" in Nov 2016. So give these flowers to others...

There are a lot of good sources to learn javascript, for example w3schools, with a lot of interactive examples.
Mariasole wrote:How do I pass a variable from javascript/browser widget to LC?
(a) Usually the following works, but there are exceptions.

Code: Select all

function jsExecute pJavascript
   do pJavascript in widget "browser"
   return the result
end jsExecute
(b) A more reliable approach is the following.

1. Put in the card's script:

Code: Select all

-- This handler receives pVal from the widget
-- it may also reside in the widget's script
on jsGetVal pVal
  put pVal into fld "fromWidget" -- a field is more 'safe' than the msg
end jsGetVal

-- This registers the receiving handler "jsGetValwith" with the widget
on openCard
  set the javascriptHandlers of widget "browser" to "jsGetVal"
end openCard
2. Then script a button as follows (includes several examples).

Code: Select all

on mouseUp
  put "liveCode.jsGetVal(document.characterSet);" into js
  -- put "liveCode.jsGetVal(document.title);" into js
  -- put "var d = Date(); liveCode.jsGetVal(d);" into js
  -- put "var x = Math.pow(2,42); liveCode.jsGetVal('2^42 = ' + x);" into js
  do js in widget "browser"
end mouseUp

Re: Scroll my widget (='.'=)

Posted: Wed Aug 16, 2017 8:07 am
by Mariasole
Thanks really -hh!
In practice you started learning LC from 2013 like me!
Only that I still do not understand and you are a magician! :oops:
Please accept my estimation flowers! :D

(='.'=)

Re: Scroll my widget (='.'=)

Posted: Sat Jan 20, 2018 12:40 pm
by trevix
Hi All.
Has been sometime since the topic started, but may be -hh is willing to help out.

How about if I want to run this javascript (and may be get some return in LC):

Code: Select all

// create an event on calendar "Personale"

var app = Application.currentApplication()
app.includeStandardAdditions = true
var Calendar = Application("Calendar")

var eventStart = app.currentDate()
eventStart = eventStart
eventStart.setDate(eventStart.getDate() + 1)
eventStart.setHours(15)
eventStart.setMinutes(0)
eventStart.setSeconds(0)
var eventEnd = new Date(eventStart.getTime())
eventEnd.setHours(16)

var projectCalendars = Calendar.calendars.whose({name: "Personale"})
var projectCalendar = projectCalendars[0]
var event = Calendar.Event({summary: "Important Meeting!", startDate: eventStart, endDate: eventEnd})
projectCalendar.events.push(event)
event
To be able to run a JavaScript could lead to the creation of a LC library to control the Calendar of OSX and iOS, I think, as from https://developer.apple.com/library/con ... 6-CH97-SW3.
Very useful since Applescript works only on OSX.
Trevix