/////////////////////////////////////////////////////////////////////////// // 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/_base/Color', 'dojo/query', "jimu/dijit/ColorChooser", 'jimu/dijit/CustomColorPicker', 'jimu/dijit/ColorRecords', 'dijit/popup', 'jimu/utils', "dijit/a11yclick" ], function (Evented, declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, lang, html, on, Color, query, ColorChooser, CustomColorPicker, ColorRecords, dojoPopup, jimuUtils, a11yclick) { return declare([_WidgetBase, _WidgetsInTemplateMixin, _TemplatedMixin, Evented], { templateString: "
", baseClass: 'jimu-color-palette', declaredClass: 'jimu.dijit.ColorPalette', _TRANSPARENT_STR: "rgba(0, 0, 0, 0)", value: "",//typeof dojoColor _defaultAppearance: { showTransparent: true, showColorPalette: true, showCoustom: true, showColorPickerOK: false,//ok btn showColorPickerApply: true,//apply btn showCoustomRecord: true, closeDialogWhenChange: false//close colorPalette dialog, when color changed }, recordUID: "",//uid for colorRecords postMixInProperties: function () { this.nls = window.jimuNls.colorPalette; }, postCreate: function () { this.inherited(arguments); //default color if (this.value) { this.value = new Color(this.value); } else { this.value = new Color('#fff'); } this._createContent(); }, initUI: function () { //restore init ui var isTirggerEvent = false; this._toggleCustomColorPicker("init", isTirggerEvent); }, _createContent: function () { this.appearance = lang.mixin(this._defaultAppearance, this.appearance); var tooltipDialogContent = html.create("div", { "class": "jimu-colorpalette" }, this.domNode); this.initPanel = html.create("div", { "class": "init-panel" }, tooltipDialogContent); this.customPanel = html.create("div", { "class": "custom-panel hide" }, tooltipDialogContent); if (this.appearance.showTransparent) { this._createSpecialColors( this.initPanel); } if (this.appearance.showColorPalette) { this._createColorChooser( this.initPanel); } if (this.appearance.showCoustom) { this._createCustomColorPicker( this.initPanel); } if (this.appearance.showCoustom && this.appearance.showCoustomRecord) { this._createCoustomRecord( this.initPanel); } }, setColor: function (newColor) { if (!this._isColorEqual(newColor)) { this.value = new Color(newColor); this._setSpatialColor(this.value); if ("undefined" !== typeof this.value.a && 0 === this.value.a) { //"transparent" this.colorChooser.setColor(new Color('transparent'), false); this.picker.setColor(new Color("#fff"), false);//set white color for picker, as "transparent" } else { //not "transparent" this.colorChooser.setColor(this.value.toHex(), false);//hex work,only this.picker.setColor(this.value, false); } if (this.colorRecords) { this.colorRecords.selecteColor(this.value); } } }, getColor: function () { return this.value; }, changeColor: function(isClose){ if ("undefined" !== typeof this.value.a && 0 === this.value.a) { this.onChange(this.value); } else { this.onChange(this.value.toHex()); } this.emit("change", this.value); if (true === this.appearance.closeDialogWhenChange && isClose !== false//DO NOT close dialog, when apply click ) { this._closeDialog(); } }, refreshRecords: function () { if (this.colorRecords) { this.colorRecords.refresh(); } }, destroy: function () { dojoPopup.close(this.tooltipDialog); this.picker.destroy(); this.inherited(arguments); }, //1.SpecialColors _createSpecialColors: function (tooltipDialogContent) { var specialColorDom = html.create("div", { "class": "special-color" }, tooltipDialogContent); this.transparentBtn = html.create("div", { "class": "transparent btn", innerHTML: '