Use CachedValue objects for viewport height and width

(imported from commit f61cca77651b5e9a66db6c2a9749fe7a1e958fac)
This commit is contained in:
Zev Benjamin 2013-08-06 15:53:41 -04:00
parent 3ce318e9a1
commit 1c4a608b40
1 changed files with 9 additions and 6 deletions

View File

@ -158,15 +158,17 @@ exports.scrollTop = function viewport_scrollTop () {
};
function make_dimen_wrapper(dimen_name, dimen_func) {
dimensions[dimen_name] = new util.CachedValue({
compute_value: function () {
return dimen_func.call(jwindow);
}
});
return function viewport_dimension_wrapper() {
if (arguments.length !== 0) {
delete dimensions[dimen_name];
dimensions[dimen_name].reset();
return dimen_func.apply(jwindow, arguments);
}
if (! dimensions.hasOwnProperty(dimen_name)) {
dimensions[dimen_name] = dimen_func.call(jwindow);
}
return dimensions[dimen_name];
return dimensions[dimen_name].get();
};
}
@ -208,7 +210,8 @@ $(function () {
jwindow = $(window);
// This handler must be placed before all resize handlers in our application
jwindow.resize(function () {
dimensions = {};
dimensions.height.reset();
dimensions.width.reset();
});
});