Skip to content

Commit

Permalink
Added no query shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj Nandan Sharma authored and Raj Nandan Sharma committed Dec 25, 2022
1 parent 0f820fe commit 9c88761
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 34 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You can register any key. To trigger, it will bind an event with your specified
## Installation
From CDN
```
<script src="https://cdn.jsdelivr.net/gh/rajnandan1/[email protected].6/dist/floodlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/rajnandan1/[email protected].7/dist/floodlight.min.js"></script>
```
From NPM
```
Expand All @@ -35,6 +35,26 @@ if (typeof window !== 'undefined') {
let fl = floodlight();
}
```
## Basic Usage - Implement a call to a function a

The below code implements a function that will trigger an alert box with a Hello World. It will listen for the a key. When someone presses a it will run.
```
let fl = new FloodLight();
//this takes to parameters. first parameter is the `key`, second is the description
let cmdHelloWorld = fl.addCommand("a", "Alert hello world");
//Implement a function that would handle the query
let helloWorld = function() {
alert("hello world")
};
//Add the action for a command. Takes a function as first param
cmd.addAction(helloWorld);
//Start floodlight. It will start listening
fl.run();
```
## Basic Usage - Implement a quick google search `g`

The below code implements a google search using floodgate. It will listen for the `g` key. When someone presses `g` it will show a search box.
Expand Down
28 changes: 14 additions & 14 deletions dist/floodlight.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions es6/floodlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ class FloodLight {
let colorItem = "#fff";
let colorItemActive = "#efefef";
let fontColor = "#1A1A40";
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
colorItem = "#111";
colorItemActive = "#231e24";
fontColor = "#efefef";
Expand Down Expand Up @@ -200,7 +197,11 @@ class FloodLight {
if (this.parameters === undefined) {
this.parameters = [];
}
if (!Array.isArray(params) || params.length == 0) {
if(typeof params === "function"){
fn = params;
params = [];
desc = "";
} else if (!Array.isArray(params) || params.length == 0) {
throw new Error("First parameter should be a non-empty array");
}
this.parameters.push({
Expand Down Expand Up @@ -362,6 +363,10 @@ class FloodLight {
// document.getElementById("bisar-input").addEventListener("input", searchInput);
}
function addContainer(ix) {
if(allCommands[ix].parameters[0].params.length == 0){
allCommands[ix].parameters[0].fn();
return;
}
let bisarMainDiv = document.getElementById(wrapper);
if (bisarMainDiv === null) {
const template = document.createElement("div");
Expand Down
Loading

0 comments on commit 9c88761

Please sign in to comment.