OJD: Add recent changes list
[eidogo-ojd.git] / index.phtml
blob6b9e15a21ab183644580130f911d0efe4ec659aa
1 <?php include("header.phtml"); ?>
3 <script type="text/javascript" src="js/rsh.compressed.js"></script>
5 <div id="player-container"></div>
7 <script type="text/javascript">
9 var player;
11 (function() {
12     
13     // Provide handlers for frontend things (page title, permalinks) that
14     // aren't handled by Player directly
15     var hooks = {
16         initGame: function() {
17             document.title = "EidoGo - " + this.getGameDescription();
18         },
19         setPermalink: function() {
20             if (!this.gameName || ['search', 'gnugo', 'url'].contains(this.gameName)) return;
21             var gn = this.gameName || "";
22             // use move-based path for KJD to future-proof permalinks
23             var path = (gn == "kjd" ?
24                 this.cursor.getPathMoves().join("") :
25                 this.cursor.getPath().join(","));
26             var hash = gn + (path ? ":" + path : "");
27             addHistory(hash);
28         },
29         searchRegion: function(params) {
30             this.hooks.initGame.call(this); // update title
31             var hash = "search:" + params.q + ":" + params.w + "x" + params.h +
32                 ":" + this.compressPattern(params.p);
33             if (params.a && params.a != "corner") hash += ":" + params.a;
34             if (hash != location.hash.replace(/^#/, "")) {
35                 addHistory(hash);
36             }
37         },
38         saved: function(gn) {
39             loadGame({gameName: gn, loadPath: [0,0]}, function() {
40                 var url = location.href.replace(/#[^#]+$/, "") + "#" + this.gameName;
41                 this.setPermalink();
42                 this.prependComment("Game saved to <a href='" + url + "'>" + url + "</a>");
43             }.bind(this));
44         }
45     };
46     
47     // Load game data; create a Player instance if necessary
48     function loadGame(params, completeFn) {
49         params = params || {};
50         var cfg = {
51             progressiveLoad:    false,
52             markCurrent:        true,
53             markVariations:     true,
54             markNext:           false,
55             showGameInfo:       true,
56             showPlayerInfo:     true,
57             showOptions:        true,
58             showTools:          true,
59             problemMode:        false
60         };
61         for (var key in params) {
62             cfg[key] = params[key];
63         }
64         if (!player) {
65             player = new eidogo.Player({
66                 container:          "player-container",
67                 sgfPath:            "sgf/",
68                 searchUrl:          "php/search.php",
69                 saveUrl:            "php/save.php",
70                 downloadUrl:        "php/download.php?id=",
71                 scoreEstUrl:        "php/gnugo.php",
72                 hooks:              hooks,
73                 enableShortcuts:    true
74             });
75         }
76         player.loadSgf(cfg, completeFn);
77     }
78     
79     var notLoaded = true;
80     
81     function loadState(hash) {
82         notLoaded = false;
83         var hashParts = hash ? hash.replace(/^#/, "").split(/:/) : [];
84         var gameName = hashParts[0] || "";
85         var loadPath = hashParts[1] ? hashParts[1].split(",") : null;
86         var rest = hashParts.slice(1);
87         if (!gameName || gameName == "kjd") {
88             if (loadPath) {
89                 var s = loadPath[0];
90                 var coord;
91                 loadPath = [];
92                 while (coord = s.substring(0, 2)) {
93                     loadPath.push(coord);
94                     s = s.substring(2);
95                 }
96             }
97             loadGame({
98                 gameName:           "ojd",
99                 sgfUrl:             "php/ojd_progressive.php",
100                 commitUrl:          "php/ojd_commit.php",
101                 loadPath:           loadPath,
102                 progressiveLoad:    true,
103                 markNext:           true,
104                 showPlayerInfo:     false,
105                 showOptions:        false
106             });
107             return;
108         }
109         if (gameName == "url") {
110             loadGame({
111                 gameName:   "url",
112                 sgfUrl:     "php/fetch.php?url=" + hash.replace(/^#?url:/, "")
113             });
114             return;
115         }
116         if (gameName == "search") {
117             if (loadPath) {
118                 loadGame({showOptions: false});
119                 player.loadSearch.apply(player, rest);
120             } else {
121                 loadGame({
122                     gameName:    "search",
123                     showOptions: false,
124                     loadPath:    [0,0]
125                 });
126             }
127             return;
128         }
129         if (gameName.indexOf("gnugo") === 0) {
130             var params = {
131                 gameName:       "",
132                 opponentUrl:    "php/gnugo.php",
133                 opponentColor:  "B"
134             };
135             var parts = gameName.split("-");
136             if (parts[1]) {
137                 params.boardSize = parts[1];
138             }
139             loadGame(params);
140             return;
141         }
142         loadGame({
143             gameName:   gameName,
144             loadPath:   loadPath
145         });
146     }
147     
148     function addHistory(hash) {
149         if (dhtmlHistory.isSafari) {
150             // Safari 2 sucks
151             location.hash = hash;
152         } else {
153             dhtmlHistory.add(hash);
154         }
155     }
156     
157     // appease RSH
158     window.dhtmlHistory.create({
159         toJSON: function(o) { return ''; },
160         fromJSON: function(s) { return {}; }
161     });
162     
164     // ajaxify our links
165     eidogo.util.addEvent(document, "click", function(evt) {
166         var target = eidogo.util.getTarget(evt)
167         if (target.nodeName.toUpperCase() != "A" || target.href.indexOf("#") == -1) return true;
168         var hash = target.href.replace(/^.*#/, "");
169         addHistory(hash);
170         player.closeSearch();
171         loadState(hash);
172         eidogo.util.stopEvent(evt);
173     });
174     
175     dhtmlHistory.initialize();
176     dhtmlHistory.addListener(loadState);
177     
178     if (notLoaded) {
179         // make sure we load our state on first page load (RSH quirk)
180         loadState(location.hash.replace(/^#/, ""));
181     }
182     
183 })();
185 </script>
187 <?php include("footer.phtml"); ?>