Wedge

Public area => Bug reports => The Pub => Archived fixes => Topic started by: live627 on April 30th, 2012, 07:22 AM

Title: sb refresh does not update scrollbar
Post by: live627 on April 30th, 2012, 07:22 AM
The scrollbar is not updated when refreshing the select box object when it contains a dozen items. Since the scrollbar variable is set on the open event, it just needs cleared when refreshing.
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on April 30th, 2012, 02:40 PM
Shouldn't it do that on re-calling .sb() anyway? I've never seen a problem with it misbehaving when calling .sb()...
Title: Re: sb refresh does not update scrollbar
Post by: live627 on May 1st, 2012, 12:03 AM
How many options do you have in your test case?
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on May 1st, 2012, 12:13 AM
I can't remember to be honest :/ Probably no more than 10 though.
Title: Re: sb refresh does not update scrollbar
Post by: live627 on May 1st, 2012, 12:58 AM
You won''t notice, then. Try it with 12 - 15 options.
Title: Re: sb refresh does not update scrollbar
Post by: Nao on May 1st, 2012, 03:11 PM
The scrollbar was a last minute addition o I wouldn't be surprised that it doesn't work as expected here. I'll have to check once I'm done with the mega commit and my rest time in the sunshine. I don't know which I'm more eager to do... Hmm.
Title: Re: sb refresh does not update scrollbar
Post by: live627 on May 31st, 2012, 09:02 PM
Has this been fixed?
Title: Re: sb refresh does not update scrollbar
Post by: Nao on May 31st, 2012, 11:53 PM
Nope... Not that I found any issues myself, though. (Known song.)
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on July 23rd, 2012, 02:57 AM
Does this still occur?
Title: Re: sb refresh does not update scrollbar
Post by: live627 on July 23rd, 2012, 04:22 AM
I'd assume so since I didn't see the fix in the changelog.
Title: Re: sb refresh does not update scrollbar
Post by: Nao on July 26th, 2012, 04:21 PM
I'd really appreciate being given a clear test case for this... ;)
Title: Re: sb refresh does not update scrollbar
Post by: live627 on July 26th, 2012, 11:08 PM
You need some code posted.....?
Title: Re: sb refresh does not update scrollbar
Post by: Nao on July 27th, 2012, 09:10 AM
Err... Yes?
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on July 27th, 2012, 05:59 PM
Either an example of where it occurs in base Wedge, or example code to reproduce it ;)
Title: Re: sb refresh does not update scrollbar
Post by: live627 on July 28th, 2012, 10:10 AM
https://github.com/live627/jAhsum/tree/master/dateinput (I forgot I open sourced it)

It just attaches to a regular text input element.
Title: Re: sb refresh does not update scrollbar
Post by: Arantor 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.)
Title: Re: sb refresh does not update scrollbar
Post by: Nao 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...)
Title: Re: sb refresh does not update scrollbar
Post by: Arantor 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.
Title: Re: sb refresh does not update scrollbar
Post by: live627 on February 1st, 2013, 12:00 PM
Can someone fix this?
Title: Re: sb refresh does not update scrollbar
Post by: Nao 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...?!
Title: Re: sb refresh does not update scrollbar
Post by: 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 ;)

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.
Title: Re: sb refresh does not update scrollbar
Post by: Nao 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)
Title: Re: sb refresh does not update scrollbar
Post by: Arantor 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.
Title: Re: sb refresh does not update scrollbar
Post by: live627 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. :)
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on February 10th, 2013, 07:11 PM
Also is it my imagination or does the scrollwheel no longer work with scrolling through the selectbox?
Title: Re: sb refresh does not update scrollbar
Post by: Nao 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
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on February 11th, 2013, 05:01 PM
Now, what about selectboxes whose content changes and .sb() is recalled? :angel: :P
Title: Re: sb refresh does not update scrollbar
Post by: Nao 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...?
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on February 11th, 2013, 11:19 PM
Pretty much. You could even have .sb() forcibly close it first if it is open?
Title: Re: sb refresh does not update scrollbar
Post by: Nao on February 11th, 2013, 11:25 PM
Hmm... That would be the cop out solution... :P
Title: Re: sb refresh does not update scrollbar
Post by: Arantor on February 11th, 2013, 11:30 PM
It would be the logical solution ;)
Title: Re: sb refresh does not update scrollbar
Post by: Nao on February 12th, 2013, 11:52 AM
There is definitely a problem with the reloadSB function.
What it does is: delete the current SB, remove its DOM elements, then repopulate it from the original, then re-create it, then open it if it was opened before, or focus if it was focused before.
It executes so fast that you never get to see the DOM be modified, and open/focus states are correctly restored. It's just the closeAndUnbind function that never properly sets the event (even though it DOES get executed at this point...)

I'm currently reviewing all .sb calls, and it seems that it's never called when in the middle of an opened SB, which totally makes sense, so indeed it might be best not to reopen the SB after re-creating it.

While doing this review, I also discovered a horrible bug in Wedge... I did, in a few occasions, launch a !ask() request in DOM events. Which is TOTALLY what should be done. Unfortunately, the nature of alert/confirm events is that they stall the execution process until we return, then we get a boolean parameter we can give back to the event. Okay. But say/ask are functions that don't stop any execution, and for that reason I had to had a callback system to allow for use in DOM events. It works very well, but it seems like I forgot to convert a few calls... And because ask() will immediately return false in a DOM event, if you take action after an !ask (rather than an ask), it will be executed.

To make it short (my explanation really sucks): Wedge could no longer un-admin anyone, or make a membergroup invisible, because it would always request confirmation and immediately return to cancelling the action, whatever your decision. Eh.
Of course, I'm fixing that right now...

But it just goes to show how fixing one bug can lead to fixing another... :^^;:
Posted: February 12th, 2013, 11:22 AM

Crap!
My 'bug' wasn't due to sbox.js itself... It was due to the fact that I was refreshing multiple select boxes at the same time. (i.e. $('select').sb()).
There's just a little bit of logic involved... Each select box, when it's opened, attaches a window event to react to a click outside of it. However, the next sbox being re-created will delete said window event... That's why I couldn't click the window to close the current box. Bugger.

I'm not sure what are the odds of this not working...

I did a version of sbox where the dropdown isn't re-created (it just stays closed). It saves 20 gzipped bytes. I don't know what is best right now...

PS: also, for similar reasons, and in ALL cases here, the scrollbar is no longer selectable after a .sb() refresh. This is due, once again, to a document-wide event not being re-created.