Repository: wieringen/tinycolorpicker Branch: master Commit: df748ba11bfa Files: 38 Total size: 86.4 KB Directory structure: gitextract_yb7_sm4l/ ├── .gitignore ├── .jshintrc ├── .travis.yml ├── Gruntfile.coffee ├── MIT-LICENSE.txt ├── README.md ├── bower.json ├── docs/ │ ├── css/ │ │ └── tinycolorpicker.css │ ├── index.html │ └── technical/ │ └── theme/ │ ├── layouts/ │ │ └── main.handlebars │ ├── partials/ │ │ ├── attrs.handlebars │ │ ├── classes.handlebars │ │ ├── events.handlebars │ │ ├── files.handlebars │ │ ├── index.handlebars │ │ ├── method.handlebars │ │ ├── module.handlebars │ │ ├── options.handlebars │ │ ├── props.handlebars │ │ └── sidebar.handlebars │ └── theme.json ├── examples/ │ ├── nojquery/ │ │ ├── index.html │ │ └── tinycolorpicker.css │ └── simple/ │ ├── index.html │ └── tinycolorpicker.css ├── lib/ │ ├── jquery.tinycolorpicker.js │ └── tinycolorpicker.js ├── package.json ├── test/ │ ├── conf/ │ │ ├── karma-all.js │ │ ├── karma-ci.js │ │ ├── karma-common.js │ │ ├── karma-debug.js │ │ └── karma-dev.js │ ├── fixtures/ │ │ ├── tinycolorpicker-css.html │ │ └── tinycolorpicker.html │ └── unit/ │ ├── jquery.tinycolorpicker.spec.js │ └── tinycolorpicker.spec.js └── tinycolorpicker.jquery.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .DS_Store .ftppass dist/ docs/technical/generated/ node_modules/ *.sublime-project *.sublime-workspace ================================================ FILE: .jshintrc ================================================ { "laxcomma" : true , "laxbreak" : false } ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - 0.10 before_script: - export CHROME_BIN=chromium-browser - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start - npm install -g grunt-cli env: global: - secure: h/UQzq/D5P/fmZRCTNdJt5LrKjCNSEKY+nTfgnzXk3yt5bIvVVxkOLsWo8dmb7JWKHhS/UJrwzmrFNCNh2DH8Zm/ffkW505Z4tH3f6tZjEoQ0nSVyuumsJ7I7rEQ0Y7e2nGE+2X8FY54JIe+hM2mUdA87OLV8XL8pcYpQDO/I7s= - secure: GJCmrqpUEkbAJ8/BfWvh8bGhGH8By1lOCTyArzBNph6EcW1x48fkVrnPYHt4JIEbDFtZbsUCeDoUut44m0pnqEb1JOEyDKDHZIWka+5i2qH4omod5zXkV9spXJ9RiM9gNlIlzQhc6A7u4uMC3pvgo8rvRONxN/I7Pf13tyDhgHQ= script: - grunt ci after_script: - cat ./dist/reports/coverage/**/lcov.info | ./node_modules/coveralls/bin/coveralls.js ================================================ FILE: Gruntfile.coffee ================================================ module.exports = ( grunt ) -> grunt.loadNpmTasks "grunt-contrib-clean" grunt.loadNpmTasks "grunt-contrib-compress" grunt.loadNpmTasks "grunt-contrib-copy" grunt.loadNpmTasks "grunt-contrib-jshint" grunt.loadNpmTasks "grunt-contrib-uglify" grunt.loadNpmTasks "grunt-contrib-yuidoc" grunt.loadNpmTasks "grunt-ftp-deploy" grunt.loadNpmTasks "grunt-karma" grunt.loadNpmTasks "grunt-processhtml" grunt.initConfig pkg: grunt.file.readJSON "package.json" # Banner we want to show above the minified js files. # banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n ' + '<%= pkg.homepage ? "* " + pkg.homepage + "\\n *\\n " : "" %>' + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> <<%= pkg.author.email %>>;\n' + ' * Licensed under the <%= _.pluck(pkg.licenses, "type").join(", ") %> license */\n\n' # Validate javascript files with jsHint. # jshint: options: jshintrc: ".jshintrc" all: [ "lib/jquery.<%= pkg.name %>.js" ] # Run unit tests. # karma: dev: configFile: "test/conf/karma-dev.js" ci: configFile: "test/conf/karma-ci.js" # Remove old build. # clean: dist: src: "dist/" # Copy the images and the index to the dist location. # copy: docs: files: [ { expand: true, cwd: "docs", src: ["**/*", "!technical/**"], dest: "dist/docs", dot: true } { expand: true, cwd: "node_modules/baijs", src: "css/**/*", dest: "dist/docs" } { expand: true, cwd: "node_modules/baijs", src: "js/**/*", dest: "dist/docs" } { expand: true, cwd: "lib", src: "**/*", dest: "dist/docs/js" } ] examples: files: [ { expand: true, cwd: "examples", src: "**/*", dest: "dist/examples" } { expand: true, cwd: "lib", src: "jquery.<%= pkg.name %>*", dest: "dist/examples/simple" } { expand: true, cwd: "lib", src: "<%= pkg.name %>*", dest: "dist/examples/nojquery" } ] # Generate technical documentation from code. # yuidoc: compile: name: '<%= pkg.name %>' description: '<%= pkg.description %>' version: '<%= pkg.version %>' url: '<%= pkg.homepage %>' options: paths: 'lib/' themedir: 'docs/technical/theme', outdir: 'docs/technical/generated' # Minify the javascript. # uglify: dist: options: banner: "<%= banner %>" beautify: false files: [ { src: "lib/jquery.<%= pkg.name %>.js", dest: "lib/jquery.<%= pkg.name %>.min.js" } { src: "lib/<%= pkg.name %>.js", dest: "lib/<%= pkg.name %>.min.js" } ] # Set paths and version. # processhtml: options: process: true strip: true environment: "dist" data: version: "<%= pkg.version %>" html: files: [ { expand: true, src: "dist/docs/index.html" } { expand: true, src: "dist/examples/**/*.html" } ] # Make a zipfile from the dist and examples. # compress: docs: options: archive: "dist/<%= pkg.name %>-<%= pkg.version %>-docs.zip" expand: true cwd: "dist/docs" src: "**/*" dest: "." examples : options : archive: "dist/<%= pkg.name %>-<%= pkg.version %>.zip" expand : true cwd: "dist/examples" src: "**/*" dest: "." # Deploy plugin to baijs.com # "ftp-deploy": docs: auth: host: "ftp.baijs.nl" port: 21 authKey: "<%= pkg.name %>" src: "dist/docs" dest: "/" examples: auth: host: "ftp.baijs.nl" port: 21 authKey: "<%= pkg.name %>" src: "dist/" dest: "/" exclusions: [ "docs" "<%= pkg.name %>-<%= pkg.version %>-docs.zip" ] grunt.registerTask( "common" [ "jshint" "copy:docs" "yuidoc" "uglify:dist" "copy:examples" "processhtml" "compress:docs" "compress:examples" ] ) grunt.registerTask( "default" [ "clean:dist" "karma:dev" "common" ] ) grunt.registerTask( "ci" [ "clean:dist" "karma:ci" "common" ] ) grunt.registerTask( "ftp" [ "default" "ftp-deploy:docs" "ftp-deploy:examples" ] ) ================================================ FILE: MIT-LICENSE.txt ================================================ Copyright 2013 Maarten Baijs http://www.baijs.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ [tinycolorpicker](http://baijs.com/tinycolorpicker) [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![NPM version][npm-image]][npm-url] ================================================== ** HELP MAINTAINER NEEDED!! ** Support ---------------------------- - Browser support differs between the jQuery plugin and the plain Javascript microlib. Specifically, the plain Javascript microlib does not support legacy browsers such as IE6-8. Use the jQuery plugin release if support for those browsers is required. What you need to build your own version of tinycolorpicker -------------------------------------- In order to build tinycolorpicker, you need to have Node.js/npm, and git 1.7 or later installed. How to build your own tinycolorpicker ---------------------------- First, clone a copy of the main tinycolorpicker git repo by running: ```bash git clone git://github.com/wieringen/tinycolorpicker.git ``` Install the grunt-cli package so that you will have the correct version of grunt available from any project that needs it. This should be done as a global install: ```bash npm install -g grunt-cli ``` Enter the tinycolorpicker directory and install the Node dependencies, this time *without* specifying a global install: ```bash cd tinycolorpicker && npm install ``` Make sure you have `grunt` installed by testing: ```bash grunt -version ``` Then, to get a complete, minified (w/ Uglify.js), linted (w/ JSHint) version of tinycolorpicker, type the following: ```bash grunt ``` The built version of tinycolorpicker will be put in the `dist/` subdirectory, along with the minified copy and associated map file. Questions? ---------- If you have any questions, please feel free to email [me](mailto:wieringen@gmail.com). [travis-image]: https://travis-ci.org/wieringen/tinycolorpicker.svg?branch=master [travis-url]: https://travis-ci.org/wieringen/tinycolorpicker [coveralls-image]: https://img.shields.io/coveralls/wieringen/tinycolorpicker/master.svg [coveralls-url]: https://coveralls.io/r/wieringen/tinycolorpicker?branch=master [npm-image]: https://badge.fury.io/js/tinycolorpicker.png [npm-url]: http://badge.fury.io/js/tinycolorpicker ================================================ FILE: bower.json ================================================ { "name": "tinycolorpicker", "version": "0.9.5", "description": "A lightweight cross browser jQuery based colorpicker.", "main": "lib/jquery.tinycolorpicker.js", "ignore": [ "**/.*", "bower.json", "Gruntfile.coffee", "package.json", "README.md" ], "resolutions": { "jquery": "~1.5.0" }, "devDependencies": { "baijs": "latest", "chai": "~1.8.1", "coveralls": "^2.11.2", "grunt": "~0.4.1", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-compress": "~0.5.2", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "~0.8.0", "grunt-contrib-uglify": "~0.2.7", "grunt-contrib-yuidoc": "^0.6.0", "grunt-ftp-deploy": "~0.1.1", "grunt-karma": "0.8.0", "grunt-processhtml": "^0.3.6", "grunt-text-replace": "~0.3.9", "iectrl": "0.0.3", "karma": "~0.12.0", "karma-chai": "^0.1.0", "karma-chai-jquery": "^1.0.0", "karma-chai-sinon": "~0.1.0", "karma-chrome-launcher": "~0.1.1", "karma-coverage": "~0.1.3", "karma-firefox-launcher": "~0.1.2", "karma-html2js-preprocessor": "~0.1.0", "karma-htmlfile-reporter": "~0.1.0", "karma-ie-launcher": "~0.1.1", "karma-ievms": "0.0.4", "karma-jquery": "^0.1.0", "karma-junit-reporter": "~0.2.1", "karma-mocha": "~0.1.1", "karma-phantomjs-launcher": "~0.1.1", "karma-script-launcher": "~0.1.0", "mocha": "~1.15.1", "sinon": "~1.7.3", "sinon-chai": "~2.4.0" } } ================================================ FILE: docs/css/tinycolorpicker.css ================================================ /* COLORPICKER 1 EXAMPLE */ #colorPicker1 { width: 30px; height: 30px; position: relative; clear: both; margin: 0 auto 20px; } #colorPicker1 .track { background: #EFEFEF url(../images/text-color.png) no-repeat 50% 50%; height: 150px; width: 150px; padding: 10px; position: absolute; cursor: crosshair; float: left; left: -71px; top: -71px; display: none; border: 1px solid #ccc; z-index: 10; -webkit-border-radius: 150px; -moz-border-radius: 150px; border-radius: 150px; } #colorPicker1 .color { width: 25px; height: 25px; padding: 1px; border: 1px solid #ccc; display: block; position: relative; z-index: 11; background-color: #EFEFEF; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; cursor: pointer; } #colorPicker1 .colorInner { width: 25px; height: 25px; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; } #colorPicker1 .dropdown { list-style: none; display: none; width: 27px; position: absolute; top: 28px; border: 1px solid #ccc; left: 0; z-index: 1000; } #colorPicker1 .dropdown li{ height: 25px; cursor: pointer; } /* COLORPICKER 2 EXAMPLE */ #colorPicker2 { width: 87px; height: 30px; position: relative; clear: both; margin: 0 auto 20px; } #colorPicker2 .track { background: #EFEFEF url(../images/firefox.png) no-repeat 50% 50%; height: 150px; width: 150px; padding: 10px; position: absolute; cursor: crosshair; float: left; left: 75px; top: -71px; display: none; border: 1px solid #ccc; z-index: 10; -webkit-border-radius: 150px; -moz-border-radius: 150px; border-radius: 150px; } #colorPicker2 .color { width: 75px; height: 25px; line-height: 25px; text-decoration : none; padding: 1px; border: 1px solid #ccc; display: block; position: relative; z-index: 11; color: #666; background-color: #EFEFEF; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; cursor: pointer; padding: 0 0 0 10px; } #colorPicker2 .colorInner { width: 25px; height: 25px; float: right; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; border-left: 3px solid #ccc; } #colorPicker2 .dropdown { list-style: none; display: none; width: 27px; position: absolute; top: 26px; border: 1px solid #ccc; right: 0; z-index: 1000; } #colorPicker2 .dropdown li{ height: 25px; cursor: pointer; } /* COLORPICKER 3 EXAMPLE */ #colorPicker3 { width: 30px; height: 30px; position: relative; clear: both; margin: 0 auto 20px; } #colorPicker3 .track { background: #EFEFEF url(../images/text-color.png) no-repeat 50% 50%; height: 150px; width: 150px; padding: 10px; position: absolute; cursor: crosshair; float: left; left: -71px; top: -71px; display: none; border: 1px solid #ccc; z-index: 10; -webkit-border-radius: 150px; -moz-border-radius: 150px; border-radius: 150px; } #colorPicker3 .color { width: 25px; height: 25px; padding: 1px; border: 1px solid #ccc; display: block; position: relative; z-index: 11; background-color: #EFEFEF; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; cursor: pointer; } #colorPicker3 .colorInner { width: 25px; height: 25px; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; } #colorPicker3 .dropdown { list-style: none; display: none; width: 27px; position: absolute; top: 28px; border: 1px solid #ccc; left: 0; z-index: 1000; } #colorPicker3 .dropdown li{ height: 25px; cursor: pointer; } ================================================ FILE: docs/index.html ================================================ Tiny Colorpicker: A lightweight cross browser color picker.

What is it?

Tiny Colorpicker is a crossbrowser lib that creates a color picker (form) input. Its a easy way to add color pickers to your forms or user interface.

It comes in 2 flavours as a vanilla Javascript microlib and as a jQuery plugin.

Browser support differs between the jQuery plugin and the plain Javascript microlib. Specifically, the plain Javascript microlib does not support legacy browsers such as IE6-8. Use the jQuery plugin release if support for those browsers is required.

Features

  • IOS, Android and Windows Phone support.
  • Available as a jQuery plugin and as a vanilla Javascript microlib.
  • AMD, Node, requirejs and commonjs support.
  • Easy customizable
  • Can be used inside forms or outside
  • Lightweight
  • Source is on GitHub

Examples

The examples below are all for the jQuery Plugin. You can find some more (advanced and simple) examples here. You can also find a example for the plain javascript library there.

The example below is the most basic version. The colors are just a image that is taken from the css and drawn to a canvas. So you are completely free in how your picker looks and how its styled.


$(document).ready(function()
{
    $("#colorpicker1").tinycolorpicker();
});
                

The example below is to make clear that it can pick colors from any image in any shape or form you want. The image is taken from stylesheet.


$(document).ready(function()
{
    $("#colorpicker2").tinycolorpicker();
});
                    

The example below is to show how to use the setColor method.


$(document).ready(function()
{
    $("#colorPicker3").tinycolorpicker();
    var picker = $('#colorPicker3').data("plugin_tinycolorpicker");

    picker.setColor("#FF45CC");
});
                    

The generated API docs will be included here.

Usage


$(document).ready(function()
{
    // Initialize a colorpicker like this.
    //
    var $box = $('#box');
    $box.tinycolorpicker();

    // Try this to get access to the actual colorpicker instance.
    //
    var box = $box.data("plugin_tinycolorpicker");

    // Now you have access to all the methods and properties.
    //
    // box.setColor("#cccccc");
    // console.log(box.colorRGB);
    //
    // etc..

    // You can bind to the change event like this.
    //
    $box.bind("change", function()
    {
        console.log("do something when a new color is set");
    });
});
                
================================================ FILE: docs/technical/theme/layouts/main.handlebars ================================================ {{>layout_content}} ================================================ FILE: docs/technical/theme/partials/attrs.handlebars ================================================
{{! For backwards compatibility }}

{{name}}

{{#crossLink type}}{{/crossLink}} {{#if deprecated}} deprecated {{/if}} {{#if access}} {{access}} {{/if}} {{#if final}} final {{/if}} {{#if static}} static {{/if}} {{#if optional}} optional {{/if}} {{#if required}} required {{/if}} {{#if readonly}} readonly {{/if}}
{{#if overwritten_from}}

Inherited from {{overwritten_from/class}} {{#if foundAt}} but overwritten in {{/if}} {{else}} {{#if extended_from}}

Inherited from {{extended_from}}: {{else}} {{#providedBy}}

Provided by the {{.}} module.

{{/providedBy}}

{{#if foundAt}} Defined in {{/if}} {{/if}} {{/if}} {{#if foundAt}} `{{{file}}}:{{{line}}}` {{/if}}

{{#if deprecationMessage}}

Deprecated: {{deprecationMessage}}

{{/if}} {{#if since}}

Available since {{since}}

{{/if}}
{{{attrDescription}}}
{{#if default}}

Default: {{default}}

{{/if}} {{#if emit}}

Fires event {{name}}Change

Fires when the value for the configuration attribute `{{{name}}}` is changed. You can listen for the event using the `on` method if you wish to be notified before the attribute's value has changed, or using the `after` method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e {{#crossLink "EventFacade"}}{{/crossLink}}
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName {{#crossLink "String"}}{{/crossLink}}
      The name of the attribute being set.
    • subAttrName {{#crossLink "String"}}{{/crossLink}}
      If setting a property within the attribute's value, the name of the sub-attribute property being set.
{{/if}} {{#example}}

Example:

{{{.}}}
{{/example}}
================================================ FILE: docs/technical/theme/partials/classes.handlebars ================================================ {{#is_constructor}}

Constructor

{{>method}}
{{/is_constructor}} {{#if properties}}

Properties

{{#properties}} {{>props}} {{/properties}}
{{/if}} {{#if attrs}}

Attributes

{{#attrs}} {{>attrs}} {{/attrs}}
{{/if}} {{#if methods}}

Methods

{{#methods}} {{>method}} {{/methods}}
{{/if}} {{#if events}}

Events

{{#events}} {{>events}} {{/events}}
{{/if}} ================================================ FILE: docs/technical/theme/partials/events.handlebars ================================================ {{name}} {{#if type}} {{#crossLink type}}{{/crossLink}} {{/if}}
{{{eventDescription}}}
{{#if params}}

Event Payload:

{{/if}} {{#example}}

Example:

{{{.}}}
{{/example}} ================================================ FILE: docs/technical/theme/partials/files.handlebars ================================================

File: {{fileName}}

{{fileData}}
    
================================================ FILE: docs/technical/theme/partials/index.handlebars ================================================

Browse to a module or class using the sidebar to view its API documentation.

Keyboard Shortcuts

================================================ FILE: docs/technical/theme/partials/method.handlebars ================================================ {{name}} {{#if params}} ( {{#params}} {{#if optional}} {{name}}{{#if optdefault}}={{optdefault}}{{/if}} {{else}} {{name}} {{/if}} {{/params}} ) {{else}} () {{/if}}
{{{methodDescription}}}
{{#if params}} {{/if}} ================================================ FILE: docs/technical/theme/partials/module.handlebars ================================================

{{name}} Module

{{#extra}} {{#selleck}} User Guide & Examples {{/selleck}} {{/extra}} {{#if requires}}
Requires
{{/if}} {{#if foundAt}}
Defined in: `{{{file}}}:{{{line}}}`
{{/if}} {{#if since}}

Available since {{since}}

{{/if}}
{{#if deprecated}}

{{#if deprecationMessage}} Deprecated: {{deprecationMessage}} {{else}} This module is deprecated. {{/if}}

{{/if}}
{{{moduleDescription}}}
{{#example}}

Example:

{{{.}}}
{{/example}}
{{#if moduleClasses}}

This module provides the following classes:

{{/if}}
{{#if subModules}}

This module is a rollup of the following modules:

{{/if}}
================================================ FILE: docs/technical/theme/partials/options.handlebars ================================================
Show:
================================================ FILE: docs/technical/theme/partials/props.handlebars ================================================ {{name}} {{#crossLink type}}{{/crossLink}} {{#if deprecated}} deprecated {{/if}} {{#if access}} {{access}} {{/if}} {{#if final}} final {{/if}} {{#if static}} static {{/if}}
{{{propertyDescription}}}
{{#if default}}

Default: {{default}}

{{/if}} {{#example}}

Example:

{{{.}}}
{{/example}} {{#if subprops}}

Sub-properties:

{{/if}} ================================================ FILE: docs/technical/theme/partials/sidebar.handlebars ================================================
================================================ FILE: docs/technical/theme/theme.json ================================================ { } ================================================ FILE: examples/nojquery/index.html ================================================ Tiny Colorpicker: A lightweight cross browser color picker.
================================================ FILE: examples/nojquery/tinycolorpicker.css ================================================ /* COLORPICKER 1 EXAMPLE */ #colorPicker { width: 30px; height: 30px; position: relative; clear: both; margin: 80px auto 20px; } #colorPicker .track { background: #EFEFEF url(images/text-color.png) no-repeat 50% 50%; height: 150px; width: 150px; padding: 10px; position: absolute; cursor: crosshair; float: left; left: -71px; top: -71px; display: none; border: 1px solid #ccc; z-index: 10; -webkit-border-radius: 150px; -moz-border-radius: 150px; border-radius: 150px; } #colorPicker .color { width: 25px; height: 25px; padding: 1px; border: 1px solid #ccc; display: block; position: relative; z-index: 11; background-color: #EFEFEF; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; cursor: pointer; } #colorPicker .colorInner { width: 25px; height: 25px; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; } #colorPicker .dropdown { list-style: none; display: none; width: 27px; position: absolute; top: 28px; border: 1px solid #ccc; left: 0; z-index: 1000; } #colorPicker .dropdown li{ height: 25px; cursor: pointer; } ================================================ FILE: examples/simple/index.html ================================================ Tiny Colorpicker: A lightweight cross browser color picker.
================================================ FILE: examples/simple/tinycolorpicker.css ================================================ /* COLORPICKER 1 EXAMPLE */ #colorPicker { width: 30px; height: 30px; position: relative; clear: both; margin: 80px auto 20px; } #colorPicker .track { background: #EFEFEF url(images/text-color.png) no-repeat 50% 50%; height: 150px; width: 150px; padding: 10px; position: absolute; cursor: crosshair; float: left; left: -71px; top: -71px; display: none; border: 1px solid #ccc; z-index: 10; -webkit-border-radius: 150px; -moz-border-radius: 150px; border-radius: 150px; } #colorPicker .color { width: 25px; height: 25px; padding: 1px; border: 1px solid #ccc; display: block; position: relative; z-index: 11; background-color: #EFEFEF; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; cursor: pointer; } #colorPicker .colorInner { width: 25px; height: 25px; -webkit-border-radius: 27px; -moz-border-radius: 27px; border-radius: 27px; } #colorPicker .dropdown { list-style: none; display: none; width: 27px; position: absolute; top: 28px; border: 1px solid #ccc; left: 0; z-index: 1000; } #colorPicker .dropdown li{ height: 25px; cursor: pointer; } ================================================ FILE: lib/jquery.tinycolorpicker.js ================================================ ;(function(factory) { if(typeof define === 'function' && define.amd) { define(['jquery'], factory); } else if(typeof exports === 'object') { module.exports = factory(require("jquery")); } else { factory(jQuery); } } (function($) { var pluginName = "tinycolorpicker" , defaults = { colors : ["#ffffff", "#A7194B","#FE2712","#FB9902","#FABC02","#FEFE33","#D0EA2B","#66B032","#0391CE","#0247FE","#3D01A5","#8601AF"] , backgroundUrl : null } ; function Plugin($container, options) { /** * The options of the colorpicker extended with the defaults. * * @property options * @type Object */ this.options = $.extend({}, defaults, options); /** * @property _defaults * @type Object * @private * @default defaults */ this._defaults = defaults; /** * @property _name * @type String * @private * @final * @default 'tinycolorpicker' */ this._name = pluginName; var self = this , $track = $container.find(".track") , $color = $container.find(".color") , $canvas = null , $colorInput = $container.find(".colorInput") , $dropdown = $container.find(".dropdown") , $dropdownItem = $dropdown.find("li").remove() , context = null , mouseIsDown = false , hasCanvas = !!document.createElement("canvas").getContext , touchEvents = "ontouchstart" in document.documentElement ; /** * The current active color in hex. * * @property colorHex * @type String * @default "" */ this.colorHex = ""; /** * The current active color in rgb. * * @property colorRGB * @type String * @default "" */ this.colorRGB = ""; /** * @method _initialize * @private */ function _initialize() { if(hasCanvas) { $canvas = $(""); $track.append($canvas); context = $canvas[0].getContext( "2d" ); _setImage(); } else { $.each(self.options.colors, function(index, color) { var $clone = $dropdownItem.clone(); $clone.css("backgroundColor", color); $clone.attr("data-color", color); $dropdown.append($clone); }); } _setEvents(); return self; } /** * @method _setImage * @private */ function _setImage() { var colorPicker = new Image() , backgroundUrl = $track.css("background-image").replace(/"/g, "").replace(/url\(|\)$/ig, "") ; colorPicker.crossOrigin = "Anonymous"; $track.css("background-image", "none"); $(colorPicker).load(function() { $canvas.attr("width", this.width); $canvas.attr("height", this.height); context.drawImage(colorPicker, 0, 0, this.width, this.height); }); colorPicker.src = self.options.backgroundUrl || backgroundUrl; } /** * @method _setEvents * @private */ function _setEvents() { var eventType = touchEvents ? "touchstart" : "mousedown"; if(hasCanvas) { $color.bind(eventType, function(event) { event.preventDefault(); event.stopPropagation(); $track.toggle(); $(document).bind("mousedown.colorpicker", function(event) { $(document).unbind(".colorpicker"); self.close(); }); }); if(!touchEvents) { $canvas.mousedown(function(event) { mouseIsDown = true; _getColorCanvas(event); $(document).bind("mouseup.colorpicker", function(event) { $(document).unbind(".colorpicker"); self.close(); return false; }); return false; }); $canvas.mousemove(_getColorCanvas); } else { $canvas.bind("touchstart", function(event) { mouseIsDown = true; _getColorCanvas(event.originalEvent.touches[0]); return false; }); $canvas.bind("touchmove", function(event) { _getColorCanvas(event.originalEvent.touches[0]); return false; }); $canvas.bind("touchend", function(event) { self.close(); return false; }); } } else { $color.bind("mousedown", function(event) { event.preventDefault(); event.stopPropagation(); $dropdown.toggle(); }); $dropdown.delegate("li", "mousedown", function(event) { event.preventDefault(); event.stopImmediatePropagation(); var color = $(this).attr("data-color"); self.setColor(color); $dropdown.hide(); }); } } /** * @method _getColorCanvas * @private */ function _getColorCanvas(event) { if(mouseIsDown) { var $target = $(event.target) , offset = $target.offset() , colorData = context.getImageData(event.pageX - offset.left, event.pageY - offset.top, 1, 1).data ; self.setColor("rgb(" + colorData[0] + "," + colorData[1] + "," + colorData[2] + ")"); /** * The change event will trigger when a new color is set. * * @event change */ $container.trigger("change", [self.colorHex, self.colorRGB]); } } /** * Set the color to a given hex or rgb color. * * @method setColor * @chainable */ this.setColor = function(color) { if(color.indexOf("#") >= 0) { self.colorHex = color; self.colorRGB = self.hexToRgb(self.colorHex); } else { self.colorRGB = color; self.colorHex = self.rgbToHex(self.colorRGB); } $color.find(".colorInner").css("backgroundColor", self.colorHex); $colorInput.val(self.colorHex); }; /** * Close the picker * * @method close * @chainable */ this.close = function() { mouseIsDown = false; $track.hide(); }; /** * Convert hex to rgb * * @method hexToRgb * @chainable */ this.hexToRgb = function(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return "rgb(" + parseInt(result[1], 16) + "," + parseInt(result[2], 16) + "," + parseInt(result[3], 16) + ")"; }; /** * Convert rgb to hex * * @method rgbToHex * @chainable */ this.rgbToHex = function(rgb) { var result = rgb.match(/\d+/g); function hex(x) { var digits = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"); return isNaN(x) ? "00" : digits[(x - x % 16 ) / 16] + digits[x % 16]; } return "#" + hex(result[0]) + hex(result[1]) + hex(result[2]); }; return _initialize(); } /** * @class tinycolorpicker * @constructor * @param {Object} options @param {Array} [options.colors=[]] fallback colors for old browsers (ie8-). @param {String} [options.backgroundUrl=''] It will look for a css image on the track div. If not found it will look if there's a url in this property. */ $.fn[pluginName] = function(options) { return this.each(function() { if(!$.data(this, "plugin_" + pluginName)) { $.data(this, "plugin_" + pluginName, new Plugin($(this), options)); } }); }; })); ================================================ FILE: lib/tinycolorpicker.js ================================================ ;(function(window, undefined) { "use strict"; function extend() { for(var i=1; i < arguments.length; i++) { for(var key in arguments[i]) { if(arguments[i].hasOwnProperty(key)) { arguments[0][key] = arguments[i][key]; } } } return arguments[0]; } var pluginName = "tinycolorpicker" , defaults = { backgroundUrl : null } ; function Plugin($container, options) { /** * The options of the colorpicker extended with the defaults. * * @property options * @type Object */ this.options = extend({}, defaults, options); /** * @property _defaults * @type Object * @private * @default defaults */ this._defaults = defaults; /** * @property _name * @type String * @private * @final * @default 'tinycolorpicker' */ this._name = pluginName; var self = this , $track = $container.querySelectorAll(".track")[0] , $color = $container.querySelectorAll(".color")[0] , $colorInner = $container.querySelectorAll(".colorInner")[0] , $canvas = null , $colorInput = $container.querySelectorAll(".colorInput")[0] , context = null , mouseIsDown = false , hasCanvas = !!document.createElement("canvas").getContext , touchEvents = "ontouchstart" in document.documentElement , changeEvent = document.createEvent("HTMLEvents") ; changeEvent.initEvent("change", true, true); /** * The current active color in hex. * * @property colorHex * @type String * @default "" */ this.colorHex = ""; /** * The current active color in rgb. * * @property colorRGB * @type String * @default "" */ this.colorRGB = ""; /** * @method _initialize * @private */ function _initialize() { if(hasCanvas) { $canvas = document.createElement("canvas"); $track.appendChild($canvas); context = $canvas.getContext("2d"); _setImage(); } _setEvents(); return self; } /** * @method _setImage * @private */ function _setImage() { var colorPicker = new Image() , style = $track.currentStyle || window.getComputedStyle($track, false) , backgroundUrl = style.backgroundImage.replace(/"/g, "").replace(/url\(|\)$/ig, "") ; colorPicker.crossOrigin = "Anonymous"; $track.style.backgroundImage = "none"; colorPicker.onload = function() { $canvas.width = this.width; $canvas.height = this.height; context.drawImage(colorPicker, 0, 0, this.width, this.height); }; colorPicker.src = self.options.backgroundUrl || backgroundUrl; } /** * @method _setEvents * @private */ function _setEvents() { var eventType = touchEvents ? "touchstart" : "mousedown"; if(hasCanvas) { $color["on" + eventType] = function(event) { event.preventDefault(); event.stopPropagation(); $track.style.display = 'block'; document.onmousedown = function(event) { document.onmousedown = null; self.close(); }; }; if(!touchEvents) { $canvas.onmousedown = function(event) { event.preventDefault(); event.stopPropagation(); mouseIsDown = true; _getColorCanvas(event); document.onmouseup = function(event) { document.onmouseup = null; self.close(); return false; }; }; $canvas.onmousemove = _getColorCanvas; } else { $canvas.ontouchstart = function(event) { mouseIsDown = true; _getColorCanvas(event.touches[0]); return false; }; $canvas.ontouchmove = function(event) { _getColorCanvas(event.touches[0]); return false; }; $canvas.ontouchend = function(event) { self.close(); return false; }; } } } /** * @method _getColorCanvas * @private */ function _getColorCanvas(event) { if(mouseIsDown) { var offset = event.target.getBoundingClientRect() , colorData = context.getImageData(event.clientX - offset.left, event.clientY - offset.top, 1, 1).data ; self.setColor("rgb(" + colorData[0] + "," + colorData[1] + "," + colorData[2] + ")"); $container.dispatchEvent(changeEvent, [self.colorHex, self.colorRGB]); } } /** * Set the color to a given hex or rgb color. * * @method setColor * @chainable */ this.setColor = function(color) { if(color.indexOf("#") >= 0) { self.colorHex = color; self.colorRGB = self.hexToRgb(self.colorHex); } else { self.colorRGB = color; self.colorHex = self.rgbToHex(self.colorRGB); } $colorInner.style.backgroundColor = self.colorHex; $colorInput.value = self.colorHex; }; /** * Close the picker * * @method close * @chainable */ this.close = function() { mouseIsDown = false; $track.style.display = 'none'; }; /** * Cobert hex to rgb * * @method hexToRgb * @chainable */ this.hexToRgb = function(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return "rgb(" + parseInt(result[1], 16) + "," + parseInt(result[2], 16) + "," + parseInt(result[3], 16) + ")"; }; /** * Cobert rgb to hex * * @method rgbToHex * @chainable */ this.rgbToHex = function(rgb) { var result = rgb.match(/\d+/g); function hex(x) { var digits = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"); return isNaN(x) ? "00" : digits[(x - x % 16 ) / 16] + digits[x % 16]; } return "#" + hex(result[0]) + hex(result[1]) + hex(result[2]); }; return _initialize(); } /** * @class window.tinycolorpicker * @constructor * @param {Object} $container * @param {Object} options @param {String} [options.backgroundUrl=''] It will look for a css image on the track div. If not found it will look if there's a url in this property. */ var tinycolorpicker = function($container, options) { return new Plugin($container, options); }; if(typeof define == 'function' && define.amd) { define(function(){ return tinycolorpicker; }); } else if(typeof module === 'object' && module.exports) { module.exports = tinycolorpicker; } else { window.tinycolorpicker = tinycolorpicker; } })(window); ================================================ FILE: package.json ================================================ { "name": "tinycolorpicker", "version": "0.9.5", "description": "A lightweight cross browser jQuery based colorpicker.", "homepage": "http://www.baijs.com/tinycolorpicker", "main": "lib/jquery.tinycolorpicker.js", "repository": { "type": "git", "url": "https://github.com/wieringen/tinycolorpicker.git" }, "keywords": [ "UI", "jQuery", "Mobile", "colorpicker", "javascript" ], "author": { "name": "Maarten Baijs", "email": "wieringen@gmail.com" }, "licenses": [ { "type": "MIT", "url": "https://github.com/wieringen/tinycolorpicker/blob/master/MIT-LICENSE.txt" } ], "bugs": { "url": "https://github.com/wieringen/tinycolorpicker/issues" }, "devDependencies": { "baijs": "latest", "chai": "~1.8.1", "coveralls": "^2.11.2", "grunt": "~0.4.1", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-compress": "~0.5.2", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "~0.8.0", "grunt-contrib-uglify": "~0.2.7", "grunt-contrib-yuidoc": "^0.6.0", "grunt-ftp-deploy": "~0.1.1", "grunt-karma": "0.8.0", "grunt-processhtml": "^0.3.6", "grunt-text-replace": "~0.3.9", "iectrl": "0.0.3", "karma": "~0.12.0", "karma-chai": "^0.1.0", "karma-chai-jquery": "^1.0.0", "karma-chai-sinon": "~0.1.0", "karma-chrome-launcher": "~0.1.1", "karma-coverage": "~0.1.3", "karma-firefox-launcher": "~0.1.2", "karma-html2js-preprocessor": "~0.1.0", "karma-htmlfile-reporter": "~0.1.0", "karma-ie-launcher": "~0.1.1", "karma-ievms": "0.0.4", "karma-jquery": "^0.1.0", "karma-junit-reporter": "~0.2.1", "karma-mocha": "~0.1.1", "karma-phantomjs-launcher": "~0.1.1", "karma-script-launcher": "~0.1.0", "mocha": "~1.15.1", "sinon": "~1.7.3", "sinon-chai": "~2.4.0" } } ================================================ FILE: test/conf/karma-all.js ================================================ var allConfig = require('./karma-common.js'); module.exports = function (config) { allConfig.browsers = [ 'Firefox', 'Chrome', 'IE9 - Win7', 'IE10 - Win7', 'IE11 - Win7' ]; allConfig.logLevel = config.LOG_INFO; config.set(allConfig); }; ================================================ FILE: test/conf/karma-ci.js ================================================ var ciConfig = require('./karma-common.js'); module.exports = function (config) { ciConfig.browsers = [ 'Firefox', 'Chrome', //'IE9 - Win7', //'IE10 - Win7', //'IE11 - Win7' ]; if (process.env.TRAVIS) { ciConfig.customLaunchers = { Chrome_travis_ci: { base: 'Chrome', flags: ['--no-sandbox'] } }; ciConfig.browsers = ['Firefox', 'Chrome_travis_ci']; } ciConfig.singleRun = true; ciConfig.reporters.push('junit'); ciConfig.junitReporter = { outputFile: 'dist/reports/test-report.xml' }; //ciConfig.coverageReporter.type = 'cobertura'; ciConfig.logLevel = config.LOG_INFO; config.set(ciConfig); }; ================================================ FILE: test/conf/karma-common.js ================================================ module.exports = { // base path, that will be used to resolve files and exclude basePath: '../../', frameworks: [ 'mocha', 'chai-sinon', 'jquery-1.8.3' ], client: { mocha: { ui: 'bdd' } }, // list of files / patterns to load in the browser files: [ 'lib/tinycolorpicker.js', 'lib/jquery.tinycolorpicker.js', 'test/unit/tinycolorpicker.spec.js', 'test/unit/jquery.tinycolorpicker.spec.js', { pattern: 'test/fixtures/**/*.html', included: true } ], // list of files to exclude exclude: [], preprocessors: { 'lib/*.js': ['coverage'], 'test/fixtures/**/*.html': ['html2js'] }, // use dots reporter, as travis terminal does not support escaping sequences // possible values: 'dots', 'progress', 'junit' // CLI --reporters progress reporters: [ 'dots', 'html', 'coverage' ], coverageReporter: { type: 'lcov', dir: 'dist/reports/coverage/' }, htmlReporter: { outputFile: 'dist/reports/test-report.html' }, // web server port // CLI --port 9876 port: 9876, // cli runner port // CLI --runner-port 9100 runnerPort: 9100, // enable / disable colors in the output (reporters and logs) // CLI --colors --no-colors colors: true, // level of logging // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG // CLI --log-level debug // logLevel: config.LOG_ERROR, // enable / disable watching file and executing tests whenever any file changes // CLI --auto-watch --no-auto-watch autoWatch: true, // Start these browsers, currently available: // - Chrome // - ChromeCanary // - Firefox // - Opera // - Safari (only Mac) // - PhantomJS // - IE (only Windows) // CLI --browsers Chrome,Firefox,Safari browsers: [ 'Firefox', 'Chrome' ], // If browser does not capture in given timeout [ms], kill it // CLI --capture-timeout 5000 captureTimeout: 15000, // Auto run tests on start (when browsers are captured) and exit // CLI --single-run --no-single-run singleRun: false, // report which specs are slower than 500ms // CLI --report-slower-than 500 reportSlowerThan: 500, //proxies: {} plugins: [ 'karma-mocha', 'karma-jquery', 'karma-chai-sinon', 'karma-ie-launcher', 'karma-chrome-launcher', 'karma-firefox-launcher', 'karma-phantomjs-launcher', 'karma-html2js-preprocessor', 'karma-coverage', 'karma-junit-reporter', 'karma-htmlfile-reporter', 'karma-ievms' ] }; ================================================ FILE: test/conf/karma-debug.js ================================================ var debugConfig = require('./karma-common.js'); module.exports = function (config) { debugConfig.browsers = [ 'Chrome' ]; debugConfig.logLevel = config.LOG_DEBUG; config.set(debugConfig); }; ================================================ FILE: test/conf/karma-dev.js ================================================ var devConfig = require('./karma-common.js'); module.exports = function (config) { devConfig.browsers = [ 'Chrome' ]; devConfig.singleRun = true; devConfig.logLevel = config.LOG_INFO; config.set(devConfig); }; ================================================ FILE: test/fixtures/tinycolorpicker-css.html ================================================ ================================================ FILE: test/fixtures/tinycolorpicker.html ================================================
================================================ FILE: test/unit/jquery.tinycolorpicker.spec.js ================================================ describe('A single Tinycolorpicker', function() { before(function () { document.head.innerHTML = __html__['test/fixtures/tinycolorpicker-css.html']; }); beforeEach(function () { document.body.innerHTML = __html__['test/fixtures/tinycolorpicker.html']; }); afterEach(function () { document.body.innerHTML = ''; }); it('should have a chainable constructor', function() { $('#colorPicker').tinycolorpicker().addClass('testing'); expect($('#colorPicker').hasClass('testing')).to.equal(true); }); it('should have a accessible instance', function() { var instance = $('#colorPicker').tinycolorpicker().data('plugin_tinycolorpicker'); expect(instance).to.be.a('object'); expect(instance._name).to.equal('tinycolorpicker'); }); it('should be able to be set to a specific hex color.', function() { var instance = $('#colorPicker').tinycolorpicker().data('plugin_tinycolorpicker'); instance.setColor('#FF0000'); expect(instance.colorHex).to.equal('#FF0000'); expect(instance.colorRGB).to.equal('rgb(255,0,0)'); }); it('should be able to be set to a specific rgb color.', function() { var instance = $('#colorPicker').tinycolorpicker().data('plugin_tinycolorpicker'); instance.setColor('rgb(255,0,0)'); expect(instance.colorHex).to.equal('#FF0000'); expect(instance.colorRGB).to.equal('rgb(255,0,0)'); }); it('should be able to convert a hex color to rgb color.', function() { var instance = $('#colorPicker').tinycolorpicker().data('plugin_tinycolorpicker'); expect(instance.hexToRgb('#FF0000')).to.equal('rgb(255,0,0)'); }); it('should be able to convert a rgb color to hex color.', function() { var instance = $('#colorPicker').tinycolorpicker().data('plugin_tinycolorpicker'); expect(instance.rgbToHex('rgb(255,0,0)')).to.equal('#FF0000'); }); }); ================================================ FILE: test/unit/tinycolorpicker.spec.js ================================================ describe('A single Tinycolorpicker', function() { before(function () { document.head.innerHTML = __html__['test/fixtures/tinycolorpicker-css.html']; }); beforeEach(function () { document.body.innerHTML = __html__['test/fixtures/tinycolorpicker.html']; }); afterEach(function () { document.body.innerHTML = ''; }); it('should have a accessible instance', function() { var instance = tinycolorpicker(document.getElementById("colorPicker")); expect(instance).to.be.a('object'); expect(instance._name).to.equal('tinycolorpicker'); }); it('should be able to be set to a specific hex color.', function() { var instance = tinycolorpicker(document.getElementById("colorPicker")); instance.setColor('#FF0000'); expect(instance.colorHex).to.equal('#FF0000'); expect(instance.colorRGB).to.equal('rgb(255,0,0)'); }); it('should be able to be set to a specific rgb color.', function() { var instance = tinycolorpicker(document.getElementById("colorPicker")); instance.setColor('rgb(255,0,0)'); expect(instance.colorHex).to.equal('#FF0000'); expect(instance.colorRGB).to.equal('rgb(255,0,0)'); }); it('should be able to convert a hex color to rgb color.', function() { var instance = tinycolorpicker(document.getElementById("colorPicker")); expect(instance.hexToRgb('#FF0000')).to.equal('rgb(255,0,0)'); }); it('should be able to convert a rgb color to hex color.', function() { var instance = tinycolorpicker(document.getElementById("colorPicker")); expect(instance.rgbToHex('rgb(255,0,0)')).to.equal('#FF0000'); }); }); ================================================ FILE: tinycolorpicker.jquery.json ================================================ { "name": "tinycolorpicker", "title": "Tiny Colorpicker", "version": "0.9.5", "description": "A lightweight cross browser jQuery based colorpicker.", "homepage": "http://www.baijs.com/tinycolorpicker", "repository": { "type": "git", "url": "https://github.com/wieringen/tinycolorpicker.git" }, "keywords": [ "UI", "jQuery", "Mobile", "colors", "colorpicker", "javascript" ], "author": { "name": "Maarten Baijs", "email": "wieringen@gmail.com" }, "licenses": [ { "type": "MIT", "url": "https://github.com/wieringen/tinycolorpicker/blob/master/MIT-LICENSE.txt" } ], "bugs": "https://github.com/wieringen/tinycolorpicker/issues", "download": "http://baijs.com/tinycolorpicker/", "demo" : "http://baijs.com/tinycolorpicker/", "docs" : "http://baijs.com/tinycolorpicker/", "dependencies": { "jquery": ">=1.5" } }