SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old June 22nd, 2005, 02:48 PM
brew_bird brew_bird is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 1 brew_bird User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 47 sec
Reputation Power: 0
selecting an image in all browsers

At work, we started using Epoz with out Plone sites, and really like its flexibility. However, we have been unable to figure out one thing, and I was hoping someon had some insight into whether it was possible or not. We'd like to write a javascript function where you can highlight an image, click on an Epoz button, pop up a window where you select a sound file that the selected image will point to, and return code to form a javascript function call around the image.

So you start with this highlighted: <img src="image.jpg">

And end up with this: <a href="javascriptopSound('sound_file.html','Title','50' ,'50');"><img src="image.jpg"></a>

I've gotten it to work with IE, but with all other browsers I lose the image. Is that just not selectable? I've tried many variations and searched the web for solution to no avail.

Thanks for any help or hints,
Eric

Here is our current function:

// Creates a Javascript popup link

function CreatePopUpLink(URL, title, width, height) {

EpozElement.contentWindow.focus();

if (browser.isIE5up) {
selection = EpozElement.contentWindow.document.selection;
} else {

selection = EpozElement.contentWindow.window.getSelection();
}

// the function called here must be defined or referenced from the page that the link is one
startTag = "a href=\"javascriptopSound('" + URL + "','" + title + "','" + width + "','" + height + "');\"";

if (browser.isIE5up) {

range = selection.createRange();
var result = '<' + startTag + '>' + range.htmlText + '</a>';

try {
range.pasteHTML(result);
} catch (e) {
// catch error when range is evil for IE
}
} else {
var result = '<' + startTag + '>' + selection + '</a>';

EpozElement.contentWindow.focus();
if (selection) {
range = selection.getRangeAt(0);
} else {
range = EpozElement.contentWindow.document.createRange();
}

var fragment = EpozElement.contentWindow.document.createDocumentF ragment();

// ** ADD NEW ELEMENT
var div = EpozElement.contentWindow.document.createElement(' a');
div.innerHTML = result;

while (div.firstChild) {
fragment.appendChild(div.firstChild);
}

selection.removeAllRanges();
range.deleteContents(); // why would you delete the selected content?

var node = range.startContainer;
var pos = range.startOffset;

//Returns a code representing the type of the underlying node
switch (node.nodeType) {
case 3: //TEXT_NODE = 3;
if (fragment.nodeType == 3) {
node.insertData(pos, fragment.data);
range.setEnd(node, pos + fragment.length);
range.setStart(node, pos + fragment.length);
} else {
node = node.splitText(pos);
node.parentNode.insertBefore(fragment, node);
range.setEnd(node, pos + fragment.length);
range.setStart(node, pos + fragment.length);
}
break;

case 1: //ELEMENT_NODE = 1;
node = node.childNodes[pos];
node.parentNode.insertBefore(fragment, node);
range.setEnd(node, pos + fragment.length);
range.setStart(node, pos + fragment.length);
break;
default:
break;
}
selection.addRange(range);
}
}

Reply With Quote
  #2  
Old June 30th, 2006, 04:51 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 471 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 10 m 16 sec
Reputation Power: 3
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
Exclamation got the soloution

hello, if you wanted to do this, the way i have done it b4 is by puting the image in a <div id="pic"><img src="hi.gif"></img></div>
now when they want to update the link, use this...
var orig=pic.innerHTML;
pic.innerHTML='<A HREF="'+linksrcORfunction+'">'+orig+'</a>

good luck,
the code above may create an error but the main idea is the
object.innerHTML

that will work

colton22

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > selecting an image in all browsers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway