This topic was marked solved by its starter, on March 16th, 2013, 01:40 AM
sb refresh does not update scrollbar

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: sb refresh does not update scrollbar
« Reply #15, on November 15th, 2012, 05:03 AM »
I have another example of this. I'm rewriting the calendar stuff (not ready to comment yet)

The existing code in SVN is broken in various ways, but in template_edit_holiday() (in ManageCalendar.template.php), you'll see some inline JS.

Replace it with:

Code: [Select]
add_js('
var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function generateDays()
{
var days = 0, selected = 0, dayElement = $("#day"), year = $("#year").val(), monthElement = $("#month")[0];

monthLength[1] = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 29 : 28;

selected = dayElement.val();
dayElement.empty();

days = monthLength[monthElement.value - 1];

for (i = 1; i <= days; i++)
dayElement.append(\'<option value="\' + i + \'">\' + i + \'</option>\');

if (selected < days)
dayElement.val(selected);

$("#day").sb();
}');

Switch months, to something like February. Boom, no scrollbar. Sorry about the code, but it's late, and I'm very fed up this evening, since every little thing seems to take 4 times longer to follow it all down the respective rabbit holes. (Oh, and the old code doesn't work because the old method of pushing new Options doesn't work for some reason.)
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: sb refresh does not update scrollbar
« Reply #16, on November 17th, 2012, 12:37 AM »
Oh, crap... Been so long since I've worked on generateDays() AND on sbox.js... I'm afraid I don't remember the specifics... :-/

(Total burnout these days. I was thrilled that I actually managed to commit a few lines today...)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: sb refresh does not update scrollbar
« Reply #17, on November 17th, 2012, 12:43 AM »
I understand about the total burnout and was actually quite pleased to see you taking a break :)

Ignore the specifics of generateDays, it doesn't really matter. What does matter is that if you update the values in a select through whatever means, and then call .sb(), it won't work properly.

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: sb refresh does not update scrollbar
« Reply #19, on February 1st, 2013, 01:07 PM »
Is there a way to reproduce this without installing the calendar...?

The scrollbar system is far from perfect. Just yesterday I had to play with < br> tags to prevent a reflow in the JS packer select box.

:edit: Hmm, I thought HTML tags were only taken 'as such' in quick reply, but even quick edit seems to do it on the br tag...?!

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: sb refresh does not update scrollbar
« Reply #20, on February 1st, 2013, 03:08 PM »
It's nothing to do with where it comes from, it's a bonus feature of the parser. If you don't want that, don't enable it ;)

Easy enough to reproduce, have a <select> with at least 15 items, call .sb() on it the first time and it sets it up. Then call .sb() again.

The calendar is the easiest way to see it but it's not the only way. It's normally not an issue because most of the selectboxes aren't that long, or where they are, they're not re-initialised.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: sb refresh does not update scrollbar
« Reply #21, on February 1st, 2013, 03:52 PM »
Quote from Arantor on February 1st, 2013, 03:08 PM
It's nothing to do with where it comes from, it's a bonus feature of the parser. If you don't want that, don't enable it ;)
Ah, yes... Forgot about that one :)
Should be disabled.
<br>
Yay.

Is it enabled by default? I don't remember... It's neither something for a 'forum for dummies' ("HTMwhat?"), neither for techies ("why can't I post my HTML code to the forum?")...
Quote from Arantor on February 1st, 2013, 03:08 PM
Easy enough to reproduce, have a <select> with at least 15 items, call .sb() on it the first time and it sets it up. Then call .sb() again.
So... Doing it on the timezone one, for instance..?
Quote from Arantor on February 1st, 2013, 03:08 PM
The calendar is the easiest way to see it but it's not the only way. It's normally not an issue because most of the selectboxes aren't that long, or where they are, they're not re-initialised.
I'm starting to be ashamed of my select box code... (Apart from the fact that it holds the dubious world record for shortest select box with scrollbar and all :P)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: sb refresh does not update scrollbar
« Reply #22, on February 1st, 2013, 04:09 PM »
Quote
Is it enabled by default? I don't remember... It's neither something for a 'forum for dummies' ("HTMwhat?"), neither for techies ("why can't I post my HTML code to the forum?")...
It's not enabled by default but it was enabled on Noisen and that was carried through here.
Quote
So... Doing it on the timezone one, for instance..?
It would - *if* the timezone selector were reinitialised for any reason after creation.

The calendar for example had[1] dropdowns for the day, month and year. The problem is that the day selector would need to be changed based on the month, e.g. selecting Feb would give you 1-28 (or 1-29), selecting January would give you 1-31 and so on. So it would adjust the select, then re-call .sb() on it to refresh it, but then it broke the selection as per the bug.
Quote
I'm starting to be ashamed of my select box code... (Apart from the fact that it holds the dubious world record for shortest select box with scrollbar and all :P)
Don't be. This scrollbar issue is a relatively minor bug. I really like it other than that one thing.
 1. It doesn't now, it has a proper date input selector.

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: sb refresh does not update scrollbar
« Reply #23, on February 2nd, 2013, 02:06 AM »
Quote
I'm starting to be ashamed of my select box code... (Apart from the fact that it holds the dubious world record for shortest select box with scrollbar and all :P)
But why? It's a nice work, something to be proud of. :)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: sb refresh does not update scrollbar
« Reply #25, on February 11th, 2013, 02:32 PM »
Oh, bugger, you're right...
I'll work on this one straight away.
Posted: February 11th, 2013, 01:30 PM

Fixed locally... I hate bugs that take an hour to 'understand'.

This is due to jQuery no longer (in v1.9+) copying originalEvent properties to the passed event object.
So I had to specifically name them. It added 3 bytes to the final code, but I guess that's still all right...
Posted: February 11th, 2013, 02:30 PM

This was actually removed in v1.7.x, not 1.9, and isn't related to the stuff I read about originalEvent... It's just that they stopped supporting it, and said to go use a plugin.
Nice... They could have said it in their blog, for instance... Hmm? ::)
http://bugs.jquery.com/ticket/10676

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: sb refresh does not update scrollbar
« Reply #27, on February 11th, 2013, 11:08 PM »
Ah yes, sorry, always forget about that one...

I thought it was a problem with the way the scrollbar thumb size was calculated... But I must have misread it... It's simply a case of "oh, these are two separate objects, if you remove one you have to remove the other..." -- heck, it took me about 20 minutes of work to generate a dummy situation where the SB would be modified in real time and then refreshed, and about 10 seconds of extra time to find out I just needed to add a 'delete scrollbar' call in reloadSB(). Bit of a shame, writing that code for nothing... :lol:
I changed it to scrollbar = '' because it saves two bytes (that's just me...), seems to work the same.

The only remaining issue is that, ahum, if the SB is open while I'm regenerating it, I can no longer click outside the SB to close it, I have to click the SB itself. And that, hmm... I spent another 10 minutes on that one, and couldn't figure it out. It just evades me for now. I guess I'll work on that one tomorrow.
Heck, it may not even be important... I'm guessing that in 99% of cases, the SB will be closed at the time you're regenerating it, anyway...?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,082