1.0.3 • Published 4 years ago

rikaaa-paging v1.0.3

Weekly downloads
3
License
Apache-2.0
Repository
-
Last release
4 years ago

rikaaa-paging.js

rikaaa-paging is plugin in order to impliment asynchronous transition between website's page.
This plugin is using Ajax,History API and Generator.
The function of this plugin similar to pjax and barba.js.
Please see example.

Installation & Usage

import rikaaaPaging from "rikaaa-paging";

var entires = rikaaaPaging(
    ["#header", "#article", "#footer"],
    document.querySelectorAll("a")
);
<script src="rikaaa-paging/dist/rikaaa-paging.iife.js"></script>

var entires = self.rikaaaPaging(
    ["#header", "#article", "#footer"],
    document.querySelectorAll("a")
);

Progress

  1. The ahchor element was clicked. browser back | forward.
  2. The hookReady() method of this plugin will be triggerd.
  3. delay
  4. XMLHttpRequest
  5. The hookStart() method of this plugin will be triggerd.
  6. delay
  7. The website will be transformed.
  8. The hookEnd() method of this plugin will be triggerd.
  9. delay
  10. The hookResult() method of this plugin will be triggerd.
  11. history.pushState() method will be triggerd. The url was changed.
  12. back to list 1.

Constructor


var entires = rikaaaPaging(ArrayOfIdAttribute,NodeListOfAnchorElement);
argumentdescription
ArrayOfIdAttributeThe parameter to set array of html id attribute. The string of id attribute is equivalent with css selector. The HTML tag with this id will be updated.
NodeListOfAnchorElementsThe parameter to set nodelist of anchor element. The webpage transition and hookReady function will be start when this anchor elements clicked.

Methods

・entires.hookReady(function)


The method will be triggerd when the anchor element you seted clicked or browser back / forward.
The argument of this method is must be function with return own argument or function with return "false". If the return value is own argument,The process of this plugin will be continu. If the return value is false, The process of this plugin will be cancel.

var entires = rikaaaPaging(["#header", "#article", "#footer"],document.querySelectorAll("a"));

entires.hookReady(function(config) {
    config.currentUrl;
    config.href;
    config.afterDelay = 1000;
    config.onProgress = function(progressByPercent){
        console.log(progressByPercent);
    };
    config.onDelay = function(progress){
        console.log(progress);
    };

    return config;
});
parametertypedescription
config.currentUrlstringThe parameter is current url.
config.hrefstringThe parameter is new url. The XMLHttpRequest use this parameter with XMLHttpRequest.open method.
config.afterDelaynumberThe parameter is delay time. This parameter delay entires.hookStart() method. The default value is 0.
config.onProgressFunctionThe parameter is function. This function will be running while XMLHttpRequest.onprogress event triggring. The progress value of XMLHttpRequest will be assigned to argument of this function. This range of value is 0 to 100.
config.onDelayFunctionThe parameter is function. This function will be running while Delaying entires.hookStart() method. The progress value of delay will be assigned to argument of this function.

・entires.hookStart(function)


This method will be triggerd when XMLHttpRequest ended.
If you set "config.afterDelay" parameter with "hookReady" function,this function will be delay. The argument of this method is must be function with return own argument or function with return "false". If the return value is own argument,The process of this plugin will be continu. If the return value is false, The process of this plugin will be cancel.

var entires = rikaaaPaging(["#header", "#article", "#footer"],document.querySelectorAll("a"));



entires.hookStart(function(config) {
    config.ready;
    config.idAttributes;
    config.currentTargets;
    config.nextTargets;
    config.title;
    config.keywords;
    config.description;
    config.response;
    config.afterDelay;
    config.onDelay;

    return config;
});
parametertypedescription
config.readyRecord<string,any>The parameter is same as own argument of function assigned entires.hookReady() method's argument.
config.idAttributesArray of stringThe parameter is same as first argument of contructor.
onfig.currentTargetsRecord<string,Element>The parameter is Record. The key is string of id attribute. The value is Element. This Element will be overwrited by value of config.nextTargets.
config.nextTargetsRecord<string,Element>The parameter is Recorde. The key is string of id attribute. The value is Element. The Element will be added to curent DOM tree.
config.titlestringThe parameter is new content of title tag.
config.keywordsArray of stringThe parameter is new content of keywords.
config.descriptionstringThe parameter is new content of description.
config.responseRecode<string,any>The parameter is return value of XMLHttpRequest. However, this value is not parfect return value.
config.afterDelaynumberThe parameter is delay time. This parameter delay entires.hookEnd() method. The default value is 0.
config.onDelayFunctionThe parameter is function. This function will be running while Delaying entires.hookEnd() method. The progress value of delay will be assigned to argument of this function.

・entires.hookEnd()


This method will be triggerd when the dom overwrited.
If you set "config.afterDelay" parameter with "hookStart" function,this function will be delay. The argument of this method is must be function with return own argument or function with return "false". If the return value is own argument,The process of this plugin will be continu. If the return value is false, The process of this plugin will be cancel.

var entires = rikaaaPaging(["#header", "#article", "#footer"],document.querySelectorAll("a"));

entires.hookEnd(function(config) {
    config.idAttributes;
    config.previousTargets;
    config.updatedTargets;
    config.newUrl;
    config.ready;
    config.start;
    config.afterDelay;
    config.onDelay;

    return config;
});
parametertypedescription
config.idAttributesArray of stringThe parameter is same as first argument of contructor.
config.previousTargetsRecord<string,Element>The parameter is Record. The key is string of id attribute. The value is Element. This Element was already overwrited by config.updatedTargets value.
config.updatedTargetsRecord<string,Element>The parameter is Record. The key is string of id attribute. The value is Element. This Element was already added to DOM tree.
config.newUrlstringThe parameter is new url. This parameter is third argument history.pushstate() method.
config.readyRecord<string,any>The parameter is same as own argument of function assigned entires.hookReady() method's argument.
config.startRecord<string,any>The parameter is same as own argument of function assigned entires.hookStart() method's argument.
config.afterDelaynumberThe parameter is delay time. This parameter delay entires.hookResult() method. The default value is 0.
config.onDelayFunctionThe parameter is function. This function will be running while Delaying entires.hookResult() method. The progress value of delay will be assigned to argument of this function.

・entires.hookResult()

This method will be triggerd when just before history.pushState/history.replaceState.
If you set "config.afterDelay" parameter with "hookEnd" function. this function will be delay.
The argument of this method is function without return value.

var entires = rikaaaPaging(["#header", "#article", "#footer"],document.querySelectorAll("a"));

entires.hookResult(function(config) {
    config.oldUrl;
    config.newUrl;
    config.updatedTarget;
    config.previousTarget;
});
parametertypedescription
config.oldUrlstringThe parameter is old url. This url will be overwrite by new url.
config.newUrlstringThe parameter is new url.
config.updatedTargetRecord<string,Element>The parameter is Record. The key is string of id attribute. The value is Element. This Element was already added to DOM tree.
config.previousTargetRecord<string,Element>The parameter is Record. The key is string of id attribute. The value is Element. This Element was already overwrited by config.updatedTargets value.

・entires.curve(type,value)


The function of method will be easing value.

argumenttypedescription
typestringThe parameter to set easing type. The variety of this parameter is "LINER","EASE_IN","EASE_OUT","EASE_IN_OUT".
valuenumberThe parameter to set value. This value will be easing. The range of parameter is 0 to 1.

・entires.map(value,istart,istop,ostart,ostop)


The function of method is equivalent with map function of Processing.
Prease see https://processing.org/reference/map_.html

Browser Support

  • Google Chrome
  • Safari
  • Firefox
  • Edge
  • IE 11

License

Apache-2.0 © rikaaa.org