Skip to content

Instantly share code, notes, and snippets.

@cmourizard
Last active December 25, 2015 02:59
Show Gist options
  • Save cmourizard/6906831 to your computer and use it in GitHub Desktop.
Save cmourizard/6906831 to your computer and use it in GitHub Desktop.
SugarCRM Subpanel lazy loadding
<?php
if (!isset($hook_array) || !is_array($hook_array)) {
$hook_array = array();
}
if (!isset($hook_array['after_ui_frame']) || !is_array($hook_array['after_ui_frame'])) {
$hook_array['after_ui_frame'] = array();
}
$hook_array['after_ui_frame'][] = array(
1,
'Lazyload',
'custom/vendor/Lazyload/LogicHooks/LazyloadLauncher.php',
'Lazyload_LogicHooks_LazyloadLauncher',
'run'
);
<?php
class Lazyload_LogicHooks_LazyloadLauncher
{
/**
* Add JS to launch Subpanel with lazyload
*
* @param string $event -- What kind of logic_hook is it (after_ui_frame, after_ui_footer...)
* @param string $arguments -- unused
* @return unknown -- No return
*/
public function run($event, $arguments)
{
if ($GLOBALS['app']->controller->action == 'DetailView') {
echo '<script type="text/javascript"">
if ( typeof(Lazyload) == \'undefined\' ) Lazyload = {};
if ( typeof(Lazyload.util) == \'undefined\' ) Lazyload.util = {};
Lazyload.util.loadVisibleSubpanel = function () {
var subPanelLayouts = SUGAR.subpanelUtils.getLayout();
for( i=0; i < subPanelLayouts.length; i++) {
var subPanelName = subPanelLayouts[i];
var position = $("#subpanel_title_"+subPanelName).offset().top;
var scllwidth = $(window).scrollTop() + $(window).height();
if ( scllwidth > position && $.inArray(subPanelName, subPanelDisplayed) == -1) {
subPanelDisplayed.push(subPanelName);
current_child_field = subPanelName;
showSubPanel(subPanelName,null,null, \'' .$GLOBALS['app']->controller->module . '\');
$(\'#show_link_\'+subPanelName).css(\'display\', \'none\');
$(\'#hide_link_\'+subPanelName).css(\'display\', \'\');
}
}
}
var subPanelDisplayed = new Array();
SUGAR.util.doWhen("typeof(SUGAR.subpanelUtils) == \'object\' && typeof(SUGAR.subpanelUtils.onDrag) == \'function\' && document.getElementById(\'subpanel_list\') && typeof($) != \'undefined\'", function() {
Lazyload.util.loadVisibleSubpanel();
$(window).scroll(Lazyload.util.loadVisibleSubpanel);
});
</script>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment