+ imp. version

This commit is contained in:
kelson42 2013-11-09 15:34:48 +01:00
parent 40acdfc252
commit c451e14479

View File

@ -1,72 +1,5 @@
var Toggled;
function initCss() {
var colorProperties = ['color', 'background-color', 'background'];
$('*').each(function () {
for (var prop in colorProperties) {
prop = colorProperties[prop];
if (($(this).css(prop) === 'rgba(0, 0, 0, 0)') || ($(this).css(prop) === 'transparent')) {
if ($(this).is('body')) {
$(this).css('background', 'rgb(255, 255, 255)');
$(this).css('color', 'rgb(0, 0, 0)');
} else
if (!$(this).is('a'))
$(this).css('color', 'rgb(0, 0, 0)');
}
}
});
}
function invertColors() {
//First init for other elements
if (typeof Toggled === 'undefined') {
initCss();
Toggled = true;
}
var colorProperties = ['color', 'background-color', 'background'];
$('*').each(function () {
var color = null;
for (var prop in colorProperties) {
prop = colorProperties[prop];
if (!$(this).css(prop)) continue;
color = new RGBColor($(this).css(prop));
if (color.ok) {
$(this).css(prop, 'rgb(' + (255 - color.r) + ',' + (255 - color.g) + ',' + (255 - color.b) + ')');
}
color = null;
}
});
}
/**
* A class to parse color values
* @author Stoyan Stefanov <sstoo@gmail.com>
* @link http://www.phpied.com/rgb-color-parser-in-javascript/
* @license Use it if you like it
*/
function RGBColor(color_string) {
this.ok = false;
// strip any leading #
if (color_string.charAt(0) == '#') { // remove # if any
color_string = color_string.substr(1, 6);
}
color_string = color_string.replace(/ /g, '');
color_string = color_string.toLowerCase();
// before getting into regexps, try simple matches
// and overwrite the input
var simple_colors = {
@ -215,12 +148,9 @@ function RGBColor(color_string) {
yellow: 'ffff00',
yellowgreen: '9acd32'
};
for (var key in simple_colors) {
if (color_string == key) {
color_string = simple_colors[key];
}
}
// emd of simple type-in colors
var colorCache = new Object();
var rgbCache = new Object();
// array of color definition objects
var color_defs = [{
@ -255,6 +185,82 @@ function RGBColor(color_string) {
}
}];
var colorProperties = ['color', 'background-color', 'background'];
function initCss() {
$('*').each(function () {
for (var prop in colorProperties) {
prop = colorProperties[prop];
if (($(this).css(prop) === 'rgba(0, 0, 0, 0)') || ($(this).css(prop) === 'transparent')) {
if ($(this).is('body')) {
$(this).css('background', 'rgb(255, 255, 255)');
$(this).css('color', 'rgb(0, 0, 0)');
} else
if (!$(this).is('a'))
$(this).css('color', 'rgb(0, 0, 0)');
}
}
});
}
function invertColors() {
//First init for other elements
if (typeof Toggled === 'undefined') {
initCss();
Toggled = true;
}
var color;
var prop;
var cssProp;
$('*').each(function () {
for (prop in colorProperties) {
prop = colorProperties[prop];
if ($(this).css(prop)) {
cssProp = $(this).css(prop);
if (colorCache[cssProp] != undefined) {
$(this).css(prop, colorCache[cssProp]);
} else {
color = new RGBColor(cssProp);
if (color.ok) {
$(this).css(prop, 'rgb(' + (255 - color.r) + ',' + (255 - color.g) + ',' + (255 - color.b) + ')');
}
colorCache[cssProp] = $(this).css(prop);
}
}
}
});
}
/**
* A class to parse color values
* @author Stoyan Stefanov <sstoo@gmail.com>
* @link http://www.phpied.com/rgb-color-parser-in-javascript/
* @license Use it if you like it
*/
function RGBColor(color_string) {
this.ok = false;
// strip any leading #
if (color_string.charAt(0) == '#') { // remove # if any
color_string = color_string.substr(1, 6);
}
color_string = color_string.replace(/ /g, '');
color_string = color_string.toLowerCase();
for (var key in simple_colors) {
if (color_string == key) {
color_string = simple_colors[key];
}
}
// emd of simple type-in colors
// search through the definitions to find a match
for (var i = 0; i < color_defs.length; i++) {
var re = color_defs[i].re;