tag-youre-it/content_script.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

$(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(
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-26 21:42:56 +02:00
if (selectedText == false) {
return;
} else {
createPopover(document.activeElement, selectedText);
}
}
function createPopover(element, content) {
console.log('createPopover');
$(document.activeElement).append('test');
$(document.activeElement).popover({
title: "Please select a semantic tag",
content: 'say something',
html: true,
placement: 'auto'
});
$(document.activeElement).popover('show');
2015-09-26 21:06:24 +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);
/*
Take the existing content, make it narrower and
insert a menu for tagging up content.
*/
var isMenuShown = false;
function bootstrapApplication () {
if (isMenuShown) {
return true;
}
$.get('example1.menu.html', function (htmlData) {
$('body').children().wrapAll('<div class="tagit-body" />');
$('.tagit-body').before(htmlData);
isMenuShown = true;
});
}
$('#js-show-menu').click(bootstrapApplication);
2015-09-26 20:48:26 +02:00
});