public function views_lazy_load_plugin_display_extender::pre_execute in Views Lazy Load 7
Same name and namespace in other branches
- 8 includes/views/views_lazy_load_plugin_display_extender.inc \views_lazy_load_plugin_display_extender::pre_execute()
Set up any variables on the view prior to execution.
Overrides views_plugin_display_extender::pre_execute
File
- includes/
views/ views_lazy_load_plugin_display_extender.inc, line 12 - A display extender plugin for lazy loading a view.
Class
- views_lazy_load_plugin_display_extender
- @file A display extender plugin for lazy loading a view.
Code
public function pre_execute() {
if ($this
->isEnabled() && empty($this->view->live_preview)) {
if (!$this
->isExcludedUserAgent()) {
// Lazy loading requires an AJAX view.
$this->view
->set_use_ajax(TRUE);
// Marking the view as executed prevents the Search API querying.
$this->view->executed = TRUE;
// Add the loading text in the area plugin.
$this
->addLoadingArea();
// Add our JavaScript to the page with an array of dom_ids that can be
// used client side to retrieve the view instance.
$path = drupal_get_path('module', 'views_lazy_load');
$settings[] = $this->view->dom_id;
drupal_add_js(array(
'views_lazy_load' => $settings,
), 'setting');
drupal_add_js($path . '/js/views-lazy-load.js', array(
'scope' => 'footer',
'weight' => 10,
));
}
else {
// Ensure that AJAX won't be used if a crawler is visiting the view
$this->view
->set_use_ajax(FALSE);
}
}
}