npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

skylark-router

v0.9.5

Published

An Elegant HTML5 Routing Framework.

Downloads

24

Readme

skylark-router

An elaborate front-end routing framework.

Features

  • Support Hashbang, HTML5 pushstate, internal implementation three routing mode, the routing mode can be set by attributes or automatically by the framework, without affecting the implementation of the application.
  • Supports global events to implement hooker functions.
  • Lightweight, even if allinone is only 13k(minified),5k(gzip)

Dependences

| Project | Status | Description | |---------|--------|-------------| | skylark-langx   | v0.9.1 | Javascript language extension library |

Different builds

| | build | Description | |---------|--------|-------------| | full | skylark-router-all.js | included skylark-langx | | only router | skylark-router.js | not included skylark-langx | | full (development) | uncompressed/skylark-router-all.js | included skylark-langx | | only router (development)| uncompressed/skylark-router.js | not included skylark-langx |

Installation

There are multiple ways to install the skylark-router library.

  • cdn
    http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/skylark-router-all.js or
    http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/uncompressed/skylark-router-all.js
  • npm
    npm install skylark-router --save
  • bower
    bower install skylark-router

Usage

Refence router module object.

  • Using the skylark-router library for a AMD module.
require({
  'paths': {
     'skylark-langx': 'http://registry.skylarkjs.org/packages/skylark-langx/v0.9.1/skylark-langx',
     'skylark-router': 'http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/skylark-router' 
  }
}, ['skylark-router'], function(srouter) {
  // srouter.route(path,setting);
});
  • Using the skylark-router library for a global object named skylarkjs.
<script type="text/javascript" src="http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/skylark-router-all.js"></script>
<script>
  // skylarkjs.router.route(path,setting);
</script>
  • Using the skylark-router library for a AMD package.
require({
  'packages': [
    { 'name': 'skylark-langx', 'location': 'http://registry.skylarkjs.org/packages/skylark-langx/v0.9.1/skylark-langx/' },
    { 'name': 'skylark-router', 'location': 'http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/skylark-router/' }
  ]
}, ['skylark-router/router'], function(srouter) {
  // srouter.route(path,setting);
});

Add route defines.

var homeRoute = router.route('home', { 
    pathto : '/', 
    entered (){ 
        $("#yield").html($('#home').html()); 
    }      
}); 
             
var pageRoute = router.route('page', { 
    pathto : '/page/:id', 
    entered(e){ 
        $("#yield").html($('#page' + e.params.id).html()); 
    } 
}); 

add callback function for route.

When the route is changed, the following event are triggered in order.

  1. exiting (for previous route)
  2. entering (for new route)
  3. entered (for new route)
  4. exited (for previous route)

In adding route at the same time, you can add the same name of the callback function, after the route is added,you can also add callback function for these events.

homeRoute.on("exited",function(){ 
   console.log('good bye Home'); 
}); 

pageRoute.on("exited",function(){ 
    var field = $('[name="field"]').val(); 
    if (field) { 
        return confirm('Are you sure you want to quit this page ?'); 
    }            
}); 

Start router.

srouter.start(); 

Hooker

The router supports global events and you can implement hooker functions by listening to global events. Built-in global events have routing before current route change and routed after current route change.

router.on("routed",function(e){ 
    var links = $("a.active"); 

    links.removeClass("active"); 

    links = $("a[href=\"" + e.current.path + "\"]"); 
    links.addClass("active"); 
    links[0].focus(); 
}); 

Select engine

The router support the following three routing engines.

  1. html5 history API egine
  2. hash egine
  3. internal management engine

The useHistoryApi attribute and useHashbang attribute of router object are used to control which engine is used:

  • useHistoryApi === null && useHashbang===null (default)
    The router automatically determine which engine to use, if running on the web, he html5 history API egine is used; if running in the local file system, The internal egine is used.
  • useHistoryApi === true
    The html5 history API egine is used.
  • useHistoryApi !== true && useHashbang===true
    The hash egine is used.
  • useHistoryApi === false && useHashbang===false
    The internal management engine is used.

API Document

  • baseUrl()
  • current()
  • go()
  • map()
  • off()
  • on()
  • one()
  • path()
  • previous()
  • Route
    • Route.prototype.match
    • Route.prototype.path
  • route()
  • routes()
  • start()
  • trigger()

Examples

Please access the following site for the execution of each example program under the "/examples" directory.

  • http://examples.skylarkjs.org/skylark-router/

Building skylark-router

  • Ensure that Node.js is installed.
  • Run npm gulp -g to ensure gulp is installed.
  • Run npm install to ensure the required dependencies are installed.
  • change current directory to build/, and run gulp. The builds will be placed in the dist/ directory.

Integration

This library is completely built-in on skylark-spa, and when you use skylark-spa or skylark.js to develop an application, you do not have to use this library's API directly

License

Released under the MIT