reference previews
[redakcja.git] / src / redakcja / static / js / wiki / view_editor_wysiwyg.js
index 726c243..c5fa8c1 100644 (file)
             element: source,
             stripOuter: true,
             success: function(text){
-                $('textarea', $overlay).val($.trim(text));
+               let ttext = $.trim(text);
+                $('textarea', $overlay).val(ttext);
 
                 setTimeout(function(){
                     $('textarea', $overlay).elastic().focus();
                         $('*[x-annotation-box]', editable).css({
                         }).show();
                     }
+                    if (editable.is('.reference-inline-box')) {
+                       let preview = $('*[x-preview]', editable);
+                       preview.show();
+                       let link = $("a", preview);
+                       let href = link.attr('href');
+                       if (link.attr('title') == '?' && href.startsWith('https://www.wikidata.org/wiki/')) {
+                           link.attr('title', '…');
+                           let qid = href.split('/').reverse()[0];
+                           $.ajax({
+                               url: 'https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/' + qid + '?_fields=labels',
+                               dataType: "json",
+                               success: function(data) {
+                                   link.attr(
+                                       'title',
+                                       data['labels']['pl'] || data['labels']['en']
+                                   );
+                               },
+                           });
+                       }
+                    }
                 });
 
                 self.caret = new Caret(element);