Markan.js is a jQuery plugin to add a dialog on text selection. Inspired by Medium and RapGenius.

Download on GitHub

Usage

$('p.tweet-this').markan({
  dialog: function(range) {
    var selected = encodeURIComponent(range.cloneContents().textContent),
        url = 'https://twitter.com/intent/tweet?text=' + selected;
    return $('<a>', { href: url }).text('Tweet this');
  }
});

Lorem ipsum, dolor sit amet

Positioning examples

Lorem ipsum, dolor sit amet

Lorem ipsum, dolor sit amet

Lorem ipsum, dolor sit amet

Lorem ipsum, dolor sit amet

Lorem ipsum, dolor sit amet

Lorem ipsum, dolor sit amet

Options

Name type default description
dialog string | element | function '' The element to be placed inside the dialog, the function takes the range as argument and returns the element to be appended.
placement string top Placement of the dialog: top | bottom
alignment string center Alignment of the dialog: left | center | right
offsetY number 10 Offset of the dialog in y

Events

Event name Description
markan.selected This event is fired when a selection is made.