reference previews
[redakcja.git] / src / redakcja / static / js / wiki / view_editor_wysiwyg.js
index e43905c..c5fa8c1 100644 (file)
@@ -56,7 +56,7 @@
     }
 
     /* Convert HTML fragment to plaintext */
-    var ANNOT_FORBIDDEN = ['pt', 'pa', 'pr', 'pe', 'begin', 'end', 'motyw'];
+    var ANNOT_FORBIDDEN = ['pt', 'pa', 'pr', 'pe', 'ptrad', 'begin', 'end', 'motyw'];
 
     function html2plainText(fragment){
         var text = "";
             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);