diff --git a/README.md b/README.md index 2cbd336..40db3e2 100644 --- a/README.md +++ b/README.md @@ -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 Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature. diff --git a/example/example.js b/example/example.js new file mode 100644 index 0000000..9f62b32 --- /dev/null +++ b/example/example.js @@ -0,0 +1,26 @@ +/* global Pjax */ +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) +}) + diff --git a/example/index.html b/example/index.html new file mode 100644 index 0000000..806338f --- /dev/null +++ b/example/index.html @@ -0,0 +1,15 @@ + + + + + Hello + + + + +
+

Index

+ hello. Go to Page 2 and view your console to see Pjax events. +
+ + diff --git a/example/page2.html b/example/page2.html new file mode 100644 index 0000000..b997abb --- /dev/null +++ b/example/page2.html @@ -0,0 +1,15 @@ + + + + + Hello + + + + +
+

Page 2

+ Hello. Go to Index. +
+ + diff --git a/package.json b/package.json index 2cecc0a..887bb3d 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "coverify": "^1.0.6", "jscs": "^1.6.2", "jshint": "^2.5.6", + "serve": "1.4.0", "tape": "^3.0.0", "testling": "^1.6.1" }, @@ -41,14 +42,20 @@ "test": "npm run lint && npm run standalone && testling", "test--html": "testling --html > tests/scripts/index.html", "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" }, "testling": { "files": "tests/**/*.js", "browsers": [ "ie/10..latest", - "firefox/4.0", "firefox/latest", "firefox/nightly", - "chrome/10", "chrome/latest", "chrome/canary", + "firefox/4.0", + "firefox/latest", + "firefox/nightly", + "chrome/10", + "chrome/latest", + "chrome/canary", "opera/12..latest", "opera/next", "safari/5.1..latest",