changelog date typo
[eidogo.git] / index.phtml
blob2654390ae71093ea35ca5705665938e6ca99cea2
1 <?php include("header.phtml"); ?>
3 <script type="text/javascript" src="js/rsh.compressed.js"></script>
5 <div id="options"></div>
7 <div id="options-joseki" style="display: none">
8     <strong>Joseki Tutor:</strong>
9     <a href="/#kjd">Kogo's Joseki Dictionary</a> |
10     <a href="/#kombilo">Kombilo / Pro Game Database</a>
11 </div>
13 <div id="options-gnugo" style="display: none">
14     <strong>GNU Go</strong>
15     &nbsp;&nbsp;&nbsp;&nbsp; Board Size:
16     <a href="/#gnugo">19x19</a> |
17     <a href="/#gnugo-9">9x9</a> |
18     <a href="/#gnugo-13">13x13</a>
19     &nbsp;&nbsp; Your Color: <select id="human-color">
20         <option value="W">White</option>
21         <option value="B">Black</option>
22     </select>
23     &nbsp;&nbsp; Handicap: <select id="handicap">
24         <option value="0">None</option>
25         <option value="1">1 stone</option>
26         <option value="2">2 stones</option>
27         <option value="3">3 stones</option>
28         <option value="4">4 stones</option>
29         <option value="5">5 stones</option>
30         <option value="6">6 stones</option>
31         <option value="7">7 stones</option>
32         <option value="8">8 stones</option>
33         <option value="9">9 stones</option>
34     </select>
35 </div>
37 <div id="options-blank" style="display: none">
38     <strong>Blank Board:</strong>
39     <a href="/#blank">19x19</a> |
40     <a href="/#blank-9">9x9</a> |
41     <a href="/#blank-13">13x13</a>
42 </div>
44 <div id="player-container"></div>
46 <script type="text/javascript">
48 var player;
50 (function() {
51     
52     var byId = eidogo.util.byId,
53         hide = eidogo.util.hide,
54         show = eidogo.util.show,
55         addEvent = eidogo.util.addEvent;
56     
57     // Provide handlers for frontend things (page title, permalinks) that
58     // aren't handled by Player directly
59     var hooks = {
60         initGame: function() {
61             document.title = "EidoGo - " + this.getGameDescription();
62         },
63         showGameInfo: function(info) {
64             if (this.gameName == "kjd") {
65                 ['KM', 'HA', 'CP', 'DT'].forEach(function(p) { delete info[p]; });
66                 info.GC = "Available from " +
67                     "<a href='http://waterfire.us/joseki.htm'>http://waterfire.us/joseki.htm</a><br><br>" +
68                     "KJD Copyright 2006-2007 by Andre Ay. Copyright 1998-2005 " +
69                     "by Gary Odom. Portions copyright 2000-2001 by Stefan " +
70                     "Verstraeten. Used with permission.";
71             } else if (this.gameName == "kombilo") {
72                 info.GN = "Kombilo / Pro Game Database";
73                 info.GC = "Continuations derived from around 10,000 pro games.\n\n" +
74                     "Since the continuations are computed automatically, there is a certain " +
75                     "amount of spurious, non-fuseki moves included.";
76             }
77         },
78         setPermalink: function() {
79             if (!this.gameName || ['search', 'gnugo', 'url'].contains(this.gameName)) return;
80             var gn = this.gameName || "";
81             // Use move-based path for josekis to future-proof permalinks
82             var path = (gn == "kjd" || gn == "kombilo" ?
83                 this.cursor.getPathMoves().join("") :
84                 this.cursor.getPath().join(","));
85             var hash = gn + (path ? ":" + path : "");
86             addHistory(hash);
87         },
88         searchRegion: function(params) {
89             this.hooks.initGame.call(this); // update title
90             var hash = "search:" + params.q + ":" + params.w + "x" + params.h +
91                 ":" + this.compressPattern(params.p);
92             if (params.a && params.a != "corner") hash += ":" + params.a;
93             if (hash != location.hash.replace(/^#/, ""))
94                 addHistory(hash);
95         },
96         saved: function(gn) {
97             loadGame({gameName: gn, loadPath: [0,0]}, function() {
98                 var url = location.href.replace(/#[^#]+$/, "") + "#" + this.gameName;
99                 this.setPermalink();
100                 this.prependComment("Game saved to <a href='" + url + "'>" + url + "</a>");
101             }.bind(this));
102         }
103     };
104     
105     // Load game data; create a Player instance if necessary
106     function loadGame(params, completeFn) {
107         params = params || {};
108         var cfg = {
109             progressiveLoad:    false,
110             markCurrent:        true,
111             markVariations:     true,
112             markNext:           false,
113             showGameInfo:       true,
114             showPlayerInfo:     true,
115             showOptions:        true,
116             showTools:          true,
117             showNavTree:        false,
118             problemMode:        false
119         };
120         for (var key in params) {
121             cfg[key] = params[key];
122         }
123         if (!player) {
124             player = new eidogo.Player({
125                 container:          "player-container",
126                 sgfPath:            "sgf/",
127                 searchUrl:          "backend/search.php",
128                 saveUrl:            "backend/save.php",
129                 downloadUrl:        "backend/download.php?id=",
130                 scoreEstUrl:        "backend/gnugo.php",
131                 hooks:              hooks,
132                 enableShortcuts:    true
133             });
134         }
135         player.loadSgf(cfg, completeFn);
136     }
137     
138     var notLoaded = true;
139     
140     // Perform the appriate loading action depending on what hash is given
141     function loadState(hash) {
142         notLoaded = false;
143         var hashParts = hash ? hash.replace(/^#/, "").split(/:/) : [];
144         var gameName = hashParts[0] || "";
145         var loadPath = hashParts[1] ? hashParts[1].split(",") : null;
146         var rest = hashParts.slice(1);
147         
148         hide("options");
149         
150         if (!gameName || gameName == "kjd" || gameName == "kombilo")
151             loadJoseki(gameName, loadPath);
152         else if (gameName == "url")
153             loadUrl(hash.replace(/^#?url:/, ""));
154         else if (gameName == "search")
155             loadSearch(rest);
156         else if (gameName.indexOf("gnugo") === 0)
157             loadGnuGo(gameName);
158         else if (gameName.indexOf("blank") === 0)
159             loadBlank(gameName);
160         else
161             loadGame({gameName: gameName, loadPath: loadPath});
162     }
163     
164     function loadJoseki(gameName, loadPath) {
165         byId("options").innerHTML = byId("options-joseki").innerHTML;
166         show("options");
167         if (loadPath) {
168             // Parse moves out of string like "aepqnctt"
169             var s = loadPath[0];
170             var coord;
171             loadPath = [];
172             while (coord = s.substring(0, 2)) {
173                 loadPath.push(coord);
174                 s = s.substring(2);
175             }
176         }
177         loadGame({
178             gameName:           gameName || "kjd",
179             progressiveUrl:     gameName == "kombilo" ? "backend/search.php" : "backend/kjd_progressive.php",
180             loadPath:           loadPath,
181             progressiveLoad:    true,
182             progressiveMode:    gameName == "kombilo" ? "pattern" : "id",
183             markNext:           true,
184             showPlayerInfo:     false,
185             showOptions:        false});
186     }
187     
188     function loadSearch(args) {
189         if (args.length) {
190             loadGame({showOptions: false});
191             player.loadSearch.apply(player, args);
192         } else {
193             loadGame({
194                 gameName:    "search",
195                 showOptions: false,
196                 loadPath:    [0,0]});
197         }
198     }
199     
200     function loadUrl(url) {
201         loadGame({
202             gameName:   "url",
203             sgfUrl:     "backend/fetch.php?url=" + url});
204     }
205     
206     function loadGnuGo(gameName) {
207         byId("options").innerHTML = byId("options-gnugo").innerHTML;
208         show("options");
209         var params = {
210             gameName:       "",
211             opponentUrl:    "backend/gnugo.php",
212             opponentColor:  "B",
213             opponentLevel:  7,
214             handicap:       0
215         };
216         var parts = gameName.split("-");
217         if (parts[1])
218             params.boardSize = parts[1];
219         var inputColor = byId("human-color"),
220             inputHandi = byId("handicap");
221         var changeHandler = function() {
222             params.opponentColor = inputColor.value == "W" ? "B" : "W";
223             params.handicap = inputHandi.value;
224             loadGame(params);
225         }
226         addEvent(inputColor, "change", changeHandler);
227         addEvent(inputHandi, "change", changeHandler);
228         loadGame(params);
229     }
230     
231     function loadBlank(gameName) {
232         byId("options").innerHTML = byId("options-blank").innerHTML;
233         show("options");
234         loadGame({gameName: gameName});
235     }
236     
237     function addHistory(hash) {
238         // Safari 2 sucks
239         if (dhtmlHistory.isSafari)
240             location.hash = hash;
241         else
242             dhtmlHistory.add(hash);
243     }
244     
245     // Appease RSH
246     window.dhtmlHistory.create({
247         toJSON: function(o) { return ''; },
248         fromJSON: function(s) { return {}; }});
250     // Ajaxify our links
251     addEvent(document, "click", function(evt) {
252         var target = eidogo.util.getTarget(evt)
253         if (target.nodeName.toUpperCase() != "A" || target.href.indexOf("#") == -1) return true;
254         var hash = target.href.replace(/^.*#/, "");
255         addHistory(hash);
256         player.closeSearch();
257         loadState(hash);
258         eidogo.util.stopEvent(evt);
259     });
260     
261     dhtmlHistory.initialize();
262     dhtmlHistory.addListener(loadState);
263     
264     // Make sure we load our state on first page load (RSH quirk)
265     if (notLoaded)
266         loadState(location.hash.replace(/^#/, ""));
267     
268 })();
270 </script>
272 <?php include("footer.phtml"); ?>