Skip to content

Commit

Permalink
Merge pull request adopted-ember-addons#15 from jgwhite/handle
Browse files Browse the repository at this point in the history
Add handle property to sortable-item
  • Loading branch information
jgwhite committed Apr 28, 2015
2 parents 037c949 + 1cadcba commit 6c52e3b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ $ ember install ember-sortable
{{! app/templates/my-route.hbs }}
{{#sortable-group tagName="ul" onChange="reorderItems" as |group|}}
{{#each model.items as |item|}}
{{#sortable-item tagName="li" model=item group=group}}
{{#each model.items as |item|}}
{{#sortable-item tagName="li" model=item group=group handle=".handle"}}
{{item.name}}
<span class="handle">&varr;</span>
{{/sortable-item}}
{{/each}}
{{/sortable-group}}
Expand Down
16 changes: 16 additions & 0 deletions addon/mixins/sortable-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export default Mixin.create({
*/
model: null,

/**
Selector for the element to use as handle.
If unset, the entire element will be used as the handle.
@property handle
@type String
@default null
*/
handle: null,

/**
True if the item is currently being dragged.
Expand Down Expand Up @@ -136,6 +146,12 @@ export default Mixin.create({
@private
*/
_startDrag(event) {
let handle = this.get('handle');

if (handle && !$(event.target).is(handle)) {
return;
}

event.preventDefault();
event.stopPropagation();

Expand Down
12 changes: 12 additions & 0 deletions tests/dummy/app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@
background: #f66;
z-index: 10;
}

.sortable-item .handle {
position: absolute;
padding: 0 .5em;
top: 0; right: 0; bottom: 0;
background: rgba(127, 0, 0, .5);
color: pink;
cursor: move;
display: flex;
flex-direction: column;
justify-content: center;
}
3 changes: 2 additions & 1 deletion tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<main>
{{#sortable-group tagName="ol" onChange="update" as |group|}}
{{#each model.items as |item|}}
{{#sortable-item tagName="li" model=item group=group}}
{{#sortable-item tagName="li" model=item group=group handle=".handle"}}
{{item}}
<span class="handle">&vArr;</span>
{{/sortable-item}}
{{/each}}
{{/sortable-group}}
Expand Down

0 comments on commit 6c52e3b

Please sign in to comment.