GithubHelp home page GithubHelp logo

lexx27 / currentjs Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 290 KB

Helps to automatically highlight current and active links in menu http://lexx27.github.io/currentjs/

License: MIT License

JavaScript 100.00%

currentjs's Introduction

currentjs

Helps to automatically highlight current and active links in menu etc <li class="active"><a href="#" class="active">current link</a></li>

Usage

Just call currentjs

$('.selector a').currentjs();

Parameters

$('.selector a').currentjs(params);

parentElement: Do you want to add an active class to the parent elemnt? ex. 'li'. default false
classname: The class name inserted to the active links. default 'active'
startonly: In some cases you want to activate a link that only contains a part only of the url path. For example if your are at http://yoursite.com/admin/user you would like a link with href /admin/ to be considered as active. Because you are in the admin area. default false
async: Add the active class when clicking on a menu link. Useful for applications that combine menu with ajax and ordinary links. default: false
segments: You can set how many segment will the scripts check. For example, Lets say that you are at the url https://github.com/lexx27/currentjs/wiki and your navigation href has https://github.com/lexx27/currentjs. In order to be considered as active you have to set segments as 2. It will compare only the fitst two url segments

Full example

Lets say we have the following html code

<ul id="mysupernav">
  <li><a href="/">Home</a></li>
  <li><a href="/about">About</a></li>
  <li><a href="/contact">Contact</a></li>
</ul>

And that we are at http://yoursite.com/about And you want to insert an active class named "current" at both the a and the li elements.

$('#mysupernav a').currentjs({
  parentElement: 'li',
  classname: 'current,
  startonly: true,
  segments: false
});

Notes

  • It works for both relative and absolute links
  • The current readme file took me more time than the actual code. So it should certainly needs some more work

currentjs's People

Contributors

lexx27 avatar missfahrenheit avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

missfahrenheit

currentjs's Issues

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.