All Downloads are FREE. Search and download functionalities are using the official Maven repository.

a.hyperscala-ui_2.11.0.9.1.source-code.drop_receiver.js Maven / Gradle / Ivy

There is a newer version: 0.10.3
Show newest version
function createDropReceiver(id) {
    var receiver = $('#' + id);
    receiver.on('dragover', function(evt) {
        return cancelDropReceiver(evt);
    });
    receiver.on('dragenter', function(evt) {
        return cancelDropReceiver(evt);
    });
    receiver.on('drop', function(evt) {
        evt.preventDefault();       // Avoid redirecting page to dropped resource
        window.dropEvent = evt;
        var originalEvent = evt.originalEvent;
        var dataTransfer = originalEvent.dataTransfer;
        var types = dataTransfer.types;
        if (types == null) {
            types = [];
        }
        var files = dataTransfer.files;
        var receiveTypes = receiver.data('receive-types');
        var data = {};
        for (var i = 0; i < types.length; i++) {
            var type = types[i];
            var acceptable = receiveTypes.indexOf(type) > -1;
            if (acceptable) {
                var s = dataTransfer.getData(type);
                s = decodeURI(encodeURI(s).replace(/%00/g, ''));
                data[type] = s;
            }
        }
        // TODO: add support for files
        realtimeSend(id, 'dropped', {
            types: types,
            data: data
        });
    });
}

function cancelDropReceiver(evt) {      // Avoid default implementation of drag functionality
    if (evt.preventDefault) {
        evt.preventDefault();
    }
    return false;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy