Skip to content

gabrielcorado/anchor_data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Anchor Data

Use anchor as query string.

Table of contents

How it works

The lib use document.location.hash to store information like query string. If you have a compound data the lib store it with a valueDelimiter which by default is = then we would have key=value. You can also store simple data in this case the lib use only the key. Is possible to store more than one data, that will be separated by delimiter which by default is &.

API

insert

To insert you can pass 3 arguments are:

  • String key
  • String value
// Simple
AnchorData.insert('flag'); // Inserts #flag

// Compound
AnchorData.insert('compound', 'value'); // Insert #compound=value

remove

Remove a data.

AnchorData.remove('flag'); // Removes #flag

AnchorData.remove('compound'); // Removes #compound=new_value

get

Get data value

// Simple
AnchorData.get('flag'); // Returns true

// Compound
AnchorData.get('compound'); // Returns 'new_value'

// Not set
AnchorData.get('notset'); // Returns false

Events

The lib emits some events to improve usage.

List

  • dataUpdated
  • dataInserted
  • dataRemoved

Usage

window.addEventListener('dataUpdated', function(e) {
  ...
});

About

Use anchor as query string

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published