Fixes #3866: Text counter with footnotes.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 6 Mar 2019 14:40:00 +0000 (15:40 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 6 Mar 2019 14:40:00 +0000 (15:40 +0100)
src/redakcja/static/js/wiki/view_summary.js
src/redakcja/static/js/wiki/wikiapi.js
src/wiki/templates/wiki/tabs/summary_view.html

index 099a0e8..1bc3fb5 100644 (file)
     SummaryPerspective.prototype.showCharCount = function() {
         var cc;
         try {
+            $('#charcounts_text').show();
+            $('#charcounts_raw').hide();
+            cc = this.doc.getLength({noFootnotes: true, noThemes: true});
+            $('#charcount').html(cc);
+            $('#charcount_pages').html((Math.round(cc/18)/100).toLocaleString());
+
             cc = this.doc.getLength();
-            $('#charcount_untagged').hide();
+            $('#charcount_full').html(cc);
+            $('#charcount_full_pages').html((Math.round(cc/18)/100).toLocaleString());
         }
         catch (e) {
-            $('#charcount_untagged').show();
+            $('#charcounts_text').hide();
+            $('#charcounts_raw').show();
             cc = this.doc.text.replace(/\s{2,}/g, ' ').length;
+            $('#charcount_raw').html(cc);
+            $('#charcount_raw_pages').html((Math.round(cc/18)/100).toLocaleString());
         }
-        $('#charcount').html(cc);
-        $('#charcount_pages').html((Math.round(cc/18)/100).toLocaleString());
     }
 
     SummaryPerspective.prototype.freezeState = function(){
index 8df3ef5..f4073ff 100644 (file)
 
 
     WikiDocument.prototype.getLength = function(params) {
+        params = $.extend({}, noops, params);
         var xml = this.text.replace(/\/(\s+)/g, '<br />$1');
         var parser = new DOMParser();
         var doc = parser.parseFromString(xml, 'text/xml');
             throw "Not an XML document.";
         }
         $.xmlns["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 
-        $('rdf|RDF, motyw, pa, pe, pr, pt', doc).remove();
+        $('rdf|RDF', doc).remove();
+        if (params.noFootnotes) {
+            $('pa, pe, pr, pt', doc).remove();
+        }
+       if (params.noThemes) {
+           $('motyw', doc).remove();
+        }
         var text = $(doc).text();
         text = $.trim(text.replace(/\s{2,}/g, ' '));
         return text.length;
index 49ad5fe..341a5ef 100644 (file)
                </p>
                <p>
                    <label>{% trans "Characters in document" %}:</label>
-                   <span id="charcount"></span> (<span id="charcount_pages"></span> {% trans "pages" %}<span id="charcount_untagged">, {% trans "untagged" %}</span>)
+                   <span id="charcounts_text">
+                           <br><span id="charcount"></span> (<span id="charcount_pages"></span> {% trans "pages" %}, {% trans "without footnotes and themes" %})
+                           <br><span id="charcount_full"></span> (<span id="charcount_full_pages"></span> {% trans "pages" %}, {% trans "with footnotes and themes" %})
+                   </span>
+                   <span id="charcounts_raw">
+                           <br><span id="charcount_raw"></span> (<span id="charcount_raw_pages"></span> {% trans "pages" %}, {% trans "untagged" %})
+                   </span>
                </p>
        </div>
 </div>