chess 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Rakefile +1 -0
- data/doc/apple-touch-icon.png +0 -0
- data/doc/classes/Chess.html +162 -0
- data/doc/classes/Chess/BadNotationError.html +84 -0
- data/doc/classes/Chess/Board.html +795 -0
- data/doc/classes/Chess/CGame.html +1168 -0
- data/doc/classes/Chess/Game.html +775 -0
- data/doc/classes/Chess/Gnuchess.html +206 -0
- data/doc/classes/Chess/IllegalMoveError.html +82 -0
- data/doc/classes/Chess/InvalidFenFormatError.html +82 -0
- data/doc/classes/Chess/InvalidPgnFormatError.html +82 -0
- data/doc/classes/Chess/Pgn.html +332 -0
- data/doc/classes/Chess/UTF8Notation.html +175 -0
- data/doc/created.rid +15 -0
- data/doc/css/github.css +123 -0
- data/doc/css/main.css +323 -0
- data/doc/css/panel.css +384 -0
- data/doc/css/reset.css +48 -0
- data/doc/favicon.ico +0 -0
- data/doc/files/README_rdoc.html +122 -0
- data/doc/files/ext/bitboard_c.html +68 -0
- data/doc/files/ext/board_c.html +68 -0
- data/doc/files/ext/chess_c.html +68 -0
- data/doc/files/ext/common_c.html +68 -0
- data/doc/files/ext/game_c.html +68 -0
- data/doc/files/ext/special_c.html +68 -0
- data/doc/files/lib/chess/exceptions_rb.html +94 -0
- data/doc/files/lib/chess/game_rb.html +84 -0
- data/doc/files/lib/chess/gnuchess_rb.html +84 -0
- data/doc/files/lib/chess/pgn_rb.html +84 -0
- data/doc/files/lib/chess/utf8_notation_rb.html +84 -0
- data/doc/files/lib/chess/version_rb.html +85 -0
- data/doc/files/lib/chess_rb.html +84 -0
- data/doc/i/arrows.png +0 -0
- data/doc/i/results_bg.png +0 -0
- data/doc/i/tree_bg.png +0 -0
- data/doc/index.html +13 -0
- data/doc/js/highlight.pack.js +1 -0
- data/doc/js/jquery-1.3.2.min.js +19 -0
- data/doc/js/jquery-effect.js +593 -0
- data/doc/js/main.js +24 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searchdoc.js +449 -0
- data/doc/js/searcher.js +228 -0
- data/doc/panel/index.html +73 -0
- data/doc/panel/links.html +34 -0
- data/doc/panel/tree.js +1 -0
- data/ext/chess.c +82 -33
- data/ext/chess.h +1 -1
- data/ext/common.c +1 -1
- data/ext/common.h +1 -1
- data/ext/game.c +7 -6
- data/ext/game.h +1 -1
- data/lib/chess/exceptions.rb +2 -1
- data/lib/chess/game.rb +18 -5
- data/lib/chess/gnuchess.rb +1 -1
- data/lib/chess/utf8_notation.rb +1 -0
- data/lib/chess/version.rb +1 -1
- metadata +50 -3
data/doc/js/main.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
function toggleSource(id)
|
2
|
+
{
|
3
|
+
var src = $('#' + id).toggle();
|
4
|
+
var isVisible = src.is(':visible');
|
5
|
+
$('#l_' + id).html(isVisible ? 'hide' : 'show');
|
6
|
+
if (!src.data('syntax-higlighted')) {
|
7
|
+
src.data('syntax-higlighted', 1);
|
8
|
+
hljs.highlightBlock(src[0]);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
window.highlight = function(url) {
|
13
|
+
var hash = url.match(/#([^#]+)$/)
|
14
|
+
if(hash) {
|
15
|
+
$('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
$(function() {
|
20
|
+
highlight('#' + location.hash);
|
21
|
+
$('.description pre').each(function() {
|
22
|
+
hljs.highlightBlock(this);
|
23
|
+
});
|
24
|
+
});
|
@@ -0,0 +1,142 @@
|
|
1
|
+
/*
|
2
|
+
* Navigation allows movement using the arrow keys through the search results.
|
3
|
+
*
|
4
|
+
* When using this library you will need to set scrollIntoView to the
|
5
|
+
* appropriate function for your layout. Use scrollInWindow if the container
|
6
|
+
* is not scrollable and scrollInElement if the container is a separate
|
7
|
+
* scrolling region.
|
8
|
+
*/
|
9
|
+
Navigation = new function() {
|
10
|
+
this.initNavigation = function() {
|
11
|
+
var _this = this;
|
12
|
+
|
13
|
+
$(document).keydown(function(e) {
|
14
|
+
_this.onkeydown(e);
|
15
|
+
}).keyup(function(e) {
|
16
|
+
_this.onkeyup(e);
|
17
|
+
});
|
18
|
+
|
19
|
+
this.navigationActive = true;
|
20
|
+
}
|
21
|
+
|
22
|
+
this.setNavigationActive = function(state) {
|
23
|
+
this.navigationActive = state;
|
24
|
+
this.clearMoveTimeout();
|
25
|
+
}
|
26
|
+
|
27
|
+
this.onkeyup = function(e) {
|
28
|
+
if (!this.navigationActive) return;
|
29
|
+
|
30
|
+
switch(e.keyCode) {
|
31
|
+
case 37: //Event.KEY_LEFT:
|
32
|
+
case 38: //Event.KEY_UP:
|
33
|
+
case 39: //Event.KEY_RIGHT:
|
34
|
+
case 40: //Event.KEY_DOWN:
|
35
|
+
this.clearMoveTimeout();
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
this.onkeydown = function(e) {
|
41
|
+
if (!this.navigationActive) return;
|
42
|
+
switch(e.keyCode) {
|
43
|
+
case 37: //Event.KEY_LEFT:
|
44
|
+
if (this.moveLeft()) e.preventDefault();
|
45
|
+
break;
|
46
|
+
case 38: //Event.KEY_UP:
|
47
|
+
if (e.keyCode == 38 || e.ctrlKey) {
|
48
|
+
if (this.moveUp()) e.preventDefault();
|
49
|
+
this.startMoveTimeout(false);
|
50
|
+
}
|
51
|
+
break;
|
52
|
+
case 39: //Event.KEY_RIGHT:
|
53
|
+
if (this.moveRight()) e.preventDefault();
|
54
|
+
break;
|
55
|
+
case 40: //Event.KEY_DOWN:
|
56
|
+
if (e.keyCode == 40 || e.ctrlKey) {
|
57
|
+
if (this.moveDown()) e.preventDefault();
|
58
|
+
this.startMoveTimeout(true);
|
59
|
+
}
|
60
|
+
break;
|
61
|
+
case 13: //Event.KEY_RETURN:
|
62
|
+
if (this.$current)
|
63
|
+
e.preventDefault();
|
64
|
+
this.select(this.$current);
|
65
|
+
break;
|
66
|
+
}
|
67
|
+
if (e.ctrlKey && e.shiftKey) this.select(this.$current);
|
68
|
+
}
|
69
|
+
|
70
|
+
this.clearMoveTimeout = function() {
|
71
|
+
clearTimeout(this.moveTimeout);
|
72
|
+
this.moveTimeout = null;
|
73
|
+
}
|
74
|
+
|
75
|
+
this.startMoveTimeout = function(isDown) {
|
76
|
+
if (!$.browser.mozilla && !$.browser.opera) return;
|
77
|
+
if (this.moveTimeout) this.clearMoveTimeout();
|
78
|
+
var _this = this;
|
79
|
+
|
80
|
+
var go = function() {
|
81
|
+
if (!_this.moveTimeout) return;
|
82
|
+
_this[isDown ? 'moveDown' : 'moveUp']();
|
83
|
+
_this.moveTimout = setTimeout(go, 100);
|
84
|
+
}
|
85
|
+
this.moveTimeout = setTimeout(go, 200);
|
86
|
+
}
|
87
|
+
|
88
|
+
this.moveRight = function() {
|
89
|
+
}
|
90
|
+
|
91
|
+
this.moveLeft = function() {
|
92
|
+
}
|
93
|
+
|
94
|
+
this.move = function(isDown) {
|
95
|
+
}
|
96
|
+
|
97
|
+
this.moveUp = function() {
|
98
|
+
return this.move(false);
|
99
|
+
}
|
100
|
+
|
101
|
+
this.moveDown = function() {
|
102
|
+
return this.move(true);
|
103
|
+
}
|
104
|
+
|
105
|
+
/*
|
106
|
+
* Scrolls to the given element in the scrollable element view.
|
107
|
+
*/
|
108
|
+
this.scrollInElement = function(element, view) {
|
109
|
+
var offset, viewHeight, viewScroll, height;
|
110
|
+
offset = element.offsetTop;
|
111
|
+
height = element.offsetHeight;
|
112
|
+
viewHeight = view.offsetHeight;
|
113
|
+
viewScroll = view.scrollTop;
|
114
|
+
|
115
|
+
if (offset - viewScroll + height > viewHeight) {
|
116
|
+
view.scrollTop = offset - viewHeight + height;
|
117
|
+
}
|
118
|
+
if (offset < viewScroll) {
|
119
|
+
view.scrollTop = offset;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
/*
|
124
|
+
* Scrolls to the given element in the window. The second argument is
|
125
|
+
* ignored
|
126
|
+
*/
|
127
|
+
this.scrollInWindow = function(element, ignored) {
|
128
|
+
var offset, viewHeight, viewScroll, height;
|
129
|
+
offset = element.offsetTop;
|
130
|
+
height = element.offsetHeight;
|
131
|
+
viewHeight = window.innerHeight;
|
132
|
+
viewScroll = window.scrollY;
|
133
|
+
|
134
|
+
if (offset - viewScroll + height > viewHeight) {
|
135
|
+
window.scrollTo(window.scrollX, offset - viewHeight + height);
|
136
|
+
}
|
137
|
+
if (offset < viewScroll) {
|
138
|
+
window.scrollTo(window.scrollX, offset);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
var search_data = {"index":{"searchIndex":["chess","badnotationerror","board","cgame","game","gnuchess","illegalmoveerror","invalidfenformaterror","invalidpgnformaterror","pgn","utf8notation","<<()","[]()","[]()","active_color()","active_player()","board()","check?()","checkmate?()","coord_moves()","current()","draw()","each()","fifty_rule_move?()","full_moves()","fullmove_number()","gnuchess_move()","gnuchess_move!()","halfmove_clock()","inactive_player()","insufficient_material?()","load()","load_fen()","load_pgn()","move()","move()","move2()","move3()","move=()","moves()","moves=()","new()","new()","over?()","pgn()","placement()","resign()","result()","rollback!()","set_fen!()","size()","stalemate?()","status()","threefold_repetition?()","to_fen()","to_s()","to_s()","to_s()","to_utf8()","write()","readme"],"longSearchIndex":["chess","chess::badnotationerror","chess::board","chess::cgame","chess::game","chess::gnuchess","chess::illegalmoveerror","chess::invalidfenformaterror","chess::invalidpgnformaterror","chess::pgn","chess::utf8notation","chess::game#<<()","chess::board#[]()","chess::cgame#[]()","chess::board#active_color()","chess::game#active_player()","chess::cgame#board()","chess::board#check?()","chess::board#checkmate?()","chess::cgame#coord_moves()","chess::cgame#current()","chess::cgame#draw()","chess::cgame#each()","chess::board#fifty_rule_move?()","chess::cgame#full_moves()","chess::board#fullmove_number()","chess::gnuchess#gnuchess_move()","chess::gnuchess#gnuchess_move!()","chess::board#halfmove_clock()","chess::game#inactive_player()","chess::board#insufficient_material?()","chess::pgn#load()","chess::game::load_fen()","chess::game::load_pgn()","chess::cgame#move()","chess::game#move()","chess::cgame#move2()","chess::cgame#move3()","chess::game#move=()","chess::cgame#moves()","chess::game#moves=()","chess::game::new()","chess::pgn::new()","chess::game#over?()","chess::game#pgn()","chess::board#placement()","chess::cgame#resign()","chess::cgame#result()","chess::cgame#rollback!()","chess::cgame#set_fen!()","chess::cgame#size()","chess::board#stalemate?()","chess::game#status()","chess::cgame#threefold_repetition?()","chess::board#to_fen()","chess::board#to_s()","chess::cgame#to_s()","chess::pgn#to_s()","chess::utf8notation#to_utf8()","chess::pgn#write()",""],"info":[["Chess","","classes/Chess.html","","<p>The Chess library module.\n"],["Chess::BadNotationError","","classes/Chess/BadNotationError.html","","<p>This exception will be raised when an invalid short algebraic chess\nnotation string is passed to the …\n"],["Chess::Board","","classes/Chess/Board.html","","<p>This class rappresents a chess board. The rappresentation of the board use\n<em>bitboards</em> where each bit represents …\n"],["Chess::CGame","","classes/Chess/CGame.html","","<p>This class rappresents a collection of boards of a single chess game.\n"],["Chess::Game","","classes/Chess/Game.html","","<p>This class rappresents a chess game.\n"],["Chess::Gnuchess","","classes/Chess/Gnuchess.html","","<p>Use Gnuchess to I.A. <em>(Only a draft)</em> To use this module, extend a\ngame object with Chess::Gnuchess. Gnuchess …\n"],["Chess::IllegalMoveError","","classes/Chess/IllegalMoveError.html","","<p>This exception will be raised when making an illegal move.\n"],["Chess::InvalidFenFormatError","","classes/Chess/InvalidFenFormatError.html","","<p>This exception will be raised when an invalid FEN string is used.\n"],["Chess::InvalidPgnFormatError","","classes/Chess/InvalidPgnFormatError.html","","<p>This exception will be raised when a malformed PGN file is loaded.\n"],["Chess::Pgn","","classes/Chess/Pgn.html","","<p>Rappresents a game in PGN (Portable Game Notation) format.\n"],["Chess::UTF8Notation","","classes/Chess/UTF8Notation.html","","<p>With this module is possible call the method <code>to_utf8</code> on a\nstring. This method convert the chess piece …\n"],["<<","Chess::Game","classes/Chess/Game.html#method-i-3C-3C","(m)",""],["[]","Chess::Board","classes/Chess/Board.html#method-i-5B-5D","(p1)","<p>Returns the piece on the <code>square</code> of the chessboard. If there is\nno piece or the square is not valid return …\n"],["[]","Chess::CGame","classes/Chess/CGame.html#method-i-5B-5D","(p1)","<p>Returns the <code>n</code>-th Board of the Game or <code>nil</code> if the\n<code>n</code>-th Board does not exist.\n"],["active_color","Chess::Board","classes/Chess/Board.html#method-i-active_color","()","<p>Returns the active color: <code>false</code> means white turn,\n<code>true</code> means black turn.\n"],["active_player","Chess::Game","classes/Chess/Game.html#method-i-active_player","()","<p>Returns <code>:white</code> if the active player is the white player,\n<code>:black</code> otherwise.\n"],["board","Chess::CGame","classes/Chess/CGame.html#method-i-board","()",""],["check?","Chess::Board","classes/Chess/Board.html#method-i-check-3F","()","<p>Returns <code>true</code> if the king of the color that has the turn is in\ncheck, <code>false</code> otherwise.\n"],["checkmate?","Chess::Board","classes/Chess/Board.html#method-i-checkmate-3F","()","<p>Returns <code>true</code> if the king of the color that has the turn is in\ncheckmate, <code>false</code> otherwise.\n"],["coord_moves","Chess::CGame","classes/Chess/CGame.html#method-i-coord_moves","()","<p>Returns the array with all moves done in coordinate chess notation <em>(es:\nb1c3)</em>.\n"],["current","Chess::CGame","classes/Chess/CGame.html#method-i-current","()","<p>Returns the current Board of the Game (the current chess position of the\ngame).\n"],["draw","Chess::CGame","classes/Chess/CGame.html#method-i-draw","()","<p>The game result is set to draw.\n"],["each","Chess::CGame","classes/Chess/CGame.html#method-i-each","()","<p>Calls <code>block</code> once for each <code>board</code> in self, passing\nthat <code>board</code>, <code>move</code>, <code>full_move</code> and\n<code>index</code> as parameters. …\n"],["fifty_rule_move?","Chess::Board","classes/Chess/Board.html#method-i-fifty_rule_move-3F","()","<p>Returns <code>true</code> if a player can claim draw by the fifty-move\nrule, <code>false</code> otherwise.\n"],["full_moves","Chess::CGame","classes/Chess/CGame.html#method-i-full_moves","()",""],["fullmove_number","Chess::Board","classes/Chess/Board.html#method-i-fullmove_number","()","<p>Returns the fullmove number: the number of the full move. It starts at 1,\nand is incremented after black's …\n"],["gnuchess_move","Chess::Gnuchess","classes/Chess/Gnuchess.html#method-i-gnuchess_move","()","<p>Return the next move calculated by Gnuchess. Gnuchess must be installed!\n"],["gnuchess_move!","Chess::Gnuchess","classes/Chess/Gnuchess.html#method-i-gnuchess_move-21","()","<p>Make a move using Gnuchess engine. This add a new Board in the Game. Return\nthe next move calculated …\n"],["halfmove_clock","Chess::Board","classes/Chess/Board.html#method-i-halfmove_clock","()","<p>Returns the halfmove clock that is the number of halfmoves since the last\npawn advance or capture. This …\n"],["inactive_player","Chess::Game","classes/Chess/Game.html#method-i-inactive_player","()","<p>Returns <code>:white</code> if the inactive player is the white player,\n<code>:black</code> otherwise.\n"],["insufficient_material?","Chess::Board","classes/Chess/Board.html#method-i-insufficient_material-3F","()","<p>Returns <code>true</code> if the board has insufficient material to\ncheckmate, <code>false</code> otherwise.\n"],["load","Chess::Pgn","classes/Chess/Pgn.html#method-i-load","(filename)","<p>Load a PGN from file.\n"],["load_fen","Chess::Game","classes/Chess/Game.html#method-c-load_fen","(fen)","<p>Creates a new game from a FEN string.\n<p>May be raise an InvalidFenFormatError.\n<p><strong>Warning</strong>: this game do not …\n"],["load_pgn","Chess::Game","classes/Chess/Game.html#method-c-load_pgn","(file)","<p>Creates a new game from a file in PGN format.\n<p>May be raise an InvalidPgnFormatError or IllegalMoveError …\n"],["move","Chess::CGame","classes/Chess/CGame.html#method-i-move","(p1, p2, p3, p4)","<p>Make a move. This add a new Board in the Game.\n<p>Parameters are:\n<p><code>piece</code> — the character of the moving piece …\n"],["move","Chess::Game","classes/Chess/Game.html#method-i-move","(m)","<p>Make a move. This add a new Board in the Storyboard.\n<p>Parameters are:\n<p><code>m</code> — represents the short algebraic chess …\n"],["move2","Chess::CGame","classes/Chess/CGame.html#method-i-move2","(p1, p2, p3)","<p>Make a move. This add a new Board in the Game.\n<p>Parameters are:\n<p><code>from</code> — the 2 character string representing …\n"],["move3","Chess::CGame","classes/Chess/CGame.html#method-i-move3","(p1, p2, p3)","<p>Make a move. This add a new Board in the Game.\n<p>Each square on the chessboard is represented by an integer …\n"],["move=","Chess::Game","classes/Chess/Game.html#method-i-move-3D","(m)",""],["moves","Chess::CGame","classes/Chess/CGame.html#method-i-moves","()","<p>Returns the array with all moves done <em>(es: Nc3)</em>.\n"],["moves=","Chess::Game","classes/Chess/Game.html#method-i-moves-3D","(moves)","<p>Make the array of moves.\n"],["new","Chess::Game","classes/Chess/Game.html#method-c-new","(moves = [])","<p>Create a new game. If an array of moves is provided, the moves will be\nperformed.\n<p>May be raise an IllegalMoveError …\n"],["new","Chess::Pgn","classes/Chess/Pgn.html#method-c-new","(filename = nil)","<p>Creates a new PGN. If param <code>filename</code>, load it from file.\n"],["over?","Chess::Game","classes/Chess/Game.html#method-i-over-3F","()","<p>Returns <code>true</code> if the game is over\n"],["pgn","Chess::Game","classes/Chess/Game.html#method-i-pgn","()","<p>Returns the PGN rappresenting the game.\n"],["placement","Chess::Board","classes/Chess/Board.html#method-i-placement","()","<p>Calls <code>block</code> once for each square in the board, passing the\n<code>piece</code> in the square and the <code>index</code> as parameters.\n…\n"],["resign","Chess::CGame","classes/Chess/CGame.html#method-i-resign","(p1)","<p>The game result is set to '1-0' if <code>color</code> is “black”,\notherwise is set to '0-1' …\n"],["result","Chess::CGame","classes/Chess/CGame.html#method-i-result","()","<p>Returns the result of the game:\n<p>* — game in progress;\n<p>1-0 — white won;\n"],["rollback!","Chess::CGame","classes/Chess/CGame.html#method-i-rollback-21","()","<p>Rollback last move.\n"],["set_fen!","Chess::CGame","classes/Chess/CGame.html#method-i-set_fen-21","(p1)","<p>Set the game position with a FEN string.\n<p>Parameters are:\n<p><code>fen</code> — the FEN (Forsyth–Edwards Notation) string …\n"],["size","Chess::CGame","classes/Chess/CGame.html#method-i-size","()","<p>Returns the number of moves done.\n"],["stalemate?","Chess::Board","classes/Chess/Board.html#method-i-stalemate-3F","()","<p>Returns <code>true</code> if the pieces of the color that has the turn are\nin stalemate, <code>false</code> otherwise.\n"],["status","Chess::Game","classes/Chess/Game.html#method-i-status","()","<p>Returns the status of the game.\n<p>Possible states are:\n<p><p><code>in_progress</code> — the game is in progress.\n"],["threefold_repetition?","Chess::CGame","classes/Chess/CGame.html#method-i-threefold_repetition-3F","()","<p>Returns <code>true</code> if a player can claim draw by the threefold\nrepetition rule, <code>false</code> otherwise.\n"],["to_fen","Chess::Board","classes/Chess/Board.html#method-i-to_fen","()","<p>Return the FEN string of the board.\n"],["to_s","Chess::Board","classes/Chess/Board.html#method-i-to_s","()","<p>Board to string.\n"],["to_s","Chess::CGame","classes/Chess/CGame.html#method-i-to_s","()","<p>Current board to string.\n"],["to_s","Chess::Pgn","classes/Chess/Pgn.html#method-i-to_s","()","<p>PGN to string.\n"],["to_utf8","Chess::UTF8Notation","classes/Chess/UTF8Notation.html#method-i-to_utf8","()","<p>Replace the piece identifier characters with UTF8 chess characters\n"],["write","Chess::Pgn","classes/Chess/Pgn.html#method-i-write","(filename)","<p>Write PGN to file.\n"],["README","","files/README_rdoc.html","","<p>Chess\n<p>A fast Ruby library to play chess with Ruby. This library is quite fast\nbecause rappresent the game …\n"]]}}
|
data/doc/js/searchdoc.js
ADDED
@@ -0,0 +1,449 @@
|
|
1
|
+
Searchdoc = {};
|
2
|
+
|
3
|
+
// navigation.js ------------------------------------------
|
4
|
+
|
5
|
+
Searchdoc.Navigation = new function() {
|
6
|
+
this.initNavigation = function() {
|
7
|
+
var _this = this;
|
8
|
+
|
9
|
+
$(document).keydown(function(e) {
|
10
|
+
_this.onkeydown(e);
|
11
|
+
}).keyup(function(e) {
|
12
|
+
_this.onkeyup(e);
|
13
|
+
});
|
14
|
+
|
15
|
+
this.navigationActive = true;
|
16
|
+
}
|
17
|
+
|
18
|
+
this.setNavigationActive = function(state) {
|
19
|
+
this.navigationActive = state;
|
20
|
+
this.clearMoveTimeout();
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
this.onkeyup = function(e) {
|
25
|
+
if (!this.navigationActive) return;
|
26
|
+
switch(e.keyCode) {
|
27
|
+
case 37: //Event.KEY_LEFT:
|
28
|
+
case 38: //Event.KEY_UP:
|
29
|
+
case 39: //Event.KEY_RIGHT:
|
30
|
+
case 40: //Event.KEY_DOWN:
|
31
|
+
case 73: // i - qwerty
|
32
|
+
case 74: // j
|
33
|
+
case 75: // k
|
34
|
+
case 76: // l
|
35
|
+
case 67: // c - dvorak
|
36
|
+
case 72: // h
|
37
|
+
case 84: // t
|
38
|
+
case 78: // n
|
39
|
+
this.clearMoveTimeout();
|
40
|
+
break;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
this.onkeydown = function(e) {
|
45
|
+
if (!this.navigationActive) return;
|
46
|
+
switch(e.keyCode) {
|
47
|
+
case 37: //Event.KEY_LEFT:
|
48
|
+
case 74: // j (qwerty)
|
49
|
+
case 72: // h (dvorak)
|
50
|
+
if (this.moveLeft()) e.preventDefault();
|
51
|
+
break;
|
52
|
+
case 38: //Event.KEY_UP:
|
53
|
+
case 73: // i (qwerty)
|
54
|
+
case 67: // c (dvorak)
|
55
|
+
if (e.keyCode == 38 || e.ctrlKey) {
|
56
|
+
if (this.moveUp()) e.preventDefault();
|
57
|
+
this.startMoveTimeout(false);
|
58
|
+
}
|
59
|
+
break;
|
60
|
+
case 39: //Event.KEY_RIGHT:
|
61
|
+
case 76: // l (qwerty)
|
62
|
+
case 78: // n (dvorak)
|
63
|
+
if (this.moveRight()) e.preventDefault();
|
64
|
+
break;
|
65
|
+
case 40: //Event.KEY_DOWN:
|
66
|
+
case 75: // k (qwerty)
|
67
|
+
case 84: // t (dvorak)
|
68
|
+
if (e.keyCode == 40 || e.ctrlKey) {
|
69
|
+
if (this.moveDown()) e.preventDefault();
|
70
|
+
this.startMoveTimeout(true);
|
71
|
+
}
|
72
|
+
break;
|
73
|
+
case 9: //Event.KEY_TAB:
|
74
|
+
case 13: //Event.KEY_RETURN:
|
75
|
+
if (this.$current) this.select(this.$current);
|
76
|
+
break;
|
77
|
+
case 83: // s (qwerty)
|
78
|
+
case 79: // o (dvorak)
|
79
|
+
if (e.ctrlKey) {
|
80
|
+
$('#search').focus();
|
81
|
+
e.preventDefault();
|
82
|
+
}
|
83
|
+
break;
|
84
|
+
}
|
85
|
+
if (e.ctrlKey && e.shiftKey) this.select(this.$current);
|
86
|
+
}
|
87
|
+
|
88
|
+
this.clearMoveTimeout = function() {
|
89
|
+
clearTimeout(this.moveTimeout);
|
90
|
+
this.moveTimeout = null;
|
91
|
+
}
|
92
|
+
|
93
|
+
this.startMoveTimeout = function(isDown) {
|
94
|
+
if (!$.browser.mozilla && !$.browser.opera) return;
|
95
|
+
if (this.moveTimeout) this.clearMoveTimeout();
|
96
|
+
var _this = this;
|
97
|
+
|
98
|
+
var go = function() {
|
99
|
+
if (!_this.moveTimeout) return;
|
100
|
+
_this[isDown ? 'moveDown' : 'moveUp']();
|
101
|
+
_this.moveTimout = setTimeout(go, 100);
|
102
|
+
}
|
103
|
+
this.moveTimeout = setTimeout(go, 200);
|
104
|
+
}
|
105
|
+
|
106
|
+
this.moveRight = function() {
|
107
|
+
}
|
108
|
+
|
109
|
+
this.moveLeft = function() {
|
110
|
+
}
|
111
|
+
|
112
|
+
this.move = function(isDown) {
|
113
|
+
}
|
114
|
+
|
115
|
+
this.moveUp = function() {
|
116
|
+
return this.move(false);
|
117
|
+
}
|
118
|
+
|
119
|
+
this.moveDown = function() {
|
120
|
+
return this.move(true);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
|
125
|
+
// scrollIntoView.js --------------------------------------
|
126
|
+
|
127
|
+
function scrollIntoView(element, view) {
|
128
|
+
var offset, viewHeight, viewScroll, height;
|
129
|
+
offset = element.offsetTop;
|
130
|
+
height = element.offsetHeight;
|
131
|
+
viewHeight = view.offsetHeight;
|
132
|
+
viewScroll = view.scrollTop;
|
133
|
+
if (offset - viewScroll + height > viewHeight) {
|
134
|
+
view.scrollTop = offset - viewHeight + height;
|
135
|
+
}
|
136
|
+
if (offset < viewScroll) {
|
137
|
+
view.scrollTop = offset;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
// panel.js -----------------------------------------------
|
142
|
+
|
143
|
+
Searchdoc.Panel = function(element, data, tree, frame) {
|
144
|
+
this.$element = $(element);
|
145
|
+
this.$input = $('input', element).eq(0);
|
146
|
+
this.$result = $('.result ul', element).eq(0);
|
147
|
+
this.frame = frame;
|
148
|
+
this.$current = null;
|
149
|
+
this.$view = this.$result.parent();
|
150
|
+
this.data = data;
|
151
|
+
this.searcher = new Searcher(data.index);
|
152
|
+
|
153
|
+
this.tree = new Searchdoc.Tree($('.tree', element), tree, this);
|
154
|
+
this.init();
|
155
|
+
}
|
156
|
+
|
157
|
+
Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
|
158
|
+
var suid = 1;
|
159
|
+
|
160
|
+
this.init = function() {
|
161
|
+
var _this = this;
|
162
|
+
var observer = function() {
|
163
|
+
_this.search(_this.$input[0].value);
|
164
|
+
};
|
165
|
+
this.$input.keyup(observer);
|
166
|
+
this.$input.click(observer); // mac's clear field
|
167
|
+
|
168
|
+
this.searcher.ready(function(results, isLast) {
|
169
|
+
_this.addResults(results, isLast);
|
170
|
+
})
|
171
|
+
|
172
|
+
this.$result.click(function(e) {
|
173
|
+
_this.$current.removeClass('current');
|
174
|
+
_this.$current = $(e.target).closest('li').addClass('current');
|
175
|
+
_this.select();
|
176
|
+
_this.$input.focus();
|
177
|
+
});
|
178
|
+
|
179
|
+
this.initNavigation();
|
180
|
+
this.setNavigationActive(false);
|
181
|
+
}
|
182
|
+
|
183
|
+
this.search = function(value, selectFirstMatch) {
|
184
|
+
value = jQuery.trim(value).toLowerCase();
|
185
|
+
this.selectFirstMatch = selectFirstMatch;
|
186
|
+
if (value) {
|
187
|
+
this.$element.removeClass('panel_tree').addClass('panel_results');
|
188
|
+
this.tree.setNavigationActive(false);
|
189
|
+
this.setNavigationActive(true);
|
190
|
+
} else {
|
191
|
+
this.$element.addClass('panel_tree').removeClass('panel_results');
|
192
|
+
this.tree.setNavigationActive(true);
|
193
|
+
this.setNavigationActive(false);
|
194
|
+
}
|
195
|
+
if (value != this.lastQuery) {
|
196
|
+
this.lastQuery = value;
|
197
|
+
this.firstRun = true;
|
198
|
+
this.searcher.find(value);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
this.addResults = function(results, isLast) {
|
203
|
+
var target = this.$result.get(0);
|
204
|
+
if (this.firstRun && (results.length > 0 || isLast)) {
|
205
|
+
this.$current = null;
|
206
|
+
this.$result.empty();
|
207
|
+
}
|
208
|
+
for (var i=0, l = results.length; i < l; i++) {
|
209
|
+
target.appendChild(renderItem.call(this, results[i]));
|
210
|
+
};
|
211
|
+
if (this.firstRun && results.length > 0) {
|
212
|
+
this.firstRun = false;
|
213
|
+
this.$current = $(target.firstChild);
|
214
|
+
this.$current.addClass('current');
|
215
|
+
if (this.selectFirstMatch) this.select();
|
216
|
+
scrollIntoView(this.$current[0], this.$view[0])
|
217
|
+
}
|
218
|
+
if (jQuery.browser.msie) this.$element[0].className += '';
|
219
|
+
}
|
220
|
+
|
221
|
+
this.open = function(src) {
|
222
|
+
this.frame.location.href = '../' + src;
|
223
|
+
if (this.frame.highlight) this.frame.highlight(src);
|
224
|
+
}
|
225
|
+
|
226
|
+
this.select = function() {
|
227
|
+
this.open(this.$current.data('path'));
|
228
|
+
}
|
229
|
+
|
230
|
+
this.move = function(isDown) {
|
231
|
+
if (!this.$current) return;
|
232
|
+
var $next = this.$current[isDown ? 'next' : 'prev']();
|
233
|
+
if ($next.length) {
|
234
|
+
this.$current.removeClass('current');
|
235
|
+
$next.addClass('current');
|
236
|
+
scrollIntoView($next[0], this.$view[0]);
|
237
|
+
this.$current = $next;
|
238
|
+
}
|
239
|
+
return true;
|
240
|
+
}
|
241
|
+
|
242
|
+
function renderItem(result) {
|
243
|
+
var li = document.createElement('li'),
|
244
|
+
html = '', badge = result.badge;
|
245
|
+
html += '<h1>' + hlt(result.title);
|
246
|
+
if (result.params) html += '<i>' + result.params + '</i>';
|
247
|
+
html += '</h1>';
|
248
|
+
html += '<p>';
|
249
|
+
if (typeof badge != 'undefined') {
|
250
|
+
html += '<span class="badge badge_' + (badge % 6 + 1) + '">' + escapeHTML(this.data.badges[badge] || 'unknown') + '</span>';
|
251
|
+
}
|
252
|
+
html += hlt(result.namespace) + '</p>';
|
253
|
+
if (result.snippet) html += '<p class="snippet">' + escapeHTML(result.snippet.replace(/^<p>/, '')) + '</p>';
|
254
|
+
li.innerHTML = html;
|
255
|
+
jQuery.data(li, 'path', result.path);
|
256
|
+
return li;
|
257
|
+
}
|
258
|
+
|
259
|
+
function hlt(html) {
|
260
|
+
return escapeHTML(html).replace(/\u0001/g, '<b>').replace(/\u0002/g, '</b>')
|
261
|
+
}
|
262
|
+
|
263
|
+
function escapeHTML(html) {
|
264
|
+
return html.replace(/[&<>]/g, function(c) {
|
265
|
+
return '&#' + c.charCodeAt(0) + ';';
|
266
|
+
});
|
267
|
+
}
|
268
|
+
|
269
|
+
});
|
270
|
+
|
271
|
+
// tree.js ------------------------------------------------
|
272
|
+
|
273
|
+
Searchdoc.Tree = function(element, tree, panel) {
|
274
|
+
this.$element = $(element);
|
275
|
+
this.$list = $('ul', element);
|
276
|
+
this.tree = tree;
|
277
|
+
this.panel = panel;
|
278
|
+
this.init();
|
279
|
+
}
|
280
|
+
|
281
|
+
Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
|
282
|
+
this.init = function() {
|
283
|
+
var stopper = document.createElement('li');
|
284
|
+
stopper.className = 'stopper';
|
285
|
+
this.$list[0].appendChild(stopper);
|
286
|
+
for (var i=0, l = this.tree.length; i < l; i++) {
|
287
|
+
buildAndAppendItem.call(this, this.tree[i], 0, stopper);
|
288
|
+
};
|
289
|
+
var _this = this;
|
290
|
+
this.$list.click(function(e) {
|
291
|
+
var $target = $(e.target),
|
292
|
+
$li = $target.closest('li');
|
293
|
+
if ($target.hasClass('icon')) {
|
294
|
+
_this.toggle($li);
|
295
|
+
} else {
|
296
|
+
_this.select($li);
|
297
|
+
}
|
298
|
+
})
|
299
|
+
|
300
|
+
this.initNavigation();
|
301
|
+
if (jQuery.browser.msie) document.body.className += '';
|
302
|
+
}
|
303
|
+
|
304
|
+
this.select = function($li) {
|
305
|
+
this.highlight($li);
|
306
|
+
var path = $li[0].searchdoc_tree_data.path;
|
307
|
+
if (path) this.panel.open(path);
|
308
|
+
}
|
309
|
+
|
310
|
+
this.highlight = function($li) {
|
311
|
+
if (this.$current) this.$current.removeClass('current');
|
312
|
+
this.$current = $li.addClass('current');
|
313
|
+
}
|
314
|
+
|
315
|
+
this.toggle = function($li) {
|
316
|
+
var closed = !$li.hasClass('closed'),
|
317
|
+
children = $li[0].searchdoc_tree_data.children;
|
318
|
+
$li.toggleClass('closed');
|
319
|
+
for (var i=0, l = children.length; i < l; i++) {
|
320
|
+
toggleVis.call(this, $(children[i].li), !closed);
|
321
|
+
};
|
322
|
+
}
|
323
|
+
|
324
|
+
this.moveRight = function() {
|
325
|
+
if (!this.$current) {
|
326
|
+
this.highlight(this.$list.find('li:first'));
|
327
|
+
return;
|
328
|
+
}
|
329
|
+
if (this.$current.hasClass('closed')) {
|
330
|
+
this.toggle(this.$current);
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
this.moveLeft = function() {
|
335
|
+
if (!this.$current) {
|
336
|
+
this.highlight(this.$list.find('li:first'));
|
337
|
+
return;
|
338
|
+
}
|
339
|
+
if (!this.$current.hasClass('closed')) {
|
340
|
+
this.toggle(this.$current);
|
341
|
+
} else {
|
342
|
+
var level = this.$current[0].searchdoc_tree_data.level;
|
343
|
+
if (level == 0) return;
|
344
|
+
var $next = this.$current.prevAll('li.level_' + (level - 1) + ':visible:first');
|
345
|
+
this.$current.removeClass('current');
|
346
|
+
$next.addClass('current');
|
347
|
+
scrollIntoView($next[0], this.$element[0]);
|
348
|
+
this.$current = $next;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
this.move = function(isDown) {
|
353
|
+
if (!this.$current) {
|
354
|
+
this.highlight(this.$list.find('li:first'));
|
355
|
+
return true;
|
356
|
+
}
|
357
|
+
var next = this.$current[0];
|
358
|
+
if (isDown) {
|
359
|
+
do {
|
360
|
+
next = next.nextSibling;
|
361
|
+
if (next && next.style && next.style.display != 'none') break;
|
362
|
+
} while(next);
|
363
|
+
} else {
|
364
|
+
do {
|
365
|
+
next = next.previousSibling;
|
366
|
+
if (next && next.style && next.style.display != 'none') break;
|
367
|
+
} while(next);
|
368
|
+
}
|
369
|
+
if (next && next.className.indexOf('stopper') == -1) {
|
370
|
+
this.$current.removeClass('current');
|
371
|
+
$(next).addClass('current');
|
372
|
+
scrollIntoView(next, this.$element[0]);
|
373
|
+
this.$current = $(next);
|
374
|
+
}
|
375
|
+
return true;
|
376
|
+
}
|
377
|
+
|
378
|
+
function toggleVis($li, show) {
|
379
|
+
var closed = $li.hasClass('closed'),
|
380
|
+
children = $li[0].searchdoc_tree_data.children;
|
381
|
+
$li.css('display', show ? '' : 'none')
|
382
|
+
if (!show && this.$current && $li[0] == this.$current[0]) {
|
383
|
+
this.$current.removeClass('current');
|
384
|
+
this.$current = null;
|
385
|
+
}
|
386
|
+
for (var i=0, l = children.length; i < l; i++) {
|
387
|
+
toggleVis.call(this, $(children[i].li), show && !closed);
|
388
|
+
};
|
389
|
+
}
|
390
|
+
|
391
|
+
function buildAndAppendItem(item, level, before) {
|
392
|
+
var li = renderItem(item, level),
|
393
|
+
list = this.$list[0];
|
394
|
+
item.li = li;
|
395
|
+
list.insertBefore(li, before);
|
396
|
+
for (var i=0, l = item[3].length; i < l; i++) {
|
397
|
+
buildAndAppendItem.call(this, item[3][i], level + 1, before);
|
398
|
+
};
|
399
|
+
return li;
|
400
|
+
}
|
401
|
+
|
402
|
+
function renderItem(item, level) {
|
403
|
+
var li = document.createElement('li'),
|
404
|
+
cnt = document.createElement('div'),
|
405
|
+
h1 = document.createElement('h1'),
|
406
|
+
p = document.createElement('p'),
|
407
|
+
icon, i;
|
408
|
+
|
409
|
+
li.appendChild(cnt);
|
410
|
+
li.style.paddingLeft = getOffset(level);
|
411
|
+
cnt.className = 'content';
|
412
|
+
if (!item[1]) li.className = 'empty ';
|
413
|
+
cnt.appendChild(h1);
|
414
|
+
// cnt.appendChild(p);
|
415
|
+
h1.appendChild(document.createTextNode(item[0]));
|
416
|
+
// p.appendChild(document.createTextNode(item[4]));
|
417
|
+
if (item[2]) {
|
418
|
+
i = document.createElement('i');
|
419
|
+
i.appendChild(document.createTextNode(item[2]));
|
420
|
+
h1.appendChild(i);
|
421
|
+
}
|
422
|
+
if (item[3].length > 0) {
|
423
|
+
icon = document.createElement('div');
|
424
|
+
icon.className = 'icon';
|
425
|
+
cnt.appendChild(icon);
|
426
|
+
}
|
427
|
+
|
428
|
+
// user direct assignement instead of $()
|
429
|
+
// it's 8x faster
|
430
|
+
// $(li).data('path', item[1])
|
431
|
+
// .data('children', item[3])
|
432
|
+
// .data('level', level)
|
433
|
+
// .css('display', level == 0 ? '' : 'none')
|
434
|
+
// .addClass('level_' + level)
|
435
|
+
// .addClass('closed');
|
436
|
+
li.searchdoc_tree_data = {
|
437
|
+
path: item[1],
|
438
|
+
children: item[3],
|
439
|
+
level: level
|
440
|
+
}
|
441
|
+
li.style.display = level == 0 ? '' : 'none';
|
442
|
+
li.className += 'level_' + level + ' closed';
|
443
|
+
return li;
|
444
|
+
}
|
445
|
+
|
446
|
+
function getOffset(level) {
|
447
|
+
return 5 + 18*level + 'px';
|
448
|
+
}
|
449
|
+
});
|