Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <!-- <link href="//cdn.jsdelivr.net/picnicss/4.1.1/picnic.min.css" rel="stylesheet"> -->
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <nav>
    <h1>Hello Mag.JS!</h1>
    <a target="_top" href="https://github.com/magnumjs/mag.js">GitHub</a>
  </nav>
  <article class="card">
    <header>
      <h2>Reorder list</h2>
    </header>
    <footer>
      <div id="reorder">
        <p>Drag and drop list items to reorder them</p>
        <ul class="zoom">
          <li><a id="one" href="#" draggable="true">one</a>
          </li>
        </ul>
      </div>
    </footer>
  </article>
  <script src="//rawgit.com/magnumjs/mag.js/master/mag-latest.min.js"></script>
  <script src="//rawgit.com/magnumjs/mag.js/master/dist/mag.addons.0.22.min.js"></script>
  <script src="//cdn.rawgit.com/timruffles/ios-html5-drag-drop-shim/master/release/index.min.js"></script>
  <script>
    MobileDragDrop.polyfill()
  </script>
</body>
</html>
 
.cloak,
li:empty,
.hide {
  display: none;
}
.mainButton {
  font-size: 1.5em;
}
a {
  display: block;
}
a:after {
  content: " \bb";
}
nav a {
  float: right;
  margin-top: -50px;
}
body {
  background: #fff;
  text-align: left;
  width: 90%;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 0 0;
}
nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3em;
  padding: 0 .6em;
  background: #fff;
  box-shadow: 0 0 0.2em rgba(17, 17, 17, 0.2);
  z-index: 10000;
  transition: all .3s;
  transform-style: preserve-3d;
}
header {
  font-weight: bold;
  position: relative;
  border-bottom: 1px solid #eee;
  padding: .6em .8em;
}
footer {
  padding: .8em;
}
article {
  top: 100px;
}
.card {
  max-width: 100%;
  display: block;
  position: relative;
  box-shadow: 0;
  border-radius: .2em;
  border: 1px solid #ccc;
  overflow: hidden;
  text-align: left;
  background: #fff;
  margin-bottom: .6em;
  padding: 6px;
  transition: all .3s ease;
}
/* draggable list */
.zoom {
  transition: transform 500ms;
}
li {
  list-style: none;
}
li a {
  text-decoration: none;
  color: #000;
  margin: 10px;
  width: 80%;
  border: 3px dashed #999;
  background: #eee;
  padding: 15px;
  display: block;
  text-align: center;
}
*[draggable=true] {
  -moz-user-select: none;
  -khtml-user-drag: element;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  cursor: move;
}
*:-khtml-drag {
  background-color: rgba(238, 238, 238, 0.5);
}
li a {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  /*only to disable context menu on long press*/
}
ul {
  min-height: 300px;
  padding: 0;
  list-style-type: none;
}
li.over {
  border-color: red;
  background: #ccc;
 
}
li.over a {
  opacity:0;
}
li.move {
  border-color: red;
  background: #ccc;
  opacity:0;
}
 
/* Mag.JS Example - Drag and Drop - reorder list
From: https://html5demos.com/drag/  */
var Reorder = {};
Reorder.controller = function(props) {
  //Map props to state:
  this.components = props.components;
}
Reorder.view = function(state, props) {
  //Map state to UI:
  state.li = state.components.map((item, index) => {
    return {
      _class: item.className,
      _text: item.name,
      a: {
        _id: index
      },
      _ondragover: e => {
        e.preventDefault()
        e.stopPropagation()
        state.components[index].className = 'over'
      },
      _onDragEnter: e => {
        e.preventDefault()
        e.stopPropagation()
      },
      _onDragEnd: e => {
        e.stopPropagation()
        state.components[state.selected].className = '';
      },
      _ondragLeave: e => {
        e.preventDefault()
        e.stopPropagation()
        state.components[index].className = ''
      },
      _ondrop: function(e) {
        e.preventDefault()
        e.stopPropagation();
        //switch items
        var current = state.components[index];
        state.components[index] = state.components[state.selected];
        state.components[state.selected] = current;
        //remove class
        state.components[index].className = ''
      },
      _ondragstart: function(e) {
        e.stopPropagation()
        state.components[index].className = 'move'
        state.selected = index
      }
    }
  })
};
var props = {
  components: [{
    name: "Apples"
  }, {
    name: "Oranges"
  }, {
    name: "Pineapples"
  }, {
    name: "Bananas"
  }]
}
mag.module("reorder", Reorder, props);
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers