This is the scenario: A user adds an image with the RixhTextEditor and hit publish.
I would like the image to be clickable to show a bigger version of it with fancybox. I was thinking that i could attach this in xslt by looping the content somehow?
For it to work you need to add an anchor around the img...
I don't think that XSLT will be the most proper way to achieve this. Since users with JavaScript disabled won't benefit from the gallery anyway it should be fairly easy to achive this using Jquery.
I don't know if you have a class or an id for the content in your webpage like
RTE content goes here...
But asuming that you do I think you should be able to write something like this...(from the top of my head).
$('#content img').each(function(){
var imgSrc = $(this).attr('src').text();
$('').insertBefore($this);$('').insertAfter($this);
});
I'm not sure this will work straight away, probably some typos in there but I hope you get the idea? :-)
We use macro's for this, we have created 2 XSLT files:
* one that expects you to select an image in the media section, and you get a input dialog for desired width & height of the thumbnail
* one that expects a folder in the mediaselection to be selected (contentpicker) and loops through all the images below it (creating a mini-gallery of thumbnails)
We automatically create resizes of all the images so we don't have people download large images if they don't have to.
* the way you suggest doesn't allow you to put hyperlinks on images (say you have a page with some logo's of partner websites in de page content area * you can't deny specific images to have a popup either
If you're working for a customer, this could become an issue (depends on how and where you use this javascript...
As for your script, don't you need to include this?:
Attach fancybox to images in bodyText with xslt
Hi!
This is the scenario: A user adds an image with the RixhTextEditor and hit publish.
I would like the image to be clickable to show a bigger version of it with fancybox. I was thinking that i could attach this in xslt by looping the content somehow?
I'm not completely sure how this would work, but probably you could do it with
The best would be to control the situation a bit more. Fx add a mediapicker-datatype (set it to advanced) or the upload-datatype.
Hi froad
For it to work you need to add an anchor around the img...
I don't think that XSLT will be the most proper way to achieve this. Since users with JavaScript disabled won't benefit from the gallery anyway it should be fairly easy to achive this using Jquery.
I don't know if you have a class or an id for the content in your webpage like
But asuming that you do I think you should be able to write something like this...(from the top of my head).
I'm not sure this will work straight away, probably some typos in there but I hope you get the idea? :-)
/Jan
Argh...the code formatting was messed up...
The code
$('#content img').each(function(){
var imgSrc = $(this).attr('src').text();
$('<a rel="fancybox" href="/forum/'& imgSrc &'">').insertBefore($this);</a>
<a rel="fancybox" href="/forum/& imgSrc &">$('</a>').insertAfter($this);
});
/Jan
Thx!
One more thing... I would like to show the small image as clickable but a bigger version when clicked; image_400.jpg.
Im no js-guru, could the imagename be splitted like we do in xslt to get the bigger image..?
Yes that should be possible. If you know that all images are fixed with the ending "_400.jpg
You should be able to do something like this...
$('#content img').each(function(){
var imgSrc = $(this).attr('src').text();
var imgName = imgSrc.split('.');
$('<a rel="fancybox" href="'& imgName[0] &'_400.jpg">').insertBefore($this);
<a rel="fancybox" href="/forum/& imgSrc &">$('</a>').insertAfter($this);
});
Hope this helps...
/Jan
Argh...really having trouble with the formatting of the code. THIS should be correct without any typos etc.
$('#content img').each(function(){
var imgSrc = $(this).attr('src').text();
var imgName = imgSrc.split('.');
$('<a rel="fancybox" href="'& imgName[0] &'_400.jpg">').insertBefore($this);
$('</a>').insertAfter($this);
});
Thx, Jan.
I reeeeealy like you :)
You're welcome. Hope that it works...otherwise let me know and we will get it to work ;-)
/Jan
Theres something fishy with this line:
I cant find the error, can you?
We use macro's for this, we have created 2 XSLT files:
* one that expects you to select an image in the media section, and you get a input dialog for desired width & height of the thumbnail
* one that expects a folder in the mediaselection to be selected (contentpicker) and loops through all the images below it (creating a mini-gallery of thumbnails)
We automatically create resizes of all the images so we don't have people download large images if they don't have to.
A walkthrough (this was made for 4.0.3 - DOES NOT WORK FOR 4.5):
<script type="text/javascript" src="/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.fancybox-1.3.0.pack.js"></script>
<script type="text/javascript" src="/scripts/jquery.easing.1.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
'titlePosition' : 'over'
});
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="bigW" select="700"/>
<xsl:variable name="bigH" select="700"/>
<xsl:variable name="imageFolder" select="/macro/imageFolder/node/@id"/>
<xsl:variable name="images" select="umbraco.library:GetMedia($imageFolder, 1)" />
<xsl:if test="count($images/node) > 0">
<xsl:for-each select="$images/node">
<xsl:if test="./data[@alias = 'umbracoExtension'] = 'gif' or ./data[@alias = 'umbracoExtension'] = 'jpg' or ./data[@alias = 'umbracoExtension'] = 'jpeg' or ./data[@alias = 'umbracoExtension'] = 'png'">
<a title="{@ImgDescription}">
<xsl:attribute name= "class">fancybox gallery</xsl:attribute>
<xsl:attribute name= "rel">group</xsl:attribute>
<xsl:choose>
<xsl:when test="./data[@alias = 'umbracoWidth'] > ./data[@alias = 'umbracoHeight']">
<xsl:attribute name= "href">/umbraco/imageGen.aspx?image=<xsl:value-of select="./data[@alias = 'umbracoFile']" />&width=<xsl:value-of select="$bigW"/>&constrain=true</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name= "href">/umbraco/imageGen.aspx?image=<xsl:value-of select="./data[@alias = 'umbracoFile']" />&height=<xsl:value-of select="$bigH"/>&constrain=true</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:if>
</xsl:template>
The solution with macro is ok, but then you miss the preview of the image and the layout in the editor gets messed up.
Im trying the javascript solution but I still get error.
Ive added this to the bottom of my document. The browser complains on the 3rd row: "Object doesn't support this property or method"
keep in mind that
* the way you suggest doesn't allow you to put hyperlinks on images (say you have a page with some logo's of partner websites in de page content area
* you can't deny specific images to have a popup either
If you're working for a customer, this could become an issue (depends on how and where you use this javascript...
As for your script, don't you need to include this?:
Also get rid of the .txt() after src
Thx!
What do you mean with it doesnt allow to put hyperlink to an image?
I finalyy made the code not to produce an error but the insertbefore and after doesnt seem to work:
>> "What do you mean with it doesnt allow to put hyperlink to an image?"
You can't put a logo in the page content area and have it link to an external/internal page or website
Im still wrestling with this problem.
Now I at least get some rendering with this code:
The problem is that the .insertAfter doesnt work as I want. The output looks like this:
As you see the </a> is not inserted after.
Why?
Finally solved it:
is working on a reply...