JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="app">
<div ng-controller="testCtrl">
<table id="testtable">
<tr>
<td colspan="2" droppable>
<a data-ng-repeat="firstLink in first" href="#">
{{firstLink.text}}
</a>
</td>
</tr>
<tr>
<td>
<a data-ng-repeat="secondLink in second" href="#" draggable>
{{secondLink.text}}
</a>
</td>
<td>
<a data-ng-repeat="thirdLink in third" href="#" draggable>
{{thirdLink.text}}
</a>
</td>
</tr>
</table>
</div>
</div>
CSS
#testtable {
margin: 0px auto;
}
#testtable td {
text-align: center;
margin: 10px;
border: 1px solid black;
}
#testtable a {
margin: 10px;
}
JavaScript
var app = angular.module('app', []);
app.controller('testCtrl', function ($scope) {
$scope.first = [
{text: 1},
{text: 2},
{text: 3}
];
$scope.second = [
{text: 4},
{text: 5},
{text: 6}
];
$scope.third = [
{text: 7},
{text: 8},
{text: 9}
];
});
app.directive('draggable', function () {
return function(scope, element) {
// this gives us the native JS object
var el = element[0];
el.draggable = true;
el.addEventListener(
'dragstart',
function(e) {
console.log('dragstart called');
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('Text', 'test test test');
return false;
},
false
);
el.addEventListener(
'dragend',
function(e) {
console.log('dragend called');
e.preventDefault();
return false;
},
false
);
}
});
app.directive('droppable', function () {
return {
scope: {
drop: '&' // parent
},
link: function(scope, element) {
var el = element[0];
console.log(el);
el.addEventListener(
'drop',
function(e) {
console.log('Why im not called?');
return false;
},
false
);
}
}
});