GithubHelp home page GithubHelp logo

pedrocatre / pwswitch Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 619 KB

Turn boring checkboxes into pretty switches - an AngularJS directive for the pswitch library.

License: MIT License

JavaScript 71.73% HTML 27.39% CSS 0.88%

pwswitch's Introduction

pwSwitch for AngularJS

Turn boring checkboxes into pretty switches. An AngularJS directive for the pswitch library.

Demo

http://pedrocatre.github.io/pwSwitch/#/

Dependencies

This plugin uses AngularJS version 1.x and the pswitch library and jQuery.

Install

bower install angular-pwSwitch --save

Include the stylesheet and javascript from the pswitch dist folder into your project.

<link rel="stylesheet" type="text/css" href="bower_components/pswitch/dist/jquery.pswitch.min.css" />
<script type="javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="javascript" src="bower_components/pswitch/dist/jquery.pswitch.min.js"></script>

Also include the pwSwitch angular directive from the pwSwitch dist folder, after you have included angular.

<script type="javascript" src="bower_components/angular-pwSwitch/dist/pwSwitch.min.js"></script>

Usage Example

Inject in the dependencies:

angular.module('app', [
        'pwSwitch'
    ]);

And use the directive in a template:

<pw-switch ng-model="switchValue"></pw-switch>

To display labels on the sides of the switch for the on and off state, define two data attributes on the directive. The switch will be displayed without labels if you do not specify them.

<pw-switch ng-model="switchValue"
data-checked="activated"
data-unchecked="deactivated">
</pw-switch>

Like a checkbox you can specify ng-true-value and ng-false-value to specify the value to which the expression should be set when selected. you can read more about it in the AngularJS docs. And here is an example of that:

<pw-switch ng-model="switchValue"
ng-true-value="'ACTIVE'"
ng-false-value="'DEACTIVATED'"
data-checked="activated"
data-unchecked="deactivated">
</pw-switch>

To change the switch color, just pass the color code for the switch:

<pw-switch ng-model="switchValue"
r="140"
g="25"
b="30">
</pw-switch>

To control if the switch is enabled or disabled pass it in:

<pw-switch ng-model="switchValue"
enabled="switchValueEnabled"></pw-switch>

To go to a flat-ui style pass flat=true:

<pw-switch ng-model="switchValue"
flat="true"></pw-switch>

Dependencies

This plugin uses AngularJS version 1.x and the pswitch library and jQuery.

Browser compatibility

Chrome, Safari, Firefox, IE9+

Credits

pswitch jQuery lib for transforming the checkboxes built by Thomas Pischke

License

The code in this repository can be used under the MIT License.

pwswitch's People

Stargazers

Bob Rupholdt avatar TC Devs avatar Arne Pettersen avatar Mehul Patel avatar Dmitry Malchikov avatar Brian Bonner avatar Kai avatar Pedro Catré avatar

Watchers

Pedro Catré avatar James Cloos avatar

Forkers

adswebwork

pwswitch's Issues

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.