Responsive web design
This example shows how to make responsive web design. You will need to bundle foundation-rails gem so add this line to your Gemfile:
You will also need to add this two lines to your application.js file:
$(document).foundation();
and this to your application.css file:
I don't recommend adding this lines to cms.js and cms.css. They will make havok to data entry forms ;-)
Lets look at design template which would normally be defined in dc_site.design field.
id='meni-site' class='small-block-grid-3'
<%= dc_render(:dc_simple_menu, name: 'meni-site', method: 'as_responsive') %>
class="site-top picture-top"
src="/files/logos/top-bg-pic.jpg"
id="page" class="row"
id="div-main" class="small-12 large-7 columns"
class="show-for-medium-down" style="padding: 10px;" <%= dc_render (:responsive, method: 'i_move') %>
[main]
id="div-right" class="small-12 large-5 columns"
class="show-for-medium-up"<%= dc_render(:responsive, method: 'i_move') %>
<%= dc_render(:responsive, method: 'roller') %>
class="na-mailing"<%= dc_render(:dc_poll, poll_id: 'mail-subscribe') %>
class="na-mailing"<%= dc_render(:responsive, method: 'send_mail') %>
id="site-footer"
<%= dc_render(:dc_piece, id: 'site-footer') %>
<%= dc_render(:responsive, method: 'eu_cookies') %>
<%= dc_render(:dc_common, method: 'google_analytics') %>
Lets look at the design step by step. At top we have small menu which is rendered by DcSimpleMenu.as_responsive method.
id='site-menu' class='small-block-grid-3'
<%= dc_render(:dc_simple_menu, name: 'site-menu', method: 'as_responsive') %>
Below menu there is a huge (1280x480) picture, which is automatically resized when screen size gets smaller.
src="/files/logos/top-pic.jpg"
text-align: center;
position: relative;
height: 0;
overflow: hidden;
}
.picture-top { padding-bottom:37.5%; }
Continue to central part of site which is divided into two parts. div-main for displaying main page data and div-right which is used for interacting with users, showing ads etc.
Main part also has part which is shown only on phones. This part is rendered by Responsive.i_move method.
id="div-main" class="small-12 large-7 columns"
class="show-for-medium-down" style="padding: 10px;"<%= dc_render(:responsive, method: 'i_move') %>
[main]
[main] string is replaced by code defined in design document and looks like this.
<%= dc_replace_in_design(replace: '[main]', with: main) %>
Responsive.all_documents collect all available documents and display them in main part of site.
The right div of the site center has four parts. They will move to bottom when displayed on phone.
class="show-for-medium-up"<%= dc_render(:responsive, method: 'i_move') %>
<%= dc_render(:responsive, method: 'roller') %>
class="na-mailing"<%= dc_render(:dc_poll, poll_id: 'subscribe') %>
class="na-mailing" <%= dc_render(:responsive, method: 'send_mail') %>
First part is show only when screen size is large enough.
Roller method will prepare ads pictures, which will scroll with a help of slick http://kenwheeler.github.io/slick/ javascript library.
Mail subscribe is a simple poll which only asks for entering e-mail address and calls ResponsiveController.subscribe action to save address to internal database intended for news subscribers.
Responsive.send_mail again prepares mail_to link which visitor may use to send ideas to site owners.
At the bottom of page there is a site-footer div which is saved in dc_piece collection name 'site-footer' document.
<%= dc_render(:dc_piece, id: 'site-footer') %>
<%= dc_render(:responsive, method: 'eu_cookies') %>
<%= dc_render(:dc_common, method: 'google_analytics') %>
And finally there is google_analytics token and div which informs user about Euro cookies law, which must be implemented in Europe if site uses google_analytics.