Ajoute les commentaires et la documentation RDoc

This commit is contained in:
julien committed 2026-10-08 19:42:56 +02:00
1 parent 5cf2d683e7
commit dbd8c51412
56 files changed
+3601 -17

No files matched your search

+120
View File
@@ -0,0 +1,120 @@
/**
*
* Darkfish Page Functions
* $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
*
* Author: Michael Granger <mgranger@laika.com>
*
*/
/* Provide console simulation for firebug-less environments */
/*
if (!("console" in window) || !("firebug" in console)) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {};
};
*/
function showSource( e ) {
var target = e.target;
while (!target.classList.contains('method-detail')) {
target = target.parentNode;
}
if (typeof target !== "undefined" && target !== null) {
target = target.querySelector('.method-source-code');
}
if (typeof target !== "undefined" && target !== null) {
target.classList.toggle('active-menu')
}
};
function hookSourceViews() {
document.querySelectorAll('.method-source-toggle').forEach(function (codeObject) {
codeObject.addEventListener('click', showSource);
});
};
function hookSearch() {
var input = document.querySelector('#search-field');
var result = document.querySelector('#search-results');
result.classList.remove("initially-hidden");
var search_section = document.querySelector('#search-section');
search_section.classList.remove("initially-hidden");
var search = new Search(search_data, input, result);
search.renderItem = function(result) {
var li = document.createElement('li');
var html = '';
// TODO add relative path to <script> per-page
html += '<p class="search-match"><a href="' + index_rel_prefix + this.escapeHTML(result.path) + '">' + this.hlt(result.title);
if (result.params)
html += '<span class="params">' + result.params + '</span>';
html += '</a>';
if (result.namespace)
html += '<p class="search-namespace">' + this.hlt(result.namespace);
if (result.snippet)
html += '<div class="search-snippet">' + result.snippet + '</div>';
li.innerHTML = html;
return li;
}
search.select = function(result) {
window.location.href = result.firstChild.firstChild.href;
}
search.scrollIntoView = search.scrollInWindow;
};
function hookFocus() {
document.addEventListener("keydown", (event) => {
if (document.activeElement.tagName === 'INPUT') {
return;
}
if (event.key === "/") {
event.preventDefault();
document.querySelector('#search-field').focus();
}
});
}
function hookSidebar() {
var navigation = document.querySelector('#navigation');
var navigationToggle = document.querySelector('#navigation-toggle');
navigationToggle.addEventListener('click', function() {
navigation.hidden = !navigation.hidden;
navigationToggle.ariaExpanded = navigationToggle.ariaExpanded !== 'true';
});
var isSmallViewport = window.matchMedia("(max-width: 1023px)").matches;
if (isSmallViewport) {
navigation.hidden = true;
navigationToggle.ariaExpanded = false;
document.addEventListener('click', (e) => {
if (e.target.closest('#navigation a')) {
navigation.hidden = true;
navigationToggle.ariaExpanded = false;
}
});
}
}
document.addEventListener('DOMContentLoaded', function() {
hookSourceViews();
hookSearch();
hookFocus();
hookSidebar();
});
+105
View File
@@ -0,0 +1,105 @@
/*
* Navigation allows movement using the arrow keys through the search results.
*
* When using this library you will need to set scrollIntoView to the
* appropriate function for your layout. Use scrollInWindow if the container
* is not scrollable and scrollInElement if the container is a separate
* scrolling region.
*/
Navigation = new function() {
this.initNavigation = function() {
var _this = this;
document.addEventListener('keydown', function(e) {
_this.onkeydown(e);
});
this.navigationActive = true;
}
this.setNavigationActive = function(state) {
this.navigationActive = state;
}
this.onkeydown = function(e) {
if (!this.navigationActive) return;
switch(e.key) {
case 'ArrowLeft':
if (this.moveLeft()) e.preventDefault();
break;
case 'ArrowUp':
if (e.key == 'ArrowUp' || e.ctrlKey) {
if (this.moveUp()) e.preventDefault();
}
break;
case 'ArrowRight':
if (this.moveRight()) e.preventDefault();
break;
case 'ArrowDown':
if (e.key == 'ArrowDown' || e.ctrlKey) {
if (this.moveDown()) e.preventDefault();
}
break;
case 'Enter':
if (this.current) e.preventDefault();
this.select(this.current);
break;
}
if (e.ctrlKey && e.shiftKey) this.select(this.current);
}
this.moveRight = function() {
}
this.moveLeft = function() {
}
this.move = function(isDown) {
}
this.moveUp = function() {
return this.move(false);
}
this.moveDown = function() {
return this.move(true);
}
/*
* Scrolls to the given element in the scrollable element view.
*/
this.scrollInElement = function(element, view) {
var offset, viewHeight, viewScroll, height;
offset = element.offsetTop;
height = element.offsetHeight;
viewHeight = view.offsetHeight;
viewScroll = view.scrollTop;
if (offset - viewScroll + height > viewHeight) {
view.scrollTop = offset - viewHeight + height;
}
if (offset < viewScroll) {
view.scrollTop = offset;
}
}
/*
* Scrolls to the given element in the window. The second argument is
* ignored
*/
this.scrollInWindow = function(element, ignored) {
var offset, viewHeight, viewScroll, height;
offset = element.offsetTop;
height = element.offsetHeight;
viewHeight = window.innerHeight;
viewScroll = window.scrollY;
if (offset - viewScroll + height > viewHeight) {
window.scrollTo(window.scrollX, offset - viewHeight + height);
}
if (offset < viewScroll) {
window.scrollTo(window.scrollX, offset);
}
}
}
Binary file not shown.
+110
View File
@@ -0,0 +1,110 @@
Search = function(data, input, result) {
this.data = data;
this.input = input;
this.result = result;
this.current = null;
this.view = this.result.parentNode;
this.searcher = new Searcher(data.index);
this.init();
}
Search.prototype = Object.assign({}, Navigation, new function() {
var suid = 1;
this.init = function() {
var _this = this;
var observer = function(e) {
switch(e.key) {
case 'ArrowUp':
case 'ArrowDown':
return;
}
_this.search(_this.input.value);
};
this.input.addEventListener('keyup', observer);
this.input.addEventListener('click', observer); // mac's clear field
this.searcher.ready(function(results, isLast) {
_this.addResults(results, isLast);
})
this.initNavigation();
this.setNavigationActive(false);
}
this.search = function(value, selectFirstMatch) {
value = value.trim().toLowerCase();
if (value) {
this.setNavigationActive(true);
} else {
this.setNavigationActive(false);
}
if (value == '') {
this.lastQuery = value;
this.result.innerHTML = '';
this.result.setAttribute('aria-expanded', 'false');
this.setNavigationActive(false);
} else if (value != this.lastQuery) {
this.lastQuery = value;
this.result.setAttribute('aria-busy', 'true');
this.result.setAttribute('aria-expanded', 'true');
this.firstRun = true;
this.searcher.find(value);
}
}
this.addResults = function(results, isLast) {
var target = this.result;
if (this.firstRun && (results.length > 0 || isLast)) {
this.current = null;
this.result.innerHTML = '';
}
for (var i=0, l = results.length; i < l; i++) {
var item = this.renderItem.call(this, results[i]);
item.setAttribute('id', 'search-result-' + target.childElementCount);
target.appendChild(item);
};
if (this.firstRun && results.length > 0) {
this.firstRun = false;
this.current = target.firstChild;
this.current.classList.add('search-selected');
}
//TODO: ECMAScript
//if (jQuery.browser.msie) this.$element[0].className += '';
if (isLast) this.result.setAttribute('aria-busy', 'false');
}
this.move = function(isDown) {
if (!this.current) return;
var next = isDown ? this.current.nextElementSibling : this.current.previousElementSibling;
if (next) {
this.current.classList.remove('search-selected');
next.classList.add('search-selected');
this.input.setAttribute('aria-activedescendant', next.getAttribute('id'));
this.scrollIntoView(next, this.view);
this.current = next;
this.input.value = next.firstChild.firstChild.text;
this.input.select();
}
return true;
}
this.hlt = function(html) {
return this.escapeHTML(html).
replace(/\u0001/g, '<em>').
replace(/\u0002/g, '</em>');
}
this.escapeHTML = function(html) {
return html.replace(/[&<>"`']/g, function(c) {
return '&#' + c.charCodeAt(0) + ';';
});
}
});
+1
View File
@@ -0,0 +1 @@
var search_data = {"index":{"searchIndex":["card","deck","game","player","terminalui","add_point()","change_dealer()","choose_card()","clear_hand()","deal()","debug_game()","determine_dealer()","display_trick_winner()","display_wrong_card()","draw()","game_winner()","new()","new()","new()","new()","other_player()","play()","play()","play_trick()","receive()","shuffle()","stock()","strength()","to_s()","valid_follow_card?()","readme"],"longSearchIndex":["card","deck","game","player","terminalui","player#add_point()","game#change_dealer()","terminalui#choose_card()","player#clear_hand()","game#deal()","terminalui#debug_game()","game#determine_dealer()","terminalui#display_trick_winner()","terminalui#display_wrong_card()","deck#draw()","game#game_winner()","card::new()","deck::new()","game::new()","player::new()","game#other_player()","game#play()","player#play()","game#play_trick()","player#receive()","deck#shuffle()","game#stock()","card#strength()","card#to_s()","game#valid_follow_card?()",""],"info":[["Card","","Card.html","","<p>Représente une carte à jouer avec sa valeur et sa couleur.\n"],["Deck","","Deck.html","","<p>Représente un paquet de cartes et gère son contenu.\n"],["Game","","Game.html","","<p>Gère le déroulement et les règles d’une partie d’Écarté.\n"],["Player","","Player.html","","<p>Représente un joueur, sa main et son score.\n"],["TerminalUI","","TerminalUI.html","","<p>Gère l’affichage et les saisies dans le terminal.\n"],["add_point","Player","Player.html#method-i-add_point","()","<p>Ajoute un point au joueur.\n"],["change_dealer","Game","Game.html#method-i-change_dealer","()","<p>Échange les rôles de donneur et de non-donneur.\n"],["choose_card","TerminalUI","TerminalUI.html#method-i-choose_card","(player)","<p>Demande au joueur de choisir une carte et la retourne.\n"],["clear_hand","Player","Player.html#method-i-clear_hand","()","<p>Vide la main du joueur.\n"],["deal","Game","Game.html#method-i-deal","()","<p>Distribue les cartes et pose la retourne.\n"],["debug_game","TerminalUI","TerminalUI.html#method-i-debug_game","(game)","<p>Affiche les informations de débogage.\n"],["determine_dealer","Game","Game.html#method-i-determine_dealer","()","<p>Simule une coupe pour déterminer quel joueur sera le donneur.\n"],["display_trick_winner","TerminalUI","TerminalUI.html#method-i-display_trick_winner","(player)","<p>Affiche le joueur ayant remporté le pli.\n"],["display_wrong_card","TerminalUI","TerminalUI.html#method-i-display_wrong_card","()","<p>Affiche un avertissement si le coup joué ne respecte pas les règles.\n"],["draw","Deck","Deck.html#method-i-draw","()","<p>Retire et retourne la dernière carte du paquet.\n"],["game_winner","Game","Game.html#method-i-game_winner","()","<p>Retourne le joueur ayant le meilleur score.\n"],["new","Card","Card.html#method-c-new","(value, suit)",""],["new","Deck","Deck.html#method-c-new","()",""],["new","Game","Game.html#method-c-new","(player_name1, player_name2)",""],["new","Player","Player.html#method-c-new","(name)",""],["other_player","Game","Game.html#method-i-other_player","(player)","<p>Retourne l’autre joueur.\n"],["play","Game","Game.html#method-i-play","()","<p>Joue une partie.\n"],["play","Player","Player.html#method-i-play","(card)","<p>Retire une carte de la main du joueur.\n"],["play_trick","Game","Game.html#method-i-play_trick","(lead_player, follow_player)","<p>Joue un pli.\n"],["receive","Player","Player.html#method-i-receive","(card)","<p>Ajoute une carte à la main du joueur.\n"],["shuffle","Deck","Deck.html#method-i-shuffle","()","<p>Mélange les cartes du paquet.\n"],["stock","Game","Game.html#method-i-stock","()","<p>Retourne les cartes restantes dans le talon.\n"],["strength","Card","Card.html#method-i-strength","()","<p>Retourne la force de la carte sous forme d’integer.\n"],["to_s","Card","Card.html#method-i-to_s","()","<p>Retourne une représentation de la carte sous forme de string.\n"],["valid_follow_card?","Game","Game.html#method-i-valid_follow_card-3F","(follow_player, lead_card, follow_card)","<p>Vérifie si le coup du second joueur respecte les règles.\n"],["README","","README_md.html","","<p>Écarté\n"]]}}
Binary file not shown.
+229
View File
@@ -0,0 +1,229 @@
Searcher = function(data) {
this.data = data;
this.handlers = [];
}
Searcher.prototype = new function() {
// search is performed in chunks of 1000 for non-blocking user input
var CHUNK_SIZE = 1000;
// do not try to find more than 100 results
var MAX_RESULTS = 100;
var huid = 1;
var suid = 1;
var runs = 0;
this.find = function(query) {
var queries = splitQuery(query);
var regexps = buildRegexps(queries);
var highlighters = buildHilighters(queries);
var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
var _this = this;
this.currentSuid = state.n;
if (!query) return;
var run = function() {
// stop current search thread if new search started
if (state.n != _this.currentSuid) return;
var results =
performSearch(_this.data, regexps, queries, highlighters, state);
var hasMore = (state.limit > 0 && state.pass < 4);
triggerResults.call(_this, results, !hasMore);
if (hasMore) {
setTimeout(run, 2);
}
runs++;
};
runs = 0;
// start search thread
run();
}
/* ----- Events ------ */
this.ready = function(fn) {
fn.huid = huid;
this.handlers.push(fn);
}
/* ----- Utilities ------ */
function splitQuery(query) {
return query.split(/(\s+|::?|\(\)?)/).filter(function(string) {
return string.match(/\S/);
});
}
function buildRegexps(queries) {
return queries.map(function(query) {
return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
});
}
function buildHilighters(queries) {
return queries.map(function(query) {
return query.split('').map(function(l, i) {
return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
}).join('');
});
}
// function longMatchRegexp(index, longIndex, regexps) {
// for (var i = regexps.length - 1; i >= 0; i--){
// if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
// };
// return true;
// }
/* ----- Mathchers ------ */
/*
* This record matches if the index starts with queries[0] and the record
* matches all of the regexps
*/
function matchPassBeginning(index, longIndex, queries, regexps) {
if (index.indexOf(queries[0]) != 0) return false;
for (var i=1, l = regexps.length; i < l; i++) {
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
return false;
};
return true;
}
/*
* This record matches if the longIndex starts with queries[0] and the
* longIndex matches all of the regexps
*/
function matchPassLongIndex(index, longIndex, queries, regexps) {
if (longIndex.indexOf(queries[0]) != 0) return false;
for (var i=1, l = regexps.length; i < l; i++) {
if (!longIndex.match(regexps[i]))
return false;
};
return true;
}
/*
* This record matches if the index contains queries[0] and the record
* matches all of the regexps
*/
function matchPassContains(index, longIndex, queries, regexps) {
if (index.indexOf(queries[0]) == -1) return false;
for (var i=1, l = regexps.length; i < l; i++) {
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
return false;
};
return true;
}
/*
* This record matches if regexps[0] matches the index and the record
* matches all of the regexps
*/
function matchPassRegexp(index, longIndex, queries, regexps) {
if (!index.match(regexps[0])) return false;
for (var i=1, l = regexps.length; i < l; i++) {
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
return false;
};
return true;
}
/* ----- Highlighters ------ */
function highlightRegexp(info, queries, regexps, highlighters) {
var result = createResult(info);
for (var i=0, l = regexps.length; i < l; i++) {
result.title = result.title.replace(regexps[i], highlighters[i]);
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
};
return result;
}
function hltSubstring(string, pos, length) {
return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
}
function highlightQuery(info, queries, regexps, highlighters) {
var result = createResult(info);
var pos = 0;
var lcTitle = result.title.toLowerCase();
pos = lcTitle.indexOf(queries[0]);
if (pos != -1) {
result.title = hltSubstring(result.title, pos, queries[0].length);
}
result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
for (var i=1, l = regexps.length; i < l; i++) {
result.title = result.title.replace(regexps[i], highlighters[i]);
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
};
return result;
}
function createResult(info) {
var result = {};
result.title = info[0];
result.namespace = info[1];
result.path = info[2];
result.params = info[3];
result.snippet = info[4];
result.badge = info[6];
return result;
}
/* ----- Searching ------ */
function performSearch(data, regexps, queries, highlighters, state) {
var searchIndex = data.searchIndex;
var longSearchIndex = data.longSearchIndex;
var info = data.info;
var result = [];
var i = state.from;
var l = searchIndex.length;
var togo = CHUNK_SIZE;
var matchFunc, hltFunc;
while (state.pass < 4 && state.limit > 0 && togo > 0) {
if (state.pass == 0) {
matchFunc = matchPassBeginning;
hltFunc = highlightQuery;
} else if (state.pass == 1) {
matchFunc = matchPassLongIndex;
hltFunc = highlightQuery;
} else if (state.pass == 2) {
matchFunc = matchPassContains;
hltFunc = highlightQuery;
} else if (state.pass == 3) {
matchFunc = matchPassRegexp;
hltFunc = highlightRegexp;
}
for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
if (info[i].n == state.n) continue;
if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
info[i].n = state.n;
result.push(hltFunc(info[i], queries, regexps, highlighters));
state.limit--;
}
};
if (searchIndex.length <= i) {
state.pass++;
i = state.from = 0;
} else {
state.from = i;
}
}
return result;
}
function triggerResults(results, isLast) {
this.handlers.forEach(function(fn) {
fn.call(this, results, isLast)
});
}
}
Binary file not shown.