aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Sherov <mike.sherov@gmail.com>2014-08-11 09:51:45 -0400
committerMike Sherov <mike.sherov@gmail.com>2014-08-11 09:51:45 -0400
commit0ad31ca469d541dd0ee56c992da08bfaafbdfeaf (patch)
treeca8c9bcc306cc78528fde05d78b27c672a138e49
parent87081b855c5ded96039d16791a30ff0181fb5a9f (diff)
downloadjquery-ui-0ad31ca469d541dd0ee56c992da08bfaafbdfeaf.tar.gz
jquery-ui-0ad31ca469d541dd0ee56c992da08bfaafbdfeaf.zip
Resizable: fix JSCS violations
-rw-r--r--Gruntfile.js6
-rw-r--r--ui/resizable.js253
2 files changed, 183 insertions, 76 deletions
diff --git a/Gruntfile.js b/Gruntfile.js
index 5f9efd32b..a3d545ce3 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -159,9 +159,9 @@ grunt.initConfig({
}
},
jscs: {
- // datepicker, sortable, resizable and draggable are getting rewritten, ignore until that's done
- ui: [ "ui/*.js", "!ui/datepicker.js", "!ui/sortable.js", "!ui/resizable.js" ],
- // TODO enable this once we have a tool that can help with fixing formatting of existing files
+ // datepicker and sortable are getting rewritten, ignore until that's done
+ ui: [ "ui/*.js", "!ui/datepicker.js", "!ui/sortable.js" ],
+ // TODO enable this once we have a tool that can auto format files
// tests: "tests/unit/**/*.js",
grunt: [ "Gruntfile.js", "build/tasks/*.js" ]
},
diff --git a/ui/resizable.js b/ui/resizable.js
index db71610e2..a02837a19 100644
--- a/ui/resizable.js
+++ b/ui/resizable.js
@@ -58,7 +58,7 @@ $.widget("ui.resizable", $.ui.mouse, {
},
_isNumber: function( value ) {
- return !isNaN( parseInt( value , 10 ) );
+ return !isNaN( parseInt( value, 10 ) );
},
_hasScroll: function( el, a ) {
@@ -99,7 +99,7 @@ $.widget("ui.resizable", $.ui.mouse, {
});
// Wrap the element if it cannot hold child nodes
- if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
+ if (this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
this.element.wrap(
$("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({
@@ -117,14 +117,28 @@ $.widget("ui.resizable", $.ui.mouse, {
this.elementIsWrapper = true;
- this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
- this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
+ this.element.css({
+ marginLeft: this.originalElement.css("marginLeft"),
+ marginTop: this.originalElement.css("marginTop"),
+ marginRight: this.originalElement.css("marginRight"),
+ marginBottom: this.originalElement.css("marginBottom")
+ });
+ this.originalElement.css({
+ marginLeft: 0,
+ marginTop: 0,
+ marginRight: 0,
+ marginBottom: 0
+ });
// support: Safari
// Prevent Safari textarea resize
this.originalResizeStyle = this.originalElement.css("resize");
this.originalElement.css("resize", "none");
- this._proportionallyResizeElements.push(this.originalElement.css({ position: "static", zoom: 1, display: "block" }));
+ this._proportionallyResizeElements.push( this.originalElement.css({
+ position: "static",
+ zoom: 1,
+ display: "block"
+ }) );
// support: IE9
// avoid IE jump (hard set the margin)
@@ -133,8 +147,20 @@ $.widget("ui.resizable", $.ui.mouse, {
this._proportionallyResize();
}
- this.handles = o.handles || (!$(".ui-resizable-handle", this.element).length ? "e,s,se" : { n: ".ui-resizable-n", e: ".ui-resizable-e", s: ".ui-resizable-s", w: ".ui-resizable-w", se: ".ui-resizable-se", sw: ".ui-resizable-sw", ne: ".ui-resizable-ne", nw: ".ui-resizable-nw" });
- if(this.handles.constructor === String) {
+ this.handles = o.handles ||
+ ( !$(".ui-resizable-handle", this.element).length ?
+ "e,s,se" : {
+ n: ".ui-resizable-n",
+ e: ".ui-resizable-e",
+ s: ".ui-resizable-s",
+ w: ".ui-resizable-w",
+ se: ".ui-resizable-se",
+ sw: ".ui-resizable-sw",
+ ne: ".ui-resizable-ne",
+ nw: ".ui-resizable-nw"
+ } );
+
+ if (this.handles.constructor === String) {
if ( this.handles === "all") {
this.handles = "n,e,s,w,se,sw,ne,nw";
@@ -143,10 +169,10 @@ $.widget("ui.resizable", $.ui.mouse, {
n = this.handles.split(",");
this.handles = {};
- for(i = 0; i < n.length; i++) {
+ for (i = 0; i < n.length; i++) {
handle = $.trim(n[i]);
- hname = "ui-resizable-"+handle;
+ hname = "ui-resizable-" + handle;
axis = $("<div class='ui-resizable-handle " + hname + "'></div>");
axis.css({ zIndex: o.zIndex });
@@ -156,7 +182,7 @@ $.widget("ui.resizable", $.ui.mouse, {
axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se");
}
- this.handles[handle] = ".ui-resizable-"+handle;
+ this.handles[handle] = ".ui-resizable-" + handle;
this.element.append(axis);
}
@@ -168,9 +194,9 @@ $.widget("ui.resizable", $.ui.mouse, {
target = target || this.element;
- for(i in this.handles) {
+ for (i in this.handles) {
- if(this.handles[i].constructor === String) {
+ if (this.handles[i].constructor === String) {
this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
}
@@ -192,7 +218,7 @@ $.widget("ui.resizable", $.ui.mouse, {
}
// TODO: What's that good for? There's not anything to be executed left
- if(!$(this.handles[i]).length) {
+ if (!$(this.handles[i]).length) {
continue;
}
}
@@ -224,7 +250,7 @@ $.widget("ui.resizable", $.ui.mouse, {
$(this).removeClass("ui-resizable-autohide");
that._handles.show();
})
- .mouseleave(function(){
+ .mouseleave(function() {
if (o.disabled) {
return;
}
@@ -245,8 +271,13 @@ $.widget("ui.resizable", $.ui.mouse, {
var wrapper,
_destroy = function(exp) {
- $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
- .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove();
+ $(exp)
+ .removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
+ .removeData("resizable")
+ .removeData("ui-resizable")
+ .unbind(".resizable")
+ .find(".ui-resizable-handle")
+ .remove();
};
// TODO: Unwrap at same DOM position
@@ -303,13 +334,34 @@ $.widget("ui.resizable", $.ui.mouse, {
this.offset = this.helper.offset();
this.position = { left: curleft, top: curtop };
- this.size = this._helper ? { width: this.helper.width(), height: this.helper.height() } : { width: el.width(), height: el.height() };
- this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
+
+ this.size = this._helper ? {
+ width: this.helper.width(),
+ height: this.helper.height()
+ } : {
+ width: el.width(),
+ height: el.height()
+ };
+
+ this.originalSize = this._helper ? {
+ width: el.outerWidth(),
+ height: el.outerHeight()
+ } : {
+ width: el.width(),
+ height: el.height()
+ };
+
+ this.sizeDiff = {
+ width: el.outerWidth() - el.width(),
+ height: el.outerHeight() - el.height()
+ };
+
this.originalPosition = { left: curleft, top: curtop };
- this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
this.originalMousePosition = { left: event.pageX, top: event.pageY };
- this.aspectRatio = (typeof o.aspectRatio === "number") ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
+ this.aspectRatio = (typeof o.aspectRatio === "number") ?
+ o.aspectRatio :
+ ((this.originalSize.width / this.originalSize.height) || 1);
cursor = $(".ui-resizable-" + this.axis).css("cursor");
$("body").css("cursor", cursor === "auto" ? this.axis + "-resize" : cursor);
@@ -324,8 +376,8 @@ $.widget("ui.resizable", $.ui.mouse, {
var data, props,
smp = this.originalMousePosition,
a = this.axis,
- dx = (event.pageX-smp.left)||0,
- dy = (event.pageY-smp.top)||0,
+ dx = (event.pageX - smp.left) || 0,
+ dy = (event.pageY - smp.top) || 0,
trigger = this._change[a];
this._updatePrevProperties();
@@ -334,7 +386,7 @@ $.widget("ui.resizable", $.ui.mouse, {
return false;
}
- data = trigger.apply(this, [event, dx, dy]);
+ data = trigger.apply(this, [ event, dx, dy ]);
this._updateVirtualBoundaries(event.shiftKey);
if (this._aspectRatio || event.shiftKey) {
@@ -368,16 +420,21 @@ $.widget("ui.resizable", $.ui.mouse, {
var pr, ista, soffseth, soffsetw, s, left, top,
o = this.options, that = this;
- if(this._helper) {
+ if (this._helper) {
pr = this._proportionallyResizeElements;
ista = pr.length && (/textarea/i).test(pr[0].nodeName);
- soffseth = ista && this._hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height;
+ soffseth = ista && this._hasScroll(pr[0], "left") ? 0 : that.sizeDiff.height;
soffsetw = ista ? 0 : that.sizeDiff.width;
- 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;
+ 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 }));
@@ -448,22 +505,22 @@ $.widget("ui.resizable", $.ui.mouse, {
maxHeight: this._isNumber(o.maxHeight) ? o.maxHeight : Infinity
};
- if(this._aspectRatio || forceAspectRatio) {
+ if (this._aspectRatio || forceAspectRatio) {
pMinWidth = b.minHeight * this.aspectRatio;
pMinHeight = b.minWidth / this.aspectRatio;
pMaxWidth = b.maxHeight * this.aspectRatio;
pMaxHeight = b.maxWidth / this.aspectRatio;
- if(pMinWidth > b.minWidth) {
+ if (pMinWidth > b.minWidth) {
b.minWidth = pMinWidth;
}
- if(pMinHeight > b.minHeight) {
+ if (pMinHeight > b.minHeight) {
b.minHeight = pMinHeight;
}
- if(pMaxWidth < b.maxWidth) {
+ if (pMaxWidth < b.maxWidth) {
b.maxWidth = pMaxWidth;
}
- if(pMaxHeight < b.maxHeight) {
+ if (pMaxHeight < b.maxHeight) {
b.maxHeight = pMaxHeight;
}
}
@@ -514,8 +571,10 @@ $.widget("ui.resizable", $.ui.mouse, {
var o = this._vBoundaries,
a = this.axis,
- ismaxw = this._isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = this._isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
- isminw = this._isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = this._isNumber(data.height) && o.minHeight && (o.minHeight > 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 = 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,
dh = this.position.top + this.size.height,
cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
@@ -616,7 +675,7 @@ $.widget("ui.resizable", $.ui.mouse, {
var el = this.element, o = this.options;
this.elementOffset = el.offset();
- if(this._helper) {
+ if (this._helper) {
this.helper = this.helper || $("<div style='overflow:hidden;'></div>");
@@ -624,8 +683,8 @@ $.widget("ui.resizable", $.ui.mouse, {
width: this.element.outerWidth() - 1,
height: this.element.outerHeight() - 1,
position: "absolute",
- left: this.elementOffset.left +"px",
- top: this.elementOffset.top +"px",
+ left: this.elementOffset.left + "px",
+ top: this.elementOffset.top + "px",
zIndex: ++o.zIndex //TODO: Don't modify option
});
@@ -655,21 +714,25 @@ $.widget("ui.resizable", $.ui.mouse, {
return { height: this.originalSize.height + dy };
},
se: function(event, dx, dy) {
- return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
+ return $.extend(this._change.s.apply(this, arguments),
+ this._change.e.apply(this, [ event, dx, dy ]));
},
sw: function(event, dx, dy) {
- return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
+ return $.extend(this._change.s.apply(this, arguments),
+ this._change.w.apply(this, [ event, dx, dy ]));
},
ne: function(event, dx, dy) {
- return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
+ return $.extend(this._change.n.apply(this, arguments),
+ this._change.e.apply(this, [ event, dx, dy ]));
},
nw: function(event, dx, dy) {
- return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
+ return $.extend(this._change.n.apply(this, arguments),
+ this._change.w.apply(this, [ event, dx, dy ]));
}
},
_propagate: function(n, event) {
- $.ui.plugin.call(this, n, [event, this.ui()]);
+ $.ui.plugin.call(this, n, [ event, this.ui() ]);
(n !== "resize" && this._trigger(n, event, this.ui()));
},
@@ -700,11 +763,13 @@ $.ui.plugin.add("resizable", "animate", {
o = that.options,
pr = that._proportionallyResizeElements,
ista = pr.length && (/textarea/i).test(pr[0].nodeName),
- soffseth = ista && that._hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height,
+ soffseth = ista && that._hasScroll(pr[0], "left") ? 0 : that.sizeDiff.height,
soffsetw = ista ? 0 : that.sizeDiff.width,
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;
+ 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;
that.element.animate(
$.extend(style, top && left ? { top: top, left: left } : {}), {
@@ -816,7 +881,11 @@ $.ui.plugin.add( "resizable", "containment", {
}
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 ) );
+ 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;
continueResize = false;
@@ -825,7 +894,11 @@ $.ui.plugin.add( "resizable", "containment", {
}
if ( cp.top < ( that._helper ? co.top : 0 ) ) {
- that.size.height = that.size.height + ( that._helper ? ( that.position.top - co.top ) : that.position.top );
+ 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;
continueResize = false;
@@ -844,8 +917,15 @@ $.ui.plugin.add( "resizable", "containment", {
that.offset.top = that.element.offset().top;
}
- woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - co.left)) + that.sizeDiff.width );
- hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
+ woset = Math.abs( that.sizeDiff.width +
+ (that._helper ?
+ that.offset.left - cop.left :
+ (that.offset.left - co.left)) );
+
+ hoset = Math.abs( that.sizeDiff.height +
+ (that._helper ?
+ that.offset.top - cop.top :
+ (that.offset.top - co.top)) );
if ( woset + that.size.width >= that.parentData.width ) {
that.size.width = that.parentData.width - woset;
@@ -871,7 +951,7 @@ $.ui.plugin.add( "resizable", "containment", {
}
},
- stop: function(){
+ stop: function() {
var that = $( this ).resizable( "instance" ),
o = that.options,
co = that.containerOffset,
@@ -902,10 +982,10 @@ $.ui.plugin.add( "resizable", "containment", {
$.ui.plugin.add("resizable", "alsoResize", {
- start: function () {
+ start: function() {
var that = $(this).resizable( "instance" ),
o = that.options,
- _store = function (exp) {
+ _store = function(exp) {
$(exp).each(function() {
var el = $(this);
el.data("ui-resizable-alsoresize", {
@@ -916,30 +996,42 @@ $.ui.plugin.add("resizable", "alsoResize", {
};
if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) {
- if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
- else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
- }else{
+ if (o.alsoResize.length) {
+ o.alsoResize = o.alsoResize[0];
+ _store(o.alsoResize);
+ } else {
+ $.each(o.alsoResize, function(exp) {
+ _store(exp);
+ });
+ }
+ } else {
_store(o.alsoResize);
}
},
- resize: function (event, ui) {
+ resize: function(event, ui) {
var that = $(this).resizable( "instance" ),
o = that.options,
os = that.originalSize,
op = that.originalPosition,
delta = {
- 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
+ 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) {
+ _alsoResize = function(exp, c) {
$(exp).each(function() {
var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
- css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ["width", "height"] : ["width", "height", "top", "left"];
-
- $.each(css, function (i, prop) {
- var sum = (start[prop]||0) + (delta[prop]||0);
+ css = c && c.length ?
+ c :
+ el.parents(ui.originalElement[0]).length ?
+ [ "width", "height" ] :
+ [ "width", "height", "top", "left" ];
+
+ $.each(css, function(i, prop) {
+ var sum = (start[prop] || 0) + (delta[prop] || 0);
if (sum && sum >= 0) {
style[prop] = sum || null;
}
@@ -950,13 +1042,15 @@ $.ui.plugin.add("resizable", "alsoResize", {
};
if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
- $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
- }else{
+ $.each(o.alsoResize, function(exp, c) {
+ _alsoResize(exp, c);
+ });
+ } else {
_alsoResize(o.alsoResize);
}
},
- stop: function () {
+ stop: function() {
$(this).removeData("resizable-alsoresize");
}
});
@@ -969,7 +1063,16 @@ $.ui.plugin.add("resizable", "ghost", {
that.ghost = that.originalElement.clone();
that.ghost
- .css({ opacity: 0.25, display: "block", position: "relative", height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
+ .css({
+ opacity: 0.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 : "");
@@ -977,10 +1080,14 @@ $.ui.plugin.add("resizable", "ghost", {
},
- resize: function(){
+ resize: function() {
var that = $(this).resizable( "instance" );
if (that.ghost) {
- that.ghost.css({ position: "relative", height: that.size.height, width: that.size.width });
+ that.ghost.css({
+ position: "relative",
+ height: that.size.height,
+ width: that.size.width
+ });
}
},
@@ -1003,9 +1110,9 @@ $.ui.plugin.add("resizable", "grid", {
os = that.originalSize,
op = that.originalPosition,
a = that.axis,
- grid = typeof o.grid === "number" ? [o.grid, o.grid] : o.grid,
- gridX = (grid[0]||1),
- gridY = (grid[1]||1),
+ grid = typeof o.grid === "number" ? [ o.grid, o.grid ] : o.grid,
+ gridX = (grid[0] || 1),
+ gridY = (grid[1] || 1),
ox = Math.round((cs.width - os.width) / gridX) * gridX,
oy = Math.round((cs.height - os.height) / gridY) * gridY,
newWidth = os.width + ox,