Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Benjamin Black posted:

Uh, but the class is only ever used once on the page.


gently caress. It's not actually the first (or last) child of an id I'm trying to modify. I didn't think that was even an option when I presented the example.


Wow, you sure are a nice person. Glad you got it all figured out, and good luck in all future endeavors.

Adbot
ADBOT LOVES YOU

The Man From Melmac
Sep 8, 2008

Lumpy posted:

Wow, you sure are a nice person. Glad you got it all figured out, and good luck in all future endeavors.

:confused: Did I come off that dickish? If I did I'm sorry. Thank you for helping me.

The Man From Melmac fucked around with this message at 05:16 on Feb 1, 2012

subx
Jan 12, 2003

If we hit that bullseye, the rest of the dominoes should fall like a house of cards. Checkmate.

Benjamin Black posted:

Uh, but the class is only ever used once on the page.

Just pointing out that this doesn't matter. If you build an array with a single value it is still an array, it doesn't care that it doesn't "need" to be an array. This is pretty essential to understand for all programming, not just Javascript.

Any time you run a "elementsBySomething" (other than Id) it's going to return a collection, even if it's just a single item.

The Man From Melmac
Sep 8, 2008

subx posted:

Just pointing out that this doesn't matter. If you build an array with a single value it is still an array, it doesn't care that it doesn't "need" to be an array. This is pretty essential to understand for all programming, not just Javascript.

Any time you run a "elementsBySomething" (other than Id) it's going to return a collection, even if it's just a single item.

I was referring more to the comment that mentioned 'ALL h1 tags within the banana class will have their text replaced' (or something to that effect), which isn't really a problem for the site I'm working on.

Funking Giblet
Jun 28, 2004

Jiglightful!

peepsalot posted:

Or don't because IE up to and including IE 8 do not support it.

http://www.quirksmode.org/dom/w3c_core.html



Try document.querySelector or document.querySelectorAll for IE8 and above, allows some CSS type selectors as well.

Ixian
Oct 9, 2001

Many machines on Ix....new machines
Pillbug
I have an issue I've been trying to wrap my head around all day and am hoping someone can point out where I've been dumb.

I wrote a custom script to listen to events from a media player (JW Player). I set up an event listener like this
code:
document.addEventListener(PLAYER_EVENT_PLAY, onPlayerPlay, false);
Then I create custom events for that like this:
code:
this.playEvent = document.createEvent("CustomEvent");
                this.playEvent.initEvent(PLAYER_EVENT_PLAY, true, true);
Then I send off states like this:
code:
if (isPlaying.call(this) && this.playEvent != undefined) document.dispatchEvent(this.playEvent);
So that the player can interact with my app. I do stuff like track time and whatnot with it so I can fire that back to my actual app in case you care.

Now, all of the above works just dandy with IE9 and every other regular browser. Of course, IE8 and lower don't (shocking!) because those browsers don't know what the gently caress addEventListener, etc are.

So I re-wrote some IE8/lower specific code like this:
code:
window.attachEvent(PLAYER_EVENT_PLAY, onPlayerPlay);

this.playEvent = document.createEventObject(PLAYER_EVENT_PLAY, true, true);

if (isPlaying.call(this) && this.playEvent != undefined) return document.fireEvent('onchange' +this.playEvent);
Thinking those were the IE8 equivalents, so to speak. And it sort of works, but one part is missing, and it looks like the fireEvent piece.

I don't know nearly enough about it - can anyone tell me how the document.dispatchEvent routine, etc I've got can be translated into something that works with IE8/lower?

I know at some point I am just going to attack this with a hammer and redo the whole thing in JQuery-land, but that's a bigger project than I have time for at the moment.

Thanks for any advice!

Edit: I did end up re-doing it in JQuery, that turned out to be the right solution.

Ixian fucked around with this message at 15:47 on Feb 8, 2012

SpaceAceJase
Nov 8, 2008

and you
have proved
to be...

a real shitty poster,
and a real james
I'd like to create two fields: an input box and a multi-line select box.
I'm using jquery, and I'd like to search the selectbox based on input in the text field. How would I go about this?

I've seen it done before, http://www.realestate.com.au/buy (Click a state first and type any suburb into the box).

Any suggestions or help would be much appreciated. I don't want to filter the contents of the selectbox, but rather have it automatically scroll down to the closest match to the input field value.

fizzbin
Dec 13, 2006

gooo

SpaceAceJase posted:

I'd like to create two fields: an input box and a multi-line select box.
I'm using jquery, and I'd like to search the selectbox based on input in the text field. How would I go about this?

I've seen it done before, http://www.realestate.com.au/buy (Click a state first and type any suburb into the box).

Any suggestions or help would be much appreciated. I don't want to filter the contents of the selectbox, but rather have it automatically scroll down to the closest match to the input field value.

I didn't see what you were asking for on that link.

But I did some investigation because this is an interesting question:

You can set where the listbox is scrolled to: $("select")[0].scrollTop = 100
That'll make it scroll 100px down.

The issue I ran into is that there seems to be no way to determine the position accurately of each list element.
$("option")[0].clientHeight
$("option").eq(0).outerHeight(true)

Both of these return 0. I can only assume the height is 100% browser/platform dependent and every static number would be incorrect.

Apparently you can scroll to an element by selecting it but that did not work in my tests, at least with a multi-select.

So apart from rolling your own control so you know the heights of the list elements, this does not seem possible.

ComptimusPrime
Jan 23, 2006
Computer Transformer
jQuery provides some nice functions like offset and position. offset() will give you an elements position in the document, while position() will give you the elements location within its parent. You can also retrieve the calculated height of each element through calls to height.

Also, there is a jQuery function scrollTop.

Essentially you would find the first matching element, and then call

$('#myselectbox').scrollTop($(selector).position().top);

Though I'm guessing you want to animate this, so it is just a matter of animating the scroll top to the appropriate position.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA
Any of you ever look in-depth into browser form-caching? I have an unanswered stackoverflow question that's left me kinda stumped. Can't really find any useful specs or documentation on it - the terms just mean too many other things.

ComptimusPrime
Jan 23, 2006
Computer Transformer
I have never looked in to form caching, but what do you mean in the Stack Overflow question when you say:

quote:

I was hoping I could save the "new" widget count in a hidden field and then on domReady simply generate the missing input fields and assign them their original names and IDs but this doesn't seem to work, browsers don't seem to want to do anything with generated content.

Dynamically generated HTML is definitely used all the time. Could you clarify what the problem you are running in to at this point is exactly?

Orbis Tertius
Feb 13, 2007

Mr. Wynand posted:

Any of you ever look in-depth into browser form-caching? I have an unanswered stackoverflow question that's left me kinda stumped. Can't really find any useful specs or documentation on it - the terms just mean too many other things.

In terms of the familiar browser behavior, the term I think you're looking for is 'autocompletion', specifically 'session history caching' (using mozilla's terminology). Googling turned up this mozilla doc page (the introduction talks about the browser behavior in general, though the subject of the page is about how to turn it off by using the form attribute).

From your stack overflow question:

quote:

Overall this is probably sensible enough, but is there maybe a way to interact with this form cache mechanism directly?

I don't think so. However, even if there was a way to control it, you'd still have to deal with the fact that user's can turn off that behavior in their browser settings. That is, if the caching behavior you're looking to implement is central to your widget's functionality, you probably don't want to rely upon (or modify, somehow) that built-in browser behavior.

quote:

One possible work-around would be to store not only the new item count in a hidden field but some sort of serialization of the full content of the new widgets. Should work but it's a fair bit of additional effort :/

Yeah, something along those lines. If you're working with a popular framework (jquery/mootools/etc), there's probably a plugin out there that does something very close to what you want - Sisyphus, for example.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
This feature has been requested:
* They want a county map of Wisconsin.
* They want to be able to click a county and highlight it.
* They want to be able to highlight multiple counties.

Now, I have a couple of options.

One:
* Find a map of the counties of Wisconsin (done)
* Make an image map of it (not done)
* Create or find a Javascript to color in the image mapped portions. This would not be precise, as I'd either have to dumb down some of the county borders, or accept that the coloring would not fill in the counties fully.

Two:
* Find an SVG of the counties if Wisconsin (done)
* Find a script that allows on-the-fly changing of a county's color. This would be precise, due to the fact that it's an SVG.

Which sounds more sane, and does Javascript or jQuery exist for either one?

baquerd
Jul 2, 2007

by FactsAreUseless

Golbez posted:

* Create or find a Javascript to color in the image mapped portions. This would not be precise, as I'd either have to dumb down some of the county borders, or accept that the coloring would not fill in the counties fully.

You don't need to go this far, you can just put a colored dot on the image to indicate highlighted sections.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

baquerd posted:

You don't need to go this far, you can just put a colored dot on the image to indicate highlighted sections.

They want the whole county filled in, though. This is to create a printable pretty map.

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
Another option would be to stack a transparent GIFs/PNGs for each county atop each other, dynamically adding or toggling each's visibility according what's been selected.

Or just indicate selection through changing the styling of their textual labels.

486
Jun 15, 2003

Delicious soda
I've never used this, but it seems pretty neat from the demo

http://davidlynch.org/blog/2008/03/maphilight-image-map-mouseover-highlighting/

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
You could try something with overlays in Google Maps

Just from a quick Googling, this might help: http://elliottmediagroup.com/2011/01/24/maps-api/

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Blinkz0rz posted:

You could try something with overlays in Google Maps

Just from a quick Googling, this might help: http://elliottmediagroup.com/2011/01/24/maps-api/

I thought about that, but since this is going out in commercial literature there's probably license issues with that. And I think they want the map with all the county borders.

And now that I think of it, the final step of this - getting a PDF printout of it. Like, within other PDF sheets. In other words, having to pass all this data back to the server. Hrmmm.

Edit: I'm a little surprised at saying this but the idea of using a transparent image for each county seems to make the most sense, and it's the easiest to handle server-side as well. Thankfully this is Wisconsin and not Texas so I don't have to manage 250 pictures.

Golbez fucked around with this message at 18:37 on Feb 15, 2012

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Even if you already decided to do this with transparent pictures...

From Javascript perspective, svg is pretty close to html.

Just add a stylesheet to the the svg-file:
code:
<?xml-stylesheet type="text/css" href="my_style.css" ?>
Then add some styles to the css file:
code:
.selected
{
	stroke:rgb(255,255,0);
	stroke-width:1px;
	opacity:1;
}
Then add the above style to your selected regions:
code:
region.setAttributeNS(null, "class", "selected");

Deus Rex
Mar 5, 2005

Golbez posted:

This feature has been requested:
* They want a county map of Wisconsin.
* They want to be able to click a county and highlight it.
* They want to be able to highlight multiple counties.

Now, I have a couple of options.

One:
* Find a map of the counties of Wisconsin (done)
* Make an image map of it (not done)
* Create or find a Javascript to color in the image mapped portions. This would not be precise, as I'd either have to dumb down some of the county borders, or accept that the coloring would not fill in the counties fully.

Two:
* Find an SVG of the counties if Wisconsin (done)
* Find a script that allows on-the-fly changing of a county's color. This would be precise, due to the fact that it's an SVG.

Which sounds more sane, and does Javascript or jQuery exist for either one?

use raphael.js with option #2

http://raphaeljs.com/australia.html

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Deus Rex posted:

use raphael.js with option #2

http://raphaeljs.com/australia.html

Thanks for the response, though I ended up getting mapper.js and heavily modifying it for what I needed.

darthbob88
Oct 13, 2011

YOSPOS
I need to scrape the page type, product ID, and similar info from pages like this, this, this and others from the same platform. The most nearly obvious way to do it, since the page structure is less than consistent, is to check the URL using window.location.search and parse it from there. I have two one question, aside from the obvious "Is this the right way?"; can I test this safely someplace aside from in production, will
code:
var string = window.location.search;
//work on it from there
and
code:
var string = "http://www.the.literal?url";
//work on it from there
lead to the same outcome?

Is there a good way to parse out just the PROD or CTGY or whatever? I can use string.search() or .match() to find "Product_Code=BUTTS", but I can't just parse out the "BUTTS".
Edit: Apparently it is possible to just parse out the "BUTTS". /product_code=(\w*)/gi. Still don't have a good place to test everything.

darthbob88 fucked around with this message at 00:17 on Feb 27, 2012

ComptimusPrime
Jan 23, 2006
Computer Transformer
Do you not keep a local copy of the website for you to test on?

If you really have no other way, open up the firebug or chrome js console and start trying out your code.

darthbob88
Oct 13, 2011

YOSPOS
It's not my website, the company I work for is going to provide a recommendation service to the owners of that site, so I'm three degrees removed from the actual owner. Been saving copies to my computer so I can work on it locally, but there's a difference between C://path/to/file and http://www.the.literal?url. Had quite forgotten that Chrome's console can do that sort of thing, I've only been using it to see what errors have come up. Will try that now.

Doctor w-rw-rw-
Jun 24, 2008
I cannot for the life of me get jQuery Mobile and Backbone.js to play nicely with each other. I am too much of a newbie jQM, Backbone, and JS to really know what I'm doing, and the latest complete, easily-googled example of integration is a year old and obsolete, or a months-old article hinting at a part 2 which never materialized.

I'm desperate to get this working. Can someone help me out?

(I also happen to be using precompiled Handlebars templates, and am planning on using PhoneGap to deploy it as an app to the App Store + Android market.)

ComptimusPrime
Jan 23, 2006
Computer Transformer
What kind of problem are you having?

Doctor w-rw-rw-
Jun 24, 2008

ComptimusPrime posted:

What kind of problem are you having?

Well, I scrapped the code because my dealings with it devolved into cargo-culty copying of snippets to alter its behavior. Specifically, jQuery Mobile's responding to URL changes no matter what combination of the following I use:
code:
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
I also changed Ben Nolan's code to call .trigger("pagechange") instead of whatever he did, since that seemed more general. But the docs say that "pageinit" is better. Which then broke the drat page-showing.

So I'm basically at a loss because I have a very weak concept of how jQM works, how Backbone works, and how they interact, because I usually throw poo poo together and use it and fix it until it works before focusing on learning and improving the conceptual integrity and clarity of my understanding and the project itself.

---

Well gently caress me. Someone wrote a blog post and pushed to GitHub 13 hours ago finally explaining this.

http://coenraets.org/blog/2012/03/using-backbone-js-with-jquery-mobile/
https://github.com/ccoenraets/backbone-jquerymobile

Hallelujah. I am saved.

Lasalas
Feb 26, 2005
Holy poo poo, I thought the "F12 Developer Tools" was actually just some weird string error nobody ever bothered to fix.

Oh, Microsoft :allears:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I assume it was initially a placeholder name that never got changed, since the alternative is just too dumb.

Atimo
Feb 21, 2007
Lurking since '03
Fun Shoe
I'm trying to learn backbone for a small project, and I am really having a tough time working through it.

What I need is to be able to grow a chain of content down, and then be able to collapse it back upwards, where the only expand/collapse buttons that are enabled are on the very last item.

I have it sort of working bare-bones now, and I was hoping some experts could give it a quick glance and point out all the horrible things I'm doing wrong.

Html/template: http://pastebin.com/cZKzN9T0

Css: http://pastebin.com/RYbwKTC0

Coffeescript: http://pastebin.com/M9pY7mpc

Javascript for the Coffeescript: http://pastebin.com/eCYcgx8H

I would put it up an a demo but I don't know a quick free place to set something like that up.



Edit -

Not exactly an online demo, but here is everything in a nice little zip file.

http://www.mediafire.com/?smw5j4nfw5uka94



Online demo with source!

http://test.isawalion.com/

Atimo fucked around with this message at 16:34 on Mar 14, 2012

Mrs. Wynand
Nov 23, 2002

DLT 4EVA
I've been a bad posted and forgot to check in with my question, sorry.

Orbis Tertius posted:

I don't think so. However, even if there was a way to control it, you'd still have to deal with the fact that user's can turn off that behavior in their browser settings. That is, if the caching behavior you're looking to implement is central to your widget's functionality, you probably don't want to rely upon (or modify, somehow) that built-in browser behavior.

It's not "central" no, and the whole point is to try and maintain the user's expectation about widgets - i.e. if i hit refresh (without shift) or go back my widget state should be where I left it. If they turned off this feature then they obviously do not expect this and all is well.

quote:

Yeah, something along those lines. If you're working with a popular framework (jquery/mootools/etc), there's probably a plugin out there that does something very close to what you want - Sisyphus, for example.

Yeah so going through LocalStorage is actually a bad thing in this case because that would work against the usual behavior (e.g. shift refresh will fail to clear the value).

Anyway this isn't a huge deal. I've found it a very convenient and useful nicety in the past, but it kinda falls on its face once you generate series of fields :(

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

ComptimusPrime posted:

I have never looked in to form caching, but what do you mean in the Stack Overflow question when you say:


Dynamically generated HTML is definitely used all the time. Could you clarify what the problem you are running in to at this point is exactly?

Well of course it's used, but it doesn't seem to be noticed by the browser's form cache mechanism (the one that preserves your form through refreshes and back-navigation)

Bearnt!
Feb 6, 2004

No onions, no onions
Is there any code I can tack onto the default Twitter website widget to get it to cycle through say the last 5 tweets or so dynamically instead of showing only the latest one statically? Here is my code Thanks!

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
I have been given a nice problem to solve and have no idea what I am going to do... I need to us the JustGiving Javascript API to enable functionality to a flash app. Is there a way for me to utilise JS in actionscript 3? Here is a link to the API if anyone fancies a look. https://api.justgiving.com/docs

The project is for a major charity who have zero technical people to help me out, so its goon power or nothing.

5TonsOfFlax
Aug 31, 2001
You can use ExternalInterface to call js from flash and vice versa.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

5TonsOfFlax posted:

You can use ExternalInterface to call js from flash and vice versa.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html

thanks 5TonsOfFlax
OK so this should't be too hard then? Where would you recommend hiring someone to do this small snippet? A Javascript programmer or a flash programmer?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

thegasman2000 posted:

thanks 5TonsOfFlax
OK so this should't be too hard then? Where would you recommend hiring someone to do this small snippet? A Javascript programmer or a flash programmer?

You'll need both (or one person who can do both, which is fairly common). You'll need AS guy to expose any Actionscript methods that JS needs to call via externalInterface (and maybe write them if what you want to do isn't already in the AS). You'll need JS guy to be aware of the methods that were exposed, and to write code to call them based on page events.

If the AS stuff already exists in the flash file, then AS guy literally just adds one line per method to the actionscript file and writes down the 'public' names he gave them.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

Lumpy posted:

You'll need both (or one person who can do both, which is fairly common). You'll need AS guy to expose any Actionscript methods that JS needs to call via externalInterface (and maybe write them if what you want to do isn't already in the AS). You'll need JS guy to be aware of the methods that were exposed, and to write code to call them based on page events.

If the AS stuff already exists in the flash file, then AS guy literally just adds one line per method to the actionscript file and writes down the 'public' names he gave them.

Are you that guy?

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

thegasman2000 posted:

Are you that guy?

Uhh.. I could be, I guess. PM me with your contact info and I'll ask you some questions to see if I am. Mainly a question of time / timing; the code will be no problem, it's if I have the time to do it by the time you need it. OTherwise, there are lots of "that guy" here in goon-land.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply