Dev: Standardized the resizable test suite. Fixed #8754 - Dev: Get resizable test suite to pass

This commit is contained in:
Mike Sherov 2012-10-31 08:30:01 -04:00 committed by Scott González
parent 8746042ae1
commit d85b0160f2
8 changed files with 99 additions and 99 deletions

View File

@ -21,7 +21,7 @@ var versions = {
"Menu": "menu/menu.html", "Menu": "menu/menu.html",
"Position": "position/position.html", "Position": "position/position.html",
"Progressbar": "progressbar/progressbar.html", "Progressbar": "progressbar/progressbar.html",
//"Resizable": "resizable/resizable.html", "Resizable": "resizable/resizable.html",
"Selectable": "selectable/selectable.html", "Selectable": "selectable/selectable.html",
//"Slider": "slider/slider.html", //"Slider": "slider/slider.html",
//"Sortable": "sortable/sortable.html", //"Sortable": "sortable/sortable.html",

View File

@ -281,13 +281,13 @@ grunt.initConfig({
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) { files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now // disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go // TODO except for all|index|test, try to include more as we go
return !( /(all|all-active|index|test|resizable|sortable|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file ); return !( /(all|all-active|index|test|sortable|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file );
}) })
}, },
lint: { lint: {
ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) { ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
// TODO remove items from this list once rewritten // TODO remove items from this list once rewritten
return !( /(mouse|datepicker|resizable|sortable)\.js$/ ).test( file ); return !( /(mouse|datepicker|sortable)\.js$/ ).test( file );
}), }),
grunt: [ "grunt.js", "build/**/*.js" ], grunt: [ "grunt.js", "build/**/*.js" ],
tests: "tests/unit/**/*.js" tests: "tests/unit/**/*.js"

View File

@ -28,7 +28,7 @@
"menu/menu.html", "menu/menu.html",
"position/position.html", "position/position.html",
"progressbar/progressbar.html", "progressbar/progressbar.html",
//"resizable/resizable.html", "resizable/resizable.html",
"selectable/selectable.html", "selectable/selectable.html",
//"slider/slider.html", //"slider/slider.html",
//"sortable/sortable.html", //"sortable/sortable.html",

View File

@ -28,7 +28,7 @@
"menu/menu.html", "menu/menu.html",
"position/position.html", "position/position.html",
"progressbar/progressbar.html", "progressbar/progressbar.html",
//"resizable/resizable.html", "resizable/resizable.html",
"selectable/selectable.html", "selectable/selectable.html",
"slider/slider.html", "slider/slider.html",
//"sortable/sortable.html", //"sortable/sortable.html",

View File

@ -2,18 +2,20 @@
* resizable_core.js * resizable_core.js
*/ */
TestHelpers.resizableDrag = function(el, dx, dy, complete) { TestHelpers.resizable = {
drag: function(el, dx, dy, complete) {
// speed = sync -> Drag syncrhonously. // speed = sync -> Drag syncrhonously.
// speed = fast|slow -> Drag asyncrhonously - animated. // speed = fast|slow -> Drag asyncrhonously - animated.
//this mouseover is to work around a limitation in resizable //this mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used //TODO: fix resizable so handle doesn't require mouseover in order to be used
$(el).simulate("mouseover"); $(el).simulate("mouseover");
return $(el).simulate("drag", { return $(el).simulate("drag", {
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
}); });
}
}; };
(function($) { (function($) {
@ -44,10 +46,10 @@ test("n", function() {
var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' }); var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, 0, -50); TestHelpers.resizable.drag(handle, 0, -50);
equal( target.height(), 150, "compare height" ); equal( target.height(), 150, "compare height" );
TestHelpers.resizableDrag(handle, 0, 50); TestHelpers.resizable.drag(handle, 0, 50);
equal( target.height(), 100, "compare height" ); equal( target.height(), 100, "compare height" );
}); });
@ -56,10 +58,10 @@ test("s", function() {
var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' }); var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, 0, 50); TestHelpers.resizable.drag(handle, 0, 50);
equal( target.height(), 150, "compare height" ); equal( target.height(), 150, "compare height" );
TestHelpers.resizableDrag(handle, 0, -50); TestHelpers.resizable.drag(handle, 0, -50);
equal( target.height(), 100, "compare height" ); equal( target.height(), 100, "compare height" );
}); });
@ -68,10 +70,10 @@ test("e", function() {
var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' }); var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, 50); TestHelpers.resizable.drag(handle, 50);
equal( target.width(), 150, "compare width"); equal( target.width(), 150, "compare width");
TestHelpers.resizableDrag(handle, -50); TestHelpers.resizable.drag(handle, -50);
equal( target.width(), 100, "compare width" ); equal( target.width(), 100, "compare width" );
}); });
@ -80,10 +82,10 @@ test("w", function() {
var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' }); var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, -50); TestHelpers.resizable.drag(handle, -50);
equal( target.width(), 150, "compare width" ); equal( target.width(), 150, "compare width" );
TestHelpers.resizableDrag(handle, 50); TestHelpers.resizable.drag(handle, 50);
equal( target.width(), 100, "compare width" ); equal( target.width(), 100, "compare width" );
}); });
@ -92,11 +94,11 @@ test("ne", function() {
var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' }); var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, -50, -50); TestHelpers.resizable.drag(handle, -50, -50);
equal( target.width(), 50, "compare width" ); equal( target.width(), 50, "compare width" );
equal( target.height(), 150, "compare height" ); equal( target.height(), 150, "compare height" );
TestHelpers.resizableDrag(handle, 50, 50); TestHelpers.resizable.drag(handle, 50, 50);
equal( target.width(), 100, "compare width" ); equal( target.width(), 100, "compare width" );
equal( target.height(), 100, "compare height" ); equal( target.height(), 100, "compare height" );
}); });
@ -106,11 +108,11 @@ test("se", function() {
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' }); var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, 50, 50); TestHelpers.resizable.drag(handle, 50, 50);
equal( target.width(), 150, "compare width" ); equal( target.width(), 150, "compare width" );
equal( target.height(), 150, "compare height" ); equal( target.height(), 150, "compare height" );
TestHelpers.resizableDrag(handle, -50, -50); TestHelpers.resizable.drag(handle, -50, -50);
equal( target.width(), 100, "compare width" ); equal( target.width(), 100, "compare width" );
equal( target.height(), 100, "compare height" ); equal( target.height(), 100, "compare height" );
}); });
@ -120,11 +122,11 @@ test("sw", function() {
var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' }); var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, -50, -50); TestHelpers.resizable.drag(handle, -50, -50);
equal( target.width(), 150, "compare width" ); equal( target.width(), 150, "compare width" );
equal( target.height(), 50, "compare height" ); equal( target.height(), 50, "compare height" );
TestHelpers.resizableDrag(handle, 50, 50); TestHelpers.resizable.drag(handle, 50, 50);
equal( target.width(), 100, "compare width" ); equal( target.width(), 100, "compare width" );
equal( target.height(), 100, "compare height" ); equal( target.height(), 100, "compare height" );
}); });
@ -134,11 +136,11 @@ test("nw", function() {
var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' }); var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' });
TestHelpers.resizableDrag(handle, -50, -50); TestHelpers.resizable.drag(handle, -50, -50);
equal( target.width(), 150, "compare width" ); equal( target.width(), 150, "compare width" );
equal( target.height(), 150, "compare height" ); equal( target.height(), 150, "compare height" );
TestHelpers.resizableDrag(handle, 50, 50); TestHelpers.resizable.drag(handle, 50, 50);
equal( target.width(), 100, "compare width" ); equal( target.width(), 100, "compare width" );
equal( target.height(), 100, "compare height" ); equal( target.height(), 100, "compare height" );
}); });

View File

@ -10,11 +10,11 @@ test("aspectRatio: 'preserve' (e)", function() {
var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
TestHelpers.resizableDrag(handle, 80); TestHelpers.resizable.drag(handle, 80);
equal( target.width(), 130, "compare maxWidth"); equal( target.width(), 130, "compare maxWidth");
equal( target.height(), 130, "compare maxHeight"); equal( target.height(), 130, "compare maxHeight");
TestHelpers.resizableDrag(handle, -130); TestHelpers.resizable.drag(handle, -130);
equal( target.width(), 70, "compare minWidth"); equal( target.width(), 70, "compare minWidth");
equal( target.height(), 70, "compare minHeight"); equal( target.height(), 70, "compare minHeight");
}); });
@ -24,11 +24,11 @@ test("aspectRatio: 'preserve' (w)", function() {
var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
TestHelpers.resizableDrag(handle, -80); TestHelpers.resizable.drag(handle, -80);
equal( target.width(), 130, "compare maxWidth"); equal( target.width(), 130, "compare maxWidth");
equal( target.height(), 130, "compare maxHeight"); equal( target.height(), 130, "compare maxHeight");
TestHelpers.resizableDrag(handle, 130); TestHelpers.resizable.drag(handle, 130);
equal( target.width(), 70, "compare minWidth"); equal( target.width(), 70, "compare minWidth");
equal( target.height(), 70, "compare minHeight"); equal( target.height(), 70, "compare minHeight");
}); });
@ -38,11 +38,11 @@ test("aspectRatio: 'preserve' (n)", function() {
var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
TestHelpers.resizableDrag(handle, 0, -80); TestHelpers.resizable.drag(handle, 0, -80);
equal( target.width(), 130, "compare maxWidth"); equal( target.width(), 130, "compare maxWidth");
equal( target.height(), 130, "compare maxHeight"); equal( target.height(), 130, "compare maxHeight");
TestHelpers.resizableDrag(handle, 0, 80); TestHelpers.resizable.drag(handle, 0, 80);
equal( target.width(), 70, "compare minWidth"); equal( target.width(), 70, "compare minWidth");
equal( target.height(), 70, "compare minHeight"); equal( target.height(), 70, "compare minHeight");
}); });
@ -52,11 +52,11 @@ test("aspectRatio: 'preserve' (s)", function() {
var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
TestHelpers.resizableDrag(handle, 0, 80); TestHelpers.resizable.drag(handle, 0, 80);
equal( target.width(), 130, "compare maxWidth"); equal( target.width(), 130, "compare maxWidth");
equal( target.height(), 130, "compare maxHeight"); equal( target.height(), 130, "compare maxHeight");
TestHelpers.resizableDrag(handle, 0, -80); TestHelpers.resizable.drag(handle, 0, -80);
equal( target.width(), 70, "compare minWidth"); equal( target.width(), 70, "compare minWidth");
equal( target.height(), 70, "compare minHeight"); equal( target.height(), 70, "compare minHeight");
}); });
@ -66,11 +66,11 @@ test("aspectRatio: 'preserve' (se)", function() {
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
TestHelpers.resizableDrag(handle, 80, 80); TestHelpers.resizable.drag(handle, 80, 80);
equal( target.width(), 130, "compare maxWidth"); equal( target.width(), 130, "compare maxWidth");
equal( target.height(), 130, "compare maxHeight"); equal( target.height(), 130, "compare maxHeight");
TestHelpers.resizableDrag(handle, -80, -80); TestHelpers.resizable.drag(handle, -80, -80);
equal( target.width(), 70, "compare minWidth"); equal( target.width(), 70, "compare minWidth");
equal( target.height(), 70, "compare minHeight"); equal( target.height(), 70, "compare minHeight");
}); });
@ -80,11 +80,11 @@ test("aspectRatio: 'preserve' (sw)", function() {
var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
TestHelpers.resizableDrag(handle, -80, 80); TestHelpers.resizable.drag(handle, -80, 80);
equal( target.width(), 130, "compare maxWidth"); equal( target.width(), 130, "compare maxWidth");
equal( target.height(), 130, "compare maxHeight"); equal( target.height(), 130, "compare maxHeight");
TestHelpers.resizableDrag(handle, 80, -80); TestHelpers.resizable.drag(handle, 80, -80);
equal( target.width(), 70, "compare minWidth"); equal( target.width(), 70, "compare minWidth");
equal( target.height(), 70, "compare minHeight"); equal( target.height(), 70, "compare minHeight");
}); });
@ -94,11 +94,11 @@ test("aspectRatio: 'preserve' (ne)", function() {
var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
TestHelpers.resizableDrag(handle, 80, -80); TestHelpers.resizable.drag(handle, 80, -80);
equal( target.width(), 130, "compare maxWidth"); equal( target.width(), 130, "compare maxWidth");
equal( target.height(), 130, "compare maxHeight"); equal( target.height(), 130, "compare maxHeight");
TestHelpers.resizableDrag(handle, -80, 80); TestHelpers.resizable.drag(handle, -80, 80);
equal( target.width(), 70, "compare minWidth"); equal( target.width(), 70, "compare minWidth");
equal( target.height(), 70, "compare minHeight"); equal( target.height(), 70, "compare minHeight");
}); });
@ -108,11 +108,11 @@ test("grid", function() {
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] }); var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] });
TestHelpers.resizableDrag(handle, 3, 9); TestHelpers.resizable.drag(handle, 3, 9);
equal( target.width(), 103, "compare width"); equal( target.width(), 103, "compare width");
equal( target.height(), 100, "compare height"); equal( target.height(), 100, "compare height");
TestHelpers.resizableDrag(handle, 15, 11); TestHelpers.resizable.drag(handle, 15, 11);
equal( target.width(), 118, "compare width"); equal( target.width(), 118, "compare width");
equal( target.height(), 120, "compare height"); equal( target.height(), 120, "compare height");
}); });
@ -122,11 +122,11 @@ test("grid (wrapped)", function() {
var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] }); var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] });
TestHelpers.resizableDrag(handle, 3, 9); TestHelpers.resizable.drag(handle, 3, 9);
equal( target.width(), 103, "compare width"); equal( target.width(), 103, "compare width");
equal( target.height(), 100, "compare height"); equal( target.height(), 100, "compare height");
TestHelpers.resizableDrag(handle, 15, 11); TestHelpers.resizable.drag(handle, 15, 11);
equal( target.width(), 118, "compare width"); equal( target.width(), 118, "compare width");
equal( target.height(), 120, "compare height"); equal( target.height(), 120, "compare height");
}); });
@ -136,11 +136,11 @@ test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
TestHelpers.resizableDrag(handle, -50, -50); TestHelpers.resizable.drag(handle, -50, -50);
equal( target.width(), 60, "compare minWidth" ); equal( target.width(), 60, "compare minWidth" );
equal( target.height(), 60, "compare minHeight" ); equal( target.height(), 60, "compare minHeight" );
TestHelpers.resizableDrag(handle, 70, 70); TestHelpers.resizable.drag(handle, 70, 70);
equal( target.width(), 100, "compare maxWidth" ); equal( target.width(), 100, "compare maxWidth" );
equal( target.height(), 100, "compare maxHeight" ); equal( target.height(), 100, "compare maxHeight" );
}); });
@ -150,11 +150,11 @@ test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
TestHelpers.resizableDrag(handle, 50, -50); TestHelpers.resizable.drag(handle, 50, -50);
equal( target.width(), 60, "compare minWidth" ); equal( target.width(), 60, "compare minWidth" );
equal( target.height(), 60, "compare minHeight" ); equal( target.height(), 60, "compare minHeight" );
TestHelpers.resizableDrag(handle, -70, 70); TestHelpers.resizable.drag(handle, -70, 70);
equal( target.width(), 100, "compare maxWidth" ); equal( target.width(), 100, "compare maxWidth" );
equal( target.height(), 100, "compare maxHeight" ); equal( target.height(), 100, "compare maxHeight" );
}); });
@ -164,11 +164,11 @@ test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
TestHelpers.resizableDrag(handle, -50, 50); TestHelpers.resizable.drag(handle, -50, 50);
equal( target.width(), 60, "compare minWidth" ); equal( target.width(), 60, "compare minWidth" );
equal( target.height(), 60, "compare minHeight" ); equal( target.height(), 60, "compare minHeight" );
TestHelpers.resizableDrag(handle, 70, -70); TestHelpers.resizable.drag(handle, 70, -70);
equal( target.width(), 100, "compare maxWidth" ); equal( target.width(), 100, "compare maxWidth" );
equal( target.height(), 100, "compare maxHeight" ); equal( target.height(), 100, "compare maxHeight" );
}); });
@ -178,11 +178,11 @@ test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
TestHelpers.resizableDrag(handle, 70, 70); TestHelpers.resizable.drag(handle, 70, 70);
equal( target.width(), 60, "compare minWidth" ); equal( target.width(), 60, "compare minWidth" );
equal( target.height(), 60, "compare minHeight" ); equal( target.height(), 60, "compare minHeight" );
TestHelpers.resizableDrag(handle, -70, -70); TestHelpers.resizable.drag(handle, -70, -70);
equal( target.width(), 100, "compare maxWidth" ); equal( target.width(), 100, "compare maxWidth" );
equal( target.height(), 100, "compare maxHeight" ); equal( target.height(), 100, "compare maxHeight" );
}); });

View File

@ -14,8 +14,6 @@
* jquery.ui.mouse.js * jquery.ui.mouse.js
* jquery.ui.draggable.js * jquery.ui.draggable.js
*/ */
(function( $, undefined ) { (function( $, undefined ) {
/*jshint onevar: false, curly: false, eqeqeq: false, laxbreak: true */ /*jshint onevar: false, curly: false, eqeqeq: false, laxbreak: true */

View File

@ -15,6 +15,16 @@
*/ */
(function( $, undefined ) { (function( $, undefined ) {
/*jshint onevar: false, curly: false, eqeqeq: false, funcscope: true, loopfunc: true */
function num(v) {
return parseInt(v, 10) || 0;
}
function isNumber(value) {
return !isNaN(parseInt(value, 10));
}
$.widget("ui.resizable", $.ui.mouse, { $.widget("ui.resizable", $.ui.mouse, {
version: "@VERSION", version: "@VERSION",
widgetEventPrefix: "resize", widgetEventPrefix: "resize",
@ -106,7 +116,7 @@ $.widget("ui.resizable", $.ui.mouse, {
//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 //Insert into internal handles object and append to element
this.handles[handle] = '.ui-resizable-'+handle; this.handles[handle] = '.ui-resizable-'+handle;
@ -275,8 +285,8 @@ $.widget("ui.resizable", $.ui.mouse, {
_mouseDrag: function(event) { _mouseDrag: function(event) {
//Increase performance, avoid regex //Increase performance, avoid regex
var el = this.helper, o = this.options, props = {}, var el = this.helper,
that = this, smp = this.originalMousePosition, a = this.axis; smp = this.originalMousePosition, a = this.axis;
var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0; var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
var trigger = this._change[a]; var trigger = this._change[a];
@ -372,7 +382,6 @@ $.widget("ui.resizable", $.ui.mouse, {
}, },
_updateCache: function(data) { _updateCache: function(data) {
var o = this.options;
this.offset = this.helper.offset(); this.offset = this.helper.offset();
if (isNumber(data.left)) this.position.left = data.left; if (isNumber(data.left)) this.position.left = data.left;
if (isNumber(data.top)) this.position.top = data.top; if (isNumber(data.top)) this.position.top = data.top;
@ -380,9 +389,9 @@ $.widget("ui.resizable", $.ui.mouse, {
if (isNumber(data.width)) this.size.width = data.width; if (isNumber(data.width)) this.size.width = data.width;
}, },
_updateRatio: function(data, event) { _updateRatio: function( data ) {
var o = this.options, cpos = this.position, csize = this.size, a = this.axis; var cpos = this.position, csize = this.size, a = this.axis;
if (isNumber(data.height)) data.width = (data.height * this.aspectRatio); if (isNumber(data.height)) data.width = (data.height * this.aspectRatio);
else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio); else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio);
@ -399,11 +408,11 @@ $.widget("ui.resizable", $.ui.mouse, {
return data; return data;
}, },
_respectSize: function(data, event) { _respectSize: function( data ) {
var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis, var o = this._vBoundaries, a = this.axis,
ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height), ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = 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 = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
if (isminw) data.width = o.minWidth; if (isminw) data.width = o.minWidth;
if (isminh) data.height = o.minHeight; if (isminh) data.height = o.minHeight;
@ -428,7 +437,6 @@ $.widget("ui.resizable", $.ui.mouse, {
_proportionallyResize: function() { _proportionallyResize: function() {
var o = this.options;
if (!this._proportionallyResizeElements.length) return; if (!this._proportionallyResizeElements.length) return;
var element = this.helper || this.element; var element = this.helper || this.element;
@ -451,7 +459,7 @@ $.widget("ui.resizable", $.ui.mouse, {
width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0 width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
}); });
}; }
}, },
@ -484,15 +492,15 @@ $.widget("ui.resizable", $.ui.mouse, {
}, },
_change: { _change: {
e: function(event, dx, dy) { e: function(event, dx) {
return { width: this.originalSize.width + dx }; return { width: this.originalSize.width + dx };
}, },
w: function(event, dx, dy) { w: function(event, dx) {
var o = this.options, cs = this.originalSize, sp = this.originalPosition; var cs = this.originalSize, sp = this.originalPosition;
return { left: sp.left + dx, width: cs.width - dx }; return { left: sp.left + dx, width: cs.width - dx };
}, },
n: function(event, dx, dy) { n: function(event, dx, dy) {
var o = this.options, cs = this.originalSize, sp = this.originalPosition; var cs = this.originalSize, sp = this.originalPosition;
return { top: sp.top + dy, height: cs.height - dy }; return { top: sp.top + dy, height: cs.height - dy };
}, },
s: function(event, dx, dy) { s: function(event, dx, dy) {
@ -539,7 +547,7 @@ $.widget("ui.resizable", $.ui.mouse, {
$.ui.plugin.add("resizable", "alsoResize", { $.ui.plugin.add("resizable", "alsoResize", {
start: function (event, ui) { start: function () {
var that = $(this).data("resizable"), o = that.options; var that = $(this).data("resizable"), o = that.options;
var _store = function (exp) { var _store = function (exp) {
@ -590,14 +598,14 @@ $.ui.plugin.add("resizable", "alsoResize", {
} }
}, },
stop: function (event, ui) { stop: function () {
$(this).removeData("resizable-alsoresize"); $(this).removeData("resizable-alsoresize");
} }
}); });
$.ui.plugin.add("resizable", "animate", { $.ui.plugin.add("resizable", "animate", {
stop: function(event, ui) { stop: function( event ) {
var that = $(this).data("resizable"), o = that.options; var that = $(this).data("resizable"), o = that.options;
var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName), var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
@ -636,7 +644,7 @@ $.ui.plugin.add("resizable", "animate", {
$.ui.plugin.add("resizable", "containment", { $.ui.plugin.add("resizable", "containment", {
start: function(event, ui) { start: function() {
var that = $(this).data("resizable"), o = that.options, el = that.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; var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
if (!ce) return; if (!ce) return;
@ -671,10 +679,10 @@ $.ui.plugin.add("resizable", "containment", {
} }
}, },
resize: function(event, ui) { resize: function( event ) {
var that = $(this).data("resizable"), o = that.options, var that = $(this).data("resizable"), o = that.options,
ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position, co = that.containerOffset, cp = that.position,
pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement; 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 (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;
@ -712,8 +720,8 @@ $.ui.plugin.add("resizable", "containment", {
} }
}, },
stop: function(event, ui){ stop: function(){
var that = $(this).data("resizable"), o = that.options, cp = that.position, var that = $(this).data("resizable"), o = that.options,
co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement; co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement;
var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height; var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height;
@ -729,13 +737,13 @@ $.ui.plugin.add("resizable", "containment", {
$.ui.plugin.add("resizable", "ghost", { $.ui.plugin.add("resizable", "ghost", {
start: function(event, ui) { start: function() {
var that = $(this).data("resizable"), o = that.options, cs = that.size; var that = $(this).data("resizable"), o = that.options, cs = that.size;
that.ghost = that.originalElement.clone(); that.ghost = that.originalElement.clone();
that.ghost that.ghost
.css({ opacity: .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('ui-resizable-ghost')
.addClass(typeof o.ghost == 'string' ? o.ghost : ''); .addClass(typeof o.ghost == 'string' ? o.ghost : '');
@ -743,13 +751,13 @@ $.ui.plugin.add("resizable", "ghost", {
}, },
resize: function(event, ui){ resize: function(){
var that = $(this).data("resizable"), o = that.options; var that = $(this).data("resizable");
if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width }); if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width });
}, },
stop: function(event, ui){ stop: function() {
var that = $(this).data("resizable"), o = that.options; var that = $(this).data("resizable");
if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0)); if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0));
} }
@ -757,8 +765,8 @@ $.ui.plugin.add("resizable", "ghost", {
$.ui.plugin.add("resizable", "grid", { $.ui.plugin.add("resizable", "grid", {
resize: function(event, ui) { resize: function() {
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; var that = $(this).data("resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis;
o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid; 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); 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);
@ -786,12 +794,4 @@ $.ui.plugin.add("resizable", "grid", {
}); });
var num = function(v) {
return parseInt(v, 10) || 0;
};
var isNumber = function(value) {
return !isNaN(parseInt(value, 10));
};
})(jQuery); })(jQuery);