By azote on
hey guys ... I know that this is not the place to post this but the BBCode Formatting Bar project (http://drupal.org/node/24875) don't allow to post issues... so I wanted to share my enhancement to it..
I added a new extra button that adds tho [code] [/code] tags on the fly ... also they can be access with e short cut Ctrl+Shift+C
just copy the text below to a file (addcode.patch) and apply the patch in the modules/bbcode_wysiwyg folder with: patch -p0 < addcode.patch
here is the patch:
--- org/bbcode_wysiwyg.module 2007-02-24 14:29:04.000000000 -0600
+++ ./bbcode_wysiwyg.module 2007-02-24 15:19:46.000000000 -0600
@@ -81,6 +81,19 @@
'value' => t('Image'),
)) .'/>',
),
+ 'code' => array(
+ '#type' => 'markup',
+ '#value' => '<input '. drupal_attributes(array(
+ 'type' => 'button',
+ 'id' => 'bbcode',
+ 'class' => 'bbcode_wysiwyg',
+ 'onclick' => 'codeSelection();setClicked(this.id);',
+ 'value' => t('Code'),
+ 'alt' => 'Ctrl+Shift+C',
+ 'title' => 'Ctrl+Shift+C',
+ )) .'/>',
+ ),
+
);
if ($is_story) {
$form['break'] = array(
--- org/quick_reply.js 2007-02-24 14:31:37.000000000 -0600
+++ ./quick_reply.js 2007-02-24 15:10:11.000000000 -0600
@@ -53,6 +53,24 @@
return sel;
}
+function codeSelection() {
+ var textarea = getTextarea();
+ var theSelection = getTextareaSelection();
+ if (theSelection == '') {
+ if (bb_open[4]) {
+ bb_open[4] = false;
+ PostWrite('[/code]');
+ } else {
+ bb_open[4] = true;
+ PostWrite('[code]');
+ }
+ } else {
+ // Add tags around selection
+ PostWrite( '[code]' + theSelection + '[/code]');
+ }
+}
+
+
function quoteSelection() {
var textarea = getTextarea();
var theSelection = getTextareaSelection();
@@ -75,6 +93,7 @@
if (id == 'bbitalic') var bbcid=1;
if (id == 'bbquote') var bbcid=2;
if (id == 'bbcenter') var bbcid=3;
+ if (id == 'bbcode') var bbcid=4;
if (bb_open[bbcid])
document.getElementById(id).className = 'bbcode_wysiwyg_down';
else
@@ -253,6 +272,15 @@
break;
}
break;
+ case 67: // C
+ if (ctrl_pressed && shift_pressed) {
+ quoteSelection();
+ setClicked('code');
+ ctrl_pressed = false;
+ shift_pressed = false;
+ break;
+ }
+ break;
case 73: // I
if (ctrl_pressed && shift_pressed) {
BBC('i');