Durandal binds view model to view before it has attached, and when you try to check element sizes using jquery it always returns 0. That's because jQuery can't get correct sizes of element which is invisible or is in invisible container.
My binding handler, which limits text with some number of lines and replaces remaining text with ellipsis, is not working when durandal is binding page, but works after second updates, when element is visible
ko.bindingHandlers.ellipsis = {
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
ko.bindingHandlers.text.update(element, valueAccessor);
var lines = allBindings.get('lines');
var $element = $(element);
var lineHeight = 1.3;
var heigth = lines * (+$element.css('font-size').substr(0, 2)) * lineHeight;
while ($element.outerHeight() > heigth) {
$element.text(replaceLast);
}
function replaceLast(index, text) {
return text.replace(/\W*\s(\S)*$/, '...');
}
}
};
I had this problem also when I used jQuery.customSelect through binding handler and when I used it through binding callback manually