<!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>[2253] 2013/ahoereth/trunk: No longer using JS for expanind and highlighting the correct menu item when viewing code revisions.</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://gsoc.trac.wordpress.org/changeset/2253">2253</a></dd>
<dt>Author</dt> <dd>a.hoereth</dd>
<dt>Date</dt> <dd>2013-09-03 19:19:31 +0000 (Tue, 03 Sep 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>No longer using JS for expanind and highlighting the correct menu item when viewing code revisions. See <a href="http://gsoc.trac.wordpress.org/ticket/316">#316</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#2013ahoerethtrunkincclasscoderevisionsphp">2013/ahoereth/trunk/inc/class-code-revisions.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#2013ahoerethtrunkjsviewerjs">2013/ahoereth/trunk/js/viewer.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="2013ahoerethtrunkincclasscoderevisionsphp"></a>
<div class="modfile"><h4>Modified: 2013/ahoereth/trunk/inc/class-code-revisions.php (2252 => 2253)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/ahoereth/trunk/inc/class-code-revisions.php 2013-08-30 07:01:00 UTC (rev 2252)
+++ 2013/ahoereth/trunk/inc/class-code-revisions.php 2013-09-03 19:19:31 UTC (rev 2253)
</span><span class="lines">@@ -15,6 +15,14 @@
</span><span class="cx"> private $metakey;
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * When viewing code revisions in the revision viewer on wp-admin/revision.php
+ * this contains the it's parent post id; otherwise 0.
+ *
+ * @var int
+ */
+ private $id = 0;
+
+ /**
</ins><span class="cx"> * Class constructor for adding actions to hook into core.
</span><span class="cx"> *
</span><span class="cx"> * @since 0.1
</span><span class="lines">@@ -24,40 +32,72 @@
</span><span class="cx"> add_action( 'load-post.php', array( $this, 'redirect' ) );
</span><span class="cx"> add_action( 'wp_restore_post_revision', array( $this, 'restore' ), 10, 2 );
</span><span class="cx"> add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
</span><ins>+ add_filter( 'parent_file', array( $this, 'parentage' ) );
</ins><span class="cx">
</span><span class="cx"> $this->metakey = '_' . str_replace( '-', '_', CODE_REVISIONS_NAME );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Filter $parent_file and change $submenu_file to expand and highlight the
+ * correct submenu when viewing code revisions in the revision viewer.
+ *
+ * @since 0.9
+ *
+ * @param string $parent_file File which acts as parent for the currently viewed screen
+ * for use in the admin menu system. E.g. edit.php
+ * @return string New $parent_file variable possibly adjusted for code revisions.
+ */
+ public function parentage( $parent_file ) {
+ global $submenu_file;
+
+ if ( $this->id = $this->viewing_code_revision() ) {
+ $meta = get_post_meta( $this->id, $this->metakey, true );
+ $submenu_file = $meta['type'] . '-editor.php';
+ $parent_file = $meta['type'] . 's.php';
+ }
+
+ return $parent_file;
+ }
+
+ /**
</ins><span class="cx"> * Enqueue scripts and styles.
</span><span class="cx"> *
</span><span class="cx"> * @since 0.4
</span><span class="cx"> */
</span><del>- public function scripts( $hook ) {
- //$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
- $suffix = '';
-
- // revisions viewer wp-admin/revisions.php
- if ( 'revision.php' != $hook )
</del><ins>+ public function scripts() {
+ if ( ! $this->id = $this->viewing_code_revision() )
</ins><span class="cx"> return;
</span><span class="cx">
</span><del>- $rev_id = ! empty( $_GET['revision'] ) ? $_GET['revision'] : $_GET['from'];
- $revision = get_post( $rev_id );
- $post = get_post( $revision->post_parent );
- if ( CODE_REVISIONS_POST_TYPE != $post->post_type )
- return;
-
- wp_register_style( 'code_revisions_viewer', CODE_REVISIONS_URL . "css/viewer.css", array(), CODE_REVISIONS_VER );
</del><ins>+ wp_register_style( 'code_revisions_viewer', CODE_REVISIONS_URL . "css/viewer.css", array(), CODE_REVISIONS_VER );
</ins><span class="cx"> wp_enqueue_style( 'code_revisions_viewer' );
</span><ins>+ }
</ins><span class="cx">
</span><del>- wp_register_script( 'code_revisions_viewer', CODE_REVISIONS_URL . "js/viewer$suffix.js", array( 'jquery' ), CODE_REVISIONS_VER, false );
- wp_enqueue_script( 'code_revisions_viewer' );
</del><ins>+ /**
+ * Used for checking if currently viewing a code revision on wp-admin/revision.php.
+ *
+ * @since 0.9
+ *
+ * @uses $this->id to avoid checking post parent and post type twice.
+ * @return int The parent post id of the currently viewed revision if it is a
+ * code revision; otherwise 0.
+ */
+ private function viewing_code_revision() {
+ global $pagenow;
</ins><span class="cx">
</span><del>- $meta = get_post_meta( $post->ID, $this->metakey, true );
- wp_localize_script( 'code_revisions_viewer', '_code_revisions_viewer', array(
- 'kind' => $meta['type'],
- 'page' => 'theme' == $meta['type'] ? 'appearance' : 'plugins',
- ));
</del><ins>+ // only check once
+ if ( $this->id )
+ return $this->id;
+
+ if ( 'revision.php' == $pagenow ) {
+ $revision_id = ! empty( $_GET['revision'] ) ? $_GET['revision'] : $_GET['from'];
+ $revision = get_post( $revision_id );
+ $post = get_post( $revision->post_parent );
+
+ if ( CODE_REVISIONS_POST_TYPE == $post->post_type )
+ return $post->ID;
+ }
+
+ return 0;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre></div>
<a id="2013ahoerethtrunkjsviewerjs"></a>
<div class="delfile"><h4>Deleted: 2013/ahoereth/trunk/js/viewer.js (2252 => 2253)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/ahoereth/trunk/js/viewer.js 2013-08-30 07:01:00 UTC (rev 2252)
+++ 2013/ahoereth/trunk/js/viewer.js 2013-09-03 19:19:31 UTC (rev 2253)
</span><span class="lines">@@ -1,14 +0,0 @@
</span><del>-/*
- * File is only included on wp-admin/revision.php when viewing code revisions.
- * Used for opening the correct sub menu in the left admin navigation:
- * Appearance/Editor or Plugins/Editor
- *
- * @since 0.7
- */
-jQuery(document).ready(function($){
- data = _code_revisions_viewer;
-
- $('#menu-' + data.page + ', #menu-' + data.page + ' a:first')
- .addClass('wp-has-current-submenu wp-menu-open').removeClass('wp-not-current-submenu')
- .find('a[href="' + data.kind + '-editor.php"]').parent('li').addClass('current');
-});
</del><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>