Search Blockly

This commit is contained in:
oc 2018-12-13 22:43:28 +08:00
parent 71f03ffbfe
commit 8d31055c52
4 changed files with 25 additions and 13 deletions

View File

@ -393,7 +393,7 @@ table.row td {
display: none !important;
}
#blockSearch {
#searchBlock {
width: 100px;
background-color: #E9EBF2;
border-radius: 10px;
@ -407,6 +407,6 @@ table.row td {
height: 15px;
position: absolute;
left: 6px;
top: 7px;
top: 6px;
background-image:url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGJhc2VQcm9maWxlPSJmdWxsIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4bWxuczpldj0iaHR0cDovL3d3dy53My5vcmcvMjAwMS94bWwtZXZlbnRzIj4KPGc%2BCgk8cG9seWdvbiBmaWxsPSIjNjY2IiBwb2ludHM9IjkuMjA3LDYuMTI2IDcuNzkzLDcuNTQxIDExLjc5MywxMS41NDEgMTMuMjA3LDEwLjEyNiIgLz4KCTxwYXRoIGZpbGw9IiM2NjYiIGQ9Ik01LjkxNywyYzEuNjA4LDAsMi45MTcsMS4zMDgsMi45MTcsMi45MTdTNy41MjUsNy44MzMsNS45MTcsNy44MzNTMyw2LjUyNSwzLDQuOTE3UzQuMzA4LDIsNS45MTcsMgoJCSBNNS45MTcsMEMzLjIwMSwwLDEsMi4yMDEsMSw0LjkxN3MyLjIwMSw0LjkxNyw0LjkxNyw0LjkxN3M0LjkxNy0yLjIwMSw0LjkxNy00LjkxN0MxMC44MzMsMi4yMDEsOC42MzIsMCw1LjkxNywwTDUuOTE3LDB6IiAvPgo8L2c%2BCjwvc3ZnPgo%3D');
}

View File

@ -313,7 +313,7 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){
var doubleClickCheck=[[0,'abc']];
function omitedcheckUpdateFunction(event) {
if(event.type==='move'){
if(event.type==='create'){
editor_blockly.addIntoLastUsedType(event.blockId);
}
if(event.type==='ui'){
@ -559,27 +559,32 @@ function omitedcheckUpdateFunction(event) {
if(!b)return;
var blockType = b.type;
if(!blockType || blockType.indexOf("_s")!==blockType.length-2 || blockType==='pass_s')return;
console.log(b);
editor_blockly.lastUsedType = editor_blockly.lastUsedType.filter(function (v) {return v!==blockType;});
if (editor_blockly.lastUsedType.length >= editor_blockly.lastUsedTypeNum)
editor_blockly.lastUsedType.pop();
editor_blockly.lastUsedType.unshift(blockType);
document.getElementById("searchBlock").value='';
}
// Index from 1 - 9
editor_blockly.openToolbox = function(index) {
var element = document.getElementById(':'+index);
if (element == null || element.getAttribute("aria-selected")=="true") return;
element.click();
// var element = document.getElementById(':'+index);
// if (element == null || element.getAttribute("aria-selected")=="true") return;
// element.click();
editor_blockly.workspace.toolbox_.tree_.setSelectedItem(editor_blockly.workspace.toolbox_.tree_.children_[index-1]);
}
editor_blockly.reopenToolbox = function(index) {
var element = document.getElementById(':'+index);
if (element == null) return;
if (element.getAttribute("aria-selected")=="true") element.click();
element.click();
// var element = document.getElementById(':'+index);
// if (element == null) return;
// if (element.getAttribute("aria-selected")=="true") element.click();
// element.click();
editor_blockly.workspace.toolbox_.tree_.setSelectedItem(editor_blockly.workspace.toolbox_.tree_.children_[index-1]);
editor_blockly.workspace.getFlyout_().show(editor_blockly.workspace.toolbox_.tree_.children_[index-1].blocks);
}
editor_blockly.closeToolbox = function() {
/*
for (var i=1; i<=10; i++) {
var element = document.getElementById(':'+i);
if (element && element.getAttribute("aria-selected")=="true") {
@ -587,9 +592,11 @@ function omitedcheckUpdateFunction(event) {
return;
}
}
*/
editor_blockly.workspace.toolbox_.clearSelection();
}
var searchInput = document.getElementById("blockSearch");
var searchInput = document.getElementById("searchBlock");
searchInput.onfocus = function () {
editor_blockly.reopenToolbox(9);
}

View File

@ -179,6 +179,11 @@
<button onclick="editor_blockly.confirm()">确认</button>
<button onclick="editor_blockly.parse()">解析</button>
<button onclick="editor_blockly.cancel()">取消</button>
<!-- 手机端放不下,因此不显示搜索框 -->
<div style="display: none">
<div class="searchLogo"></div>
<input type="text" id="searchBlock" placeholder="搜索图块"/>
</div>
<xml id="toolbox" style="display:none">
</xml>
</h3>

View File

@ -180,7 +180,7 @@
<button onclick="editor_blockly.cancel()">取消</button>
<div style="position: relative; display: inline-block; margin-left: 10px">
<div class="searchLogo"></div>
<input type="text" id="blockSearch" placeholder="搜索图块"/>
<input type="text" id="searchBlock" placeholder="搜索图块"/>
</div>
<xml id="toolbox" style="display:none">
</xml>