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/documents/xml_tools.py
src/redakcja/static/css/html.scss
src/redakcja/static/js/wiki/view_editor_wysiwyg.js
src/redakcja/static/js/wiki/wikiapi.js
src/wiki/templates/wiki/tabs/annotations_view.html
src/wlxml/templates/wlxml/wl2html.xsl

index ac145db..d7e3fcf 100644 (file)
@@ -107,7 +107,7 @@ def split_xml(text):
 
         # find the chapter's title
         name_elem = deepcopy(element)
 
         # find the chapter's title
         name_elem = deepcopy(element)
-        for tag in 'extra', 'motyw', 'pa', 'pe', 'pr', 'pt', 'uwaga':
+        for tag in 'extra', 'motyw', 'pa', 'pe', 'pr', 'pt', 'ptrad', 'uwaga':
             for a in name_elem.findall('.//' + tag):
                 a.text=''
                 del a[:]
             for a in name_elem.findall('.//' + tag):
                 a.text=''
                 del a[:]
index d9886d4..9148210 100644 (file)
@@ -300,12 +300,19 @@ div[x-node] > .uwaga {
  * Przypisy w tekście
  */
  
  * 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;
         display: none;
         width: 300px;
         font-size: 10pt;
index e43905c..c5fa8c1 100644 (file)
@@ -56,7 +56,7 @@
     }
 
     /* Convert HTML fragment to plaintext */
     }
 
     /* 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 = "";
 
     function html2plainText(fragment){
         var text = "";
             element: source,
             stripOuter: true,
             success: function(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();
 
                 setTimeout(function(){
                     $('textarea', $overlay).elastic().focus();
                         $('*[x-annotation-box]', editable).css({
                         }).show();
                     }
                         $('*[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);
                 });
 
                 self.caret = new Caret(element);
index 73642ac..5675913 100644 (file)
             $.xmlns["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
             $('rdf|RDF', doc).remove();
             if (params.noFootnotes) {
             $.xmlns["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
             $('rdf|RDF', doc).remove();
             if (params.noFootnotes) {
-                $('pa, pe, pr, pt', doc).remove();
+                $('pa, pe, pr, pt, ptrad', doc).remove();
             }
            if (params.noThemes) {
                $('motyw', doc).remove();
             }
            if (params.noThemes) {
                $('motyw', doc).remove();
index 6cfef19..1c6bcc0 100644 (file)
         <a href='#' class="nav-link refresh" title="Przypisy tłumacza" data-tag="pt">pt</a>
       </li>
       <li class="nav-item">
         <a href='#' class="nav-link refresh" title="Przypisy tłumacza" data-tag="pt">pt</a>
       </li>
       <li class="nav-item">
-        <a href='#' class="nav-link refresh" title="Wszystkie przypisy" data-tag="pa,pe,pr,pt">{% trans "all" %}</a>
+        <a href='#' class="nav-link refresh" title="Przypisy tradycyjne" data-tag="ptrad">ptrad</a>
+      </li>
+      <li class="nav-item">
+        <a href='#' class="nav-link refresh" title="Wszystkie przypisy" data-tag="pa,pe,pr,pt,ptrad">{% trans "all" %}</a>
       </li>
     </ul>
     <div id="annotations-container">
       </li>
     </ul>
     <div id="annotations-container">
index c3af0ff..fbb66fb 100644 (file)
           <xsl:with-param name="extra-class" select="'reference-inline-box'" />
         </xsl:call-template>
         <a class="reference">📌</a>
           <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>
     
       </span>
     </xsl:template>