BB-Code-Button for Code-Block (Features)
Hello
Yes, that's it.
Okay. At the moment, it is a Quick&Dirty-Version. I fight with smarty and lost :-/ So, I belive Alex must adjust the code (past it to a external file to keep it more clear etc.).
I would only suggest to set the cursor between the BB-code-tags instead to select the tags [1]. Maybe the script can get a routine to find a better place for the box
I keep the code very small. That means I'm using only the JavaScripts, which are still avaible in mlf2. I don't add a new one. The Box is using Alex's JavaScript show_box('codepicker',40,-100);
. I'm currently not sure, how I can calculate a better position (and set is to 40, -100). Maybe, Alex can help. The cursor position is also a part of the main.js and not one of me.
[2] By the way: In a beta version of mlf2 it gave two code-tags, one for code blocks, another for inline code.
See the answere from Alfie. It still works and I include both codes.
My changes:
[index.php]
Here, I add the directory read loop, thats not the best way but I found no outher :-/ I include it into the posting-case:
case 'posting': $langDir = "./modules/geshi/geshi"; $codeLangs = array(); if ($handle = @opendir($langDir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $codeLangs[] = strtoupper( substr($file, 0, strrpos ( $file, "." ) ) ); } } closedir($handle); sort($codeLangs); $smarty->assign("codeLangs",$codeLangs); } include('includes/posting.inc.php'); break;
I create a subtemplate called codepicker.tpl.inc
[codepicker.tpl.inc]
{config_load file=$settings.language_file section="general"}{config_load file=$settings.language_file section="insert_code"} <div id="codepicker"> <p><a href="#" onclick="bbcode('text','code',''); hide_element('codepicker'); return false">{#insert_code_no_lang#}</a></p> <p><a href="#" onclick="bbcode('text','inlinecode',''); hide_element('codepicker'); return false">{#insert_code_inline#}</a></p> {foreach name='lang' from=$codeLangs item=lang} <p><a href="#" onclick="bbcode('text','code','{$lang}'); hide_element('codepicker'); return false">{$lang}</a></p> {/foreach} </div>
at the posting.tpl.inc I add a button
<input class="bbcode-button" type="button" name="image" value="{#bbcode_code_marking#}" title="{#bbcode_code_title#}" onclick="show_box('codepicker',40,-100);" /><br />
and inclde the tpl at the end of this file
{include file="$template/subtemplates/codepicker.tpl.inc"}
Regards Micha
--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences