Add example

This commit is contained in:
Rico Sta. Cruz
2015-11-13 10:40:59 +11:00
parent ad6292fffb
commit b20ee2261e
5 changed files with 69 additions and 2 deletions

View File

@@ -537,6 +537,12 @@ wrapper on each page (to avoid differences of DOM between pages)
--- ---
## Examples
Clone this repository and run `npm run example`, then open `http://localhost:3000/example` in your browser.
---
## Contributing ## Contributing
Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature. Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.

25
example/example.js Normal file
View File

@@ -0,0 +1,25 @@
console.log('Document initialized:', window.location.href)
document.addEventListener('pjax:send', function () {
console.log('Event: pjax:send', arguments)
})
document.addEventListener('pjax:complete', function () {
console.log('Event: pjax:complete', arguments)
})
document.addEventListener('pjax:error', function () {
console.log('Event: pjax:error', arguments)
})
document.addEventListener('pjax:success', function () {
console.log('Event: pjax:success', arguments)
})
document.addEventListener('DOMContentLoaded', function () {
var pjax = new Pjax({
selectors: ['.body']
})
console.log('Pjax initialized.', pjax)
})

15
example/index.html Normal file
View File

@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>Hello</title>
<script src='../pjax.js'></script>
<script src='example.js'></script>
</head>
<body>
<div class='body'>
<h1>Index</h1>
hello. Go to <a href='page2.html'>Page 2</a> and view your console to see Pjax events.
</div>
</body>
</html>

15
example/page2.html Normal file
View File

@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>Hello</title>
<script src='../pjax.js'></script>
<script src='example.js'></script>
</head>
<body>
<div class='body'>
<h1>Page 2</h1>
Hello. Go to <a href='index.html'>Index</a>.
</div>
</body>
</html>

View File

@@ -33,6 +33,7 @@
"coverify": "^1.0.6", "coverify": "^1.0.6",
"jscs": "^1.6.2", "jscs": "^1.6.2",
"jshint": "^2.5.6", "jshint": "^2.5.6",
"serve": "1.4.0",
"tape": "^3.0.0", "tape": "^3.0.0",
"testling": "^1.6.1" "testling": "^1.6.1"
}, },
@@ -42,14 +43,19 @@
"test--html": "testling --html > tests/scripts/index.html", "test--html": "testling --html > tests/scripts/index.html",
"coverage": "browserify -t coverify tests/**/*.js | testling | coverify", "coverage": "browserify -t coverify tests/**/*.js | testling | coverify",
"standalone": "browserify index.js --standalone Pjax > pjax.js", "standalone": "browserify index.js --standalone Pjax > pjax.js",
"example": "echo '\n==> Open http://localhost:3000/example in your browser.'; serve .",
"prepublish": "npm run standalone" "prepublish": "npm run standalone"
}, },
"testling": { "testling": {
"files": "tests/**/*.js", "files": "tests/**/*.js",
"browsers": [ "browsers": [
"ie/10..latest", "ie/10..latest",
"firefox/4.0", "firefox/latest", "firefox/nightly", "firefox/4.0",
"chrome/10", "chrome/latest", "chrome/canary", "firefox/latest",
"firefox/nightly",
"chrome/10",
"chrome/latest",
"chrome/canary",
"opera/12..latest", "opera/12..latest",
"opera/next", "opera/next",
"safari/5.1..latest", "safari/5.1..latest",