Giter Club home page Giter Club logo

pattern-lock-js's Introduction

pattern-lock-js

A passcode mechanism built with scalable vector graphics (SVG) and javascript for modern web application with mobile and tablet support

Install

Install using npm:

npm i pattern-lock-js --save

... or install using yarn:

yarn add pattern-lock-js

Getting started

Import dependecies:

<script src="jquery.js" charset="utf-8"></script>

Import the module:

<link rel="stylesheet" href="patternlock.min.css">
<script src="patternlock.min.js" charset="utf-8"></script>

Design your desired svg pattern (or use the default one below). Your svg graphics must as a minimum have the patternlock class and three groups <g> with the classes lock-actives, lock-lines and lock-dots

<svg class="patternlock" id="lock" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
    <g class="lock-actives"></g>
    <g class="lock-lines"></g>
    <g class="lock-dots">
        <circle cx="20" cy="20" r="2"/>
        <circle cx="50" cy="20" r="2"/>
        <circle cx="80" cy="20" r="2"/>

        <circle cx="20" cy="50" r="2"/>
        <circle cx="50" cy="50" r="2"/>
        <circle cx="80" cy="50" r="2"/>

        <circle cx="20" cy="80" r="2"/>
        <circle cx="50" cy="80" r="2"/>
        <circle cx="80" cy="80" r="2"/>
    </g>
</svg>

Initialise the component

var lock = new PatternLock("#lock", {
  onPattern: function(pattern) {
    // Context is the pattern lock instance
    console.log(pattern)
   }
});

Options

The returned object from new PatternLock(...) has the following utility functions:

  • clear() Clears the current pattern
  • success() Validates the pattern as correct
  • error() Validates the pattern as incorrect
  • getPattern() Returnes the currently active pattern or NaN

The pattern lock constructor accepts a second argument - an object literal with the following properties:

  • onPattern: function Called when a pattern is drawn with the pattern as argument. Returning true/false validates/invalidates the pattern - the same as calling success() and error(). The context is set to the pattern lock instance itself.
  • vibrate: boolean Defines if there should be vibrations while using the PatternLock (if available). Default: true

pattern-lock-js's People

Contributors

tympanix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pattern-lock-js's Issues

Port to Angular

I'd love to have this library ported to Angular (and possibly other available frontend frameworks).

Possible to draw illegal pattern

Hi, it is possible to draw an illegal pattern that skips a dot by drawing around it. For example 19854 should not be possible.

Fix for preventDefault issue

Hi, when connecting any dot, the follwoing error is raised in console (at least in Chrome):
Unable to preventDefault inside passive event listener due to target being treated as passive.

image

This can be fixed by simply adding the following code into you CSS.

svg {
  touch-action: none;
  }

P.S. I'm using v1.0.1

Thanks for the plugin :-)

Add numbers to pattern

ITS NOT AN ISSUE BUT SIMPLE YET EFFECTIVE ADD-ON. You can add the respective numbers to the pattern that a user can record after creating pattern below the pattern frame. like for a Home type pattern - 4-2-6-3-9-8-7-1. So this number can be displayed below so that it is easy to remember as after few seconds user might forget where they started while creating complex pattern types.
NOT AN ISSUE BUT JUST IT WOULD BE AN INTERESTING ADDON.

show old pattern

I can show a pattern we drew before, for example (123654), how it was drawn again.

Multiple Select

Is there any way to document when an already hit dot gets hit again?

1 2 3
4 5 6
7 8 9

if i go 159654, the second 5 is not recorded.

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.