let workType = false;
let workTool = false;
document.onmousedown = function(event) {
var event = event || window.event;
if ((event.button == "0" || event.button == "1") && !workTool) {
if (workTool) {
return 0;
}
if (document.getElementById("bblock") && !workTool) {
document.body.removeChild(document.getElementById("bblock"));
}
workType = true;
document.onmouseup = function(event) {
if (workType) {
workType = false;
var txt = window.getSelection ? window.getSelection() : document.selection.createRange().text;
txt = txt + "";
txt = txt.replace(/^\s+|\s+$/g, "");
if (txt != "") {
creatDiv(txt);
}
}
}
}
}
function mousePosition(evt) {
evt = evt || window.event;
var xPos = evt.pageX;
var yPos = evt.pageY;
return [xPos, yPos];
}
function creatDiv(str) {
var arr = mousePosition();
var newDiv = document.createElement('div');
var newContent = document.createTextNode(str);
newDiv.appendChild(newContent);
newDiv.id = "bblock";
newDiv.style.width = "50px";
newDiv.style.position = "absolute";
newDiv.style.left = arr[0] + 10 + "px";
newDiv.style.top = arr[1]- 25 + "px";
newDiv.style.zIndex = "1000";
newDiv.innerHTML = "<img id='openTag' src='text/images/total.png' οnclick='openDilog(\""+str+"\")'>";
var bo = document.body;
bo.insertBefore(newDiv, bo.lastChild);
bingDiv();
}
function bingDiv() {
document.getElementById("bblock").onmouseover = function() {
workTool = true;
}
document.getElementById("bblock").onmouseout = function() {
workTool = false;
}
}
<ul id="ContentMenuId"></ul>
var n1 = 1;
var n2 = 1;
var n3 = 1;
function creatMenus(i, obj) {
if ($(obj).get(0).tagName == 'H1') {
$('#ContentMenuId').append(
'<li class="doc_vavigat_h1"><a id="linkmark'
+ i + '">'
+ n1 + $(obj).text() + '</a></li>');
n1++;
n2 = 1;
n3 = 1;
}
if ($(obj).get(0).tagName == 'H2') {
$('#ContentMenuId')
.append(
'<li class="doc_vavigat_h2"><a id="linkmark'
+ i + '">'
+ (n1 - 1) + '.' + n2 + $(obj).text()
+ '</a></li>');
n2++;
n3 = 1;
}
if ($(obj).get(0).tagName == 'H3') {
$('#ContentMenuId').append(
'<li class="doc_vavigat_h2"><a id="linkmark'
+ i + '">'
+ (n1 - 1) + '.' + (n2 - 1) + '.' + n3
+ $(obj).text() + '</a></li>');
n3++;
}
}
function initLeftMenu() {
$('#docContentMenuId').affix({
offset : {
top : 50,
bottom : 5
}
})
$('h1,h2,h3', '#docContentsId').each(function(i, obj) {
creatMenus(i, obj);
$(obj).before("<a name='mark" + i + "'></a>");
$('#linkmark' + i).bind('click', function() {
$('html,body').animate({
scrollTop : $("a[name='mark" + i + "']").offset().top - 100
}, 500);
});
});