Giter VIP home page Giter VIP logo

nestable2's Introduction

Nestable2

At this moment I really don't have any spare time to maintain this package. 
If there is anyone that wants to help me out with this, please message me trough a issue of mail.

Drag & drop hierarchical list with mouse and touch compatibility (jQuery / Zepto plugin)

Status Demo Build Status License NPM version Bower version

Nestable is an experimental example and IS under active development. If it suits your requirements feel free to expand upon it!

Install

You can install this package either with npm or with bower.

npm

npm install --save nestable2

Then add a <script> to your index.html:

<script src="/node_modules/nestable2/jquery.nestable.js"></script>

Or require('nestable2') from your code.

bower

bower install --save nestable2

CDN

You can also find us on CDNJS:

//cdnjs.cloudflare.com/ajax/libs/nestable2/1.6.0/jquery.nestable.min.css
//cdnjs.cloudflare.com/ajax/libs/nestable2/1.6.0/jquery.nestable.min.js

You can also find us on jsDelivr

//cdn.jsdelivr.net/npm/[email protected]/jquery.nestable.min.js
//cdn.jsdelivr.net/npm/[email protected]/jquery.nestable.min.css

Usage

Write your nested HTML lists like so:

<div class="dd">
    <ol class="dd-list">
        <li class="dd-item" data-id="1">
            <div class="dd-handle">Item 1</div>
        </li>
        <li class="dd-item" data-id="2">
            <div class="dd-handle">Item 2</div>
        </li>
        <li class="dd-item" data-id="3">
            <div class="dd-handle">Item 3</div>
            <ol class="dd-list">
                <li class="dd-item" data-id="4">
                    <div class="dd-handle">Item 4</div>
                </li>
                <li class="dd-item" data-id="5" data-foo="bar">
                    <div class="dd-nodrag">Item 5</div>
                </li>
            </ol>
        </li>
    </ol>
</div>

Then activate with jQuery like so:

$('.dd').nestable({ /* config options */ });

Events

change: For using an .on handler in jquery

The callback provided as an option is fired when elements are reordered or nested.

$('.dd').nestable({
    callback: function(l,e){
        // l is the main container
        // e is the element that was moved
    }
});

onDragStart callback provided as an option is fired when user starts to drag an element. Returning false from this callback will disable the dragging.

$('.dd').nestable({
    onDragStart: function(l,e){
        // l is the main container
        // e is the element that was moved
    }
});

This callback can be used to manipulate element which is being dragged as well as whole list. For example you can conditionally add .dd-nochildren to forbid dropping current element to some other elements for instance based on data-type of current element and other elements:

$('.dd').nestable({
    onDragStart: function (l, e) {
        // get type of dragged element
        var type = $(e).data('type');
        
        // based on type of dragged element add or remove no children class
        switch (type) {
            case 'type1':
                // element of type1 can be child of type2 and type3
                l.find("[data-type=type2]").removeClass('dd-nochildren');
                l.find("[data-type=type3]").removeClass('dd-nochildren');
                break;
            case 'type2':
                // element of type2 cannot be child of type2 or type3
                l.find("[data-type=type2]").addClass('dd-nochildren');
                l.find("[data-type=type3]").addClass('dd-nochildren');
                break;
            case 'type3':
                // element of type3 cannot be child of type2 but can be child of type3
                l.find("[data-type=type2]").addClass('dd-nochildren');
                l.find("[data-type=type3]").removeClass('dd-nochildren');
                break;
            default:
                console.error("Invalid type");
        }
    }
});

beforeDragStop callback provided as an option is fired when user drop an element and before 'callback' method fired. Returning false from this callback will disable the dropping and restore element at start position.

$('.dd').nestable({
    beforeDragStop: function(l,e, p){
        // l is the main container
        // e is the element that was moved
        // p is the place where element was moved.
    }
});

Methods

serialize: You can get a serialised object with all data-* attributes for each item.

$('.dd').nestable('serialize');

The serialised JSON for the example above would be:

[{"id":1},{"id":2},{"id":3,"children":[{"id":4},{"id":5,"foo":"bar"}]}]

toArray:

$('.dd').nestable('toArray');

Builds an array where each element looks like:

{
    'depth': depth,
    'id': id,
    'left': left,
    'parent_id': parentId || null,
    'right': right
}

You can get a hierarchical nested set model like below.

$('.dd').nestable('asNestedSet');

The output will be like below:

[{"id":1,"parent_id":"","depth":0,"lft":1,"rgt":2},{"id":2,"parent_id":"","depth":0,"lft":3,"rgt":4},{"id":3,"parent_id":"","depth":0,"lft":5,"rgt":10},{"id":4,"parent_id":3,"depth":1,"lft":6,"rgt":7},{"id":5,"parent_id":3,"depth":1,"lft":8,"rgt":9}]

add: You can add any item by passing an object. New item will be appended to the root tree.

$('.dd').nestable('add', {"id":1,"children":[{"id":4}]});

Optionally you can set 'parent_id' property on your object and control in which place in tree your item will be added.

$('.dd').nestable('add', {"id":1,"parent_id":2,"children":[{"id":4}]});

replace: You can replace existing item in tree by passing an object with 'id' property.

$('.dd').nestable('replace', {"id":1,"foo":"bar"});

You need to remember that if you're replacing item with children's you need to pass this children's in object as well.

$('.dd').nestable('replace', {"id":1,"children":[{"id":4}]});

remove: You can remove existing item by passing 'id' of this element. To animate item removing check effect config option. This will delete the item with all his children.

$('.dd').nestable('remove', 1);

This will invoke callback function after deleting the item with data-id '1'.

$('.dd').nestable('remove', 1, function(){
    console.log('Item deleted');
});

removeAll: Removes all items from the list. To animate items removing check effect config option. You can also use callback function to do something after removing all items.

$('.dd').nestable('removeAll', function(){
    console.log('All items deleted');
});

destroy: You can deactivate the plugin by running

$('.dd').nestable('destroy');

Autoscroll while dragging

Autoscrolls the container element while dragging if you drag the element over the offsets defined in scrollTriggers config option.

$('.dd').nestable({ scroll: true });

To use this feature you need to have jQuery >= 1.9 and scrollParent() method. You can be find this method in jQuery UI or if you don't want to have jQuery UI as a dependency you can use this repository.

You can also control the scroll sensitivity and speed, check scrollSensitivity and scrollSpeed options.

On the fly nestable generation

You can passed serialized JSON as an option if you like to dynamically generate a Nestable list:

<div class="dd" id="nestable-json"></div>

<script>
var json = '[{"id":1},{"id":2},{"id":3,"children":[{"id":4},{"id":5,"foo":"bar"}]}]';
var options = {'json': json}
$('#nestable-json').nestable(options);
</script>

NOTE: serialized JSON has been expanded so that an optional "content" property can be passed which allows for arbitrary custom content (including HTML) to be placed in the Nestable item

Or do it yourself the old-fashioned way:

<div class="dd" id="nestable3">
    <ol class='dd-list dd3-list'>
        <div id="dd-empty-placeholder"></div>
    </ol>
</div>

<script>
$(document).ready(function(){
    var obj = '[{"id":1},{"id":2},{"id":3,"children":[{"id":4},{"id":5}]}]';
    var output = '';
    function buildItem(item) {

        var html = "<li class='dd-item' data-id='" + item.id + "'>";
        html += "<div class='dd-handle'>" + item.id + "</div>";

        if (item.children) {

            html += "<ol class='dd-list'>";
            $.each(item.children, function (index, sub) {
                html += buildItem(sub);
            });
            html += "</ol>";

        }

        html += "</li>";

        return html;
    }

    $.each(JSON.parse(obj), function (index, item) {

        output += buildItem(item);

    });

    $('#dd-empty-placeholder').html(output);
    $('#nestable3').nestable();
});
</script>

Configuration

You can change the follow options:

  • maxDepth number of levels an item can be nested (default 5)
  • group group ID to allow dragging between lists (default 0)
  • callback callback function when an element has been changed (default null)
  • scroll enable or disable the scrolling behaviour (default: false)
  • scrollSensitivity mouse movement needed to trigger the scroll (default: 1)
  • scrollSpeed speed of the scroll (default: 5)
  • scrollTriggers distance from the border where scrolling become active (default: { top: 40, left: 40, right: -40, bottom: -40 })
  • effect removing items animation effect (default: { animation: 'none', time: 'slow'}). To fadeout elements set 'animation' value to 'fade', during initialization the plugin.

These advanced config options are also available:

  • contentCallback The callback for customizing content (default function(item) {return item.content || '' ? item.content : item.id;})
  • listNodeName The HTML element to create for lists (default 'ol')
  • itemNodeName The HTML element to create for list items (default 'li')
  • rootClass The class of the root element .nestable() was used on (default 'dd')
  • listClass The class of all list elements (default 'dd-list')
  • itemClass The class of all list item elements (default 'dd-item')
  • dragClass The class applied to the list element that is being dragged (default 'dd-dragel')
  • noDragClass The class applied to an element to prevent dragging (default 'dd-nodrag')
  • handleClass The class of the content element inside each list item (default 'dd-handle')
  • collapsedClass The class applied to lists that have been collapsed (default 'dd-collapsed')
  • noChildrenClass The class applied to items that cannot have children (default 'dd-nochildren')
  • placeClass The class of the placeholder element (default 'dd-placeholder')
  • emptyClass The class used for empty list placeholder elements (default 'dd-empty')
  • expandBtnHTML The HTML text used to generate a list item expand button (default '<button data-action="expand">Expand></button>')
  • collapseBtnHTML The HTML text used to generate a list item collapse button (default '<button data-action="collapse">Collapse</button>')
  • includeContent Enable or disable the content in output (default false)
  • listRenderer The callback for customizing final list output (default function(children, options) { ... } - see defaults in code)
  • itemRenderer The callback for customizing final item output (default function(item_attrs, content, children, options) { ... } - see defaults in code)
  • json JSON string used to dynamically generate a Nestable list. This is the same format as the serialize() output

Inspect the Nestable2 Demo for guidance.

Change Log

21th October 2017

  • [klgd] Fixed conflict when project using also jQuery 2.*
  • [RomanBurunkov] Moved effect and time parameter in remove method to config option. This changes break backward compatibility with version 1.5
  • [RomanBurunkov] Added callback in methods remove and removeAll as a parameter
  • [RomanKhomyshynets] Fixed add function with non-leaf parent_id, fixed #84

9th August 2017

  • [pjona] Added support for string (GUID) as a data id

21th July 2017

  • [spathon] Append the .dd-empty div if the list don't have any items on init, fixed #52
  • [pjona] Fixed problem on Chrome with touch screen and mouse, fixed #28 and#73

15th July 2017

  • [RomanBurunkov] Added fadeOut support to remove method
  • [pjona] Fixed replace method (added collapse/expand buttons when item has children), see #69
  • [uniring] Added autoscroll while dragging, see #71

2nd July 2017

  • [pjona] Added CDN support
  • [pjona] Removed unneeded directories in dist/

25th June 2017

  • [pjona] Fixed add method when using parent_id, see #66

22th June 2017

  • [pjona] Added Travis CI builds after each commit and pull request
  • [pjona] Added test task in gulp with eslint validation
  • [pjona] Added minified version of JS and CSS
  • [pjona] Changed project name to nestable2
  • [pjona] Fixed remove method when removing last item from the list

16th June 2017

  • [imliam] Added support to return false from the onDragStart event to disable the drag event

28th May 2017

  • [pjona] Function add support parent_id property
  • [pjona] Added replace function
  • [pjona] Added remove function

22th May 2017

  • [pjona] Added npm installation
  • [pjona] Added add function

10th April 2017

  • [timalennon] Added functions: toHierarchy and toArray

17th November 2015

  • [oimken] Added destroy function

2nd November 2015

  • [ivanbarlog] Added onDragStart event fired when user starts to drag an element

21th April 2015

  • [ozdemirburak] Added asNestedSet function
  • [ozdemirburak] Added bower installation

6th October 2014

  • [zemistr] Created listRenderer and itemRenderer. Refactored build from JSON.
  • [zemistr] Added support for adding classes via input data. ([{"id": 1, "content": "First item", "classes": ["dd-nochildren", "dd-nodrag", ...] }, ... ])

3rd October 2014

  • [zemistr] Added support for additional data parameters.
  • [zemistr] Added callback for customizing content.
  • [zemistr] Added parameter "includeContent" for including / excluding content from the output data.
  • [zemistr] Added fix for input data. (JSON string / Javascript object)

7th April 2014

  • New pickup of repo for developement.

14th March 2013

13th March 2013

  • [tchapi] Replace previous change behaviour with a callback

12th February 2013

  • Merge fix from [jails] : Fix change event triggered twice.

3rd December 2012

  • [dbushell] add no-drag class for handle contents
  • [dbushell] use el.closest instead of el.parents
  • [dbushell] fix scroll offset on document.elementFromPoint()

15th October 2012

  • Merge for Zepto.js support
  • Merge fix for remove/detach items

27th June 2012

  • Added maxDepth option (default to 5)
  • Added empty placeholder
  • Updated CSS class structure with options for listClass and itemClass.
  • Fixed to allow drag and drop between multiple Nestable instances (off by default).
  • Added group option to enabled the above.

Original Author: David Bushell http://dbushell.com @dbushell

New Author : Ramon Smit http://ramonsmit.nl @ramonsmit94

Contributors :

Copyright © 2012 David Bushell / © Ramon Smit 2014/2017 | BSD & MIT license

nestable2's People

Contributors

2metres avatar baskan avatar dark-cms avatar dbushell avatar hakoniemi avatar imliam avatar ivanbarlog avatar jails avatar johnsardine avatar klgd avatar lhl avatar nate-strauser avatar oimken avatar pjona avatar ramonsmit avatar romanburunkov avatar sevban avatar teymur-mardaliyev avatar timomeh avatar zemistr avatar zgldh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nestable2's Issues

'dd-nodrag' not working

I've tried to set "dd-nodrag" to several items, but it just doens't work.

example:

<ol class="dd-list">
    <li data-id="1" class="dd-item"><div class="dd-handle dd-nodrag">test 1</div></li>
    <li data-id="2" class="dd-item"><div class="dd-handle dd-nodrag">test 2</div></li>
    <li data-id="3" class="dd-item"><div class="dd-handle">test 3</div></li>
    <ol class="dd-list">
        <li data-id="4" class="dd-item"><div class="dd-handle dd-nodrag>test 4</div></li>
        <li data-id="5" class="dd-item"><div class="dd-handle">test 5</div></li>
    </ol>
    <li data-id="6" class="dd-item"><div class="dd-handle">test 6</div></li>    
</ol>

I looked into the javascript code, and in the onStartEven method, i think I found a bug.
In the first "if-statement" there is this.

if(!handle.hasClass(list.options.handleClass)) {

When I remove the "!" .. it works again.

if(handle.hasClass(list.options.handleClass)) {

Replace doesn't appear to work correctly

Using the following code:

            nestableElement.nestable('replace', {
                id: replaceId,
                name: name,
                label: name,
                slug: slug,
                css_class: cssClass,
                children: children
            });

where children is similar to the following object:

[{
        "css_class" : "",
        "slug" : "/distributors/find",
        "id" : 1472820817026,
        "label" : "Find A Distributor",
        "name" : "Find A Distributor"
    }, {
        "css_class" : "",
        "slug" : "/distributors/become",
        "id" : 1472820818729,
        "label" : "Become A Distributor",
        "name" : "Become A Distributor"
    }, {
        "css_class" : "",
        "slug" : "/distributors/suggest",
        "id" : 1472820819257,
        "label" : "Suggest A Distributor",
        "name" : "Suggest A Distributor"
    }
]

It results in a new li being created inside the existing li, and the expand/collapse doesn't display. The following is copied from Chrome:

<li data-name="Distributors" data-label="Distributors" data-id="1472139716346" data-url="/distributors" data-css_class="" data-is_open="true" class="dd-item">
<li data-id="1472139716346" data-name="Distributors" data-label="Distributors" data-url="/distributors" data-css_class="" class="dd-item">
   <div class="dd-handle"><span class="dd-content">Distributors</span></div>
   <div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
   <ol class="dd-list">
      <li data-css_class="" data-url="/distributors/find" data-id="1472820817026" data-label="Find A Distributor" data-name="Find A Distributor" class="dd-item">
         <div class="dd-handle"><span class="dd-content">Find A Distributor</span></div>
         <div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
      </li>
      <li data-css_class="" data-url="/distributors/become" data-id="1472820818729" data-label="Become A Distributor" data-name="Become A Distributor" class="dd-item">
         <div class="dd-handle"><span class="dd-content">Become A Distributor</span></div>
         <div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
      </li>
      <li data-css_class="" data-url="/distributors/suggest" data-id="1472820819257" data-label="Suggest A Distributor" data-name="Suggest A Distributor" class="dd-item">
         <div class="dd-handle"><span class="dd-content">Suggest A Distributor</span></div>
         <div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
      </li>
   </ol>
</li>
</li>

I'm using a custom itemRenderer:

function (item_attrs, content, children, options, item) {
                        var item_attrs_string = $.map(item_attrs, function (value, key) {
                            return ' ' + key + '="' + value + '"';
                        }).join(' ');

                        if (!item.label) {
                            setTimeout(function () {
                                $('[data-id=' + item.id + ']').find('.dd-handle').effect('highlight', {color: '#dff0d8'}, 2000);
                            }, 100);
                        }

                        var html = '<' + options.itemNodeName + item_attrs_string + '>';
                        html += '<' + options.handleNodeName + ' class="' + options.handleClass + '">';
                        html += '<' + options.contentNodeName + ' class="' + options.contentClass + '">';
                        html += content;
                        html += '</' + options.contentNodeName + '>';
                        html += '</' + options.handleNodeName + '><div class="dd-options">' +
                            "<button class='btn btn-sm btn-success add' data-toggle='tooltip' data-placement='top' title='' " +
                            "data-original-title='Add'> " +
                            "<i class='fa fa-plus-square'></i>" +
                            "</button>" +
                            "<button class='btn btn-sm btn-info edit' data-toggle='tooltip' data-placement='top' title='' " +
                            "data-original-title='Edit'> " +
                            "<i class='fa fa-edit'></i>" +
                            "</button>" +
                            "<button class='btn btn-sm btn-danger delete' data-toggle='tooltip' data-placement='top' title='' " +
                            "data-original-title='Delete'> " +
                            "<i class='fa fa-trash'></i>" +
                            "</button>" +
                            "</div>";
                        html += children;
                        html += '</' + options.itemNodeName + '>';

                        return html;
                    }

I can't see that I'm doing anything wrong here. I've inspected the nestable source and I'd suggest the replace function should use replaceWith() instead html():

replace: function (item)
        {
            var html = this._buildItem(item, this.options);
            this._getItemById(item.id).replaceWith(html);
        }

This appears to fix the HTML structure issue but the expand/collapse still doesn't display. Are you able and available to help?

Many thanks

Demo will not work in Windows 8.1 and Firefox 30 or later

Tried the demo both included in the package as well as another one at http://daltcore.net/nestable/nestable_demo.html. Neither let me do anything as far as dragging or dropping. It will let me collapse and expand, but not drag and drop.

It does not seem to want to let the mouse pick up the item to drag like it will in Chrome and IE.
I am on Windows 8.1 running Firefox 31.
Now I tested it on Windows 7 with the same version of Firefox and it works. So much fun!

Again it works with Chrome and IE on Windows 8, just nor Firefox.

Links are not click-able in Label

Expected behavior

I tried to add a link for each element to edit or delete a specific element.

Actual behavior

On clicking on the a-tags the e.preventDefault() seems to trigger, so that i can't get the on.click event :(

Steps to reproduce the behavior

<div class="dd" id="modal_1500296184866-nestable-list">
  <ol class="dd-list" id="modal_1500296184866-structList-first">
    <li class="dd-item" data-id="1" data-title="test">
      <div class="dd-handle blue white-text">
        test
        <div class="right">
          <a class="pointer white-text margin-r10 modal_1500296184866-struct-edit" data-id="1" title="Bearbeiten">
            <i class="fa fa-pencil" aria-hidden="true"></i>
          </a>
          <a class="pointer white-text modal_1500296184866-struct-delete" data-id="1" title="Löschen">
            <i class="fa fa-trash" aria-hidden="true"></i>
          </a>
        </div>
        <div class="clear-fix"></div>
      </div>
    </li>
  </ol>
</div>

I was thinking of a new feature

Hi there,

I was thinking of a new feature, which will make the nestable as levels, what I mean by that (not easy to explain)

lets say that we have 4 levels of lists as follows for example:

Sales Director
Sales Managers
Sales Supervisors
Salesmen
each one of these levels especially 3rd and 4th level, needs to be locked. What I mean is that salesman can be moved from a sales supervisor to another sales supervisor but can't be a sales supervisor or sales manager or sales director so he/she must be locked as a salesman in terms of level, but can jump from a branch to another branch.

Same thing with sales supervisor can be moved with his/her salesmen from a sales manager to another sales manager but can't be promoted to a sales manager and can't become a salesman. AND So On...

Thank you,

P.S.: I am welling to sponsor that feature to make the developer get some support.

Add: custom layout wrong

Expected behavior

When adding an item using:
$('.dd').nestable('add', {"id":1,"children":[{"id":4}]});
..it would be nice if the layout would consider a custom build function. Like when using:
buildItem(item) { ... }

Actual behavior

When adding an item, the default layout is used for a new item.

Steps to reproduce the behavior

Use a custom layout with:
buildItem(item) { ... }
Then use:
$('.dd').nestable('add', {"id":1,"children":[{"id":4}]});

Collapse items

If i create a cookie with an array of id's to store the collapsed items, how can I collapse all items from the array when I'm the tree gets rendered?

Issue with touch detection in Firefox

hasTouch is returning a false positive in the below version of Firefox which means that the drag/drop ability of the plugin stops working.

jQuery: 1.12.4
Firefox: 50.1.0

Make call to jQuery in demo protocol relative

Jquery is being called like:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

and should be called like:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

so that drag and drop works for people viewing the demo over HTTPS:

https://dbushell.github.io/Nestable/

If the demo gets served from the master branch, that line is:

https://github.com/RamonSmit/Nestable/blob/master/index.html#L449

New release and Bower

Hi,

Since this project is under active development again, could you please distribute a new release?

The last version (1.2.3) dates back to 27 February and some new features (such as asNestedSet method) are not available. It would be useful to get a more recent release available via Bower.

Can't drag item to the end of the list right after item with children if use draggable handle

Considering example from demo page: https://ramonsmit.github.io/Nestable2/

Example for 'Draggable Handles'(the last one).

Expected behavior

Drag should work for any position in the list.

Actual behavior

e.g.
I'm not able to drag item14 after item 15 if item 15 expanded.

Steps to reproduce the behavior

  1. Go to https://ramonsmit.github.io/Nestable2/.
  2. Drag item 14.
  3. Try to drop it right after Item 15 to the end of the list.

Tried in latest FF and Chrome.
But it works fine if don't use additional draggable handle.

Consolidating Pull Requests, Issues

Hey, Ramon, so I was looking at Nestable and the various forks out there. Seems like yours is the most recent/active. It's also the only one that changed the README.md as something that you wanted to maintain (and has no outstanding pull requests).

Just wondering if this is something you're going to actively work on? If so, it might be worth:

Regardless, I plan on using this as a codebase for some projects so if you're responsive to pull requests that'd be great, just checking in!

Restrict drag/drop to certain depths

Is there a way to restrict an item to a certain depth in the tree?

For instance, let's say I'm displaying "folders" and "files". I want to restrict files to only be re-ordered in their folders or be dropped into other folders. Folder should only be sortable within their own level.

Also, how do you prevent something from being dropped at the root level? Putting dd-nochildren on the root list seems to prevent targeting any level of the list.

I've tried achieving this with the onDragStart even and adding dd-nochildren, but I can't seem to get it right.

Levels

Hi there,

my maximum menu depth is 3.
Is it possible that a main menu item (depth/level 1) has a menu item with depth/level 3 (without using a level 2 item)?
Right now I am only to make it work with a menu item with depth/level 2 inbetween.

I hope someone can help me with this!
Thank you (and sorry for my english)!

Demo is not a demo

You reference your demo page in the Readme but does not have a demo of the current abilities of Nestable.

distance option

Need option that 'Distance the mouse has to travel to start dragging'.

Do not delete the selected item

Hi!

Version: 1.6

I'm trying to delete the selected item, but it does not delete.
My code is from the example:

visible.nestable('remove', id, function(){
        console.log(id);
      });

In this case, the ID of the element to be deleted is displayed in the console.

nestable.css is overly onerous

How about reducing nestable.css to what's needed to actually function? I mean really .dd { max-width: 600px; }?

Even the requirement to add the dd, dd-list, and dd-item (I can see dd-handle, but even that could have a default) is unnecessary: you can figure out who gets what class assigned upon the initial nestable call.

My initial code didn't use the included CSS (from the nestable 1 days). I used jquery to assign the classes and just styled what I needed. Worked great. Until I dragged the cursor out of the nestable div. THen, all by LIs disappeared. Still don't know why. Ended up removing all my custom CSS and included nestable.css and it worked. Nothing in my structure changed.

Want Drag Copy of Item to another List not Moving

Expected behavior

HI!
Want Drag Item to another List and Item should remain in Previous List and also added to another list. (Clone option)

Actual behavior

There is an option (clone) for this purpose in Nestable-1 . but when we use it it duplicates the list even we click or drag back to same list.

Steps to reproduce the behavior

Fork this template to reproduce issue.

dd-nochildren not working as expected

Drag a item above dd-nochildren item just not show the placeholder, but if it have children by default and you drop it, it will become a children anyway.

Items sometimes hide

Hello, when i m start dragging some li tag some another li are hidden... When i m start drag last li tag all li elements are hidden except my dragged.. It was happens to anyone? I do some mistake?
Btw HTML structure is copied and here is javascript code:
$('.dd').nestable();

Thanks.

Add package.json

Hi, I'm interesting by adding npm support via package.json. Is it possible ?

not maintained

Its hard do determine how beneficial this branch is, it has not been updated since october, nor is it an actual fork of nestable, which is odd. It is hard to determine its worth and it doesn't show up in nestables network.

It might be good to establish a roadmap , especially since the readme still even links to nestables demos

I am trying to determine which pull requests against dbushell have been merged in here, and what issues need to be preserved as outstanding.

has everyone moved to a new library?

Nestable became draggable?

Am i the only one experiencing this. This just happened, idk.
It ruined my whole system. The nestable became draggable, i can now drag the panels in which of the objects in it dont functio anymore. What happened? I tried it on different units, still the same results i got. Is this because of the browser or what? I need help pls? T_T

Find element

Hi, me again.
I am working in a funcionality, based in you plugin. So, my quietion is
It is possible to find an element based on its id, ie when clicking a link go to the element, even if it is inside another element collapsed.

Nestable not working on Chrome

I copied the example which you provided in the code tab.
I exactly copy and past the following

  1. html
  2. javascript code
  3. your library (js and css file)

simply 'nestable' is not working on chrome version 55.0.2883.87 m (currently latest version)
-note: the chrome console does NOT give me any errors, it is clean

but it's working on Firefox correctly (version 50.1.0)

Any help. Thanks in Advanced

Add first child via 'add' method doesn't add collapse/expand buttons

I've tested add method and found out one issue when adding item with parent_id.
When adding first child to parent with id parent_id, add method doesn't add expand/colapse buttons and further we have no chance to add them from user side. Looks like we should use setParent method which already exist. But I'm not quite sure where to add it.

Bug: Insertion of duplicate items when trying to use 'add' with parent_id

Hi! There is a bug in Add function. When we try to add new item with setting parent_id, where parent item is non-leaf element, a new item appends to the parent item and to each its descendant.
For example, there is a code from your Demo-page:
https://jsfiddle.net/RomanKhomyshynets/4vogfw6o/1/
When we bind for "Add new item" button such actions
if(action === 'add-item') { var newItem = { "id": ++lastId, "content": "New Item " + lastId, "parent_id":2 }; $('#nestable').nestable('add', newItem); }
Nestable inserts "New item 13" two times - as a child of Item 2 and child of Item 5.

Horizontal sorting

I know there are some other scripts out there that offer the possibility to sort blocks horizontally, RubaXa/Sortable is a popular one.

The big drawback is that this script doesn't have the "nested" ability. So is it possible to create an option so that your script also would work horizontally? Without the nesting then of course.

Thanks!

Add default css as file

It would be nice to have the css from the index.html as a seperate file, to allow it to be used by bower

scrolling on top while element moving

hello,
when you drag an element with a scroll on a parent container with elements, scrolling effects only on down side, but when you drag on top,it doesn't makes an effect.
that is.
thanks.

Unable to catch click events from contentClass

I'm trying to attach data to items using data attributes. What I need is a way for the click event to bubble up so I can access the $(event.target).data( 'myattr' );

Right now the event target is always the outermost container.

Is there a way to do this?

Improve bower support

You should put the index.html in the bower ignore tag, its not really needed, or at least use an empty ignore tag so bower stops complaining.

For versioning you could take a look at http://bower.io/docs/api/#version , it seems to create git tags automatically, and keeps the bower.json in sync.

CDN Support

It would be useful to provide CDN support for this plugin

scroll not working

I try to move an item in a div with scroll, but dont up and dont down scroll when the item is in top or bottom div.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.