2015-09-26 11:43:02 +02:00
|
|
|
$(document).ready(function () {
|
|
|
|
|
2015-09-26 21:06:24 +02:00
|
|
|
function processSelection () {
|
|
|
|
var focused = document.activeElement;
|
|
|
|
var selectedText;
|
|
|
|
if (focused) {
|
|
|
|
try {
|
|
|
|
selectedText = focused.value.substring(
|
2015-09-27 17:04:35 +02:00
|
|
|
focused.selectionStart, focused.selectionEnd);
|
2015-09-26 21:06:24 +02:00
|
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (selectedText == undefined) {
|
|
|
|
var sel = window.getSelection();
|
|
|
|
var selectedText = sel.toString();
|
|
|
|
}
|
2015-09-27 19:16:17 +02:00
|
|
|
if (selectedText) {
|
|
|
|
console.log(selectedText);
|
2015-09-26 21:42:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-26 21:06:24 +02:00
|
|
|
document.addEventListener('click', function(evt) {
|
|
|
|
if (!document.hasFocus()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
processSelection();
|
|
|
|
// evt.stopPropagation();
|
|
|
|
// evt.preventDefault();
|
|
|
|
}, false);
|
2015-09-26 11:43:02 +02:00
|
|
|
|
2015-09-27 17:04:35 +02:00
|
|
|
/*
|
|
|
|
Take the existing content, make it narrower and
|
|
|
|
insert a menu for tagging up content.
|
|
|
|
*/
|
|
|
|
var isMenuShown = false;
|
2015-09-27 19:16:17 +02:00
|
|
|
|
|
|
|
function addMenu () {
|
|
|
|
if (isMenuShown) return;
|
2015-09-27 17:04:35 +02:00
|
|
|
$.get('example1.menu.html', function (htmlData) {
|
|
|
|
$('body').children().wrapAll('<div class="tagit-body" />');
|
|
|
|
$('.tagit-body').before(htmlData);
|
2015-09-27 19:16:17 +02:00
|
|
|
$('#js-hide-menu').click(removeMenu);
|
2015-09-27 17:04:35 +02:00
|
|
|
isMenuShown = true;
|
|
|
|
});
|
|
|
|
}
|
2015-09-27 19:16:17 +02:00
|
|
|
function removeMenu () {
|
|
|
|
if (!isMenuShown) return;
|
|
|
|
$('.tagit-body').children().unwrap();
|
|
|
|
$('.tagit-menu').remove();
|
|
|
|
isMenuShown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#js-show-menu').click(addMenu);
|
|
|
|
|
2015-09-26 20:48:26 +02:00
|
|
|
});
|