I just submitted a couple of patches that add $node->preview and $comment->preview flags to allow themes to style previews:

http://drupal.org/node/18792

Screen shots and discussion are here:

http://mg.to/2005/03/13/drupal-preview-confusion

and a working demo with an updated FriendsLight theme is here:

http://drupal.mg.to/2005/03/13/friendslight-theme-with-styled-preview

This is a real usability improvement for Drupal. More times than I want to admit, I've failed to save a post after previewing it, because the preview page looks so much like a normal page view. Applying a different visual style to the preview prevents this problem.

I know that 4.6.0 is close to release, but given the simplicity of the patch and its value in protecting people from losing their work, I'd like to respectfully suggest that it be considered for inclusion in 4.6.0. Thanks!

Comments

Geary’s picture

With apologies for the duplication, I also submitted the patches here:

http://drupal.org/node/18847

They didn't get into the patch queue when I entered them as comments to another issue, so I entered them as a separate issue.

Geary’s picture

Hey, bear with me, I'm new at this. :-) But after posting this I realized it was probably more relevant to the themes forum, and theme developers probably don't read this forum, so I posted a smaller version there. If a wizardly admin thinks I'm posting too much duplicate content, please feel free to trim it down, maybe by deleting this forum post. (I would have done it myself but it looks like that permission isn't turned on.)

chrismessina’s picture

Hi Geary,

Great to see movement on this! I've talked to drumm and other Drupal folks about this kind of thing for a while and there is consensus that it's needed. My Democratica theme actually was able to implement previews though it was something of a hack, so I very much appreciate you moving forward on this.

Could you talk to drumm about your patch though and make sure that you're not duplicating or recreating work that's already been done?

Thanks!

Chris

--
Drupal Grand Usability Poo-bah
User Experience Architect for CivicSpace Labs

Geary’s picture

Wow, I had forgotten that you had gotten preview highlighting working in Democratica, Chris. That may be a hack, but it is a mighty clever one. I couldn't figure out a way to do it without a core change.

See my other comment below for some comparisons between the 4.6 code and my patch. I'll give drumm a shout and we can compare notes--thanks for the tip!

-Mike

Steven’s picture

Drupal 4.6 RC already has a node preview class if I'm not mistaken. Perhaps you should take a closer look at how that is done, and implement comment previews similarly. It is certainly a valuable feature, which is why we already have it ;).

Also, please don't cross post patches and forum topics, it tends to fragment discussion and is very annoying later when you are looking something up.

--
If you have a problem, please search before posting a question.

Geary’s picture

Ah, do I feel stupid or what. I wasn't really thinking about 4.6 when I worked on this; I needed something right away for my 4.5.2 site, and somehow didn't look to see if there was anything new in the 4.6 code.

It is interesting to compare the two approaches. Both the 4.6 code and my patch add the same <div class="preview"> tag, but they do it in different ways and in different places.

The 4.6 code seems better conceptually: It takes some hard coded HTML out of node_preview() and makes it a themable function, theme_node_preview().

But the default implementation of theme_node_preview() doesn't look quite right. I took my updated FriendsLight and ran it using that code instead of mine, and here was the result when previewing a node with a teaser:

http://mg.to/images/drupal-node-preview-46rc.png

The dashed red border and pale highlight surround the entire preview block including both the trimmed and untrimmed versions. That seems fairly confusing to me.

This happens because the code puts the <div class="preview"> around everything:

function theme_node_preview($node) {
  $output = '<div class="preview">';
  if ($node->teaser && $node->teaser != $node->body) {
    $output .= '<h3>'. t('Preview trimmed version') .'</h3>';
    $output .= node_view($node, 1, FALSE, 0);
    $output .= '<p><em>'. t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication. You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.') .'</em></p>';
    $output .= '<h3>'. t('Preview full version') .'</h3>';
    $output .= node_view($node, 0, FALSE, 0);
  }
  else {
    $output .= node_view($node, 0, FALSE, 0);
  }
  $output .= "</div>\n";

  return $output;
}

We can improve this by using two separate preview divs that surround only the node_view calls:

function theme_node_preview($node) {
  $output = '';

  if ($node->teaser && $node->teaser != $node->body) {
    $output .= '<h3>'. t('Preview trimmed version') .'</h3>';
    $output .= '<div class="preview">' . node_view($node, 1, FALSE, 0) . "</div>\n";
    $output .= '<p><em>'. t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication. You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.') .'</em></p>';
    $output .= '<h3>'. t('Preview full version') .'</h3>';
  }

  $output .= '<div class="preview">' . node_view($node, 0, FALSE, 0) . "</div>\n";

  return $output;
}

With that change, the preview comes out much better:

http://mg.to/images/drupal-node-preview-46rc-a.png

But, my version looks even better than that (to my eyes):

http://mg.to/images/drupal-node-preview-mg.png

What I did different was this: Instead of putting the <div class="preview"> outside the <div class="node"> as the 4.6 code does, I put it inside the node div.

Of course, a theme could customize all of this further, but I'm exploring what makes it easy for a theme to get nice looking results here without extra work.

Perhaps you should take a closer look at how [the 4.6 node preview] is done, and implement comment previews similarly.

That sounds like a good idea, and I followed up on it and took a look at the comment code. But the comment code is quite different and I didn't see an obvious place to put in a theme hook like the node code has.

I'd like to investigate further, but I'm afraid I can't spare the time right now--must get back to the day job and my family. :-) And in any case, the $comment->preview flag does the job perfectly already, so I'm a happy camper.