spacer.png, 0 kB
  May 24, 2013, 07:14:12

 
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: window.scrollTo()  (Read 11686 times)
mrjb

Posts: 18


View Profile
« on: September 11, 2008, 22:43:21 »

time to worry again  Grin I have been playing.


I have added a little bit of custom code to the end of the browse.tpl/php and js.js to re-open the div I was looking at when I click to preview . Basically it just re-runs ShowSetInfo when the page reloads. That works fine.

I am now trying to get the page to automatically scroll down to the aforementioned div using window.scrollTo(x,y).   I had gotten the x,y position of the open div and then called window.scrollTo() on that position ... however it doesn't work. So I took the code out and am now just testing with window.scrollTo in the tpl via a custom smarty variable I setup in browse.php.  I have tried it in all sorts of different places in the page thinking that I am just not using it in the correct div but I am now at a loss. I just can't get the page to scroll period.

Any ideas?

Mr Johnathan Bravo
Logged

Mr Johnathan Bravo
spearhead
Administrator
*
Posts: 1038


View Profile WWW
« Reply #1 on: September 12, 2008, 11:16:55 »

time to worry again  Grin I have been playing.


I have added a little bit of custom code to the end of the browse.tpl/php and js.js to re-open the div I was looking at when I click to preview . Basically it just re-runs ShowSetInfo when the page reloads. That works fine.

I am now trying to get the page to automatically scroll down to the aforementioned div using window.scrollTo(x,y).   I had gotten the x,y position of the open div and then called window.scrollTo() on that position ... however it doesn't work. So I took the code out and am now just testing with window.scrollTo in the tpl via a custom smarty variable I setup in browse.php.  I have tried it in all sorts of different places in the page thinking that I am just not using it in the correct div but I am now at a loss. I just can't get the page to scroll period.

Any ideas?

Mr Johnathan Bravo


Sounds useful. I'm not really a JS guru here... maybe styck knows. But be sure to post the code if you got it working so we can include it.
Logged
mrjb

Posts: 18


View Profile
« Reply #2 on: September 12, 2008, 17:50:35 »

will do.

Still haven't figured this one out...

if you want the code to re-open the currently open div I will post that... that works...

How should I do it. There's 3 different files I edited in a few different places.
Is there a utility that I could run that you know of that would make a diff of the files
? Or should I just post the code additions per file?

please advise...

thanks

Mr Johnathan Bravo
Logged

Mr Johnathan Bravo
spearhead
Administrator
*
Posts: 1038


View Profile WWW
« Reply #3 on: September 12, 2008, 18:12:18 »

just mail me the files you changed as you have them (see PM). That'd probably be easiest.

and yea there is a tool it's actually called diff ;-)

BTW firefox has a js debug plugin too... haven't tried it, but maybe that helps
Logged
mrjb

Posts: 18


View Profile
« Reply #4 on: September 12, 2008, 19:05:12 »

ok... will do.

I have been using the js error console and the DOM inspector to try and find out why window.scrollTo() isnt working. So far the call to window.ScrollTo() doesn't generate errors. I think I will lookup that debug console and try to step through it later today to see if I can get any more clues. Tnx for the pointer.

Mr Johnathan Bravo
Logged

Mr Johnathan Bravo
Styck
Administrator
*
Posts: 125


View Profile
« Reply #5 on: September 12, 2008, 23:24:55 »

You can't scroll the window, as the window isn't scrolling Smiley
It's the #contentout div that is actually scrolling. You can manually scroll by using:
document.getElementById('contentout').scrollTop=100;

In firefox, while trying the code in the location bar, it was buggy. But it should work or at least help you on your way! Smiley

Styck
Logged
spearhead
Administrator
*
Posts: 1038


View Profile WWW
« Reply #6 on: September 13, 2008, 00:47:19 »

Actually, what version do you work on? I hope at least 0.5.4 but preferably 0.5.5 or better You'd best use the version from Subversion http://code.google.com/p/urd/source/checkout as that is the most up-to-date and you can get regular updates of everything we add to the repository. (even though it maybe a bit unstable as that is our working copy - numbered 0.5.6). It also saves us time to merge patches back in.

Logged
mrjb

Posts: 18


View Profile
« Reply #7 on: September 13, 2008, 16:24:57 »

styck...
ok.. that explains it...I kinda thought I had to get a handle on the correct element but I didn't know that i couldn't use window.scrollto from within that div to get it scrolling. So can I use document.getElementById('contentout').scrollTo(x,y) from within js.js?  I have a couple of functions; getPosX(elementobject) and getPosY (elementObject) that get the X and Y pixel coord from the document of the element you pass. So it would be easier(I think?) to call the element.scrollTo from within that file.
 anyway I'll run some tests and I'll incorporate my code today or tomorrow and e-mail the files to Spearhead. 

Spearhead.
 using 0.5.5. Although if you want I can use the svn and make the changes in those files instead and then e-mail you either the full files or the diff files( now that I know that utility exists :0

Mr Johnathan Bravo
    suffering from  id10T errors all his life.. Ohhh MAMA!!
Logged

Mr Johnathan Bravo
spearhead
Administrator
*
Posts: 1038


View Profile WWW
« Reply #8 on: September 13, 2008, 16:35:00 »


Spearhead.
 using 0.5.5. Although if you want I can use the svn and make the changes in those files instead and then e-mail you either the full files or the diff files( now that I know that utility exists :0


there hasn't been many changes since 0.5.5 to the browse pages, so it won't be a big issue (0.5.4 or earlier would be a very different story though  Cool ) . Anyway if you use diff use the options -uN

And yes the code is rather complex, no wonder you make errors.... try having a go at the daemon; I'm trying to clean that up ;-)
Logged
mrjb

Posts: 18


View Profile
« Reply #9 on: September 13, 2008, 17:15:59 »

speahead
     ok... I will use diff  on the files i am working from now in the 0.5.5 . Sometime this wk when I have time I;ll update my installation to the svn and work against them from now on. Your right, the code is complex... but I gotta hand it to you guys ... you document well and once I got a handle on smarty, its pretty well straightforward AJAX.  Love the idea of Smarty tho... after I get this little enhancement going I am going to have a go at making a slightly different browse template. Since there won't be any functional difference I am thinking it should be "fairly" easy.

Mr Johnathan Bravo
Logged

Mr Johnathan Bravo
spearhead
Administrator
*
Posts: 1038


View Profile WWW
« Reply #10 on: September 13, 2008, 18:04:46 »

speahead
     ok... I will use diff  on the files i am working from now in the 0.5.5 . Sometime this wk when I have time I;ll update my installation to the svn and work against them from now on. Your right, the code is complex... but I gotta hand it to you guys ... you document well and once I got a handle on smarty, its pretty well straightforward AJAX.  Love the idea of Smarty tho... after I get this little enhancement going I am going to have a go at making a slightly different browse template. Since there won't be any functional difference I am thinking it should be "fairly" easy.


I keep an eye on my mailbox Wink

Updating to SVN should be pretty straightforward as there are no db updates (yet), so if you do a check out somewhere and then copy the config files (smarty_config.php, dbconfig.php and config.php) that should be it basically. And set the path to urdd.sh to the correct one in admin/config.

Smarty is neat indeed. Some of the syntax stuff is a bit cranky, but I got used to it.

If you're finished we can always add the template to our repository if it is maintained. Basically you can copy the default template to a new dir and then you can select the new template in the interface ... that should be it, really. Then you can change the new template all you want.
Logged
Styck
Administrator
*
Posts: 125


View Profile
« Reply #11 on: September 13, 2008, 18:58:55 »

Ehm hang on, there are DB changes Tongue
(news server priority stuff)
So upgrading needs manual db updating.

Also, don't use the function .scrollTo but the variable .scrollTop, no typo there Smiley The variable can be read out (currentscroll = thediv.scrollTop) and set (thediv.scrollTop = 100).
Logged
spearhead
Administrator
*
Posts: 1038


View Profile WWW
« Reply #12 on: September 13, 2008, 19:26:48 »

Ehm hang on, there are DB changes Tongue
(news server priority stuff)
So upgrading needs manual db updating.


The priority field was in the db already in 0.5.5. Until now there is one change and that is the removal of the active field. I also added an update.sql file now with all the changes to the db.
Logged
mrjb

Posts: 18


View Profile
« Reply #13 on: September 13, 2008, 20:13:30 »

styck
        Ok.. i'll use scrollTop.  So I should be able to update a session var with the current value of kinda like
$curScrollVal= document.getElementById('contentout').scrollTop
_Post('curScrollVal')

and then set it in DisplaySetInfo() in js.js

like

document.getElementById('contentout').scrollTop=document.getElementById('curScrollVal');


btw I will write in the if cases and tests against null.

just out of curiosity... I thought element.scrollTo(x,y) was on the DOM in js by default. Is this not the case or is there another reason not to use it as opposed to scrollTop? again .. this is just simple curiosity.

Mr Johnathan Bravo
Logged

Mr Johnathan Bravo
Styck
Administrator
*
Posts: 125


View Profile
« Reply #14 on: September 13, 2008, 23:16:29 »

AFAIK (I googled it a bit Tongue), window.scrollTo(x,y) is valid only for the complete window.
For scrollable div's, you need to use .scrollTop(y) and scrollLeft(x). Different objects, different methods Smiley
Logged
mrjb

Posts: 18


View Profile
« Reply #15 on: September 14, 2008, 01:46:19 »

ok... sorry I just realized my mistake. I had been assuming, incorrectly, that Element.scrollTo(x,y) was a function defined in javascript by default on the DOM. As i have read further it seems that some js api's define something of the sort but that its not anywhere in the standard. Thanks for clearing it up.


Mr Johnathan Bravo

Logged

Mr Johnathan Bravo
mrjb

Posts: 18


View Profile
« Reply #16 on: September 15, 2008, 23:59:28 »

Ok ...
       I think I got it working the way I want it to. Check it out and let me know if I need to make any changes.

Mr Johnathan Bravo

Logged

Mr Johnathan Bravo
spearhead
Administrator
*
Posts: 1038


View Profile WWW
« Reply #17 on: September 19, 2008, 14:34:57 »

Ok ...
       I think I got it working the way I want it to. Check it out and let me know if I need to make any changes.

Mr Johnathan Bravo


I added the patch to svn. Made a few small changes here and there but it seems to be working. Thanx...
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
Amigri by Fakdordes
spacer.png, 0 kB
spacer.png, 0 kB
spacer.png, 0 kB