WordPress.org

Make WordPress Core

#23875 closed defect (bug) (fixed)

Twenty Thirteen: improve jQuery code: remove deprecated functions, namespace events, and more

Reported by: obenland Owned by:
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.6
Component: Bundled Theme Keywords: has-patch
Focuses: Cc:

Description (last modified by lancewillett)

  1. The syntax $(document).on("ready", handler) is deprecated as of jQuery 1.8.

It behaves similarly to the ready method but if the ready event has already fired and you try to .on("ready") the bound handler will not be executed. See: http://api.jquery.com/ready/

  1. We should namespace events: http://docs.jquery.com/Namespaced_Events
  1. The scroll event should be throttled for performance.

Attachments (5)

23875.diff (420 bytes) - added by obenland 13 months ago.
23875.1.diff (3.9 KB) - added by lancewillett 12 months ago.
23875.2.diff (1.8 KB) - added by obenland 12 months ago.
23875.3.diff (2.7 KB) - added by lancewillett 12 months ago.
23875.4.diff (1.8 KB) - added by lancewillett 12 months ago.

Download all attachments as: .zip

Change History (16)

obenland13 months ago

comment:1 lancewillett13 months ago

  • Priority changed from normal to low

I'm going to leave this 'til after beta, we can do some other general refactoring here.

comment:2 nacin13 months ago

In 23891:

Don't use jQuery.on('ready'). props obenland. see #23875.

comment:3 lancewillett12 months ago

  • Description modified (diff)
  • Keywords needs-refresh added
  • Priority changed from low to normal
  • Summary changed from Twenty Thirteen: Replace deprecated jQuery code to Twenty Thirteen: improve jQuery code: remove deprecated functions, namespace events, and more

comment:4 lancewillett12 months ago

  • Keywords needs-testing added; needs-refresh removed

.1 patch does the following:

  • Moves away from namespaced function names, just make them same scope as other variables
  • Add event namespacing
  • Add debounce function and use it to throttle scroll events
  • Code comment improvements

lancewillett12 months ago

comment:5 lancewillett12 months ago

In 24004:

Twenty Thirteen: improvements to functions.js to add namespacing to events and simplify repeatable functions. See #23875.

obenland12 months ago

lancewillett12 months ago

comment:6 lancewillett12 months ago

.3 builds on .2 from obenland to introduce a short delay so we don't trigger an avalanche of function calls with the scroll handler.

Thoughts on the UX? The navbar will hide and show with a tiny delay instead of being instant.

comment:7 lancewillett12 months ago

In 24005:

Twenty Thirteen: further performance for functions.js scroll event callback, props obenland. See #23875.

comment:8 lancewillett12 months ago

Further improvements to the scroll event now pending a decision: we discussed removing the fixed navbar completely today, in IRC #wordpress-dev, see log.

lancewillett12 months ago

comment:9 lancewillett12 months ago

@mfields brought to my attention a possible XSS vulnerability at https://wpcom-themes.trac.automattic.com/browser/twentythirteen/js/functions.js#L102

Where we don't check that the hash input is a valid element in the DOM.

See .4 diff for his suggested patch.

This approach is closer to the original code at http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ and also closes a possible XSS vulnerability in jQuery Migrate, see https://github.com/jquery/jquery-migrate/issues/36.

Last edited 12 months ago by lancewillett (previous) (diff)

comment:10 lancewillett12 months ago

In 24070:

Twenty Thirteen: update JavaScript-based accessibility function hooked to hashchange event to verify user input correctly. Props mfields for the original patch.

Also add textarea to list of elements. See #23875.

comment:11 lancewillett12 months ago

  • Keywords needs-testing removed
  • Resolution set to fixed
  • Status changed from new to closed

Closing now that #24184 negates the need to throttle the scroll event (which will be removed).

Note: See TracTickets for help on using tickets.