Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/willdurand/anchorify.js

A dead simple JavaScript library for automatically creating anchored headings in your HTML documents.
https://github.com/willdurand/anchorify.js

Last synced: about 2 months ago
JSON representation

A dead simple JavaScript library for automatically creating anchored headings in your HTML documents.

Awesome Lists containing this project

README

        

Anchorify.js
============

[![Build Status](https://travis-ci.org/willdurand/anchorify.js.png?branch=master)](https://travis-ci.org/willdurand/anchorify.js)

Anchorify.js is a dead simple JavaScript library for automatically creating
anchored headings in your HTML documents. It guarantees uniqueness of the anchor
names, and is able to reuse existing ids.

It can be used either as a jQuery plugin, or as a standalone library without any
dependencies (except `querySelectorAll()`).

Usage
-----

It could not be easier as Anchorify.js provides a jQuery plugin out of the box:

``` javascript
$('h2 h3').anchorify();
```

Anchorify.js generates clean anchor names:

``` html

Hello, World!

Hello, World!


```

By default, it uses the `¶` sign for the links' text, and adds an `anchor-link`
CSS class on each link.

However, you can configure your own text, CSS class and anchor position using
the `text`, `cssClass` and `position` options:

``` javascript
$('h2').anchorify({ text: 'Hey', cssClass: 'anchor', position: 'prepend' });
```

``` html


HeyHello, World!


```

Running the Tests
-----------------

Open the `tests/index.html` file in your browser or use
[PhantomJS](http://phantomjs.org/):

phantomjs tests/run-qunit.js file:///.../anchorify.js/tests/index.html

License
-------

Anchorify.js is released under the MIT License. See the bundled LICENSE file for
details.