1.0.1 • Published 6 years ago

pjax-router v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

PjaxRouter

Pjax Router for static websites.

Latest NPM release MIT License

demos

supported

IE10+ and others.

Usage

Both standalone lib and NPM package are available.

Standalone

<script src="./js/PjaxRouter.js"></script>

NPM

$ npm install --save pjax-router

then

import PjaxRouter from 'pjax-router';

var router = new PjaxRouter( {
	// trigger for Pjax link
	triggers: [ 'a' ],
	// ignore selectors for Pjax link
	ignores: [ 'a.ignore' ],
	// replace target areas
	selectors: [ 'title', '.sandbox1', '.sandbox2' ],
	// callback for page transition. called when ajax has done
	switches: {
		'title': function ( newEl, oldEl ) {

			document.title = newEl.innerHTML;

		},
		'.sandbox1': function ( newEl, oldEl ) {

			document.querySelector('.sandbox1').innerHTML = newEl.innerHTML;

		},
		'.sandbox2': function ( newEl, oldEl ) {

			document.querySelector('.sandbox2').innerHTML = newEl.innerHTML;

		}
	}
} );

// events
router.on( 'beforeload',   function () { console.log( 'beforeload' );   } );
router.on( 'load',         function () { console.log( 'load' );         } );
router.on( 'beforeswitch', function () { console.log( 'beforeswitch' ); } );
router.on( 'afterswitch',  function () { console.log( 'afterswitch' );  } );
router.on( 'error',        function () { console.log( 'error' );        } );
1.0.1

6 years ago

1.0.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago