|
|
@ -3,11 +3,11 @@ var Backbone = require('backbone'); |
|
|
module.exports = Backbone.View.extend({ |
|
|
module.exports = Backbone.View.extend({ |
|
|
|
|
|
|
|
|
events: { |
|
|
events: { |
|
|
mousedown: 'onDrag' |
|
|
mousedown: 'startDrag' |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
initialize(o, config) { |
|
|
initialize(o, config) { |
|
|
_.bindAll(this, 'onDrop'); |
|
|
_.bindAll(this, 'endDrag'); |
|
|
this.config = config || {}; |
|
|
this.config = config || {}; |
|
|
this.ppfx = this.config.pStylePrefix || ''; |
|
|
this.ppfx = this.config.pStylePrefix || ''; |
|
|
this.listenTo(this.model, 'destroy remove', this.remove); |
|
|
this.listenTo(this.model, 'destroy remove', this.remove); |
|
|
@ -18,7 +18,7 @@ module.exports = Backbone.View.extend({ |
|
|
* Start block dragging |
|
|
* Start block dragging |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
onDrag(e) { |
|
|
startDrag(e) { |
|
|
//Right or middel click
|
|
|
//Right or middel click
|
|
|
if (e.button !== 0) { |
|
|
if (e.button !== 0) { |
|
|
return; |
|
|
return; |
|
|
@ -33,16 +33,23 @@ module.exports = Backbone.View.extend({ |
|
|
sorter.setDragHelper(this.el, e); |
|
|
sorter.setDragHelper(this.el, e); |
|
|
sorter.startSort(this.el); |
|
|
sorter.startSort(this.el); |
|
|
sorter.setDropContent(this.model.get('content')); |
|
|
sorter.setDropContent(this.model.get('content')); |
|
|
this.doc.on('mouseup', this.onDrop); |
|
|
this.doc.on('mouseup', this.endDrag); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Drop block |
|
|
* Drop block |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
onDrop() { |
|
|
endDrag(e) { |
|
|
this.doc.off('mouseup', this.onDrop); |
|
|
this.doc.off('mouseup', this.endDrag); |
|
|
this.config.getSorter().endMove(); |
|
|
const sorter = this.config.getSorter(); |
|
|
|
|
|
|
|
|
|
|
|
// After dropping the block in the canvas the mouseup event is not yet
|
|
|
|
|
|
// triggerd on 'this.doc' and so clicking outside, the sorter, tries to move
|
|
|
|
|
|
// things (throws false positives). As this method just need to drop away
|
|
|
|
|
|
// the block helper I use the trick of 'moved = 0' to void those errors.
|
|
|
|
|
|
sorter.moved = 0; |
|
|
|
|
|
sorter.endMove(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
|