Browse Source

Update BlockView, avoid false positives with the Sorter

pull/261/head
Artur Arseniev 9 years ago
parent
commit
9f39cdf026
  1. 21
      src/block_manager/view/BlockView.js
  2. 7
      src/block_manager/view/BlocksView.js
  3. 4
      src/utils/Sorter.js

21
src/block_manager/view/BlockView.js

@ -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() {

7
src/block_manager/view/BlocksView.js

@ -73,7 +73,8 @@ module.exports = Backbone.View.extend({
* @private * @private
*/ */
onDrop(model) { onDrop(model) {
this.em.runDefault(); const em = this.em;
em.runDefault();
if (model && model.get) { if (model && model.get) {
if(model.get('activeOnRender')) { if(model.get('activeOnRender')) {
@ -82,9 +83,9 @@ module.exports = Backbone.View.extend({
} }
// Register all its components (eg. for the Undo Manager) // Register all its components (eg. for the Undo Manager)
this.em.initChildrenComp(model); em.initChildrenComp(model);
em.trigger('block:drag:stop', model);
} }
this.em.trigger('block:drag:stop', model);
}, },
/** /**

4
src/utils/Sorter.js

@ -769,8 +769,10 @@ module.exports = Backbone.View.extend({
} }
} }
if(this.moved) if (this.moved) {
created = this.move(this.target, src, this.lastPos); created = this.move(this.target, src, this.lastPos);
}
if(this.plh) if(this.plh)
this.plh.style.display = 'none'; this.plh.style.display = 'none';

Loading…
Cancel
Save