#1 Edited by billyboy (5 posts) -

So looking at the description in games there is a problem. In some the entire url to giant bomb is supplied

ie: http://www.giantbomb.com/third-person-perspective/3015-464/

in others only partial

ie: /third-person-perspective/3015-464/

and in some a mix of both. I write some jquery to fill the void of the partial but for those that supply the giantbomb.com url I end up having

ie: http://giantbomb.com//www.giantbomb.com/assassins-creed-iii/3030-37494/

So what is the way around this, does anyone have a code snippet to work around this?

Currently I have this

[code]

$("[data-ref-id|='3030']").attr('href', function (idx, href) {

return 'http://giantbomb.com' + href;

});

[/code]

Where I just supply the first 4 numbers of the ref id to the url.

#2 Edited by Laika (107 posts) -

Where are you seeing partial URLs returned? They should (probably) always be absolute.

For the time being, you can just check whether the domain substring is present (see String.prototype.indexOf), and conditionally add it in.

Staff
#3 Posted by billyboy (5 posts) -

@laika: most overviews of games either have it, dont or are a mix.

doesn't have it - http://www.giantbomb.com/api/game/3030-44217/?api_key=xxxxx&filter=name:minecraft&format=json

doesn'thave it - http://www.giantbomb.com/api/game/3030-30475/?api_key=xxxxx&filter=name:minecraft&format=json

is a mix - http://www.giantbomb.com/api/game/3030-31709/?api_key=xxxxx&filter=name:minecraft&format=json

is a mix - http://www.giantbomb.com/api/game/3030-41484/?api_key=xxxxx&filter=name:minecraft&format=json

is a mix - http://www.giantbomb.com/api/game/3030-41518/?api_key=xxxxx&filter=name:minecraft&format=json

like this for a lot of games, haven't yet looked over any of the others but it appears to only be in the descriptions.

at first i thought the urls were partial so the links could go to your own site but then i noticed a mix and thought something must be wrong.

#4 Edited by Laika (107 posts) -

Links in the description field are added by wiki editors and not normalized. We can consider adding that in the upcoming wiki work.

Staff
#5 Edited by billyboy (5 posts) -

I cant for the life of me get it to work with

String.prototype.indexOf

been trying something like this

var giant = "http://giantbomb.com";

if (giant.indexOf("http://giantbomb.com") !=-1)

("[data-ref-id|='3010']").attr('href', function (idx, href) {

return href;

});

else

("[data-ref-id|='3010']").attr('href', function (idx, href) {

return 'http://giantbomb.com' + href;

});

if (giant.indexOf("http://giantbomb.com") !=-1)

("[data-ref-id|='3045']").attr('href', function (idx, href) {

return href;

});

else

("[data-ref-id|='3045']").attr('href', function (idx, href) {

return 'http://giantbomb.com' + href;

});

but is a no go

#6 Edited by Chaser324 (6544 posts) -

@billyboy: Well without spending any time really parsing through your code, I immediately notice several typos where you misspelled giantbomb.

Moderator Online
#7 Edited by billyboy (5 posts) -

@chaser324: my bad, even with out typos i cant get it to work. i must have spent a few hours trying various ways with String.prototype.indexOf on my page and with jsfiddle

so for the time being until someone can answer this or post a legit way of working with this i just did a str.replace to remove the url and then added it back in with javascript...

#8 Edited by Chaser324 (6544 posts) -

@billyboy: I'm not too sure what exactly it is you're trying to accomplish with your code. Do you have a link to the jsfiddle?

First off, doing something like this is unnecessary:

("[data-ref-id|='3010']").attr('href', function (idx, href) { return href; });

You're just setting the href attribute equal to its current value. Second, I'm a bit curious where this comes from:

var giant = "http://giantbomb.com";

I'm assuming that's just a test value for your code here, but where do you actually intend to pull that value from? Isn't that just going to be pulled from the href attribute itself? In which case, why not just do this:

$("[data-ref-id|='3045']").not("[href*='giantbomb.com']").attr('href', function (idx, href) {

return 'http://giantbomb.com' + href;

});

That should only select elements with that particular data-ref-id attribute which do not contain 'giantbomb.com' in their href attribute.

Moderator Online
#9 Posted by billyboy (5 posts) -

@billyboy: I'm not too sure what exactly it is you're trying to accomplish with your code. Do you have a link to the jsfiddle?

First off, doing something like this is unnecessary:

("[data-ref-id|='3010']").attr('href', function (idx, href) { return href; });

You're just setting the href attribute equal to its current value. Second, I'm a bit curious where this comes from:

var giant = "http://giantbomb.com";

I'm assuming that's just a test value for your code here, but where do you actually intend to pull that value from? Isn't that just going to be pulled from the href attribute itself? In which case, why not just do this:

$("[data-ref-id|='3045']").not("[href*='giantbomb.com']").attr('href', function (idx, href) {

return 'http://giantbomb.com' + href;

});

That should only select elements with that particular data-ref-id attribute which do not contain 'giantbomb.com' in their href attribute.

your awesome thanks ,this is what i wanted. im not a professional and javascript is not my strong side :D