Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag ref count #59

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions addon/components/pl-uploader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Ember from 'ember';
import DinoSheet from 'dinosheets';
import trim from '../system/trim';
import w from '../computed/w';

Expand All @@ -24,14 +23,6 @@ var isDragAndDropSupported = (function () {
};
}());

var styleSheet;
var sharedStyleSheet = function () {
if (styleSheet == null) {
styleSheet = new DinoSheet();
}
return styleSheet;
};

var slice = Array.prototype.slice;

export default Ember.Component.extend({
Expand Down Expand Up @@ -137,7 +128,7 @@ export default Ember.Component.extend({
// Send up the pluploader object so the app implementing this component as has access to it
var pluploader = queue.get('queues.firstObject');
this.sendAction('onInitOfUploader', pluploader);
this._dragInProgress = false;
this._dragCounter = 0;
this._invalidateDragData();
},

Expand All @@ -151,6 +142,7 @@ export default Ember.Component.extend({

keys(handlers).forEach(function (key) {
Ember.$(document).on(key, '#' + dropzoneId, handlers[key]);
Ember.$(document).on(key, '.moxie-shim', handlers[key]);
});
}
},
Expand All @@ -161,9 +153,6 @@ export default Ember.Component.extend({
queue.orphan();
set(this, 'queue', null);
}
let sheet = sharedStyleSheet();
sheet.css(`#${get(this, 'dropzone.id')} *`, null);
sheet.applyStyles();
}),

teardownDragListeners: Ember.on('willDestroyElement', function () {
Expand All @@ -172,41 +161,39 @@ export default Ember.Component.extend({
var handlers = this.eventHandlers;
keys(handlers).forEach(function (key) {
Ember.$(document).off(key, '#' + dropzoneId, handlers[key]);
Ember.$(document).off(key, '.moxie-shim', handlers[key]);
});
this.eventHandlers = null;
}
}),

dragData: null,
enteredDropzone({ originalEvent: evt }) {
if (this._dragInProgress === false) {
this._dragInProgress = true;
this.activateDropzone(evt);
enteredDropzone(evt) {
var e = evt.originalEvent;
if (e.preventDefault) { e.preventDefault(); }
if (e.stopPropagation) { e.stopPropagation(); }
if (this._dragCounter === 0) {
this.activateDropzone(evt.originalEvent);
}
this._dragCounter++;
},

leftDropzone() {
if (this._dragInProgress === true) {
this._dragInProgress = false;
leftDropzone(evt) {
var e = evt.originalEvent;
if (e.preventDefault) { e.preventDefault(); }
if (e.stopPropagation) { e.stopPropagation(); }
this._dragCounter--;
if (this._dragCounter === 0) {
this.deactivateDropzone();
}
},

activateDropzone(evt) {
let sheet = sharedStyleSheet();
sheet.css(`#${get(this, 'dropzone.id')} *`, {
pointerEvents: 'none'
});
Ember.run.scheduleOnce('render', sheet, 'applyStyles');
set(this, 'dragData', get(evt, 'dataTransfer'));
},

deactivateDropzone() {
let sheet = sharedStyleSheet();
sheet.css(`#${get(this, 'dropzone.id')} *`, null);
Ember.run.scheduleOnce('render', sheet, 'applyStyles');

this._dragInProgress = false;
this._dragCounter = 0;
set(this, 'dragData', null);
},

Expand Down