1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-15 22:34:51 +00:00
TiddlyWiki5/plugins/tiddlywiki/dynannotate/modules/startup.js
jeremy@jermolene.com 1d32ef44e5 Add element spotlight to dynannotate plugin
Useful for highlighting on screen elements for the user
2023-02-01 17:12:06 +00:00

63 lines
2.1 KiB
JavaScript

const { ElementSpotlight } = require("./element-spotlight");
/*\
title: $:/plugins/tiddlywiki/dynannotate/startup.js
type: application/javascript
module-type: startup
Startup the dyannotate background daemon to track the selection
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Export name and synchronous status
exports.name = "dyannotate-startup";
exports.platforms = ["browser"];
exports.after = ["render"];
exports.synchronous = true;
var CONFIG_SELECTION_TRACKER_TITLE = "$:/config/Dynannotate/SelectionTracker/Enable",
CONFIG_LEGACY_SELECTION_TRACKER_TITLE = "$:/config/Dynannotate/LegacySelectionTracker/Enable";
var SelectionTracker = require("$:/plugins/tiddlywiki/dynannotate/selection-tracker.js").SelectionTracker,
LegacySelectionTracker = require("$:/plugins/tiddlywiki/dynannotate/legacy-selection-tracker.js").LegacySelectionTracker,
ElementSpotlight = require("$:/plugins/tiddlywiki/dynannotate/element-spotlight.js").ElementSpotlight;
exports.startup = function() {
$tw.dynannotate = {};
// Setup selection tracker
if($tw.wiki.getTiddlerText(CONFIG_SELECTION_TRACKER_TITLE,"yes") === "yes") {
$tw.dynannotate.selectionTracker = new SelectionTracker($tw.wiki);
}
// Setup legacy selection tracker
if($tw.wiki.getTiddlerText(CONFIG_LEGACY_SELECTION_TRACKER_TITLE,"yes") === "yes") {
$tw.dynannotate.legacySelectionTracker = new LegacySelectionTracker($tw.wiki,{
allowBlankSelectionPopup: true
});
}
// Set up the element spotlight
$tw.dynannotate.elementSpotlight = new ElementSpotlight();
$tw.rootWidget.addEventListener("tm-spotlight-element",function(event) {
var selectors = [];
if(event.paramObject.selector) {
selectors.push(event.paramObject.selector);
}
$tw.utils.each(Object.keys(event.paramObject).sort(),function(name) {
var SELECTOR_PROPERTY_PREFIX = "selector-";
if($tw.utils.startsWith(name,SELECTOR_PROPERTY_PREFIX)) {
selectors.push(event.paramObject[name]);
}
});
if(event.paramObject["selector-fallback"]) {
selectors.push(event.paramObject["selector-fallback"]);
}
$tw.dynannotate.elementSpotlight.shineSpotlight(selectors);
});
};
})();