Skip to content

Commit

Permalink
Merge pull request #10 from backdrop-contrib/preview-fix
Browse files Browse the repository at this point in the history
Preview fix
  • Loading branch information
korontari committed Oct 23, 2019
2 parents 4d3557b + be51893 commit bea9633
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
5 changes: 2 additions & 3 deletions config/mosaic_grid.settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"_config_name": "mosaic_grid.settings",
"loader_style": "spinning_ring",
"loader_color": "#cccccc",
"loader_color": "#aaaaaa",
"caption_style_override": false,
"caption_font_color": "#ffffff",
"caption_opacity": 50,
"caption_font_size": 12,
"caption_padding": 10,
"show_empty_images": false,
"lazyload_enabled": true,
"lazyload_edgeY": 0
}
}
8 changes: 6 additions & 2 deletions js/mosaic_grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

for(var i in settings.mosaic_grid) {
if(i == 'lazyload') {
// In views preview force start lazyLoadXT.
if(settings.mosaic_grid.lazyload.editing){
$(window).lazyLoadXT();
}
// Configure lazyLoadXT.
$.extend($.lazyLoadXT, {
edgeY: settings.mosaic_grid.lazyload.edgeY,
Expand All @@ -25,7 +29,7 @@
itemDiv.children('.mosaic-grid-loader').remove();
}
},
});
});
}
else {
// Initiate grid on a page.
Expand All @@ -39,7 +43,7 @@
});
}
}

}
};

Expand Down
10 changes: 0 additions & 10 deletions mosaic_grid.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,6 @@ function mosaic_grid_admin_form($form, &$form_state) {
),
),
);

$form['appearance']['show_empty_images'] = array(
'#type' => 'checkbox',
'#title' => t('Show empty images'),
'#description' => t("Enable this to show empty space with warning for images
that have their file missing. By default such images are ignored and
not displayed in the grid."),
'#default_value' => $config->get('show_empty_images'),
);

$form['lazyload'] = array(
'#type' => 'fieldset',
Expand Down Expand Up @@ -177,7 +168,6 @@ function mosaic_grid_admin_form_submit($form, &$form_state) {
$config->set('caption_opacity', $form_state['values']['caption_opacity']);
$config->set('caption_padding', $form_state['values']['caption_padding']);
$config->set('caption_font_size', $form_state['values']['caption_font_size']);
$config->set('show_empty_images', $form_state['values']['show_empty_images']);
$config->set('lazyload_enabled', $form_state['values']['lazyload_enabled']);
$config->set('lazyload_edgeY', $form_state['values']['lazyload_edgeY']);

Expand Down
2 changes: 1 addition & 1 deletion mosaic_grid.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ description = Provides views style plugin for building image galleries layed out
backdrop = 1.x
package = Views
type = module
version = 1.x-2.0.1
version = 1.x-2.0.2
dependencies[] = views
configure = admin/config/media/mosaic_grid
16 changes: 13 additions & 3 deletions mosaic_grid.module
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function template_preprocess_views_view_mosaic_grid(&$vars) {
break;
}
}
elseif ($config->get('show_empty_images')) {
elseif (empty($options['hide_empty'])) {
// Fill in values needed for empty image warning display.
$items_rendered[$i] = FALSE;
$items_width[$i] = 100;
Expand Down Expand Up @@ -199,6 +199,7 @@ function template_preprocess_views_view_mosaic_grid(&$vars) {
'mosaic_grid' => array(
'lazyload' => array(
'edgeY' => $config->get('lazyload_edgeY'),
'editing' => $view->editing,
),
$mosaic_id => array (
'max_row_height' => $options['max_row_height'],
Expand Down Expand Up @@ -260,13 +261,14 @@ SPIN;
.mosaic-grid-loader:before,
.mosaic-grid-loader:after {
background: {$color_hex};
color: {$color_hex};
}
color: {$color_hex};}
SPIN;
break;
}
if($loader_css)
$loader_css = minify($loader_css);
backdrop_add_css($loader_css, array('type' => 'inline'));
$vars['loader_css'] = $loader_css;
}

// Create style overrides if caption style is set to custom.
Expand All @@ -291,12 +293,20 @@ SPIN;
}
CAP;
// Add the css as inline style sheet.
$custom_caption_css = minify($custom_caption_css);
backdrop_add_css($custom_caption_css, array('type' => 'inline'));
// Store it for template. It will be used for views preview.
$vars['custom_caption_css'] = $custom_caption_css;
}
}

/*
* Removes unnesessary symbols from code string.
*/
function minify($string){
return str_replace(array(" ", "\r", "\n"), '', $string);
}


/**
* Implements hook_preprocess_image().
Expand Down
10 changes: 6 additions & 4 deletions views-view-mosaic-grid.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

<?php if($view->editing): ?>
<style>
<?php print $custom_caption_css; ?>
<?php
print $custom_caption_css;
if($loader_css):
print $loader_css;
endif;
?>
</style>
<script>
$(window).lazyLoadXT({show: true});
</script>
<?php endif; ?>

<?php if (!empty($title)) : ?>
Expand Down
8 changes: 8 additions & 0 deletions views_plugin_style_mosaic_grid.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class views_plugin_style_mosaic_grid extends views_plugin_style {
$options['caption'] = array('default' => 'none');
$options['max_rows'] = array('default' => 0);
$options['truncate'] = array('default' => false);
$options['hide_empty'] = array('default' => true);

return $options;
}
Expand Down Expand Up @@ -85,6 +86,13 @@ class views_plugin_style_mosaic_grid extends views_plugin_style {
'#description' => t("Hide incomplete last row of items."),
'#default_value' => $this->options['truncate'],
);

$form['hide_empty'] = array(
'#type' => 'checkbox',
'#title' => t('Hide empty fields'),
'#description' => t("Do not display items that are empty."),
'#default_value' => $this->options['hide_empty'],
);
}

/**
Expand Down

0 comments on commit bea9633

Please sign in to comment.