Resizable: remove redundant comments and whitespace

This commit is contained in:
Jyoti Deka 2013-12-15 13:04:08 -05:00 committed by Mike Sherov
parent 20f064662a
commit bc8e75059c

View File

@ -53,7 +53,6 @@ $.widget("ui.resizable", $.ui.mouse, {
_hasScroll: function( el, a ) { _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") { if ( $( el ).css( "overflow" ) === "hidden") {
return false; return false;
} }
@ -89,10 +88,9 @@ $.widget("ui.resizable", $.ui.mouse, {
_helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null _helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null
}); });
//Wrap the element if it cannot hold child nodes // 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)) {
//Create a wrapper element and set the wrapper to the new current internal element
this.element.wrap( this.element.wrap(
$("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({ $("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({
position: this.element.css("position"), position: this.element.css("position"),
@ -103,30 +101,26 @@ $.widget("ui.resizable", $.ui.mouse, {
}) })
); );
//Overwrite the original this.element
this.element = this.element.parent().data( this.element = this.element.parent().data(
"ui-resizable", this.element.resizable( "instance" ) "ui-resizable", this.element.resizable( "instance" )
); );
this.elementIsWrapper = true; this.elementIsWrapper = true;
//Move margins to the wrapper
this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") }); 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.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
// support: Safari
//Prevent Safari textarea resize // Prevent Safari textarea resize
this.originalResizeStyle = this.originalElement.css("resize"); this.originalResizeStyle = this.originalElement.css("resize");
this.originalElement.css("resize", "none"); this.originalElement.css("resize", "none");
//Push the actual element to our proportionallyResize internal array
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) // avoid IE jump (hard set the margin)
this.originalElement.css({ margin: this.originalElement.css("margin") }); this.originalElement.css({ margin: this.originalElement.css("margin") });
// fix handlers offset
this._proportionallyResize(); 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" }); 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" });
@ -145,15 +139,13 @@ $.widget("ui.resizable", $.ui.mouse, {
hname = "ui-resizable-"+handle; hname = "ui-resizable-"+handle;
axis = $("<div class='ui-resizable-handle " + hname + "'></div>"); axis = $("<div class='ui-resizable-handle " + hname + "'></div>");
// Apply zIndex to all handles - see #7960
axis.css({ zIndex: o.zIndex }); axis.css({ zIndex: o.zIndex });
//TODO : What's going on here? // TODO : What's going on here?
if ("se" === handle) { if ("se" === handle) {
axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se"); axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se");
} }
//Insert into internal handles object and append to element
this.handles[handle] = ".ui-resizable-"+handle; this.handles[handle] = ".ui-resizable-"+handle;
this.element.append(axis); this.element.append(axis);
} }
@ -172,15 +164,12 @@ $.widget("ui.resizable", $.ui.mouse, {
this.handles[i] = this.element.children( this.handles[ i ] ).first().show(); this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
} }
//Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) { if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
axis = $(this.handles[i], this.element); axis = $(this.handles[i], this.element);
//Checking the correct pad and border
padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth(); padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
//The padding type i have to apply...
padPos = [ "padding", padPos = [ "padding",
/ne|nw|n/.test(i) ? "Top" : /ne|nw|n/.test(i) ? "Top" :
/se|sw|s/.test(i) ? "Bottom" : /se|sw|s/.test(i) ? "Bottom" :
@ -192,31 +181,28 @@ $.widget("ui.resizable", $.ui.mouse, {
} }
//TODO: What's that good for? There's not anything to be executed left // 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; continue;
} }
} }
}; };
//TODO: make renderAxis a prototype function // TODO: make renderAxis a prototype function
this._renderAxis(this.element); this._renderAxis(this.element);
this._handles = $(".ui-resizable-handle", this.element) this._handles = $(".ui-resizable-handle", this.element)
.disableSelection(); .disableSelection();
//Matching axis name
this._handles.mouseover(function() { this._handles.mouseover(function() {
if (!that.resizing) { if (!that.resizing) {
if (this.className) { if (this.className) {
axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i); axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
} }
//Axis, default = se
that.axis = axis && axis[1] ? axis[1] : "se"; that.axis = axis && axis[1] ? axis[1] : "se";
} }
}); });
//If we want to auto hide the elements
if (o.autoHide) { if (o.autoHide) {
this._handles.hide(); this._handles.hide();
$(this.element) $(this.element)
@ -239,7 +225,6 @@ $.widget("ui.resizable", $.ui.mouse, {
}); });
} }
//Initialize the mouse interaction
this._mouseInit(); this._mouseInit();
}, },
@ -254,7 +239,7 @@ $.widget("ui.resizable", $.ui.mouse, {
.removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove(); .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove();
}; };
//TODO: Unwrap at same DOM position // TODO: Unwrap at same DOM position
if (this.elementIsWrapper) { if (this.elementIsWrapper) {
_destroy(this.element); _destroy(this.element);
wrapper = this.element; wrapper = this.element;
@ -297,7 +282,7 @@ $.widget("ui.resizable", $.ui.mouse, {
this.resizing = true; this.resizing = true;
// bugfix for http://dev.jquery.com/ticket/1749 // Bugfix for http://bugs.jqueryui.com/ticket/1749
if ( (/absolute/).test( el.css("position") ) ) { if ( (/absolute/).test( el.css("position") ) ) {
el.css({ position: "absolute", top: el.css("top"), left: el.css("left") }); el.css({ position: "absolute", top: el.css("top"), left: el.css("left") });
} else if (el.is(".ui-draggable")) { } else if (el.is(".ui-draggable")) {
@ -314,7 +299,6 @@ $.widget("ui.resizable", $.ui.mouse, {
curtop += $(o.containment).scrollTop() || 0; curtop += $(o.containment).scrollTop() || 0;
} }
//Store needed variables
this.offset = this.helper.offset(); this.offset = this.helper.offset();
this.position = { left: curleft, top: curtop }; 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.size = this._helper ? { width: this.helper.width(), height: this.helper.height() } : { width: el.width(), height: el.height() };
@ -323,7 +307,6 @@ $.widget("ui.resizable", $.ui.mouse, {
this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() }; this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
this.originalMousePosition = { left: event.pageX, top: event.pageY }; this.originalMousePosition = { left: event.pageX, top: event.pageY };
//Aspect Ratio
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"); cursor = $(".ui-resizable-" + this.axis).css("cursor");
@ -336,7 +319,6 @@ $.widget("ui.resizable", $.ui.mouse, {
_mouseDrag: function(event) { _mouseDrag: function(event) {
//Increase performance, avoid regex
var data, var data,
el = this.helper, props = {}, el = this.helper, props = {},
smp = this.originalMousePosition, smp = this.originalMousePosition,
@ -358,10 +340,8 @@ $.widget("ui.resizable", $.ui.mouse, {
return false; return false;
} }
// Calculate the attrs that will be change
data = trigger.apply(this, [event, dx, dy]); data = trigger.apply(this, [event, dx, dy]);
// Put this in the mouseDrag handler since the user can start pressing shift while resizing
this._updateVirtualBoundaries(event.shiftKey); this._updateVirtualBoundaries(event.shiftKey);
if (this._aspectRatio || event.shiftKey) { if (this._aspectRatio || event.shiftKey) {
data = this._updateRatio(data, event); data = this._updateRatio(data, event);
@ -371,7 +351,6 @@ $.widget("ui.resizable", $.ui.mouse, {
this._updateCache(data); this._updateCache(data);
// plugins callbacks need to be called first
this._propagate("resize", event); this._propagate("resize", event);
if ( this.position.top !== this.prevPosition.top ) { if ( this.position.top !== this.prevPosition.top ) {
@ -386,15 +365,14 @@ $.widget("ui.resizable", $.ui.mouse, {
if ( this.size.height !== this.prevSize.height ) { if ( this.size.height !== this.prevSize.height ) {
props.height = this.size.height + "px"; props.height = this.size.height + "px";
} }
el.css(props); el.css( props );
if (!this._helper && this._proportionallyResizeElements.length) { if ( !this._helper && this._proportionallyResizeElements.length ) {
this._proportionallyResize(); this._proportionallyResize();
} }
// Call the user callback if the element was resized if ( !$.isEmptyObject( props ) ) {
if ( ! $.isEmptyObject(props) ) { this._trigger( "resize", event, this.ui() );
this._trigger("resize", event, this.ui());
} }
return false; return false;
@ -455,8 +433,6 @@ $.widget("ui.resizable", $.ui.mouse, {
}; };
if(this._aspectRatio || forceAspectRatio) { if(this._aspectRatio || forceAspectRatio) {
// We want to create an enclosing box whose aspect ration is the requested one
// First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
pMinWidth = b.minHeight * this.aspectRatio; pMinWidth = b.minHeight * this.aspectRatio;
pMinHeight = b.minWidth / this.aspectRatio; pMinHeight = b.minWidth / this.aspectRatio;
pMaxWidth = b.maxHeight * this.aspectRatio; pMaxWidth = b.maxHeight * this.aspectRatio;
@ -553,7 +529,7 @@ $.widget("ui.resizable", $.ui.mouse, {
data.top = dh - o.maxHeight; data.top = dh - o.maxHeight;
} }
// fixing jump error on top/left - bug #2330 // Fixing jump error on top/left - bug #2330
if (!data.width && !data.height && !data.left && data.top) { if (!data.width && !data.height && !data.left && data.top) {
data.top = null; data.top = null;
} else if (!data.width && !data.height && !data.top && data.left) { } else if (!data.width && !data.height && !data.top && data.left) {
@ -753,10 +729,7 @@ $.ui.plugin.add( "resizable", "containment", {
width: $( document ).width(), width: $( document ).width(),
height: $( document ).height() || document.body.parentNode.scrollHeight height: $( document ).height() || document.body.parentNode.scrollHeight
}; };
} } else {
// i'm a node, so compute top, left, right, bottom
else {
element = $( ce ); element = $( ce );
p = []; p = [];
$([ "Top", "Right", "Left", "Bottom" ]).each(function( i, name ) { $([ "Top", "Right", "Left", "Bottom" ]).each(function( i, name ) {