Giter Site home page Giter Site logo

scribble's Introduction

#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:

  • canvas-holder : Class for the div that wraps the canvas. (Default: scribble-canvas-holder)
  • main-canvas : Class for the main canvas. (Default: scribble-main-canvas)
  • shadow-canvas : Class for the auxiliar canvas used. (Default: scribble-main-canvas)

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.

  • pencil : This is the default value and is what you expect.
  • eraser : This is what you expect too… It will erase as you draw.

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:

  • toJSON : It returns an object literall with all the points.
  • loadJSON : It loads that object and draws everything back.
  • toDataURL : Converts the canvas to base64 string
  • loadDataUrl : Loads the canvas from a base64 string

##Development

###Requirements

  • node and npm
  • bower npm install -g bower
  • grunt npm install -g grunt-cli

###Setup

  • npm install
  • bower install

###Run

grunt dev

or for just running tests on file changes:

grunt ci

###Tests

grunt mocha

scribble's People

Contributors

antonio-laguna avatar jgallen23 avatar

Watchers

 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.