mediawiki.util: Optimise addPortletLink
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 18 Sep 2018 02:15:07 +0000 (03:15 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 18 Sep 2018 19:42:51 +0000 (19:42 +0000)
commitbe2774703aaedd0a7726bdfd1d4144fa2d90484d
tree79bdbdb12e9225796d5758a4465b6c7808858ebf
parent1a625b8ced8b27cf892dc4a2d58a1b7682382b17
mediawiki.util: Optimise addPortletLink

* Use prop() instead of attr().
  - Avoids extra overhead from attr() relating to XML/SVG compat.
  - Makes the code consistent with jquery.accessKeyLabel, which,
    reads the node.accessKey value as property already, and we now
    set it the same way.

* Use append() instead of wrap().parent().
  Most use of adding portlets is as links in the sidebar or
  as menu items for the page actions menu. For this, simply
  assign the <li> directly, and append the link. Instead of
  wrapping it in the DOM and then unwrapping the jQuery
  collection. This also saves a bunch of clone operations
  internally due to how jQuery objects keep a stack of
  mutations.

* Set 'textContent' directly instead of text().

* Use $('<li>') instead of $().wrap('<li></li>') which allows jQuery
  to take a fast path for element creation. Also consistent with
  MW code conventions which say to avoid <tag></tag>.

* Use node.querySelector(str) instead of $(node).find(str).eq(0).
  The latter does a lot more, including querySelectorAll(),
  and twice a clone/push/merge of the jQuery collection.

* Use createElement() for the anchor tag, given that none of the
  remaining code needed the jQuery object anymore. The return
  value was already the DOM Node directly as well.

Bug: T204625
Change-Id: I9070f63a4c75411c0eff7757bd2d8aed46c182e9
resources/src/mediawiki.util.js