Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: farbtastic.js
/*!
[0] Fix | Delete
* Farbtastic: jQuery color picker plug-in v1.3u
[1] Fix | Delete
*
[2] Fix | Delete
* Licensed under the GPL license:
[3] Fix | Delete
* http://www.gnu.org/licenses/gpl.html
[4] Fix | Delete
*/
[5] Fix | Delete
(function($) {
[6] Fix | Delete
[7] Fix | Delete
$.fn.farbtastic = function (options) {
[8] Fix | Delete
$.farbtastic(this, options);
[9] Fix | Delete
return this;
[10] Fix | Delete
};
[11] Fix | Delete
[12] Fix | Delete
$.farbtastic = function (container, callback) {
[13] Fix | Delete
var container = $(container).get(0);
[14] Fix | Delete
return container.farbtastic || (container.farbtastic = new $._farbtastic(container, callback));
[15] Fix | Delete
};
[16] Fix | Delete
[17] Fix | Delete
$._farbtastic = function (container, callback) {
[18] Fix | Delete
// Store farbtastic object
[19] Fix | Delete
var fb = this;
[20] Fix | Delete
[21] Fix | Delete
// Insert markup
[22] Fix | Delete
$(container).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');
[23] Fix | Delete
var e = $('.farbtastic', container);
[24] Fix | Delete
fb.wheel = $('.wheel', container).get(0);
[25] Fix | Delete
// Dimensions
[26] Fix | Delete
fb.radius = 84;
[27] Fix | Delete
fb.square = 100;
[28] Fix | Delete
fb.width = 194;
[29] Fix | Delete
[30] Fix | Delete
// Fix background PNGs in IE6
[31] Fix | Delete
if (navigator.appVersion.match(/MSIE [0-6]\./)) {
[32] Fix | Delete
$('*', e).each(function () {
[33] Fix | Delete
if (this.currentStyle.backgroundImage != 'none') {
[34] Fix | Delete
var image = this.currentStyle.backgroundImage;
[35] Fix | Delete
image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
[36] Fix | Delete
$(this).css({
[37] Fix | Delete
'backgroundImage': 'none',
[38] Fix | Delete
'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
[39] Fix | Delete
});
[40] Fix | Delete
}
[41] Fix | Delete
});
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Link to the given element(s) or callback.
[46] Fix | Delete
*/
[47] Fix | Delete
fb.linkTo = function (callback) {
[48] Fix | Delete
// Unbind previous nodes
[49] Fix | Delete
if (typeof fb.callback == 'object') {
[50] Fix | Delete
$(fb.callback).unbind('keyup', fb.updateValue);
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
// Reset color
[54] Fix | Delete
fb.color = null;
[55] Fix | Delete
[56] Fix | Delete
// Bind callback or elements
[57] Fix | Delete
if (typeof callback == 'function') {
[58] Fix | Delete
fb.callback = callback;
[59] Fix | Delete
}
[60] Fix | Delete
else if (typeof callback == 'object' || typeof callback == 'string') {
[61] Fix | Delete
fb.callback = $(callback);
[62] Fix | Delete
fb.callback.bind('keyup', fb.updateValue);
[63] Fix | Delete
if (fb.callback.get(0).value) {
[64] Fix | Delete
fb.setColor(fb.callback.get(0).value);
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
return this;
[68] Fix | Delete
};
[69] Fix | Delete
fb.updateValue = function (event) {
[70] Fix | Delete
if (this.value && this.value != fb.color) {
[71] Fix | Delete
fb.setColor(this.value);
[72] Fix | Delete
}
[73] Fix | Delete
};
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Change color with HTML syntax #123456
[77] Fix | Delete
*/
[78] Fix | Delete
fb.setColor = function (color) {
[79] Fix | Delete
var unpack = fb.unpack(color);
[80] Fix | Delete
if (fb.color != color && unpack) {
[81] Fix | Delete
fb.color = color;
[82] Fix | Delete
fb.rgb = unpack;
[83] Fix | Delete
fb.hsl = fb.RGBToHSL(fb.rgb);
[84] Fix | Delete
fb.updateDisplay();
[85] Fix | Delete
}
[86] Fix | Delete
return this;
[87] Fix | Delete
};
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Change color with HSL triplet [0..1, 0..1, 0..1]
[91] Fix | Delete
*/
[92] Fix | Delete
fb.setHSL = function (hsl) {
[93] Fix | Delete
fb.hsl = hsl;
[94] Fix | Delete
fb.rgb = fb.HSLToRGB(hsl);
[95] Fix | Delete
fb.color = fb.pack(fb.rgb);
[96] Fix | Delete
fb.updateDisplay();
[97] Fix | Delete
return this;
[98] Fix | Delete
};
[99] Fix | Delete
[100] Fix | Delete
/////////////////////////////////////////////////////
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Retrieve the coordinates of the given event relative to the center
[104] Fix | Delete
* of the widget.
[105] Fix | Delete
*/
[106] Fix | Delete
fb.widgetCoords = function (event) {
[107] Fix | Delete
var offset = $(fb.wheel).offset();
[108] Fix | Delete
return { x: (event.pageX - offset.left) - fb.width / 2, y: (event.pageY - offset.top) - fb.width / 2 };
[109] Fix | Delete
};
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Mousedown handler
[113] Fix | Delete
*/
[114] Fix | Delete
fb.mousedown = function (event) {
[115] Fix | Delete
// Capture mouse
[116] Fix | Delete
if (!document.dragging) {
[117] Fix | Delete
$(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup);
[118] Fix | Delete
document.dragging = true;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// Check which area is being dragged
[122] Fix | Delete
var pos = fb.widgetCoords(event);
[123] Fix | Delete
fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square;
[124] Fix | Delete
[125] Fix | Delete
// Process
[126] Fix | Delete
fb.mousemove(event);
[127] Fix | Delete
return false;
[128] Fix | Delete
};
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Mousemove handler
[132] Fix | Delete
*/
[133] Fix | Delete
fb.mousemove = function (event) {
[134] Fix | Delete
// Get coordinates relative to color picker center
[135] Fix | Delete
var pos = fb.widgetCoords(event);
[136] Fix | Delete
[137] Fix | Delete
// Set new HSL parameters
[138] Fix | Delete
if (fb.circleDrag) {
[139] Fix | Delete
var hue = Math.atan2(pos.x, -pos.y) / 6.28;
[140] Fix | Delete
if (hue < 0) hue += 1;
[141] Fix | Delete
fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]);
[142] Fix | Delete
}
[143] Fix | Delete
else {
[144] Fix | Delete
var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5));
[145] Fix | Delete
var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5));
[146] Fix | Delete
fb.setHSL([fb.hsl[0], sat, lum]);
[147] Fix | Delete
}
[148] Fix | Delete
return false;
[149] Fix | Delete
};
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Mouseup handler
[153] Fix | Delete
*/
[154] Fix | Delete
fb.mouseup = function () {
[155] Fix | Delete
// Uncapture mouse
[156] Fix | Delete
$(document).unbind('mousemove', fb.mousemove);
[157] Fix | Delete
$(document).unbind('mouseup', fb.mouseup);
[158] Fix | Delete
document.dragging = false;
[159] Fix | Delete
};
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Update the markers and styles
[163] Fix | Delete
*/
[164] Fix | Delete
fb.updateDisplay = function () {
[165] Fix | Delete
// Markers
[166] Fix | Delete
var angle = fb.hsl[0] * 6.28;
[167] Fix | Delete
$('.h-marker', e).css({
[168] Fix | Delete
left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px',
[169] Fix | Delete
top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px'
[170] Fix | Delete
});
[171] Fix | Delete
[172] Fix | Delete
$('.sl-marker', e).css({
[173] Fix | Delete
left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px',
[174] Fix | Delete
top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px'
[175] Fix | Delete
});
[176] Fix | Delete
[177] Fix | Delete
// Saturation/Luminance gradient
[178] Fix | Delete
$('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5])));
[179] Fix | Delete
[180] Fix | Delete
// Linked elements or callback
[181] Fix | Delete
if (typeof fb.callback == 'object') {
[182] Fix | Delete
// Set background/foreground color
[183] Fix | Delete
$(fb.callback).css({
[184] Fix | Delete
backgroundColor: fb.color,
[185] Fix | Delete
color: fb.hsl[2] > 0.5 ? '#000' : '#fff'
[186] Fix | Delete
});
[187] Fix | Delete
[188] Fix | Delete
// Change linked value
[189] Fix | Delete
$(fb.callback).each(function() {
[190] Fix | Delete
if (this.value && this.value != fb.color) {
[191] Fix | Delete
this.value = fb.color;
[192] Fix | Delete
}
[193] Fix | Delete
});
[194] Fix | Delete
}
[195] Fix | Delete
else if (typeof fb.callback == 'function') {
[196] Fix | Delete
fb.callback.call(fb, fb.color);
[197] Fix | Delete
}
[198] Fix | Delete
};
[199] Fix | Delete
[200] Fix | Delete
/* Various color utility functions */
[201] Fix | Delete
fb.pack = function (rgb) {
[202] Fix | Delete
var r = Math.round(rgb[0] * 255);
[203] Fix | Delete
var g = Math.round(rgb[1] * 255);
[204] Fix | Delete
var b = Math.round(rgb[2] * 255);
[205] Fix | Delete
return '#' + (r < 16 ? '0' : '') + r.toString(16) +
[206] Fix | Delete
(g < 16 ? '0' : '') + g.toString(16) +
[207] Fix | Delete
(b < 16 ? '0' : '') + b.toString(16);
[208] Fix | Delete
};
[209] Fix | Delete
[210] Fix | Delete
fb.unpack = function (color) {
[211] Fix | Delete
if (color.length == 7) {
[212] Fix | Delete
return [parseInt('0x' + color.substring(1, 3)) / 255,
[213] Fix | Delete
parseInt('0x' + color.substring(3, 5)) / 255,
[214] Fix | Delete
parseInt('0x' + color.substring(5, 7)) / 255];
[215] Fix | Delete
}
[216] Fix | Delete
else if (color.length == 4) {
[217] Fix | Delete
return [parseInt('0x' + color.substring(1, 2)) / 15,
[218] Fix | Delete
parseInt('0x' + color.substring(2, 3)) / 15,
[219] Fix | Delete
parseInt('0x' + color.substring(3, 4)) / 15];
[220] Fix | Delete
}
[221] Fix | Delete
};
[222] Fix | Delete
[223] Fix | Delete
fb.HSLToRGB = function (hsl) {
[224] Fix | Delete
var m1, m2, r, g, b;
[225] Fix | Delete
var h = hsl[0], s = hsl[1], l = hsl[2];
[226] Fix | Delete
m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s;
[227] Fix | Delete
m1 = l * 2 - m2;
[228] Fix | Delete
return [this.hueToRGB(m1, m2, h+0.33333),
[229] Fix | Delete
this.hueToRGB(m1, m2, h),
[230] Fix | Delete
this.hueToRGB(m1, m2, h-0.33333)];
[231] Fix | Delete
};
[232] Fix | Delete
[233] Fix | Delete
fb.hueToRGB = function (m1, m2, h) {
[234] Fix | Delete
h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
[235] Fix | Delete
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
[236] Fix | Delete
if (h * 2 < 1) return m2;
[237] Fix | Delete
if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
[238] Fix | Delete
return m1;
[239] Fix | Delete
};
[240] Fix | Delete
[241] Fix | Delete
fb.RGBToHSL = function (rgb) {
[242] Fix | Delete
var min, max, delta, h, s, l;
[243] Fix | Delete
var r = rgb[0], g = rgb[1], b = rgb[2];
[244] Fix | Delete
min = Math.min(r, Math.min(g, b));
[245] Fix | Delete
max = Math.max(r, Math.max(g, b));
[246] Fix | Delete
delta = max - min;
[247] Fix | Delete
l = (min + max) / 2;
[248] Fix | Delete
s = 0;
[249] Fix | Delete
if (l > 0 && l < 1) {
[250] Fix | Delete
s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
[251] Fix | Delete
}
[252] Fix | Delete
h = 0;
[253] Fix | Delete
if (delta > 0) {
[254] Fix | Delete
if (max == r && max != g) h += (g - b) / delta;
[255] Fix | Delete
if (max == g && max != b) h += (2 + (b - r) / delta);
[256] Fix | Delete
if (max == b && max != r) h += (4 + (r - g) / delta);
[257] Fix | Delete
h /= 6;
[258] Fix | Delete
}
[259] Fix | Delete
return [h, s, l];
[260] Fix | Delete
};
[261] Fix | Delete
[262] Fix | Delete
// Install mousedown handler (the others are set on the document on-demand)
[263] Fix | Delete
$('*', e).mousedown(fb.mousedown);
[264] Fix | Delete
[265] Fix | Delete
// Init color
[266] Fix | Delete
fb.setColor('#000000');
[267] Fix | Delete
[268] Fix | Delete
// Set linked elements/callback
[269] Fix | Delete
if (callback) {
[270] Fix | Delete
fb.linkTo(callback);
[271] Fix | Delete
}
[272] Fix | Delete
};
[273] Fix | Delete
[274] Fix | Delete
})(jQuery);
[275] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function