Skip to content

Commit

Permalink
Resizable: Moved helper methods into the widget prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed Oct 24, 2013
1 parent 8dbda00 commit b7e3e46
Showing 1 changed file with 51 additions and 50 deletions.
101 changes: 51 additions & 50 deletions ui/jquery.ui.resizable.js
Expand Up @@ -15,37 +15,6 @@
*/ */
(function( $, undefined ) { (function( $, undefined ) {


function num(v) {
return parseInt(v, 10) || 0;
}

function isNumber(value) {
return !isNaN(parseInt(value, 10));
}

function hasScroll( el, a ) {

//If overflow is hidden, the element might have extra content, but the user wants to hide it
if ( $( el ).css( "overflow" ) === "hidden") {
return false;
}

var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
has = false;

if ( el[ scroll ] > 0 ) {
return true;
}

// TODO: determine which cases actually cause this to happen
// if the element doesn't have the scroll set, see if it's possible to
// set the scroll
el[ scroll ] = 1;
has = ( el[ scroll ] > 0 );
el[ scroll ] = 0;
return has;
}

$.widget("ui.resizable", $.ui.mouse, { $.widget("ui.resizable", $.ui.mouse, {
version: "@VERSION", version: "@VERSION",
widgetEventPrefix: "resize", widgetEventPrefix: "resize",
Expand Down Expand Up @@ -73,6 +42,38 @@ $.widget("ui.resizable", $.ui.mouse, {
start: null, start: null,
stop: null stop: null
}, },

_num: function( value ) {
return parseInt( value, 10 ) || 0;
},

_isNumber: function( value ) {
return !isNaN( parseInt( value , 10 ) );
},

_hasScroll: function( el, a ) {

//If overflow is hidden, the element might have extra content, but the user wants to hide it
if ( $( el ).css( "overflow" ) === "hidden") {
return false;
}

var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
has = false;

if ( el[ scroll ] > 0 ) {
return true;
}

// TODO: determine which cases actually cause this to happen
// if the element doesn't have the scroll set, see if it's possible to
// set the scroll
el[ scroll ] = 1;
has = ( el[ scroll ] > 0 );
el[ scroll ] = 0;
return has;
},

_create: function() { _create: function() {


var n, i, handle, axis, hname, var n, i, handle, axis, hname,
Expand Down Expand Up @@ -305,8 +306,8 @@ $.widget("ui.resizable", $.ui.mouse, {


this._renderProxy(); this._renderProxy();


curleft = num(this.helper.css("left")); curleft = this._num(this.helper.css("left"));
curtop = num(this.helper.css("top")); curtop = this._num(this.helper.css("top"));


if (o.containment) { if (o.containment) {
curleft += $(o.containment).scrollLeft() || 0; curleft += $(o.containment).scrollLeft() || 0;
Expand Down Expand Up @@ -404,7 +405,7 @@ $.widget("ui.resizable", $.ui.mouse, {


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


s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) }; s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) };
Expand Down Expand Up @@ -442,10 +443,10 @@ $.widget("ui.resizable", $.ui.mouse, {
o = this.options; o = this.options;


b = { b = {
minWidth: isNumber(o.minWidth) ? o.minWidth : 0, minWidth: this._isNumber(o.minWidth) ? o.minWidth : 0,
maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity, maxWidth: this._isNumber(o.maxWidth) ? o.maxWidth : Infinity,
minHeight: isNumber(o.minHeight) ? o.minHeight : 0, minHeight: this._isNumber(o.minHeight) ? o.minHeight : 0,
maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity maxHeight: this._isNumber(o.maxHeight) ? o.maxHeight : Infinity
}; };


if(this._aspectRatio || forceAspectRatio) { if(this._aspectRatio || forceAspectRatio) {
Expand Down Expand Up @@ -474,16 +475,16 @@ $.widget("ui.resizable", $.ui.mouse, {


_updateCache: function(data) { _updateCache: function(data) {
this.offset = this.helper.offset(); this.offset = this.helper.offset();
if (isNumber(data.left)) { if (this._isNumber(data.left)) {
this.position.left = data.left; this.position.left = data.left;
} }
if (isNumber(data.top)) { if (this._isNumber(data.top)) {
this.position.top = data.top; this.position.top = data.top;
} }
if (isNumber(data.height)) { if (this._isNumber(data.height)) {
this.size.height = data.height; this.size.height = data.height;
} }
if (isNumber(data.width)) { if (this._isNumber(data.width)) {
this.size.width = data.width; this.size.width = data.width;
} }
}, },
Expand All @@ -494,9 +495,9 @@ $.widget("ui.resizable", $.ui.mouse, {
csize = this.size, csize = this.size,
a = this.axis; a = this.axis;


if (isNumber(data.height)) { if (this._isNumber(data.height)) {
data.width = (data.height * this.aspectRatio); data.width = (data.height * this.aspectRatio);
} else if (isNumber(data.width)) { } else if (this._isNumber(data.width)) {
data.height = (data.width / this.aspectRatio); data.height = (data.width / this.aspectRatio);
} }


Expand All @@ -516,8 +517,8 @@ $.widget("ui.resizable", $.ui.mouse, {


var o = this._vBoundaries, var o = this._vBoundaries,
a = this.axis, a = this.axis,
ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height), ismaxw = this._isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = this._isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height), isminw = this._isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = this._isNumber(data.height) && o.minHeight && (o.minHeight > data.height),
dw = this.originalPosition.left + this.originalSize.width, dw = this.originalPosition.left + this.originalSize.width,
dh = this.position.top + this.size.height, dh = this.position.top + this.size.height,
cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a); cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
Expand Down Expand Up @@ -678,7 +679,7 @@ $.ui.plugin.add("resizable", "animate", {
o = that.options, o = that.options,
pr = that._proportionallyResizeElements, pr = that._proportionallyResizeElements,
ista = pr.length && (/textarea/i).test(pr[0].nodeName), ista = pr.length && (/textarea/i).test(pr[0].nodeName),
soffseth = ista && hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height, soffseth = ista && that._hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height,
soffsetw = ista ? 0 : that.sizeDiff.width, soffsetw = ista ? 0 : that.sizeDiff.width,
style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) }, 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, left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null,
Expand Down Expand Up @@ -742,7 +743,7 @@ $.ui.plugin.add("resizable", "containment", {
else { else {
element = $(ce); element = $(ce);
p = []; p = [];
$([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); }); $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = that._num(element.css("padding" + name)); });


that.containerOffset = element.offset(); that.containerOffset = element.offset();
that.containerPosition = element.position(); that.containerPosition = element.position();
Expand All @@ -751,8 +752,8 @@ $.ui.plugin.add("resizable", "containment", {
co = that.containerOffset; co = that.containerOffset;
ch = that.containerSize.height; ch = that.containerSize.height;
cw = that.containerSize.width; cw = that.containerSize.width;
width = (hasScroll(ce, "left") ? ce.scrollWidth : cw ); width = (that._hasScroll(ce, "left") ? ce.scrollWidth : cw );
height = (hasScroll(ce) ? ce.scrollHeight : ch); height = (that._hasScroll(ce) ? ce.scrollHeight : ch);


that.parentData = { that.parentData = {
element: ce, left: co.left, top: co.top, width: width, height: height element: ce, left: co.left, top: co.top, width: width, height: height
Expand Down

0 comments on commit b7e3e46

Please sign in to comment.