Solved

How is this Javascript extended to replace the domain name etc?

Posted on 2008-10-21
9
307 Views
Last Modified: 2008-11-11
Hello,

I'm using the Javascript thumbnail viewer called Highslide (http://highslide.com/). One of the commands that are available allow an image filename to be added as a image caption.

For example:
      hs.captionEval = 'this.content.src.replace(\'.jpg\', \'\')';

...will remove the '.jpg' from the filename.

Please can some tell me how i can extend this so that the current caption can be changed from:
http://www.globexposure.net/includes/travel_pics/163/Toby Texas%20Chainsaw%20Massacre.jpg
to
Toby Texas Chainsaw Massacre

Please note, however, that the '163' element of the current name is an id variable, and will therefore change between images.


Many thanks for your help
0
Comment
Question by:Daniish
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:bluV11t
Comment Utility
This might help:

hs.captionEval = this.content.src.replace(\'.jpg\', \'\');
//add this line after:
hs.captionEval= hs.captionEval.substr(myString.lastIndexOf('/')+1));
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
try:
var str="http://www.globexposure.net/includes/travel_pics/163/Toby Texas%20Chainsaw%20Massacre.jpg";
var result = str.replace( /.*\/([^\/]+)\.jpg$/i,"$1")
alert( result );

Open in new window

0
 

Author Comment

by:Daniish
Comment Utility
Blu - your code makes the whole caption area under the images, disappear!

Hielo - sorry perhaps i wasn't clear, each image on my site (there will be hundreds) needs to have its filename set to be the caption. Therefore, it is not possible to hardcode the var 'str'.
Is there a way var str could be set dynamically?
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
the hard-coded value was just an example. What you really need is:



hs.captionEval = 'this.content.src.replace( /.*\/([^\/]+)\.jpg$/i,"$1")';

Open in new window

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Daniish
Comment Utility
Hi Hielo,

It looks very complex, but i'm afraid that it doesn't appear to do anything. I can't begin to understand what it does but hopefully you can see what's wrong.

Thanks again but please keep trying.
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>but please keep trying.
Yeah right. Not in the dark!
0
 
LVL 7

Expert Comment

by:bluV11t
Comment Utility
Try this:
myString = this.content.src.replace(\'.jpg\', \'\');
//add this line after:
hs.captionEval= hs.captionEval.substr(myString.lastIndexOf('/')+1));
0
 

Author Comment

by:Daniish
Comment Utility
Hi Blu - your code seems to hide both the caption and controlbar

You can see the effect here www.globexposure.net/index_blu.php

as opposed to the normal look www.globexposure.net/index.php
0
 

Accepted Solution

by:
Daniish earned 0 total points
Comment Utility
The Highslide forum author has provided a working solution:
http://highslide.com/forum/viewtopic.php?t=2580&highlight=
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now