View source
<?php
$plugin = array(
'title' => t('Lazy pane'),
'cache get' => 'lazy_pane_lazy_cache_get',
'cache set' => 'lazy_pane_lazy_cache_set',
'cache clear' => 'lazy_pane_lazy_cache_clear',
'settings form' => 'lazy_pane_lazy_cache_settings_form',
'defaults' => array(
'load_strategy' => 'page-loaded',
'load_text' => '',
'show_spinner' => FALSE,
),
);
function lazy_pane_lazy_cache_get($conf, $display, $args, $contexts, $pane = NULL) {
$cache_expiry = CACHE_PERMANENT;
$lazy_pane_id = lazy_pane_lazy_id($display, $pane);
$data = array(
'conf' => $conf,
'display' => $display,
'args' => $args,
'contexts' => $contexts,
'pane' => $pane,
'path' => current_path(),
);
cache_set($lazy_pane_id, $data, 'cache', $cache_expiry);
if (!lazy_pane_is_lazy_request()) {
$module_path = drupal_get_path('module', 'lazy_pane');
drupal_add_library('system', 'drupal.ajax');
drupal_add_js($module_path . '/js/lazy-pane.js');
drupal_add_css($module_path . '/css/lazy-pane.css');
$settings = array(
'lazy_pane' => array(
'current_path' => current_path(),
),
);
drupal_add_js($settings, 'setting');
}
$attr = array(
'class' => 'lazy-pane-placeholder',
'data-lazy-pane-id' => $lazy_pane_id,
'data-lazy-pane-load-strategy' => $conf['load_strategy'],
);
$placeholder_contents = '';
if (!empty($conf['show_spinner'])) {
$placeholder_contents .= '<span class="lazy-pane-spinner"></span>';
}
if (!empty($conf['load_text'])) {
$placeholder_contents .= '<p class="lazy-pane-text">' . check_plain(ctools_context_keyword_substitute($conf['load_text'], array(), $contexts)) . '</p>';
}
$fake_content = new stdClass();
$fake_content->type = empty($pane) ? '' : $pane->type;
$fake_content->subtype = empty($pane) ? '' : $pane->subtype;
$fake_content->content = '<div ' . drupal_attributes($attr) . '>' . $placeholder_contents . '</div>';
$fake_cache = new lazy_pane_lazy_cache_object();
$fake_cache->content = $fake_content;
if (empty($pane)) {
$fake_cache->content = $fake_content->content;
}
return $fake_cache;
}
function lazy_pane_lazy_cache_settings_form($conf, $display, $pid) {
$form = array();
$form['load_strategy'] = array(
'#title' => t('Load this pane when'),
'#type' => 'select',
'#options' => array(
'page-loaded' => t('The page has loaded'),
'pane-visible' => t('The pane becomes visible'),
),
'#default_value' => $conf['load_strategy'],
'#description' => t('The "Pane becomes visible" loading strategy may not work always, as it depends on external factors to the module such as CSS positioning/display rules on the theme.'),
);
$form['show_spinner'] = array(
'#title' => t('Show Spinner'),
'#type' => 'checkbox',
'#default_value' => $conf['show_spinner'],
'#description' => t('If set the placeholder will show a loading spinner.'),
);
$form['load_text'] = array(
'#title' => t('Loading Text'),
'#type' => 'textfield',
'#default_value' => $conf['load_text'],
'#description' => t('If set, the inserted text will be shown on the placeholder while loading. This text is localizable and supports replacement patterns.'),
'#maxlength' => 256,
);
return $form;
}
function lazy_pane_lazy_cache_set($conf, $content, $display, $args, $contexts, $pane = NULL) {
}
function lazy_pane_lazy_cache_clear($display) {
}
function lazy_pane_lazy_id($display, $pane) {
$id = array(
'lazy_pane',
);
if (!empty($display->cache_key)) {
$id[] = $display->cache_key;
}
else {
$id[] = current_path();
}
if (!empty($pane)) {
$id[] = $pane->type;
$id[] = $pane->subtype;
$id[] = $pane->pid;
$id[] = empty($pane->did) ? '' : $pane->did;
}
return implode(':', $id);
}
class lazy_pane_lazy_cache_object extends panels_cache_object {
function restore() {
}
}