Exemplo n.º 1
0
 public function apply_breakpoints($layout)
 {
     $css = '';
     $breakpoints = $this->get_breakpoints(true);
     foreach ($breakpoints as $name => $point) {
         $this->_current_breakpoint = $point;
         $point_css = '';
         $line_height = $point->get_line_height();
         $point_css .= $point->get_frontend_rule($layout);
         $layout_view = new Upfront_Layout_View($layout);
         $point_css .= $layout_view->get_style_for($point, $this->get_grid_scope());
         $width_pfx = $point->get_prefix(Upfront_GridBreakpoint::PREFIX_WIDTH);
         foreach ($layout['regions'] as $region) {
             // Cascade defaults
             $container = !empty($region['container']) ? $region['container'] : $region['name'];
             $region['sub'] = !empty($region['sub']) ? $region['sub'] : false;
             if ($container == $region['name']) {
                 $container_view = new Upfront_Region_Container($region);
                 $point_css .= $container_view->get_style_for($point, $this->get_grid_scope());
             }
             if ($region['sub'] == 'top' || $region['sub'] == 'bottom') {
                 $sub_container_view = new Upfront_Region_Sub_Container($region);
                 $point_css .= $sub_container_view->get_style_for($point, $this->get_grid_scope());
                 $region_col = $point->get_columns();
             } else {
                 $region_col = $this->_get_property_col($region);
             }
             $region_col = $region_col ? $region_col : $this->_get_available_container_col($container, $layout['regions']);
             $region_row = $this->_get_property_row($region);
             $region_hide = $this->_get_breakpoint_data($region, 'hide');
             $region_view = new Upfront_Region($region);
             $name = strtolower(str_replace(" ", "-", $region_view->get_name()));
             $point_css .= $region_view->get_style_for($point, $this->get_grid_scope());
             $point_css .= $point->apply_col($region_col, $region, $this->get_grid_scope(), '#upfront-region-' . $name);
             if ($region_row) {
                 $point_css .= $point->apply_row($region_row, $region, $this->get_grid_scope(), '#upfront-region-' . $name);
             }
             if (!$point->is_default() && $region['sub'] == 'fixed') {
                 // @TODO we hide float region by default for responsive for now
                 $region_hide = 1;
             }
             if ($region_hide == 1) {
                 $point_css .= $point->apply_hide($region_hide, $region, $this->get_grid_scope(), '#upfront-region-' . $name);
             }
             $point_css .= $this->_apply_modules($region, $region_col);
         }
         if ($this->_debugger->is_active(Upfront_Debug::STYLE)) {
             $point_css .= $point->get_debug_rule($this->get_grid_scope());
         }
         $css .= $point->wrap($point_css, $breakpoints);
     }
     return $css;
 }
Exemplo n.º 2
0
 public function apply_layout()
 {
     $layout = $this->_layout->to_php();
     $html = '';
     $html_layout = '';
     if ($this->_debugger->is_active(Upfront_Debug::MARKUP)) {
         $html = "<!-- Code generated by Upfront core -->\n";
         $name = !empty($layout['name']) ? $layout['name'] : '';
         $html .= "<!-- Layout Name: {$name} -->\n";
     }
     $layout_view = new Upfront_Layout_View($layout);
     $region_markups = array();
     $region_markups_before = array();
     $region_markups_after = array();
     $container_views = array();
     // Construct container views first
     foreach ($layout['regions'] as $region) {
         $container = empty($region['container']) ? $region['name'] : $region['container'];
         if ($container == $region['name']) {
             $container_views[$container] = new Upfront_Region_Container($region);
         }
     }
     // Iterate through regions
     foreach ($layout['regions'] as $region) {
         $region_view = new Upfront_Region($region);
         $region_sub = $region_view->get_sub();
         $markup = $region_view->get_markup();
         $container = $region_view->get_container();
         if (!isset($region_markups[$container])) {
             $region_markups[$container] = '';
         }
         if (!isset($region_markups_before[$container])) {
             $region_markups_before[$container] = '';
         }
         if (!isset($region_markups_after[$container])) {
             $region_markups_after[$container] = '';
         }
         if ($region_sub == 'top' || $region_sub == 'bottom') {
             if (isset($container_views[$container])) {
                 $type = $container_views[$container]->get_entity_type();
                 if ($type != 'full') {
                     continue;
                 }
                 // Don't add top/bottom sub container if it's not full
             }
             $sub_container = new Upfront_Region_Sub_Container($region);
             $markup = $sub_container->wrap($markup);
             if ($region_sub == 'top') {
                 $region_markups_before[$container] .= $markup;
             } else {
                 $region_markups_after[$container] .= $markup;
             }
         } else {
             if ($region_sub == 'fixed') {
                 $region_markups_after[$container] .= $markup;
             } else {
                 if ($region_sub == 'left') {
                     $region_markups[$container] = $markup . $region_markups[$container];
                 } else {
                     $region_markups[$container] .= $markup;
                 }
             }
         }
     }
     foreach ($container_views as $container => $container_view) {
         $type = $container_view->get_entity_type();
         $html_layout .= $container_view->wrap($region_markups[$container], $region_markups_before[$container], $region_markups_after[$container]);
     }
     $html .= $layout_view->wrap($html_layout);
     if ($this->_debugger->is_active(Upfront_Debug::MARKUP)) {
         $html .= "<!-- Upfront layout end -->\n";
     }
     do_action('upfront-layout-applied', $layout);
     return $html;
 }