Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Selectbox
« Reply #60, on December 31st, 2011, 12:31 AM »
Worst nightmare in months... Every time I fix a bug in this, it creates a new one. Frankly, if I didn't know better, I'd just come to the conclusion that I suck at JavaScript!
It isn't the case -- it's just that it's a fucked up concept. The main issue is with event transmission. I've looked into other plugins and they all have strange ways to deal with these -- and they're not very good at dealing with internal modifications like adding an option dynamically, etc.

Anyway, I just wanted to post that, next time I want to implement a library that "seems easy enough to do", someone should tell me to give up immediately because it's gonna bite my in the ass... :lol:
Re: Selectbox
« Reply #61, on December 31st, 2011, 05:41 PM »
Just for 'fun'... Here's what I'm having trouble with.

User clicks select box "Label selected" in PM area. This triggers a "focus" event, loadLabelChoices(). Which fills in the select box with the proper values.

That's the theory... Now, in practice:

- if I fill the select box again, then I need to refresh the Wedge version of it... So at the end of the function, I'll call the refresh function.
- said refresh function will call .focus() on the original.
- which triggers loadLabelChoices, which triggers the refresh, etc...
It's not exactly an infinite loop because I've added protections, but this is enough to screw up the process.

I've been on this for two days... Trying to find a 'proper' way to launch a refresh without having to say, "okay guys, we don't want you to focus the original... Okay?". Found many techniques, each time it fails somewhere.

Now, the funny thing is that Wedge only has TWO FREAKING select boxes in the entire codebase that bother with the focus event... (This one, and the JumpTo.) And both of these will actually never make use of the focus accessibility feature, because as soon as you click an option, it goes to another page...

I'm just posting to... well, make sure that it's on a record. Select boxes suck!!

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Selectbox
« Reply #62, on December 31st, 2011, 05:49 PM »
What about the one on the who's online page?
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: Selectbox
« Reply #63, on December 31st, 2011, 07:50 PM »
I don't think it's generated on focus. Can't check though. Not on my pc.

Btw some bugs I had in Firefox 3 don't show up in later versions. Ahah. Good fun. I'll use v8 for the rest then.
Re: Selectbox
« Reply #64, on January 1st, 2012, 08:15 PM »
Okay, to answer the post above -- the Who's online page reacts on change(), not focus(), so it's definitely not an issue.

BTW... It's been over 24 hours since the last post was sent here. I think we broke a record or something... :P
Re: Selectbox
« Reply #65, on January 2nd, 2012, 10:37 AM »
Okay, an alternative to the odd code seen in rev 1233 would be to simply not care about onfocus, and ask modders to use onclick instead...

The difference is simple. onfocus triggers when you activate a select box (in 99% of cases, that means when you click it.) onclick triggers when you click the select box (as it opens the dropdown.)
So, basically, the ONLY difference is that onclick is never run when you use the keyboard to navigate.
I figured, I *could* possibly fire a click event when opening the select box via the keyboard... What do you think?
That way, the infinite loop thingy is no longer possible. (As long as no one uses onfocus, of course!)

I wrote a small piece of code that would watch for DOM changes to any select box and call reloadSB as needed, but (1) it adds about 200 bytes of code to the whole thing, (2) it's a hack, (3) it adds more issues that I can't bother to fix right now. So I'm adding it to our wip folder instead... (Because it's still quite cool.)
Re: Selectbox
« Reply #66, on January 2nd, 2012, 05:26 PM »
Any reasons I'm the only one who posted in the last 48 hours...?
Am I that boring?
Technical issues?

Aaron

  • Posts: 356
Re: Selectbox
« Reply #67, on January 2nd, 2012, 06:51 PM »
Well, yesterday was New Year's Day ...

Speaking for myself, January is a crazy month in terms of deadlines and exams. Priorities, heh ...
"The entire British Empire was built on cups of tea … and if you think I'm going to war without one, mate, you're mistaken."

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Selectbox
« Reply #68, on January 2nd, 2012, 07:06 PM »
Quote from Aaron on January 2nd, 2012, 06:51 PM
Well, yesterday was New Year's Day ...
I heard about that one... :P
It's just that I kept seeing people in the Who's Online list, but no one would post... Even those who made it a habit to post their opinions on many different subjects. :-/
Re: Selectbox
« Reply #69, on January 2nd, 2012, 08:02 PM »
So... It's 8PM, I've been on this since 8AM...
Trying to fix onclick events. Breaks onfocus events. Then the other way around. Then all works... But not when using keyboard. Fixing this. Breaks onclick. Fixing. Breaks onfocus. Fixing... Breaks mouse events.

OH MY...

Select boxes are developer hell. I just checked out Kyodai Mahjongg and since I'd rewritten the entire UI to use textures, obviously I'd made my own select box for it... (Used in the high scores window.) Well, it works. Only it doesn't have all of these silly events to deal with... :^^;:

I don't know where to start (or finish)... And again, I'm tempted to call it quits.
Re: Selectbox
« Reply #70, on January 3rd, 2012, 04:26 PM »
So... It turned out that many of my issues with events here (namely, them not triggering when expected), was due not to the order in which events are executed -- but simply, to the fact that the original events were only copied on the first call (with a pretty smart single-line statement). Fact is, that single line only works *before* the page has finished loading. After that, it's useless. So I wrote a longer version, and also used the opportunity to retrieve all non-jQuery events, making it possible to add events to select boxes through .html("<select onclick...>") rather than assigning them any .bind() events after creation.

Meh... It's messy.
And of course it didn't work in IE8. (At first.)

I think I've had my share of SHITTY code that keeps sending me bugs whatever I do. I always beat them in the end. This one is no different, I'll beat it just the same. Problem is just that -- WHEN the hell does this happen?!
I've been on this for THREE WEEKS. Fantastic. And it's far from being finished! I still need to write that scrollbar code. And check every single <select> in Wedge. (All direct <select> manipulations are done, but I have no idea where it has some silly hidden code like $('<select id=something>') then $('#something').append()... (This is why I'd rather always use clearer code.)
Re: Selectbox
« Reply #71, on January 3rd, 2012, 07:21 PM »
Aaaand I think I'm going to give up on these event imports as well...
Probably just going to import .click events, I guess. Because let's be honest, it's the only kind of event we have in Wedge, AND it's not like I'm trying to make a universal select box. Modders can adapt. If I want to go universal, I'll rewrite it again anyway...
Re: Selectbox
« Reply #72, on January 5th, 2012, 03:45 PM »
Well... Good news: it only took me a day to implement the custom scrollbar... :eheh:
It has its limitations, of course. But not that many, compared to the small size (~700 bytes of minified/gzipped JS + about 90 bytes of minified/gzipped CSS for now.)
And it has a few bugs left... But the main code is done, phew.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Selectbox
« Reply #73, on January 6th, 2012, 07:25 PM »
You have done very, very well with this :)

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Selectbox
« Reply #74, on January 6th, 2012, 09:20 PM »
Thanks :)

And good to have you back!

I'm still not sure about the scrollbar thing... I actually made the script.js optimizations (rev 1237) in order to compensate for the extra bytes added by it. But it's still not enough IMHO. Also -- script remains quite buggy... I'll have to delve deeper into it. It's spectacularly broken right now, I don't know when/where I screwed it up.