Author Topic: Shortcut keys for bold, italic, underline, etc. needed  (Read 21072 times)

Offline Rudy64

  • Semi-Newbie
  • *
  • Posts: 16
Shortcut keys for bold, italic, underline, etc. needed
« on: November 28, 2006, 10:39:58 AM »
Sorry to cross-post, but this is one feature that is make or break with me.  I've stopped installing SMF as a replacement for others until I can figure this out.

Anyway, the other forum systems I use let you use something like ALT-B (or CTRL-B) to apply boldface in a message post window, and ALT-I (or CTRL-I) to use italics.  Other tags have keyboard shortcuts as well.  I noticed that wasn't a feature here in a default SMF installation.  (I've installed 1.1 RC3.)

Has anyone written a modification to enable this?  Tried a search here, but didn't come up with anything helpful. 

I did try it with an "accesskey=" declaration in the <a> tag (adding another element to the array as well), but it doesn't work, so I'm guessing it may have to work via JavaScript somehow.  (When I view source, the accesskey entries show up as I expected, but the keys do not work.)  I develop a lot in PHP, but not in JavaScript.  If I knew what I could use in the existing <a> tag to trigger the shortcut key behavior, I'd try it.  I was slightly surprised that "accesskey=" didn't work, but on the other hand, that's been my luck lately. 

Any ideas of what I could try to get this to work?

Offline Rudy64

  • Semi-Newbie
  • *
  • Posts: 16
Re: Shortcut keys for bold, italic, underline, etc. needed
« Reply #1 on: December 12, 2006, 12:07:05 AM »
Well, good news: I upgraded to SMF 1.1, and went back in and reapplied the same changes I made for the accesskey modification I had in mind.  And, it worked!  :D

My modifications are in the Post.template.php file.  Quite simple, really: in the $context['bbc_tags'][] array, I added a fifth element, called "accesskey", at the end of each code array.  Looks like this now, using the bold code as an example (and the red text my addition):

'bold' => array('code' => 'b', 'before' => '', 'after' => '', 'description' => $txt[253], 'accesskey' => 'b'),

For buttons where I didn't need shortcut keys, I simply left the array element empty ('accesskey' => ''), so it is easy to tweak or add shortcuts in the future.

A little further down, where we loop through the array to create the buttons, we make two changes where we "echo" out the anchor tags.

Code: [Select]
// If there's no after, we're just replacing the entire selection in the post box.
if (!isset($tag['after']))
echo '<a href="javascript:void(0);" onclick="replaceText(\'', $tag['before'], '\', document.forms.', $context['post_form'], '.', $context['post_box_name'], '); return false;" accesskey="'.$tag['accesskey'].'">';
// On the other hand, if there is one we are surrounding the selection ;).
echo '<a href="javascript:void(0);" onclick="surroundText(\'', $tag['before'], '\', \'', $tag['after'], '\', document.forms.', $context['post_form'], '.', $context['post_box_name'], '); return false;" accesskey="'.$tag['accesskey'].'">';

Above, I added the  accesskey="'.$tag['accesskey'].'" block of code right after the return false;" at the end of each anchor tag.

Did the edits, saved the file, and now ALT-B adds boldface!   8)  I'll poke around the forum a bit, and see if there's a formal procedure for submitting these modifications.  But for now, I just wanted to let everyone know I got it working. 

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,012
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Shortcut keys for bold, italic, underline, etc. needed
« Reply #2 on: December 12, 2006, 12:09:10 AM »
Good work. It would be a great mod to add!
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more! -  Paid Modifications for SMF

EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Offline niko

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,003
  • Gender: Male
    • Madjoki
Re: Shortcut keys for bold, italic, underline, etc. needed
« Reply #3 on: December 12, 2006, 04:05:02 AM »
You should add check if there is acesskey or it will fill up your error log.