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

pastpresentfuture

v0.1.6

Published

Where have we been? Where are we going?

Downloads

23

Readme

PastPresentFuture

A JavaScipt library for manipulating browser history with pushState and AJAX.

Introduction

PastPresentFuture is a JavaScript library for interacting with history.pushState() while loading internal URLs with AJAX. The goal is to maintain a single load of CSS and JS assets per user session, speeding up page changes for time-on-site retention with increased page views. Below you will find documentation on its configuration and usage.

Installation

Bower

Use the Bower package manager to install PastPresentFuture into your project. To do so you can either use the CLI:

$ bower install pastpresentfuture --save

Or define it in your bower.json manifest:

    "dependencies": {
        "pastpresentfuture": "latest"
    }

npm

Similarly, PastPresentFuture can be installed using npm. To do so you can either use the CLI:

$ npm install pastpresentfuture --save

Or define it in your package.json manifest:

    "dependencies": {
        "pastpresentfuture": "latest"
    }

Direct download

If package managers are not your thing, the library can be downloaded directly from GitHub using the Download ZIP button.

Basic Usage

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>PastPresentFuture Usage</title>
    <script src="jquery.js"></script>
    <script src="PastPresentFuture.min.js"></script>
</head>
<body>
    <!--
    This is the main container with content that can be changed.
    -->
    <div class="page_content_holder"></div>

    <script type="text/javascript">
        ( function () {

            PastPresentFuture();

        } () );
    </script>
</body>
</html>

Configuration

| key | type | | -------------------------------------------- | -------- | | content | String | | ajaxContainer | String | | prefetchCacheLimit | Integer | | ajaxCacheLimit | Integer | | onParseHtml | Function |

Example Configuration:

{
    content: '.page_content_holder',
    ajaxContainer: '.page_content_holder',
    prefetchCacheLimit: 15,
    ajaxCacheLimit: 15
}

content

Type: String

Default: '.page_content_holder'

Description: The wrapper that contains the dynamic aspects of the page to be replaced.

:arrow_up:

ajaxContainer

Type: String

Default: '.page_content_holder'

Description: The wrapper that new content will be applied. This defaults the current container, but can be used for a new container if an animation affect is desired.

:arrow_up:

prefetchCacheLimit

Type: Integer

Default: 15

Description: This declares the number of pages that are stored in the prefetch cache. The prefetch cache is set by a flag on the next article it increase the load of that page.

:arrow_up:

ajaxCacheLimit

Type: Integer

Default: 15

Description: This declares the limit of the cache on pages that have already been visited that are not already in the prefetch cache.

:arrow_up:

onParseHtml

Type: Function

Default: None.

Description: Callback to filter the HTML before insertion into the DOM. Must return the HTML collection.

:arrow_up:

Events

Custom jQuery events prefixed with PastPresentFuture.

| event | trigger source | | ---------------------------------------------------------------------------- | --------------- | | PastPresentFuture:AfterInitState | internal | | PastPresentFuture:PushState | internal | | PastPresentFuture:NewState | internal | | PastPresentFuture:PopState | internal | | PastPresentFuture:LoadingReveal | internal | | PastPresentFuture:LoadingComplete | internal | | PastPresentFuture:GotoUrl | both | | PastPresentFuture:RecordPageview | internal | | PastPresentFuture:RenderUrl | internal | | PastPresentFuture:FetchedData | internal | | PastPresentFuture:BeforeTransition | internal | | PastPresentFuture:AnimateTransition | internal | | PastPresentFuture:ResetPage | internal |

PastPresentFuture:AfterInitState

Description: Called on initial load and after pushState.

:arrow_up:

PastPresentFuture:PushState

Description: An event wrapper for history.pushState(). It is called before render of AJAX data.

Parameter: options {Object}

| name | type | description | | ---------- | ------- | --------------------------------------------- | | url | String | The url to push into the brower’s history. | | popstate | Boolean | Whether this is a popstate event. Optional. | | title | String | The page title for the new url. Optional. |

:arrow_up:

PastPresentFuture:NewState

Description: Called after pushState.

:arrow_up:

PastPresentFuture:PopState

Description: This event is called when the history is changed by browser forward and back buttons.

:arrow_up:

PastPresentFuture:LoadingReveal

Description: Called while data from the new page is being loaded into memory.

:arrow_up:

PastPresentFuture:LoadingComplete

Description: Called just before data is rendered to the DOM.

:arrow_up:

PastPresentFuture:GotoUrl

Description: A trigger to be used for loading a new page. Accepts the URL and Options for pushState.

Parameters:

url {String} The url of the page to go to. options {Object}

| name | type | description | | ---------- | ------- | ------------------------------------------- | | url | String | The url of the page to go to. | | popstate | Boolean | Optional, set to false by default. | | options | Object | Optional, specifically used for pushState. |

:arrow_up:

PastPresentFuture:RecordPageview

Description: Called on init state, passes the current URL and page title.

:arrow_up:

PastPresentFuture:RenderUrl

Description: This event is called after a page is fetch for processing the data.

:arrow_up:

PastPresentFuture:FetchedData

Description: Event for passing data if a page has already been cached.

:arrow_up:

PastPresentFuture:BeforeTransition

Description: This event is called when the content and ajaxContainer set in the Config aren’t the same.

Parameter: containers {Object}

| name | type | description | | --------------- | ----- | --------------------------------------------------- | | contentHolder | Array | jQuery selection for the content element. | | ajaxContainer | Array | jQuery selection for the ajax container element. |

:arrow_up:

PastPresentFuture:AnimateTransition

Description: This event is called when the content and ajaxContainer set in the Config aren’t the same. It's called after LoadingComplete is triggered.

:arrow_up:

PastPresentFuture:ResetPage

Description: This event is fired when the library tries to reload the page it is already on. This is particularly useful if the current page has javascript elements that need to be reset.

:arrow_up:

Contributing

Coding Style

PastPresentFuture follows the WordPress JavaScript Coding Standards. There is a .jscsrc included in the project for automatic linting using JSCS.

The modules are written in the UMD pattern to support AMD, CommonJS, and global usage.

Development

The project contains a gulpfile.js for concatenation and minification. To use first install gulp and the dependencies (npm install). The default gulp task (gulp) will start the watch task.

Dependencies

PastPresentFuture requires jQuery.