From 9efe490906b90a1c8ee750ca2030aabd644280a7 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:06:29 +0200 Subject: [PATCH] Fixed author hover --- package.json | 2 +- static/js/index.js | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index d7ea3f5..1a3ce5f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ }, "name": "ep_author_hover", "description": "Adds author names to span titles (shows on hover), works as authors change their name. Hover includes author color and fast switching between author spans. Hat tip to Martyn York for the initial work on this.", - "version": "0.3.55", + "version": "1.0.0", "repository": { "type": "git", "url": "git@github.com:JohnMcLear/ep_author_hover.git" diff --git a/static/js/index.js b/static/js/index.js index b4d1c87..cc604c4 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1,20 +1,19 @@ 'use strict'; const padcookie = require('ep_etherpad-lite/static/js/pad_cookie').padcookie; +import html10n from 'ep_etherpad-lite/static/js/vendors/html10n' let timer = 0; const showAuthor = { - enable: (context) => { - context.ace.callWithAce((ace) => { - const doc = ace.ace_getDocument(); - $(doc).find('#innerdocbody').mousemove(exports.showAuthor.hover.bind(ace)); - }, 'showAuthor', true); + enable: () => { + $('iframe[name="ace_outer"]').contents().find('iframe') + .contents().find('#innerdocbody').on('mousemove',exports.showAuthor.hover); }, disable: (context) => { context.ace.callWithAce((ace) => { const doc = ace.ace_getDocument(); - $(doc).find('#innerdocbody').mousemove(null.bind(ace)); + $(doc).find('#innerdocbody').on('mousemove',null.bind(ace)); }, 'showAuthor', true); }, hover: (span) => { @@ -34,7 +33,7 @@ const showAuthor = { if (!authorId) { return; } // Default text isn't shown showAuthor.destroy(); // Destroy existing const authorNameAndColor = - showAuthor.authorNameAndColorFromAuthorId(authorId); // Get the authorName And Color + showAuthor.authorNameAndColorFromAuthorId(authorId); // Get the authorName And Color showAuthor.draw(span, authorNameAndColor.name, authorNameAndColor.color); } }, @@ -57,7 +56,7 @@ const showAuthor = { const myAuthorId = pad.myUserInfo.userId.substring(0, 14); if (myAuthorId === authorId) { return { - name: window._('ep_author_hover.me'), + name: html10n.get('ep_author_hover.me'), color: '#fff', }; } @@ -68,7 +67,7 @@ const showAuthor = { if (authorId === $(this).data('authorid').substring(0, 14)) { $(this).find('.usertdname').each(function () { authorObj.name = $(this).text(); - if (authorObj.name === '') authorObj.name = window._('ep_author_hover.unknow_author'); + if (authorObj.name === '') authorObj.name = html10n.get('ep_author_hover.unknow_author'); }); $(this).find('.usertdswatch > div').each(function () { authorObj.color = $(this).css('background-color'); @@ -83,12 +82,12 @@ const showAuthor = { authorObj = clientVars.collab_client_vars.historicalAuthorData[fullAuthorId]; } - return authorObj || {name: window._('ep_author_hover.unknow_author'), color: '#fff'}; + return authorObj || {name: html10n.get('ep_author_hover.unknow_author'), color: '#fff'}; }, draw: (target, authorName, authorColor) => { if (!authorName) { const warning = - 'No authorName, I have no idea why! Help me debug this by providing steps to replicate!'; + 'No authorName, I have no idea why! Help me debug this by providing steps to replicate!'; console.warn(warning); return; } @@ -144,11 +143,7 @@ exports.postAceInit = (hookName, context) => { $('#options-author-hover').attr('checked', 'checked'); } - if ($('#options-author-hover').is(':checked')) { - clientVars.plugins.plugins.ep_author_hover.enabled = true; - } else { - clientVars.plugins.plugins.ep_author_hover.enabled = false; - } + clientVars.plugins.plugins.ep_author_hover.enabled = !!$('#options-author-hover').is(':checked'); /* on click */ $('#options-author-hover').on('click', () => {