Skip to content

Commit

Permalink
Slider & Interactions: Add Windows 8 touch support
Browse files Browse the repository at this point in the history
Fixes #9709
Fixes #9710
Closes gh-1152
  • Loading branch information
tjvantoll committed Jan 15, 2014
1 parent 1bbbcc7 commit 28310ff
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/unit/draggable/draggable_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,18 @@ asyncTest( "#4261: active element should blur when mousing down on a draggable",
});
});

test( "ui-draggable-handle assigned to appropriate element", function() {
expect( 4 );

var element = $( "<div><p></p></div>" ).appendTo( "#qunit-fixture" ).draggable();
ok( element.hasClass( "ui-draggable-handle" ), "handle is element by default" );

element.draggable( "option", "handle", "p" );
ok( !element.hasClass( "ui-draggable-handle" ), "removed from element" );
ok( element.find( "p" ).hasClass( "ui-draggable-handle" ), "added to handle" );

element.draggable( "destroy" );
ok( !element.find( "p" ).hasClass( "ui-draggable-handle" ), "removed in destroy()" );
});

})( jQuery );
21 changes: 21 additions & 0 deletions tests/unit/sortable/sortable_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,25 @@ test( "#9314: Sortable: Items cannot be dragged directly into bottom position",
TestHelpers.sortable.sort( $( "li", el[ 1 ] )[ 0 ], 0, -12, 5, "Dragging the sortable into connected sortable" );
});

test( "ui-sortable-handle applied to appropriate element", function() {
expect( 6 );
var item = "<li><p></p></li>",
el = $( "<ul>" + item + item + "</ul>" )
.sortable()
.appendTo( "#qunit-fixture" );

ok( el.find( "li:first" ).hasClass( "ui-sortable-handle" ), "defaults to item" );
ok( el.find( "li:last" ).hasClass( "ui-sortable-handle" ), "both items received class name" );

el.sortable( "option", "handle", "p" );
ok( !el.find( "li" ).hasClass( "ui-sortable-handle" ), "removed on change" );
ok( el.find( "p" ).hasClass( "ui-sortable-handle" ), "applied to handle" );

el.append( item ).sortable( "refresh" );
ok( el.find( "p:last" ).hasClass( "ui-sortable-handle" ), "class name applied on refresh" );

el.sortable( "destroy" );
equal( el.find( ".ui-sortable-handle" ).length, 0, "class name removed on destroy" );
});

})( jQuery );
2 changes: 2 additions & 0 deletions themes/base/jquery.ui.base.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
@import url("jquery.ui.button.css");
@import url("jquery.ui.datepicker.css");
@import url("jquery.ui.dialog.css");
@import url("jquery.ui.draggable.css");
@import url("jquery.ui.menu.css");
@import url("jquery.ui.progressbar.css");
@import url("jquery.ui.resizable.css");
@import url("jquery.ui.selectable.css");
@import url("jquery.ui.selectmenu.css");
@import url("jquery.ui.sortable.css");
@import url("jquery.ui.slider.css");
@import url("jquery.ui.spinner.css");
@import url("jquery.ui.tabs.css");
Expand Down
12 changes: 12 additions & 0 deletions themes/base/jquery.ui.draggable.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*!
* jQuery UI Draggable @VERSION
* http://jqueryui.com
*
* Copyright 2013 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
.ui-draggable-handle {
-ms-touch-action: none;
touch-action: none;
}
2 changes: 2 additions & 0 deletions themes/base/jquery.ui.resizable.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
position: absolute;
font-size: 0.1px;
display: block;
-ms-touch-action: none;
touch-action: none;
}
.ui-resizable-disabled .ui-resizable-handle,
.ui-resizable-autohide .ui-resizable-handle {
Expand Down
4 changes: 4 additions & 0 deletions themes/base/jquery.ui.selectable.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* Released under the MIT license.
* http://jquery.org/license
*/
.ui-selectable {
-ms-touch-action: none;
touch-action: none;
}
.ui-selectable-helper {
position: absolute;
z-index: 100;
Expand Down
2 changes: 2 additions & 0 deletions themes/base/jquery.ui.slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
width: 1.2em;
height: 1.2em;
cursor: default;
-ms-touch-action: none;
touch-action: none;
}
.ui-slider .ui-slider-range {
position: absolute;
Expand Down
12 changes: 12 additions & 0 deletions themes/base/jquery.ui.sortable.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*!
* jQuery UI Sortable @VERSION
* http://jqueryui.com
*
* Copyright 2013 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
.ui-sortable-handle {
-ms-touch-action: none;
touch-action: none;
}
19 changes: 19 additions & 0 deletions ui/jquery.ui.draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ $.widget("ui.draggable", $.ui.mouse, {
if (this.options.disabled){
this.element.addClass("ui-draggable-disabled");
}
this._setHandleClassName();

this._mouseInit();
},

_setOption: function( key, value ) {
this._super( key, value );
if ( key === "handle" ) {
this._setHandleClassName();
}
},

_destroy: function() {
Expand All @@ -71,6 +78,7 @@ $.widget("ui.draggable", $.ui.mouse, {
return;
}
this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" );
this._removeHandleClassName();
this._mouseDestroy();
},

Expand Down Expand Up @@ -296,6 +304,17 @@ $.widget("ui.draggable", $.ui.mouse, {
true;
},

_setHandleClassName: function() {
this._removeHandleClassName();
$( this.options.handle || this.element ).addClass( "ui-draggable-handle" );
},

_removeHandleClassName: function() {
this.element.find( ".ui-draggable-handle" )
.addBack()
.removeClass( "ui-draggable-handle" );
},

_createHelper: function(event) {

var o = this.options,
Expand Down
24 changes: 23 additions & 1 deletion ui/jquery.ui.sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,35 @@ $.widget("ui.sortable", $.ui.mouse, {
//Initialize mouse events for interaction
this._mouseInit();

this._setHandleClassName();

//We're ready to go
this.ready = true;

},

_setOption: function( key, value ) {
this._super( key, value );

if ( key === "handle" ) {
this._setHandleClassName();
}
},

_setHandleClassName: function() {
this.element.find( ".ui-sortable-handle" ).removeClass( "ui-sortable-handle" );
$.each( this.items, function() {
( this.instance.options.handle ?
this.item.find( this.instance.options.handle ) : this.item )
.addClass( "ui-sortable-handle" );
});
},

_destroy: function() {
this.element
.removeClass("ui-sortable ui-sortable-disabled");
.removeClass( "ui-sortable ui-sortable-disabled" )
.find( ".ui-sortable-handle" )
.removeClass( "ui-sortable-handle" );
this._mouseDestroy();

for ( var i = this.items.length - 1; i >= 0; i-- ) {
Expand Down Expand Up @@ -598,6 +619,7 @@ $.widget("ui.sortable", $.ui.mouse, {

refresh: function(event) {
this._refreshItems(event);
this._setHandleClassName();
this.refreshPositions();
return this;
},
Expand Down

0 comments on commit 28310ff

Please sign in to comment.