Skip to content

Commit

Permalink
Added support for draggable handle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwong Kiu authored and Kwong Kiu committed Dec 5, 2014
1 parent e228fe3 commit 7e6b01b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/angular-nestable.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@
this.defaultOptions = function(value){
defaultOptions = value;
};
})


/**
* Flag to turn on/off draggable handle
* @param {[string]} value
*/
this.enableDraggableHandle = false;
})
.directive('ngNestable', ['$compile', '$nestable', function($compile, $nestable){
return {
restrict: 'A',
Expand Down Expand Up @@ -183,16 +190,29 @@
controller: angular.noop
};

function buildNestableHtml(model, tpl){
function buildNestableHtml(model, tpl) {
var root = $('<div class="dd"></div>');
var rootList = $('<ol class="dd-list"></ol>').appendTo(root);
var draggableHandle = $nestable.enableDraggableHandle;
model.forEach(function f(item){
var list = Array.prototype.slice.call(arguments).slice(-1)[0];
if(!(list instanceof $)) list = rootList;

var listItem = $('<li class="dd-item"></li>');
var listElement = $('<div ng-nestable-item class="dd-handle"></div>');
listElement.append(tpl).appendTo(listItem);
var listItem, listElement;
var content = $('<div ng-nestable-item class="dd3-content"></div>');

if (draggableHandle) {
listItem = $('<li class="dd-item dd3-item"></li>');
listElement = $('<div class="dd-handle dd3-handle">&nbsp;</div>');
listElement.appendTo(listItem);
content.append(tpl).appendTo(listItem);

} else {
listItem = $('<li class="dd-item"></li>');
listElement = $('<div ng-nestable-item class="dd-handle"></div>');
listElement.append(tpl).appendTo(listItem);
}

list.append(listItem);
var itemData = $nestable.itemProperty ? item[$nestable.itemProperty] : item;
listItem.data('item', itemData);
Expand Down

0 comments on commit 7e6b01b

Please sign in to comment.