AjaxとpushStateを使った非同期ページ書き換えライブラリ
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
dest
docs
src
.gitignore
LICENSE
gulpfile.js
package-lock.json
package.json
readme.ja.md
readme.md

readme.md

tjax

Asynchronous page replacement JavaScript library using Ajax and pushState.

Download

tjax.js

Demo

https://totoraj930.github.io/tjax

Usage

Basic

<!DOCTYPE html>
<html lang="en">
<head>
    <title>tjax</title>
    <script src="tjax.js"></script>
    <script>
        var tjax = new Tjax();

        if (!tjax.isSupported()) return;

        document.addEventListener("click", function (event) {
            var target = event.target;
            if (target.hasAttribute("data-tjax")) {
                event.preventDefault();
                event.stopPropagation();
                tjax.load(target.href);
                return false;
            }
        });
    </script>
</head>
<body>
    <a href="./page2.html" data-tjax>Go to page2</a>
</body>
</html>

API

Tjax.setOptions

Set the option.

See Options.

tjax.setOptions({
    areas: ["#replace_area", "#foot"],
    wait: 400
});

Tjax.load

Load the page according to the option and replace the elements.

tjax.load("./page-2.html");

Tjax.isSupported

Return whether it supports browsers.

tjax.isSupported();

Options

Name Description Default
areas Selector array of elements to replace ["body"]
wait Wait time to replace(ms) 0
changeTitle Whether to change the title true
loadScript Whether to load the script true
controlScroll Whether to control the scroll true
waitPopState Whether to use "wait" for "onpopstate". true
onErrorNotMove Please feel it!!!(I can not write English!!!) false

Events

All events dispatch to "document".

Name Description
tjax:start When processing is started
tjax:loaded When XMLHttpRequest completed
tjax:error When an error occurs
tjax:end When processing is completed

Supported Browsers

  • Google Chrome
  • Firefox
  • IE10+
  • Edge

Do not know

  • Safari

Author

Reona Oshima (totoraj)

License

Copyright © 2017 Reona Oshima (totoraj)
This work is released under the MIT License.
http://opensource.org/licenses/mit-license.php