<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[26767] trunk: Make the Backbone routes pushSTate capable with ?theme=themename type urls instead of hashes.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/26767">26767</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2013-12-07 03:10:44 +0000 (Sat, 07 Dec 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Make the Backbone routes pushSTate capable with ?theme=themename type urls instead of hashes. Same applies to search queries.
Props adamsilverstein, nacin
fixes <a href="http://core.trac.wordpress.org/ticket/25963">#25963</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkGruntfilejs">trunk/Gruntfile.js</a></li>
<li><a href="#trunksrcwpadminjsthemejs">trunk/src/wp-admin/js/theme.js</a></li>
<li><a href="#trunksrcwpadminthemesphp">trunk/src/wp-admin/themes.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkGruntfilejs"></a>
<div class="modfile"><h4>Modified: trunk/Gruntfile.js (26766 => 26767)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Gruntfile.js 2013-12-07 02:02:55 UTC (rev 26766)
+++ trunk/Gruntfile.js 2013-12-07 03:10:44 UTC (rev 26767)
</span><span class="lines">@@ -36,7 +36,8 @@
</span><span class="cx"> src: [
</span><span class="cx"> '**',
</span><span class="cx"> '!**/.{svn,git}/**', // Ignore version control directories.
</span><del>- '!wp-includes/version.php' // Exclude version.php
</del><ins>+ '!wp-includes/version.php', // Exclude version.php
+ '!wp-content/themes/wpcom-themes/**'
</ins><span class="cx"> ],
</span><span class="cx"> dest: BUILD_DIR
</span><span class="cx"> },
</span></span></pre></div>
<a id="trunksrcwpadminjsthemejs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/js/theme.js (26766 => 26767)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/theme.js 2013-12-07 02:02:55 UTC (rev 26766)
+++ trunk/src/wp-admin/js/theme.js 2013-12-07 03:10:44 UTC (rev 26767)
</span><span class="lines">@@ -293,7 +293,7 @@
</span><span class="cx"> scroll = document.body.scrollTop;
</span><span class="cx">
</span><span class="cx"> // Clean the url structure
</span><del>- themes.router.navigate( '' );
</del><ins>+ themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } );
</ins><span class="cx">
</span><span class="cx"> // Restore scroll position
</span><span class="cx"> document.body.scrollTop = scroll;
</span><span class="lines">@@ -301,29 +301,9 @@
</span><span class="cx"> }
</span><span class="cx"> },
</span><span class="cx">
</span><del>- // Handles arrow keys navigation for the overlay
- // Triggers theme:next and theme:previous events
</del><ins>+ // Handles .disabled classes for next/previous buttons
</ins><span class="cx"> navigation: function() {
</span><del>- var self = this;
</del><span class="cx">
</span><del>- $( 'body' ).on( 'keyup', function( event ) {
-
- // Pressing the right arrow key fires a theme:next event
- if ( event.keyCode === 39 ) {
- self.trigger( 'theme:next', self.model.cid );
- }
-
- // Pressing the left arrow key fires a theme:previous event
- if ( event.keyCode === 37 ) {
- self.trigger( 'theme:previous', self.model.cid );
- }
-
- // Pressing the escape key closes the theme details panel
- if ( event.keyCode === 27 ) {
- self.collapse();
- }
- });
-
</del><span class="cx"> // Disable Left/Right when at the start or end of the collection
</span><span class="cx"> if ( this.model.cid === this.model.collection.at(0).cid ) {
</span><span class="cx"> this.$el.find( '.left' ).addClass( 'disabled' );
</span><span class="lines">@@ -377,6 +357,7 @@
</span><span class="cx"> themes.view.Themes = wp.Backbone.View.extend({
</span><span class="cx">
</span><span class="cx"> className: 'themes',
</span><ins>+ $overlay: $( 'div.theme-overlay' ),
</ins><span class="cx">
</span><span class="cx"> // Number to keep track of scroll position
</span><span class="cx"> // while in theme-overlay mode
</span><span class="lines">@@ -407,6 +388,24 @@
</span><span class="cx"> this.listenTo( this.parent, 'theme:scroll', function() {
</span><span class="cx"> self.renderThemes( self.parent.page );
</span><span class="cx"> });
</span><ins>+
+ // Bind keyboard events.
+ $('body').on( 'keyup', function( event ) {
+ // Pressing the right arrow key fires a theme:next event
+ if ( event.keyCode === 39 ) {
+ self.overlay.nextTheme();
+ }
+
+ // Pressing the left arrow key fires a theme:previous event
+ if ( event.keyCode === 37 ) {
+ self.overlay.previousTheme();
+ }
+
+ // Pressing the escape key fires a theme:collapse event
+ if ( event.keyCode === 27 ) {
+ self.overlay.collapse( event );
+ }
+ });
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> // Manages rendering of theme pages
</span><span class="lines">@@ -508,7 +507,7 @@
</span><span class="cx"> this.model = self.collection.get( id );
</span><span class="cx">
</span><span class="cx"> // Trigger a route update for the current model
</span><del>- themes.router.navigate( 'theme/' + this.model.id );
</del><ins>+ themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ), { replace: true } );
</ins><span class="cx">
</span><span class="cx"> // Sets this.view to 'detail'
</span><span class="cx"> this.setView( 'detail' );
</span><span class="lines">@@ -520,7 +519,7 @@
</span><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> this.overlay.render();
</span><del>- this.$el.append( this.overlay.el );
</del><ins>+ this.$overlay.html( this.overlay.el );
</ins><span class="cx">
</span><span class="cx"> // Bind to theme:next and theme:previous
</span><span class="cx"> // triggered by the arrow keys
</span><span class="lines">@@ -558,8 +557,8 @@
</span><span class="cx"> this.overlay.closeOverlay();
</span><span class="cx">
</span><span class="cx"> // Trigger a route update for the current model
</span><del>- // that renders the new theme's overlay
- themes.router.navigate( 'theme/' + nextModel.id, { trigger: true } );
</del><ins>+ self.theme.trigger( 'theme:expand', nextModel.cid );
+
</ins><span class="cx"> }
</span><span class="cx"> },
</span><span class="cx">
</span><span class="lines">@@ -582,8 +581,8 @@
</span><span class="cx"> this.overlay.closeOverlay();
</span><span class="cx">
</span><span class="cx"> // Trigger a route update for the current model
</span><del>- // that renders the new theme's overlay
- themes.router.navigate( 'theme/' + previousModel.id, { trigger: true } );
</del><ins>+ self.theme.trigger( 'theme:expand', previousModel.cid );
+
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> });
</span><span class="lines">@@ -617,9 +616,9 @@
</span><span class="cx">
</span><span class="cx"> // Update the URL hash
</span><span class="cx"> if ( event.target.value ) {
</span><del>- themes.router.navigate( 'search/' + event.target.value, { replace: true } );
</del><ins>+ themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true } );
</ins><span class="cx"> } else {
</span><del>- themes.router.navigate( '' );
</del><ins>+ themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> });
</span><span class="lines">@@ -628,20 +627,22 @@
</span><span class="cx"> // Listens to [theme] and [search] params
</span><span class="cx"> themes.routes = Backbone.Router.extend({
</span><span class="cx">
</span><del>- routes: {
- 'search/*query': 'search',
- 'theme/*slug': 'theme'
</del><ins>+ initialize: function() {
+ this.routes = _.object([
+ ]);
</ins><span class="cx"> },
</span><span class="cx">
</span><ins>+ baseUrl: function( url ) {
+ return themes.data.settings.root + url;
+ },
+
</ins><span class="cx"> // Set the search input value based on url
</span><span class="cx"> search: function( query ) {
</span><span class="cx"> $( '.theme-search' ).val( query );
</span><ins>+ self.themes.doSearch( query );
</ins><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><del>-// Make routes easily extendable
-_.extend( themes.routes, themes.data.settings.extraRoutes );
-
</del><span class="cx"> // Execute and setup the application
</span><span class="cx"> themes.Run = {
</span><span class="cx"> init: function() {
</span><span class="lines">@@ -660,12 +661,24 @@
</span><span class="cx"> render: function() {
</span><span class="cx"> // Render results
</span><span class="cx"> this.view.render();
</span><del>-
- // Calls the routes functionality
</del><span class="cx"> this.routes();
</span><span class="cx">
</span><del>- // Set ups history with pushState and our root
- Backbone.history.start({ root: themes.data.settings.root });
</del><ins>+ // Set the initial theme
+ if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){
+ this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) );
+ }
+
+ // Set the initial search
+ if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){
+ $( '.theme-search' ).val( themes.data.settings.search );
+ this.themes.doSearch( themes.data.settings.search );
+ }
+
+ // Start the router if browser supports History API
+ if ( window.history && window.history.pushState ) {
+ // Calls the routes functionality
+ Backbone.history.start({ pushState: true, silent: true });
+ }
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> routes: function() {
</span><span class="lines">@@ -673,16 +686,6 @@
</span><span class="cx"> // Bind to our global thx object
</span><span class="cx"> // so that the object is available to sub-views
</span><span class="cx"> themes.router = new themes.routes();
</span><del>-
- // Handles theme details route event
- themes.router.on( 'route:theme', function( slug ) {
- self.view.view.expand( slug );
- });
-
- // Handles search route event
- themes.router.on( 'route:search', function( query ) {
- self.themes.doSearch( query );
- });
</del><span class="cx"> }
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpadminthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/themes.php (26766 => 26767)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/themes.php 2013-12-07 02:02:55 UTC (rev 26766)
+++ trunk/src/wp-admin/themes.php 2013-12-07 03:10:44 UTC (rev 26767)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx"> } else {
</span><span class="cx"> $themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
</span><span class="cx"> }
</span><ins>+wp_reset_vars( array( 'theme', 'search' ) );
</ins><span class="cx">
</span><span class="cx"> wp_localize_script( 'theme', '_wpThemeSettings', array(
</span><span class="cx"> 'themes' => $themes,
</span><span class="lines">@@ -98,8 +99,10 @@
</span><span class="cx"> 'canInstall' => ( ! is_multisite() && current_user_can( 'install_themes' ) ),
</span><span class="cx"> 'installURI' => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
</span><span class="cx"> 'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
</span><del>- 'root' => admin_url( 'themes.php' ),
- 'extraRoutes' => '',
</del><ins>+ 'root' => parse_url( admin_url( 'themes.php' ), PHP_URL_PATH ),
+ 'theme' => esc_html( $theme ),
+ 'search' => esc_html( $search ),
+
</ins><span class="cx"> ),
</span><span class="cx"> 'l10n' => array(
</span><span class="cx"> 'addNew' => __( 'Add New Theme' ),
</span><span class="lines">@@ -227,6 +230,7 @@
</span><span class="cx"> <br class="clear" />
</span><span class="cx"> </div>
</span><span class="cx"> </div>
</span><ins>+<div class="theme-overlay"></div>
</ins><span class="cx">
</span><span class="cx"> <?php
</span><span class="cx"> // List broken themes, if any.
</span></span></pre>
</div>
</div>
</body>
</html>