";
// Step 10 - Final Touches:
if (generateInline&&!exportCSSfile) {layoutheader = layoutheader.replace(/\n/g, " ");}
if (exportCSSfile) {
var downloadAttrSupported = ("download" in document.createElement("a"));
if (!downloadAttrSupported) {warningSystem('Your browser does not support the
Download attribute. As such, the CSS cannot be exported as a separate file.'); return;}
var elementList = layoutheader.match(/");
}
// Step 11 - Output:
document.getElementById("ly-makerHeader").value = layoutheader;
document.getElementById("ly-makerFooter").value = layoutfooter;
if (exportCSSfile) {layoutheader = layoutheader2;} //dirty hacksĀ²
document.getElementById("ly-makerPreview").innerHTML = "
Layout Preview
" + layoutheader +
"
Originally posted by Sample quote" +
"
Originally posted by Sample nested quote Sample linkSample quote
Sample linkSample post with
bold and
italics." + layoutfooter;
}
function warningSystem(value) {
var warningsDOC = document.getElementById("warnings");
if (warningsDOC.innerHTML) {warningsDOC.innerHTML += "
";}
warningsDOC.innerHTML += "
Warning: " + value;
warningsDOC.style.display = "";
}
function colorParser(colorValue, alpha, ignoreErrors) {
try {
if (!ignoreErrors) {
if (!colorValue) throw "No color value was specified.";
if (!colorValue.match(/^#[A-F,0-9]{3}$|^#[A-F,0-9]{6}$|^rgb\(\d\d?\d?, ?\d\d?\d?, ?\d\d?\d?\)$|^hsl\(\d\d?\d?, ?\d\d?\d?%, ?\d\d?\d?%\)$/i)) throw "Invalid color value.";
if (alpha < 0||alpha > 100) throw "Invalid opacity value (too high/low).";
if (isNaN(alpha)&&alpha !== false) throw "Invalid opacity value (non-number).";
}
}
catch(error) {document.getElementById("errors").innerHTML = "
Color Validation Error: " + error; document.getElementById("errors").style.display = ""; stop = now;}
colorValue = colorValue.toString();
// If an alpha value doesn't exist, there's no need to convert it to RGBA/HSLA.
if (alpha) {
if (colorValue.match(/^hsl\(\d\d?\d?, ?\d\d?\d?%, ?\d\d?\d?%\)$/i)) {
colorValue = colorValue.replace(")", ", " + (alpha / 100) + ")");
colorValue = colorValue.replace("hsl", "hsla");
return colorValue;
}
if (colorValue.match(/^#[A-F,0-9]{3}$/i)) {
var hex1 = colorValue.substring(1, 2);
var hex2 = colorValue.substring(2, 3);
var hex3 = colorValue.substring(3, 4);
colorValue = "#" + hex1 + hex1 + hex2 + hex2 + hex3 + hex3;
}
if (colorValue.match(/^#[A-F,0-9]{6}$/i)) {
var rgb1 = parseInt(colorValue.substring(1, 3), 16);
var rgb2 = parseInt(colorValue.substring(3, 5), 16);
var rgb3 = parseInt(colorValue.substring(5, 7), 16);
colorValue = "rgba(" + rgb1 + ", " + rgb2 + ", " + rgb3 + ", " + (alpha / 100) + ")"
} else {colorValue = colorValue.replace(")", ", " + (alpha / 100) + ")"); colorValue = colorValue.replace("rgb", "rgba");}
}
return colorValue;
}
function colorContrast(bgColor, textColor) {
bgColor = colorParser(bgColor, bgColor, 100, true);
bgColor = bgColor.replace(/[\(\)rgba]/ig, "");
bgColor = bgColor.split(", ");
textColor = colorParser(textColor, textColor, 100, true);
textColor = textColor.replace(/[\(\)rgba]/ig, "");
textColor = textColor.split(", ");
bgColor.forEach(srgbMadness);
textColor.forEach(srgbMadness);
var L1 = (0.2126 * bgColor[0]) + (0.7152 * bgColor[1]) + (0.0722 * bgColor[2]);
var L2 = (0.2126 * textColor[0]) + (0.7152 * textColor[1]) + (0.0722 * textColor[2]);
if (L2 > L1) {var contrast = (L2 + 0.05) / (L1 + 0.05)} else {var contrast = (L1 + 0.05) / (L2 + 0.05);}
contrast = Math.round(contrast * 100) / 100;
if (contrast < 4.5) {warningSystem("The contrast ratio between the text and the background is too low " + "(" + contrast + "). " +
"A contrast ratio of 4.5 or higher is recommended so it is easier to read your post.");}
}
function srgbMadness(value, index, array) {
value /= 255;
if (value <= 0.03928) {value /= 12.92;} else {value = Math.pow((value + 0.055) / 1.055, 2.4);}
array[index] = value;
// I FORGOT THIS LAST ONE BEFORE SO IT WASN'T SAVING THE VALUE BACK AT THE ARRAY AND I SPENT SO MUCH TIME TRYING TO FIX THE FORMULA ITSELF TO FIGURE OUT WHAT WAS WRONG
}
/**
* Converts an HSL color value to RGB. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes h, s, and l are contained in the set [0, 1] and
* returns r, g, and b in the set [0, 255].
*
* @param {number} h The hue
* @param {number} s The saturation
* @param {number} l The lightness
* @return {Array} The RGB representation
*/
function hslToRgb(h, s, l) {
var r, g, b;
if (s == 0) {r = g = b = l; /* achromatic */} else {
var hue2rgb = function hue2rgb(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
// return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]; I don't really need to return it as an array in this code so...yeah.
return "rgb(" + Math.round(r * 255) + ", " + Math.round(g * 255) + ", " + Math.round(b * 255) + ")";
}