#26543 closed enhancement (fixed)
Backbone Routing doesn't support query arguments as parseable route components. WordPress uses them extensively, so it'd be worthwhile to support them in wp-backbone.js for ease of use.
Reported by: | matveb | Owned by: | |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | General | Keywords: | has-patch needs-testing |
Focuses: | javascript | Cc: |
Description
We currently have a few pieces of wp-admin relying on Backbone. One issue is that we cannot use pushState navigation with GET params natively from Backbone's routing system, and WordPress uses them extensively.
The current approaches at solving this complicate the code unnecessarily, and mostly miss the chance of using events to handle location changes on the front end. (Basically, the routing system becomes blind to location changes.)
We should instead extend Backbone.History to support basic query type fragments as routes so we can natively use
route:events
instead of the way we are handling it now — parsing the URL with PHP and sending the values to localize_script and triggering stuff blindly.
Instead of hacking solutions every time we do a Backbone implementation, let's provide some helper code from
wp-backbone.js
.
Revisions and Themes would benefit greatly from it and the simplified code. Any subsequent Backbone implementation on the admin would also be able to easily register ?param=value
routes.
Concept: https://cloudup.com/c0ZdVFJ1Sky
Attachments (4)
Change History (20)
#4
@
11 years ago
26543-theme-js restores native routes like the following:
routes: { 'themes.php?theme=:slug': 'theme', 'themes.php?search=:query': 'search', 'themes.php?s=:query': 'search' }
#5
@
11 years ago
works well in my testing, nice work! like that we don't need to pass the vars from php any more.
#6
@
11 years ago
26543.diff combines patches & removes php passed vars
#11
@
11 years ago
Thanks for the patch, ehg.
From Backbone 1.1.1 release notes: Added an execute hook to the Router, which allows you to hook in and custom-parse route arguments, like query strings, for example. Hat-tip mattwiebe
This ticket was mentioned in IRC in #wordpress-dev by nacin. View the logs.
11 years ago
#13
@
11 years ago
If we upgrade Backbone to 1.1.2, the patching of Backbone.History
is no longer necessary. See #27182
For future reference, if patching is needed it would be better to extend Backbone.History
to create a new wp.Backbone.History
constructor. And, then in places where we need our version use Backbone.history = new wp.Backbone.History()
, which would negate the need for idioms like originalFragment: Backbone.History.prototype.getFragment
.
I also noticed that some of the navigate()
calls should probably not use replace: true
so that entries are added to the browser's history so that the back button still works. The changes to how routing is handled in THX probably should be a separate ticket.
#14
@
11 years ago
Thanks for the look. The original separate THX ticket that led to this one: #25963. If anyone feels like updating the latest patch to make use of the new Router hooks and avoid modifying Backbone.History to parse the queries, be my guest. Otherwise I'll try to get to it sometime next week. It's probably worth starting a new one.
(Also related: #26565.)
With 26543-wp-backbone.diff you can now start Backbone.history with an optional
queryUri
param that triggers the query var support:Backbone.history.start({ pushState: true, queryUri: true });
If you don't pass it you should get vanilla Backbone routing.