3 Polymer('core-drag-drop', {
6 'x y': 'coordinatesChanged'
10 if (!this.__proto__.avatar) {
11 this.__proto__.avatar = document.createElement('core-drag-avatar');
12 document.body.appendChild(this.avatar);
14 this.dragging = false;
17 draggingChanged: function() {
18 this.avatar.style.display = this.dragging ? '' : 'none';
21 coordinatesChanged: function() {
22 var x = this.x, y = this.y;
23 this.avatar.style.transform =
24 this.avatar.style.webkitTransform =
25 'translate(' + x + 'px, ' + y + 'px)';
28 attached: function() {
29 var listen = function(event, handler) {
30 Polymer.addEventListener(this.parentNode, event, this[handler].bind(this));
33 listen('trackstart', 'trackStart');
34 listen('track', 'track');
35 listen('trackend', 'trackEnd');
37 var host = this.parentNode.host || this.parentNode;
38 host.style.cssText += '; user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none;';
41 trackStart: function(event) {
42 this.avatar.style.cssText = '';
47 this.fire('drag-start', this.dragInfo);
48 // flaw #1: what if user doesn't need `drag()`?
49 this.dragging = Boolean(this.dragInfo.drag);
52 track: function(event) {
56 this.dragInfo.event = event;
57 this.dragInfo.p = {x : this.x, y: this.y};
58 this.dragInfo.drag(this.dragInfo);
62 trackEnd: function(event) {
64 this.dragging = false;
65 if (this.dragInfo.drop) {
66 this.dragInfo.framed = this.framed(event.relatedTarget);
67 this.dragInfo.event = event;
68 this.dragInfo.drop(this.dragInfo);
74 framed: function(node) {
75 var local = node.getBoundingClientRect();
76 return {x: this.x - local.left, y: this.y - local.top};