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

Add the TKRangeSelect class #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions TangleKit/TangleKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ Tangle.classes.TKIf = {
};


//----------------------------------------------------------
//
// TKRangeSelect
//
// Chooses between a range of numbers, changing with each click.
//
// By default, the range is from 0 to the number of children of the element.
//
// Attributes: data-min (optional): minimum value
// data-max (optional): maximum value

Tangle.classes.TKRangeSelect = {

initialize: function (element, options, tangle, variable) {
element.addEvent("click", function (event) {
var minRange = (options.min == undefined) ? 0 : options.min;
var maxRange = (options.max == undefined) ? (element.getChildren().length - 1) : options.max;
var curValue = tangle.getValue(variable);
var nextValue = curValue + 1;

if (nextValue > maxRange) nextValue = minRange;
tangle.setValue(variable, nextValue);
});
}
};


//----------------------------------------------------------
//
// TKSwitch
Expand Down