reference previews master
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 3 Jan 2025 13:36:16 +0000 (14:36 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 3 Jan 2025 13:36:16 +0000 (14:36 +0100)
src/redakcja/static/css/html.scss
src/redakcja/static/js/wiki/view_editor_wysiwyg.js
src/wlxml/templates/wlxml/wl2html.xsl

index d9886d4..9148210 100644 (file)
@@ -300,12 +300,19 @@ div[x-node] > .uwaga {
  * Przypisy w tekście
  */
  
-.htmlview .annotation-inline-box {
-    &:hover > span[x-annotation-box] {
-        display: block;
+.htmlview .annotation-inline-box,
+.htmlview .reference-inline-box {
+    &:hover {
+       > span[x-annotation-box],
+       > span[x-preview]
+       {
+            display: block;
+       }
     }
 
-    > span[x-annotation-box] {
+    > span[x-annotation-box],
+    > span[x-preview]
+    {
         display: none;
         width: 300px;
         font-size: 10pt;
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);
index c3af0ff..fbb66fb 100644 (file)
           <xsl:with-param name="extra-class" select="'reference-inline-box'" />
         </xsl:call-template>
         <a class="reference">📌</a>
+        <span x-preview="true" x-pass-thru="true">
+         <a target="wiki" title="?">
+           <xsl:attribute name="href">
+             <xsl:value-of select="@href" />
+           </xsl:attribute>
+           <xsl:value-of select="@href" />
+         </a>
+        </span>
       </span>
     </xsl:template>