JSFiddle - React, Tailwind, and code Playground
by jquery4u
JavaScript
/*!
jQuery Window Resize plugin Template
@name jquery.windowResize.js
@author Christoph Ono ([email protected] or @gbks)
@author Sebastian Helzle ([email protected] or @sebobo)
@author Sam Deering ([email protected] or @jquery4u)
@version 1.0
@date 08/04/2013
@category jQuery Plugin
@copyright (c) 2009-2013 Christoph Ono (wookmark.com)
@copyright (c) 2013 Sam Deering (samdeering.com)
@license Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
(function($){
var windowResize, defaultOptions, __bind;
__bind = function(fn, me) {
return function() {
return fn.apply(me, arguments);
};
};
// Plugin default options.
defaultOptions = {
autoResize: true,
resizeDelay: 50
};
windowResize = (function(options) {
function windowResize(handler, options) {
this.handler = handler;
// Plugin variables.
this.resizeTimer = null;
// Extend default options.
$.extend(true, this, defaultOptions, options);
// Bind methods.
this.update = __bind(this.update, this);
this.onResize = __bind(this.onResize, this);
this.clear = __bind(this.clear, this);
// Listen to resize event if requested.
if (this.autoResize) {
$(window).bind('resize.windowResize', this.onResize);
};
};
// Method for updating the plugins options.
windowResize.prototype.update = function(options) {
$.extend(true, this, options);
};
// This timer ensures that layout is not continuously called as window is being dragged.
windowResize.prototype.onResize = function() {
clearTimeout(this.resizeTimer);
this.resizeTimer = setTimeout(this.resizeFunc, this.resizeDelay);
};
// Example API function.
windowResize.prototype.resizeFunc = function() {
//...do something when window is resized
};
// Clear event listeners and time outs.
windowResize.prototype.clear = function() {
...