The Gamer Corner
Stop slacking off by working, and get to work slacking off
Lost your password?

HTML Rules: To Cheat or Not To Cheat?

HTML Rules: To Cheat or Not To Cheat? – February 2, 2011 2:44 PM (edited 2/2/11 9:47 AM)
Talraen (2373 posts) Doesn't Play with Others
Rating: Not Rated
So my AJAX-powered table coolness for the guides site is coming along nicely. However, I am about to run into an interesting hitch. Right now, I can convert any basic list page table into a dynamic table. The HTML to do this is very simple:
<div class="dataTable" id="monsters">Loading data...</div>
Basically what's going on here is this: jQuery looks for any objects with a class of "dataTable" then loads that table based on their id. For a simple case like this, it works without a hitch and is pretty sweet. However, the main advantage of my site is all the cross-referencing, and this method introduces two distinct issues with that. To understand them, you need to know the rules behind ID's in HTML:

• ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
• ID tokens must be unique to a particular page.
• It is recommended that colons (":") and periods (".") not be used due to specialized meaning in CSS and jQuery.

The lesser problem is that, because I'm using ID, I can only have one of a particular table on a given page. This could be addressed by using NAME instead, or adding some kind of trailing code (like hyphen-number) that jQuery knows to ignore, so it's not a big deal.

The real issue is that, on specific view pages, I want to show filtered versions of these lists. For instance, on a "view map" page I might want the same monsters table I mentioned above. To create that filter, I need to specify that I want to use a map as a filter, and which one. In URL parameter terms, I want something like "&map_id=5". However, neither & nor = are valid characters in ID or NAME tokens.

Now, there are a few easy solutions to this. For one, I could create a custom token, like "loadUrl", and just put whatever I want in it. However, XHTML doesn't technically allow custom tokens, and I don't want to break my OCD validation streak if I don't have to. Alternately, I could pass the relevant filter info to each page as javascript variables, then check those when loading the tables. I don't like this idea because having the tables be completely self-contained would be really sweet.

So what I'm looking for is a parseable but valid system to use for ID (or NAME) to generate any table with any number and combination of filters. I would very much like to avoid using colons and periods if I can, since it's generally a bad idea to do so, but that leaves me with exactly one delimiter, the hyphen. However, the reason you want to avoid colons and periods is because you need to escape them to use CSS or jQuery selectors, neither of which I would actually do with these anyway. So they could be in play if it makes things much easier.

So far the best I can come up with is "tabletype--param-value--param-value" (that's two hyphens between name-value pairs). However, I know there are tabletypes with a hyphen in them, and there very well might be parameter names with a hyphen, so I might need to go triple and double hyphen for delimiters instead. Or I could go "tabletype:param.value:param.value". It works, but I'd like to avoid it. So does anyone out there have any interesting ideas for how to deal with this elegantly?

EDIT: Oh I forgot to mention that underscores are also available, because I forgot. They're fine, so I could use double and single underscores instead of hyphens, or some combination (probably still using double hyphens to allow for hyphenated parameters). So that's also doable, just ugly and still not very elegant.

--
There is no Mythril Sword in Elfheim
Re: HTML Rules: To Cheat or Not To Cheat? – February 3, 2011 1:27 PM (edited 2/3/11 8:27 AM)
Cuzzdog (1522 posts) Head of Gamer Corner R&D
Rating: Not Rated
Can you use ~? ~ is a popular delimiter. Also |, but that might have to be escaped.

Re: HTML Rules: To Cheat or Not To Cheat? – February 3, 2011 1:38 PM (edited 2/3/11 8:38 AM)
Talraen (2373 posts) Doesn't Play with Others
Rating: Not Rated
No, those are literally the only characters that are legal. You can't escape characters because the escape character wouldn't be legal either. Wink

In the end I went with the colon-period method, because it's the most human-readable. And the whole thing I was working on is pretty sweet, it should be up in a few days.

--
There is no Mythril Sword in Elfheim
Active Users: (guests only)
1 user viewing | Refresh