Need help with coding for generated link

Discussion in 'JavaScript' started by onetr1p, Mar 19, 2007.

  1. #1
    This is my code:
    
    else {// "image" is the default
     if (modRewrite) {
     path = webPath+"/"+albumUrl+"/"+imageUrl
    } else {
     path = webPath+"/albums/"+albumUrl+"/"+imageUrl
    }
    imageHTML += path;
    }
    
    Code (markup):
    The link that is generated looks like this:

    <a href="http://www.domain.com/albums/cars/ferrari.jpg"/>
    Code (markup):
    How can I add rel="lightbox" to the coding?

    I tried:

    path = webPath+"/albums/"+albumUrl+"/"+imageUrl+" rel="lightbox"
    Code (markup):
    but I get this generated:

    <a href="http://www.domain.com/albums/cars/ferrari.jpg%20rel="lightbox.jpg""/>
    Code (markup):
    but I need it to have the space for it to work.
    so it would look like

    <a href="http://www.domain.com/albums/cars/ferrari.jpg" rel="lightbox">
    Code (markup):
    How can I do this? Sorry I have no knowledge of java at all. Thanks in advanced.

    [update] resolved
     
    onetr1p, Mar 19, 2007 IP
  2. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #2
    mate post the full code, how can one solve your problem by looking a few lines?
     
    designcode, Mar 20, 2007 IP
  3. onetr1p

    onetr1p Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry, Here's the full code that is related to this function:

    
    /**
     * Class declaration
     */
    function ZenpressPopup() {
    };
     
     /**
      * Insert an image in the text editor
      * @param imageId	Id of the image (not used yet)
      * @param imageUrl	Filename of the image
      * @param imageName	Name (title) of the image
      */
    ZenpressPopup.prototype.insertImage = function(imageId,imageUrl,imageName) {
    	form = this.getEl('options');
    	whatValue = this.getRadioValue(form.what);
    	linkValue = this.getRadioValue(form.link);
    	closeValue = this.getRadioValue(form.close);
    	wrapValue = this.getRadioValue(form.wrap);
    	sizeValue = this.getRadioValue(form.size);
    	modRewrite = form.mod_rewrite.value;
    	webPath = form.zp_web_path.value;
    	albumUrl = form.album_url.value;
    	albumName = form.album_name.value;
    	customWidth = form.custom_width.value;
    	customHeight = form.custom_height.value;
    	
    	imageHTML = "";
    	
    	if (linkValue!="none") {
    		imageHTML += '<a href="';
    		if (linkValue=="album") {
    			if (modRewrite) {
    				path = webPath+"/"+albumUrl;
    			} else {
    				path = webPath+"/index.php?album="+albumUrl;
    			}
    			imageHTML += path;
    		} else if (linkValue=="custom" && form.link_custom_url.value!="") {
    			imageHTML += form.link_custom_url.value;
    		} else {	// "image" is the default
    			if (modRewrite) {
    				path = webPath+"/"+albumUrl+"/"+imageUrl
    			} else {
    				path = webPath+"/index.php?album="+albumUrl+"&amp;image="+imageUrl
    			}
    			imageHTML += path;
    		}
    		imageHTML += '">';
    	}
    	if (whatValue=="title") {
    		imageHTML += imageName;
    	} else if (whatValue=="custom" && form.what_custom_text.value!="") {
    		imageHTML += form.what_custom_text.value;
    	} else if (whatValue=="album") {
    		imageHTML += albumName;
    	} else {	// "thumb" is the default
    		if (modRewrite && sizeValue!="custom") {
    			// ZenPhoto's mod_rewrite does not support custom size!
    			path = webPath+"/"+albumUrl+"/image/";
    			if (sizeValue!="full") {
    				path += "thumb/"
    			}
    			path += imageUrl
    		} else {
    			path = webPath+"/zen/i.php?a="+albumUrl+"&amp;i="+imageUrl;
    			if (sizeValue!="full" && sizeValue!="custom") {
    				path += "&amp;s=thumb";
    			} else if (sizeValue=="custom") {
    				path += "&amp;w="+customWidth+"&amp;h="+customHeight;
    			}
    		}
    		imageStyle = '';
    		imageClass = 'ZenPress_thumb ';
    		
    		if (wrapValue!="none") {
    			imageStyle += 'float:'+wrapValue+'; ';
    			imageClass += 'ZenPress_'+wrapValue+' ';
    		}
    		styleAttr = '';
    		if (imageStyle!='') {
    			styleAttr = 'style="'+imageStyle+'"';
    		}
    		imageHTML += '<img class="'+imageClass+'" alt="'+imageName+'" title="'+imageName+'" src="'+path+'" '+styleAttr+' />';
    	}
    	if (linkValue!="none") {
    		imageHTML += '</a>';
    	}
    
    	if(window.tinyMCE) {
    		window.opener.tinyMCE.execCommand("mceInsertContent",true,imageHTML);
    	} else {
    		this.insertAtCursor(window.opener.document.forms["post"].elements["content"],imageHTML);
    	}
    	
    	if (closeValue!="false") {
    		window.close();
    	}
    }
    
    Code (markup):
     
    onetr1p, Mar 20, 2007 IP
  4. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #4
    IMHO you're trying to make a wrong url.
    Instead of

    <a href="http://www.domain.com/albums/cars/ferrari.jpg rel="lightbox"/>

    You should try to make this:

    <a href="http://www.domain.com/albums/cars/ferrari.jpg" rel="lightbox"/>


    You can go here for syntax of the LINK <a> element: http://www.w3.org/TR/html401/struct/links.html#edef-LINK
     
    ajsa52, Mar 20, 2007 IP
  5. onetr1p

    onetr1p Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You are right, I got sloppy with the syntax. But I still wouldn't know how to do it. I have no knowledge in any programming. I'm just trying to modify a wordpress plugin to do what I want it to.
     
    onetr1p, Mar 20, 2007 IP
  6. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #6
    Here you go, use the following code, it it shud work

    
    
    /**
     * Class declaration
     */
    function ZenpressPopup() {
    };
     
     /**
      * Insert an image in the text editor
      * @param imageId	Id of the image (not used yet)
      * @param imageUrl	Filename of the image
      * @param imageName	Name (title) of the image
      */
    ZenpressPopup.prototype.insertImage = function(imageId,imageUrl,imageName) {
    	form = this.getEl('options');
    	whatValue = this.getRadioValue(form.what);
    	linkValue = this.getRadioValue(form.link);
    	closeValue = this.getRadioValue(form.close);
    	wrapValue = this.getRadioValue(form.wrap);
    	sizeValue = this.getRadioValue(form.size);
    	modRewrite = form.mod_rewrite.value;
    	webPath = form.zp_web_path.value;
    	albumUrl = form.album_url.value;
    	albumName = form.album_name.value;
    	customWidth = form.custom_width.value;
    	customHeight = form.custom_height.value;
    	
    	imageHTML = "";
    	
    	if (linkValue!="none") {
    		imageHTML += '<a rel="lightbox" href="';
    		if (linkValue=="album") {
    			if (modRewrite) {
    				path = webPath+"/"+albumUrl;
    			} else {
    				path = webPath+"/index.php?album="+albumUrl;
    			}
    			imageHTML += path;
    		} else if (linkValue=="custom" && form.link_custom_url.value!="") {
    			imageHTML += form.link_custom_url.value;
    		} else {	// "image" is the default
    			if (modRewrite) {
    				path = webPath+"/"+albumUrl+"/"+imageUrl
    			} else {
    				path = webPath+"/index.php?album="+albumUrl+"&amp;image="+imageUrl
    			}
    			imageHTML += path;
    		}
    		imageHTML += '">';
    	}
    	if (whatValue=="title") {
    		imageHTML += imageName;
    	} else if (whatValue=="custom" && form.what_custom_text.value!="") {
    		imageHTML += form.what_custom_text.value;
    	} else if (whatValue=="album") {
    		imageHTML += albumName;
    	} else {	// "thumb" is the default
    		if (modRewrite && sizeValue!="custom") {
    			// ZenPhoto's mod_rewrite does not support custom size!
    			path = webPath+"/"+albumUrl+"/image/";
    			if (sizeValue!="full") {
    				path += "thumb/"
    			}
    			path += imageUrl
    		} else {
    			path = webPath+"/zen/i.php?a="+albumUrl+"&amp;i="+imageUrl;
    			if (sizeValue!="full" && sizeValue!="custom") {
    				path += "&amp;s=thumb";
    			} else if (sizeValue=="custom") {
    				path += "&amp;w="+customWidth+"&amp;h="+customHeight;
    			}
    		}
    		imageStyle = '';
    		imageClass = 'ZenPress_thumb ';
    		
    		if (wrapValue!="none") {
    			imageStyle += 'float:'+wrapValue+'; ';
    			imageClass += 'ZenPress_'+wrapValue+' ';
    		}
    		styleAttr = '';
    		if (imageStyle!='') {
    			styleAttr = 'style="'+imageStyle+'"';
    		}
    		imageHTML += '<img class="'+imageClass+'" alt="'+imageName+'" title="'+imageName+'" src="'+path+'" '+styleAttr+' />';
    	}
    	if (linkValue!="none") {
    		imageHTML += '</a>';
    	}
    
    	if(window.tinyMCE) {
    		window.opener.tinyMCE.execCommand("mceInsertContent",true,imageHTML);
    	} else {
    		this.insertAtCursor(window.opener.document.forms["post"].elements["content"],imageHTML);
    	}
    	
    	if (closeValue!="false") {
    		window.close();
    	}
    }
    
    
    
    Code (markup):
     
    designcode, Mar 20, 2007 IP
  7. onetr1p

    onetr1p Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks a lot, it worked perfectly.
     
    onetr1p, Mar 20, 2007 IP
  8. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #8
    so wanna add to my rep ;)
     
    designcode, Mar 20, 2007 IP
  9. onetr1p

    onetr1p Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I just did, thanks.
     
    onetr1p, Mar 20, 2007 IP