@richscripts/richtexteditor 2.10.0 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,11 +28,24 @@
28
28
  \****************************************************************/
29
29
 
30
30
 
31
+ var _colorPickerMemoryStore = {};
31
32
  function SetCookie(name, value, seconds) {
32
- localStorage.setItem("rte-" + name, value);
33
+ var key = "rte-" + name;
34
+ try {
35
+ localStorage.setItem(key, value);
36
+ }
37
+ catch (e) {
38
+ _colorPickerMemoryStore[key] = String(value);
39
+ }
33
40
  }
34
41
  function GetCookie(name) {
35
- return localStorage.getItem("rte-" + name);
42
+ var key = "rte-" + name;
43
+ try {
44
+ return localStorage.getItem(key);
45
+ }
46
+ catch (e) {
47
+ return _colorPickerMemoryStore[key] || null;
48
+ }
36
49
  }
37
50
  function GetCookieDictionary() {
38
51
  var dict = {};
@@ -126,13 +139,11 @@
126
139
  if (span) span.value = color;
127
140
  }
128
141
  function do_saverecent(color) {
129
- if (!color) return;
130
- if (color.length != 7) return;
131
- if (color.substring(0, 1) != "#") return;
132
- var hex = color.substring(1, 7);
142
+ var hex = normalizeHexInput(color);
143
+ if (!hex) return;
133
144
  var recent = GetCookie("RecentColors");
134
- console.log("load recent", recent);
135
145
  if (!recent) recent = "";
146
+ recent = recent.toUpperCase();
136
147
  if ((recent.length % 6) != 0) recent = "";
137
148
  for (var i = 0; i < recent.length; i += 6) {
138
149
  if (recent.substr(i, 6) == hex) {
@@ -143,9 +154,32 @@
143
154
  if (recent.length > 31 * 6)
144
155
  recent = recent.substr(0, 31 * 6);
145
156
  recent = hex + recent;
146
- //alert(recent);
147
157
  SetCookie("RecentColors", recent, 60 * 60 * 24 * 365);
148
- console.log("save recent", recent);
158
+ }
159
+
160
+ function normalizeHexInput(value) {
161
+ if (value === null || value === undefined) return null;
162
+ var color = String(value).replace(/^\s+|\s+$/g, "");
163
+ if (color.substring(0, 1) == "#") color = color.substring(1);
164
+ if (/^[0-9a-f]{3}$/i.test(color)) {
165
+ color = color.charAt(0) + color.charAt(0) + color.charAt(1) + color.charAt(1) + color.charAt(2) + color.charAt(2);
166
+ }
167
+ if (/^[0-9a-f]{6}$/i.test(color)) return color.toUpperCase();
168
+ var rgbMatch = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i.exec(color);
169
+ if (!rgbMatch) return null;
170
+ var rgb = [Number(rgbMatch[1]), Number(rgbMatch[2]), Number(rgbMatch[3])];
171
+ if (rgb[0] > 255 || rgb[1] > 255 || rgb[2] > 255) return null;
172
+ return RgbToHex(rgb).toUpperCase();
173
+ }
174
+
175
+ function handleHexPaste(e) {
176
+ var clipboard = e.clipboardData || window.clipboardData;
177
+ var value = clipboard && clipboard.getData ? clipboard.getData("text") || clipboard.getData("Text") : "";
178
+ var hex = normalizeHexInput(value);
179
+ if (!hex) return;
180
+ e.preventDefault();
181
+ frm.txtHex.value = hex;
182
+ Hex_Changed(e);
149
183
  }
150
184
 
151
185
  setCallback(do_saverecent);
@@ -228,6 +262,7 @@
228
262
  frm.txtRGB_Blue.onkeypress = validateNumber;
229
263
  frm.txtHex.onkeyup = Hex_Changed;
230
264
  frm.txtHex.onkeypress = validateHex;
265
+ frm.txtHex.onpaste = handleHexPaste;
231
266
  frm.btnWebSafeColor.onclick = btnWebSafeColor_Click;
232
267
  frm.rdoHSB_Hue.onclick = rdoHsb_Hue_Click;
233
268
  frm.rdoHSB_Saturation.onclick = rdoHsb_Saturation_Click;
@@ -332,6 +367,13 @@
332
367
  document.getElementById("pnlRGB_Green"), msg.RgbGreenTooltip,
333
368
  document.getElementById("pnlRGB_Blue"), msg.RgbBlueTooltip
334
369
  );
370
+ frm.txtHSB_Hue.setAttribute("aria-label", msg.HsbHueTooltip);
371
+ frm.txtHSB_Saturation.setAttribute("aria-label", msg.HsbSaturationTooltip);
372
+ frm.txtHSB_Brightness.setAttribute("aria-label", msg.HsbBrightnessTooltip);
373
+ frm.txtRGB_Red.setAttribute("aria-label", msg.RgbRedTooltip);
374
+ frm.txtRGB_Green.setAttribute("aria-label", msg.RgbGreenTooltip);
375
+ frm.txtRGB_Blue.setAttribute("aria-label", msg.RgbBlueTooltip);
376
+ frm.txtHex.setAttribute("aria-label", "Hexadecimal color value");
335
377
 
336
378
  }
337
379
  function window_load(e) {
@@ -358,9 +400,14 @@
358
400
  hex = recent.substr((i - 1) * 6, 6);
359
401
  var rgb = HexToRgb(hex);
360
402
  var title = formatString(msg.RecentTooltip, hex, rgb[0], rgb[1], rgb[2]);
361
- SetBg(document.getElementById("pnlRecent" + i), hex);
362
- SetTitle(document.getElementById("pnlRecent" + i), title);
363
- document.getElementById("pnlRecent" + i).onclick = pnlRecent_Click;
403
+ var recentColor = document.getElementById("pnlRecent" + i);
404
+ SetBg(recentColor, hex);
405
+ SetTitle(recentColor, title);
406
+ recentColor.setAttribute("role", "button");
407
+ recentColor.setAttribute("aria-label", title);
408
+ recentColor.tabIndex = 0;
409
+ recentColor.onclick = pnlRecent_Click;
410
+ recentColor.onkeydown = pnlRecent_KeyDown;
364
411
  }
365
412
  else
366
413
  document.getElementById("pnlRecent" + i).style.border = "0px";
@@ -385,6 +432,13 @@
385
432
  frm.txtHex.value = color;
386
433
  Hex_Changed(e);
387
434
  }
435
+ function pnlRecent_KeyDown(e) {
436
+ var key = e.key || e.keyCode;
437
+ if (key == "Enter" || key == " " || key == 13 || key == 32) {
438
+ e.preventDefault();
439
+ pnlRecent_Click({ target: e.currentTarget || e.target });
440
+ }
441
+ }
388
442
  function pnlOldClick_Click(e) {
389
443
  frm.txtHex.value = document.getElementById("pnlOldColor").style.backgroundColor.substr(1, 6).toUpperCase();
390
444
  Hex_Changed(e);
@@ -518,8 +572,8 @@
518
572
  function validateNumber(e) {
519
573
  var key = String.fromCharCode(e.which);
520
574
  if (IgnoreKey(e)) return;
521
- if ("01234567879".indexOf(key) != -1) return;
522
- e.which = 0;
575
+ if ("0123456789".indexOf(key) != -1) return;
576
+ rejectKey(e);
523
577
  }
524
578
  function validateHex(e) {
525
579
  if (IgnoreKey(e)) return;
@@ -528,8 +582,12 @@
528
582
  //e.which = key.toUpperCase().charCodeAt(0);
529
583
  return;
530
584
  }
531
- if ("01234567879ABCDEF".indexOf(key) != -1) return;
532
- //e.which = 0;
585
+ if ("0123456789ABCDEF".indexOf(key) != -1) return;
586
+ rejectKey(e);
587
+ }
588
+ function rejectKey(e) {
589
+ if (e.preventDefault) e.preventDefault();
590
+ e.which = 0;
533
591
  }
534
592
  function IgnoreKey(e) {
535
593
  var key = String.fromCharCode(e.which);
@@ -543,7 +601,7 @@
543
601
  selectCancel();
544
602
  }
545
603
  function btnOK_Click() {
546
- var hex = "#"+ new String(frm.txtHex.value);
604
+ var hex = "#" + Form_Get_Hex();
547
605
  //alert(hex);
548
606
  do_saverecent(hex);
549
607
  selectColor(hex);
@@ -596,6 +654,7 @@
596
654
  Form_Set_Rgb(rgb);
597
655
  Form_Set_Hsb(hsb);
598
656
  SetBg(document.getElementById("pnlNewColor"), hex);
657
+ announceColor(hex, rgb);
599
658
  SetupCursors(e);
600
659
  SetupGradients();
601
660
  checkWebSafe();
@@ -608,6 +667,7 @@
608
667
  Form_Set_Hsb(hsb);
609
668
  Form_Set_Hex(hex);
610
669
  SetBg(document.getElementById("pnlNewColor"), hex);
670
+ announceColor(hex, rgb);
611
671
  SetupCursors(e);
612
672
  SetupGradients();
613
673
  checkWebSafe();
@@ -620,6 +680,7 @@
620
680
  Form_Set_Rgb(rgb);
621
681
  Form_Set_Hex(hex);
622
682
  SetBg(document.getElementById("pnlNewColor"), hex);
683
+ announceColor(hex, rgb);
623
684
  SetupCursors(e);
624
685
  SetupGradients();
625
686
  checkWebSafe();
@@ -629,6 +690,38 @@
629
690
  frm.txtHex.value = hex;
630
691
  }
631
692
 
693
+ function getColorFamily(rgb) {
694
+ var hsb = RgbToHsb(rgb);
695
+ if (hsb[1] < 0.12) {
696
+ if (hsb[2] < 0.18) return "black";
697
+ if (hsb[2] > 0.9) return "white";
698
+ return "gray";
699
+ }
700
+ var hue = Math.round((hsb[0] * 360) % 360);
701
+ if (hue < 15 || hue >= 345) return "red";
702
+ if (hue < 45) return "orange";
703
+ if (hue < 70) return "yellow";
704
+ if (hue < 165) return "green";
705
+ if (hue < 195) return "cyan";
706
+ if (hue < 255) return "blue";
707
+ if (hue < 290) return "purple";
708
+ if (hue < 330) return "magenta";
709
+ return "rose";
710
+ }
711
+
712
+ function announceColor(hex, rgb) {
713
+ var description = "Selected " + getColorFamily(rgb) + ", #" + hex +
714
+ ", red " + rgb[0] + ", green " + rgb[1] + ", blue " + rgb[2];
715
+ var preview = document.getElementById("pnlNewColor");
716
+ if (preview) {
717
+ preview.setAttribute("role", "img");
718
+ preview.setAttribute("aria-label", description);
719
+ preview.title = description;
720
+ }
721
+ var live = document.getElementById("colorAnnouncement");
722
+ if (live) live.textContent = description;
723
+ }
724
+
632
725
  function Form_Get_Hex() {
633
726
  var hex = new String(frm.txtHex.value);
634
727
  for (var i = 0; i < hex.length; i++)
@@ -648,19 +741,19 @@
648
741
  hsb[0] = new Number(frm.txtHSB_Hue.value) / 360;
649
742
  hsb[1] = new Number(frm.txtHSB_Saturation.value) / 100;
650
743
  hsb[2] = new Number(frm.txtHSB_Brightness.value) / 100;
651
- if (hsb[0] > 1 || isNaN(hsb[0])) {
652
- hsb[0] = 1;
653
- frm.txtHSB_Hue.value = 360;
744
+ if (hsb[0] < 0 || hsb[0] > 1 || isNaN(hsb[0])) {
745
+ hsb[0] = hsb[0] < 0 ? 0 : 1;
746
+ frm.txtHSB_Hue.value = hsb[0] * 360;
654
747
  alert(formatString(msg.BadNumber, 0, 360));
655
748
  }
656
- if (hsb[1] > 1 || isNaN(hsb[1])) {
657
- hsb[1] = 1;
658
- frm.txtHSB_Saturation.value = 100;
749
+ if (hsb[1] < 0 || hsb[1] > 1 || isNaN(hsb[1])) {
750
+ hsb[1] = hsb[1] < 0 ? 0 : 1;
751
+ frm.txtHSB_Saturation.value = hsb[1] * 100;
659
752
  alert(formatString(msg.BadNumber, 0, 100));
660
753
  }
661
- if (hsb[2] > 1 || isNaN(hsb[2])) {
662
- hsb[2] = 1;
663
- frm.txtHSB_Brightness.value = 100;
754
+ if (hsb[2] < 0 || hsb[2] > 1 || isNaN(hsb[2])) {
755
+ hsb[2] = hsb[2] < 0 ? 0 : 1;
756
+ frm.txtHSB_Brightness.value = hsb[2] * 100;
664
757
  alert(formatString(msg.BadNumber, 0, 100));
665
758
  }
666
759
  return hsb;
@@ -678,19 +771,19 @@
678
771
  rgb[1] = new Number(frm.txtRGB_Green.value);
679
772
  rgb[2] = new Number(frm.txtRGB_Blue.value);
680
773
 
681
- if (rgb[0] > 255 || isNaN(rgb[0]) || rgb[0] != Math.round(rgb[0])) {
682
- rgb[0] = 255;
683
- frm.txtRGB_Red.value = 255;
774
+ if (rgb[0] < 0 || rgb[0] > 255 || isNaN(rgb[0]) || rgb[0] != Math.round(rgb[0])) {
775
+ rgb[0] = rgb[0] < 0 ? 0 : 255;
776
+ frm.txtRGB_Red.value = rgb[0];
684
777
  alert(formatString(msg.BadNumber, 0, 255));
685
778
  }
686
- if (rgb[1] > 255 || isNaN(rgb[1]) || rgb[1] != Math.round(rgb[1])) {
687
- rgb[1] = 255;
688
- frm.txtRGB_Green.value = 255;
779
+ if (rgb[1] < 0 || rgb[1] > 255 || isNaN(rgb[1]) || rgb[1] != Math.round(rgb[1])) {
780
+ rgb[1] = rgb[1] < 0 ? 0 : 255;
781
+ frm.txtRGB_Green.value = rgb[1];
689
782
  alert(formatString(msg.BadNumber, 0, 255));
690
783
  }
691
- if (rgb[2] > 255 || isNaN(rgb[2]) || rgb[2] != Math.round(rgb[2])) {
692
- rgb[2] = 255;
693
- frm.txtRGB_Blue.value = 255;
784
+ if (rgb[2] < 0 || rgb[2] > 255 || isNaN(rgb[2]) || rgb[2] != Math.round(rgb[2])) {
785
+ rgb[2] = rgb[2] < 0 ? 0 : 255;
786
+ frm.txtRGB_Blue.value = rgb[2];
694
787
  alert(formatString(msg.BadNumber, 0, 255));
695
788
  }
696
789
  return rgb;
@@ -2335,6 +2428,7 @@ Elements
2335
2428
  <div id="ajaxdiv">
2336
2429
 
2337
2430
  <div id="colorpickerpanel" style="position: relative; text-align: left; height: 350px">
2431
+ <div id="colorAnnouncement" aria-live="polite" aria-atomic="true" style="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap"></div>
2338
2432
  <!--
2339
2433
  -----------------------------------------------------
2340
2434
  Author: Lewis E. Moten III