From d14923890dd5e49fa8fa489feaff1c35a25af974 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 7 Mar 2011 15:12:51 +0100 Subject: [PATCH 1/1] char counter in summary, check rdf namespace on hiding rdf in html view --- apps/wiki/locale/pl/LC_MESSAGES/django.mo | Bin 5088 -> 5351 bytes apps/wiki/locale/pl/LC_MESSAGES/django.po | 62 ++- .../templates/wiki/tabs/summary_view.html | 4 + redakcja/settings/compress.py | 1 + redakcja/static/css/html.css | 2 +- redakcja/static/js/lib/jquery/jquery.xmlns.js | 411 ++++++++++++++++++ redakcja/static/js/wiki/view_summary.js | 16 + redakcja/static/js/wiki/wikiapi.js | 17 + 8 files changed, 494 insertions(+), 19 deletions(-) create mode 100644 redakcja/static/js/lib/jquery/jquery.xmlns.js diff --git a/apps/wiki/locale/pl/LC_MESSAGES/django.mo b/apps/wiki/locale/pl/LC_MESSAGES/django.mo index 1f5e5140300fe6d1738fdcfbb7d9fc5e450acd2d..8ec3fdf264e55e06530234cb49cdfca63c64f254 100644 GIT binary patch delta 2116 zcmZ9NZERCj7{|}L$#k0q>cE#N+!YbW=+v8-J7ejMxnM>d;OdS}8T~G-OKn2_lZ-e{c zUGOk$ho@l(*0Q<+t$=#26%xX9!7A9jFfSO>!=M#M9M;4Aa4DRE%KRwQPCtN3uw?!7 zP>G*|3UCo>;j2*h{bl`&Ys!He;BNe@AUT?Y@)O@oGf<}Q$^mDg0w0Ge^&HfKUqb~r z3vYtw?e|xqc3eRgN~j(xp)eP%*8<7KY_Rjqa3%8|SWtiw20hS+YvFOINky$L!#uM4qr5f>GukV|R>B{l zc6b~co zj-c?ez2P8K#_vD{JO*Eavrs$lAS*qv393@PPzeq|eLrNm2l6q`b5V&8L2@;3+WAq) zl4hptFPM`Il<6s`1kOV(co8b#6}SRclD-xU!|kvMs+4K#pN0(_>(sJ~ApK`T43t2lWem14-vafb$wBSlHK+yOhDz*+ozK|$M^J%2v;4yH8>oQu zPzjuY^s3o`I*D)YMIA^Du?;zBJ-QFwjbvJ2C(^IsQ6%d^YPOA)*OvRqc!oq$S!wZDx31X$ks&8?R46r zvH#pxJX`l-Mg5arVzgAuJ9&~DRdUIcJNa~QvY{`X%1$_GKVK>iI_b>Bcs^4qCS5O; nXenL_z85IIvUF#_$>uV?XU6>8c)olcH(tv1$<5CvJlFgU;#A|J delta 1851 zcmY+_S!_&E9LMp0r>$0XI#el!nz6Tx&ZttgmDb+c9%#h&B9^v1AkwIeJrZezvBZ){ zD>RW%$#}9vL}E#K;fbUTUU<-i;Kdf--#87uyI@8k%a#0ftqWUAqjBN%gK{aaNTGVxGTz>;9aU*WQeaO)E!S#Pd zP4uVQym*3N>I8>c)ep9Xaay&!Kjt6*ZA|=Uoib?m#`lAE*iCbFp?H zh#I%ZwI^h=|EY9Lr9&&8iJDLqD)B-*n!?I4K)aJ{8t515x(sHe33yRw!;iXeifdP( zc62Qc!>y>TKaOmIwdSz@)a{!4;tuMDXQ-|2L~`3lRDz#40{vVx3M+6XZp6OWhAi4{ zqwar%TJbB?gx{hT@E(itQ2r@0Lq!2a0WYn{-L@u$_NN%e~CEAU;?igx|&%5t0 zqb7V4mGC|uz(=SRFXE)@`W2Xm(e+d`ft{!e_Mm2d1htjtk$bJxwd2U2-E#d;Q4{P$ zCGJLz^9_|KoxuvwhZ=7@&c#w>2cy>HzPN+|zPO6onhw-feMhY%jb$rA7HXh;)Q%LO zCJ=H?#|gA+P`?{{Q42VY8m|pCu^Wjt&;OR|cz{au%=rS9=p}LnZ6eX1(8-=f=vu8r z&tJcsV+cKxWKnW{OcUoMgtLk1go<{gipV2>A_+OHhA1Sa5-M7)&Vb$w6}_U#GJ}fV z9PNP0d?G?jBjyk)Y~0^c>S{V;3tU}4%Tb+b6>Z6IVkA*XBuh1w5@IMZo>)w1yC)H& z2|cQ%M6!%^6}@i%mW4EQE{gu?oNTr{@y|uC)HotQ=ozU@Au0$xOFh3u#1dj2p#vKx zk|jum^Je8lSuB)M7i-UGj<3tC_r#xP`90Y?Hf?CwV2RJ|u}tquZ#Wc*gi6AJNNIUE o9IN;G|L=*P^zKiIjrE;~zx1_w;)io*dAtqVb~Ns?#Al=Z29vCsQ2+n{ diff --git a/apps/wiki/locale/pl/LC_MESSAGES/django.po b/apps/wiki/locale/pl/LC_MESSAGES/django.po index 0b102e90..0dbb13a5 100644 --- a/apps/wiki/locale/pl/LC_MESSAGES/django.po +++ b/apps/wiki/locale/pl/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: Platforma Redakcyjna\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-11-30 15:00+0100\n" -"PO-Revision-Date: 2010-11-30 15:00+0100\n" +"POT-Creation-Date: 2011-03-07 12:31+0100\n" +"PO-Revision-Date: 2011-03-07 12:31+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: Fundacja Nowoczesna Polska \n" "Language: \n" @@ -61,69 +61,78 @@ msgstr "Gotowe do publikacji" msgid "ZIP file" msgstr "Plik ZIP" -#: forms.py:82 +#: forms.py:80 +#: forms.py:118 msgid "Author" msgstr "Autor" -#: forms.py:83 +#: forms.py:81 +#: forms.py:119 msgid "Your name" msgstr "Imię i nazwisko" -#: forms.py:88 +#: forms.py:86 +#: forms.py:124 msgid "Author's email" msgstr "E-mail autora" -#: forms.py:89 +#: forms.py:87 +#: forms.py:125 msgid "Your email address, so we can show a gravatar :)" msgstr "Adres e-mail, żebyśmy mogli pokazać gravatar :)" -#: forms.py:95 +#: forms.py:93 +#: forms.py:131 msgid "Your comments" msgstr "Twój komentarz" -#: forms.py:96 +#: forms.py:94 msgid "Describe changes you made." msgstr "Opisz swoje zmiany" -#: forms.py:102 +#: forms.py:100 msgid "Completed" msgstr "Ukończono" -#: forms.py:103 +#: forms.py:101 msgid "If you completed a life cycle stage, select it." msgstr "Jeśli został ukończony etap prac, wskaż go." -#: models.py:94 +#: forms.py:132 +msgid "Describe the reason for reverting." +msgstr "Opisz powód przywrócenia." + +#: models.py:93 #, python-format msgid "Finished stage: %s" msgstr "Ukończony etap: %s" -#: models.py:153 +#: models.py:152 msgid "name" msgstr "nazwa" -#: models.py:157 +#: models.py:156 msgid "theme" msgstr "motyw" -#: models.py:158 +#: models.py:157 msgid "themes" msgstr "motywy" -#: views.py:167 +#: views.py:168 #, python-format msgid "Title already used for %s" msgstr "Nazwa taka sama jak dla pliku %s" -#: views.py:169 +#: views.py:170 msgid "Title already used in repository." msgstr "Plik o tej nazwie już istnieje w repozytorium." -#: views.py:175 +#: views.py:176 msgid "File should be UTF-8 encoded." msgstr "Plik powinien mieć kodowanie UTF-8." -#: views.py:358 +#: views.py:379 msgid "Tag added" msgstr "Dodano tag" @@ -220,6 +229,11 @@ msgstr "Pominięte pliki" msgid "Files skipped due to no .xml extension" msgstr "Pliki pominięte z powodu braku rozszerzenia .xml." +#: templates/wiki/revert_dialog.html:38 +msgid "Revert" +msgstr "Przywróć" + +#: templates/wiki/revert_dialog.html:39 #: templates/wiki/tag_dialog.html:16 msgid "Cancel" msgstr "Anuluj" @@ -322,6 +336,18 @@ msgid "Link to gallery" msgstr "Link do galerii" #: templates/wiki/tabs/summary_view.html:31 +msgid "Characters in document" +msgstr "Znaków w dokumencie" + +#: templates/wiki/tabs/summary_view.html:32 +msgid "pages" +msgstr "stron" + +#: templates/wiki/tabs/summary_view.html:32 +msgid "untagged" +msgstr "nieotagowane" + +#: templates/wiki/tabs/summary_view.html:35 msgid "Publish" msgstr "Opublikuj" diff --git a/apps/wiki/templates/wiki/tabs/summary_view.html b/apps/wiki/templates/wiki/tabs/summary_view.html index c33baecc..f0b57f6d 100644 --- a/apps/wiki/templates/wiki/tabs/summary_view.html +++ b/apps/wiki/templates/wiki/tabs/summary_view.html @@ -27,6 +27,10 @@ {{ document_meta.gallery}}

+

+ + ( {% trans "pages" %}, {% trans "untagged" %}) +

diff --git a/redakcja/settings/compress.py b/redakcja/settings/compress.py index 8bade8d0..6e733f5d 100644 --- a/redakcja/settings/compress.py +++ b/redakcja/settings/compress.py @@ -30,6 +30,7 @@ COMPRESS_JS = { 'js/lib/jquery/jquery.autocomplete.js', 'js/lib/jquery/jquery.blockui.js', 'js/lib/jquery/jquery.elastic.js', + 'js/lib/jquery/jquery.xmlns.js', 'js/button_scripts.js', 'js/slugify.js', diff --git a/redakcja/static/css/html.css b/redakcja/static/css/html.css index 3255d751..0d43611b 100644 --- a/redakcja/static/css/html.css +++ b/redakcja/static/css/html.css @@ -37,7 +37,7 @@ -webkit-border-radius: 4px; } */ -.htmlview *[x-node = 'RDF'] { +.htmlview *[x-node = 'RDF'][x-ns = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'] { display: none; } diff --git a/redakcja/static/js/lib/jquery/jquery.xmlns.js b/redakcja/static/js/lib/jquery/jquery.xmlns.js new file mode 100644 index 00000000..96c5a559 --- /dev/null +++ b/redakcja/static/js/lib/jquery/jquery.xmlns.js @@ -0,0 +1,411 @@ +// +// jquery.xmlns.js: xml-namespace selector support for jQuery +// +// This plugin modifies the jQuery tag and attribute selectors to +// support optional namespace specifiers as defined in CSS 3: +// +// $("elem") - matches 'elem' nodes in the default namespace +// $("|elem") - matches 'elem' nodes that don't have a namespace +// $("NS|elem") - matches 'elem' nodes in declared namespace 'NS' +// $("*|elem") - matches 'elem' nodes in any namespace +// $("NS|*") - matches any nodes in declared namespace 'NS' +// +// A similar synax is also supported for attribute selectors, but note +// that the default namespace does *not* apply to attributes - a missing +// or empty namespace selector selects only attributes with no namespace. +// +// In a slight break from the W3C standards, and with a nod to ease of +// implementation, the empty namespace URI is treated as equivalent to +// an unspecified namespace. Plenty of browsers seem to make the same +// assumption... +// +// Namespace declarations live in the $.xmlns object, which is a simple +// mapping from namespace ids to namespace URIs. The default namespace +// is determined by the value associated with the empty string. +// +// $.xmlns.D = "DAV:" +// $.xmlns.FOO = "http://www.foo.com/xmlns/foobar" +// $.xmlns[""] = "http://www.example.com/new/default/namespace/" +// +// Unfortunately this is a global setting - I can't find a way to do +// query-object-specific namespaces since the jQuery selector machinery +// is stateless. However, you can use the 'xmlns' function to push and +// pop namespace delcarations with ease: +// +// $().xmlns({D:"DAV:"}) // pushes the DAV: namespace +// $().xmlns("DAV:") // makes DAV: the default namespace +// $().xmlns(false) // pops the namespace we just pushed +// $().xmlns(false) // pops again, returning to defaults +// +// To execute this as a kind of "transaction", pass a function as the +// second argument. It will be executed in the context of the current +// jQuery object: +// +// $().xmlns("DAV:",function() { +// // The default namespace is DAV: within this function, +// // but it is reset to the previous value on exit. +// return this.find("response").each(...); +// }).find("div") +// +// If you pass a string as a function, it will be executed against the +// current jQuery object using find(); i.e. the following will find all +// "href" elements in the "DAV:" namespace: +// +// $().xmlns("DAV:","href") +// +// +// And finally, the legal stuff: +// +// Copyright (c) 2009, Ryan Kelly. +// TAG and ATTR functions derived from jQuery's selector.js. +// Dual licensed under the MIT and GPL licenses. +// http://docs.jquery.com/License +// + +(function($) { + +// Some common default namespaces, that are treated specially by browsers. +// +var default_xmlns = { + "xml": "http://www.w3.org/XML/1998/namespace", + "xmlns": "http://www.w3.org/2000/xmlns/", + "html": "http://www.w3.org/1999/xhtml/" +}; + + +// A reverse mapping for common namespace prefixes. +// +var default_xmlns_rev = {} +for(var k in default_xmlns) { + default_xmlns_rev[default_xmlns[k]] = k; +} + + +// $.xmlns is a mapping from namespace identifiers to namespace URIs. +// The default default-namespace is "*", and we provide some additional +// defaults that are specified in the XML Namespaces standard. +// +$.extend({xmlns: $.extend({},default_xmlns,{"":"*"})}); + + +// jQuery method to push/pop namespace declarations. +// +// If a single argument is specified: +// * if it's a mapping, push those namespaces onto the stack +// * if it's a string, push that as the default namespace +// * if it evaluates to false, pop the latest namespace +// +// If two arguments are specified, the second is executed "transactionally" +// using the namespace declarations found in the first. It can be either a +// a selector string (in which case it is passed to this.find()) or a function +// (in which case it is called in the context of the current jQuery object). +// The given namespace mapping is automatically pushed before executing and +// popped afterwards. +// +var xmlns_stack = []; +$.fn.extend({xmlns: function(nsmap,func) { + if(typeof nsmap == "string") { + nsmap = {"":nsmap}; + } + if(nsmap) { + xmlns_stack.push($.xmlns); + $.xmlns = $.extend({},$.xmlns,nsmap); + if(func !== undefined) { + if(typeof func == "string") { + return this.find(func).xmlns(undefined) + } else { + var self = this; + try { + self = func.call(this); + if(!self) { + self = this; + } + } finally { + self.xmlns(undefined); + } + return self + } + } else { + return this; + } + } else { + $.xmlns = (xmlns_stack ? xmlns_stack.pop() : {}); + return this; + } +}}); + + +// Convert a namespace prefix into a namespace URI, based +// on the delcarations made in $.xmlns. +// +var getNamespaceURI = function(id) { + // No namespace id, use the default. + if(!id) { + return $.xmlns[""]; + } + // Strip the pipe character from the specifier + id = id.substr(0,id.length-1); + // Certain special namespaces aren't mapped to a URI + if(id == "" || id == "*") { + return id; + } + var ns = $.xmlns[id]; + if(typeof(ns) == "undefined") { + throw "Syntax error, undefined namespace prefix '" + id + "'"; + } + return ns; +}; + + +// Update the regex used by $.expr to parse selector components for a +// particular type of selector (e.g. "TAG" or "ATTR"). +// +// This logic is taken straight from the jQuery/Sizzle sources. +// +var setExprMatchRegex = function(type,regex) { + $.expr.match[type] = new RegExp(regex.source + /(?![^\[]*\])(?![^\(]*\))/.source); + if($.expr.leftMatch) { + $.expr.leftMatch[type] = new RegExp(/(^(?:.|\r|\n)*?)/.source + $.expr.match[type].source.replace(/\\(\d+)/g, function(all, num){ + return "\\" + (num - 0 + 1); + })); + } +} + + + +// Modify the TAG match regexp to include optional namespace selector. +// This is basically (namespace|)?(tagname). +// +setExprMatchRegex("TAG",/^((?:((?:[\w\u00c0-\uFFFF\*_-]*\|)?)((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)))/); + + +// Perform some capability-testing. +// +var div = document.createElement("div"); + +// Sometimes getElementsByTagName("*") will return comment nodes, +// which we will have to remove from the results. +// +var gebtn_yields_comments = false; +div.appendChild(document.createComment("")); +if(div.getElementsByTagName("*").length > 0) { + gebtn_yields_comments = true; +} + +// Some browsers return node.localName in upper case, some in lower case. +// +var localname_is_uppercase = true; +if(div.localName && div.localName == "div") { + localname_is_uppercase = false; +} + +// Allow the testing div to be garbage-collected. +// +div = null; + + +// Modify the TAG find function to account for a namespace selector. +// +$.expr.find.TAG = function(match,context,isXML) { + var ns = getNamespaceURI(match[2]); + var ln = match[3]; + var res; + if(typeof context.getElementsByTagNameNS != "undefined") { + // Easy case - we have getElementsByTagNameNS + res = context.getElementsByTagNameNS(ns,ln); + } else if(typeof context.selectNodes != "undefined") { + // Use xpath if possible (not available on HTML DOM nodes in IE) + if(context.ownerDocument) { + context.ownerDocument.setProperty("SelectionLanguage","XPath"); + } else { + context.setProperty("SelectionLanguage","XPath"); + } + var predicate = ""; + if(ns != "*") { + if(ln != "*") { + predicate="namespace-uri()='"+ns+"' and local-name()='"+ln+"'"; + } else { + predicate="namespace-uri()='"+ns+"'"; + } + } else { + if(ln != "*") { + predicate="local-name()='"+ln+"'"; + } + } + if(predicate) { + res = context.selectNodes("descendant-or-self::*["+predicate+"]"); + } else { + res = context.selectNodes("descendant-or-self::*"); + } + } else { + // Otherwise, we need to simulate using getElementsByTagName + res = context.getElementsByTagName(ln); + if(gebtn_yields_comments && ln == "*") { + var tmp = []; + for(var i=0; res[i]; i++) { + if(res[i].nodeType == 1) { + tmp.push(res[i]); + } + } + res = tmp; + } + if(res && ns != "*") { + var tmp = []; + for(var i=0; res[i]; i++) { + if(res[i].namespaceURI == ns || res[i].tagUrn == ns) { + tmp.push(res[i]); + } + } + res = tmp; + } + } + return res; +}; + + +// Check whether a node is part of an XML document. +// Copied verbatim from jQuery sources, needed in TAG preFilter below. +// +var isXML = function(elem){ + return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" || + !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; +}; + + +// Modify the TAG preFilter function to work with modified match regexp. +// This normalises case of the tag name if we're in a HTML document. +// +$.expr.preFilter.TAG = function(match, curLoop, inplace, result, not, isXML) { + var ln = match[3]; + if(!isXML) { + if(localname_is_uppercase) { + ln = ln.toUpperCase(); + } else { + ln = ln.toLowerCase(); + } + } + return [match[0],getNamespaceURI(match[2]),ln]; +}; + + +// Modify the TAG filter function to account for a namespace selector. +// +$.expr.filter.TAG = function(elem,match) { + var ns = match[1]; + var ln = match[2]; + var e_ns = elem.namespaceURI ? elem.namespaceURI : elem.tagUrn; + var e_ln = elem.localName ? elem.localName : elem.tagName; + if(ns == "*" || e_ns == ns || (ns == "" && !e_ns)) { + return ((ln == "*" && elem.nodeType == 1) || e_ln == ln); + } + return false; +}; + + +// Modify the ATTR match regexp to extract a namespace selector. +// This is basically ([namespace|])(attrname)(op)(quote)(pattern)(quote) +// +setExprMatchRegex("ATTR",/\[\s*((?:((?:[\w\u00c0-\uFFFF\*_-]*\|)?)((?:[\w\u00c0-\uFFFF_-]|\\.)+)))\s*(?:(\S?=)\s*(['"]*)(.*?)\5|)\s*\]/); + + +// Modify the ATTR preFilter function to account for new regexp match groups, +// and normalise the namespace URI. +// +$.expr.preFilter.ATTR = function(match, curLoop, inplace, result, not, isXML) { + var name = match[3].replace(/\\/g, ""); + if(!isXML && $.expr.attrMap[name]) { + match[3] = $.expr.attrMap[name]; + } + if( match[4] == "~=" ) { + match[6] = " " + match[6] + " "; + } + if(!match[2] || match[2] == "|") { + match[2] = ""; + } else { + match[2] = getNamespaceURI(match[2]); + } + return match; +}; + + +// Modify the ATTR filter function to account for namespace selector. +// Unfortunately this means factoring out the attribute-checking code +// into a separate function, since it might be called multiple times. +// +var filter_attr = function(result,type,check) { + var value = result + ""; + return result == null ? + type === "!=" : + type === "=" ? + value === check : + type === "*=" ? + value.indexOf(check) >= 0 : + type === "~=" ? + (" " + value + " ").indexOf(check) >= 0 : + !check ? + value && result !== false : + type === "!=" ? + value != check : + type === "^=" ? + value.indexOf(check) === 0 : + type === "$=" ? + value.substr(value.length - check.length) === check : + type === "|=" ? + value === check || value.substr(0,check.length+1)===check+"-" : + false; +} + + +$.expr.filter.ATTR = function(elem, match) { + var ns = match[2]; + var name = match[3]; + var type = match[4]; + var check = match[6]; + var result; + // No namespace, just use ordinary attribute lookup. + if(ns == "") { + result = $.expr.attrHandle[name] ? + $.expr.attrHandle[name](elem) : + elem[name] != null ? + elem[name] : + elem.getAttribute(name); + return filter_attr(result,type,check); + } + // Directly use getAttributeNS if applicable and available + if(ns != "*" && typeof elem.getAttributeNS != "undefined") { + return filter_attr(elem.getAttributeNS(ns,name),type,check); + } + // Need to iterate over all attributes, either because we couldn't + // look it up or because we need to match all namespaces. + var attrs = elem.attributes; + for(var i=0; attrs[i]; i++) { + var ln = attrs[i].localName; + if(!ln) { + ln = attrs[i].nodeName + var idx = ln.indexOf(":"); + if(idx >= 0) { + ln = ln.substr(idx+1); + } + } + if(ln == name) { + result = attrs[i].nodeValue; + if(ns == "*" || attrs[i].namespaceURI == ns) { + if(filter_attr(result,type,check)) { + return true; + } + } + if(attrs[i].namespaceURI === "" && attrs[i].prefix) { + if(attrs[i].prefix == default_xmlns_rev[ns]) { + if(filter_attr(result,type,check)) { + return true; + } + } + } + } + } + return false; +}; + + +})(jQuery); + diff --git a/redakcja/static/js/wiki/view_summary.js b/redakcja/static/js/wiki/view_summary.js index 811096dd..b16c288f 100644 --- a/redakcja/static/js/wiki/view_summary.js +++ b/redakcja/static/js/wiki/view_summary.js @@ -29,12 +29,28 @@ SummaryPerspective.prototype = new $.wiki.Perspective(); + SummaryPerspective.prototype.showCharCount = function() { + var cc; + try { + cc = this.doc.getLength(); + $('#charcount_untagged').hide(); + } + catch (e) { + $('#charcount_untagged').show(); + cc = this.doc.text.replace(/\s{2,}/g, ' ').length; + } + $('#charcount').html(cc); + $('#charcount_pages').html((Math.round(cc/18)/100).toLocaleString()); + } + SummaryPerspective.prototype.freezeState = function(){ // must }; SummaryPerspective.prototype.onEnter = function(success, failure){ $.wiki.Perspective.prototype.onEnter.call(this); + + this.showCharCount(); console.log("Entered summery view"); }; diff --git a/redakcja/static/js/wiki/wikiapi.js b/redakcja/static/js/wiki/wikiapi.js index 8da5929a..4fe2707d 100644 --- a/redakcja/static/js/wiki/wikiapi.js +++ b/redakcja/static/js/wiki/wikiapi.js @@ -393,5 +393,22 @@ }); }; + WikiDocument.prototype.getLength = function(params) { + var xml = this.text.replace(/\/(\s+)/g, '
$1'); + var parser = new DOMParser(); + var doc = parser.parseFromString(xml, 'text/xml'); + var error = $('parsererror', doc); + + if (error.length > 0) { + 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(); + var text = $(doc).text(); + text = $.trim(text.replace(/\s{2,}/g, ' ')); + return text.length; + } + + $.wikiapi.WikiDocument = WikiDocument; })(jQuery); -- 2.20.1