diff --git a/dist/display.es6.js b/dist/display.es6.js index cedfac9..1373d1c 100644 --- a/dist/display.es6.js +++ b/dist/display.es6.js @@ -314,6 +314,15 @@ class DisplayJS { document.addEventListener("DOMContentLoaded", fn); } } + scroll (callback) { + window.addEventListener("scroll", callback); + } + scrollTo (x, y) { + window.scroll(x, y); + } + scrollTop (el = [document.body]) { + return el[0].scrollTop; + } show(element) { element[0].style.display = "block"; return true; diff --git a/dist/display.es6.min.js b/dist/display.es6.min.js index 58a3112..9d8a205 100644 --- a/dist/display.es6.min.js +++ b/dist/display.es6.min.js @@ -1 +1 @@ -class DisplayJS{constructor(a){this.obj=a}var(a){const b=()=>{this.if(),this.else();const a=document.querySelectorAll("[var]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}render(a){this.var(a)}renderVariables(a){this.var(a)}xss(a){const b=//g,d=/'/g,e=/"/g;return a.toString().replace(b,"<").replace(c,">").replace(d,"'").replace(e,""")}xssURI(a){return encodeURI(a)}target(b=()=>{this.var()}){const c=(()=>{return document.addEventListener?(a,b,c)=>{a.addEventListener(b,c,!1)}:(a,b,c)=>{a.attachEvent(`on${b}`,c)}})(),d=this.obj;[].forEach.call(document.querySelectorAll("[target]"),(e,f,g)=>{c(g[f],"change",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"keydown",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"input",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"paste",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()})})}if(a){const b=()=>{const a=document.querySelectorAll("[if]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}else(a){const b=()=>{const a=document.querySelectorAll("[else]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}repeat(a,b,c,d="",e=""){let f=d;if("object"==typeof c)for(let a=0;a{const c=document.querySelectorAll(`[${a}]`);for(let d=0;d{d()})):window.setInterval(()=>{d()},c):d()}live(a,b){const c={watch(a,b,c){const d=Object.getOwnPropertyDescriptor(a,b);if("undefined"==typeof d)throw new Error(`DisplayJS: Invalid descriptor for property: ${b}, object: ${a}`);if("function"!=typeof c)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${c}`);let e=a[b];Object.defineProperty(a,b,{enumerable:!0,configurable:!0,get(){return e},set(d){if(d!==e)return c(a,b,d,e),e=d}})},watchAll(a,b){if("function"!=typeof b)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${b}`);for(const c in a)this.watch(a,c,b)}};c.watchAll(a,(a,c,d,e)=>{b(a,c,d,e)})}onEvent(){const a=document.querySelectorAll("[on]");for(let b=0;b{eval(d)})}}all(a,b){a.forEach((a)=>{const c=[];c.push(a),b(c)})}text(a,b){a[0].innerHTML=this.xss(b)}html(a,b){a[0].innerHTML=b}append(a,b){a[0].innerHTML+=b}after(a,b){a[0].insertAdjacentHTML("afterend",b)}before(a,b){a[0].insertAdjacentHTML("beforebegin",b)}clone(a){a[0].cloneNode(!0)}is(a,b){return!(a[0]!==b[0])}select(a){if(this.isElement(a))return a;const b=document.querySelectorAll(a);return b}single(a){if(this.isElement(a))return a;const b=document.querySelector(a);return b}s(){return this.select(arguments)}empty(a){a[0].innerHTML=null}valEmpty(a){a[0].value=null}remove(a){a[0].parentNode.removeChild(a[0])}on(a,b,c){a[0].addEventListener(b,c)}ready(a){(document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?a():document.addEventListener("DOMContentLoaded",a)}show(a){return a[0].style.display="block",!0}hide(a){return a[0].style.display="none",!0}ajax(a,b,c,d,e="application/x-www-form-urlencoded; charset=UTF-8"){const f=new XMLHttpRequest;f.open(b,a,!0),f.setRequestHeader("Content-Type",e),f.onload=()=>{if(200<=f.status&&400>f.status){const a=f.responseText;d(a)}else console.error("DisplayJS error: The ajax request returned an error.")},f.onerror=()=>{console.error("DisplayJS error: The ajax request returned an error.")},f.send(c)}hasClass(a,b){return a[0].classList?a[0].classList.contains(b):!!a[0].className.match(new RegExp(`(\\s|^)${b}(\\s|$)`))}addClass(a,b){a[0].classList?a[0].classList.add(b):!this.hasClass(a,b)&&(a[0].className+=` ${b}`)}removeClass(a,b){if(a[0].classList)a[0].classList.remove(b);else if(this.hasClass(a,b)){const c=new RegExp(`(\\s|^)${b}(\\s|$)`);a[0].className=a[0].className.replace(c," ")}}toggleClass(a,b){this.hasClass(a,b)?this.removeClass(a,b):this.addClass(a,b)}css(a,b,c){a[0].style[b]=c}getStyle(a,b){return a[0].style[b]}fadeOut(a,b=0.1){const c=a[0];c.style.opacity=1,function a(){0>(c.style.opacity-=b)?c.style.display="none":requestAnimationFrame(a)}()}fadeIn(a,b=0.1,c){const d=a[0];d.style.opacity=0,d.style.display=c||"block",function a(){let c=parseFloat(d.style.opacity);1<(c+=b)||(d.style.opacity=c,requestAnimationFrame(a))}()}extend(a,b){const c={};for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);for(d in b)Object.prototype.hasOwnProperty.call(b,d)&&(c[d]=b[d]);return c}fn(){return DisplayJS.prototype}dynamic(a,b=250){window.setInterval(a,b)}parent(a,b=0){let c=a[0];for(const d in this.range(b))c=c.parentNode;return[c]}isNode(a){return"object"==typeof Node?a instanceof Node:a&&"object"==typeof a&&"number"==typeof a.nodeType&&"string"==typeof a.nodeName}isElement(a){return"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName}arange(a,b,c,d){const e=(Math.abs(b-a)+2*(d||0))/(c||1)+1,f=aa-f*(d||0)+f*(c||1)*e)}range(a){return this.arange(0,a,1)}linespace(a,b,c){return this.arange(a,b,(b-a)/c)}reshape(a,b){const c=[];for(let d=0;dthis.math().add(c,a),0)}multiply(a){return a.reduce((c,a)=>this.math().mul(c,a),0)}flatten(a){return a.reduce((c,a)=>c.concat(a),[])}drop(a,b){return 0this.math().sub(c,a));const b=Math.floor(this.math().div(a.length,2));return a.length%2?a[b]:this.math().div(this.math().add(a[b-1],a[b]),2)}predict(c,a,b=!1){function d(d,f){const g=c[0][0],h=c[1][0],i=c[0][1],j=c[1][1],k=e.math().div(e.math().sub(i,j),e.math().sub(g,h)),a=e.math().sub(j,e.math().mul(h,k));return!0==f?`f(x) = ${k}x+${a}; f(${d}) = ${d*k+a}`:d*k+a}const e=this;return function(a){return!(2=9007199254740991)throw"The result is not a safe integer."},shiftComma(a,b){return this.toExponent(this.countDecimals([a]),-b)[0]},countResult(a,b){let c=a[0];for(let d=1;da.length)throw"Set at least two numerical values.";for(const b in a){if(a[b]=parseFloat(a[b]),"number"!=typeof a[b]||isNaN(a[b]))throw"Every smMath argument must be of type number.";if(a[b]===Number.POSITIVE_INFINITY||a[b]===Number.NEGATIVE_INFINITY)throw"Every smMath argument must be a numerical value between positive and negative Infinity."}return a},countDecimals(a){const b=[];for(const c in a){let d=0;const e=a[c].toString().split("e"),f=e[0].indexOf(".");d-=-1===f?0:e[0].length-1-f,d+=isNaN(+e[1])?0:+e[1],e[0]=+e[0].replace(".",""),b.push({integer:e[0],comma:d})}return b}};return a}}"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports&&(module.exports=new DisplayJS); \ No newline at end of file +class DisplayJS{constructor(a){this.obj=a}var(a){const b=()=>{this.if(),this.else();const a=document.querySelectorAll("[var]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}render(a){this.var(a)}renderVariables(a){this.var(a)}xss(a){const b=//g,d=/'/g,e=/"/g;return a.toString().replace(b,"<").replace(c,">").replace(d,"'").replace(e,""")}xssURI(a){return encodeURI(a)}target(b=()=>{this.var()}){const c=(()=>{return document.addEventListener?(a,b,c)=>{a.addEventListener(b,c,!1)}:(a,b,c)=>{a.attachEvent(`on${b}`,c)}})(),d=this.obj;[].forEach.call(document.querySelectorAll("[target]"),(e,f,g)=>{c(g[f],"change",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"keydown",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"input",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"paste",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()})})}if(a){const b=()=>{const a=document.querySelectorAll("[if]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}else(a){const b=()=>{const a=document.querySelectorAll("[else]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}repeat(a,b,c,d="",e=""){let f=d;if("object"==typeof c)for(let a=0;a{const c=document.querySelectorAll(`[${a}]`);for(let d=0;d{d()})):window.setInterval(()=>{d()},c):d()}live(a,b){const c={watch(a,b,c){const d=Object.getOwnPropertyDescriptor(a,b);if("undefined"==typeof d)throw new Error(`DisplayJS: Invalid descriptor for property: ${b}, object: ${a}`);if("function"!=typeof c)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${c}`);let e=a[b];Object.defineProperty(a,b,{enumerable:!0,configurable:!0,get(){return e},set(d){if(d!==e)return c(a,b,d,e),e=d}})},watchAll(a,b){if("function"!=typeof b)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${b}`);for(const c in a)this.watch(a,c,b)}};c.watchAll(a,(a,c,d,e)=>{b(a,c,d,e)})}onEvent(){const a=document.querySelectorAll("[on]");for(let b=0;b{eval(d)})}}all(a,b){a.forEach((a)=>{const c=[];c.push(a),b(c)})}text(a,b){a[0].innerHTML=this.xss(b)}html(a,b){a[0].innerHTML=b}append(a,b){a[0].innerHTML+=b}after(a,b){a[0].insertAdjacentHTML("afterend",b)}before(a,b){a[0].insertAdjacentHTML("beforebegin",b)}clone(a){a[0].cloneNode(!0)}is(a,b){return!(a[0]!==b[0])}select(a){if(this.isElement(a))return a;const b=document.querySelectorAll(a);return b}single(a){if(this.isElement(a))return a;const b=document.querySelector(a);return b}s(){return this.select(arguments)}empty(a){a[0].innerHTML=null}valEmpty(a){a[0].value=null}remove(a){a[0].parentNode.removeChild(a[0])}on(a,b,c){a[0].addEventListener(b,c)}ready(a){(document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?a():document.addEventListener("DOMContentLoaded",a)}scroll(a){window.addEventListener("scroll",a)}scrollTo(a,b){window.scroll(a,b)}scrollTop(a=[document.body]){return a[0].scrollTop}show(a){return a[0].style.display="block",!0}hide(a){return a[0].style.display="none",!0}ajax(a,b,c,d,e="application/x-www-form-urlencoded; charset=UTF-8"){const f=new XMLHttpRequest;f.open(b,a,!0),f.setRequestHeader("Content-Type",e),f.onload=()=>{if(200<=f.status&&400>f.status){const a=f.responseText;d(a)}else console.error("DisplayJS error: The ajax request returned an error.")},f.onerror=()=>{console.error("DisplayJS error: The ajax request returned an error.")},f.send(c)}hasClass(a,b){return a[0].classList?a[0].classList.contains(b):!!a[0].className.match(new RegExp(`(\\s|^)${b}(\\s|$)`))}addClass(a,b){a[0].classList?a[0].classList.add(b):!this.hasClass(a,b)&&(a[0].className+=` ${b}`)}removeClass(a,b){if(a[0].classList)a[0].classList.remove(b);else if(this.hasClass(a,b)){const c=new RegExp(`(\\s|^)${b}(\\s|$)`);a[0].className=a[0].className.replace(c," ")}}toggleClass(a,b){this.hasClass(a,b)?this.removeClass(a,b):this.addClass(a,b)}css(a,b,c){a[0].style[b]=c}getStyle(a,b){return a[0].style[b]}fadeOut(a,b=0.1){const c=a[0];c.style.opacity=1,function a(){0>(c.style.opacity-=b)?c.style.display="none":requestAnimationFrame(a)}()}fadeIn(a,b=0.1,c){const d=a[0];d.style.opacity=0,d.style.display=c||"block",function a(){let c=parseFloat(d.style.opacity);1<(c+=b)||(d.style.opacity=c,requestAnimationFrame(a))}()}extend(a,b){const c={};for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);for(d in b)Object.prototype.hasOwnProperty.call(b,d)&&(c[d]=b[d]);return c}fn(){return DisplayJS.prototype}dynamic(a,b=250){window.setInterval(a,b)}parent(a,b=0){let c=a[0];for(const d in this.range(b))c=c.parentNode;return[c]}isNode(a){return"object"==typeof Node?a instanceof Node:a&&"object"==typeof a&&"number"==typeof a.nodeType&&"string"==typeof a.nodeName}isElement(a){return"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName}arange(a,b,c,d){const e=(Math.abs(b-a)+2*(d||0))/(c||1)+1,f=aa-f*(d||0)+f*(c||1)*e)}range(a){return this.arange(0,a,1)}linespace(a,b,c){return this.arange(a,b,(b-a)/c)}reshape(a,b){const c=[];for(let d=0;dthis.math().add(c,a),0)}multiply(a){return a.reduce((c,a)=>this.math().mul(c,a),0)}flatten(a){return a.reduce((c,a)=>c.concat(a),[])}drop(a,b){return 0this.math().sub(c,a));const b=Math.floor(this.math().div(a.length,2));return a.length%2?a[b]:this.math().div(this.math().add(a[b-1],a[b]),2)}predict(c,a,b=!1){function d(d,f){const g=c[0][0],h=c[1][0],i=c[0][1],j=c[1][1],k=e.math().div(e.math().sub(i,j),e.math().sub(g,h)),a=e.math().sub(j,e.math().mul(h,k));return!0==f?`f(x) = ${k}x+${a}; f(${d}) = ${d*k+a}`:d*k+a}const e=this;return function(a){return!(2=9007199254740991)throw"The result is not a safe integer."},shiftComma(a,b){return this.toExponent(this.countDecimals([a]),-b)[0]},countResult(a,b){let c=a[0];for(let d=1;da.length)throw"Set at least two numerical values.";for(const b in a){if(a[b]=parseFloat(a[b]),"number"!=typeof a[b]||isNaN(a[b]))throw"Every smMath argument must be of type number.";if(a[b]===Number.POSITIVE_INFINITY||a[b]===Number.NEGATIVE_INFINITY)throw"Every smMath argument must be a numerical value between positive and negative Infinity."}return a},countDecimals(a){const b=[];for(const c in a){let d=0;const e=a[c].toString().split("e"),f=e[0].indexOf(".");d-=-1===f?0:e[0].length-1-f,d+=isNaN(+e[1])?0:+e[1],e[0]=+e[0].replace(".",""),b.push({integer:e[0],comma:d})}return b}};return a}}"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports&&(module.exports=new DisplayJS); \ No newline at end of file diff --git a/dist/display.js b/dist/display.js index 95023b6..0477127 100644 --- a/dist/display.js +++ b/dist/display.js @@ -406,6 +406,23 @@ var DisplayJS = function () { document.addEventListener("DOMContentLoaded", fn); } } + }, { + key: "scroll", + value: function scroll(callback) { + window.addEventListener("scroll", callback); + } + }, { + key: "scrollTo", + value: function scrollTo(x, y) { + window.scroll(x, y); + } + }, { + key: "scrollTop", + value: function scrollTop() { + var el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [document.body]; + + return el[0].scrollTop; + } }, { key: "show", value: function show(element) { diff --git a/dist/display.min.js b/dist/display.min.js index 0138203..fa036ba 100644 --- a/dist/display.min.js +++ b/dist/display.min.js @@ -1 +1 @@ -"use strict";function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n/g,">").replace(/'/g,"'").replace(/"/g,""")}},{key:"xssURI",value:function(e){return encodeURI(e)}},{key:"target",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){e.var()},n=function(){return document.addEventListener?function(e,t,n){e.addEventListener(t,n,!1)}:function(e,t,n){e.attachEvent("on"+t,n)}}(),r=this.obj;[].forEach.call(document.querySelectorAll("[target]"),function(e,i,o){n(o[i],"change",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()}),n(o[i],"keydown",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()}),n(o[i],"input",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()}),n(o[i],"paste",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()})})}},{key:"if",value:function _if(push){var _this3=this,if_push=function if_push(){for(var elements=document.querySelectorAll("[if]"),i=0;i3&&void 0!==arguments[3]?arguments[3]:"",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",o=r;if("object"==(void 0===n?"undefined":_typeof(n)))for(var a=0;a4&&void 0!==arguments[4]?arguments[4]:"application/x-www-form-urlencoded; charset=UTF-8",o=new XMLHttpRequest;o.open(t,e,!0),o.setRequestHeader("Content-Type",i),o.onload=function(){if(o.status>=200&&o.status<400){var e=o.responseText;r(e)}else console.error("DisplayJS error: The ajax request returned an error.")},o.onerror=function(){console.error("DisplayJS error: The ajax request returned an error.")},o.send(n)}},{key:"hasClass",value:function(e,t){return e[0].classList?e[0].classList.contains(t):!!e[0].className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},{key:"addClass",value:function(e,t){e[0].classList?e[0].classList.add(t):this.hasClass(e,t)||(e[0].className+=" "+t)}},{key:"removeClass",value:function(e,t){if(e[0].classList)e[0].classList.remove(t);else if(this.hasClass(e,t)){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e[0].className=e[0].className.replace(n," ")}}},{key:"toggleClass",value:function(e,t){this.hasClass(e,t)?this.removeClass(e,t):this.addClass(e,t)}},{key:"css",value:function(e,t,n){e[0].style[t]=n}},{key:"getStyle",value:function(e,t){return e[0].style[t]}},{key:"fadeOut",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.1,n=e[0];n.style.opacity=1,function e(){(n.style.opacity-=t)<0?n.style.display="none":requestAnimationFrame(e)}()}},{key:"fadeIn",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.1,n=arguments[2],r=e[0];r.style.opacity=0,r.style.display=n||"block",function e(){var n=parseFloat(r.style.opacity);(n+=t)>1||(r.style.opacity=n,requestAnimationFrame(e))}()}},{key:"extend",value:function(e,t){var n={},r=void 0;for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);for(r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}},{key:"fn",value:function(){return DisplayJS.prototype}},{key:"dynamic",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250;window.setInterval(e,t)}},{key:"parent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=e[0];for(var r in this.range(t))n=n.parentNode;return[n]}},{key:"isNode",value:function(e){return"object"===("undefined"==typeof Node?"undefined":_typeof(Node))?e instanceof Node:e&&"object"===(void 0===e?"undefined":_typeof(e))&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName}},{key:"isElement",value:function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":_typeof(HTMLElement))?e instanceof HTMLElement:e&&"object"===(void 0===e?"undefined":_typeof(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName}},{key:"arange",value:function(e,t,n,r){var i=(Math.abs(t-e)+2*(r||0))/(n||1)+1,o=e0?e.slice(t,e.length):e.slice(0,e.length-t)}},{key:"isIn",value:function(e,t){return!!e.includes(t)}},{key:"rmFromArray",value:function(e,t){var n=[];for(var r in e)t(r)||n.push(e[r]);return n}},{key:"average",value:function(e){var t=this.sum(e);return this.math().div(t,e.length)}},{key:"median",value:function(e){var t=this;e.sort(function(e,n){return t.math().sub(e,n)});var n=Math.floor(this.math().div(e.length,2));return e.length%2?e[n]:this.math().div(this.math().add(e[n-1],e[n]),2)}},{key:"predict",value:function(e,t){function n(t,n){var r=e[0][0],o=e[1][0],a=e[0][1],u=e[1][1],s=i.math().div(i.math().sub(a,u),i.math().sub(r,o)),l=i.math().sub(u,i.math().mul(o,s));return 1==n?"f(x) = "+s+"x+"+l+"; f("+t+") = "+(t*s+l):t*s+l}var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=this;return function(e){return!(e.length>2)||n(e[2][0],!1)==e[2][1]}(e)?n(t,r):"DisplayJS: Error, can't find any pattern."}},{key:"math",value:function(){var e={add:function(){return t.addSubDiv(arguments,0)},sub:function(){return t.addSubDiv(arguments,1)},mul:function(){return t.mul(arguments)},div:function(){return t.addSubDiv(arguments,3)}},t={addSubDiv:function(e,t){var n=this.countDecimals(this.validMe(e)),r=this.biggestComma(n),i=3!==t?r:0,o=this.shiftComma(this.countResult(this.toExponent(n,r),t),i);return this.isSafeInteger(o),o},mul:function(e){var t=this.countDecimals(this.validMe(e)),n=[],r=0;for(var i in t)r+=t[i].comma,n.push(t[i].integer);return this.shiftComma(this.countResult(n,2),r)},isSafeInteger:function(e){if(e<=-(Math.pow(2,53)-1)||e>=Math.pow(2,53)-1)throw"The result is not a safe integer."},shiftComma:function(e,t){return this.toExponent(this.countDecimals([e]),-t)[0]},countResult:function(e,t){for(var n=e[0],r=1;r=0?"+":"";n.push(Number(e[r].integer.toString()+"e"+i+e[r].comma))}return n},biggestComma:function(e){var t=[];for(var n in e)t.push(e[n].comma);return Math.min.apply(null,t)},validMe:function(e){if(e.length<2)throw"Set at least two numerical values.";for(var t in e){if(e[t]=parseFloat(e[t]),"number"!=typeof e[t]||isNaN(e[t]))throw"Every smMath argument must be of type number.";if(e[t]===Number.POSITIVE_INFINITY||e[t]===Number.NEGATIVE_INFINITY)throw"Every smMath argument must be a numerical value between positive and negative Infinity."}return e},countDecimals:function(e){var t=[];for(var n in e){var r=0,i=e[n].toString().split("e"),o=i[0].indexOf(".");r-=-1!==o?i[0].length-1-o:0,r+=isNaN(Number(i[1]))?0:Number(i[1]),i[0]=Number(i[0].replace(".","")),t.push({integer:i[0],comma:r})}return t}};return e}}]),DisplayJS}(),_DOM_DJS=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),t}(DisplayJS);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports&&(module.exports=new DisplayJS); \ No newline at end of file +"use strict";function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n/g,">").replace(/'/g,"'").replace(/"/g,""")}},{key:"xssURI",value:function(e){return encodeURI(e)}},{key:"target",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){e.var()},n=function(){return document.addEventListener?function(e,t,n){e.addEventListener(t,n,!1)}:function(e,t,n){e.attachEvent("on"+t,n)}}(),r=this.obj;[].forEach.call(document.querySelectorAll("[target]"),function(e,i,o){n(o[i],"change",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()}),n(o[i],"keydown",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()}),n(o[i],"input",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()}),n(o[i],"paste",function(){var e=o[i].getAttribute("target");"checkbox"==this.type?r[e]=this.checked:"select"==this.type?r[e]=this.options[this.selectedIndex].value:r[e]=this.value,t()})})}},{key:"if",value:function _if(push){var _this3=this,if_push=function if_push(){for(var elements=document.querySelectorAll("[if]"),i=0;i3&&void 0!==arguments[3]?arguments[3]:"",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",o=r;if("object"==(void 0===n?"undefined":_typeof(n)))for(var a=0;a0&&void 0!==arguments[0]?arguments[0]:[document.body])[0].scrollTop}},{key:"show",value:function(e){return e[0].style.display="block",!0}},{key:"hide",value:function(e){return e[0].style.display="none",!0}},{key:"ajax",value:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"application/x-www-form-urlencoded; charset=UTF-8",o=new XMLHttpRequest;o.open(t,e,!0),o.setRequestHeader("Content-Type",i),o.onload=function(){if(o.status>=200&&o.status<400){var e=o.responseText;r(e)}else console.error("DisplayJS error: The ajax request returned an error.")},o.onerror=function(){console.error("DisplayJS error: The ajax request returned an error.")},o.send(n)}},{key:"hasClass",value:function(e,t){return e[0].classList?e[0].classList.contains(t):!!e[0].className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},{key:"addClass",value:function(e,t){e[0].classList?e[0].classList.add(t):this.hasClass(e,t)||(e[0].className+=" "+t)}},{key:"removeClass",value:function(e,t){if(e[0].classList)e[0].classList.remove(t);else if(this.hasClass(e,t)){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e[0].className=e[0].className.replace(n," ")}}},{key:"toggleClass",value:function(e,t){this.hasClass(e,t)?this.removeClass(e,t):this.addClass(e,t)}},{key:"css",value:function(e,t,n){e[0].style[t]=n}},{key:"getStyle",value:function(e,t){return e[0].style[t]}},{key:"fadeOut",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.1,n=e[0];n.style.opacity=1,function e(){(n.style.opacity-=t)<0?n.style.display="none":requestAnimationFrame(e)}()}},{key:"fadeIn",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.1,n=arguments[2],r=e[0];r.style.opacity=0,r.style.display=n||"block",function e(){var n=parseFloat(r.style.opacity);(n+=t)>1||(r.style.opacity=n,requestAnimationFrame(e))}()}},{key:"extend",value:function(e,t){var n={},r=void 0;for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);for(r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}},{key:"fn",value:function(){return DisplayJS.prototype}},{key:"dynamic",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250;window.setInterval(e,t)}},{key:"parent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=e[0];for(var r in this.range(t))n=n.parentNode;return[n]}},{key:"isNode",value:function(e){return"object"===("undefined"==typeof Node?"undefined":_typeof(Node))?e instanceof Node:e&&"object"===(void 0===e?"undefined":_typeof(e))&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName}},{key:"isElement",value:function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":_typeof(HTMLElement))?e instanceof HTMLElement:e&&"object"===(void 0===e?"undefined":_typeof(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName}},{key:"arange",value:function(e,t,n,r){var i=(Math.abs(t-e)+2*(r||0))/(n||1)+1,o=e0?e.slice(t,e.length):e.slice(0,e.length-t)}},{key:"isIn",value:function(e,t){return!!e.includes(t)}},{key:"rmFromArray",value:function(e,t){var n=[];for(var r in e)t(r)||n.push(e[r]);return n}},{key:"average",value:function(e){var t=this.sum(e);return this.math().div(t,e.length)}},{key:"median",value:function(e){var t=this;e.sort(function(e,n){return t.math().sub(e,n)});var n=Math.floor(this.math().div(e.length,2));return e.length%2?e[n]:this.math().div(this.math().add(e[n-1],e[n]),2)}},{key:"predict",value:function(e,t){function n(t,n){var r=e[0][0],o=e[1][0],a=e[0][1],u=e[1][1],s=i.math().div(i.math().sub(a,u),i.math().sub(r,o)),l=i.math().sub(u,i.math().mul(o,s));return 1==n?"f(x) = "+s+"x+"+l+"; f("+t+") = "+(t*s+l):t*s+l}var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=this;return function(e){return!(e.length>2)||n(e[2][0],!1)==e[2][1]}(e)?n(t,r):"DisplayJS: Error, can't find any pattern."}},{key:"math",value:function(){var e={add:function(){return t.addSubDiv(arguments,0)},sub:function(){return t.addSubDiv(arguments,1)},mul:function(){return t.mul(arguments)},div:function(){return t.addSubDiv(arguments,3)}},t={addSubDiv:function(e,t){var n=this.countDecimals(this.validMe(e)),r=this.biggestComma(n),i=3!==t?r:0,o=this.shiftComma(this.countResult(this.toExponent(n,r),t),i);return this.isSafeInteger(o),o},mul:function(e){var t=this.countDecimals(this.validMe(e)),n=[],r=0;for(var i in t)r+=t[i].comma,n.push(t[i].integer);return this.shiftComma(this.countResult(n,2),r)},isSafeInteger:function(e){if(e<=-(Math.pow(2,53)-1)||e>=Math.pow(2,53)-1)throw"The result is not a safe integer."},shiftComma:function(e,t){return this.toExponent(this.countDecimals([e]),-t)[0]},countResult:function(e,t){for(var n=e[0],r=1;r=0?"+":"";n.push(Number(e[r].integer.toString()+"e"+i+e[r].comma))}return n},biggestComma:function(e){var t=[];for(var n in e)t.push(e[n].comma);return Math.min.apply(null,t)},validMe:function(e){if(e.length<2)throw"Set at least two numerical values.";for(var t in e){if(e[t]=parseFloat(e[t]),"number"!=typeof e[t]||isNaN(e[t]))throw"Every smMath argument must be of type number.";if(e[t]===Number.POSITIVE_INFINITY||e[t]===Number.NEGATIVE_INFINITY)throw"Every smMath argument must be a numerical value between positive and negative Infinity."}return e},countDecimals:function(e){var t=[];for(var n in e){var r=0,i=e[n].toString().split("e"),o=i[0].indexOf(".");r-=-1!==o?i[0].length-1-o:0,r+=isNaN(Number(i[1]))?0:Number(i[1]),i[0]=Number(i[0].replace(".","")),t.push({integer:i[0],comma:r})}return t}};return e}}]),DisplayJS}(),_DOM_DJS=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),t}(DisplayJS);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports&&(module.exports=new DisplayJS); \ No newline at end of file diff --git a/package.json b/package.json index 742f51a..002ce03 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "run": "npm test", "build": "npm test", - "test": "npm run gulp && npm run lint && exit 0", + "test": "npm run lint && npm run gulp && exit 0", "gulp": "gulp", "lint": "./node_modules/.bin/eslint src/display.js --fix" }, diff --git a/src/display.js b/src/display.js index cedfac9..1373d1c 100644 --- a/src/display.js +++ b/src/display.js @@ -314,6 +314,15 @@ class DisplayJS { document.addEventListener("DOMContentLoaded", fn); } } + scroll (callback) { + window.addEventListener("scroll", callback); + } + scrollTo (x, y) { + window.scroll(x, y); + } + scrollTop (el = [document.body]) { + return el[0].scrollTop; + } show(element) { element[0].style.display = "block"; return true;