UNPKG

chicago

Version:

A front-end JavaScript library for user-interface developers.

42 lines (39 loc) 1.21 kB
// @name: Chicago.events.resizeend // @description: Triggers an event when a user ends resizing the bound element (typically the window) // @since: 1.0.0-beta resizeend : { latency : 250, setup : function(data) { var uid = _c.utils.uid('resizeend'), _data = _c.$.extend({ latency : _c.$.event.special.resizeend.latency }, data), timer, handler = function(e) { if(timer) { win.clearTimeout(timer); } timer = win.setTimeout(function() { timer = null; var target = _c.$(e.target); return target.trigger('resizeend', [{ width : target.width(), height : target.height(), }]); }, _data.latency); }; _c.$(this).data('chicago.event.resizeend.uid', uid); _c.$(this).on('resizeend', function() { return _c.$(this).off('resize', _c.utils.debounce(handler, 100)); }); return _c.$(this).on('resizestart', function() { return _c.$(this).on('resize', _c.utils.debounce(handler, 100)).data(uid, handler); }); }, teardown : function() { var uid = _c.$(this).data('chicago.event.resizeend.uid'); _c.$(this).off('resize', _c.$(this).data(uid)); _c.$(this).removeData(uid); return _c.$(this).removeData('chicago.event.resizeend.uid'); } },