<!DOCTYPE html>
<html>

<head>
  <script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js?ver=4.0'></script>
  <link data-require="bootstrap@*" data-semver="3.2.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
  <script data-require="bootstrap@*" data-semver="3.2.0" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
  <script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
  
  <link rel="stylesheet" href="style-tree.css" />
  
  <link rel="stylesheet" href="nestable.css" />
  
  <script src="script-tree-edit.js"></script>
  
  <script src="nestable.js"></script>
  <script src="page-nestable.js"></script>
  
</head>

<body>
  <div class="container">
    
    <h1>View Document</h1>


    <div class="panel panel-default tree">
      <div class="panel-heading clearfix">
        <h3 class="panel-title pull-left">Doing Business With Fannie Mae</h3>
      </div>
      <div class="panel-body">
        <div class="tree-body">
        
          <ul>
            <li>
              <span class="leaf-content">
                <div class="panel panel-default">
                  <div class="panel-body">
                    <span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> <strong>Doing Business With Fannie Mae</strong>
                    <div class="btn-group pull-right">
                      <button type="button" class="btn btn-default btn-xs">Add child</button>
                      <button type="button" class="btn btn-default btn-xs">Edit</button>
                      <button type="button" class="btn btn-danger btn-xs">Delete</button>
                    </div>
                  </div>
                </div>
              </span>
        
              <ul>
                <li>
                  <span class="leaf-content">
                    <div class="panel panel-default">
                      <div class="panel-body">
                        <span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> A1: Approval Qualification
                       
                      </div>
                    </div>
                  </span>
                  <ul>
                    <li>
                      <span class="leaf-content">
                        <div class="panel panel-default">
                          <div class="panel-body">
                            <span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> A1.1: Application and Approval of Leader
                           
                          </div>
                        </div>
                      </span>
                      <ul>
                        <li>
                          <span class="leaf-content">
                            <div class="panel panel-default">
                              <div class="panel-body">
                                <span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> A1.1.1: Application and Approval of Lender
                              </div>
                            </div>
                          </span>
                        </li>
                      </ul>
                    </li>
                    <li>
                      <span class="leaf-content">
                        <div class="panel panel-default">
                          <div class="panel-body">
                            <span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> A1.2: Lender Contract
                           
                          </div>
                        </div>
                      </span>
                      
                    </li>
                  </ul>
                </li>
                <li>
                  <span class="leaf-content">
                    <div class="panel panel-default">
                      <div class="panel-body">
                        <span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> A2: Getting Started with Fannie Mae
                        
                      </div>
                    </div>
                  </span>
                  <ul>
                    <li>
                      <span class="leaf-content">
                        <div class="panel panel-default">
                          <div class="panel-body">
                            <span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> A2.1: Fannie Mae’s Technology Products
                           
                          </div>
                        </div>
                      </span>
                    </li>
                  </ul>
                </li>
              </ul>
            </li>
          </ul>
        </div>
      </div>
    </div>
    
  <div class="hierarchy">
    
    <div class="dd">
      
      <ol class="dd-list">
        <li class="dd-item" data-id="1">
          <div class="panel panel-default dd-handle">
            <div class="panel-body">
              <span class="list-text">Item 1</span>
            </div>
          </div>
          <ol class="dd-list">
            <li class="dd-item" data-id="2">
              <div class="panel panel-default dd-handle">
                <div class="panel-body">
                  <span class="list-text">Item 1</span>
                </div>
              </div>
              <ol class="dd-list">
                <li class="dd-item" data-id="3">
                  <div class="panel panel-default dd-handle">
                    <div class="panel-body">
                      <span class="list-text">Item 1</span>
                    </div>
                  </div>
                  <ol class="dd-list">
                    <li class="dd-item" data-id="4">
                      <div class="panel panel-default dd-handle">
                        <div class="panel-body">
                          <span class="list-text">Item 1</span>
                        </div>
                      </div>
                    </li>
                  </ol>
                </li>
                <li class="dd-item" data-id="5">
                  <div class="panel panel-default dd-handle">
                    <div class="panel-body">
                      <span class="list-text">Item 1</span>
                    </div>
                  </div>
                </li>
              </ol>
            </li>
            <li class="dd-item" data-id="6">
              <div class="panel panel-default dd-handle">
                <div class="panel-body">
                  <span class="list-text">Item 1</span>
                </div>
              </div>
              <ol class="dd-list">
                <li class="dd-item" data-id="7">
                  <div class="panel panel-default dd-handle">
                    <div class="panel-body">
                      <span class="list-text">Item 1</span>
                    </div>
                  </div>
                </li>
              </ol>
            </li>
          </ol>
        </li>
      </ol>
      
    </div>
    
  </div>
    
    
  </div>
  <!--container-->



</body>

</html>
$(document).ready(function() {
  
  $("#toggle").click(function(){
    $("#slide").slideToggle("slow");
    
    if ($.trim($(this).text()) === 'Minimize') {
      $(this).text('Expand');
      $("#filters").text('Investor: "Fannie Mae";  Program: "Jumbo";  Start Date: "1/1/13"');
    } else {
      $(this).text('Minimize');
      $("#filters").text("");
    }
  });
  
  $('.save').on('click', function(e) {
    
    $(this).addClass('btn-success').removeClass('btn-primary');
    $('.saved-message').css("display", "inline");
    
  });
  
  $('.add-filter').on('click', function(e) {
    var whereToAdd = $(this).parent().parent();
     whereToAdd.after('<div class="row filter-row" style="margin-bottom:10px"><div class="col-md-3 col-sm-3"><select class="form-control"><option>Investor</option><option>Program</option><option>Client</option><option>Start date</option><option>End date</option></select></div><div class="col-md-7 col-sm-7"><div class="form-group"><input type="text" class="form-control" placeholder="Enter field here..." /></div><!-- /input-group --></div><!--col--><div class="col-md-2 col-sm-2"><button type="button" class="btn btn-default remove-filter">Remove filter</span></button></div></div>');
    //give appropriate class to new add buttons and disable other buttons
    //$(this).addClass('disabled');
  });
  
  //$newFilter = $('<div class="row" style="margin-bottom:10px"><div class="col-md-3 col-sm-3"><select class="form-control"><option>Investor</option><option>Program</option><option>Client</option><option>Start Date</option><option>End date</option></select></div><div class="col-md-8 col-sm-8"><div class="input-group"><input type="text" class="form-control" placeholder="Enter field here..." /><span class="input-group-btn"><button class="btn btn-default" type="button">Filter</button></span></div><!-- /input-group --></div><!--col--><div class="col-md-1 col-sm-1"><button type="button" class="btn btn-link add-filter"><span class="glyphicon glyphicon-plus pull-right" style="color:green" aria-hidden="true"></span></button></div></div>');
  
  $('.add-guide').on('click', function(e) {
    var rowToAdd = $(this).parent().parent().parent();
    rowToAdd.append('<tr><td></td><td><a href="frameset.html"><button type="button" class="btn btn-link title">New Guideline</button></a></td><td><button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target=".delete-modal">Delete</span></button></td></tr>');
    
    //give appropriate class to new add buttons and disable other buttons
  });
  
  //$newGuide = $('<tr><td></td><td><a href="frameset.html"><button type="button" class="btn btn-link title">New Guideline</button></a></td><td><button type="button" class="btn btn-link" data-toggle="modal" data-target=".delete-modal"><span class="glyphicon glyphicon-remove" style="color:red" aria-hidden="true"></span></button></td></tr>');
  
});


/* Styles go here */

body {
  margin-top: 50px;
}
.delete-modal .modal-header {
  color: #D9534F;
}
/*
.delete-modal .modal-header {
  background-color:#D9534F;
  color:white;
}
*/

.edit-btn {
  margin: 0px;
  padding-top: 0px;
  padding-bottom: 0px;
}
.body-frame {
  margin: 0px;
}
.title {
  padding-right: 50px;
}
.view-checkbox {
  display: inline;
}
.back {
  margin: 20px;
}
.saved-message {
  color: green;
  font-size: 90%;
  font-weight: bold;
  margin-left: 10px;
  display: none;
}
.remove-filter {
  color: red;
}
.add-filter {
  color: green;
}
#toggle {
  margin: 0px;
}
#filters {
  margin-left: 20px;
  color: #999;
}
.expBtn,
.colBtn {
  padding: 0px;
  margin: 0px;
  background:transparent;
}
.dropdown-icon {
  padding-top:5px;
  padding-bottom:5px;
  padding-left:2px;
  padding-right:2px;
}
.tree-body {
  padding:0px;
  font-size:90%;
}

.tree-body .panel {
  margin:0px;
}

.tree-body {
  padding:0px;
  margin:0px;
}
.tree-body > ul{
    padding-left:0px;
}
.tree-body li {
    list-style-type:none;
    margin:0;
    padding:10px 0px 0px 5px;
    position:relative
}
.tree-body li::before, .tree-body li::after {
    content:'';
    left:-5px;
    position:absolute;
    right:auto
}
/*tree lines*/
.tree-body li::before { 
    border-left:1px solid #999;
    bottom:50px;
    height:100%;
    top:0;
    width:1px
}
.tree-body li::after {
    border-top:1px solid #999;
    height:20px;
    top:25px;
    width:10px
}
/*end tree lines*/
.tree-body li .leaf-content {
    display:inline-block;
    text-decoration:none;
    width:100%;
}
.tree-body li.parent-li>.leaf-content {
    cursor:pointer
}
.tree-body>ul>li::before, .tree-body>ul>li::after {
    border:0
}
.tree-body li:last-child::before {
    height:25px
}

.tree-body li .panel:hover {
    background:#eee;
    color:#000
}


.tree-body li.parent-li>.leaf-content {
    cursor:auto;
}
.tree-body .parent-li> span> div> div> .dropdown-icon {
  cursor:pointer;
}
.tree-body .panel-body {
  padding:5px;
}
.tree-body ul {
  padding-left:20px;
}
$(function() {
  $('.tree-body li:has(ul)').addClass('parent-li').find(' > span');
  
  $('.tree-body li.parent-li > span').on('click', function(e) {
    
    var children = $(this).parent('li.parent-li').find(' > ul > li');
    
    if (children.is(":visible")) {
      children.hide('fast');
      $(this).find('.dropdown-icon').addClass('glyphicon-plus-sign').removeClass('glyphicon-minus-sign');
    } 
    
    else {
      children.show('fast');
      $(this).find('.dropdown-icon').addClass('glyphicon-minus-sign').removeClass('glyphicon-plus-sign');
    }
    
    e.stopPropagation();
    
  });
});
$(function() {
  $('.tree-body li:has(ul)').addClass('parent-li').find(' > span');

  $('.tree-body li.parent-li .dropdown-icon').on('click', function(e) {
    
    var children = $(this).parent().parent().parent().parent('li.parent-li').find(' > ul > li');
    
    if (children.is(":visible")) {
      children.hide('fast');
      $(this).addClass('glyphicon-plus-sign').removeClass('glyphicon-minus-sign');
    } 
    
    else {
      children.show('fast');
      $(this).addClass('glyphicon-minus-sign').removeClass('glyphicon-plus-sign');
    }
    
    e.stopPropagation();
    
  });
  
  $('.add-child').on('click', function(e) {
    var parentToAdd = $(this).parent().parent().parent().parent();
    parentToAdd.append('<ul><li><span class="leaf-content"><div class="panel panel-default"><div class="panel-body"><span class="dropdown-icon glyphicon glyphicon-minus-sign"></span> New Child <a href="edit-frame.html" target="edit-frame"><button type="button" class="btn btn-primary btn-xs pull-right">Edit</button></a><button type="button" class="btn btn-default btn-xs pull-right add-child">Add child</button><button type="button" class="btn btn-warning btn-xs pull-right override">Override</button></div></div></span></li></ul>');

  });
  
});
// Code goes here

/*!
 * Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/
 * Dual-licensed under the BSD or MIT licenses
 */
;(function($, window, document, undefined)
{
    var hasTouch = 'ontouchstart' in document;

    /**
     * Detect CSS pointer-events property
     * events are normally disabled on the dragging element to avoid conflicts
     * https://github.com/ausi/Feature-detection-technique-for-pointer-events/blob/master/modernizr-pointerevents.js
     */
    var hasPointerEvents = (function()
    {
        var el    = document.createElement('div'),
            docEl = document.documentElement;
        if (!('pointerEvents' in el.style)) {
            return false;
        }
        el.style.pointerEvents = 'auto';
        el.style.pointerEvents = 'x';
        docEl.appendChild(el);
        var supports = window.getComputedStyle && window.getComputedStyle(el, '').pointerEvents === 'auto';
        docEl.removeChild(el);
        return !!supports;
    })();

    var defaults = {
            listNodeName    : 'ol',
            itemNodeName    : 'li',
            rootClass       : 'dd',
            listClass       : 'dd-list',
            itemClass       : 'dd-item',
            dragClass       : 'dd-dragel',
            handleClass     : 'dd-handle',
            collapsedClass  : 'dd-collapsed',
            placeClass      : 'dd-placeholder',
            noDragClass     : 'dd-nodrag',
            emptyClass      : 'dd-empty',
            expandBtnHTML   : '<button class="btn expBtn" data-action="expand" type="button"><span class="glyphicon glyphicon-plus-sign"></span></button>',
            collapseBtnHTML : '<button class="btn colBtn" data-action="collapse" type="button"><span class="glyphicon glyphicon-minus-sign"></span></button>',
            group           : 0,
            maxDepth        : 5,
            threshold       : 20
        };

    function Plugin(element, options)
    {
        this.w  = $(document);
        this.el = $(element);
        this.options = $.extend({}, defaults, options);
        this.init();
    }

    Plugin.prototype = {

        init: function()
        {
            var list = this;

            list.reset();

            list.el.data('nestable-group', this.options.group);

            list.placeEl = $('<div class="' + list.options.placeClass + '"/>');

            $.each(this.el.find(list.options.itemNodeName), function(k, el) {
                list.setParent($(el));
            });

            list.el.on('click', 'button', function(e) {
                if (list.dragEl) {
                    return;
                }
                var target = $(e.currentTarget),
                    action = target.data('action'),
                    item   = target.parent(list.options.itemNodeName);
                if (action === 'collapse') {
                    list.collapseItem(item);
                }
                if (action === 'expand') {
                    list.expandItem(item);
                }
            });

            var onStartEvent = function(e)
            {
                var handle = $(e.target);
                if (!handle.hasClass(list.options.handleClass)) {
                    if (handle.closest('.' + list.options.noDragClass).length) {
                        return;
                    }
                    handle = handle.closest('.' + list.options.handleClass);
                }

                if (!handle.length || list.dragEl) {
                    return;
                }

                list.isTouch = /^touch/.test(e.type);
                if (list.isTouch && e.touches.length !== 1) {
                    return;
                }

                e.preventDefault();
                list.dragStart(e.touches ? e.touches[0] : e);
            };

            var onMoveEvent = function(e)
            {
                if (list.dragEl) {
                    e.preventDefault();
                    list.dragMove(e.touches ? e.touches[0] : e);
                }
            };

            var onEndEvent = function(e)
            {
                if (list.dragEl) {
                    e.preventDefault();
                    list.dragStop(e.touches ? e.touches[0] : e);
                }
            };

            if (hasTouch) {
                list.el[0].addEventListener('touchstart', onStartEvent, false);
                window.addEventListener('touchmove', onMoveEvent, false);
                window.addEventListener('touchend', onEndEvent, false);
                window.addEventListener('touchcancel', onEndEvent, false);
            }

            list.el.on('mousedown', onStartEvent);
            list.w.on('mousemove', onMoveEvent);
            list.w.on('mouseup', onEndEvent);

        },

        serialize: function()
        {
            var data,
                depth = 0,
                list  = this;
                step  = function(level, depth)
                {
                    var array = [ ],
                        items = level.children(list.options.itemNodeName);
                    items.each(function()
                    {
                        var li   = $(this),
                            item = $.extend({}, li.data()),
                            sub  = li.children(list.options.listNodeName);
                        if (sub.length) {
                            item.children = step(sub, depth + 1);
                        }
                        array.push(item);
                    });
                    return array;
                };
            data = step(list.el.find(list.options.listNodeName).first(), depth);
            return data;
        },

        serialise: function()
        {
            return this.serialize();
        },

        reset: function()
        {
            this.mouse = {
                offsetX   : 0,
                offsetY   : 0,
                startX    : 0,
                startY    : 0,
                lastX     : 0,
                lastY     : 0,
                nowX      : 0,
                nowY      : 0,
                distX     : 0,
                distY     : 0,
                dirAx     : 0,
                dirX      : 0,
                dirY      : 0,
                lastDirX  : 0,
                lastDirY  : 0,
                distAxX   : 0,
                distAxY   : 0
            };
            this.isTouch    = false;
            this.moving     = false;
            this.dragEl     = null;
            this.dragRootEl = null;
            this.dragDepth  = 0;
            this.hasNewRoot = false;
            this.pointEl    = null;
        },

        expandItem: function(li)
        {
            li.removeClass(this.options.collapsedClass);
            li.children('[data-action="expand"]').hide();
            li.children('[data-action="collapse"]').show();
            li.children(this.options.listNodeName).show();
        },

        collapseItem: function(li)
        {
            var lists = li.children(this.options.listNodeName);
            if (lists.length) {
                li.addClass(this.options.collapsedClass);
                li.children('[data-action="collapse"]').hide();
                li.children('[data-action="expand"]').show();
                li.children(this.options.listNodeName).hide();
            }
        },

        expandAll: function()
        {
            var list = this;
            list.el.find(list.options.itemNodeName).each(function() {
                list.expandItem($(this));
            });
        },

        collapseAll: function()
        {
            var list = this;
            list.el.find(list.options.itemNodeName).each(function() {
                list.collapseItem($(this));
            });
        },

        setParent: function(li)
        {
            if (li.children(this.options.listNodeName).length) {
                li.prepend($(this.options.expandBtnHTML));
                li.prepend($(this.options.collapseBtnHTML));
            }
            li.children('[data-action="expand"]').hide();
        },

        unsetParent: function(li)
        {
            li.removeClass(this.options.collapsedClass);
            li.children('[data-action]').remove();
            li.children(this.options.listNodeName).remove();
        },

        dragStart: function(e)
        {
            var mouse    = this.mouse,
                target   = $(e.target),
                dragItem = target.closest(this.options.itemNodeName);

            this.placeEl.css('height', dragItem.height());

            mouse.offsetX = e.offsetX !== undefined ? e.offsetX : e.pageX - target.offset().left;
            mouse.offsetY = e.offsetY !== undefined ? e.offsetY : e.pageY - target.offset().top;
            mouse.startX = mouse.lastX = e.pageX;
            mouse.startY = mouse.lastY = e.pageY;

            this.dragRootEl = this.el;

            this.dragEl = $(document.createElement(this.options.listNodeName)).addClass(this.options.listClass + ' ' + this.options.dragClass);
            this.dragEl.css('width', dragItem.width());

            dragItem.after(this.placeEl);
            dragItem[0].parentNode.removeChild(dragItem[0]);
            dragItem.appendTo(this.dragEl);

            $(document.body).append(this.dragEl);
            this.dragEl.css({
                'left' : e.pageX - mouse.offsetX,
                'top'  : e.pageY - mouse.offsetY
            });
            // total depth of dragging item
            var i, depth,
                items = this.dragEl.find(this.options.itemNodeName);
            for (i = 0; i < items.length; i++) {
                depth = $(items[i]).parents(this.options.listNodeName).length;
                if (depth > this.dragDepth) {
                    this.dragDepth = depth;
                }
            }
        },

        dragStop: function(e)
        {
            var el = this.dragEl.children(this.options.itemNodeName).first();
            el[0].parentNode.removeChild(el[0]);
            this.placeEl.replaceWith(el);

            this.dragEl.remove();
            this.el.trigger('change');
            if (this.hasNewRoot) {
                this.dragRootEl.trigger('change');
            }
            this.reset();
        },

        dragMove: function(e)
        {
            var list, parent, prev, next, depth,
                opt   = this.options,
                mouse = this.mouse;

            this.dragEl.css({
                'left' : e.pageX - mouse.offsetX,
                'top'  : e.pageY - mouse.offsetY
            });

            // mouse position last events
            mouse.lastX = mouse.nowX;
            mouse.lastY = mouse.nowY;
            // mouse position this events
            mouse.nowX  = e.pageX;
            mouse.nowY  = e.pageY;
            // distance mouse moved between events
            mouse.distX = mouse.nowX - mouse.lastX;
            mouse.distY = mouse.nowY - mouse.lastY;
            // direction mouse was moving
            mouse.lastDirX = mouse.dirX;
            mouse.lastDirY = mouse.dirY;
            // direction mouse is now moving (on both axis)
            mouse.dirX = mouse.distX === 0 ? 0 : mouse.distX > 0 ? 1 : -1;
            mouse.dirY = mouse.distY === 0 ? 0 : mouse.distY > 0 ? 1 : -1;
            // axis mouse is now moving on
            var newAx   = Math.abs(mouse.distX) > Math.abs(mouse.distY) ? 1 : 0;

            // do nothing on first move
            if (!mouse.moving) {
                mouse.dirAx  = newAx;
                mouse.moving = true;
                return;
            }

            // calc distance moved on this axis (and direction)
            if (mouse.dirAx !== newAx) {
                mouse.distAxX = 0;
                mouse.distAxY = 0;
            } else {
                mouse.distAxX += Math.abs(mouse.distX);
                if (mouse.dirX !== 0 && mouse.dirX !== mouse.lastDirX) {
                    mouse.distAxX = 0;
                }
                mouse.distAxY += Math.abs(mouse.distY);
                if (mouse.dirY !== 0 && mouse.dirY !== mouse.lastDirY) {
                    mouse.distAxY = 0;
                }
            }
            mouse.dirAx = newAx;

            /**
             * move horizontal
             */
            if (mouse.dirAx && mouse.distAxX >= opt.threshold) {
                // reset move distance on x-axis for new phase
                mouse.distAxX = 0;
                prev = this.placeEl.prev(opt.itemNodeName);
                // increase horizontal level if previous sibling exists and is not collapsed
                if (mouse.distX > 0 && prev.length && !prev.hasClass(opt.collapsedClass)) {
                    // cannot increase level when item above is collapsed
                    list = prev.find(opt.listNodeName).last();
                    // check if depth limit has reached
                    depth = this.placeEl.parents(opt.listNodeName).length;
                    if (depth + this.dragDepth <= opt.maxDepth) {
                        // create new sub-level if one doesn't exist
                        if (!list.length) {
                            list = $('<' + opt.listNodeName + '/>').addClass(opt.listClass);
                            list.append(this.placeEl);
                            prev.append(list);
                            this.setParent(prev);
                        } else {
                            // else append to next level up
                            list = prev.children(opt.listNodeName).last();
                            list.append(this.placeEl);
                        }
                    }
                }
                // decrease horizontal level
                if (mouse.distX < 0) {
                    // we can't decrease a level if an item preceeds the current one
                    next = this.placeEl.next(opt.itemNodeName);
                    if (!next.length) {
                        parent = this.placeEl.parent();
                        this.placeEl.closest(opt.itemNodeName).after(this.placeEl);
                        if (!parent.children().length) {
                            this.unsetParent(parent.parent());
                        }
                    }
                }
            }

            var isEmpty = false;

            // find list item under cursor
            if (!hasPointerEvents) {
                this.dragEl[0].style.visibility = 'hidden';
            }
            this.pointEl = $(document.elementFromPoint(e.pageX - document.body.scrollLeft, e.pageY - (window.pageYOffset || document.documentElement.scrollTop)));
            if (!hasPointerEvents) {
                this.dragEl[0].style.visibility = 'visible';
            }
            if (this.pointEl.hasClass(opt.handleClass)) {
                this.pointEl = this.pointEl.parent(opt.itemNodeName);
            }
            if (this.pointEl.hasClass(opt.emptyClass)) {
                isEmpty = true;
            }
            else if (!this.pointEl.length || !this.pointEl.hasClass(opt.itemClass)) {
                return;
            }

            // find parent list of item under cursor
            var pointElRoot = this.pointEl.closest('.' + opt.rootClass),
                isNewRoot   = this.dragRootEl.data('nestable-id') !== pointElRoot.data('nestable-id');

            /**
             * move vertical
             */
            if (!mouse.dirAx || isNewRoot || isEmpty) {
                // check if groups match if dragging over new root
                if (isNewRoot && opt.group !== pointElRoot.data('nestable-group')) {
                    return;
                }
                // check depth limit
                depth = this.dragDepth - 1 + this.pointEl.parents(opt.listNodeName).length;
                if (depth > opt.maxDepth) {
                    return;
                }
                var before = e.pageY < (this.pointEl.offset().top + this.pointEl.height() / 2);
                    parent = this.placeEl.parent();
                // if empty create new list to replace empty placeholder
                if (isEmpty) {
                    list = $(document.createElement(opt.listNodeName)).addClass(opt.listClass);
                    list.append(this.placeEl);
                    this.pointEl.replaceWith(list);
                }
                else if (before) {
                    this.pointEl.before(this.placeEl);
                }
                else {
                    this.pointEl.after(this.placeEl);
                }
                if (!parent.children().length) {
                    this.unsetParent(parent.parent());
                }
                if (!this.dragRootEl.find(opt.itemNodeName).length) {
                    this.dragRootEl.append('<div class="' + opt.emptyClass + '"/>');
                }
                // parent root list has changed
                if (isNewRoot) {
                    this.dragRootEl = pointElRoot;
                    this.hasNewRoot = this.el[0] !== this.dragRootEl[0];
                }
            }
        }

    };

    $.fn.nestable = function(params)
    {
        var lists  = this,
            retval = this;

        lists.each(function()
        {
            var plugin = $(this).data("nestable");

            if (!plugin) {
                $(this).data("nestable", new Plugin(this, params));
                $(this).data("nestable-id", new Date().getTime());
            } else {
                if (typeof params === 'string' && typeof plugin[params] === 'function') {
                    retval = plugin[params]();
                }
            }
        });

        return retval || lists;
    };

})(window.jQuery || window.Zepto, window, document);
/**
 * Nestable
 */

.dd {
  position: relative;
  display: block;
  margin: 0;
  padding: 0;
  max-width: 600px;
  list-style: none;
  line-height: 20px;
}
.dd-list {
  display: block;
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}
.dd-list .dd-list {
  padding-left: 20px;
}
.dd-collapsed .dd-list {
  display: none;
}
.dd-item,
.dd-empty,
.dd-placeholder {
  display: block;
  position: relative;
  margin: 0;
  padding: 0;
  min-height: 20px;
  line-height: 20px;
}
.dd-handle {
  /*
  display: block;
  height: 30px;
  margin: 5px 0;
  padding: 5px 10px;
  
  font-weight: bold;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-sizing: border-box;
  */
}
.dd-handle:hover {
  background: #eee;
}

.panel-body {
  padding:5px;
}

.panel {
  margin:0px;
}

/*
.dd-item > button {
  display: block;
  position: relative;
  cursor: pointer;
  float: left;
  width: 25px;
  height: 20px;
  margin: 5px 0;
  padding: 0;
  text-indent: 100%;
  white-space: nowrap;
  overflow: hidden;
  border: 0;
  background: transparent;
  font-size: 12px;
  line-height: 1;
  text-align: center;
  font-weight: bold;
}
.dd-item > button:before {
  content: '+';
  display: block;
  position: absolute;
  width: 100%;
  text-align: center;
  text-indent: 0;
}
.dd-item > button[data-action="collapse"]:before {
  content: '-';
}
*/

.dd-placeholder,
.dd-empty {
  margin: 5px 0;
  padding: 0;
  min-height: 30px;
  background: #f2fbff;
  border: 1px dashed #b6bcbf;
  box-sizing: border-box;
}
.dd-empty {
}
.dd-dragel {
  position: absolute;
  pointer-events: none;
  z-index: 9999;
}
.dd-dragel > .dd-item .dd-handle {
  margin-top: 0;
}
.dd-dragel .dd-handle {
  
}


/**
 * Nestable Extras


.nestable-lists {
  display: block;
  clear: both;
  padding: 30px 0;
  width: 100%;
  border: 0;
  border-top: 2px solid #ddd;
  border-bottom: 2px solid #ddd;
}
#nestable-menu {
  padding: 0;
  margin: 20px 0;
}
#nestable-output,
#nestable3-output {
  width: 100%;
  height: 7em;
  font-size: 0.75em;
  line-height: 1.333333em;
  font-family: Consolas, monospace;
  padding: 5px;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
}
#nestable2 .dd-handle {
  color: #fff;
  border: 1px solid #999;
  background: #bbb;
  background: -webkit-linear-gradient(top, #bbb 0%, #999 100%);
  background: -moz-linear-gradient(top, #bbb 0%, #999 100%);
  background: linear-gradient(top, #bbb 0%, #999 100%);
}
#nestable2 .dd-handle: hover {
  background: #bbb;
}
#nestable2 .dd-item > button: before {
  color: #fff;
}
@media only screen and (min-width: 700px) {
  .dd {
    float: left;
    width: 48%;
  }
  .dd + .dd {
    margin-left: 2%;
  }
}
.dd-hover > .dd-handle {
  background: #2ea8e5 !important;
}
 */



/**
 * Nestable Draggable Handles
 

.dd3-content {
  display: block;
  height: 30px;
  margin: 5px 0;
  padding: 5px 10px 5px 40px;
  color: #333;
  text-decoration: none;
  font-weight: bold;
  border: 1px solid #ccc;
  background: #fafafa;
  background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
  background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
  background: linear-gradient(top, #fafafa 0%, #eee 100%);
  -webkit-border-radius: 3px;
  border-radius: 3px;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
}
.dd3-content: hover {
  color: #2ea8e5;
  background: #fff;
}
.dd-dragel > .dd3-item > .dd3-content {
  margin: 0;
}
.dd3-item > button {
  margin-left: 30px;
}
.dd3-handle {
  position: absolute;
  margin: 0;
  left: 0;
  top: 0;
  cursor: pointer;
  width: 30px;
  text-indent: 100%;
  white-space: nowrap;
  overflow: hidden;
  border: 1px solid #aaa;
  background: #ddd;
  background: -webkit-linear-gradient(top, #ddd 0%, #bbb 100%);
  background: -moz-linear-gradient(top, #ddd 0%, #bbb 100%);
  background: linear-gradient(top, #ddd 0%, #bbb 100%);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.dd3-handle: before {
  content: '≡';
  display: block;
  position: absolute;
  left: 0;
  top: 3px;
  width: 100%;
  text-align: center;
  text-indent: 0;
  color: #fff;
  font-size: 20px;
  font-weight: normal;
}
.dd3-handle: hover {
  background: #ddd;
}dle: hover {
  background: #ddd;
}

*/
$(document).ready(function()
{

    var updateOutput = function(e)
    {
        var list   = e.length ? e : $(e.target),
            output = list.data('output');
        if (window.JSON) {
            output.val(window.JSON.stringify(list.nestable('serialize')));//, null, 2));
        } else {
            output.val('JSON browser support required for this demo.');
        }
    };

    $('.dd').nestable({
        group: 1
    });


    // activate Nestable for list 1
    $('#nestable').nestable({
        group: 1
    })
    .on('change', updateOutput);

    // activate Nestable for list 2
    $('#nestable2').nestable({
        group: 1
    })
    .on('change', updateOutput);

    // output initial serialised data
    updateOutput($('#nestable').data('output', $('#nestable-output')));
    updateOutput($('#nestable2').data('output', $('#nestable2-output')));

    $('#nestable-menu').on('click', function(e)
    {
        var target = $(e.target),
            action = target.data('action');
        if (action === 'expand-all') {
            $('.dd').nestable('expandAll');
        }
        if (action === 'collapse-all') {
            $('.dd').nestable('collapseAll');
        }
    });

    $('#nestable3').nestable().on('change', updateOutput);
    updateOutput($('#nestable3').data('output', $('#nestable3-output')));

    Socialite.load();

});
/* Styles go here */




/**
 * Nestable
 */

.dd { position: relative; display: block; margin: 0; padding: 0; max-width: 600px; list-style: none; font-size: 13px; line-height: 20px; }

.dd-list { display: block; position: relative; margin: 0; padding: 0; list-style: none; }
.dd-list .dd-list { padding-left: 30px; }
.dd-collapsed .dd-list { display: none; }

.dd-item,
.dd-empty,
.dd-placeholder { display: block; position: relative; margin: 0; padding: 0; min-height: 20px; font-size: 13px; line-height: 20px; }

.dd-handle { display: block; height: 30px; margin: 5px 0; padding: 5px 10px; color: #333; text-decoration: none; font-weight: bold; border: 1px solid #ccc;
    background: #fafafa;
    background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
    background:    -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
    background:         linear-gradient(top, #fafafa 0%, #eee 100%);
    -webkit-border-radius: 3px;
            border-radius: 3px;
    box-sizing: border-box; -moz-box-sizing: border-box;
}
.dd-handle:hover { color: #2ea8e5; background: #fff; }

.dd-item > button { display: block; position: relative; cursor: pointer; float: left; width: 25px; height: 20px; margin: 5px 0; padding: 0; text-indent: 100%; white-space: nowrap; overflow: hidden; border: 0; background: transparent; font-size: 12px; line-height: 1; text-align: center; font-weight: bold; }
.dd-item > button:before { content: '+'; display: block; position: absolute; width: 100%; text-align: center; text-indent: 0; }
.dd-item > button[data-action="collapse"]:before { content: '-'; }

.dd-placeholder,
.dd-empty { margin: 5px 0; padding: 0; min-height: 30px; background: #f2fbff; border: 1px dashed #b6bcbf; box-sizing: border-box; -moz-box-sizing: border-box; }
.dd-empty { border: 1px dashed #bbb; min-height: 100px; background-color: #e5e5e5;
    background-image: -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
                      -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
    background-image:    -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
                         -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
    background-image:         linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
                              linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
    background-size: 60px 60px;
    background-position: 0 0, 30px 30px;
}

.dd-dragel { position: absolute; pointer-events: none; z-index: 9999; }
.dd-dragel > .dd-item .dd-handle { margin-top: 0; }
.dd-dragel .dd-handle {
}

/**
 * Nestable Extras
 */

.nestable-lists { display: block; clear: both; padding: 30px 0; width: 100%; border: 0; border-top: 2px solid #ddd; border-bottom: 2px solid #ddd; }

#nestable-menu { padding: 0; margin: 20px 0; }

#nestable-output,
#nestable3-output { width: 100%; height: 7em; font-size: 0.75em; line-height: 1.333333em; font-family: Consolas, monospace; padding: 5px; box-sizing: border-box; -moz-box-sizing: border-box; }

#nestable2 .dd-handle {
    color: #fff;
    border: 1px solid #999;
    background: #bbb;
    background: -webkit-linear-gradient(top, #bbb 0%, #999 100%);
    background:    -moz-linear-gradient(top, #bbb 0%, #999 100%);
    background:         linear-gradient(top, #bbb 0%, #999 100%);
}
#nestable2 .dd-handle:hover { background: #bbb; }
#nestable2 .dd-item > button:before { color: #fff; }

@media only screen and (min-width: 700px) {

    .dd { float: left; width: 48%; }
    .dd + .dd { margin-left: 2%; }

}

.dd-hover > .dd-handle { background: #2ea8e5 !important; }

/**
 * Nestable Draggable Handles
 */

.dd3-content { display: block; height: 30px; margin: 5px 0; padding: 5px 10px 5px 40px; color: #333; text-decoration: none; font-weight: bold; border: 1px solid #ccc;
    background: #fafafa;
    background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
    background:    -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
    background:         linear-gradient(top, #fafafa 0%, #eee 100%);
    -webkit-border-radius: 3px;
            border-radius: 3px;
    box-sizing: border-box; -moz-box-sizing: border-box;
}
.dd3-content:hover { color: #2ea8e5; background: #fff; }

.dd-dragel > .dd3-item > .dd3-content { margin: 0; }

.dd3-item > button { margin-left: 30px; }

.dd3-handle { position: absolute; margin: 0; left: 0; top: 0; cursor: pointer; width: 30px; text-indent: 100%; white-space: nowrap; overflow: hidden;
    border: 1px solid #aaa;
    background: #ddd;
    background: -webkit-linear-gradient(top, #ddd 0%, #bbb 100%);
    background:    -moz-linear-gradient(top, #ddd 0%, #bbb 100%);
    background:         linear-gradient(top, #ddd 0%, #bbb 100%);
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.dd3-handle:before { content: '≡'; display: block; position: absolute; left: 0; top: 3px; width: 100%; text-align: center; text-indent: 0; color: #fff; font-size: 20px; font-weight: normal; }
.dd3-handle:hover { background: #ddd; }