1
2jQuery(function(){
3
4    var snippetMap = {};
5    var loadingImg = '<img src="'+DOKU_BASE+'lib/images/throbber.gif" class="load" alt="loading..." />';
6    showSnippet(jQuery(".editions_editionlist a"));
7
8    function showSnippet($editionLink) {
9        $editionLink.removeAttr('title').hover(
10            function () {
11                var $this        = jQuery(this);
12                var target       = $this.attr("href");
13                var hashPos      = target.lastIndexOf('#');
14                var targetURL    = target.substring(0, hashPos);
15                var targetAnchor = target.substring(hashPos+1, target.length);
16                var edition      = $this.attr('class');
17
18                fillSnippet(targetURL, targetAnchor, edition);
19            },
20            function () {
21                var $this        = jQuery(this);
22                var target       = $this.attr("href");
23                var hashPos      = target.lastIndexOf('#');
24                var targetURL    = target.substring(0, hashPos);
25                var targetAnchor = target.substring(hashPos+1, target.length);
26
27                jQuery('#load__'+targetAnchor).empty().hide();
28            }
29        );
30    }
31
32    function fillSnippet(targetURL, targetAnchor, edition) {
33        var $snippet = jQuery('#load__'+targetAnchor).show().html(loadingImg);
34        var snippetMapKey = edition+'-'+targetAnchor;
35        var snippetMapValue = snippetMap[snippetMapKey];
36
37        if (snippetMapValue) {
38            $snippet.html(snippetMapValue);
39        } else {
40            $snippet.load(targetURL+' #'+targetAnchor, function(response, status, xhr) {
41                if (status == "success") {
42                    snippetMap[snippetMapKey] = jQuery(this).clone().html();
43                }
44            });
45        }
46    }
47
48});
49