Skip to content

Commit

Permalink
Fix color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
uxder committed Mar 2, 2012
1 parent e71cf82 commit e417dfc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
61 changes: 31 additions & 30 deletions javascript/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading

0 comments on commit e417dfc

Please sign in to comment.