We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Locked Topic
  • Pages:
  • 1
[ C ] Code to get a link from a profile field.
Topic Started: Jul 19 2013, 08:05 PM (864 Views)
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
Board Address: Great Escape
Board Software: ZetaBoards
Description: I have the following code created by HolySavior of ZNR (with my links in it, obviously)
Code:
 
/*created by HolySavior of ZNR and Javascriptin.com */
var idrop = new Array()
idrop[0] = ["URL","Link Name that appears in menu"]
idrop[1] = ["URL","Link Name that appears in menu"]
idrop[2] = ["URL","Link Name that appears in menu"]
idrop[3] = ["URL","Link Name that appears in menu"]
idrop[4] = ["URL","Link Name that appears in menu"]
idrop[5] = ["URL","Link Name that appears in menu"]

if($("#top_menu:contains('Inbox ')").html()) {

$("#top_menu").append("<li><a>Helpful Links</a><ul id='newdrop'></ul></li>");

for(x=0;x<idrop.length;x++) {
$("#newdrop").append("<li><a href='"+idrop[x][0]+"'>"+idrop[x][1]+"</a></li>");
}
}
What I'd ideally like to add to it is a link line (this would be either "idrop[6]" or I might re-number them and make the new one "idrop[0]") that would get an address from a profile field labelled "My Radio Station" and then open a new pop-BEHIND (or popped up, but instantly minimized) window for that radio station's live broadcast.

I'd like the link in the menu, when created, to be named "My Radio".

Here's an example of a link that would be found in the "My Radio Station" profile field (it's my local station, that I listen to): http://www.wimz.com/sites/wimz/wimz.html

Is this possible?
Edited by RichardInTN, Jul 19 2013, 08:07 PM.
Offline Profile Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
I don't have the window/tab focus operational at the moment, but this is a start:
Code:
 
idrop[#] = ["" + main_url + "home/?c=6","My Radio"];
Code:
 
<script type="text/javascript">
//<![CDATA[
$(function () {
var pField = 'My Radio';

function openRadio() {
$('#newdrop a:contains(' + pField + ')').click();
}

$('#newdrop a:contains(' + pField + ')').one('click', function (e) {
e.returnValue = e.preventDefault && e.preventDefault() ? false : false;
var $this = $(this);

$.get($(this).attr('href') + '&force_ads', function (data) {
var rStation = $('#edit_profile td.c_desc:contains(' + pField + ')', data).next('td').find('input').val();
$this.attr('href', rStation);
});
}).attr('target', '_blank');
openRadio();
});
//]]>
</script>
Offline Profile Goto Top
 
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
In the Javascript window shouldn't
Code:
 
var pField = 'My Radio';
actually be
Code:
 
var pField = 'My Radio Station';
so it matches the "My Radio Station" profile field?


Other than that, it looks great so far. I'll wait to implement it though, until you say you've got the window focus set up.
Edited by RichardInTN, Jul 20 2013, 04:29 AM.
Offline Profile Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Indeed, make sure your profile field name and link name is the same, or if you don't want them the same just a few things in the script will need to be modified.
Offline Profile Goto Top
 
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
Also, when I do install the javascript you are writing... where will it go in relation to HolySavior's script? It's in "Above the Board"... will your script be added before or after HolySavior's?
Offline Profile Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Above or below the code should be fine. It's a click function, so it doesn't need to be placed in a specific location in relation to the code to parse correctly.
Offline Profile Goto Top
 
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
I changed my mind, and decided to go ahead and add it (I can always update it with the window focus).

I found a glitch. When it's clicked, it takes me to the "Edit Profile" page instead of going to the radio station's site.


ETA: Would it matter that (because I'm getting close to my character limit) I saved the script as a file and "called it" using
Code:
 
<script type="text/javascript" src="http://z5.ifrm.com/30158/152/0/f5216828/MyRadio.js">
</script>
(That's how I call HolySavior's code as well)
Edited by RichardInTN, Jul 20 2013, 09:49 PM.
Offline Profile Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
You'll need to change the link name to My Live Radio as well or change this:
Code:
 
$('#newdrop a:contains(' + pField + ')')
To this:
Code:
 
$('#newdrop a:contains(My Radio)')
Offline Profile Goto Top
 
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
Cory
Jul 21 2013, 03:06 AM
You'll need to change the link name to My Live Radio as well or change this:
Code:
 
$('#newdrop a:contains(' + pField + ')')
To this:
Code:
 
$('#newdrop a:contains(My Radio)')
Changing the link name fixed it.

I thought you meant only the variable attached to the name had to be the same. I misunderstood.

Thanks for your efforts so far, I hope you can get the focus to work so it opens behind everything else OR opens minimized.
Encountered an unexpected problem (nothing to do with your code though) that gave me an idea.

My local station (the link in the OP) goes to "dead air" when they are broadcasting (over antenna) subcontracted content (no live DJ at their station)... like, right now, "the House of Hair" (80's heavy metal "hair bands") is being broadcast by antenna, but there's nothing on the on-line broadcast but an notation that they are broadcasting "House of Hair"...

So... would a SECOND choice be possible? I'm thinking with completely separate and independent profile fields (make them "My Live Radio 1" and "My Live Radio 2") and separate "idrop[#]" entries in the "Helpful Links" drop down menu?
Edited by RichardInTN, Jul 21 2013, 09:41 PM.
Offline Profile Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
First things first, I'm not sure about the window/tab focus. In a way, the possibility of doing this sounds like it could be a security breach, meaning any site can set their website window/tab to focus, while all other websites are blurred making it where their site is always viewable. Using window.open() to open a popup doesn't seem doable because so many browsers allow or enable popup blockers by default because they are generally considered intrusive, especially when it comes to advertising. I was taking a peek at some of the answers on Stack Overflow about this window/tab focus issue and most of the answers said it wasn't possible or practical.

I have an idea myself though: You can create a webpage and have an input box and submit button. In the input box users can insert their radio station link and when the form is submitted the link will either open in a new tab/window or open in an iFrame on the webpage itself. All links on this webpage can have the 'target' attribute set to _blank so the links will open in a new tab/window and the user won't be navigated away from their radio station and it will basically be playing in the background while they are browsing other parts of the forum. Or, scratch the insertion of the radio link in the input box idea and make it so the radio link is grabbed from their Editing Profile page and all they have to do is click a button on the webpage to turn it on using the methods described above.
Offline Profile Goto Top
 
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
Well, the window focus wasn't a "necessity" so much as it would have been a "niceity". There's always the standby of RIGHT-CLICK on the link in the menu and tell it "Open link in new window", then just minimize the window (that's how I personally use it now).

ETA: that didn't sound "clear" to me... so, to be clear, the code you already wrote works perfectly if the user RIGHT-Clicks.
Edited by RichardInTN, Jul 22 2013, 03:19 AM.
Offline Profile Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
You could try something like this I guess:
Code:
 
<script type="text/javascript">
//<![CDATA[
$(function () {
var pField = 'My Live Radio';

$.get(main_url + 'home/?c=6&force_ads', function (data) {
var rStation = $('#edit_profile td.c_desc:contains(' + pField + ')', data).next('td').find('input').val();
$('#newdrop a:contains(' + pField + ')').attr('href', rStation);
});

$('#newdrop a:contains(' + pField + ')').click(function (e) {
e.returnValue = e.preventDefault && e.preventDefault() ? false : false;
alert('Right click the link and select the \'Open Link in New Window\' option');
});
});
//]]>
</script>
Offline Profile Goto Top
 
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
It's o.k. ... don't worry about that alert. I have "How to" pages for certain things... I wrote one for this, so RIGHT-Clicking is already covered.

The only thing really needed now is a second link for a second station (just in case the first one is dead air)... and whatever coding in your Javascript to make the second link work.
Offline Profile Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Try this:
Code:
 
idrop[#] = ['', 'My Radio 1'];
idrop[#] = ['', 'My Radio 2'];
Code:
 
<script type="text/javascript">
//<![CDATA[
$(function () {
var pField1 = 'My Radio 1';
var pField2 = 'My Radio 2';

$('#newdrop a:contains(' + pField1 + '), #newdrop a:contains(' + pField2 + ')').attr('target', '_blank');

if ($.zb.get('rStation1') || $.zb.get('rStation2')) {
$('#newdrop a:contains(' + pField1 + ')').attr('href', $.zb.get('rStation1'));
$('#newdrop a:contains(' + pField2 + ')').attr('href', $.zb.get('rStation2'));
} else {
$.get(main_url + 'home/?c=6&force_ads', function (data) {
var rStation1 = $('#edit_profile td.c_desc:contains(' + pField1 + ')', data).next('td').find('input').val();
var rStation2 = $('#edit_profile td.c_desc:contains(' + pField2 + ')', data).next('td').find('input').val();
$.zb.set('rStation1', rStation1);
$.zb.set('rStation2', rStation2);
$('#newdrop a:contains(' + pField1 + ')').attr('href', rStation1);
$('#newdrop a:contains(' + pField2 + ')').attr('href', rStation2);
});
}

$('#edit_profile').closest('form').submit(function () {
$.zb.del('rStation1');
$.zb.del('rStation2');
});
});
//]]>
</script>
Offline Profile Goto Top
 
RichardInTN
Member Avatar
I believe in I.D.I.C.
[ *  *  * ]
Works perfectly Cory. You are a RockStar dude.
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Closed Requests · Next Topic »
Locked Topic
  • Pages:
  • 1