Hi

I simply would like to be able to hide/show blocks depending on screen size, so, a different block will be displayed when, for example, someone views website via a smartphone, or iPad.

I am sure this is possible, possibly in conjunction with Delta and Context, but not sure exactly how to achieve this.

If anyone can offer advice/guidance that would be great.

Matt

Comments

5n00py’s picture

The easy solution is disable some blocks via css in global.css (display:none) and re-enable it narrow css file .

okeedoak’s picture

Mobile Tools, when ready for D7, would seem to offer a better solution. Or AdaptiveTheme right now.

mattys’s picture

i'm not keen to disable via css because, as far as i am aware, the code is still there, just hidden, so, this could effect download speed, especially for mobile devices, smart phones, etc.

mobile tools doesn't have a D7 version for production so will have to give that a miss, but adaptive looks worth trying

thanks for input

js’s picture

@mattys also, I am not sure if a Google ad would still be rendered in a block that is hidden.

In my case with Omega, I would like to change eliminate the sidebar and make the content full width for the narrow theme. I should be able to do this with template files and CSS, but it would be ideal if the theme would switch the number of columns used for the regions.

With my limited experience with Omega, it seems awkward for working with something that is a fixed width in the sidebar, such as an advertisement or certain views.

mattys’s picture

I did some snooping, but its inconclusive as to whether a block of code hidden via display:none would still load, thus effect load times, especially for mobile... if anyone has any input RE this would love to hear, or an alternative to showing/hiding content based on screen size.

js - i guess you would like to hide a region based on screen size, that would be good to know too, especially if not via display:none

TelFiRE’s picture

Delta/context is for grabbing information about where you are on the site, not how big the browser is. That's what media queries are for. The right way to do this is simply write different CSS rules in your different style sheets.

Regarding whether things load on display:none, the short answer is yes, they do load. But truly it depends on the browser. One thing that holds true for almost every browser is that image backgrounds of child elements will not be downloaded. For example, if #mydiv has a background and display none, it will still load the background. But if I wrap #mydiv in #mywrap and do the display none on #mywrap instead, most browsers will not download the background of #mydiv unless/until #mywrap is shown.

I don't know the best-integrated solution for handling this more legitimately, but I would imagine it has something to do with using Drupal Image Styles to dynamically create smaller versions and serve them based on what stylesheet is loaded.

js’s picture

@Telfire, I don't agree that the "right way" is to use media queries and CSS exclusively. When working with a site where performance matters, to me, it makes sense to make media queries from code at times; such as not rendering a view for a right column that will not be displayed. But working though this issue on a current site, I would also like to render alternate views for the content for the narrow displays. You experience likely varies from mine, as I do appreciate what you can accomplish with CSS alone.

mattys’s picture

so, to summarise, the only way to show/hide content based on screen size is using css, nothing via UI

hmmm...

koppie’s picture

Status: Active » Closed (duplicate)

(post removed by user)

koppie’s picture

Status: Closed (duplicate) » Active
TelFiRE’s picture

Js, no, there's no reason to use anything but CSS for what the op asked:

"I simply would like to be able to hide/show blocks depending on screen size,"

That's what I was answering. In terms of actually moving the markup to a different place, that's a completely different issue/question, once which I don't know the answer to and am also attempting to find a good solution for.

And matt, of course there's no UI way to do a simple display:none. If you don't know CSS you shouldn't be using Omega. That's the most fundamental, core necessary skill required to develop a theme, and this is a base theme for developers, not a consumer theme. If you want something that you can just change the colors with a web UI, go for some pre-conceived theme that is already close to what you want, and is made for consumers not developers, as you will most definitely need CSS to use Omega.

mattys’s picture

Telfire - i know css, i was referring to ability to hide blocks, etc. using UI (not adding display:none via css)

TelFiRE’s picture

It's not a feature that would make sense to add. It's one line of CSS to do what you're asking. For what reason would you need a UI. Sounds like this should be marked "works as designed" but I'll leave that to someone else.

mattys’s picture

I know it takes one line to do what i ask, but, i asked if the code you display:none for is still loaded, general consensus was yes, it is still loaded, so, there must be some performance draw backs, especially for mobile devices, especially if it is a large chunk of code, so, this is why i then asked if there was anything in UI that could make blocks, sections, etc. hide, or appear depending on screen size, after all, there is plenty other stuff. Obviously there isn't, so, i have to decide whether display:none loaded code will effect performance before I go ahead and use module in production

mattys’s picture

Status: Active » Closed (works as designed)
Anandyrh’s picture

As we have screen size numeric data stored in each and every delta, we could develop another supporting module just like 'Context' to disable blocks based on the specified screen sizes. The UI for this module can be as simple as the current admin block UI (i.e.admin/structure/block). Where the sizes will become tabs and within each tab there list of all blocks with disable and enable option as a dropdown, so that we can have control over disabling and enabling the block based on sizes, and it also help websites load time on smaller devices.

This was just my thoughts after reading all the comments on top. Just because I too wanted to do the same.

Thanks,
Anand

swfindlay’s picture

I would like to see this as well - use case: extra features on desktop site (e.g. Facebook images, comment boxes etc), and strip these away for mobile as they can significantly impact slow download speeds.

I've tried combining PHP and Javascript in the "Pages on which this PHP code returns true" option, but not with any success as yet...

5t4rdu5t’s picture

I think the answer to this question is https://drupal.org/project/context_breakpoint. It has complications of its own though, such as requiring Javascript and cookies to be enabled, need to use auto-reload feature for testing different resolutions in your browser, and caching implications which are explained on the README.txt.

jsidigital’s picture

5t4rdu5t,
Did you get context_breakpoint to work for this?

Also, even if there was a solution to this. How would cache be affected?
We are using Varnish, Memcache & APC. Would there be any problems with the cache? If the page cached is a mobile version, what happens when a user using full width screen sees it? Will the cache be of the mobile only? To avoid problems with cache, is the css format the best option?

Anybody figure this out?

FranCarstens’s picture

Issue summary: View changes

I have the same problem. Enabling cache also caches the position of blocks (using blocks & omega) in context. Effectively preventing me from using cache at all.