firstandthird / scribble

Javascript library for turning an element into a canvas for drawing
MIT License
2 stars 3 forks source link

scribble

Turn a canvas element into a scribble pad that supports bouth mouse and touch.

Installation

Bower

bower install scribble

Manual Download

Usage

In order to initialize the module, you'll need to target either a canvas or a div. The module will wrap the canvas with a div or create a canvas inside the supplied div.

Finally, you need to just call scribble on top of the jQuery element:

$('#myAwesomeCanvas').scribble();

And that's it! Well, I lied a little. You have some methods and options available!

Available options

Option Explanation Default
color Color in which you'll draw #000000
size Size of the stroke 2
readMode Sets whether the canvas is in read mode false
tool Selected tool at beginning pencil
stopDrawingTime Time to debounce stop drawing 500
cssClasses Object that holds css classes to style See below

cssClasses have this configurable properties:

Note: Aside from cssClases, all the options can be change with methods after initialization.

Available methods

Several methods are exposed through Fidel for you to use that allows you to do fancy things.

changeColor(color)

With this method you can… change the stroke color. What did you expect? There is no validation performed on plugin side so you should be sure you're passing a good value.

changeSize(size)

Changes the size of the stroke. Size has to be an integer.

changeReadMode(mode)

Changes the read mode to whatever value you pass. If you pass true, you'll enable read mode and false will disable it.

undo

This method will undo the latest drawing.

redo

This method will redo the latest undone action.

clear

This method will clear the drawing canvas.

changeTool(tool)

This method allows you to change "drawing" tool. Currently there are only two possible values. Plugin will yell if you pass something which is not implemented.

Fired events

drawing.changed

Whenever the user finished drawing, this event will fire. It's debounced so it won't fire until the time defined on the option stopDrawingTime passess without any more alike events.

Export methods

There are 2 exports methods with their counterpart that will import as well:

Development

Requirements

Setup

Run

grunt dev

or for just running tests on file changes:

grunt ci

Tests

grunt mocha