Skip to content

Commit

Permalink
Merge pull request ipython-contrib#831 from juhasch/fix/dragdrop
Browse files Browse the repository at this point in the history
Use util function for upload to add authentication
  • Loading branch information
juhasch committed Jan 6, 2017
2 parents bb7410c + 2e3907c commit bc53717
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ define([
type : "PUT",
data: data,
contentType: 'application/json',
dataType : "json",
dataType : "json"
};
IPython.utils.promising_ajax(IPython.contents.api_url(path), settings);
}
utils.promising_ajax(IPython.contents.api_url(path), settings);
};

var send_to_server = function(name, msg) {
var path = utils.url_path_join(utils.url_path_split(IPython.notebook.notebook_path)[0], params.subdirectory);
Expand All @@ -73,15 +73,18 @@ define([
data : JSON.stringify(data),
headers : {'Content-Type': 'text/plain'},
async : false,
success : function (data, status, xhr) {
error : function() {console.log('Data transfer for drag-and-drop failed.'); }
};
utils.promising_ajax(url, settings).then(
function on_success (data, status, xhr) {
var new_cell = IPython.notebook.insert_cell_below('markdown');
var str = '<img src="' + utils.url_path_join(params.subdirectory, name) + '"/>';
new_cell.set_text(str);
new_cell.execute();
},
error : function() {console.log('Data transfer for drag-and-drop failed.'); }
};
$.ajax(url, settings);
},
function on_error (reason) {
console.log('Data transfer for drag-and-drop failed.');
});
};

/* the dragover event needs to be canceled to allow firing the drop event */
Expand Down

0 comments on commit bc53717

Please sign in to comment.