BarnamenevisEditor Documentation

Complete guide to using BarnamenevisEditor in your projects

Installation

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>

Basic Usage

Initialize the editor on a textarea element:

<textarea id="myEditor">Initial content</textarea>

<script>
$(document).ready(function() {
    $('#myEditor').barnamenevisEditor({
        language: 'en'
    });
});
</script>

Configuration Options

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.

Example Configuration:

$('#myEditor').barnamenevisEditor({
    height: '600px',
    language: 'en',
    toolbar: 'full',
    onChange: function(content) {
        console.log('Content changed:', content);
    },
    onInit: function(editor) {
        console.log('Editor initialized:', editor);
    }
});

Methods

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');

Events

Listen to editor events:

Event Description Example
barnameneviseditor.change Triggered when content changes
$('#myEditor').on('barnameneviseditor.change', function(e, content) {
    console.log('Changed:', content);
});
barnameneviseditor.init Triggered when editor is initialized
$('#myEditor').on('barnameneviseditor.init', function(e, editor) {
    console.log('Initialized');
});
barnameneviseditor.focus Triggered when editor gains focus
$('#myEditor').on('barnameneviseditor.focus', function() {
    console.log('Focused');
});
barnameneviseditor.blur Triggered when editor loses focus
$('#myEditor').on('barnameneviseditor.blur', function() {
    console.log('Blurred');
});

Toolbar Options

Customize the toolbar with preset configurations or custom buttons:

Preset Configurations:

  • 'full' - All available buttons (default)
  • 'basic' - Essential formatting buttons only
  • 'minimal' - Minimal set of buttons

Custom Toolbar:

$('#myEditor').barnamenevisEditor({
    language: 'en',
    toolbar: [
        ['bold', 'italic', 'underline'],
        ['fontname', 'fontsize'],
        ['forecolor', 'backcolor'],
        ['insertLink', 'insertImage'],
        ['undo', 'redo']
    ]
});

Available Toolbar Buttons:

  • bold - Bold text
  • italic - Italic text
  • underline - Underline text
  • strikethrough - Strikethrough text
  • fontname - Font family selector
  • fontsize - Font size selector
  • forecolor - Text color
  • backcolor - Background color
  • removeFormat - Clear formatting
  • insertOrderedList - Numbered list
  • insertUnorderedList - Bulleted list
  • justifyLeft - Align left
  • justifyCenter - Align center
  • justifyRight - Align right
  • justifyFull - Justify
  • directionLTR - Set inline LTR direction
  • directionRTL - Set inline RTL direction
  • paragraphLTR - Set block-level LTR direction
  • paragraphRTL - Set block-level RTL direction
  • insertTable - Insert table
  • insertImage - Insert image
  • insertLink - Insert link
  • codeView - Toggle HTML view
  • fullscreen - Toggle fullscreen
  • undo - Undo
  • redo - Redo
Note: Color pickers include a live indicator bar that mirrors the selected text/background color and resets when no color is applied.

Localization

BarnamenevisEditor ships with English (en) and Persian (fa). Adding more languages is straightforward:

1. Load Language Files

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>

2. Initialize with Language

$('#editor').barnamenevisEditor({
    language: 'fa'  // or 'en'
});

3. Create New Translations

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: 'ابدأ الكتابة...'
    };
})();
Tips
  • Only load the language files you need to keep bundle size small
  • RTL languages should set <html dir="rtl"> (or wrap the editor)
  • Missing translations fall back to English automatically

Custom Fonts

BarnamenevisEditor can show any font in the dropdown—system fonts, local @font-face, or Google Fonts.

Basic Setup

  1. Load the font (CSS @font-face, external stylesheet, or Google Fonts link)
  2. Provide the font list via fontFamilies. When specified, your list replaces the defaults entirely.
  3. Use object format to show localized names or include fallbacks

Example: Custom Fonts with Display Names

$('#editor').barnamenevisEditor({
    language: 'en',
    fontFamilies: [
        'Arial',
        'Georgia',
        { displayName: 'میخک (Mikhak)', value: 'Mikhak, Tahoma, sans-serif' },
        { displayName: 'Roboto', value: 'Roboto, Arial, sans-serif' }
    ]
});

Example: Persian Editor with Custom Fonts

<!-- 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>
Best Practices
  • Always include fallback fonts in value
  • Ensure the font stylesheet loads before initializing the editor
  • Use Developer Tools → Network (Font filter) to confirm font files load successfully
  • When fontFamilies is specified, only those fonts appear—no defaults are merged

Styling & Themes

BarnamenevisEditor supports multiple themes and custom styling:

Dark Mode:

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');
Note: Demo pages include a toggle that adds 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.

Custom Styling:

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;
}

Keyboard Shortcuts

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)
Tip: On macOS, use Cmd instead of Ctrl.

Code Examples

Example 1: Basic Editor

<textarea id="editor1"></textarea>

<script>
$('#editor1').barnamenevisEditor({ language: 'en' });
</script>

Example 2: Editor with Custom Height

$('#editor2').barnamenevisEditor({
    height: '300px',
    toolbar: 'basic',
    language: 'en'
});

Example 3: Editor with Change Callback

$('#editor3').barnamenevisEditor({
    language: 'en',
    onChange: function(content) {
        $('#preview').html(content);
    }
});

Example 4: Multiple Editors

$('.editor').each(function() {
    $(this).barnamenevisEditor({
        height: '250px',
        toolbar: 'minimal',
        language: 'en'
    });
});

Example 5: Get and Set Content

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

Troubleshooting

Common issues and solutions:

Ensure jQuery loads before js/app.js. Check the browser console for JavaScript errors and verify all script tags are in the correct order.

Call $('#editor').barnamenevisEditor('getContent') on form submit to retrieve the HTML content manually. The original textarea is hidden and not automatically updated.

  • Confirm font files load (check Network tab in DevTools)
  • Match the exact font-family name in CSS
  • Include fallback fonts in the value property
  • Ensure font stylesheets load before editor initialization

Verify selection is active. Modal and color pickers now save & restore selection automatically, but if issues persist, click inside the editor content area before applying formatting.

Wrap the editor container with dir="rtl" or use the paragraph direction buttons (paragraphLTR/paragraphRTL) to toggle block-level direction. For inline direction changes, use directionLTR/directionRTL buttons.

Browser Support

BarnamenevisEditor works on all modern browsers without polyfills:

  • Chrome / Edge (Chromium) Supported
  • Firefox Supported
  • Safari Supported
  • Mobile browsers (iOS/Android) Supported
Note: Internet Explorer is not supported. All features rely on modern JavaScript APIs and CSS features available in evergreen browsers.

Need Help?

Check out the Examples page for more practical demonstrations.