Permalink
Browse files

Fix color picker

  • Loading branch information...
1 parent e71cf82 commit e417dfcf9e5c1a8648b190f619312c68bd2b20e0 @uxder uxder committed Mar 2, 2012
Showing with 36 additions and 31 deletions.
  1. +1 −1 index.html
  2. +31 −30 javascript/javascript.js
  3. +4 −0 javascript/jquery-1.7.1.min.js
View
@@ -11,7 +11,7 @@
<script>if (((navigator.plugins && typeof navigator.plugins['Shockwave Flash'] == 'object') || (window.ActiveXObject && (new ActiveXObject('ShockwaveFlash.ShockwaveFlash')))) && location.protocol != 'file:') document.documentElement.className = 'flash';</script>
<!-- its only up here because the js does syntax highlighting so i want the js loaded before the page loads. bad practice i know... -->
-<script src="javascript/jquery-1.4.2.js"></script>
+<script src="javascript/jquery-1.7.1.min.js"></script>
<script src="javascript/jquery.plugins.min.js"></script>
<script src="javascript/javascript.js"></script>
<script src="javascript/cb_plugins.js"></script>
View
@@ -557,42 +557,43 @@ $(document).ready(function () {
}
//create colorpicker
- //colorPicker.load("b[i='s2Hex']", 'hex');
+ colorPicker("b[i='s2Hex']", 'hex');
});
$(window).load(function(){
setTimeout(copypasta,1000);
})
-window.colorPicker = {
- _currentTarget: "",
- _colors: {},
- load: function(selector, colorType) {
- var cp = this;
- $(selector).ColorPicker({
- onBeforeShow: function () {
- var span = $(this),
- text = span.text();
-
- cp._currentTarget = span; //workaround to colorpicker plugin not preseving current element?
- span.ColorPickerSetColor(text); //set the colorpicker value
- },
- onChange: function (hsb, hex, rgb) {
- cp._colors = {
- hsl: hsb,
- hex: hex,
- rgb: rgb
- };
- },
- onHide: function(){
- //update the colors
- var input = cp._currentTarget.find('input');
- input.val("#" + cp._colors[colorType]);
- generator.grabAndSet(input[0]);
- }
- });
- }
-}
+window.colorPicker = (function(){
+ var currentTarget = "",
+ colors = {},
+ currentColor,
+ picker = function(selector, colorType) {
+ $(selector).ColorPicker({
+ onBeforeShow: function () {
+ var t = $(this);
+ colors = {}; //reset colors
+ currentColor = t.text();
+ currentTarget = t; //workaround to colorpicker plugin not preseving current element?
+ t.ColorPickerSetColor(currentColor); //set the colorpicker value
+ },
+ onChange: function (hsb, hex, rgb) {
+ colors = {
+ hsl: hsb,
+ hex: hex,
+ rgb: rgb
+ };
+ //update the colors
+ var input = currentTarget.find('input'),
+ color = (colors[colorType]) ? "#" + colors[colorType] : currentColor;
+ input.val(color);
+ generator.grabAndSet(input[0]);
+ }
+ });
+ }
+
+ return picker;
+})();
window.css = {
Oops, something went wrong.

0 comments on commit e417dfc

Please sign in to comment.