jQuery UI Droppable with Bootstrap Navbar - How to drop a item inside Dropdown -


i using jquery ui droppable bootstrap menu navigation...

i want drag element item "menu items" dropdown , drop inside "my apps" dropdown. dropped element should go inside "my apps > ul > li" hidden default untill click on apps link.

ps: my apps <li> item

everything working except dropping directly "my apps > li" element instead of "my apps > ul > li".

i have tried "$("#header-my-apps>li").appendto("#header-my-apps ul.h-droped-list");" without luck :(

pease me out.


fiddle


jquery

/* menu items drag n drop create short cuts in favorites bar */ $(document).ready(function () {      $('.rp-draggable li').not('li.pd-dropdown').each(function (i) {         $(this).attr('uuid', +i);     });      $("#header-my-apps>li").appendto("#header-my-apps ul.h-droped-list");      /* jquery droppable */     $(function () {         $(".rp-draggable li").not('li.pd-dropdown').draggable({             helper: "clone",             placeholder: "ui-state-highlight",         });         $("#header-my-apps").droppable({             activeclass: "ui-state-default",             hoverclass: "ui-state-hover",             accept: ":not(.ui-sortable-helper)",             drop: function (event, ui) {                 $(this).find(".placeholder").hide();                 $(ui.draggable).addclass("addedtofav").clone().appendto(this);             }         }).sortable({             items: "li:not(.placeholder)",             sort: function () {                 $(this).removeclass("ui-state-default");             }         });     });       /* click star icon add drop here container */     $('ul.rp-draggable li .fa-star-o').click(function () {         var $target = $(this).closest("li"),             $dropedlist = $(".h-droped-list"),             id = $target.attr("uuid");          if (!$target.hasclass("addedtofav")) {             $target.addclass("addedtofav").clone().appendto($dropedlist);             $dropedlist.find(".placeholder").hide();             $('#header-my-apps>a').addclass("animated tada");             settimeout(function() {                 $("#header-my-apps>a").removeclass('animated tada');             }, 1500);         } else {             $dropedlist.find("li")             .each(function (index, item) {                 var $elem = $(item);                  if ($elem.attr("uuid") == id) {                     $elem.remove();                     $target.removeclass("addedtofav");                 }                  if ($dropedlist.children().length == 1) {                     var $lastitem = $($dropedlist.children()[0]);                     $lastitem.hasclass("placeholder") && $lastitem.show();                 }             })         }      });      /* click close icon remove drop here container */     $("ul.h-droped-list").on('click', 'li .fa-star-o', function () {         var $target = $(this).closest("li"),             $catalog = $("#catalog ul"),             id = $target.attr("uuid"),             $droplist = $target.parent("ul");          $target.remove();          $catalog.find("li[uuid='"+id+"']").removeclass("addedtofav");          if ($droplist.children().length == 1) {             var $lastitem = $($droplist.children()[0]);             $lastitem.hasclass("placeholder") && $lastitem.show();         }      });  }); 

html

<nav class="navbar navbar-default">     <div class="container-fluid">                 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">             <ul class="nav navbar-nav rp-draggable">                  <!-- draggable block -->                 <li class="dropdown">                     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">menu items <span class="caret"></span></a>                     <ul class="dropdown-menu rp-draggable" role="menu" id="catalog">                         <li><a href="#">link 1</a></li>                         <li><a href="#">link 2</a></li>                         <li><a href="#">link 3</a></li>                     </ul>                 </li>                 <!-- /draggable block -->                  <!-- droppable block -->                 <li class="dropdown" id="header-my-apps">                     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i id="icon-my-apps"></i> <span class="hma-text"><i class="fa fa-star-o"></i>my apps</span></a>                     <div class="dropdown-menu header-favorites" role="menu">                         <ul class="h-droped-list">                             <li class="placeholder">my favs</li>                         </ul>                     </div>                 </li>                 <!-- /droppable block -->              </ul>          </div><!-- /.navbar-collapse -->     </div><!-- /.container-fluid --> </nav> 

please ignore junk code while copied project directly

that's because appending element this i.e. #header-my-apps , not ul class h-droped-list. made below changes in $("#header-my-apps").droppable({ part , hope that's want:

var dropplace=$(this).find('ul.h-droped-list');        $(ui.draggable).addclass("addedtofav").clone().appendto(dropplace); 

demo here


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -