Solved

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

Posted on 2008-10-21
9
309 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
ID: 22769309
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
ID: 22769333
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
ID: 22771654
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 82

Expert Comment

by:hielo
ID: 22771859
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
 

Author Comment

by:Daniish
ID: 22772151
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
ID: 22772377
>>but please keep trying.
Yeah right. Not in the dark!
0
 
LVL 7

Expert Comment

by:bluV11t
ID: 22775273
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
ID: 22775586
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
ID: 22897537
The Highslide forum author has provided a working solution:
http://highslide.com/forum/viewtopic.php?t=2580&highlight= 
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

856 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