News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Shortcut keys for bold, italic, underline, etc. needed

Started by Rudy64, November 28, 2006, 10:39:58 AM

Previous topic - Next topic

Rudy64

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?

Rudy64

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.

// 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 ;).
else
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. 


vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

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

niko

You should add check if there is acesskey or it will fill up your error log.
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

Advertisement: