export function add(parent, child) { parent.content.append(child.root); } export function methodRef(_this, methodName, args) { return function() { _this[methodName].apply(_this, args); }; } export function Box(parent) { this.root = this.content = $('
'); this.root.addClass('tc-box tc-scroll'); this.root.appendTo(parent ? parent : 'body'); } Box.prototype.close = function() { this.root.remove(); }; export function Panel() { this.root = this.content = $('
'); this.root.addClass('tc-panel tc-scroll'); } Panel.prototype.close = function() { this.root.remove(); }; export function Folder(title) { this.root = $('
', {'class': 'tc-folder'}); this.content = $('
'); this.root.append($('
', {text: title, 'class': 'tc-row tc-title'})); this.root.append(this.content); } export function Button(title) { this.root = $('
', {'class': 'tc-row tc-ctrl tc-ctrl-btn', text: title}); } export function CheckBox(title, checked) { this.root = $('
', {'class': 'tc-row tc-ctrl'}); this.root.append('') this.input = this.root.find("input"); this.input.prop('checked', !!checked); } export function InlineRadio(choiceLabels, choiceValues, checkedIndex) { var name = 'TCAD.toolkit.InlineRadio_' + (InlineRadio.COUNTER++) this.root = $('
', {'class': 'tc-row tc-ctrl tc-inline-radio'}); this.inputs = []; for (var i = 0; i < choiceLabels.length; i++) { var checked = checkedIndex === i ? "checked" : ''; var label = $(''); this.inputs.push(label.find("input")); this.root.append(label); } this.inputs[checkedIndex].prop('checked', true); } InlineRadio.prototype.getValue = function() { for (var i = 0; i < this.inputs.length; i++) { if (this.inputs[i].prop('checked')) { return this.inputs[i].attr('value'); } } return null; }; InlineRadio.COUNTER = 0; export function propLayout(root, name, valueEl) { root.append($('', {'class': 'tc-prop-name', text: name})) .append($('
', {'class': 'tc-prop-value'}) .append(valueEl)); } function NumberWidget(name, initValue, baseStep, round) { this.root = $('
', {'class': 'tc-row tc-ctrl tc-ctrl-number'}); this.input = $(""); this.slide = false; baseStep = baseStep || 1; round = round || 0; this.min = null; this.max = null; this.accelerator = 100; var scope = this; var lastValue = null; function trigger() { if ($(this).val() !== lastValue) { $(this).trigger('t-change'); lastValue = $(this).val(); } } this.input.on('input', function(e) { var val = $(this).val(); //var floatRegex = /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/; //if (!floatRegex.test(val)) { // $(this).val(val.replace(/[^0-9\.-]/g, '')); //} trigger.call(this); }); this.input.get(0).addEventListener('mousewheel', function (e) { var delta = 0; if ( e.wheelDelta ) { // WebKit / Opera / Explorer 9 delta = e.wheelDelta; } else if ( e.detail ) { // Firefox delta = - e.detail; } var val = $(this).val(); if (!val) val = 0; var step = baseStep * (e.shiftKey ? scope.accelerator : 1); val = parseFloat(val) + (delta < 0 ? -step : step); if (scope.min != null && val < scope.min) { val = scope.min; } if (scope.max != null && val > scope.max) { val = scope.max; } if (round !== 0) { val = val.toFixed(round); } $(this).val(val); e.preventDefault(); e.stopPropagation(); trigger.call(this); }, false); propLayout(this.root, name, this.input); } NumberWidget.prototype.val = function() { return Number(this.input.val()); }; export function Text(name, initValue) { this.root = $('
', {'class': 'tc-row tc-ctrl'}); this.input = $(""); propLayout(this.root, name, this.input); } export function Combo(id, labelText) { this.root = $('
', {'class': 'tc-row tc-ctrl tc-ctrl-combo'}); var label = $('', {'class': 'tc-prop-name', text: labelText}); this.select = $('