mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-31 19:29:11 +00:00
Added hover functionality to button and link macros
This commit is contained in:
parent
034af3b126
commit
c58903f865
@ -20,6 +20,7 @@ exports.info = {
|
|||||||
set: {byName: true, type: "tiddler"},
|
set: {byName: true, type: "tiddler"},
|
||||||
setTo: {byName: true, type: "text"},
|
setTo: {byName: true, type: "text"},
|
||||||
popup: {byName: true, type: "tiddler"},
|
popup: {byName: true, type: "tiddler"},
|
||||||
|
hover: {byName: true, type: "text"},
|
||||||
qualifyTiddlerTitles: {byName: true, type: "text"},
|
qualifyTiddlerTitles: {byName: true, type: "text"},
|
||||||
"class": {byName: true, type: "text"}
|
"class": {byName: true, type: "text"}
|
||||||
}
|
}
|
||||||
@ -34,25 +35,14 @@ exports.dispatchMessage = function(event) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.triggerPopup = function(event) {
|
exports.triggerPopup = function(event) {
|
||||||
// Get the textref of the popup state tiddler
|
$tw.popup.triggerPopup({
|
||||||
var textRef = this.params.popup;
|
textRef: this.params.popup,
|
||||||
if(this.hasParameter("qualifyTiddlerTitles") && this.params.qualifyTiddlerTitles === "yes") {
|
domNode: this.child.domNode,
|
||||||
textRef = "(" + this.parents.join(",") + "," + this.tiddlerTitle + ")" + textRef;
|
qualifyTiddlerTitles: this.params.qualifyTiddlerTitles,
|
||||||
}
|
contextTiddlerTitle: this.tiddlerTitle,
|
||||||
// Get the current popup state tiddler
|
contextParents: this.parents,
|
||||||
var value = this.wiki.getTextReference(textRef,"",this.tiddlerTitle);
|
wiki: this.wiki
|
||||||
// Check if the popup is open by checking whether it matches "(<x>,<y>)"
|
});
|
||||||
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/;
|
|
||||||
if(popupLocationRegExp.test(value)) {
|
|
||||||
$tw.popup.cancel();
|
|
||||||
} else {
|
|
||||||
// Set the position if we're opening it
|
|
||||||
this.wiki.setTextReference(textRef,
|
|
||||||
"(" + this.child.domNode.offsetLeft + "," + this.child.domNode.offsetTop + "," +
|
|
||||||
this.child.domNode.offsetWidth + "," + this.child.domNode.offsetHeight + ")",
|
|
||||||
this.tiddlerTitle,true);
|
|
||||||
$tw.popup.popup(textRef);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setTiddler = function() {
|
exports.setTiddler = function() {
|
||||||
@ -76,6 +66,13 @@ exports.handleEvent = function(event) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(event.type === "mouseover" || event.type === "mouseout") {
|
||||||
|
if(this.hasParameter("popup")) {
|
||||||
|
this.triggerPopup(event);
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,8 +87,12 @@ exports.executeMacro = function() {
|
|||||||
for(var t=0; t<this.content.length; t++) {
|
for(var t=0; t<this.content.length; t++) {
|
||||||
this.content[t].execute(this.parents,this.tiddlerTitle);
|
this.content[t].execute(this.parents,this.tiddlerTitle);
|
||||||
}
|
}
|
||||||
|
var events = ["click"];
|
||||||
|
if(this.hasParameter("hover") && this.params.hover === "yes") {
|
||||||
|
events.push("mouseover","mouseout");
|
||||||
|
}
|
||||||
return $tw.Tree.Element("button",attributes,this.content,{
|
return $tw.Tree.Element("button",attributes,this.content,{
|
||||||
events: ["click"],
|
events: events,
|
||||||
eventHandler: this
|
eventHandler: this
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,9 @@ exports.info = {
|
|||||||
params: {
|
params: {
|
||||||
to: {byName: "default", type: "tiddler", skinny: true},
|
to: {byName: "default", type: "tiddler", skinny: true},
|
||||||
throughField: {byname: true, type: "text"},
|
throughField: {byname: true, type: "text"},
|
||||||
space: {byName: true, type: "text"}
|
space: {byName: true, type: "text"},
|
||||||
|
qualifyHoverTitle: {byName: true, type: "text"},
|
||||||
|
hover: {byName: true, type: "tiddler"}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,6 +44,20 @@ exports.handleEvent = function (event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(event.type === "mouseover" || event.type === "mouseout") {
|
||||||
|
if(this.hasParameter("hover")) {
|
||||||
|
$tw.popup.triggerPopup({
|
||||||
|
textRef: this.params.hover,
|
||||||
|
domNode: this.child.domNode,
|
||||||
|
qualifyTiddlerTitles: this.params.qualifyHoverTitle,
|
||||||
|
contextTiddlerTitle: this.tiddlerTitle,
|
||||||
|
contextParents: this.parents,
|
||||||
|
wiki: this.wiki
|
||||||
|
});
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.executeMacro = function() {
|
exports.executeMacro = function() {
|
||||||
@ -84,11 +100,15 @@ exports.executeMacro = function() {
|
|||||||
$tw.utils.pushTop(this.linkInfo.attributes["class"],this.classes);
|
$tw.utils.pushTop(this.linkInfo.attributes["class"],this.classes);
|
||||||
}
|
}
|
||||||
// Create the link
|
// Create the link
|
||||||
|
var events = ["click"];
|
||||||
|
if(this.hasParameter("hover")) {
|
||||||
|
events.push("mouseover","mouseout");
|
||||||
|
}
|
||||||
var child;
|
var child;
|
||||||
if(this.linkInfo.suppressLink) {
|
if(this.linkInfo.suppressLink) {
|
||||||
child = $tw.Tree.Element("span",{},this.content);
|
child = $tw.Tree.Element("span",{},this.content);
|
||||||
} else {
|
} else {
|
||||||
child = $tw.Tree.Element("a",this.linkInfo.attributes,this.content,{events: ["click"], eventHandler: this});
|
child = $tw.Tree.Element("a",this.linkInfo.attributes,this.content,{events: events, eventHandler: this});
|
||||||
}
|
}
|
||||||
child.execute(this.parents,this.tiddlerTitle);
|
child.execute(this.parents,this.tiddlerTitle);
|
||||||
return child;
|
return child;
|
||||||
|
Loading…
Reference in New Issue
Block a user