123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /**
- * This JS file is for examples list and actions linked to examples.
- */
- class Examples {
- constructor(parent) {
- this.parent = parent;
- this.isExamplesDisplayed = false;
- this.fpsLabel = document.getElementById('fpsLabel');
- this.examplesButtons = document.getElementsByClassName('examplesButton');
- this.exampleList = document.getElementById('exampleList');
- /**
- * Display / hide with the "examples" button. On any size interface
- */
- if (this.examplesButtons.length > 0) {
- for (var i = 0; i < this.examplesButtons.length; i++) {
- this.examplesButtons[i].parentElement.onclick = function () {
- if (!this.isExamplesDisplayed) this.displayExamples();
- else this.hideExamples();
- }.bind(this);
- }
- }
- // There's a "close" button on the mobile interface.
- document.getElementById('examplesButtonClose').addEventListener('click', this.hideExamples.bind(this));
- /**
- * The filter bar is used to search a thing on the examples.
- * This react on any input on the bar, or on a click on the search button.
- */
- var filterBar = document.getElementById('filterBar');
- if (filterBar) {
- var filterBarClear = document.getElementById('filterBarClear');
- var filter = function () {
- var filterText = filterBar.value.toLowerCase();
- if (filterText == '') filterBarClear.style.display = 'none';
- else filterBarClear.style.display = 'inline-block';
- var lines = document.getElementsByClassName('itemLine');
- for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) {
- var line = lines[lineIndex];
- if (line.innerText.toLowerCase().indexOf(filterText) > -1) {
- line.style.display = '';
- } else {
- line.style.display = 'none';
- }
- }
- var categories = document.getElementsByClassName('categoryContainer');
- var displayCount = categories.length;
- for (var categoryIndex = 0; categoryIndex < categories.length; categoryIndex++) {
- var category = categories[categoryIndex];
- category.style.display = 'block';
- if (category.clientHeight < 25) {
- category.style.display = 'none';
- displayCount--;
- }
- }
- if (displayCount == 0) document.getElementById('noResultsContainer').style.display = 'block';
- else document.getElementById('noResultsContainer').style.display = 'none';
- }
- filterBar.oninput = function () {
- filter();
- }
- filterBarClear.onclick = function () {
- filterBar.value = '';
- filter();
- }
- }
- }
- /**
- * Function to display the examples menu
- */
- displayExamples() {
- this.parent.menuPG.removeAllOptions();
- this.isExamplesDisplayed = true;
- this.exampleList.style.display = 'block';
- document.getElementsByClassName('wrapper')[0].style.width = 'calc(100% - 400px)';
- this.fpsLabel.style.display = 'none';
- this.toggleExamplesButtons.call(this, true);
- };
- /**
- * Function to hide the examples menu
- */
- hideExamples() {
- this.isExamplesDisplayed = false;
- this.exampleList.style.display = 'none';
- document.getElementsByClassName('wrapper')[0].style.width = '100%';
-
- if(this.parent.menuPG && this.parent.menuPG.isMobileVersion && document.getElementById('jsEditor').style.display == 'block') {}
- else this.fpsLabel.style.display = 'block';
- this.toggleExamplesButtons.call(this, false);
- };
- toggleExamplesButtons(selected) {
- if (this.examplesButtons.length > 0) {
- for (var i = 0; i < this.examplesButtons.length; i++) {
- if(selected)
- this.examplesButtons[i].parentElement.classList.add("selected");
- else
- this.examplesButtons[i].parentElement.classList.remove("selected");
- }
- }
- };
- }
|