BBCode extension is a part of standard BlogEngine distribution and since 1.3 it has admin interface that you can use to add or delete codes. That is cool, what is not cool is that updated codes will not show in the comment form; the values used there are hard coded. Makes no sense, so I decided to fix this little inconvenience. This is not hard, only ~/user controls/CommentView.ascx and corresponding code behind file need to be changed. First, open for edit code behind (~/user control/CommentView.cs) and add using directive and simple function that will pull data from settings object and format them for display:

using System.Data;
 
protected string BBCodes()
{
    string retVal = string.Empty;
    string title = string.Empty;
    string code = string.Empty;
 
    ExtensionSettings settings = ExtensionManager.GetSettings("BBCode");
    DataTable table = settings.GetDataTable();
 
    foreach (DataRow row in table.Rows)
    {
        code = (string)row["Code"];
        title = "[" + code + "][/" + code + "]";
        retVal += "<a title=\"" + title + "\" href=\"\" onclick=\"AddBbCode('" + code + "'); return false;\">" + code + "</a>";
    }
 
    return retVal;
}

Now, make a change to control to use this function instead of hard coded values:

<span class="bbcode" title="BBCode tags"><%=BBCodes() %></span>

Then, add javascript function your are going to use to insert codes into text box:

function AddBbCode(v) {
  if (document.getSelection) // firefox
  {      
    tt = $("<%=txtContent.ClientID %>");
    var pretxt = tt.value.substring(0, tt.selectionStart);
    var therest = tt.value.substr(tt.selectionEnd);
    var sel = tt.value.substring(tt.selectionStart, tt.selectionEnd);
    tt.value = pretxt + "[" + v + "]" + sel + "[/" + v + "]" + therest;
  }
  else // IE
  {
    var str = document.selection.createRange().text;
    $("<%=txtContent.ClientID %>").focus();
    var sel = document.selection.createRange();
    sel.text = "[" + v + "]" + str + "[/" + v + "]";
  }
 
  ShowCommentPreview('livepreview', $("<%=txtContent.ClientID %>"));
  return;
}

You might want to add style to make it look nice. For example, for standard theme add to the style.css:

.commentForm .bbcode {
    font-size:10px;
    float:right;
    position:relative;
    padding: 3px;
}
.bbcode a {
    margin: 1px;
    padding: 1px 3px 1px 3px;
    background: #fff;
    border: 1px solid #ccc;
}

All set. From now on, if anybody making comments on you blog, they can simply select portion of the text and click any of the BBCode links to insert code in the text area. Better yet, if you add new code by going to extensions/bbcode/edit and entering new codes there, they all will be available in the comment form right away.

You are going to need BlogEngine 1.3 for this code to work. I will make changes to the code base on CodePlex later this week (and update my blog too :), but you can simply copy and paste code from this post into your CommentView template and style.css and it should work.

Share/Save/Bookmark
Signature

Comments

1/30/2008 10:51:29 PM #

Dan

Nicely done!

Dan |

1/30/2008 11:01:57 PM #

Dan

I thought that I had seen something like this over at Cristiano's site...

http://www.cristianofino.net/post/BBCode-Toolbar-extension-per-BlogEngineNET-13.aspx


Great minds think alike.

Dan |

1/31/2008 12:09:40 AM #

rtur

I thought that I had seen something like this over at Cristiano's site...
www.cristianofino.net/.../...BlogEngineNET-13.aspx


Thanks for sharing this link, great site. I could've definitely use his javascript, it took me a wile to get mine working.

rtur |

1/31/2008 3:56:11 AM #

Cristiano

Hi,
Thanks to both for compliment Smile
A question: i have posted many times this extension from Dotnetblogengine.Net contact's form (and also http://www.cristianofino.net/post/Comment-Toolbar-extension-per-BlogEngineNET-13.aspx ), but they have not been published in the extensions's page. Why ?

I love your site's theme

Cristiano |

1/31/2008 9:39:31 AM #

rtur.net

i have posted many times this extension from Dotnetblogengine.Net contact's form (and also www.cristianofino.net/.../...BlogEngineNET-13.aspx ), but they have not been published in the extensions's page. Why ?

Cristiano, did you contact Mads or Al directly? After BE 1.4 release, we will have community website were you'll be able to publish extensions yourself, until then you'll need send email to Mads and he will add extension to the list on extensions page. It's too bad this wasn't published, could save me some time Smile

rtur.net |

1/31/2008 10:08:48 AM #

Cristiano

Cristiano, did you contact Mads or Al directly?
Sure, i have contacted Mads here:
http://blog.madskristensen.dk/post/Examples-on-new-BlogEngineNET-13-features.aspx#id_cf59b069-ae24-4189-bc86-bd7bc3973d1a

will have community website were you'll be able to publish extensions yourself
I know. But it think to have mistaken the place where to publish the link (sob!): http://www.codeplex.com/BlogEngineExtensions/Thread/View.aspx?ThreadId=21105

Now, i have written a new extension (a new component of course): Top Commenters component, like WordPress Top Commenters plug-in, but more powerfull and flexible. And now ? Wink

Cristiano |

2/4/2008 10:56:37 PM #

rtur

Now, i have written a new extension (a new component of course): Top Commenters component, like WordPress Top Commenters plug-in, but more powerfull and flexible. And now ?

I've talked to Al, he will contact you shortly and will help you to push this component to community site.

rtur |

Comments are closed
<<  March 2010  >>
SuMoTuWeThFrSa
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Enhanced with Snapshots

Subscribe to Rtur.net