Giter Site home page Giter Site logo

find-in-nw's Introduction

"Find" in NW.js

Adds "Ctrl+F" find box to highlight text in the DOM

Animated example

Use

  1. npm install --save findinnw
  2. In your HTML file add:
    <script src="node_modules/findinnw/dist/find-in-nw.js"></script>
    <script>
      findInNw.initialize();
    </script>
  3. Use CTRL+F to display and give focus to the search box
  4. After typing, press ENTER to go to highlight/scroll to the next match.
  5. Use TAB to navigate to the "previous", "next", and "close" buttons.
  6. Use ENTER or SPACE to activate a button when focused.
  7. User ESC to hide the search box and return focus to the body

API

findInNw.initialize();

This is the initialization command. It must be ran once. Multiple attempts to run it are ignored.

findInNw.showSearchBox();

This is used to programmitcally display the search box. CTRL+F will still display it too.

findInNw.hideSearchBox();

This is used to programmitcally hide the search box. ESC will still hide it too.

findInNw.search('Text to find');

This is used to programmitcally find text.

findInNw.highlightNext(); and findInNw.highlightPrevious();

This will highlight and scroll to the next or previous match.

findInNw.clearTokens();

This is used to remove all the highlighted tokens.

Customizing Styles

Highlight tokens

All highlight tokens of matching searched text will be wrapped in a <mark class="find-in-nw-token">searched text</mark>.

They will also contain a data-find-in-nw-position="4" data attribute, the number correlates to a zero-based index of all matches.

As you navigate from one match to the next, the currently selected match will have a class of .find-in-nw-current-token.

You can customize this by targeting the following

mark.find-in-nw-token {
    background-color: #00F;
}

mark.find-in-nw-current-token {
    background-color: #38D878;
}

Search Box

Each element of the search box is styled by targeting a class. They also all have a matching ID that you can target to override them.

/* The container for the input/count/close */
#find-in-nw-search-box {}

/* The input field you type in */
#find-in-nw-input {}

/* The current selected match number. Ex: The number 1 in "1/5" */
#find-in-nw-current {}

/* The separator between the current and count. Ex: The slash (/) in "1/5" */
#find-in-nw-of {}

/* The count of matching highlighted items. Ex: The number 5 in "1/5" */
#find-in-nw-count {}

/* The previous and next buttons, ∧ and ∨ */
#find-in-nw-previous {}
#find-in-nw-next {}

/* The × close button */
#find-in-nw-close {}

Contributing

  1. Create an issue first for your desired improvements and how you think they should be implemented.
  2. If plan is approved (or no response given in a timely manner), then you can submit a PR.
  3. Make sure to run npm run validate prior to submitting your PR and fix any errors or warnings.

find-in-nw's People

Contributors

suziwen avatar thejaredwilcurt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.