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
peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

stack posted:

tooltips
I don't see anything about ttDestroy in either the source code or the examples page in the two links you posted. Where did you see that?

Adbot
ADBOT LOVES YOU

stack
Nov 28, 2000
Looks like his site doesn't use the same version as is at github.

http://github.com/lukasbob/Tooltip-Toolbox/blob/master/js/tooltip.js

spiritual bypass
Feb 19, 2008

Grimey Drawer
I've had great success with qtip for jQuery

stack
Nov 28, 2000

Thanks! qTip looks really good.

LP0 ON FIRE
Jan 25, 2006

beep boop
For some reason, I cannot get a span to display when I'm passing the name of it using selectedIndex. If I simply use onChange="Show_Stuff(this.display4)" it works.

head:

code:
function Show_Stuff(Click_Menu){
// Function that will swap the display/no display for
// all content within span tags

if (Click_Menu.style.display == "none"){
Click_Menu.style.display = "";
}
else{
Click_Menu.style.display = "none";
}
}
-->


body:

code:
<select onChange="Show_Stuff(this.selectedIndex)">
  <option value = "0" selected>nothing</option>
  <option value = "display4">display4</option>
</select>

<span ID="display4" style="display: none">
<table>
<tr><td width=40>&nbsp;</td><td width=200 wrap>
Sound Mixing<br>
Audio Editing<br>
Audio Restoration<br>
Sound Design<br>
</td>
</tr>
</table>
</span>
I've also tried experimenting with options[].value

code:
<select id="test" onChange="Show_Stuff(document.getElementById('test').options[document.getElementById('test').selectedIndex].value)">

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

awdio posted:

For some reason, I cannot get a span to display when I'm passing the name of it using selectedIndex. If I simply use onChange="Show_Stuff(this.display4)" it works.

Off the top of my head, but this should work:

code:
function Show_Stuff(myID)
{
 if(window.console.log) window.console.log( "I was passed: " + myID);
 var el = document.getElementById( myID );
 if(window.console.log) window.console.log( "el? " + el);
 if (el.style.display == "none")
 {
  el.style.display = "";
 }
 else
 {
  el.style.display = "none";
 }
}



body:

code:
<select onChange="Show_Stuff(this.selectedIndex.value)">
  <option value = "0" selected>nothing</option>
  <option value = "display4">display4</option>
</select>

<ul id="display4" class="aListStyle" style="display: none">
<li>Sound Mixing</li>
<li>Audio Editing</li>
<li>Audio Restoration</li>
<li>Sound Design</li>
</ul>
I fixed your HTML too.

LP0 ON FIRE
Jan 25, 2006

beep boop
It does not work. I think it's because an options value, not a selected index value, needs to be passed somehow. Without it being so dynamic, this is what originally worked: onChange="Show_Stuff(display4)"

Supervillin
Feb 6, 2005

Pillbug

awdio posted:

It does not work. I think it's because an options value, not a selected index value, needs to be passed somehow. Without it being so dynamic, this is what originally worked: onChange="Show_Stuff(display4)"

code:
ShowStuff(this.selectedIndex.value); // selectedIndex is a number, .value doesn't exist
ShowStuff(this[this.childNodes[this.selectedIndex].value); // this[index] is an option, .value exists

Supervillin fucked around with this message at 02:00 on Dec 2, 2009

Elected by Dogs
Apr 20, 2006
Is there a simple way to ask "Are you sure if you want to leave (domain)" on any links clicked that don't match a whitelist of domains (maybe using onunload?)

Googled, couldn't really find anything lightweight

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Elected by Dogs posted:

Is there a simple way to ask "Are you sure if you want to leave (domain)" on any links clicked that don't match a whitelist of domains (maybe using onunload?)

Googled, couldn't really find anything lightweight

I think the best way to do this would be to add an onclick handler to all anchor tags.
Something like this should work using jQuery:
code:
$("a").click(function() { if (/**some url-testing regex**/.test(this.href)) { return confirm("You sure about that?")} })
Also, if some of your anchor tags already have some onclick handler, you might need to have some extra checks in there to avoid adding this handler to them.


You might also try onbeforeunload, but I don't think you can easily check the next page's url from within that event handler.

peepsalot fucked around with this message at 04:52 on Dec 3, 2009

Elected by Dogs
Apr 20, 2006
Scrap the whitelist I guess.. PHP spits out different URL formats right now depending on where the domain is (/external_leaving?gotourl= final destination)

Would it be easier to just make a function asking to click ok/cancel when a link is onclick=""'d?

Supervillin
Feb 6, 2005

Pillbug

Elected by Dogs posted:

Would it be easier to just make a function asking to click ok/cancel when a link is onclick=""'d?

That's what peepsalot just showed you, actually. :)

More specifically, (new RegExp(document.domain, 'i')).test(this.href) will tell you if the domain matches, and confirm(...) pops up the OK/Cancel dialog. I use that for an analytics script and it works goodish.

For performance's sake you might want to do something like:
code:
var r = new RegExp(document.domain, 'i');
$("a").click(function() { if (!r.test(this.href)) { return confirm("You sure about that?")} });
That way it can reuse one regex instead of creating a new identical regex for every link.

Edit: Whoops, misread the first question, the above will tell you if the link goes to somewhere other than the current page's domain. To whitelist you could use something like:
code:
var r = /whatever\.com|goodsite\.net|othersite\.com/i;
$("a").click(...);
Depending on how long your whitelist is and how often that list changes, you (or we) could whip up a function that joins an array of whitelisted domains and uses that in the regex.

Supervillin fucked around with this message at 07:15 on Dec 3, 2009

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Supervillin posted:

code:
new RegExp(document.domain, 'i');
You'll probably want to escape the "."s in the domain before passing it to RegExp. Though the odds of this being an issue are probably very slim.

LP0 ON FIRE
Jan 25, 2006

beep boop

Supervillin posted:

code:
ShowStuff(this.selectedIndex.value); // selectedIndex is a number, .value doesn't exist
ShowStuff(this[this.childNodes[this.selectedIndex].value); // this[index] is an option, .value exists

I'm excited to get closer to a solution, but in your example ShowStuff(this[this.childNodes[this.selectedIndex].value); where does the missing bracket go? I tried all different sorts of combinations.

Elected by Dogs
Apr 20, 2006
I'm trying this and it's not confirming or asking anything:

code:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
var r = /google\.com|youtube\.com|/i;
$("a").click(function() { if (!r.test(this.href)) { return confirm("You are now leaving this site to go to: \n"+this.href+"\n")} });
</script>

</head>
<body>
<a href="http://go.at.se" rel="nofollow" class="outbound extlink">bad link</a>
</body>
I checked error console on firefox, nothing really popped out - any ideas what's wrong?

(sorry, I'm a total newbie to JS)

Kekekela
Oct 28, 2004

Elected by Dogs posted:

any ideas what's wrong?

Wrap the javascript in a document ready handler as shown below to get the click function working. Also the test condition in your if-statement evaluates to false so you wouldn't get to the confirm dialog anyway, I added an alert in an else-block that illustrates this. There might be some other problems (I didn't really get into the logic of what you were trying to do, just why the click function wasn't firing, and then why the confirm statement wasn't being reached once the click function was fixed). This should get you going:

code:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
  var r = /google\.com|youtube\.com|/i;
  $("a").click(function() 
  {if (!r.test(this.href)) 
    {return confirm("You are now leaving this site to go to: \n"+this.href+"\n")}
   else 
    {alert('test condition is false');return false;}
  });
});
</script>

</head>
<body>
<a href="http://go.at.se" rel="nofollow" class="outbound extlink">bad link</a>
</body>

Kekekela fucked around with this message at 22:29 on Dec 3, 2009

Supervillin
Feb 6, 2005

Pillbug

awdio posted:

I'm excited to get closer to a solution, but in your example ShowStuff(this[this.childNodes[this.selectedIndex].value); where does the missing bracket go? I tried all different sorts of combinations.

Whoops! So this is why they always said "show your work" in math class. Didn't need the initial "this".
code:
// more verbose
var index = this.selectedIndex; // chosen option's index
var option = this.childNodes[index]; // actual <option> element
var value = option.value; // chosen option's value attribute

ShowStuff(this.childNodes[this.selectedIndex].value); // try this!

LP0 ON FIRE
Jan 25, 2006

beep boop

Supervillin posted:

Whoops! So this is why they always said "show your work" in math class. Didn't need the initial "this".
code:
// more verbose
var index = this.selectedIndex; // chosen option's index
var option = this.childNodes[index]; // actual <option> element
var value = option.value; // chosen option's value attribute

ShowStuff(this.childNodes[this.selectedIndex].value); // try this!

Tried that... still nothing. I'm just trying to pass an options value. From what you mentioned above, shouldn't it be option.value?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

awdio posted:

Tried that... still nothing. I'm just trying to pass an options value. From what you mentioned above, shouldn't it be option.value?

this.options[this.selectedIndex].value

Really, just google "get selected value with javascript"

LP0 ON FIRE
Jan 25, 2006

beep boop

Lumpy posted:

this.options[this.selectedIndex].value

Really, just google "get selected value with javascript"

I have with no such luck yet. I really thank you guys for helping me out, and it's opened my mind a little bit. But try it if you want. It's not working for me.

code:

<html>
<head>
<script language="JavaScript">
<!--
function Show_Stuff(Click_Menu){

if (Click_Menu.style.display == "none"){
Click_Menu.style.display = "";
}
else{
Click_Menu.style.display = "none";
}
}
-->
</script>
</head>

<body>

<form>
<select "test" onChange="Show_Stuff(this.options[this.selectedIndex].value);">
  <option value = "0" selected>nothing</option>
  <option value = "display4">display4</option>
  <option value = "display5">display5</option>
</select>
</form>

<span ID="display4" style="display: none">
hey
</span>

</body>

</html>

Again, <select "test" onChange="Show_Stuff(display4);"> works fine.

LP0 ON FIRE fucked around with this message at 21:40 on Dec 4, 2009

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

awdio posted:

:words:
Your Show_Stuff function expects a DOM element parameter to be passed to it, and you're passing it the value attribute of an element(a string).

epswing
Nov 4, 2003

Soiled Meat
Just thought I'd share a snippet I've gotten a lot of mileage out of:

code:
var url = function() {
	var url_regex = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
	var url = url_regex.exec(location.href);
	return {
		url: url[0], 	// http://www.site.com:8080/subdir/search.html?q=help#top
		scheme: url[1], // http
		slash: url[2], 	// //
		host: url[3], 	// [url]www.site.com[/url]
		port: url[4], 	// 8080
		path: url[5], 	// /subdir/search.html
		query: url[6], 	// q=help
		hash: url[7] 	// top
	};
}();
Use it like this:
code:
alert(url.scheme + '://' + url.host + ':' + url.port); // "http://www.site.com:8080"
Credit goes to Crockford's The Good Parts.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

peepsalot posted:

Your Show_Stuff function expects a DOM element parameter to be passed to it, and you're passing it the value attribute of an element(a string).

Yup, that's why in the code I posted for him before I used getElementById to make a DOM object. I even put in console logging for him. :sigh:

loteck
May 25, 2005

what is BAPE?
I've got an issue where all the images I'm using in a jquery slideshow I've got on the page (images in a <ul>) all flash on the screen briefly when the page loads. Googling has led me to investigate using CSS to set all the images to be hidden and then using a javascript to automatically set them to unhidden on page load. The javascript I'm using (taken from an about.com page)

As you can see below, the javascript as it is written requires an event to be triggered (link click) and a parameter passed to the script (of the element ID to affect).

code:
<script type="text/javascript">
function unhide(divID) {
  var item = document.getElementById(divID);
  if (item) {
    item.className=(item.className=='hidden')?'unhidden':'hidden';
  }
}
</script>
relevant css:
code:
		#feature-header ul#cta.hidden {
			position: absolute; list-style: none; top: -25px; left: 50px;
			overflow: hidden; visibility: hidden;
		}
		#feature-header ul#cta.unhidden {
			position: absolute; list-style: none; top: -25px; left: 50px;
			overflow: hidden; visibility: visible;
		}		
The script works fine if I do it as a triggered event, like clicking a link. I'm trying to modify the script so that it just automatically modifies the same divID on every page load. Replacing (divID) in the above script with the id of the div I want to be affected (cta) is not getting me anywhere so far, having tried inserting it with and without apostrophes.

Can anyone lead me in the right direction or suggest a different strategy for tackling this problem? Thanks.

SuckerPunched
Dec 20, 2006

Just use jQuery for it:

code:
$(document).ready(function(){
   $('#feature-header ul#cta').removeClass('hidden').addClass('unhidden');
});

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

epswing posted:

Just thought I'd share a snippet I've gotten a lot of mileage out of:

code:
var url = function() {
	var url_regex = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
	var url = url_regex.exec(location.href);
	return {
		url: url[0], 	// [url]http://www.site.com:8080/subdir/search.html?q=help#top[/url]
		scheme: url[1], // http
		slash: url[2], 	// //
		host: url[3], 	// [url]www.site.com[/url]
		port: url[4], 	// 8080
		path: url[5], 	// /subdir/search.html
		query: url[6], 	// q=help
		hash: url[7] 	// top
	};
}();
Use it like this:
code:
alert(url.scheme + '://' + url.host + ':' + url.port); // "http://www.site.com:8080"
Credit goes to Crockford's The Good Parts.

The location object already has all these properties

epswing
Nov 4, 2003

Soiled Meat
well shiver me timbers

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.
Aye matey.

Could still be useful as a function you pass urls into that aren't the current location.

ronin109
Aug 23, 2002

awdio posted:

For some reason, I cannot get a span to display when I'm passing the name of it using selectedIndex. If I simply use onChange="Show_Stuff(this.display4)" it works.
... code snippet ...

The following will display the element matching the selected ID attribute:
code:
<script>
function Show_Stuff(selEl) {
    var id = selEl[selEl.selectedIndex].value;
    var el = document.getElementById(id);
    if (el) {
        el.style.display = "";
    }
}
</script>

<select onchange="Show_Stuff(this)">
    <option value="0" selected>nothing</option>
    <option value="display4">display4</option>
</select>

<ul id="display4" class="aListStyle" style="display: none">
    <li>Sound Mixing</li>
    <li>Audio Editing</li>
    <li>Audio Restoration</li>
    <li>Sound Design</li>
</ul>

epswing
Nov 4, 2003

Soiled Meat

jupo posted:

Aye matey.

Could still be useful as a function you pass urls into that aren't the current location.

ARRRRRR

code:
var url = function(loc) {
	var url_regex = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
	var url = url_regex.exec(typeof loc === 'string' ? loc : location.href);
	return {
		url: url[0], 	// [url]http://www.site.com:8080/subdir/search.html?q=help#top[/url]
		scheme: url[1], // http
		slash: url[2], 	// //
		host: url[3], 	// [url]www.site.com[/url]
		port: url[4], 	// 8080
		path: url[5], 	// /subdir/search.html
		query: url[6], 	// q=help
		hash: url[7] 	// top
	};
};

LP0 ON FIRE
Jan 25, 2006

beep boop

ronin109 posted:

The following will display the element matching the selected ID attribute:
*code*

Thanks!!! Works great.

RussianManiac
Dec 27, 2005

by Ozmaugh
is there a good stand-alone interpreter for javascript, so I could write javascript scripts as replacement for perl or LISP scripts?

epswing
Nov 4, 2003

Soiled Meat

RussianManiac posted:

is there a good stand-alone interpreter for javascript, so I could write javascript scripts as replacement for perl or LISP scripts?

I think you're looking for Rhino

Ghotli
Dec 31, 2005

what am art?
art am what?
what.
I hear V8 and Node.js are all the rage these days. Seems to be what most of the server side js guys are starting to standardize around. I've written very little server side js so YMMV.

http://code.google.com/p/v8/
http://nodejs.org/

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

RussianManiac posted:

is there a good stand-alone interpreter for javascript, so I could write javascript scripts as replacement for perl or LISP scripts?

You could also try spidermonkey

loteck
May 25, 2005

what is BAPE?

SuckerPunched posted:

Just use jQuery for it:

code:
$(document).ready(function(){
   $('#feature-header ul#cta').removeClass('hidden').addClass('unhidden');
});

Great suggestion, really appreciate it. Worked beautifully.

NZAmoeba
Feb 14, 2005

It turns out it's MAN!
Hair Elf
I know absolutely nothing about javascript or really coding in general short of a semester or two 7 years back.

We have a display that we want to cycle various web pages, scroll down them, then move to the next one after a short time. I've been able to google up something that'll do the 'cycle through pages' thing, but now I just need to figure out how to make it scroll vertically through the content.

This is what I have now:
code:
<html>
      <head>

<script type="text/javascript">
var pages = [
"http://google.com",
"http://yahoo.com",
"http://cnn.com"
];
var currentIndex = -1;
function startCycle() {
    var iframe = document.getElementById("iframe1");
    currentIndex = (++currentIndex) % pages.length;
    iframe.onload = function() {
        window.setTimeout(startCycle, 20000); //Currently set to change every 20 seconds
    }
    iframe.src = pages[currentIndex];
}
window.onload = startCycle;</script>
      </head>
      <body>
            <iframe  id="iframe1"  frameborder="0"  vspace="0"  hspace="0"  marginwidth="0"  

marginheight="0"
                  width="100%"  scrolling="yes"  height="100%">
            </iframe>
      </body>
</html> 
This page: http://www.mediacollege.com/internet/javascript/page/scroll.html seems to have what looks like the sort of thing I want to make it scroll, but it's designed for scrolling the whole page, not just an individual iframe. How do I transplant that code into what I have to make it scroll down? Also is this going to get really difficult if I want it to scroll back up once it reaches the bottom?

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

NZAmoeba posted:

How do I transplant that code into what I have to make it scroll down? Also is this going to get really difficult if I want it to scroll back up once it reaches the bottom?
I don't think you can access the DOM of any of iframe pages(hence can't scroll) unless they are on the same domain as your main page. If they are one different domains, you might need to load them through a sort of proxy on your own domain.

nanerpuss
Aug 6, 2005

voudrais-tu une banane, mon amie?
So I'm going to assume you guys have heard of the Google AJAX Feed API right? Pretty killer tool, but I'm having a small issue that really isnt that important, but I'd love to fix it soon.

As I am sure most of you know, text overflow is handled pretty well in all browsers BUT Firefox... which seems a bit odd really, but for some reason, they are the only ones that don't offer a 'ellipsis' as an overflow option.

So what I have is a plugin I discovered written in JQuery that apparently fixes these problems, but I can't get it to work because said plugin requires an ID be assigned to the link(s) that the Javascript file creates... and it's not fun to gently caress with.

I won't bother with the plugin code because I prefer to not gently caress with it, but here is the code Google gave us:
http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js

Now notice the class .gfg-listentry... that is the class that needs an 'id="one"' added in every time it is displayed... otherwise i get a nasty looking text-cutoff in Firefox. :smith:

Any advice on how to do this or any easier way to accomplish what I need? Thanks.

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

NANERPUSS posted:

So I'm going to assume you guys have heard of the Google AJAX Feed API right? Pretty killer tool, but I'm having a small issue that really isnt that important, but I'd love to fix it soon.

As I am sure most of you know, text overflow is handled pretty well in all browsers BUT Firefox... which seems a bit odd really, but for some reason, they are the only ones that don't offer a 'ellipsis' as an overflow option.

So what I have is a plugin I discovered written in JQuery that apparently fixes these problems, but I can't get it to work because said plugin requires an ID be assigned to the link(s) that the Javascript file creates... and it's not fun to gently caress with.

I won't bother with the plugin code because I prefer to not gently caress with it, but here is the code Google gave us:
http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js

Now notice the class .gfg-listentry... that is the class that needs an 'id="one"' added in every time it is displayed... otherwise i get a nasty looking text-cutoff in Firefox. :smith:

Any advice on how to do this or any easier way to accomplish what I need? Thanks.

Modify the plugin to select .gfg-listentry instead of #one ?

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