restored and fixed colorpicker to regain flexible functionality and way-backwards-compatibility
* fixed bug that prevented colorpicker from working at all * fixed bug that prevented display of colors that are changed but not saved * <% colorpicker name="xyz" %> now renders the default colorpicker * <% colorpicker name="xyz" skin="colorpickerExt" %> renders the extended version (or any other depending on the skin) * modified site's edit.skin to open the extended version * put client-side scripts and functionality into global Antville object to define a strict namespace * updated AntvilleLib NOTE: THIS IS STILL WORK IN PROGRESS
This commit is contained in:
parent
463d4b3177
commit
73ca975e42
9 changed files with 496 additions and 489 deletions
|
@ -75,7 +75,9 @@ function safescripts_action() {
|
|||
*/
|
||||
|
||||
function colorpicker_action() {
|
||||
renderSkin("colorpicker");
|
||||
if (!req.data.skin)
|
||||
req.data.skin = "colorpicker";
|
||||
renderSkin(req.data.skin);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,249 +1,56 @@
|
|||
Antville = {
|
||||
encode: function(str) {
|
||||
var chars = ["&", "<", ">", '"'];
|
||||
for (var i in chars) {
|
||||
var c = chars[i];
|
||||
var re = new RegExp(c, "g");
|
||||
str = str.replace(re, "&#" + c.charCodeAt() + ";");
|
||||
}
|
||||
return str;
|
||||
},
|
||||
decode: function(str) {
|
||||
return str.replace(/&/g, "&");
|
||||
},
|
||||
Referrer: function(url, text, count) {
|
||||
this.url = url;
|
||||
this.text = text;
|
||||
this.count = count;
|
||||
this.compose = function(key, prefix) {
|
||||
var query = new Antville.Query(this.url);
|
||||
if (query[key]) {
|
||||
if (prefix == null)
|
||||
prefix = "";
|
||||
return prefix + Antville.encode(query[key]);
|
||||
}
|
||||
return this.text;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
Query: function(str) {
|
||||
if (str == undefined)
|
||||
var str = location.search.substring(1);
|
||||
else if (str.indexOf("?") > -1)
|
||||
var str = str.split("?")[1];
|
||||
if (str == "")
|
||||
return this;
|
||||
var parts = Antville.decode(unescape(str)).split("&");
|
||||
for (var i in parts) {
|
||||
var pair = parts[i].split("=");
|
||||
var key = pair[0];
|
||||
if (key) {
|
||||
key = key.replace(/\+/g, " ");
|
||||
var value = pair[1];
|
||||
if (value)
|
||||
value = value.replace(/\+/g, " ");
|
||||
this[key] = value;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
},
|
||||
Filter: function(def, key) {
|
||||
this.key = key;
|
||||
if (def == null)
|
||||
this.items = [];
|
||||
else if (def instanceof Array)
|
||||
this.items = def;
|
||||
Antville = {};
|
||||
Antville.prefix = "Antville_";
|
||||
|
||||
Antville.pixel = new Image();
|
||||
Antville.pixel.src = "<% image name="/pixel" as="url" %>";
|
||||
|
||||
Antville.colors = {"aliceblue": true, "antiquewhite": true, "aqua": true, "aquamarine": true, "azure": true, "beige": true, "bisque": true, "black": true, "blanchedalmond": true, "blue": true, "blueviolet": true, "brown": true, "burlywood": true, "cadetblue": true, "chartreuse": true, "chocolate": true, "coral": true, "cornflowerblue": true, "cornsilk": true, "crimson": true, "cyan": true, "darkblue": true, "darkcyan": true, "darkgoldenrod": true, "darkgray": true, "darkgreen": true, "darkkhaki": true, "darkmagenta": true, "darkolivegreen": true, "darkorange": true, "darkorchid": true, "darkred": true, "darksalmon": true, "darkseagreen": true, "darkslateblue": true, "darkslategray": true, "darkturquoise": true, "darkviolet": true, "deeppink": true, "deepskyblue": true, "dimgray": true, "dodgerblue": true, "firebrick": true, "floralwhite": true, "forestgreen": true, "fuchsia": true, "gainsboro": true, "ghostwhite": true, "gold": true, "goldenrod": true, "gray": true, "green": true, "greenyellow": true, "honeydew": true, "hotpink": true, "indianred ": true, "indigo ": true, "ivory": true, "khaki": true, "lavender": true, "lavenderblush": true, "lawngreen": true, "lemonchiffon": true, "lightblue": true, "lightcoral": true, "lightcyan": true, "lightgoldenrodyellow": true, "lightgrey": true, "lightgreen": true, "lightpink": true, "lightsalmon": true, "lightseagreen": true, "lightskyblue": true, "lightslateblue": true, "lightslategray": true, "lightsteelblue": true, "lightyellow": true, "lime": true, "limegreen": true, "linen": true, "magenta": true, "maroon": true, "mediumaquamarine": true, "mediumblue": true, "mediumorchid": true, "mediumpurple": true, "mediumseagreen": true, "mediumslateblue": true, "mediumspringgreen": true, "mediumturquoise": true, "mediumvioletred": true, "midnightblue": true, "mintcream": true, "mistyrose": true, "moccasin": true, "navajowhite": true, "navy": true, "oldlace": true, "olive": true, "olivedrab": true, "orange": true, "orangered": true, "orchid": true, "palegoldenrod": true, "palegreen": true, "paleturquoise": true, "palevioletred": true, "papayawhip": true, "peachpuff": true, "peru": true, "pink": true, "plum": true, "powderblue": true, "purple": true, "red": true, "rosybrown": true, "royalblue": true, "saddlebrown": true, "salmon": true, "sandybrown": true, "seagreen": true, "seashell": true, "sienna": true, "silver": true, "skyblue": true, "slateblue": true, "slategray": true, "snow": true, "springgreen": true, "steelblue": true, "tan": true, "teal": true, "thistle": true, "tomato": true, "turquoise": true, "violet": true, "violetred": true, "wheat": true, "white": true, "whitesmoke": true, "yellow": true, "yellowgreen": true};
|
||||
|
||||
Antville.ColorPickerFactory = function() {
|
||||
this.prefix = Antville.prefix + "ColorPicker_";
|
||||
this.valuePrefix = Antville.prefix + "ColorValue_";
|
||||
|
||||
this.open = function(name, text, skin) {
|
||||
var cpWindow = window.open("<% site.href action="colorpicker" %>?name=" + name + "&text=" + text + "&skin=" + skin, Antville.ColorPicker.prefix, "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width=350,height=320");
|
||||
}
|
||||
|
||||
this.set = function(name, color) {
|
||||
var prefix = Antville.ColorPicker.prefix;
|
||||
var valuePrefix = Antville.ColorPicker.valuePrefix;
|
||||
var color = Antville.parseColor(color);
|
||||
if (color)
|
||||
document.getElementById(prefix + name).style.backgroundColor = color;
|
||||
else
|
||||
this.items = def.replace(/\r/g, "\n").split("\n");
|
||||
this.test = function(str) {
|
||||
if (!str)
|
||||
return false;
|
||||
for (var n in this.items) {
|
||||
var re = new RegExp(this.items[n], "i");
|
||||
if (re.test(str))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return this;
|
||||
color = Antville.parseColor(document.getElementById(prefix + name).style.backgroundColor);
|
||||
if (color.indexOf("#") == 0)
|
||||
color = color.substr(1,color.length-1);
|
||||
document.getElementById(valuePrefix + name).value = color;
|
||||
return;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
function openColorPicker(name, text) {
|
||||
var cpWindow = window.open("<% param.cpHost %>colorpicker?name=" + name + "&text=" + text, "cpWindow", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width=480,height=320");
|
||||
}
|
||||
Antville.ColorPicker = new Antville.ColorPickerFactory();
|
||||
|
||||
function setBg() {
|
||||
var c = document.getElementById("cp2_bgcolor").style.backgroundColor;
|
||||
document.body.style.backgroundColor = c;
|
||||
var tds = document.getElementsByTagName("td");
|
||||
for (var i in tds) {
|
||||
if (tds[i].style)
|
||||
tds[i].style.backgroundColor = c;
|
||||
Antville.encode = function(str) {
|
||||
var chars = ["&", "<", ">", '"'];
|
||||
for (var i in chars) {
|
||||
var c = chars[i];
|
||||
var re = new RegExp(c, "g");
|
||||
str = str.replace(re, "&#" + c.charCodeAt() + ";");
|
||||
}
|
||||
return;
|
||||
return str;
|
||||
}
|
||||
|
||||
function setColorPreview(name, color) {
|
||||
color = parseColor(color);
|
||||
if (color)
|
||||
document.getElementById('cp2_' + name).style.backgroundColor = color;
|
||||
else
|
||||
color = parseColor(document.getElementById('cp2_' + name).style.backgroundColor);
|
||||
if (color.indexOf("#") == 0)
|
||||
color = color.substr(1,color.length-1);
|
||||
document.getElementById('cp1_' + name).value = color;
|
||||
Antville.decode = function(str) {
|
||||
return str.replace(/&/g, "&");
|
||||
}
|
||||
|
||||
function parseColor(color) {
|
||||
c = color.toLowerCase();
|
||||
var colorNames = new Object();
|
||||
colorNames["aliceblue"] = true;
|
||||
colorNames["antiquewhite"]= true
|
||||
colorNames["aqua"] = true;
|
||||
colorNames["aquamarine"] = true;
|
||||
colorNames["azure"] = true;
|
||||
colorNames["beige"] = true;
|
||||
colorNames["bisque"] = true;
|
||||
colorNames["black"] = true;
|
||||
colorNames["blanchedalmond"] = true;
|
||||
colorNames["blue"] = true;
|
||||
colorNames["blueviolet"] = true;
|
||||
colorNames["brown"] = true;
|
||||
colorNames["burlywood"] = true;
|
||||
colorNames["cadetblue"] = true;
|
||||
colorNames["chartreuse"] = true;
|
||||
colorNames["chocolate"] = true;
|
||||
colorNames["coral"] = true;
|
||||
colorNames["cornflowerblue"] = true;
|
||||
colorNames["cornsilk"] = true;
|
||||
colorNames["crimson"] = true;
|
||||
colorNames["cyan"] = true;
|
||||
colorNames["darkblue"] = true;
|
||||
colorNames["darkcyan"] = true;
|
||||
colorNames["darkgoldenrod"] = true;
|
||||
colorNames["darkgray"] = true;
|
||||
colorNames["darkgreen"] = true;
|
||||
colorNames["darkkhaki"] = true;
|
||||
colorNames["darkmagenta"] = true;
|
||||
colorNames["darkolivegreen"] = true;
|
||||
colorNames["darkorange"] = true;
|
||||
colorNames["darkorchid"] = true;
|
||||
colorNames["darkred"] = true;
|
||||
colorNames["darksalmon"] = true;
|
||||
colorNames["darkseagreen"] = true;
|
||||
colorNames["darkslateblue"] = true;
|
||||
colorNames["darkslategray"] = true;
|
||||
colorNames["darkturquoise"] = true;
|
||||
colorNames["darkviolet"] = true;
|
||||
colorNames["deeppink"] = true;
|
||||
colorNames["deepskyblue"] = true;
|
||||
colorNames["dimgray"] = true;
|
||||
colorNames["dodgerblue"] = true;
|
||||
colorNames["firebrick"] = true;
|
||||
colorNames["floralwhite"] = true;
|
||||
colorNames["forestgreen"] = true;
|
||||
colorNames["fuchsia"] = true;
|
||||
colorNames["gainsboro"] = true;
|
||||
colorNames["ghostwhite"] = true;
|
||||
colorNames["gold"] = true;
|
||||
colorNames["goldenrod"] = true;
|
||||
colorNames["gray"] = true;
|
||||
colorNames["green"] = true;
|
||||
colorNames["greenyellow"] = true;
|
||||
colorNames["honeydew"] = true;
|
||||
colorNames["hotpink"] = true;
|
||||
colorNames["indianred "] = true;
|
||||
colorNames["indigo "] = true;
|
||||
colorNames["ivory"] = true;
|
||||
colorNames["khaki"] = true;
|
||||
colorNames["lavender"] = true;
|
||||
colorNames["lavenderblush"] = true;
|
||||
colorNames["lawngreen"] = true;
|
||||
colorNames["lemonchiffon"] = true;
|
||||
colorNames["lightblue"] = true;
|
||||
colorNames["lightcoral"] = true;
|
||||
colorNames["lightcyan"] = true;
|
||||
colorNames["lightgoldenrodyellow"] = true;
|
||||
colorNames["lightgrey"] = true;
|
||||
colorNames["lightgreen"] = true;
|
||||
colorNames["lightpink"] = true;
|
||||
colorNames["lightsalmon"] = true;
|
||||
colorNames["lightseagreen"] = true;
|
||||
colorNames["lightskyblue"] = true;
|
||||
colorNames["lightslateblue"] = true;
|
||||
colorNames["lightslategray"] = true;
|
||||
colorNames["lightsteelblue"] = true;
|
||||
colorNames["lightyellow"] = true;
|
||||
colorNames["lime"] = true;
|
||||
colorNames["limegreen"] = true;
|
||||
colorNames["linen"] = true;
|
||||
colorNames["magenta"] = true;
|
||||
colorNames["maroon"] = true;
|
||||
colorNames["mediumaquamarine"] = true;
|
||||
colorNames["mediumblue"] = true;
|
||||
colorNames["mediumorchid"] = true;
|
||||
colorNames["mediumpurple"] = true;
|
||||
colorNames["mediumseagreen"] = true;
|
||||
colorNames["mediumslateblue"] = true;
|
||||
colorNames["mediumspringgreen"] = true;
|
||||
colorNames["mediumturquoise"] = true;
|
||||
colorNames["mediumvioletred"] = true;
|
||||
colorNames["midnightblue"] = true;
|
||||
colorNames["mintcream"] = true;
|
||||
colorNames["mistyrose"] = true;
|
||||
colorNames["moccasin"] = true;
|
||||
colorNames["navajowhite"] = true;
|
||||
colorNames["navy"] = true;
|
||||
colorNames["oldlace"] = true;
|
||||
colorNames["olive"] = true;
|
||||
colorNames["olivedrab"] = true;
|
||||
colorNames["orange"] = true;
|
||||
colorNames["orangered"] = true;
|
||||
colorNames["orchid"] = true;
|
||||
colorNames["palegoldenrod"] = true;
|
||||
colorNames["palegreen"] = true;
|
||||
colorNames["paleturquoise"] = true;
|
||||
colorNames["palevioletred"] = true;
|
||||
colorNames["papayawhip"] = true;
|
||||
colorNames["peachpuff"] = true;
|
||||
colorNames["peru"] = true;
|
||||
colorNames["pink"] = true;
|
||||
colorNames["plum"] = true;
|
||||
colorNames["powderblue"] = true;
|
||||
colorNames["purple"] = true;
|
||||
colorNames["red"] = true;
|
||||
colorNames["rosybrown"] = true;
|
||||
colorNames["royalblue"] = true;
|
||||
colorNames["saddlebrown"] = true;
|
||||
colorNames["salmon"] = true;
|
||||
colorNames["sandybrown"] = true;
|
||||
colorNames["seagreen"] = true;
|
||||
colorNames["seashell"] = true;
|
||||
colorNames["sienna"] = true;
|
||||
colorNames["silver"] = true;
|
||||
colorNames["skyblue"] = true;
|
||||
colorNames["slateblue"] = true;
|
||||
colorNames["slategray"] = true;
|
||||
colorNames["snow"] = true;
|
||||
colorNames["springgreen"] = true;
|
||||
colorNames["steelblue"] = true;
|
||||
colorNames["tan"] = true;
|
||||
colorNames["teal"] = true;
|
||||
colorNames["thistle"] = true;
|
||||
colorNames["tomato"] = true;
|
||||
colorNames["turquoise"] = true;
|
||||
colorNames["violet"] = true;
|
||||
colorNames["violetred"] = true;
|
||||
colorNames["wheat"] = true;
|
||||
colorNames["white"] = true;
|
||||
colorNames["whitesmoke"] = true;
|
||||
colorNames["yellow"] = true;
|
||||
colorNames["yellowgreen"] = true;
|
||||
|
||||
if (colorNames[c])
|
||||
return(c);
|
||||
|
||||
Antville.parseColor = function(color) {
|
||||
var c = color.toLowerCase();
|
||||
if (Antville.colors[c])
|
||||
return c;
|
||||
var rgb = new RegExp("rgb ?\\( ?([0-9^,]*), ?([0-9^,]*), ?([0-9^ \\)]*) ?\\)");
|
||||
var result = color.match(rgb);
|
||||
if (result) {
|
||||
|
@ -253,7 +60,7 @@ function parseColor(color) {
|
|||
if (R.length == 1) R="0"+R;
|
||||
if (G.length == 1) G="0"+G;
|
||||
if (B.length == 1) B="0"+B;
|
||||
return("#"+R+G+B);
|
||||
return "#"+R+G+B;
|
||||
}
|
||||
if (c.indexOf("#") == 0)
|
||||
c = c.substr(1,c.length-1);
|
||||
|
@ -262,7 +69,66 @@ function parseColor(color) {
|
|||
nonhex.ignoreCase = true;
|
||||
var found = c.match(nonhex);
|
||||
if (!found)
|
||||
return("#" + c);
|
||||
return "#" + c;
|
||||
}
|
||||
return(null);
|
||||
return;
|
||||
}
|
||||
|
||||
Antville.Referrer = function(url, text, count) {
|
||||
this.url = url;
|
||||
this.text = text;
|
||||
this.count = count;
|
||||
this.compose = function(key, prefix) {
|
||||
var query = new Antville.Query(this.url);
|
||||
if (query[key]) {
|
||||
if (prefix == null)
|
||||
prefix = "";
|
||||
return prefix + Antville.encode(query[key]);
|
||||
}
|
||||
return this.text;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Antville.Query = function(str) {
|
||||
if (str == undefined)
|
||||
var str = location.search.substring(1);
|
||||
else if (str.indexOf("?") > -1)
|
||||
var str = str.split("?")[1];
|
||||
if (str == "")
|
||||
return this;
|
||||
var parts = Antville.decode(unescape(str)).split("&");
|
||||
for (var i in parts) {
|
||||
var pair = parts[i].split("=");
|
||||
var key = pair[0];
|
||||
if (key) {
|
||||
key = key.replace(/\+/g, " ");
|
||||
var value = pair[1];
|
||||
if (value)
|
||||
value = value.replace(/\+/g, " ");
|
||||
this[key] = value;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Antville.Filter = function(def, key) {
|
||||
this.key = key;
|
||||
if (def == null)
|
||||
this.items = [];
|
||||
else if (def instanceof Array)
|
||||
this.items = def;
|
||||
else
|
||||
this.items = def.replace(/\r/g, "\n").split("\n");
|
||||
this.test = function(str) {
|
||||
if (!str)
|
||||
return false;
|
||||
for (var n in this.items) {
|
||||
var re = new RegExp(this.items[n], "i");
|
||||
if (re.test(str))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue