jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/339808 )
Change subject: Hygiene: move collapseTables.getTableHeader to applib ...................................................................... Hygiene: move collapseTables.getTableHeader to applib Bug: T158309 Change-Id: I86bdbc30e435316cee170f36ac5a69c8b126f547 --- M app/src/main/assets/bundle.js M www/js/transforms/collapseTables.js M www/package.json 3 files changed, 70 insertions(+), 77 deletions(-) Approvals: Dbrant: Looks good to me, approved jenkins-bot: Verified Mholloway: Looks good to me, but someone else must approve diff --git a/app/src/main/assets/bundle.js b/app/src/main/assets/bundle.js index b68585f..676fc1c 100644 --- a/app/src/main/assets/bundle.js +++ b/app/src/main/assets/bundle.js @@ -760,44 +760,8 @@ } } ); },{"../transformer":14,"../utilities":25}],17:[function(require,module,exports){ +var getTableHeader = require("applib").CollapseElement.getTableHeader; var transformer = require("../transformer"); - -/* -Tries to get an array of table header (TH) contents from a given table. -If there are no TH elements in the table, an empty array is returned. -*/ -function getTableHeader( element ) { - var thArray = []; - if (element.children === undefined || element.children === null) { - return thArray; - } - for (var i = 0; i < element.children.length; i++) { - var el = element.children[i]; - if (el.tagName === "TH") { - // ok, we have a TH element! - // However, if it contains more than two links, then ignore it, because - // it will probably appear weird when rendered as plain text. - var aNodes = el.querySelectorAll( "a" ); - if (aNodes.length < 3) { - // Also ignore it if it's identical to the page title. - if (el.innerText.length > 0 && el.innerText !== window.pageTitle && el.innerHTML !== window.pageTitle) { - thArray.push(el.innerText); - } - } - } - //if it's a table within a table, don't worry about it - if (el.tagName === "TABLE") { - continue; - } - //recurse into children of this element - var ret = getTableHeader(el); - //did we get a list of TH from this child? - if (ret.length > 0) { - thArray = thArray.concat(ret); - } - } - return thArray; -} function handleTableCollapseOrExpandClick() { var container = this.parentNode; @@ -839,7 +803,7 @@ } var isInfobox = tables[i].classList.contains( 'infobox' ); - var headerText = getTableHeader(tables[i]); + var headerText = getTableHeader(tables[i], window.pageTitle); if (headerText.length === 0 && !isInfobox) { continue; } @@ -899,7 +863,7 @@ module.exports = { handleTableCollapseOrExpandClick: handleTableCollapseOrExpandClick }; -},{"../transformer":14}],18:[function(require,module,exports){ +},{"../transformer":14,"applib":26}],18:[function(require,module,exports){ var transformer = require("../transformer"); var collapseTables = require("./collapseTables"); @@ -1330,4 +1294,66 @@ firstAncestorWithMultipleChildren: firstAncestorWithMultipleChildren }; +},{}],26:[function(require,module,exports){ +'use strict'; + +/** + Tries to get an array of table header (TH) contents from a given table. If + there are no TH elements in the table, an empty array is returned. + @param {!Element} element Table or blob of HTML containing a table? + @param {?string} pageTitle + @return {!Array<string>} +*/ +var getTableHeader = function getTableHeader(element, pageTitle) { + var thArray = []; + + if (element.children === undefined || element.children === null) { + return thArray; + } + + for (var i = 0; i < element.children.length; i++) { + var el = element.children[i]; + + if (el.tagName === 'TH') { + // ok, we have a TH element! + // However, if it contains more than two links, then ignore it, because + // it will probably appear weird when rendered as plain text. + var aNodes = el.querySelectorAll('a'); + if (aNodes.length < 3) { + // todo: remove nonstandard Element.innerText usage + // Also ignore it if it's identical to the page title. + if ((el.innerText && el.innerText.length || el.textContent.length) > 0 && el.innerText !== pageTitle && el.textContent !== pageTitle && el.innerHTML !== pageTitle) { + thArray.push(el.innerText || el.textContent); + } + } + } + + // if it's a table within a table, don't worry about it + if (el.tagName === 'TABLE') { + continue; + } + + // recurse into children of this element + var ret = getTableHeader(el, pageTitle); + + // did we get a list of TH from this child? + if (ret.length > 0) { + thArray = thArray.concat(ret); + } + } + + return thArray; +}; + +var CollapseElement = { + getTableHeader: getTableHeader +}; + +var index = { + CollapseElement: CollapseElement +}; + +module.exports = index; + + },{}]},{},[2,9,25,14,15,16,17,18,23,24,19,20,21,22,1,5,6,7,8,4,11,12,13]); diff --git a/www/js/transforms/collapseTables.js b/www/js/transforms/collapseTables.js index d9a4e05..a44825e 100644 --- a/www/js/transforms/collapseTables.js +++ b/www/js/transforms/collapseTables.js @@ -1,41 +1,5 @@ +var getTableHeader = require("applib").CollapseElement.getTableHeader; var transformer = require("../transformer"); - -/* -Tries to get an array of table header (TH) contents from a given table. -If there are no TH elements in the table, an empty array is returned. -*/ -function getTableHeader( element ) { - var thArray = []; - if (element.children === undefined || element.children === null) { - return thArray; - } - for (var i = 0; i < element.children.length; i++) { - var el = element.children[i]; - if (el.tagName === "TH") { - // ok, we have a TH element! - // However, if it contains more than two links, then ignore it, because - // it will probably appear weird when rendered as plain text. - var aNodes = el.querySelectorAll( "a" ); - if (aNodes.length < 3) { - // Also ignore it if it's identical to the page title. - if (el.innerText.length > 0 && el.innerText !== window.pageTitle && el.innerHTML !== window.pageTitle) { - thArray.push(el.innerText); - } - } - } - //if it's a table within a table, don't worry about it - if (el.tagName === "TABLE") { - continue; - } - //recurse into children of this element - var ret = getTableHeader(el); - //did we get a list of TH from this child? - if (ret.length > 0) { - thArray = thArray.concat(ret); - } - } - return thArray; -} function handleTableCollapseOrExpandClick() { var container = this.parentNode; @@ -77,7 +41,7 @@ } var isInfobox = tables[i].classList.contains( 'infobox' ); - var headerText = getTableHeader(tables[i]); + var headerText = getTableHeader(tables[i], window.pageTitle); if (headerText.length === 0 && !isInfobox) { continue; } diff --git a/www/package.json b/www/package.json index da756c1..294733b 100644 --- a/www/package.json +++ b/www/package.json @@ -3,6 +3,9 @@ "scripts": { "test": "grunt test" }, + "dependencies": { + "applib": "0.1.2" + }, "devDependencies": { "grunt": "0.4.5", "grunt-cli": "0.1.13", -- To view, visit https://gerrit.wikimedia.org/r/339808 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I86bdbc30e435316cee170f36ac5a69c8b126f547 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: Sniedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits