Page MenuHomePhabricator

Inputs should recognize copy-pasted links to Wikidata items
Closed, DuplicatePublic

Description

If one copies a link to a Wikidata item and pastes it into a text field requiring a Wikidata item, the JS should accept it as directly being the item itself, not just the raw text to be used to help find the item. Acting on every copy-paste might slow performance a slight amount, but I think it would be worth it. The code getting the contents of the paste could look something very roughly like this:

$input.on("paste", function (e) {

try {
    var oEvt = e.originalEvent, 
        href;
    if (oEvt.clipboardData && oEvt.clipboardData.getData) {
        var clp = oEvt.clipboardData.getData('text/html');
        href = $("<p>").html(clp).find("a").attr("href");
    } else if (document.queryCommandEnabled("paste")) {
        var $pasteBox = $('<p>').attr("contenteditable", "true").insertBefore( $input ).focus();
        document.execCommand("paste");
        href = $pasteBox.find("a").attr("href");
        $pasteBox.remove();
    }
    var itemId = href && href.match(/Q\d+$/); // preferably with a more thorough check than this...
    if (itemId) {
        // do some stuff with itemId
        return false;
    }
} catch (err) {};

});


Version: unspecified
Severity: normal
Whiteboard: u=dev c=backend p=0

Details

Reference
bz61354

Related Objects