1/*
2 * DokuWiki Bootstrap3 Template: Plugins Hacks!
3 *
4 * Home     http://dokuwiki.org/template:bootstrap3
5 * Author   Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
6 * License  GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 */
8
9// Semantic Plugin
10
11var $wikilinks = jQuery('article .wikilink1');
12
13if (typeof JSINFO.plugin === 'undefined') {
14    JSINFO.plugin = {};
15}
16
17if (typeof JSINFO.plugin.semantic === 'undefined') {
18    JSINFO.plugin.semantic = {};
19}
20
21if ($wikilinks.length
22    && JSINFO.plugin.semantic.exposeWebService
23    && JSINFO.bootstrap3.config.showSemanticPopup) {
24
25    $wikilinks.hover(function () {
26
27        $wikilinks.popover('destroy');
28
29        var $wikilink = jQuery(this),
30            page_id = $wikilink.attr('title');
31
32        // Disable popup for linked tabs/navs items (Bootstrap Wrapper Plugin)
33        if ($wikilink.parents('.bs-wrap-nav').length) {
34            return false;
35        }
36
37        if (!page_id) return false;
38        if (page_id == JSINFO.id) return false; // Self
39
40        jQuery.get(
41            DOKU_BASE + 'doku.php',
42            {
43                id: page_id,
44                do: 'export_xhtmlsummary'
45            },
46            function (data) {
47
48                var content = '<div class="popover-xhtmlsummary">'
49                    + '  <div class="popover-body">' + data + '</div>'
50                    + '  <div class="popover-footer text-right">'
51                    + '    <a class="btn btn-xs btn-primary" href="' + $wikilink.attr('href') + '">' + page_id + '</a>'
52                    + '  </div>'
53                    + '</div>';
54
55                $wikilink.popover({
56                    trigger: 'manual',
57                    html: true,
58                    title: page_id,
59                    content: content,
60                    placement: 'auto left',
61                }).popover('show');
62
63                $wikilink.attr('title', page_id);
64
65            }
66        );
67
68        // jQuery.post(
69        //   DOKU_BASE + 'lib/exe/ajax.php',
70        //   { call: 'plugin_semantic', id: page_id },
71        //   function(data) {
72
73        //     var jsonld = data[0];
74
75        //     if (! (jsonld.headline && jsonld.description)) return false;
76
77        //     $wikilink.data('original-title', page_id);
78        //     $wikilink.attr('title', '');
79
80        //     var title       = jsonld.headline;
81        //     var image       = ('image' in jsonld) ? [ '<img src="', jsonld.image.url, '" alt="" class="img-responsive" /><br/>' ].join('') : '';
82        //     var description = jQuery.trim(jsonld.description.replace(/\t\*$/, ''))
83        //                         .replace(/\*(.*)/g, '<span class="iconify mr-2" data-icon="mdi:circle"></span> $1')
84        //                         .replace(/\n/g, "<br/>\n")
85        //                         .replace(/\t/g, '&nbsp;');
86
87        //     var content = [ '<div class="row small"><div class="col-md-12">', image, description, ' ... </div></div>' ].join('');
88
89        //     $wikilink.popover({
90        //       trigger   : 'manual',
91        //       html      : true,
92        //       title     : title,
93        //       content   : content,
94        //       placement : 'auto left',
95        //     }).popover('show');
96
97        //     $wikilink.attr('title', page_id);
98
99        //   });
100
101    }, function () {
102
103        var self = this;
104
105        setTimeout(function () {
106            if (jQuery(self).next('.popover').length && !jQuery(self).next('.popover:hover').length) {
107                jQuery(self).popover('destroy');
108            }
109        }, 300);
110
111    });
112
113}
114