I try to use mid button to close a tid but failed, how to make it?

I try to use mid button to close a tid.

But nothing happened when I add some js code to my tw.


I get a good reference 2click2edit, which dblclick to addListener, but I use midbutton.
I think Just change the name and rewrite the addEventListener function will make it.

Here is the compare result of my code and 2click2edit.


Here is my MidClickListener code

/*\
title: $:/plugins/danielo515/2click2edit/MidClickListener.js
type: application/javascript
module-type: widget

This widgets adds an double click event listener to its parent

\*/

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var MidClickListener = function(parseTreeNode,options) {
	this.initialise(parseTreeNode,options);
};

/*
Inherit from the base widget class
*/
MidClickListener.prototype = new Widget();

/*
Render this widget into the DOM
*/
MidClickListener.prototype.render = function(parent,nextSibling) {
	this.parentDomNode = parent;
	this.execute();
	var self = this;
    /*Since the event listener have been added to the parent, the "this" property is pointing to the
    wrong object, we should call our edit function with our widget object set as the this property.*/
    parent.addEventListener("mousedown",function(event){
      if(event.button == 1){
        self.editTiddler.call(self,event)
        }
      else if(event.button == 2){
        alert("right click");
        }
    });
};

MidClickListener.prototype.editTiddler = function(event) {
    this.dispatchEvent({type: "tm-edit-tiddler", param: this.getVariable("currentTiddler")});    
};

/*
Compute the internal state of the widget
*/
MidClickListener.prototype.execute = function() {
};

/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
MidClickListener.prototype.refresh = function(changedTiddlers) {
	return false;
};

exports.click = MidClickListener;

})();


I also find a tid named viewtemplate which contains a widget <$click> which I don’t know what it is after some google work.

I haven’t add this <$click> thing to my scripts Will this leads to the failed of my script?

source code of 2click2eidt

$__plugins_danielo515_2click2edit.json (3.1 KB)

You need to add your widget to the tiddler view template in order for it to work, it needs to wrap the contents of the template.

Sorry I don’t know how to wrap the widget to tiddler view template. Can you give me a link about it?

Try using this template but replace the $click widget with your own widget:

https://danielorodriguez.com/TW5-2click2edit/#%24%3A%2Fplugins%2Fdanielo515%2F2click2edit%2Fui%2FViewTemplate

2 Likes