Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit b98242cec89ba7ace1ddcebad76476ccd2fe6d24 0 parents
Scott Gonzalez authored
Showing with 116 additions and 0 deletions.
  1. +14 −0 jquery.nmk.colorswatch.css
  2. +102 −0 jquery.nmk.colorswatch.js
14 jquery.nmk.colorswatch.css
@@ -0,0 +1,14 @@
+.nmk-colorswatch {
+ border: 1px solid #000;
+ float: left;
+ position: absolute;
+}
+.nmk-colorswatch-row {
+ clear: both;
+}
+.nmk-colorswatch-color {
+ width: 16px;
+ height: 16px;
+ float: left;
+ margin: 2px;
+}
102 jquery.nmk.colorswatch.js
@@ -0,0 +1,102 @@
+(function($) {
+
+$.widget('nmk.colorswatch', {
+ isInput: false,
+
+ _init: function() {
+ this.swatch = (this.element.is(':input') ? this._initFromInput() : this.element)
+ .addClass('nmk-colorswatch');
+
+ this._render();
+ },
+
+ _initFromInput: function() {
+ this.isInput = true;
+
+ if (this.options.value === null) {
+ this.options.value = this.element.val();
+ }
+
+ var self = this;
+ this.element.click(function() {
+ self.show();
+ });
+
+ return $('<div></div>')
+ .hide()
+ .insertAfter(this.element);
+ },
+
+ _render: function() {
+ var row,
+ rowSize = this.options.rowSize,
+ swatch = this.swatch.empty();
+
+ $.each(this.options.colors, function(i, color) {
+ if (!(i % rowSize)) {
+ row = $('<div></div>')
+ .addClass('nmk-colorswatch-row')
+ .appendTo(swatch);
+ }
+
+ $('<div></div>')
+ .addClass('nmk-colorswatch-color')
+ .css('backgroundColor', color)
+ .data('colorswatch-color', color)
+ .appendTo(row);
+ });
+ },
+
+ show: function() {
+ this.swatch.show();
+ }
+});
+
+$.extend($.nmk.colorswatch, {
+ version: '1.0pre',
+ defaults: {
+ colors: [
+ '#000000',
+ '#993300',
+ '#333300',
+ '#000080',
+ '#333399',
+ '#333333',
+ '#800000',
+ '#FF6600',
+ '#808000',
+ '#008000',
+ '#008080',
+ '#0000FF',
+ '#666699',
+ '#808080',
+ '#FF0000',
+ '#FF9900',
+ '#99CC00',
+ '#339966',
+ '#33CCCC',
+ '#3366FF',
+ '#800080',
+ '#999999',
+ '#FF00FF',
+ '#FFCC00',
+ '#FFFF00',
+ '#00FF00',
+ '#00FFFF',
+ '#00CCFF',
+ '#993366',
+ '#C0C0C0',
+ '#FF99CC',
+ '#FFCC99',
+ '#FFFF99',
+ '#CCFFFF',
+ '#99CCFF',
+ '#FFFFFF'
+ ],
+ rowSize: 6,
+ value: null
+ }
+});
+
+})(jQuery);
+
Please sign in to comment.
Something went wrong with that request. Please try again.