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
///////////////////////////////////////////////////////////////////////////
// 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',
  'dojox/widget/ColorPicker',
  "dijit/_base/focus",
  "dojo/fx",
  'dojo/_base/lang',
  'dojo/_base/html',
  "dojo/sniff"
], function (Evented, declare, _WidgetBase, dojoxColorPicker, FocusManager, fx, lang, html, has) {
  return declare([_WidgetBase, dojoxColorPicker, Evented], {
    baseClass: 'jimu-color-selector',
    declaredClass: 'jimu.dijit.ColorSelector',
 
    //overwirte this method, because it get wrong color when clicled
    _setPoint: function (/* Event */evt) {
      if (evt) { FocusManager.focus(evt.target); }
      //half of icon
      if (!this._CURSOR_WIDTH || !this._CURSOR_HEIGHT) {
        var cursorNodeBox = html.getMarginBox(this.cursorNode);
        if (cursorNodeBox.w && cursorNodeBox.h) {
          this._CURSOR_WIDTH = cursorNodeBox.w / 2;
          this._CURSOR_HEIGHT = cursorNodeBox.h / 2;
        }
      }
      //border w/h
      if (!this._BORDER_WIDTH || !this._BORDER_HEIGHT) {
        var borderObj = html.getBorderExtents(evt.target || evt.srcElement);
        if (borderObj.w && borderObj.h) {
          this._BORDER_WIDTH = borderObj.w;
          this._BORDER_HEIGHT = borderObj.h;
        }
      }
 
      //fix position
      var tarX = 0,
        tarY = 0;
      if (has("ff") || has("ie") || has("MSIE")) {
        //ff ie, without border
        tarX = evt.offsetX;
        tarY = evt.offsetY;
      } else if (evt.offsetX && evt.offsetY) {
        //chrome edge, with border w/h
        tarX = evt.offsetX + this._BORDER_WIDTH;
        tarY = evt.offsetY + this._BORDER_HEIGHT;
      }
      //targetX/Y - halfWidth/Height of icon
      var newTop = tarY - this._CURSOR_HEIGHT;
      var newLeft = tarX - this._CURSOR_WIDTH;
 
      //set color
      if (this.animatePoint) {
        fx.slideTo({
          node: this.cursorNode,
          duration: this.slideDuration,
          top: newTop,
          left: newLeft,
          onEnd: lang.hitch(this, function () { this._updateColor(true); FocusManager.focus(this.cursorNode); })
        }).play();
      } else {
        html.style(this.cursorNode, {
          left: newLeft + "px",
          top: newTop + "px"
        });
        this._updateColor(true);
      }
    },
 
    _setHuePoint: function (/* Event */evt) {
      var selCenter = this.PICKER_HUE_SELECTOR_H / 2;//half of icon
      var ypos = evt.offsetY - selCenter;
 
      if (this.animatePoint) {
        fx.slideTo({
          node: this.hueCursorNode,
          duration: this.slideDuration,
          top: ypos,
          left: 0,
          onEnd: lang.hitch(this, function () { this._updateColor(true); FocusManager.focus(this.hueCursorNode); })
        }).play();
      } else {
        html.style(this.hueCursorNode, "top", ypos + "px");
        this._updateColor(true);
      }
    }
  });
});