Complete guide to using BarnamenevisEditor in your projects
Include the required files in your HTML:
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">
<link href="css/BarnamenevisEditor.css" rel="stylesheet">
<!-- JavaScript -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="js/BarnamenevisEditor.js"></script>
<script src="js/lang/en.js"></script>
Initialize the editor on a textarea element:
<textarea id="myEditor">Initial content</textarea>
<script>
$(document).ready(function() {
$('#myEditor').barnamenevisEditor({
language: 'en'
});
});
</script>
Customize the editor with various options:
| Option | Type | Default | Description |
|---|---|---|---|
height |
String | '400px' | Height of the editor content area. Accepts any valid CSS height. |
language |
String | 'en' | Language code loaded from window.BarnamenevisEditor.lang (e.g., 'en', 'fa') |
toolbar |
String/Array | 'full' | Toolbar configuration: 'full', 'basic', 'minimal', or custom nested array of button ids |
fontFamilies |
Array | internal defaults | Array of strings or {displayName, value} objects. Replaces defaults entirely when specified. |
fontSizes |
Array | [1,2,3,4,5,6,7] | Mapping onto browser font size levels (1–7) |
colors |
Array | 64 preset hex values | Color palette for foreground/background pickers |
showStatusBar |
Boolean | true | Toggle status bar with word/character counts |
placeholder |
String | 'Start typing…' | Placeholder text shown when editor is empty |
onInit |
Function | null | Callback fired after editor mounts. Receives editor instance. |
onChange |
Function | null | Fired whenever content changes. Receives HTML string. |
$('#myEditor').barnamenevisEditor({
height: '600px',
language: 'en',
toolbar: 'full',
onChange: function(content) {
console.log('Content changed:', content);
},
onInit: function(editor) {
console.log('Editor initialized:', editor);
}
});
Available methods to interact with the editor:
getContent()Get the HTML content from the editor
var html = $('#myEditor').barnamenevisEditor('getContent');
setContent(html)Set HTML content in the editor
$('#myEditor').barnamenevisEditor('setContent', '<p>New content</p>');
getText()Get plain text content (without HTML tags)
var text = $('#myEditor').barnamenevisEditor('getText');
clear()Clear all content from the editor
$('#myEditor').barnamenevisEditor('clear');
destroy()Destroy the editor instance and restore the original textarea
$('#myEditor').barnamenevisEditor('destroy');
focus()Set focus to the editor
$('#myEditor').barnamenevisEditor('focus');
disable()Disable the editor (read-only mode)
$('#myEditor').barnamenevisEditor('disable');
enable()Enable the editor
$('#myEditor').barnamenevisEditor('enable');
Listen to editor events:
| Event | Description | Example |
|---|---|---|
barnameneviseditor.change |
Triggered when content changes | |
barnameneviseditor.init |
Triggered when editor is initialized | |
barnameneviseditor.focus |
Triggered when editor gains focus | |
barnameneviseditor.blur |
Triggered when editor loses focus | |
Customize the toolbar with preset configurations or custom buttons:
'full' - All available buttons (default)'basic' - Essential formatting buttons only'minimal' - Minimal set of buttons$('#myEditor').barnamenevisEditor({
language: 'en',
toolbar: [
['bold', 'italic', 'underline'],
['fontname', 'fontsize'],
['forecolor', 'backcolor'],
['insertLink', 'insertImage'],
['undo', 'redo']
]
});
bold - Bold textitalic - Italic textunderline - Underline textstrikethrough - Strikethrough textfontname - Font family selectorfontsize - Font size selectorforecolor - Text colorbackcolor - Background colorremoveFormat - Clear formattinginsertOrderedList - Numbered listinsertUnorderedList - Bulleted listjustifyLeft - Align leftjustifyCenter - Align centerjustifyRight - Align rightjustifyFull - JustifydirectionLTR - Set inline LTR directiondirectionRTL - Set inline RTL directionparagraphLTR - Set block-level LTR directionparagraphRTL - Set block-level RTL directioninsertTable - Insert tableinsertImage - Insert imageinsertLink - Insert linkcodeView - Toggle HTML viewfullscreen - Toggle fullscreenundo - Undoredo - RedoBarnamenevisEditor ships with English (en) and Persian (fa). Adding more languages is straightforward:
Load the language file(s) after js/BarnamenevisEditor.js:
<script src="js/BarnamenevisEditor.js"></script>
<script src="js/lang/en.js"></script>
<script src="js/lang/fa.js"></script>
$('#editor').barnamenevisEditor({
language: 'fa' // or 'en'
});
Copy js/lang/en.js and update the language code:
(function () {
window.BarnamenevisEditor = window.BarnamenevisEditor || {};
window.BarnamenevisEditor.lang = window.BarnamenevisEditor.lang || {};
window.BarnamenevisEditor.lang.ar = {
toolbar: {
undo: 'تراجع (Ctrl+Z)',
redo: 'إعادة (Ctrl+Y)',
// … more toolbar strings
},
modal: {
insertLink: 'إدراج رابط',
// … more modal strings
},
statusBar: {
words: 'كلمات',
word: 'كلمة',
characters: 'أحرف',
character: 'حرف'
},
messages: {
enterUrl: 'الرجاء إدخال عنوان URL'
},
placeholder: 'ابدأ الكتابة...'
};
})();
<html dir="rtl"> (or wrap the editor)BarnamenevisEditor can show any font in the dropdown—system fonts, local @font-face, or Google Fonts.
fontFamilies. When specified, your list replaces the defaults entirely.$('#editor').barnamenevisEditor({
language: 'en',
fontFamilies: [
'Arial',
'Georgia',
{ displayName: 'میخک (Mikhak)', value: 'Mikhak, Tahoma, sans-serif' },
{ displayName: 'Roboto', value: 'Roboto, Arial, sans-serif' }
]
});
<!-- Load Persian fonts -->
<link rel="stylesheet" href="fonts/mikhak/Mikhak.css">
<link rel="stylesheet" href="fonts/sahel/Sahel.css">
<link rel="stylesheet" href="fonts/vazir/Vazirmatn.css">
<script>
$('#persianEditor').barnamenevisEditor({
language: 'fa',
fontFamilies: [
'Tahoma',
'Arial',
{ displayName: 'میخک (Mikhak)', value: 'Mikhak, Tahoma, sans-serif' },
{ displayName: 'ساحل (Sahel)', value: 'Sahel, Tahoma, sans-serif' },
{ displayName: 'وزیر (Vazir)', value: 'Vazirmatn, Tahoma, sans-serif' }
]
});
</script>
valuefontFamilies is specified, only those fonts appear—no defaults are mergedBarnamenevisEditor supports multiple themes and custom styling:
Toggle dark mode by adding the theme-dark class to the editor wrapper:
// Enable dark mode
$('.custom-editor-wrapper').addClass('theme-dark');
// Toggle dark mode
$('.custom-editor-wrapper').toggleClass('theme-dark');
// Full page dark mode
$('body').addClass('dark-mode');
$('.custom-editor-wrapper').addClass('theme-dark');
body.dark-mode, theming headings, buttons, code blocks, and the editor wrapper together. Code view and HTML preview force LTR direction, Consolas font, no left gutter, and sanitized indentation.
Override CSS classes to customize appearance:
.custom-editor-wrapper {
border: 2px solid #007bff;
border-radius: 8px;
}
.custom-editor-toolbar {
background: linear-gradient(to right, #667eea 0%, #764ba2 100%);
}
.custom-editor-content {
font-family: 'Georgia', serif;
font-size: 16px;
}
BarnamenevisEditor supports standard keyboard shortcuts for common editing tasks:
| Shortcut | Action |
|---|---|
| Ctrl + B | Bold |
| Ctrl + I | Italic |
| Ctrl + U | Underline |
| Ctrl + Z | Undo |
| Ctrl + Y | Redo |
| Ctrl + Shift + Z | Redo (alternative) |
| Tab | Indent (in lists) |
| Ctrl + C / X / V | Copy / Cut / Paste (browser defaults) |
<textarea id="editor1"></textarea>
<script>
$('#editor1').barnamenevisEditor({ language: 'en' });
</script>
$('#editor2').barnamenevisEditor({
height: '300px',
toolbar: 'basic',
language: 'en'
});
$('#editor3').barnamenevisEditor({
language: 'en',
onChange: function(content) {
$('#preview').html(content);
}
});
$('.editor').each(function() {
$(this).barnamenevisEditor({
height: '250px',
toolbar: 'minimal',
language: 'en'
});
});
// Get content
var html = $('#editor5').barnamenevisEditor('getContent');
console.log(html);
// Set content
$('#editor5').barnamenevisEditor('setContent', '<h1>Hello World</h1>');
// Get plain text
var text = $('#editor5').barnamenevisEditor('getText');
console.log(text);
Common issues and solutions:
js/app.js. Check the browser console for JavaScript errors and verify all script tags are in the correct order.
$('#editor').barnamenevisEditor('getContent') on form submit to retrieve the HTML content manually. The original textarea is hidden and not automatically updated.
font-family name in CSSvalue propertydir="rtl" or use the paragraph direction buttons (paragraphLTR/paragraphRTL) to toggle block-level direction. For inline direction changes, use directionLTR/directionRTL buttons.
BarnamenevisEditor works on all modern browsers without polyfills:
Check out the Examples page for more practical demonstrations.