aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Schmitz <arschmitz@gmail.com>2015-01-01 12:11:06 -0500
committerAlexander Schmitz <arschmitz@gmail.com>2015-03-11 16:04:34 -0400
commitf58277a521ae41b1d3e054a419ef5fda85e7db21 (patch)
tree838593ff770211c94c8fe24cf3a3baa019426a65
parente9bb449b5dde255e4a79ea6768864ba26529ed6c (diff)
downloadjquery-ui-f58277a521ae41b1d3e054a419ef5fda85e7db21.tar.gz
jquery-ui-f58277a521ae41b1d3e054a419ef5fda85e7db21.zip
Droppable: Add classes option
Ref #7053 Ref gh-1411
-rw-r--r--demos/droppable/accepted-elements.html6
-rw-r--r--demos/droppable/photo-manager.html8
-rw-r--r--demos/droppable/propagation.html12
-rw-r--r--demos/droppable/revert.html6
-rw-r--r--demos/droppable/shopping-cart.html6
-rw-r--r--demos/droppable/visual-feedback.html10
-rw-r--r--tests/unit/droppable/droppable.html3
-rw-r--r--tests/unit/droppable/droppable_common.js2
-rw-r--r--tests/unit/droppable/droppable_common_deprecated.js21
-rw-r--r--tests/unit/droppable/droppable_deprecated.html47
-rw-r--r--ui/droppable.js89
11 files changed, 169 insertions, 41 deletions
diff --git a/demos/droppable/accepted-elements.html b/demos/droppable/accepted-elements.html
index 19db54650..2a5029526 100644
--- a/demos/droppable/accepted-elements.html
+++ b/demos/droppable/accepted-elements.html
@@ -20,8 +20,10 @@
$( "#draggable, #draggable-nonvalid" ).draggable();
$( "#droppable" ).droppable({
accept: "#draggable",
- activeClass: "ui-state-hover",
- hoverClass: "ui-state-active",
+ classes: {
+ "ui-droppable-active": "ui-state-active",
+ "ui-droppable-hover": "ui-state-hover"
+ },
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
diff --git a/demos/droppable/photo-manager.html b/demos/droppable/photo-manager.html
index 6323e5d7b..6a8cf33d1 100644
--- a/demos/droppable/photo-manager.html
+++ b/demos/droppable/photo-manager.html
@@ -47,7 +47,9 @@
// let the trash be droppable, accepting the gallery items
$trash.droppable({
accept: "#gallery > li",
- activeClass: "ui-state-highlight",
+ classes: {
+ "ui-droppable-active": "ui-state-highlight"
+ },
drop: function( event, ui ) {
deleteImage( ui.draggable );
}
@@ -56,7 +58,9 @@
// let the gallery be droppable as well, accepting items from the trash
$gallery.droppable({
accept: "#trash li",
- activeClass: "custom-state-active",
+ classes: {
+ "ui-droppable-active": "custom-state-active"
+ },
drop: function( event, ui ) {
recycleImage( ui.draggable );
}
diff --git a/demos/droppable/propagation.html b/demos/droppable/propagation.html
index 60cf7cb37..99fb21711 100644
--- a/demos/droppable/propagation.html
+++ b/demos/droppable/propagation.html
@@ -21,8 +21,10 @@
$( "#draggable" ).draggable();
$( "#droppable, #droppable-inner" ).droppable({
- activeClass: "ui-state-hover",
- hoverClass: "ui-state-active",
+ classes: {
+ "ui-droppable-active": "ui-state-active",
+ "ui-droppable-hover": "ui-state-hover"
+ },
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
@@ -34,8 +36,10 @@
$( "#droppable2, #droppable2-inner" ).droppable({
greedy: true,
- activeClass: "ui-state-hover",
- hoverClass: "ui-state-active",
+ classes: {
+ "ui-droppable-active": "ui-state-active",
+ "ui-droppable-hover": "ui-state-hover"
+ },
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
diff --git a/demos/droppable/revert.html b/demos/droppable/revert.html
index 74ccb6fc5..f34801e90 100644
--- a/demos/droppable/revert.html
+++ b/demos/droppable/revert.html
@@ -21,8 +21,10 @@
$( "#draggable2" ).draggable({ revert: "invalid" });
$( "#droppable" ).droppable({
- activeClass: "ui-state-default",
- hoverClass: "ui-state-hover",
+ classes: {
+ "ui-droppable-active": "ui-state-active",
+ "ui-droppable-hover": "ui-state-hover"
+ },
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
diff --git a/demos/droppable/shopping-cart.html b/demos/droppable/shopping-cart.html
index 0304004ed..747c23a83 100644
--- a/demos/droppable/shopping-cart.html
+++ b/demos/droppable/shopping-cart.html
@@ -28,8 +28,10 @@
helper: "clone"
});
$( "#cart ol" ).droppable({
- activeClass: "ui-state-default",
- hoverClass: "ui-state-hover",
+ classes: {
+ "ui-droppable-active": "ui-state-active",
+ "ui-droppable-hover": "ui-state-hover"
+ },
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
$( this ).find( ".placeholder" ).remove();
diff --git a/demos/droppable/visual-feedback.html b/demos/droppable/visual-feedback.html
index 9b197c56e..9852f371b 100644
--- a/demos/droppable/visual-feedback.html
+++ b/demos/droppable/visual-feedback.html
@@ -20,7 +20,9 @@
$(function() {
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
- hoverClass: "ui-state-hover",
+ classes: {
+ "ui-droppable-hover": "ui-state-hover"
+ },
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
@@ -32,7 +34,9 @@
$( "#draggable2" ).draggable();
$( "#droppable2" ).droppable({
accept: "#draggable2",
- activeClass: "ui-state-default",
+ classes: {
+ "ui-droppable-active": "ui-state-default"
+ },
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
@@ -66,7 +70,7 @@
</div>
<div class="demo-description">
-<p>Change the droppable's appearance on hover, or when the droppable is active (an acceptable draggable is dropped on it). Use the <code>hoverClass</code> or <code>activeClass</code> options to specify respective classes.</p>
+<p>Change the droppable's appearance on hover, or when the droppable is active (an acceptable draggable is dropped on it). Set the values of the <code>ui-droppable-hover</code> or <code>ui-droppable-active</code> properties on the <code>classes</code> option to specify the respective classes.</p>
</div>
</body>
</html>
diff --git a/tests/unit/droppable/droppable.html b/tests/unit/droppable/droppable.html
index 03ff888e8..52dc3d543 100644
--- a/tests/unit/droppable/droppable.html
+++ b/tests/unit/droppable/droppable.html
@@ -5,6 +5,9 @@
<title>jQuery UI Droppable Test Suite</title>
<script src="../../jquery.js"></script>
+ <script>
+ $.uiBackCompat = false;
+ </script>
<link rel="stylesheet" href="../../../external/qunit/qunit.css">
<script src="../../../external/qunit/qunit.js"></script>
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
diff --git a/tests/unit/droppable/droppable_common.js b/tests/unit/droppable/droppable_common.js
index bd56aa35f..87d3ca1db 100644
--- a/tests/unit/droppable/droppable_common.js
+++ b/tests/unit/droppable/droppable_common.js
@@ -1,12 +1,10 @@
TestHelpers.commonWidgetTests( "droppable", {
defaults: {
accept: "*",
- activeClass: false,
addClasses: true,
classes: {},
disabled: false,
greedy: false,
- hoverClass: false,
scope: "default",
tolerance: "intersect",
diff --git a/tests/unit/droppable/droppable_common_deprecated.js b/tests/unit/droppable/droppable_common_deprecated.js
new file mode 100644
index 000000000..bd56aa35f
--- /dev/null
+++ b/tests/unit/droppable/droppable_common_deprecated.js
@@ -0,0 +1,21 @@
+TestHelpers.commonWidgetTests( "droppable", {
+ defaults: {
+ accept: "*",
+ activeClass: false,
+ addClasses: true,
+ classes: {},
+ disabled: false,
+ greedy: false,
+ hoverClass: false,
+ scope: "default",
+ tolerance: "intersect",
+
+ // callbacks
+ activate: null,
+ create: null,
+ deactivate: null,
+ drop: null,
+ out: null,
+ over: null
+ }
+});
diff --git a/tests/unit/droppable/droppable_deprecated.html b/tests/unit/droppable/droppable_deprecated.html
new file mode 100644
index 000000000..5af53a2f7
--- /dev/null
+++ b/tests/unit/droppable/droppable_deprecated.html
@@ -0,0 +1,47 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Droppable Test Suite</title>
+
+ <script src="../../jquery.js"></script>
+ <link rel="stylesheet" href="../../../external/qunit/qunit.css">
+ <script src="../../../external/qunit/qunit.js"></script>
+ <script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
+ <script src="../testsuite.js"></script>
+ <script src="../../../external/qunit-assert-classes/qunit-assert-classes.js"></script>
+ <script>
+ TestHelpers.loadResources({
+ css: [ "core" ],
+ js: [
+ "ui/core.js",
+ "ui/widget.js",
+ "ui/mouse.js",
+ "ui/draggable.js",
+ "ui/droppable.js"
+ ]
+ });
+ </script>
+
+ <script src="droppable_common_deprecated.js"></script>
+ <script src="droppable_core.js"></script>
+ <script src="droppable_events.js"></script>
+ <script src="droppable_methods.js"></script>
+ <script src="droppable_options.js"></script>
+ <script src="droppable_test_helpers.js"></script>
+
+ <script src="../swarminject.js"></script>
+</head>
+<body>
+
+<div id="qunit"></div>
+<div id="qunit-fixture">
+
+<div id="draggable1" style="width: 25px; height: 25px;">Draggable</div>
+<div id="droppable1" style="width: 100px; height: 100px;">Droppable</div>
+<div id="droppable2" style="width: 100px; height: 100px;">Droppable</div>
+<div style='width:1000px;height:1000px;'>&nbsp;</div>
+
+</div>
+</body>
+</html>
diff --git a/ui/droppable.js b/ui/droppable.js
index a164f5522..98be34bab 100644
--- a/ui/droppable.js
+++ b/ui/droppable.js
@@ -36,10 +36,8 @@ $.widget( "ui.droppable", {
widgetEventPrefix: "drop",
options: {
accept: "*",
- activeClass: false,
addClasses: true,
greedy: false,
- hoverClass: false,
scope: "default",
tolerance: "intersect",
@@ -80,7 +78,7 @@ $.widget( "ui.droppable", {
this._addToManager( o.scope );
- o.addClasses && this.element.addClass( "ui-droppable" );
+ o.addClasses && this._addClass( "ui-droppable" );
},
@@ -103,8 +101,6 @@ $.widget( "ui.droppable", {
var drop = $.ui.ddmanager.droppables[ this.options.scope ];
this._splice( drop );
-
- this.element.removeClass( "ui-droppable ui-droppable-disabled" );
},
_setOption: function( key, value ) {
@@ -125,9 +121,8 @@ $.widget( "ui.droppable", {
_activate: function( event ) {
var draggable = $.ui.ddmanager.current;
- if ( this.options.activeClass ) {
- this.element.addClass( this.options.activeClass );
- }
+
+ this._addActiveClass();
if ( draggable ){
this._trigger( "activate", event, this.ui( draggable ) );
}
@@ -135,9 +130,8 @@ $.widget( "ui.droppable", {
_deactivate: function( event ) {
var draggable = $.ui.ddmanager.current;
- if ( this.options.activeClass ) {
- this.element.removeClass( this.options.activeClass );
- }
+
+ this._removeActiveClass();
if ( draggable ){
this._trigger( "deactivate", event, this.ui( draggable ) );
}
@@ -153,9 +147,7 @@ $.widget( "ui.droppable", {
}
if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem || draggable.element ) ) ) {
- if ( this.options.hoverClass ) {
- this.element.addClass( this.options.hoverClass );
- }
+ this._addHoverClass();
this._trigger( "over", event, this.ui( draggable ) );
}
@@ -171,9 +163,7 @@ $.widget( "ui.droppable", {
}
if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem || draggable.element ) ) ) {
- if ( this.options.hoverClass ) {
- this.element.removeClass( this.options.hoverClass );
- }
+ this._removeHoverClass();
this._trigger( "out", event, this.ui( draggable ) );
}
@@ -204,12 +194,9 @@ $.widget( "ui.droppable", {
}
if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem || draggable.element ) ) ) {
- if ( this.options.activeClass ) {
- this.element.removeClass( this.options.activeClass );
- }
- if ( this.options.hoverClass ) {
- this.element.removeClass( this.options.hoverClass );
- }
+ this._removeActiveClass();
+ this._removeHoverClass();
+
this._trigger( "drop", event, this.ui( draggable ) );
return this.element;
}
@@ -225,8 +212,25 @@ $.widget( "ui.droppable", {
position: c.position,
offset: c.positionAbs
};
- }
+ },
+ // Extension points just to make backcompat sane and avoid duplicating logic
+ // TODO: Remove in 1.13 along with call to it below
+ _addHoverClass: function() {
+ this._addClass( "ui-droppable-hover" );
+ },
+
+ _removeHoverClass: function() {
+ this._removeClass( "ui-droppable-hover" );
+ },
+
+ _addActiveClass: function() {
+ this._addClass( "ui-droppable-active" );
+ },
+
+ _removeActiveClass: function() {
+ this._removeClass( "ui-droppable-active" );
+ }
});
var intersect = (function() {
@@ -413,6 +417,43 @@ $.ui.ddmanager = {
}
};
+// DEPRECATED
+// TODO: switch return back to widget declaration at top of file when this is removed
+if ( $.uiBackCompat !== false ) {
+
+ // Backcompat for activeClass and hoverClass options
+ $.widget( "ui.droppable", $.ui.droppable, {
+ options: {
+ hoverClass: false,
+ activeClass: false
+ },
+ _addActiveClass: function() {
+ this._super();
+ if ( this.options.activeClass ) {
+ this.element.addClass( this.options.activeClass );
+ }
+ },
+ _removeActiveClass: function() {
+ this._super();
+ if ( this.options.activeClass ) {
+ this.element.removeClass( this.options.activeClass );
+ }
+ },
+ _addHoverClass: function() {
+ this._super();
+ if ( this.options.hoverClass ) {
+ this.element.addClass( this.options.hoverClass );
+ }
+ },
+ _removeHoverClass: function() {
+ this._super();
+ if ( this.options.hoverClass ) {
+ this.element.removeClass( this.options.hoverClass );
+ }
+ }
+ });
+}
+
return $.ui.droppable;
}));