Introduction
Example
Download
Documentation
Contact

Introduction

The SVG Colour Palette (SVGCP) was created to easily deploy a colour selection palette without requiring an accompanying image. The SVGCP palette can be inserted through a few chunks of code. It is very modular. Simply place the SVG palette code where you wish as well as the accompanying header files. It will appear by calling the javascript function PL.openPl with which you pass the function you wish to be called when the user selects a colour.

Example

Click the icon to make the SVG Colour Palette appear:

Download

Download the zip file containing everything you need:

  • svgpal/
    • example.html
    • pal.css
    • pal.js
    • palicon.png
    • svg.js
    • svgpal_snip.txt

Documentation

Installation

To insert the SVGCP you need to do the following:

  1. Include the 3 header files. The Google svgweb plugin, SVGCP javascript, and css for the palette.

    <script src="svgpal/svg.js"></script>
    <script src="svgpal/pal.js"></script>
    <link rel='stylesheet' type='text/css' href='svgpal/pal.css'>
  2. Insert the SVG palette code. You can be simple or fancy when doing this. Using the z-index property you can overlay the SVGCP anywhere. The contents are in the svgpal_snip.txt file as well as in the example html file in the download package.

    <!-- COPY FROM HERE FOR SVG PALETTE -->
    <div id='svgpalPkg'>
     <script type="image/svg+xml">
      <svg id='svgpal' width="220" height="200">
       <defs>
        <linearGradient id="bw-grad" x1="0%" y1="0%" x2="100%" y2="0%">
         <stop offset="0%" style="stop-color:rgb(255,255,255); stop-opacity:1"/>
         <stop offset="50%" style="stop-color:rgb(255,255,255); stop-opacity:0"/>
         <stop offset="100%" style="stop-color:rgb(0,0,0); stop-opacity:1"/>
        </linearGradient>
        <linearGradient id="bk-grad" x1="0%" y1="0%" x2="0%" y2="100%">
         <stop offset="0%" style="stop-color:rgb(0,0,0)"/>
         <stop offset="100%" style="stop-color:rgb(255,255,255)"/>
        </linearGradient>
        <linearGradient id="rnbw-grad" x1="0%" y1="0%" x2="0%" y2="100%">
         <stop offset="0%" style="stop-color:rgb(255,0,0); stop-opacity:1"/>
         <stop offset="17%" style="stop-color:rgb(255,255,0); stop-opacity:1"/>
         <stop offset="33%" style="stop-color:rgb(0,255,0); stop-opacity:1"/>
         <stop offset="50%" style="stop-color:rgb(0,255,255); stop-opacity:1"/>
         <stop offset="66%" style="stop-color:rgb(0,0,255); stop-opacity:1"/>
         <stop offset="83%" style="stop-color:rgb(255,0,255); stop-opacity:1"/>
         <stop offset="100%" style="stop-color:rgb(255,0,0); stop-opacity:1"/>
        </linearGradient>
       </defs>
       <rect x='0' y='0' width='200' height='200' style='fill:url(#rnbw-grad)' />
       <rect x='0' y='0' width='200' height='200' style='fill:url(#bw-grad)' />
       <rect x='200' y='0' width='21' height='200' style='fill:url(#bk-grad)' />
      </svg>
     </script>
    </div>
    <!-- COPY UP TO HERE FOR SVG PALETTE -->
    
  3. Insert the onclick call to the PL.openPl(somefunction) function in the item that will reveal the SVGCP and the function to which to pass the hex 6 character colour value to. I use the icon included for a palette link that on being clicked will make appear the SVG Palette. We wish the colour selected to be passed to the changeBG function:

    <img src='svgpal/palicon.png' onclick='javascript:PL.openPl(changeBG)'/>

Voila! Done.

Browsers

Works in Firefox, Safari and Chrome.I haven't tried IE yet.

Versioning

V1.0
----
Know issues: none

Licence

Copyright (c) 2010 Cyrille Médard de Chardon

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.

Contact

Questions or Comments?

Get in touch with me:

Cyrille Médard de Chardon

cyrillem@gmail.com