nnnjjj123
2020-11-17 1b2c1edb61190eeb19f465ff031eaa3b2a1b8dbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
///////////////////////////////////////////////////////////////////////////
// Copyright © 2014 - 2018 Esri. All Rights Reserved.
//
// Licensed under the Apache License Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///////////////////////////////////////////////////////////////////////////
 
define(['dojo/Evented',
  'dojo/_base/declare',
  'dijit/_WidgetBase',
  'dijit/_TemplatedMixin',
  'dijit/_WidgetsInTemplateMixin',
  'dojo/_base/lang',
  'dojo/_base/html',
  'dojo/on',
  'dojo/query',
  "dojo/i18n",// i18n.getLocalization
  'dojo/_base/Color',
  "dijit/a11yclick",
  "dojo/i18n!dojo/nls/colors"// translations
],
  function (Evented, declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin,
    lang, html, on, query, i18n, Color, a11yclick) {
    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, Evented], {
      templateString: '<div><div class="dijitInline dijitColorPalette" role="grid">' +
      '<table class="dijitPaletteTable" cellspacing="0" cellpadding="0" role="presentation">' +
      '<tbody data-dojo-attach-point="gridNode">' +
      '</tbody>' +
      '</table>' +
      '</div>' +
      '</div>',
      baseClass: 'jimu-color-chooser',
      declaredClass: 'jimu.dijit.ColorChooser',
      uid: "",
      colorsArray: [
        ["white", "seashell", "cornsilk", "lemonchiffon", "lightyellow", "palegreen", "paleturquoise",
          "lightcyan", "lavender", "plum"],
        ["lightgray", "pink", "bisque", "moccasin", "khaki", "lightgreen", "lightseagreen", "lightskyblue",
          "cornflowerblue", "violet"],
        ["silver", "lightcoral", "sandybrown", "orange", "palegoldenrod", "chartreuse", "mediumturquoise",
          "skyblue", "mediumslateblue", "orchid"],
        ["gray", "red", "orangered", "darkorange", "yellow", "limegreen", "darkseagreen", "royalblue",
          "slateblue", "mediumorchid"],
        ["dimgray", "crimson", "chocolate", "coral", "gold", "forestgreen", "seagreen", "blue", "blueviolet",
          "darkorchid"],
        ["darkslategray", "firebrick", "saddlebrown", "sienna", "olive", "green", "darkcyan", "mediumblue",
          "darkslateblue", "darkmagenta"],
        ["rgb(0,0,1)", "darkred", "maroon", "brown", "darkolivegreen", "darkgreen", "midnightblue", "navy",
          "indigo", "purple"]
      ],
 
      postCreate: function () {
        this.inherited(arguments);
 
        this.colorTitleNls = i18n.getLocalization("dojo", "colors"/*, dojo.locale*/);
        this._createColorsBlocks();
      },
      _createColorsBlocks: function () {
        this._row = this.colorsArray.length;
        this._col = this.colorsArray[0].length;
 
        for (var j = 0; j < this._row; j++) {
          var row = html.create('tr', {
            //'tabindex': j,
            'role': "row"
          }, this.gridNode);
 
          for (var i = 0; i < this._col; i++) {
            var alias = this.colorsArray[j][i];
            var colorValue = Color.named[alias];
 
            var dataTitle = "";
            if (colorValue) {
              dataTitle = alias;
            } else if (alias === "rgb(0,0,1)") {//name in _palettes, to cheat editor
              dataTitle = "black";
              colorValue = "rgb(0,0,1)";
            }
            var title = this.colorTitleNls[dataTitle];
 
            var rgbaVal = new Color(colorValue).toString();
 
            this["record" + i] = html.create('td', {
              'class': 'dijitPaletteCell',
              //'tabindex': i,
              'data-title': rgbaVal,
              'role': "gridcell"
            }, row);
            var span = html.create('span', {
              'class': 'dijitInline dijitPaletteImg'
            }, this["record" + i]);
 
            html.create('img', {
              'class': "dijitColorPaletteSwatch",
              'src': require.toUrl("dojo/resources/blank.gif"),
              "alt": title,
              "title": title,
              "data-title": dataTitle,
              "width": "16px",
              "height": "16px",
              "style": "background-color: " + rgbaVal
            }, span);
          }
        }
 
        //must use a11yclick, if not the first click maybe Invalid
        this.own(on(this.gridNode, /*"click"*/a11yclick, lang.hitch(this, this.onColorClick)));
      },
      onColorClick: function (evt) {
        var target = evt.target;
        while(target.tagName !== "TD"){
          if(!target.parentNode || target === this.gridNode){// probably can never happen, but just in case
            return;
          }
          target = target.parentNode;
        }
 
        var color = html.getAttr(target, "data-title");
        color = new Color(color).toString();
        //console.log("color==>" + color);
        this.setColor(color);
 
        evt.stopPropagation();
        evt.preventDefault();
      },
      _onChange: function (color) {
        this.emit("change", color);
      },
 
      setColor: function (color, isOnChange) {
        //selected style
        var newColor = new Color(color);
        var td = null;
        var tds = query("td", this.domNode);
        //clean selected
        for (var i = 0, len = tds.length; i < len; i++) {
          html.removeClass(tds[i], "dijitPaletteCellSelected");
        }
        //find td
        for (i = 0, len = tds.length; i < len; i++) {
          if (newColor.toString() === html.getAttr(tds[i], "data-title")) {
            td = tds[i];
            break;
          }
        }
        //set color
        if (td) {
          html.addClass(td, "dijitPaletteCellSelected");
        }
        //emit
        if (td && typeof isOnChange === "undefined" || true === isOnChange) {
          this._onChange(newColor);
        }
      }
    });
  });