Skip to content
Permalink
Browse files

Resizable: Remove uses of self var; use that var.

  • Loading branch information
scottgonzalez committed May 9, 2012
1 parent 8fcf7ea commit 84c8ba014e4dc51d136d8a8856f6f88bb1a6f2ad
Showing with 93 additions and 93 deletions.
  1. +93 −93 ui/jquery.ui.resizable.js
@@ -37,7 +37,7 @@ $.widget("ui.resizable", $.ui.mouse, {
},
_create: function() {

var self = this, o = this.options;
var that = this, o = this.options;
this.element.addClass("ui-resizable");

$.extend(this, {
@@ -158,11 +158,11 @@ $.widget("ui.resizable", $.ui.mouse, {

//Matching axis name
this._handles.mouseover(function() {
if (!self.resizing) {
if (!that.resizing) {
if (this.className)
var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
//Axis, default = se
self.axis = axis && axis[1] ? axis[1] : 'se';
that.axis = axis && axis[1] ? axis[1] : 'se';
}
});

@@ -174,13 +174,13 @@ $.widget("ui.resizable", $.ui.mouse, {
.hover(function() {
if (o.disabled) return;
$(this).removeClass("ui-resizable-autohide");
self._handles.show();
that._handles.show();
},
function(){
if (o.disabled) return;
if (!self.resizing) {
if (!that.resizing) {
$(this).addClass("ui-resizable-autohide");
self._handles.hide();
that._handles.hide();
}
});
}
@@ -276,7 +276,7 @@ $.widget("ui.resizable", $.ui.mouse, {

//Increase performance, avoid regex
var el = this.helper, o = this.options, props = {},
self = this, smp = this.originalMousePosition, a = this.axis;
that = this, smp = this.originalMousePosition, a = this.axis;

var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
var trigger = this._change[a];
@@ -314,22 +314,22 @@ $.widget("ui.resizable", $.ui.mouse, {
_mouseStop: function(event) {

this.resizing = false;
var o = this.options, self = this;
var o = this.options, that = this;

if(this._helper) {
var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
soffsetw = ista ? 0 : self.sizeDiff.width;
soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
soffsetw = ista ? 0 : that.sizeDiff.width;

var s = { width: (self.helper.width() - soffsetw), height: (self.helper.height() - soffseth) },
left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
var s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) },
left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;

if (!o.animate)
this.element.css($.extend(s, { top: top, left: left }));

self.helper.height(self.size.height);
self.helper.width(self.size.width);
that.helper.height(that.size.height);
that.helper.width(that.size.width);

if (this._helper && !o.animate) this._proportionallyResize();
}
@@ -547,7 +547,7 @@ $.widget("ui.resizable", $.ui.mouse, {
$.ui.plugin.add("resizable", "alsoResize", {

start: function (event, ui) {
var self = $(this).data("resizable"), o = self.options;
var that = $(this).data("resizable"), o = that.options;

var _store = function (exp) {
$(exp).each(function() {
@@ -568,11 +568,11 @@ $.ui.plugin.add("resizable", "alsoResize", {
},

resize: function (event, ui) {
var self = $(this).data("resizable"), o = self.options, os = self.originalSize, op = self.originalPosition;
var that = $(this).data("resizable"), o = that.options, os = that.originalSize, op = that.originalPosition;

var delta = {
height: (self.size.height - os.height) || 0, width: (self.size.width - os.width) || 0,
top: (self.position.top - op.top) || 0, left: (self.position.left - op.left) || 0
height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
},

_alsoResize = function (exp, c) {
@@ -605,34 +605,34 @@ $.ui.plugin.add("resizable", "alsoResize", {
$.ui.plugin.add("resizable", "animate", {

stop: function(event, ui) {
var self = $(this).data("resizable"), o = self.options;
var that = $(this).data("resizable"), o = that.options;

var pr = self._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
soffsetw = ista ? 0 : self.sizeDiff.width;
var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
soffsetw = ista ? 0 : that.sizeDiff.width;

var style = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) },
left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
var style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;

self.element.animate(
that.element.animate(
$.extend(style, top && left ? { top: top, left: left } : {}), {
duration: o.animateDuration,
easing: o.animateEasing,
step: function() {

var data = {
width: parseInt(self.element.css('width'), 10),
height: parseInt(self.element.css('height'), 10),
top: parseInt(self.element.css('top'), 10),
left: parseInt(self.element.css('left'), 10)
width: parseInt(that.element.css('width'), 10),
height: parseInt(that.element.css('height'), 10),
top: parseInt(that.element.css('top'), 10),
left: parseInt(that.element.css('left'), 10)
};

if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });

// propagating resize, and updating values for each animation step
self._updateCache(data);
self._propagate("resize", event);
that._updateCache(data);
that._propagate("resize", event);

}
}
@@ -644,17 +644,17 @@ $.ui.plugin.add("resizable", "animate", {
$.ui.plugin.add("resizable", "containment", {

start: function(event, ui) {
var self = $(this).data("resizable"), o = self.options, el = self.element;
var that = $(this).data("resizable"), o = that.options, el = that.element;
var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
if (!ce) return;

self.containerElement = $(ce);
that.containerElement = $(ce);

if (/document/.test(oc) || oc == document) {
self.containerOffset = { left: 0, top: 0 };
self.containerPosition = { left: 0, top: 0 };
that.containerOffset = { left: 0, top: 0 };
that.containerPosition = { left: 0, top: 0 };

self.parentData = {
that.parentData = {
element: $(document), left: 0, top: 0,
width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
};
@@ -665,70 +665,70 @@ $.ui.plugin.add("resizable", "containment", {
var element = $(ce), p = [];
$([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });

self.containerOffset = element.offset();
self.containerPosition = element.position();
self.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
that.containerOffset = element.offset();
that.containerPosition = element.position();
that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };

var co = self.containerOffset, ch = self.containerSize.height, cw = self.containerSize.width,
var co = that.containerOffset, ch = that.containerSize.height, cw = that.containerSize.width,
width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);

self.parentData = {
that.parentData = {
element: ce, left: co.left, top: co.top, width: width, height: height
};
}
},

resize: function(event, ui) {
var self = $(this).data("resizable"), o = self.options,
ps = self.containerSize, co = self.containerOffset, cs = self.size, cp = self.position,
pRatio = self._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = self.containerElement;
var that = $(this).data("resizable"), o = that.options,
ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position,
pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement;

if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;

if (cp.left < (self._helper ? co.left : 0)) {
self.size.width = self.size.width + (self._helper ? (self.position.left - co.left) : (self.position.left - cop.left));
if (pRatio) self.size.height = self.size.width / self.aspectRatio;
self.position.left = o.helper ? co.left : 0;
if (cp.left < (that._helper ? co.left : 0)) {
that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
if (pRatio) that.size.height = that.size.width / that.aspectRatio;
that.position.left = o.helper ? co.left : 0;
}

if (cp.top < (self._helper ? co.top : 0)) {
self.size.height = self.size.height + (self._helper ? (self.position.top - co.top) : self.position.top);
if (pRatio) self.size.width = self.size.height * self.aspectRatio;
self.position.top = self._helper ? co.top : 0;
if (cp.top < (that._helper ? co.top : 0)) {
that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
if (pRatio) that.size.width = that.size.height * that.aspectRatio;
that.position.top = that._helper ? co.top : 0;
}

self.offset.left = self.parentData.left+self.position.left;
self.offset.top = self.parentData.top+self.position.top;
that.offset.left = that.parentData.left+that.position.left;
that.offset.top = that.parentData.top+that.position.top;

var woset = Math.abs( (self._helper ? self.offset.left - cop.left : (self.offset.left - cop.left)) + self.sizeDiff.width ),
hoset = Math.abs( (self._helper ? self.offset.top - cop.top : (self.offset.top - co.top)) + self.sizeDiff.height );
var woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width ),
hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );

var isParent = self.containerElement.get(0) == self.element.parent().get(0),
isOffsetRelative = /relative|absolute/.test(self.containerElement.css('position'));
var isParent = that.containerElement.get(0) == that.element.parent().get(0),
isOffsetRelative = /relative|absolute/.test(that.containerElement.css('position'));

if(isParent && isOffsetRelative) woset -= self.parentData.left;
if(isParent && isOffsetRelative) woset -= that.parentData.left;

if (woset + self.size.width >= self.parentData.width) {
self.size.width = self.parentData.width - woset;
if (pRatio) self.size.height = self.size.width / self.aspectRatio;
if (woset + that.size.width >= that.parentData.width) {
that.size.width = that.parentData.width - woset;
if (pRatio) that.size.height = that.size.width / that.aspectRatio;
}

if (hoset + self.size.height >= self.parentData.height) {
self.size.height = self.parentData.height - hoset;
if (pRatio) self.size.width = self.size.height * self.aspectRatio;
if (hoset + that.size.height >= that.parentData.height) {
that.size.height = that.parentData.height - hoset;
if (pRatio) that.size.width = that.size.height * that.aspectRatio;
}
},

stop: function(event, ui){
var self = $(this).data("resizable"), o = self.options, cp = self.position,
co = self.containerOffset, cop = self.containerPosition, ce = self.containerElement;
var that = $(this).data("resizable"), o = that.options, cp = that.position,
co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement;

var helper = $(self.helper), ho = helper.offset(), w = helper.outerWidth() - self.sizeDiff.width, h = helper.outerHeight() - self.sizeDiff.height;
var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height;

if (self._helper && !o.animate && (/relative/).test(ce.css('position')))
if (that._helper && !o.animate && (/relative/).test(ce.css('position')))
$(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });

if (self._helper && !o.animate && (/static/).test(ce.css('position')))
if (that._helper && !o.animate && (/static/).test(ce.css('position')))
$(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });

}
@@ -738,56 +738,56 @@ $.ui.plugin.add("resizable", "ghost", {

start: function(event, ui) {

var self = $(this).data("resizable"), o = self.options, cs = self.size;
var that = $(this).data("resizable"), o = that.options, cs = that.size;

self.ghost = self.originalElement.clone();
self.ghost
that.ghost = that.originalElement.clone();
that.ghost
.css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
.addClass('ui-resizable-ghost')
.addClass(typeof o.ghost == 'string' ? o.ghost : '');

self.ghost.appendTo(self.helper);
that.ghost.appendTo(that.helper);

},

resize: function(event, ui){
var self = $(this).data("resizable"), o = self.options;
if (self.ghost) self.ghost.css({ position: 'relative', height: self.size.height, width: self.size.width });
var that = $(this).data("resizable"), o = that.options;
if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width });
},

stop: function(event, ui){
var self = $(this).data("resizable"), o = self.options;
if (self.ghost && self.helper) self.helper.get(0).removeChild(self.ghost.get(0));
var that = $(this).data("resizable"), o = that.options;
if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0));
}

});

$.ui.plugin.add("resizable", "grid", {

resize: function(event, ui) {
var self = $(this).data("resizable"), o = self.options, cs = self.size, os = self.originalSize, op = self.originalPosition, a = self.axis, ratio = o._aspectRatio || event.shiftKey;
var that = $(this).data("resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis, ratio = o._aspectRatio || event.shiftKey;
o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid;
var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1);

if (/^(se|s|e)$/.test(a)) {
self.size.width = os.width + ox;
self.size.height = os.height + oy;
that.size.width = os.width + ox;
that.size.height = os.height + oy;
}
else if (/^(ne)$/.test(a)) {
self.size.width = os.width + ox;
self.size.height = os.height + oy;
self.position.top = op.top - oy;
that.size.width = os.width + ox;
that.size.height = os.height + oy;
that.position.top = op.top - oy;
}
else if (/^(sw)$/.test(a)) {
self.size.width = os.width + ox;
self.size.height = os.height + oy;
self.position.left = op.left - ox;
that.size.width = os.width + ox;
that.size.height = os.height + oy;
that.position.left = op.left - ox;
}
else {
self.size.width = os.width + ox;
self.size.height = os.height + oy;
self.position.top = op.top - oy;
self.position.left = op.left - ox;
that.size.width = os.width + ox;
that.size.height = os.height + oy;
that.position.top = op.top - oy;
that.position.left = op.left - ox;
}
}

0 comments on commit 84c8ba0

Please sign in to comment.
You can’t perform that action at this time.