Skip to content

Instantly share code, notes, and snippets.

@AnalogJ
Last active December 21, 2015 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnalogJ/6360295 to your computer and use it in GitHub Desktop.
Save AnalogJ/6360295 to your computer and use it in GitHub Desktop.
please.js snippet
$(function () {
$('.js-close').click(function() {
window.close();
});
please.init(window);
please.defaults({
// reference to the window to send messages to
targetWindow: window.opener,//$('iframe').get(0).contentWindow,
// what the target window's origin must be for the communication to facilitate
targetOrigin: window.location.protocol + '//' + window.location.host,
// conditionally restrict communication
//sourceOrigin: function (messageEvent) {
// return (/^https?://example.com/.test(messageEvent.origin));
//}
});
//HTML5 PostMessage API. http://benalman.com/projects/jquery-postmessage-plugin/
//http://davidwalsh.name/window-postmessage
////respond to events
//window.addEventListener('message', function (event) {
// if (event.origin !== 'http://localhost:62466') return;
// console.log('message received: ' + event.data, event);
// event.source.postMessage('holla back youngin!', event.origin);
//}, false);
console.log('init')
var s3dropzone = $('#s3dropzone');
s3dropzone.dropzone({
parallelUploads: 2,
maxFilesize: 100, // in mb
acceptedFiles : '.epub,.mobi,.pdf,.prc',
init: function () {
this.on("complete", function() {
console.log('completed', arguments);
});
this.on("success", function(file, resp, event) {
console.log('success', arguments);
var xmlDoc = $.parseXML(resp);
var $xml = $(xmlDoc);
var $location = $xml.find('Location');
var $bucket = $xml.find('Bucket');
var $key = $xml.find('Key');
var data = {};
data.cloudKey = $key.text();
data.cloudBucket = $bucket.text();
data.location = $location.text();
data.fileName = file.name;
var myAjax = $.ajax({
type: "POST",
url: '/Member/Book/UploadBucketUrl',
contentType: 'application/json',
data: JSON.stringify(data)
});
});
this.on('totaluploadprogress', function(progress, totalBytes, totalBytesSent) {
please.call('UploadStatus', {progress: progress, totalBytes: totalBytes, totalBytesSent: totalBytesSent});
});
}
});
});
function UploadStatus(data) {
if (data.progress == 100) {
$('#UploadBooks').button('reset');
} else {
$('#UploadBooks').button('loading');
}
}
$('.js-uploadBooksBtn').click(function () {
var domain = window.location.protocol + '//' + window.location.host;
var myPopup = window.open(domain + '/Member/Home/Dropzone', 'myWindow','height=685,width=650');
please.defaults({
// reference to the window to send messages to
targetWindow: myPopup,//$('iframe').get(0).contentWindow,
// what the target window's origin must be for the communication to facilitate
targetOrigin: domain,
// conditionally restrict communication
//sourceOrigin: function (messageEvent) {
// return (/^https?://example.com/.test(messageEvent.origin));
//}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment