Can someone explain what exactly prototype is and how I can get access to a value typed into the input fields? (for example InputSwapFirst). I am trying to generate some code to teach people the Quick-Sort algorithm using H5p.
var H5P = H5P || {};
H5P.QuickSort = (function ($) {
function C(options, id) {
// Extend defaults with provided options
this.options = $.extend(true, {}, {
toSort: '42'
}, options);
// Keep provided id.
this.id = id;
this.list = this.options.toSort.split(',').map(x =>+x);
this.list = quickSort(this.list, 0, this.list.length - 1);
};
* @param {jQuery} $container
C.prototype.attach = function ($container) {
$container.addClass("QuickSort");
$container.append('<div class="greeting-text">' + this.options.toSort+testM()+ '</div>');
$container.append('<div class="greeting-text">' + this.list+ '</div>');
$container.append('<button id="ButtonSwap" class="inputSwap" type="button" id="swapBtn" onclick="testM()">Swap</button>');
$container.append('<label id="InputSwapLeftBracket" class="inputSwap" for="swap">(</label> ');
$container.append('<input id="InputSwapFirst" class="inputSwap" type="text"/>');
$container.append('<label id="InputSwapComma" class="inputSwap" for="partition">,</label> ');
$container.append('<input id="InputSwapSecond" class="inputSwap" type="text"/>');
$container.append('<label id="InputSwapRightBracket" class="inputSwap" for="partition">)</label> ');
$container.append('<button id="ButtonPart" class="inputPart" type="button" id="partBtn">Partitioniere</button>');
$container.append('<label id="InputPartLeftBracket" class="inputPart" for="partition">(</label> ');
$container.append('<input id="InputPartFirst" class="inputPart" type="text"/>');
$container.append('<label id="InputPartComma" class="inputPart" for="partition">,</label> ');
$container.append('<input id="InputPartSecond" class="inputPart" type="text"/>');
$container.append('<label id="InputPartRightBracket" class="inputPart" for="partition">)</label> ');
};
return C;
})(H5P.jQuery);