GithubHelp home page GithubHelp logo

rellikjaeger / small-color-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from antelle/small-color-picker

0.0 1.0 0.0 514 KB

jQuery color picker and button styles

Home Page: https://antelle.net/small-color-picker/

License: MIT License

JavaScript 88.02% CSS 8.95% HTML 3.03%

small-color-picker's Introduction

SmallColorPicker

SmallColorPicker is a tiny jQuery color picker licensed under MIT. Also the project includes buttons styles for color selection.
Live demo page is here. Screenshot:

Small color picker

Features

This color picker includes:

  • color wheel and text input modes;
  • minimalistic popup interface;
  • old (previous) and new (current) color display;
  • color buttons which will automatically change its color;
  • popup and static positioning;
  • text input of colors in natural language;
  • touch devices support;
  • multi-target popup mode (if initialized with several buttons, only one picker will be visible);
  • retina graphics.

This color picker does not include:

  • support of non-CSS3 browsers

Usage

SmallColorPicker initializations should look like this:

try {
    $(".color-btn").smallColorPicker({ /* options */ });
} catch (err) {
    // the browser is not supported
}

Please note: options object is mandatory, you can pass just {}.
You can use color picker either in static mode (e.g. in a control displayed on your page), or in popup mode. In case the picker is initialized in popup mode, only one picker will be created for jQuery selector used for initialization (you can see this on example.html page in the source code). If you are using color buttons from this library, the picker will automatically replace color values in them.
To get an earlier created color picker, call

var picker = $(".color-btn").smallColorPicker();  

If you wish, you can also use the picker in non-jQuery version (new SmallColorPicker.CirclePicker({})) but this is more complex and still requires jQuery for operation.

Options

$(".color-btn").smallColorPicker({
    placement: {
        position: "absolute", // positioning (ignored in popup mode)
        top: "0", // top posision (ignored in popup mode)
        left: "0", // left position (ignored in popup mode)
        parent: null, // don't pass this if you are using jQuery plugin version
        popup: true // popup or static color picker verson
    },
    colors: {
        colorOld: null, // old color (the one displayed on the left)
        colorNew: "#ff0000" // new color (displayed on the right; currently selected color)
    },
    texts: { // texts used in color picker
        ok: "OK",
        cancel: "Cancel",
        switchModeToNum: "Show numbers",
        switchModeToCol: "Show color wheel"
    },
    behavior: {
        rotate: true, // whether to rotate color shades square
        hideOnSelect: true, // auto hide picker on color select
        mode: SmallColorPicker.Mode.COLOR, // default color selection mode 
        switchMode: true, // whether the user can switch input mode
        animation: true // show/hide fade animation 
    }
});

Methods

This code explains usage of methods:

var picker = $(".color-btn").smallColorPicker(); // get the picker
picker.show(); // show the picker
picker.hide(); // hide the picker
picker.toggle(); // toggle picker visibility
picker.toggle(true); // show the picker
picker.toggle(false); // hide the picker
var visible = picker.isVisible(); // is the picker visible
picker.switchMode(); // switch input mode between color wheel and numberic
picker.switchMode(SmallColorPicker.Mode.COLOR); // switch to clor wheel mode
picker.switchMode(SmallColorPicker.Mode.NUMBER); // switch to numeric mode
picker.setColors("#ff0000"); // set the displayed (selected) color
picker.setColors("#ff0000", "#000000"); // set both colors: displayed (selected) and old (previously selected)
var parent = picker.parent(); // get picker current parent
picker.parent("#btn2"); // change picker parent
picker.destroy(); // completely remove color picker 

Events

Here's how to listen the picker events:

$(".color-btn").on {
    scp_ok: function(picker, color) {  }, // color is selected
    scp_cancel: function(picker, color) {  }, // color selection cancelled
    scp_show: function(picker) {  }, // picker is shown
    scp_hide: function(picker) {  } // picker is hidden
}

Building

Use grunt to build this project. It will put the result into ../build-v1 folder.

small-color-picker's People

Watchers

James Cloos 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.