Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TKSwitch and TKToggle combined in TKIncrement #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion TangleKit/TangleKit.css
Expand Up @@ -19,7 +19,8 @@


/* TKToggle */ /* TKToggle */


.TKToggle { .TKToggle,
.TKIncrement {
color: #46f; color: #46f;
border-bottom: 1px dashed #46f; border-bottom: 1px dashed #46f;
cursor: pointer; cursor: pointer;
Expand Down
28 changes: 27 additions & 1 deletion TangleKit/TangleKit.js
Expand Up @@ -83,6 +83,29 @@ Tangle.classes.TKToggle = {
}; };




//----------------------------------------------------------
//
// TKIncrement
//
// Click to increment value (modulo the number of options).

Tangle.classes.TKIncrement = {

initialize: function (element, options, tangle, variable) {
element.addEvent("click", function (event) {
var value = tangle.getValue(variable);
tangle.setValue(variable, ++value % element.getChildren().length);
});
},

update: function (element, value) {
element.getChildren().each( function (child, index) {
child.style.display = (index != value) ? "none" : "inline";
});
}
};


//---------------------------------------------------------- //----------------------------------------------------------
// //
// TKNumberField // TKNumberField
Expand Down Expand Up @@ -288,8 +311,11 @@ Tangle.formats.percent = function (value) {
return "" + (100 * value).round(0) + "%"; return "" + (100 * value).round(0) + "%";
}; };


Tangle.formats.height = function (value) {
return Math.floor(value/12) + "′" + value%12 + "″";
};




//---------------------------------------------------------- //----------------------------------------------------------


})(); })();
Expand Down