<!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>[20007] trunk/wp-content/themes/twentytwelve: Twenty Twelve: add support for toggling the navigation menu in small screens.</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, #logmsg > ol { margin-left: 0; 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/20007">20007</a></dd>
<dt>Author</dt> <dd>lancewillett</dd>
<dt>Date</dt> <dd>2012-02-28 03:59:47 +0000 (Tue, 28 Feb 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Twenty Twelve: add support for toggling the navigation menu in small screens. See <a href="http://core.trac.wordpress.org/ticket/19978">#19978</a>.

Triggered when a viewport is under 600 pixels wide. This functionality depends on JS being enabled, and will naturally fall back to a normal, expanded menu for a client without JS.

Props iandstewart for the original JS file and concept.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpcontentthemestwentytwelvefunctionsphp">trunk/wp-content/themes/twentytwelve/functions.php</a></li>
<li><a href="#trunkwpcontentthemestwentytwelveheaderphp">trunk/wp-content/themes/twentytwelve/header.php</a></li>
<li><a href="#trunkwpcontentthemestwentytwelvestylecss">trunk/wp-content/themes/twentytwelve/style.css</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkwpcontentthemestwentytwelvejsnavigationjs">trunk/wp-content/themes/twentytwelve/js/navigation.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpcontentthemestwentytwelvefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentytwelve/functions.php (20006 => 20007)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentytwelve/functions.php        2012-02-28 03:48:34 UTC (rev 20006)
+++ trunk/wp-content/themes/twentytwelve/functions.php        2012-02-28 03:59:47 UTC (rev 20007)
</span><span class="lines">@@ -188,6 +188,17 @@
</span><span class="cx"> endif;
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Enqueue script for handling navigation.
+ *
+ * @since Twenty Twelve 1.0
+ */
+function twentytwelve_scripts() {
+        wp_enqueue_script( 'jquery' );
+        wp_enqueue_script( 'navigation', get_template_directory_uri() . '/js/navigation.js', 'jquery', '20120227', true );
+}
+add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts' );
+
+/**
</ins><span class="cx">  * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
</span><span class="cx">  *
</span><span class="cx">  * @since Twenty Twelve 1.0
</span></span></pre></div>
<a id="trunkwpcontentthemestwentytwelveheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentytwelve/header.php (20006 => 20007)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentytwelve/header.php        2012-02-28 03:48:34 UTC (rev 20006)
+++ trunk/wp-content/themes/twentytwelve/header.php        2012-02-28 03:59:47 UTC (rev 20007)
</span><span class="lines">@@ -40,10 +40,9 @@
</span><span class="cx">                         &lt;h2 class=&quot;site-description&quot;&gt;&lt;?php bloginfo( 'description' ); ?&gt;&lt;/h2&gt;
</span><span class="cx">                 &lt;/hgroup&gt;
</span><span class="cx"> 
</span><del>-                &lt;nav class=&quot;site-navigation&quot; role=&quot;navigation&quot;&gt;
-                        &lt;h3 class=&quot;assistive-text&quot;&gt;&lt;?php _e( 'Main menu', 'twentytwelve' ); ?&gt;&lt;/h3&gt;
-                        &lt;div class=&quot;skip-link&quot;&gt;&lt;a class=&quot;assistive-text&quot; href=&quot;#content&quot; title=&quot;&lt;?php esc_attr_e( 'Skip to primary content', 'twentytwelve' ); ?&gt;&quot;&gt;&lt;?php _e( 'Skip to primary content', 'twentytwelve' ); ?&gt;&lt;/a&gt;&lt;/div&gt;
-                        &lt;div class=&quot;skip-link&quot;&gt;&lt;a class=&quot;assistive-text&quot; href=&quot;#secondary&quot; title=&quot;&lt;?php esc_attr_e( 'Skip to secondary content', 'twentytwelve' ); ?&gt;&quot;&gt;&lt;?php _e( 'Skip to secondary content', 'twentytwelve' ); ?&gt;&lt;/a&gt;&lt;/div&gt;
</del><ins>+                &lt;nav class=&quot;site-navigation main-navigation&quot; role=&quot;navigation&quot;&gt;
+                        &lt;h3 class=&quot;assistive-text&quot;&gt;&lt;?php _e( 'Menu', 'twentytwelve' ); ?&gt;&lt;/h3&gt;
+                        &lt;div class=&quot;skip-link assistive-text&quot;&gt;&lt;a href=&quot;#content&quot; title=&quot;&lt;?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?&gt;&quot;&gt;&lt;?php _e( 'Skip to content', 'twentytwelve' ); ?&gt;&lt;/a&gt;&lt;/div&gt;
</ins><span class="cx">                         &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'primary' ) ); ?&gt;
</span><span class="cx">                 &lt;/nav&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpcontentthemestwentytwelvejsnavigationjs"></a>
<div class="addfile"><h4>Added: trunk/wp-content/themes/twentytwelve/js/navigation.js (0 => 20007)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentytwelve/js/navigation.js                                (rev 0)
+++ trunk/wp-content/themes/twentytwelve/js/navigation.js        2012-02-28 03:59:47 UTC (rev 20007)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+/**
+ * navigation.js
+ *
+ * Handles toggling the navigation menu for small screens.
+ */
+jQuery( document ).ready( function( $ ) {
+        var masthead = $( '#masthead' ),
+            timeout = false;
+
+        $.fn.smallMenu = function() {
+                $( masthead ).find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' );
+                $( masthead ).find( '.site-navigation h3' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' );
+
+                $( '.menu-toggle' ).click( function() {
+                        $( masthead ).find( '.menu' ).toggle();
+                        $( this ).toggleClass( 'toggled-on' );
+                } );
+        };
+
+        // Check viewport width on first load.
+        if ( $( window ).width() &lt; 600 )
+                $.fn.smallMenu();
+
+        // Check viewport width when user resizes the browser window.
+        $( window ).resize( function() {
+                var browserWidth = $( window ).width();
+
+                if ( false !== timeout )
+                        clearTimeout( timeout );
+
+                timeout = setTimeout( function() {
+                        if ( browserWidth &lt; 600 ) {
+                                $.fn.smallMenu();
+                        } else {
+                                $( masthead ).find( '.site-navigation' ).removeClass( 'main-small-navigation' ).addClass( 'main-navigation' );
+                                $( masthead ).find( '.site-navigation h3' ).removeClass( 'menu-toggle' ).addClass( 'assistive-text' );
+                                $( masthead ).find( '.menu' ).removeAttr( 'style' );
+                        }
+                }, 200 );
+        } );
+} );
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpcontentthemestwentytwelvestylecss"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentytwelve/style.css (20006 => 20007)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentytwelve/style.css        2012-02-28 03:48:34 UTC (rev 20006)
+++ trunk/wp-content/themes/twentytwelve/style.css        2012-02-28 03:59:47 UTC (rev 20007)
</span><span class="lines">@@ -340,6 +340,26 @@
</span><span class="cx">         width: 90px;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/* Small menu */
+nav[role=&quot;navigation&quot;].main-small-navigation {
+        text-align: left;
+}
+.menu-toggle {
+        cursor: pointer;
+        font-size: 12px;
+        font-size: 0.857142857rem;
+        line-height: 1.846153846;
+}
+.main-small-navigation .menu {
+        display: none;
+}
+@media screen and (max-width: 600px) {
+        nav[role=&quot;navigation&quot;] li a {
+                padding: 8px 0;
+                line-height: 1.090909091;
+        }
+}
+
</ins><span class="cx"> /*---------------------------------------------------------
</span><span class="cx"> Banner
</span><span class="cx"> ------------------------------------------------------------ */
</span></span></pre>
</div>
</div>

</body>
</html>