www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 4a7aad03c4eb0872e0d27004457231677fa3a96c
parent 90677ae158be085f06f1dee8a7dd2f8b36c4851f
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue,  8 May 2018 20:19:53 -0400

Fix text() brokenness, and remove change warning fo attr()/text()

1) text() wasn't handling the index property.

2) This removes the warning that attr()/text() no longer no require a
document as the first argument, because there's no reason to prevent
translators from being able to pass an element. It would require
rewriting various translators unnecessarily and make certain patterns
more verbose (because you'd need to match based on global scope in each
selector).

It won't be necessary to pass a Document once we remove 4.0 support and
the global attr()/text() are always available, so we can add a warning
for that then.

Fixes zotero/translators#1647

Diffstat:
Mchrome/content/zotero/xpcom/translation/translate.js | 26++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js @@ -1885,14 +1885,17 @@ Zotero.Translate.Base.prototype = { */ _attr: function (selector, attr, index) { if (typeof arguments[0] == 'string') { - var doc = this.document; + var docOrElem = this.document; } - // Support legacy polyfill signature + // Document or element passed as first argument else { - this._debug("WARNING: attr() no longer requires a document as the first argument"); - [doc, selector, attr, index] = arguments; + // TODO: Warn if Document rather than Element is passed once we drop 4.0 translator + // support + [docOrElem, selector, attr, index] = arguments; } - var elem = index ? doc.querySelectorAll(selector).item(index) : doc.querySelector(selector); + var elem = index + ? docOrElem.querySelectorAll(selector).item(index) + : docOrElem.querySelector(selector); return elem ? elem.getAttribute(attr) : null; }, @@ -1901,14 +1904,17 @@ Zotero.Translate.Base.prototype = { */ _text: function (selector, index) { if (typeof arguments[0] == 'string') { - var doc = this.document; + var docOrElem = this.document; } - // Support legacy polyfill signature + // Document or element passed as first argument else { - this._debug("WARNING: text() no longer requires a document as the first argument"); - [doc, selector, attr, index] = arguments; + // TODO: Warn if Document rather than Element is passed once we drop 4.0 translator + // support + [docOrElem, selector, index] = arguments; } - var elem = index ? doc.querySelectorAll(selector).item(index) : doc.querySelector(selector); + var elem = index + ? docOrElem.querySelectorAll(selector).item(index) + : docOrElem.querySelector(selector); return elem ? elem.textContent : null; },