Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions jquery.simplecolorpicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,13 @@
.simplecolorpicker span.vr {
border-left: 1px solid #222; /* @gray-dark */
}

.simplecolorpicker input[type="color"] {
width: 0;
height: 0;
padding: 0;
border: 0;
visibility: hidden;
}

.simplecolorpicker .custom-container { text-align: right; }
35 changes: 32 additions & 3 deletions jquery.simplecolorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@
+ role + '>'
+ '</span>');

self.$colorList.append($colorSpan);
$colorSpan.on('click.' + self.type, $.proxy(self.colorSpanClicked, self));
if($option.data('is-user-defined') == undefined) {
self.$colorList.append($colorSpan);
$colorSpan.on('click.' + self.type, $.proxy(self.colorSpanClicked, self));
} else
self.setupCustomColorSelector($colorSpan);

var $next = $option.next();
if ($next.is('optgroup') === true) {
Expand Down Expand Up @@ -173,6 +176,29 @@
}
},

setupCustomColorSelector: function(colorSpan) {
var customColorContainer = $('<div class="custom-container">' + this.options.customString + '&nbsp;</div>');
customColorContainer.append(colorSpan);
var $userColorSelector = $('<input type="color" value="' + colorSpan.data('color') + '" />');
customColorContainer.append($userColorSelector);
this.$colorList.append(customColorContainer);
$userColorSelector.on('change.' + this.type, $.proxy(this.userColorSelected, this));
colorSpan.on('click.' + this.type, function(e) { $(e.target).next().trigger('click') });
},

/**
* The user selected custom color
*/
userColorSelected: function(e) {
var colorPicker = $(e.target);
var userColor = colorPicker.val();
var colorSpan = colorPicker.prev();
colorSpan.data('color', userColor);
this.$select.find('option[data-is-user-defined]').val(userColor);
var clickEvt = jQuery.Event('click', {target: colorSpan});
this.colorSpanClicked.call(this, clickEvt);
},

/**
* Prevents the mousedown event from "eating" the click event.
*/
Expand Down Expand Up @@ -229,7 +255,10 @@
picker: false,

// Animation delay in milliseconds
pickerDelay: 0
pickerDelay: 0,

// Custom color prompt
customString: "Select color:"
};

})(jQuery);