From 803b7c3cc42aa851eeeb5f949a0b8f536f0feaf6 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Wed, 20 May 2020 23:52:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A5=BC=E5=B1=82=E8=89=B2=E8=B0=83=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E9=80=89=E6=8B=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/editor_blockly.js | 3 +-- _server/editor_table.js | 17 +++++++++++++++++ _server/table/comment.js | 2 +- _server/thirdparty/jsColor.js | 36 ++++++++++++++++------------------- editor-mobile.html | 8 ++++---- editor.html | 8 ++++---- 6 files changed, 43 insertions(+), 31 deletions(-) diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 74325011..3d906c17 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -1169,9 +1169,8 @@ Blockly.FieldColour.prototype.createWidget_ = function() { setTimeout(function () { document.getElementById("colorPicker").value = getValue(); - window.jsColorPicker.confirm = setValue; // 设置位置 - triggerColorPicker(Blockly.WidgetDiv.DIV.style.left, Blockly.WidgetDiv.DIV.style.top); + openColorPicker(Blockly.WidgetDiv.DIV.style.left, Blockly.WidgetDiv.DIV.style.top, setValue); }); return document.createElement('table'); diff --git a/_server/editor_table.js b/_server/editor_table.js index d36d1da2..1e2e9e93 100644 --- a/_server/editor_table.js +++ b/_server/editor_table.js @@ -412,6 +412,7 @@ editor_table_wrapper = function (editor) { if (cobj._type === 'event') editor_blockly.import(guid, { type: cobj._event }); if (cobj._type === 'textarea') editor_multi.import(guid, { lint: cobj._lint, string: cobj._string }); if (cobj._type === 'material') editor.table.selectMaterial(input, cobj); + if (cobj._type === 'color') editor.table.selectColor(input); } /** @@ -426,6 +427,7 @@ editor_table_wrapper = function (editor) { if (cobj._type === 'event') editor_blockly.import(guid, { type: cobj._event }); if (cobj._type === 'textarea') editor_multi.import(guid, { lint: cobj._lint, string: cobj._string }); if (cobj._type === 'material') editor.table.selectMaterial(input, cobj); + if (cobj._type === 'color') editor.table.selectColor(input); } else if (editor_mode.doubleClickMode === 'add') { editor_mode.doubleClickMode = 'change'; editor.table.addfunc(guid, obj, commentObj, thisTr, input, field, cobj, modeNode) @@ -446,6 +448,21 @@ editor_table_wrapper = function (editor) { }) } + editor_table.prototype.selectColor = function (input) { + if (input.value != null) { + var str = input.value.toString().replace(/[^\d.,]/g, ''); + if (/^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(,0(\.\d+)?|,1)?$/.test(str)) { + document.getElementById('colorPicker').value = str; + } + } + var boundingBox = input.getBoundingClientRect(); + openColorPicker(boundingBox.x, boundingBox.y + boundingBox.height, function (value) { + value = value.replace(/[^\d.,]/g, ''); + input.value = '[' + value +']'; + input.onchange(); + }) + } + /** * 删除表格项 */ diff --git a/_server/table/comment.js b/_server/table/comment.js index 753dc71d..4cc774d4 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -464,7 +464,7 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { }, "color": { "_leaf": true, - "_type": "textarea", + "_type": "color", "_docs": "色调", "_data": "该层的默认画面色调。本项可不写(代表无色调),如果写需要是一个RGBA数组如[255,0,0,0.3]" }, diff --git a/_server/thirdparty/jsColor.js b/_server/thirdparty/jsColor.js index cbd9dee6..0d85e920 100644 --- a/_server/thirdparty/jsColor.js +++ b/_server/thirdparty/jsColor.js @@ -121,7 +121,7 @@ colorPickers.current = colorPickers[index]; } }, - createListener = function(e) { + createListener = function() { elm = document.getElementById("colorPicker"); var input = elm, position = window.ColorPicker.getOrigin(input), @@ -268,9 +268,19 @@ jsColorPicker('input.color', { size: 1, }); -function openColorFromButton() { - delete window.jsColorPicker.confirm; - triggerColorPicker('414px', '53px'); +function openColorPicker(px, py, callback) { + window.jsColorPicker.confirm = callback; + var colorPanel = document.getElementById('colorPanel'); + if (colorPanel.style.display=='none' && px != null && py != null) { + colorPanel.style.display = "inline-block"; + colorPanel.style.left = px + 'px'; + colorPanel.style.top = py + 'px'; + window.jsColorPicker.create(); + } + else { + colorPanel.style.display = 'none'; + delete window.jsColorPicker.confirm; + } } function confirmColor() { @@ -287,22 +297,8 @@ function confirmColor() { colorPicker.select(); document.execCommand("Copy"); } - - triggerColorPicker(); -} - -function triggerColorPicker(left, top) { - var colorPanel = document.getElementById('colorPanel'); - if (colorPanel.style.display=='none' && left && top) { - colorPanel.style.display = "inline-block"; - colorPanel.style.left = left; - colorPanel.style.top = top; - window.jsColorPicker.create(); - } - else { - colorPanel.style.display = 'none'; - delete window.jsColorPicker.confirm; - } + colorPanel.style.display = 'none'; + delete window.jsColorPicker.confirm; } // ------ AutoCompletion ------ diff --git a/editor-mobile.html b/editor-mobile.html index d5a712f2..cc699088 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -228,10 +228,6 @@ - @@ -249,6 +245,10 @@ +
diff --git a/editor.html b/editor.html index 3a4ffe01..afde3eb3 100644 --- a/editor.html +++ b/editor.html @@ -223,10 +223,6 @@
- @@ -244,6 +240,10 @@ +