GithubHelp home page GithubHelp logo

jwysiwyg's Introduction

jWYSIWYG 0.5 User Manual

Quick Start

The following code creates a jWYSIWYG editor with the default options:

<script type="text/javascript" src="jquery.wysiwyg.js"></script>
<script type="text/javascript">
$(function() {
    $('#wysiwyg').wysiwyg();
});
</script>

<textarea id="wysiwyg"></textarea>

Activating Hidden Controls

Toolbar buttons are selected with the controls configuration option:

$('#wysiwyg').wysiwyg({
    controls: {
        strikeThrough: { visibile: true },
        underline: { visible: true },
        subscript: { visible: true },
        superscript: { visible: true }
    }
});

A full list of available controls options is available in ____.

Adding Custom Controls

Custom controls can also be specified with the controls option:

$('#wysiwyg').wysiwyg({
    controls: {
        alertSep: { separator: true },
        alert: {
            visible: true,
            exec: function() { alert('Hello World'); },
            className: 'alert'
        }
    }
})

Styling the Content Inside the Editor

To apply a CSS stylesheet to the content inside the editor, use the css configuration option:

$('#wysiwyg').wysiwyg({
    css: 'editor.css'
});

The editor will not inherit the style of the containing page by default, you must specify a CSS file to apply to it.

Clear the Editor

To clear the editor at any time:

$('#wysiwyg').wysiwyg('clear');

Insert an Image

When the #insertImage link is clicked, insert an image inline at the current cursor location in the editor:

$('a[href="#insertImage"]').click(function() {
    $('#wysiwyg').wysiwyg('insertImage', 'img/hourglass.gif');
});

Insert an Image with Attributes

Add some additional attributes to the image, as well:

$('a[href="#insertImage"]').click(function() {
    $('#wysiwyg').wysiwyg('insertImage', 'img/hourglass.gif', { 'class': 'myClass', 'className': 'myClass' });
});

Note that the class attribute is added twice, because the class DOM attribute is recognized on IE but not on Firefox, and the className attribute is recognized on Firefox but not on IE.

Available Configuration Options

Additional configuration options are specified by passing a javascript object to the wysiwyg() function when it is first called on a textarea. Available keys are:

html

A string containing the source HTML code used inside the editor's iframe. This is a template where STYLE_SHEET and INITIAL_CONTENT are later replaced by the appropriate code for the editor instance, so those two strings must be present in this option.

css

A string containing the path to a CSS file which will be included in the editor's iframe.

debug

A boolean, enabling or disabling debugging.

autoSave

A boolean. If true, the editor will copy its contents back to the original textarea anytime it is updated. If false, this must be done manually.

rmUnwantedBr

A boolean. If true, the editor will not add extraneous <br> tags.

brIE

A boolean. If true, a <br /> will be inserted for a newline in IE.

controls

A javascript object specifying control buttons and separators to include in the toolbar. This can consist of built-in controls and custom controls. Controls are specified as key, value pairs in the javascript object, where the key is the name of the control and the value is another javascript object with a specific signature.

The signature of a control object looks like this:

{
    // If true, this object will just be a vertical separator bar,
    // and no other keys should be set.
    separator: { true | false },

    // If false, this button will be hidden.
    visible: { true | false },

    // Tags to use to wrap the selected text when this control is
    // triggered.
    tags: ['b', 'strong'],

    // CSS classes to apply to selected text when this command is
    // triggered.
    css: {
        textAlign: 'left',
        fontStyle: 'italic',
        ...
    },

    // Function to execute when this command is triggered. If this
    // key is provided, CSS classes/tags will not be applied, and
    // any built-in functionality will not be triggered.
    exec: function() { ... },
}

If you wish to override the default behavior of built-in controls, you can do so by specifying only the keys which you wish to change the behavior of. For example, since the strikeThrough control is not visibly by default, to enable it we only have to specify:

strikeThrough: { visible: true }

Additionally, custom controls may be specified by adding new keys with the same signature as a control object. For example, if we wish to create a quote control which creates <blockquote> tags, we could do specify this key:

quote: { visible; true, tags: ['blockquote'], css: { class: 'quote', className: 'quote' } }

Note that when defining custom controls, you will most likely want to add additional CSS to style the resulting toolbar button. The CSS to style a button looks like this:

div.wysiwyg ul.panel li a.quote {
    background: url('quote-button.gif') no-repeat 0px 0px;
}

Available built-in controls are:

  • bold: Make text bold.
  • italic: Make text italic.
  • strikeThrough: Make text strikethrough.
  • underline: Make text underlined.
  • seperator00
  • justifyLeft: Left-align text.
  • justifyCenter: Center-align text.
  • justifyRight: Right-align text.
  • justifyFull: Justify text.
  • separator01
  • indent: Indent text.
  • outdent: Outdent text.
  • separator02
  • subscript: Make text subscript.
  • superscript: Make text superscript.
  • separator03
  • undo: Undo last action.
  • redo: Redo last action.
  • separator04
  • insertOrderedList: Insert ordered (numbered) list.
  • insertUnorderedList: Insert unordered (bullet) list.
  • insertHorizontalRule: Insert horizontal rule.
  • separator05
  • createLink: Create a link from the selected text, by prompting user for the URL.
  • insertImage: Insert an image, by prompting the user for the image path.
  • separator06
  • h1mozilla: Make text an h1 header, Mozilla-specific.
  • h2mozilla: Make text an h2 header, Mozilla-specific.
  • h3mozilla: Make text on h3 header, Mozilla-specific.
  • h1: Make text an h1 header, non-Mozilla-specific.
  • h2: Make text an h2 header, non-Mozilla-specific.
  • h3: Make text an h3 header, non-Mozilla-specific.
  • separator07
  • cut: Cut selected text.
  • copy: Copy selected text.
  • paste: Paste from clipboard.
  • separator08
  • increaseFontSize: Increase font size.
  • decreaseFontSize: Decrease font size.
  • separator09
  • html: Show the original textarea with HTML source. When clicked again, copy the textarea code back to the jWYSIWYG editor.
  • removeFormat: Remove all formatting.
messages

A javascript object with key, value pairs setting custom messages for certain conditions. Available keys are:

  • nonSelection : Message to display when the Create Link button is pressed with no text selected.

Available Built-In Functions

Built-in editor functions can be triggered manually with the .wysiwyg() call.

Customizing the Editor Look and Feel

How it Works

When jWYSIWYG is called on a textarea, it does the following things:

  1. Creates an additional container div to encapsulate the new editor.
  2. Hides the existing textarea.
  3. Creates an iframe inside the container div, populated with editor window and toolbar.
  4. When saveContent() is called,

jwysiwyg's People

Contributors

joksnet avatar sfranchi avatar

Stargazers

William Melody avatar

Watchers

William Melody avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.