1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-24 05:34:06 +02:00

Allow dragging Twitter account links onto the app to view their profile

Closes 
This commit is contained in:
chylex 2020-02-16 11:35:20 +01:00
parent 175b067a17
commit c2c9160ed9

View File

@ -945,31 +945,42 @@
// Block: Allow drag & drop behavior for dropping links on columns to open their detail view. // Block: Allow drag & drop behavior for dropping links on columns to open their detail view.
// //
execSafe(function supportDragDropOverColumns(){ execSafe(function supportDragDropOverColumns(){
const tweetRegex = /^https?:\/\/twitter\.com\/[A-Za-z0-9_]+\/status\/(\d+)\/?\??/; const regexTweet = /^https?:\/\/twitter\.com\/[A-Za-z0-9_]+\/status\/(\d+)\/?\??/;
const selector = "section.js-column"; const regexAccount = /^https?:\/\/twitter\.com\/(?!signup$|tos$|privacy$|search$|search-)([^/?]+)\/?$/;
let isDraggingValid = false; let dragType = false;
const events = { const events = {
dragover: function(e){ dragover: function(e){
e.originalEvent.dataTransfer.dropEffect = isDraggingValid ? "all" : "none"; e.originalEvent.dataTransfer.dropEffect = dragType ? "all" : "none";
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}, },
drop: function(e){ drop: function(e){
let match = tweetRegex.exec(e.originalEvent.dataTransfer.getData("URL")); let url = e.originalEvent.dataTransfer.getData("URL");
if (match.length === 2){ if (dragType === "tweet"){
let column = TD.controller.columnManager.get($(this).attr("data-column")); let match = regexTweet.exec(url);
if (column){ if (match.length === 2){
TD.controller.clients.getPreferredClient().show(match[1], function(chirp){ let column = TD.controller.columnManager.get($(this).attr("data-column"));
TD.ui.updates.showDetailView(column, chirp, column.findChirp(chirp) || chirp);
$(document).trigger("uiGridClearSelection"); if (column){
}, function(){ TD.controller.clients.getPreferredClient().show(match[1], function(chirp){
alert("error|Could not retrieve the requested tweet."); TD.ui.updates.showDetailView(column, chirp, column.findChirp(chirp) || chirp);
}); $(document).trigger("uiGridClearSelection");
}, function(){
alert("error|Could not retrieve the requested tweet.");
});
}
}
}
else if (dragType === "account"){
let match = regexAccount.exec(url);
if (match.length === 2){
$(document).trigger("uiShowProfile", { id: match[1] });
} }
} }
@ -978,13 +989,20 @@
} }
}; };
const selectors = {
tweet: "section.js-column",
account: app
};
window.TDGF_onGlobalDragStart = function(type, data){ window.TDGF_onGlobalDragStart = function(type, data){
if (type === "link"){ if (dragType){
isDraggingValid = tweetRegex.test(data); app.undelegate(selectors[dragType], events);
app.delegate(selector, events); dragType = null;
} }
else{
app.undelegate(selector, events); if (type === "link"){
dragType = regexTweet.test(data) ? "tweet" : regexAccount.test(data) ? "account": null;
app.delegate(selectors[dragType], events);
} }
}; };
}); });