Override inline style for background image for devices
Hi, I'm using the XSLT below to grab an image from media picker to set a background image on various pages of a site. The background images are large, not in filesize, but in dimensions, i just found out that iphone 3 and below support images sizes of about 2,000,000 sq px or lower, thus not rendering our backgrounds.
So, normally to overcome this, I'd just call an iphone specific stylesheet and swap the background images there, but because i'm defining the style inline i cant. Can anyone think of a way to do this? Macro maybe? Then add an additional "mobile media picker" to the document type?
Not suggesting anyone write all this code for me, just not really sure how to work in the browser detection part and am kinda lost as to where to start...
Yeah I guess you need to create a macro to handle this. Maybe you could use ImageGen on the image so you just use the same image but specify the dimensions for the smartphone instead?
I guess you will need to use some JavaScript or some custom XSLT extension to determine the dimensions of the device accessing the site.
I'm excited to hear more about how you get this one solved :-)
Jan, I will check out ImageGen, I've actually never used it although I've read plenty about it.
So as far as detecting the browser, I can do something like this with javascript inside the document ready function:
//$("body").attr("style", "background: url(images/home_mobile.jpg");<br /> var mobileBody = "background: url('images/home.jpg') top center no-repeat;"; var standardBody = "background: url('images/home_mobile.jpg') top center no-repeat;";
Now my main question, how can that javascript be useful within a macro?
This is what I'm thinking
macro1 in header containing that javascript
macro1 calls macro mobile or macro regular based on the result of the javascript resolution detection? (or can I execute the javascript and utilize the resulting variable from the same macro?)
Pnima, this could work. My intention however was to test for resolution not User Agent so I could provide alternate content for droid, blackberry, windows mobile, etc in one process. Do you know if you can test for resolution with XSLT? I haven't been able to find any documentation on it...
I guess you will need to make something like the above but where you actually test for the resolution using javascript and then call the <xsl:value-of select="relevant-image" /> inside it.
It's not pretty but I think it's a way forward.
Do you need an example to get what I'm thinking about? :-)
Override inline style for background image for devices
Hi, I'm using the XSLT below to grab an image from media picker to set a background image on various pages of a site. The background images are large, not in filesize, but in dimensions, i just found out that iphone 3 and below support images sizes of about 2,000,000 sq px or lower, thus not rendering our backgrounds.
So, normally to overcome this, I'd just call an iphone specific stylesheet and swap the background images there, but because i'm defining the style inline i cant. Can anyone think of a way to do this? Macro maybe? Then add an additional "mobile media picker" to the document type?
Not suggesting anyone write all this code for me, just not really sure how to work in the browser detection part and am kinda lost as to where to start...
Relevent code as follow
Media picker in template:
Stylesheet ref for iPhone
I appreciate any help!
Amir
Hi Amir
Yeah I guess you need to create a macro to handle this. Maybe you could use ImageGen on the image so you just use the same image but specify the dimensions for the smartphone instead?
I guess you will need to use some JavaScript or some custom XSLT extension to determine the dimensions of the device accessing the site.
I'm excited to hear more about how you get this one solved :-)
/Jan
Jan, I will check out ImageGen, I've actually never used it although I've read plenty about it.
So as far as detecting the browser, I can do something like this with javascript inside the document ready function:
Now my main question, how can that javascript be useful within a macro?
This is what I'm thinking
Does this seem like a good way to approach it?
Thanks!
Amir
Hi Amir
Could it be done by small piece of xslt? You can detect browser in xslt. Here is a part of sample how I'm implementing...
Pnima, this could work. My intention however was to test for resolution not User Agent so I could provide alternate content for droid, blackberry, windows mobile, etc in one process. Do you know if you can test for resolution with XSLT? I haven't been able to find any documentation on it...
Thanks!
Amir
Hi Amir
I guess you will need to make something like the above but where you actually test for the resolution using javascript and then call the <xsl:value-of select="relevant-image" /> inside it.
It's not pretty but I think it's a way forward.
Do you need an example to get what I'm thinking about? :-)
/Jan
is working on a reply...