X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/a5227bf01edbe6660486c9f5c0f0ed7b7fea3130..f9001779751f83dc8a10e478bfecb4d8dd5f964c:/wp-admin/js/farbtastic.js diff --git a/wp-admin/js/farbtastic.js b/wp-admin/js/farbtastic.js index 9399d0c7..5404fb6e 100644 --- a/wp-admin/js/farbtastic.js +++ b/wp-admin/js/farbtastic.js @@ -1,26 +1,29 @@ -// $Id: farbtastic.js,v 1.2 2007/01/08 22:53:01 unconed Exp $ -// Farbtastic 1.2 - -var farbtastic_click = false; - -jQuery.fn.farbtastic = function (callback) { - jQuery.farbtastic(this, callback); +/*! + * Farbtastic: jQuery color picker plug-in v1.3u + * + * Licensed under the GPL license: + * http://www.gnu.org/licenses/gpl.html + */ +(function($) { + +$.fn.farbtastic = function (options) { + $.farbtastic(this, options); return this; }; -jQuery.farbtastic = function (container, callback) { - var container = jQuery(container).get(0); - return container.farbtastic || (container.farbtastic = new jQuery._farbtastic(container, callback)); -} +$.farbtastic = function (container, callback) { + var container = $(container).get(0); + return container.farbtastic || (container.farbtastic = new $._farbtastic(container, callback)); +}; -jQuery._farbtastic = function (container, callback) { +$._farbtastic = function (container, callback) { // Store farbtastic object var fb = this; // Insert markup - jQuery(container).html('
'); - var e = jQuery('.farbtastic', container); - fb.wheel = jQuery('.wheel', container).get(0); + $(container).html('
'); + var e = $('.farbtastic', container); + fb.wheel = $('.wheel', container).get(0); // Dimensions fb.radius = 84; fb.square = 100; @@ -28,11 +31,11 @@ jQuery._farbtastic = function (container, callback) { // Fix background PNGs in IE6 if (navigator.appVersion.match(/MSIE [0-6]\./)) { - jQuery('*', e).each(function () { + $('*', e).each(function () { if (this.currentStyle.backgroundImage != 'none') { var image = this.currentStyle.backgroundImage; image = this.currentStyle.backgroundImage.substring(5, image.length - 2); - jQuery(this).css({ + $(this).css({ 'backgroundImage': 'none', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" }); @@ -46,7 +49,7 @@ jQuery._farbtastic = function (container, callback) { fb.linkTo = function (callback) { // Unbind previous nodes if (typeof fb.callback == 'object') { - jQuery(fb.callback).unbind('keyup', fb.updateValue); + $(fb.callback).unbind('keyup', fb.updateValue); } // Reset color @@ -57,19 +60,19 @@ jQuery._farbtastic = function (container, callback) { fb.callback = callback; } else if (typeof callback == 'object' || typeof callback == 'string') { - fb.callback = jQuery(callback); + fb.callback = $(callback); fb.callback.bind('keyup', fb.updateValue); if (fb.callback.get(0).value) { fb.setColor(fb.callback.get(0).value); } } return this; - } + }; fb.updateValue = function (event) { if (this.value && this.value != fb.color) { fb.setColor(this.value); } - } + }; /** * Change color with HTML syntax #123456 @@ -83,7 +86,7 @@ jQuery._farbtastic = function (container, callback) { fb.updateDisplay(); } return this; - } + }; /** * Change color with HSL triplet [0..1, 0..1, 0..1] @@ -94,7 +97,7 @@ jQuery._farbtastic = function (container, callback) { fb.color = fb.pack(fb.rgb); fb.updateDisplay(); return this; - } + }; ///////////////////////////////////////////////////// @@ -103,64 +106,17 @@ jQuery._farbtastic = function (container, callback) { * of the widget. */ fb.widgetCoords = function (event) { - var x, y; - var el = event.target || event.srcElement; - var reference = fb.wheel; - - if (typeof event.offsetX != 'undefined') { - // Use offset coordinates and find common offsetParent - var pos = { x: event.offsetX, y: event.offsetY }; - - // Send the coordinates upwards through the offsetParent chain. - var e = el; - while (e) { - e.mouseX = pos.x; - e.mouseY = pos.y; - pos.x += e.offsetLeft; - pos.y += e.offsetTop; - e = e.offsetParent; - } - - // Look for the coordinates starting from the wheel widget. - var e = reference; - var offset = { x: 0, y: 0 } - while (e) { - if (typeof e.mouseX != 'undefined') { - x = e.mouseX - offset.x; - y = e.mouseY - offset.y; - break; - } - offset.x += e.offsetLeft; - offset.y += e.offsetTop; - e = e.offsetParent; - } - - // Reset stored coordinates - e = el; - while (e) { - e.mouseX = undefined; - e.mouseY = undefined; - e = e.offsetParent; - } - } - else { - // Use absolute coordinates - var pos = fb.absolutePosition(reference); - x = (event.pageX || 0*(event.clientX + jQuery('html').get(0).scrollLeft)) - pos.x; - y = (event.pageY || 0*(event.clientY + jQuery('html').get(0).scrollTop)) - pos.y; - } - // Subtract distance to middle - return { x: x - fb.width / 2, y: y - fb.width / 2 }; - } + var offset = $(fb.wheel).offset(); + return { x: (event.pageX - offset.left) - fb.width / 2, y: (event.pageY - offset.top) - fb.width / 2 }; + }; /** * Mousedown handler */ fb.mousedown = function (event) { - farbtastic_click = true; // Capture mouse if (!document.dragging) { - jQuery(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup); + $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup); document.dragging = true; } @@ -171,7 +127,7 @@ jQuery._farbtastic = function (container, callback) { // Process fb.mousemove(event); return false; - } + }; /** * Mousemove handler @@ -192,18 +148,17 @@ jQuery._farbtastic = function (container, callback) { fb.setHSL([fb.hsl[0], sat, lum]); } return false; - } + }; /** * Mouseup handler */ fb.mouseup = function () { // Uncapture mouse - farbtastic_click = false; - jQuery(document).unbind('mousemove', fb.mousemove); - jQuery(document).unbind('mouseup', fb.mouseup); + $(document).unbind('mousemove', fb.mousemove); + $(document).unbind('mouseup', fb.mouseup); document.dragging = false; - } + }; /** * Update the markers and styles @@ -211,29 +166,29 @@ jQuery._farbtastic = function (container, callback) { fb.updateDisplay = function () { // Markers var angle = fb.hsl[0] * 6.28; - jQuery('.h-marker', e).css({ + $('.h-marker', e).css({ left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px', top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px' }); - jQuery('.sl-marker', e).css({ + $('.sl-marker', e).css({ left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px', top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px' }); // Saturation/Luminance gradient - jQuery('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5]))); + $('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5]))); // Linked elements or callback if (typeof fb.callback == 'object') { // Set background/foreground color - jQuery(fb.callback).css({ + $(fb.callback).css({ backgroundColor: fb.color, color: fb.hsl[2] > 0.5 ? '#000' : '#fff' }); // Change linked value - jQuery(fb.callback).each(function() { + $(fb.callback).each(function() { if (this.value && this.value != fb.color) { this.value = fb.color; } @@ -242,20 +197,6 @@ jQuery._farbtastic = function (container, callback) { else if (typeof fb.callback == 'function') { fb.callback.call(fb, fb.color); } - } - - /** - * Get absolute position of element - */ - fb.absolutePosition = function (el) { - var r = { x: el.offsetLeft, y: el.offsetTop }; - // Resolve relative to offsetParent - if (el.offsetParent) { - var tmp = fb.absolutePosition(el.offsetParent); - r.x += tmp.x; - r.y += tmp.y; - } - return r; }; /* Various color utility functions */ @@ -266,7 +207,7 @@ jQuery._farbtastic = function (container, callback) { return '#' + (r < 16 ? '0' : '') + r.toString(16) + (g < 16 ? '0' : '') + g.toString(16) + (b < 16 ? '0' : '') + b.toString(16); - } + }; fb.unpack = function (color) { if (color.length == 7) { @@ -279,7 +220,7 @@ jQuery._farbtastic = function (container, callback) { parseInt('0x' + color.substring(2, 3)) / 15, parseInt('0x' + color.substring(3, 4)) / 15]; } - } + }; fb.HSLToRGB = function (hsl) { var m1, m2, r, g, b; @@ -289,7 +230,7 @@ jQuery._farbtastic = function (container, callback) { return [this.hueToRGB(m1, m2, h+0.33333), this.hueToRGB(m1, m2, h), this.hueToRGB(m1, m2, h-0.33333)]; - } + }; fb.hueToRGB = function (m1, m2, h) { h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h); @@ -297,7 +238,7 @@ jQuery._farbtastic = function (container, callback) { if (h * 2 < 1) return m2; if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6; return m1; - } + }; fb.RGBToHSL = function (rgb) { var min, max, delta, h, s, l; @@ -318,10 +259,10 @@ jQuery._farbtastic = function (container, callback) { h /= 6; } return [h, s, l]; - } + }; // Install mousedown handler (the others are set on the document on-demand) - jQuery('*', e).mousedown(fb.mousedown); + $('*', e).mousedown(fb.mousedown); // Init color fb.setColor('#000000'); @@ -330,4 +271,6 @@ jQuery._farbtastic = function (container, callback) { if (callback) { fb.linkTo(callback); } -} \ No newline at end of file +}; + +})(jQuery); \ No newline at end of file