Dojo dnd target and page load

My question is related to the dnd example (step 4: listening for events) posted at http://www.sitepen.com/blog/2011/12/05/dojo-drag-n-drop-redux/ .

In my case, I have several dnd sources that span multiple pages. How to write data to the shopping cart (target) so that the items in it do not disappear after loading different pages and so that users can still discard more items?

Any hints would be greatly appreciated!

+3
source share
2 answers

see dojotoolkit.org

Documents don't seem to be located upstream for 1.7 lists, however

subscribe to a set of topics and you will know when / what is drawn

dojo.topic.subsribe

  • /dnd/ start: DnD. , (. startDrag() ) .
  • ./dnd/ source/over: . . , . .
  • /dnd/ drop/before: . . , /DND/ .
  • /dnd/ drop: . , /dnd/start. . , . , /dnd/drop/before, , / .
  • /dnd/ cancel: DnD ( Esc), . .

:

dojo.subscribe("dnd/start", function(source, nodes, copy) {
  // see dojo.dnd.startDrag documentation for details
  // this event will process when user picks up a dnditem
  console.log("Arguments:", arguments);

};
dojo.subscribe("dnd/drop", function(source, nodes, copy, target) {
  // see dojo.dnd.startDrag documentation for details
  // this event will process when user releases dnditem on a valid target
  // note the extra parameter, target - in 99% cases a DOM node
  console.log("Arguments:", arguments);
});

, - dndmanager dojo.publish( "dnd/start", this.source, this.selection, this.bCopy). .

dojo.topic , , ,

+1

, ,

<script>
    function dropped(source, nodes, copy, target) {
      if(target.id == "myCardId") {
        var list = dojo.cookie("mycart");
        // split or initialize list (delimiter : comma)
        list = list = "" ? [] : list.split(",");
        if(dojo.indexOf(nodes[0].id), list) != -1)
           // allready there, return
           return;
        else {
           // combine list with every dropped node
           dojo.forEach(nodes, function(dropItem) { list.push(dropItem.id); });
           // set cookie with new variable
           dojo.cookie("mycart", list.join(",");
        }
      }
    }

    ....
   dojo.subscribe("dnd/drop", dropped);
</script>

PHP , , , , - db_data;

<?php

if(isset($_COOKIE) && !empty($_COOKIE['mycart'])) {
   $cartContents = "<ul class=\"dndContainer\">";
   foreach(explode(",", $_COOKIE['mycart']) as $id)
      $cartContents .= "<li class=\"dndItem\">".$db_data[$id]->title."</li>";
   $cartContent .= "</ul>";
}
?>
<div id="dragSource"><? print generateView(); ?></div>
<div id="myCartId"><? print $cartContents; ?></div>

,    script XHR ,   , , javascript, -   $ _COOKIE $_SESSION

0

All Articles