mirror of
https://gitlab.com/octtspacc/OcttKB
synced 2025-06-06 00:29:12 +02:00
OcttKB Cross-Repo Sync (HTML to Raw)
This commit is contained in:
123
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_calc.js
vendored
Normal file
123
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_calc.js
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
/*\
|
||||
title: $:/.tb/macros/calc
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
Computes a (Field) value +,-,*,/ a provided value.
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Information about this macro
|
||||
*/
|
||||
|
||||
exports.name = "calc";
|
||||
|
||||
exports.params = [
|
||||
{name: "value"},
|
||||
{name: "operation"},
|
||||
{name: "until"},
|
||||
{name: "beyond"},
|
||||
{name: "decimals"},
|
||||
{name: "tiddler"},
|
||||
{name: "by"}
|
||||
];
|
||||
|
||||
/*
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function(value, operation, until, beyond, decimals, tiddler, by) {
|
||||
if(!value) {
|
||||
return;
|
||||
}
|
||||
if("" === operation){
|
||||
operation = "+";
|
||||
}
|
||||
var
|
||||
curr,dec,init,initMatch,op,opGiven,r,result,val,
|
||||
regInit = /^((?:[0-9]+)|(?:(?:[0-9]*)[\.,\,](?:[0-9]*))){1}[=][>](.*)/mg,
|
||||
ops = ["+","-","*","/"];
|
||||
initMatch = regInit.exec(value);
|
||||
if(initMatch) {
|
||||
init = initMatch[1].replace(/[\,]/,".");
|
||||
value = initMatch[2];
|
||||
}
|
||||
curr = parseFloat(
|
||||
isNaN(parseFloat(value)) ?
|
||||
this.wiki.getTextReference(value, init || "NaN", tiddler || this.getVariable("currentTiddler")) :
|
||||
value
|
||||
);
|
||||
until = parseFloat(until);
|
||||
decimals = parseInt(decimals);
|
||||
|
||||
op = operation.charAt(0);
|
||||
opGiven = ops.indexOf(op) >= 0;
|
||||
if(!opGiven) {
|
||||
op = "+";
|
||||
}
|
||||
initMatch = regInit.exec(by);
|
||||
if(initMatch) {
|
||||
init = initMatch[1].replace(/[\,]/,".");
|
||||
by = initMatch[2];
|
||||
}
|
||||
val = parseFloat(
|
||||
isNaN(parseFloat(by)) ?
|
||||
this.wiki.getTextReference(by, init || "NaN", tiddler || this.getVariable("currentTiddler")) :
|
||||
by
|
||||
);
|
||||
if(by === "") {
|
||||
val = opGiven ?
|
||||
(operation.length < 2 ? 0 : parseFloat(operation.substr(1))) :
|
||||
parseFloat(operation);
|
||||
}
|
||||
if(isNaN(curr)) {
|
||||
result = "NaN";
|
||||
} else {
|
||||
switch (op){
|
||||
case "-": result = curr - val; break;
|
||||
case "*": result = curr * val; break;
|
||||
case "/": result = curr / val; break;
|
||||
case "+":
|
||||
/* falls through */
|
||||
default: result = curr + val;
|
||||
}
|
||||
if(!isNaN(until)) {
|
||||
if (!(
|
||||
"+" == op || "*" == op ?
|
||||
result <= until :
|
||||
result >= until
|
||||
)) {
|
||||
if("true" == beyond) {
|
||||
result = true;
|
||||
} else {
|
||||
result = until;
|
||||
}
|
||||
}
|
||||
if(beyond && result !== true) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!isNaN(result)){
|
||||
r = result.toString();
|
||||
dec = r.indexOf('.');
|
||||
if(dec > -1){
|
||||
dec = r.substr(dec).length;
|
||||
if(
|
||||
!isNaN(decimals) && dec > decimals ||
|
||||
isNaN(decimals) && dec > 2
|
||||
){
|
||||
result = result.toFixed(isNaN(decimals) ? 2 : decimals);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
};
|
||||
|
||||
})();
|
9
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_calc.js.meta
vendored
Normal file
9
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_calc.js.meta
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
created: 20150126131341956
|
||||
creator: Tobias Beer
|
||||
modified: 20230110224652721
|
||||
modifier: Tobias Beer
|
||||
module-type: macro
|
||||
revision: 0
|
||||
summary: allows simple calculations based on tiddler fields
|
||||
title: $:/ThirdParty/tobibeer/calc
|
||||
type: application/javascript
|
22
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_ibox.tid
vendored
Normal file
22
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_ibox.tid
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
created: 20141211131633372
|
||||
creator: Tobias Beer
|
||||
modified: 20230225142836580
|
||||
modifier: Octt
|
||||
tags: $:/tags/Macro
|
||||
title: $:/ThirdParty/tobibeer/ibox
|
||||
|
||||
\define ibox(image, caption, template:"$:/ThirdParty/tobibeer/ibox/Lightbox", btn-class:"ibox-btn", direct)
|
||||
<$reveal type=match text="" default="$direct$"><$button class="$btn-class$"><$action-sendmessage $message="tm-modal" $param="$template$" image="$image$" caption="$caption$"/><$image source="$image$"/></$button></$reveal><$reveal type=nomatch text="" default="$direct$"><$button class="$btn-class$"><$action-sendmessage $message="tm-modal" $param="$image$"/><$image source="$image$"/></$button></$reveal><style>
|
||||
.ibox-btn {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.ibox-btn img {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.tc-modal .tc-modal-body > div > img {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
\end
|
34
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_script.js
vendored
Normal file
34
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_script.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
enables js via <<script>> and disables with <<script 0>>
|
||||
Modified from original to add ability to exec scripts with a script="" param
|
||||
*/
|
||||
|
||||
exports.name = "script";
|
||||
|
||||
exports.params = [
|
||||
{name: "run"},
|
||||
{name: "script"},
|
||||
];
|
||||
|
||||
/*
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function(run, script) {
|
||||
var off = run ? run.toLowerCase() : false;
|
||||
if(off && ["0","no","off","false"].indexOf(off) > -1) {
|
||||
$tw.config.htmlUnsafeElements = ["script"];
|
||||
} else {
|
||||
$tw.config.htmlUnsafeElements = [];
|
||||
if (script) {
|
||||
eval(script);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
};
|
||||
})();
|
8
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_script.js.meta
vendored
Normal file
8
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/_script.js.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
created: 20150129001857442
|
||||
creator: Tobias Beer
|
||||
modified: 20230217100026908
|
||||
modifier: Octt
|
||||
module-type: macro
|
||||
tags:
|
||||
title: $:/ThirdParty/tobibeer/script
|
||||
type: application/javascript
|
10
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/ibox/_Lightbox.tid
vendored
Normal file
10
Wiki-OcttKB/tiddlers/System/ThirdParty/tobibeer/ibox/_Lightbox.tid
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
caption: Lightbox
|
||||
created: 20141211130114064
|
||||
creator: Tobias Beer
|
||||
modified: 20230117130401126
|
||||
modifier: Octt
|
||||
summary: the default modal template used with the ibox macro
|
||||
tags:
|
||||
title: $:/ThirdParty/tobibeer/ibox/Lightbox
|
||||
|
||||
<$image source=<<image>> width="100%" height="100%"/><$reveal type=match text="" default=<<caption>>><$transclude tiddler=<<image>> field=caption/></$reveal><$reveal type=nomatch text="" default=caption><<caption>></$reveal>
|
Reference in New Issue
Block a user