Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close search when clicked outside #2502

Merged
merged 4 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,22 @@ function Activity() {

searchBlockPosition = [100, 100];
prepSearchWidget();
let closeListener = (e) => {
if (docById("search").style.visibility == "visible" &&
(e.target === docById("search") || docById("search").contains(e.target))) {
//do nothing when clicked in the input field
}
else if (docById("ui-id-1").style.visibility == "visible" &&
(e.target === docById("ui-id-1") || docById("ui-id-1").contains(e.target))) {
//do nothing when clicked on the menu
}
else {
hideSearchWidget();
document.removeEventListener("mousedown", closeListener);
}
};
document.addEventListener("mousedown", closeListener);

// Give the browser time to update before selecting
// focus.
setTimeout(function() {
Expand Down
17 changes: 2 additions & 15 deletions js/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,6 @@ function Palettes() {
return;
}

if (name == "search" && this.showSearchWidget !== null) {
for (var i in this.dict) {
if (this.dict[i].visible) {
this.dict[i].hideMenu();
this.dict[i]._hideMenuItems();
}
}

console.debug("searching");
this.dict[name].visible = true;
this.showSearchWidget(true);
return;
}

this.hideSearchWidget(true);

// for (var i in this.dict) {
Expand Down Expand Up @@ -394,7 +380,7 @@ function Palettes() {
document.body.style.cursor = "pointer";
}
row.onclick = (evt) => {
if (name == "search")this.showSearchWidget();
if (name == "search") this.showSearchWidget();
else this.showPalette(name)
}
row.onmouseup = (evt) => {
Expand Down Expand Up @@ -1049,6 +1035,7 @@ function Palette(palettes, name) {

this.makeBlockFromSearch = function(protoblk, blkname, callback) {
this._makeBlockFromPalette(protoblk, blkname, callback);
this.palettes.hideSearchWidget();
};

this._makeBlockFromPalette = function(protoblk, blkname, callback) {
Expand Down