Execute a JS function after a JSReload


#1

Hi there,

this might be a very easy one for JS experts, but after trying around for 2 hours its obvious I need help :slight_smile:

Ok, I have a little JS that resizes a <div> with a certain class to the remaining screen height:

$(document).ready(function () {
	$(".pmg-lister").fillHeight();
});

window.onresize = function () {
	$(".pmg-lister").fillHeight();
}

$.fn.fillHeight = function () {
	var siblingsHeight = this.siblings("div.pmg-filter-container").height();
	var height = this.parent().parent().height() - siblingsHeight;
	this.height(height);
};

quite simple, works very well after page load and on window resize.
BUT: on some occasions this <div> gets reloaded by a JsReload. Not just this <div> or its content, but a parent div.
When this happens, I need to call fillHeight again to resize the <div> after it has been reloaded. And believe it or not, I am unable to make this happen :slight_smile:
Can you help me? The reload is triggered this way:

//define submit function
$middle_form->onSubmit(function() use ($region) {
	$region->save();
	$_SESSION[SMN]['id'] = $region['id'];
	return (new \atk4\ui\jQuery('.eoo-reload-all'))->trigger('eoo-reload-all');
});

and

$all_content->addClass('eoo-reload-all')->on('eoo-reload-all', new \atk4\ui\jsReload($all_content));

Thanks for your help!


#2

you can execute multiple actions by adding them into array, but in this case you need action to be triggered when reload is completed (loading time and all) and after all objects inside loaded area have been initialized.

Iā€™m not sure if such functionality exist yet, but it would make sense to have it:


#3

Hi,

the solution is awfully simple: If I add the JS to an element that gets reloaded, it works:

//everytime the lister gets reloaded, perform JS to set it to the remaining screen height
$lcl->js(true, (new atk4\ui\JsExpression('$(".pmg-lister").height($(".pmg-leftcolumn-container").height() - $(".pmg-filter-container").height())')));

Best regards
Philipp


#4

oh right :slight_smile: you can even add a GET argument for a trigger.