MediaWiki:Gadget-TciTest.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
// Gadget-TciTest.js — TCI Calculator (LIVE VERSION | // Gadget-TciTest.js — TCI Calculator (LIVE VERSION — debug input read) | ||
(function ($, mw, OO) { | (function ($, mw, OO) { | ||
"use strict"; | "use strict"; | ||
Line 46: | Line 46: | ||
}; | }; | ||
// ... [scale and utility functions unchanged] ... | |||
TCICalculatorTestDialog.prototype.getActionProcess = function (action) { | TCICalculatorTestDialog.prototype.getActionProcess = function (action) { | ||
Line 166: | Line 53: | ||
const abc = this.abcInput.getValue(); | const abc = this.abcInput.getValue(); | ||
const mode = this.octaveChoice.getValue(); | const mode = this.octaveChoice.getValue(); | ||
console.log('📥 ABC from textarea:\n', abc); // debug line | |||
const result = parseABC(abc, mode); | const result = parseABC(abc, mode); | ||
this.resultOutput.setValue( | this.resultOutput.setValue( |
Revision as of 18:00, 10 April 2025
// Gadget-TciTest.js — TCI Calculator (LIVE VERSION — debug input read)
(function ($, mw, OO) {
"use strict";
mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function () {
function TCICalculatorTestDialog(config) {
TCICalculatorTestDialog.super.call(this, config);
}
OO.inheritClass(TCICalculatorTestDialog, OO.ui.ProcessDialog);
TCICalculatorTestDialog.static.name = 'tciCalculatorTestDialog';
TCICalculatorTestDialog.static.title = 'Theme Code Index Calculator — LIVE VERSION';
TCICalculatorTestDialog.static.actions = [
{ action: 'cancel', label: 'Cancel', flags: 'safe' },
{ action: 'calculate', label: 'Calculate TCI', flags: ['primary', 'progressive'] }
];
TCICalculatorTestDialog.prototype.initialize = function () {
TCICalculatorTestDialog.super.prototype.initialize.call(this);
this.content = new OO.ui.PanelLayout({ padded: true, expanded: false, scrollable: true });
this.$body.append(this.content.$element);
this.abcInput = new OO.ui.MultilineTextInputWidget({ placeholder: 'Paste ABC notation here...', autosize: true, rows: 10 });
this.octaveChoice = new OO.ui.DropdownInputWidget({
options: [
{ data: 'standard', label: 'Standard fiddle range (default)' },
{ data: 'visual', label: 'Based on ABC visual octave' },
{ data: 'shiftUp', label: 'Force high octave (+1)' },
{ data: 'shiftDown', label: 'Force low octave (-1)' }
]
});
this.resultOutput = new OO.ui.MultilineTextInputWidget({ readOnly: true, autosize: true, rows: 4 });
this.content.$element.append(
new OO.ui.FieldsetLayout({
label: 'TCI Calculator Options',
items: [
new OO.ui.FieldLayout(this.abcInput, { label: 'ABC Notation', align: 'top' }),
new OO.ui.FieldLayout(this.octaveChoice, { label: 'Octave Interpretation', align: 'top' }),
new OO.ui.FieldLayout(this.resultOutput, { label: 'Theme Code Index (TCI)', align: 'top' })
]
}).$element
);
};
// ... [scale and utility functions unchanged] ...
TCICalculatorTestDialog.prototype.getActionProcess = function (action) {
if (action === 'calculate') {
return new OO.ui.Process(() => {
const abc = this.abcInput.getValue();
const mode = this.octaveChoice.getValue();
console.log('📥 ABC from textarea:\n', abc); // debug line
const result = parseABC(abc, mode);
this.resultOutput.setValue(
'Standard (4 beats): ' + result.normal +
'\nAlternate (2 beats): ' + result.dual +
'\n\n' + result.debug
);
});
} else if (action === 'cancel') {
return new OO.ui.Process(() => this.close({ action: action }));
}
return TCICalculatorTestDialog.super.prototype.getActionProcess.call(this, action);
};
function openTCICalculatorTestDialog() {
const windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
const dialog = new TCICalculatorTestDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
}
mw.util.addPortletLink('p-cactions', '#', '🎼 TCI Test', 'ca-tcitest', 'Open TCI test');
$(document).on('click', '#ca-tcitest', function (e) {
e.preventDefault();
openTCICalculatorTestDialog();
});
});
})(jQuery, mediaWiki, OO);