From ed6a9ea7862f49081c755e64a273f0cf2eefe274 Mon Sep 17 00:00:00 2001 From: Ernest Marcinko Date: Wed, 10 Jul 2024 14:46:24 +0000 Subject: [PATCH 1/2] types work --- domini.d.ts | 140 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 + src/base.js | 8 ++- src/core/css.js | 8 +-- src/core/data.js | 20 +++---- src/core/event.js | 10 ++-- test/core/data.js | 3 +- tsconfig.json | 32 +++++++++++ 8 files changed, 201 insertions(+), 23 deletions(-) create mode 100644 domini.d.ts create mode 100644 tsconfig.json diff --git a/domini.d.ts b/domini.d.ts new file mode 100644 index 0000000..cff049f --- /dev/null +++ b/domini.d.ts @@ -0,0 +1,140 @@ +declare module "domini" { + type HTMLElementWithFields = HTMLElement&{[otherFields: string]: unknown;}; + + interface DOMini extends Array { + (selector?: string|HTMLElement): this; + fn: { + _: (selector: string) => Array + }, + _fn: { + plugin: (name: string, object: Object) => this + } + add: (selector: string|HTMLElement) => this, + + css: { + (properties: Record): this; + (property: string, value: unknown): this; + }, + + hasClass: (className: string) => boolean, + + addClass: (className: string) => this, + + removeClass: (className: string) => this, + + /** + * Checks if element is visible + */ + isVisible: () => boolean, + + val: { + (value: string|number|string[]|number[]): this; + (): string|number|string[]|number[]; + }, + + attr: { + (attributes: Record): this; + (attribute: string, value: unknown): this; + (attribute: string): unknown; + }, + + removeAttr: (attribute: string) => this, + + prop: { + (attribute: string, value: unknown): this; + (attribute: string): unknown; + }, + + data: { + (key: string, value: unknown): this; + (key: string): string; + }, + + html: { + (html: string): this; + (): string; + }, + + text: { + (text: string): this; + (): string; + }, + + extend: (...args: Object) => Object, + + each: (callback: (index?: number, node?: HTMLElementWithFields, array?: HTMLElementWithFields[])=>unknown) => this + + forEach: (callback: (node?: HTMLElementWithFields, index?: number, array?: HTMLElementWithFields[])=>unknown) => this + + get: (n: number) => HTMLElementWithFields, + + offset: ()=> { + top: number, + left: number, + }, + + position: () => { + top: number, + left: number, + }, + + outerWidth: (includeMargin?: boolean = false) => number, + outerHeight: (includeMargin?: boolean = false) => number, + + noPaddingWidth: (includeMargin?: boolean = false) => number, + noPaddingHeight: (includeMargin?: boolean = false) => number, + + innerWidth: () => number, + innerHeight: () => number, + + /** + * Same as `outerWidth(false)` + */ + width: () => number, + + /** + * Same as `outerHeight(false)` + */ + height: () => number, + + on: { + (events: string, callback: (event:Event)=>void): this, + (events: string, selector: string, callback: (event:Event)=>void): this, + }, + + off: { + (): this, + (events: string): this, + (events: string, callback: Function): this + }, + + offForced: ()=> this, + + trigger: (event: string, args:unknown[], native: boolean = false, jquery: boolean = false) => this, + + /** + * Removes all DoMini related event listeners + */ + clear: () => this, + + clone: () => this, + + detach: (context?: string|HTMLElement) => this, + + remove: (context?: string|HTMLElement) => this, + + prepend: (prepend: string|HTMLElement|HTMLElement[]|DOMini) => this, + + append: (prepend: string|HTMLElement|HTMLElement[]|DOMini) => this, + + /** + * Addons and other possibly dynamically added fields + */ + [otherFields: string]: (...args:unknown)=>this | unknown; + } + + import {DOMini} from "./types"; + declare const DoMini: DOMini; + + export=DoMini; +} \ No newline at end of file diff --git a/package.json b/package.json index 4036c8c..24fce6f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.2.4", "description": "Minimalistic DOM manipulation tool", "main": "dist/domini.js", + "types": "domini.d.ts", "scripts": { "build": "webpack --mode=production --node-env=production", "test": "nodemon ./test/server.js", @@ -23,6 +24,8 @@ ], "files": [ "dist", + "types.d.ts", + "domini.d.ts", "examples.html", "readme.md" ], diff --git a/src/base.js b/src/base.js index 9429fdd..289a5ee 100644 --- a/src/base.js +++ b/src/base.js @@ -7,10 +7,12 @@ * @returns {DoMini|void} */ +let DoMini; + // Prevent overloading if ( typeof window.DoMini == 'undefined' ) { - var DoMini = function(selector, node) { + DoMini = function(selector, node) { // Actual constructor when new Domini() is called if ( typeof arguments[2] !== 'undefined' ) { return this.constructor.call(this, selector, node); @@ -44,7 +46,7 @@ if ( typeof window.DoMini == 'undefined' ) { return DoMini(node).find(s); } } else { - if (typeof s == "string" && s != '') { + if (typeof s == "string" && s !== '') { this.push(...this._(s)); } else { if ( s instanceof DoMini ) { @@ -85,7 +87,7 @@ if ( typeof window.DoMini == 'undefined' ) { // Utility functions container DoMini._fn = {}; } else { - var DoMini = window.DoMini; + DoMini = window.DoMini; } export default DoMini; \ No newline at end of file diff --git a/src/core/css.js b/src/core/css.js index 330d450..3eb356c 100644 --- a/src/core/css.js +++ b/src/core/css.js @@ -2,7 +2,7 @@ import DoMini from "../base"; DoMini.fn.css = function(prop, v) { for ( const el of this ) { - if ( arguments.length == 1 ) { + if ( arguments.length === 1 ) { if ( typeof prop == "object" ) { Object.keys(prop).forEach(function(k){ el.style[k] = prop[k]; @@ -67,9 +67,9 @@ DoMini.fn.isVisible = function() { while (el !== null) { style = window.getComputedStyle(el); if ( - style['display'] == 'none' || - style['visibility'] == 'hidden' || - style['opacity'] == 0 + style['display'] === 'none' || + style['visibility'] === 'hidden' || + parseInt(style['opacity']) === 0 ) { visible = false; break; diff --git a/src/core/data.js b/src/core/data.js index 6d09b63..dfc0d43 100644 --- a/src/core/data.js +++ b/src/core/data.js @@ -2,13 +2,13 @@ import DoMini from "../base"; DoMini.fn.val = function(v) { let ret; - if ( arguments.length == 1 ) { + if ( arguments.length === 1 ) { for ( const el of this ) { - if ( el.type == 'select-multiple' ) { + if ( el.type === 'select-multiple' ) { v = typeof v === 'string' ? v.split(',') : v; for ( let i = 0, l = el.options.length, o; i < l; i++ ) { o = el.options[i]; - o.selected = v.indexOf(o.value) != -1; + o.selected = v.indexOf(o.value) !== -1; } } else { el.value = v; @@ -18,7 +18,7 @@ DoMini.fn.val = function(v) { } else { let el = this.get(0); if ( el != null ) { - if ( el.type == 'select-multiple' ) { + if ( el.type === 'select-multiple' ) { ret = Array.prototype.map.call(el.selectedOptions, function(x){ return x.value }); } else { ret = el.value; @@ -31,7 +31,7 @@ DoMini.fn.val = function(v) { DoMini.fn.attr = function (a, v) { let ret; for ( const el of this ) { - if ( arguments.length == 2 ) { + if ( arguments.length === 2 ) { el.setAttribute(a, v); ret = this; } else { @@ -58,14 +58,14 @@ DoMini.fn.removeAttr = function(a) { DoMini.fn.prop = function(a, v) { let ret; for ( const el of this ) { - if ( arguments.length == 2 ) { + if ( arguments.length === 2 ) { el[a] = v; } else { ret = typeof el[a] != "undefined" ? el[a] : null; break; } } - if ( arguments.length == 2 ) { + if ( arguments.length === 2 ) { return this; } else { return ret; @@ -76,7 +76,7 @@ DoMini.fn.data = function(d, v) { const s = d.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); - if ( arguments.length == 2 ) { + if ( arguments.length === 2 ) { for ( const el of this ) { if ( el != null ) { el.dataset[s] = v; @@ -90,7 +90,7 @@ DoMini.fn.data = function(d, v) { }; DoMini.fn.html = function(v) { - if ( arguments.length == 1 ) { + if ( arguments.length === 1 ) { for ( const el of this ) { el.innerHTML = v; } @@ -102,7 +102,7 @@ DoMini.fn.html = function(v) { }; DoMini.fn.text = function(v) { - if ( arguments.length == 1 ) { + if ( arguments.length === 1 ) { for ( const el of this ) { el.textContent = v; } diff --git a/src/core/event.js b/src/core/event.js index dd4875b..dd1c3df 100644 --- a/src/core/event.js +++ b/src/core/event.js @@ -4,7 +4,7 @@ DoMini.fn.on = function() { let args = arguments, func = function(args, e) { let $el; - if ( e.type == 'mouseenter' || e.type == 'mouseleave' || e.type == 'mouseover' ) { + if ( e.type === 'mouseenter' || e.type === 'mouseleave' || e.type === 'mouseover' ) { let el = document.elementFromPoint(e.clientX, e.clientY); if ( !el.matches(args[1]) ) { // noinspection StatementWithEmptyBodyJS @@ -85,10 +85,10 @@ DoMini.fn.off = function(listen, callback) { let remains = []; while (cb = el._domini_events.pop()) { if ( - cb.type == type && + cb.type === type && ( typeof callback == "undefined" || - cb.trigger == callback + cb.trigger === callback ) ) { el.removeEventListener(type, cb.func, cb.args); @@ -141,7 +141,7 @@ DoMini.fn.trigger = function(type, args, native ,jquery) { if (typeof el._domini_events != "undefined") { // Case 1, regularly attached el._domini_events.forEach(function(data){ - if ( data.type == type ) { + if ( data.type === type ) { let event = new Event(type); data.trigger.apply(el, [event].concat(args)); } @@ -162,7 +162,7 @@ DoMini.fn.trigger = function(type, args, native ,jquery) { if ( targets.length > 0 && targets.get().indexOf(el) >=0 && - data.type == type + data.type === type ) { let event = new Event(type); data.trigger.apply(el, [event].concat(args)); diff --git a/test/core/data.js b/test/core/data.js index 71c9207..3c5a2de 100644 --- a/test/core/data.js +++ b/test/core/data.js @@ -1,5 +1,6 @@ +import * as $ from "domini"; + QUnit.module("data.js tests", function(hooks) { - var $ = DoMini; hooks.beforeEach(function() { var f = document.getElementById('qunit-fixture'); f.innerHTML = fixture; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6c1f9db --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "target": "ESNext", + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "node", + "lib": [ + "DOM", + "ESNext", + "dom.iterable" + ], + "jsx": "react-jsx", + "allowJs": true, + "sourceMap": true, + "isolatedModules": true, + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true + }, + "include": [ + "src/**/*", + "domini.d.ts", + ], + "exclude": [ + "./node_modules", + "./build", + "./dist", + ] +} \ No newline at end of file From b61b508d2334e752b0f5d5d7452f7fcd4651eae0 Mon Sep 17 00:00:00 2001 From: Ernest Marcinko Date: Thu, 11 Jul 2024 16:06:13 +0000 Subject: [PATCH 2/2] types work --- dist/domini-core.js | 2 +- dist/domini-highlight.js | 2 +- dist/domini-xhttp.js | 2 +- dist/domini.js | 2 +- domini.d.ts | 121 ++++++++++++++++++++++++++++++++++----- package.json | 2 +- src/base.js | 6 +- src/core/manipulation.js | 4 +- src/core/selector.js | 2 +- src/core/utils.js | 13 +++-- src/modules/highlight.js | 6 +- src/modules/xhttp.js | 8 +-- test/core/data.js | 19 +++--- test/core/selector.js | 1 + 14 files changed, 146 insertions(+), 44 deletions(-) diff --git a/dist/domini-core.js b/dist/domini-core.js index 2bc78cc..25d6c06 100644 --- a/dist/domini-core.js +++ b/dist/domini-core.js @@ -1 +1 @@ -(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};if(t.d(e,{default:()=>o}),void 0===window.DoMini){var n=function(t,e){return void 0!==arguments[2]?this.constructor.call(this,t,e):1!=arguments.length||"function"!=typeof arguments[0]?new n(t,e,!0):void("complete"===document.readyState||"loaded"===document.readyState||"interactive"===document.readyState?arguments[0].apply(this,[n]):window.addEventListener("DOMContentLoaded",(()=>{arguments[0].apply(this,[n])})))};n.prototype=n.fn={constructor:function(t,e){if(this.length=0,void 0!==e){if(e instanceof n)return e.find(t);if(this.isValidNode(e)||"string"==typeof e)return n(e).find(t)}else if("string"==typeof t&&""!=t)this.push(...this._(t));else{if(t instanceof n)return t;this.isValidNode(t)&&this.push(t)}return this},_:function(t){return"<"===t.charAt(0)?n._fn.createElementsFromHTML(t):[...document.querySelectorAll(t)]},isValidNode:t=>t instanceof Element||t instanceof Document||t instanceof Window,push:Array.prototype.push,pop:Array.prototype.pop,sort:Array.prototype.sort,splice:Array.prototype.splice},n.prototype[Symbol.iterator]=Array.prototype[Symbol.iterator],n._fn={}}else n=window.DoMini;const i=n;i.fn.get=function(t){return void 0===t?Array.from(this):this[t]},i.fn.extend=function(){for(let t=1;t0&&this.forEach((function(t){t.classList.add.apply(t.classList,e)})),this},i.fn.removeClass=function(t){if(void 0!==t){let e=t;"string"==typeof t&&(e=t.split(" ")),e=e.filter((function(t){return""!==t.trim()})),e.length>0&&this.forEach((function(t){t.classList.remove.apply(t.classList,e)}))}else this.forEach((function(t){t.classList.length>0&&t.classList.remove.apply(t.classList,t.classList)}));return this},i.fn.isVisible=function(){let t,e=this.get(0),n=!0;for(;null!==e;){if(t=window.getComputedStyle(e),"none"==t.display||"hidden"==t.visibility||0==t.opacity){n=!1;break}e=e.parentElement}return n},i.fn.val=function(t){let e;if(1==arguments.length){for(const e of this)if("select-multiple"==e.type){t="string"==typeof t?t.split(","):t;for(let n,i=0,o=e.options.length;i0?t?parseInt(this.css("height"))+parseInt(this.css("marginTop"))+parseInt(this.css("marginBottom")):parseInt(this.css("height")):0},i.fn.noPaddingWidth=function(t){return t=t||!1,this.length>0?t?parseInt(this.css("width"))+parseInt(this.css("marginLeft"))+parseInt(this.css("marginRight")):parseInt(this.css("width")):0},i.fn.innerWidth=function(){let t=this.get(0);if(null!=t){let e=window.getComputedStyle(t);return this.outerWidth()-parseFloat(e.borderLeftWidth)-parseFloat(e.borderRightWidth)}return 0},i.fn.innerHeight=function(){let t=this.get(0);if(null!=t){let e=window.getComputedStyle(t);return this.outerHeight()-parseFloat(e.borderTopWidth)-parseFloat(e.borderBottomtWidth)}return 0},i.fn.width=function(){return this.outerWidth()},i.fn.height=function(){return this.outerHeight()},i.fn.on=function(){let t=arguments,e=function(t,e){let n;if("mouseenter"==e.type||"mouseleave"==e.type||"mouseover"==e.type){let o=document.elementFromPoint(e.clientX,e.clientY);if(!o.matches(t[1]))for(;(o=o.parentElement)&&!o.matches(t[1]););null!=o&&(n=i(o))}else n=i(e.target).closest(t[1]);if(null!=n&&n.closest(this).length>0){let i=[];if(i.push(e),void 0!==t[4])for(let e=4;e0)if(void 0===t){let t;for(;t=n._domini_events.pop();)n.removeEventListener(t.type,t.func,t.args);n._domini_events=[]}else t.split(" ").forEach((function(t){let i,o=[];for(;i=n._domini_events.pop();)i.type!=t||void 0!==e&&i.trigger!=e?o.push(i):n.removeEventListener(t,i.func,i.args);n._domini_events=o}))})),this},i.fn.offForced=function(){let t=this;return this.forEach((function(e,n){let i=e.cloneNode(!0);e.parentNode.replaceChild(i,e),t[n]=i})),this},i.fn.trigger=function(t,e,n,o){return n=n||!1,o=o||!1,this.forEach((function(r){let s=!1;if(o&&"undefined"!=typeof jQuery&&void 0!==jQuery._data&&void 0!==jQuery._data(r,"events")&&void 0!==jQuery._data(r,"events")[t]&&(jQuery(r).trigger(t,e),s=!0),!s&&n){let n=new Event(t);n.detail=e,r.dispatchEvent(n)}if(void 0!==r._domini_events)r._domini_events.forEach((function(n){if(n.type==t){let i=new Event(t);n.trigger.apply(r,[i].concat(e))}}));else{let n=!1,o=r;for(;o=o.parentElement,null!=o&&(void 0!==o._domini_events&&o._domini_events.forEach((function(s){if(void 0!==s.selector){let f=i(o).find(s.selector);if(f.length>0&&f.get().indexOf(r)>=0&&s.type==t){let i=new Event(t);s.trigger.apply(r,[i].concat(e)),n=!0}}})),!n););}})),this},i.fn.clear=function(){for(const t of this)delete t._domini_events;return this},i.fn.clone=function(){let t=[];for(const e of this)t.push(e.cloneNode(!0));return i().add(t)},i.fn.detach=function(t){let e=this,n=[];void 0!==t&&(e=this.find(t));for(const t of e)null!=t.parentElement&&n.push(t.parentElement.removeChild(t));return i().add(n)},i.fn.remove=function(t){return this.detach(t).off().clear()},i.fn.prepend=function(t){if((t=i._fn.ElementArrayFromAny(t)).length>0)for(const e of this)for(const n of t)e.insertBefore(n,e.children[0]);return this},i.fn.append=function(t){if((t=i._fn.ElementArrayFromAny(t)).length>0)for(const e of this)for(const n of t)e.appendChild(n);return this},i.fn.is=function(t){let e=!1;for(const n of this)if(n.matches(t)){e=!0;break}return e},i.fn.parent=function(t){let e=[];for(const n of this){let i=n.parentElement;"string"==typeof t&&(null==i||i.matches(t)||(i=null)),e.push(i)}return i().add(e)},i.fn.copy=function(t,e){let n,i,o;if("object"!=typeof t||null===t)return n=t,n;for(i in n=new t.constructor,t)t.hasOwnProperty(i)&&(o=typeof t[i],e&&"object"===o&&null!==t[i]?n[i]=this.copy(t[i]):n[i]=t[i]);return n},i.fn.first=function(){return i(this[0])},i.fn.last=function(){return i(this[this.length-1])},i.fn.prev=function(t){let e=[];for(const n of this){let i;if("string"==typeof t)for(i=n.previousElementSibling;null!=i;){if(i.matches(t)){e.push(i);break}i=i.previousElementSibling}else e.push(n.previousElementSibling)}return i(null).add(e)},i.fn.next=function(t){let e=[];for(const n of this){let i;if("string"==typeof t)for(i=n.nextElementSibling;null!=i;){if(i.matches(t)){e.includes(i)||e.push(i);break}i=i.nextElementSibling}else e.push(n.nextElementSibling)}return i(null).add(e)},i.fn.closest=function(t){let e=[];for(let n of this)if("string"==typeof t&&""!==t){for(;!n.matches(t)&&(n=n.parentElement););e.includes(n)||e.push(n)}else{if((t=t instanceof i?t.get(0):t)instanceof Element)for(;n!==t&&(n=n.parentElement););else n=null;e.includes(n)||e.push(n)}return i().add(e)},i.fn.add=function(t){let e=i._fn.ElementArrayFromAny(t);for(const t of e)Array.from(this).includes(t)||this.push(t);return this},i.fn.find=function(t){const e=new i;if("string"==typeof t){let n=[];this.get().forEach((function(e){const i=e.querySelectorAll?.(t)??[];n=n.concat(Array.from(i))})),n.length>0&&e.add(n)}return e},i._fn.bodyTransform=function(){let t=0,e=0;if("undefined"!=typeof WebKitCSSMatrix){let n=window.getComputedStyle(document.body);if(void 0!==n.transform){let i=new WebKitCSSMatrix(n.transform);"undefined"!=i.m41&&(t=i.m41),"undefined"!=i.m42&&(e=i.m42)}}return{x:t,y:e}},i._fn.bodyTransformY=function(){return this.bodyTransform().y},i._fn.bodyTransformX=function(){return this.bodyTransform().x},i._fn.hasFixedParent=function(t){if(0!=i._fn.bodyTransformY())return!1;do{if("fixed"==window.getComputedStyle(t).position)return!0}while(t=t.parentElement);return!1},i._fn.hasEventListener=function(t,e,n){if(void 0===t._domini_events)return!1;for(let i=0;it instanceof Element))}return t},i._fn.absolutePosition=function(t){if(!t.getClientRects().length)return{top:0,left:0};let e=t.getBoundingClientRect(),n=t.ownerDocument.defaultView;return{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}},i._fn.plugin=function(t,e){i.fn[t]=function(n){return void 0!==n&&e[n]?e[n].apply(this,Array.prototype.slice.call(arguments,1)):this.forEach((function(i){i["domini_"+t]=Object.create(e).init(n,i)}))}},document.dispatchEvent(new Event("domini-dom-core-loaded"));const o=i;window.DoMini=e.default})(); \ No newline at end of file +(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};let n;t.d(e,{default:()=>o}),void 0===window.DoMini?(n=function(t,e){return void 0!==arguments[2]?this.constructor.call(this,t,e):1!==arguments.length||"function"!=typeof arguments[0]?new n(t,e,!0):void("complete"===document.readyState||"loaded"===document.readyState||"interactive"===document.readyState?arguments[0].apply(this,[n]):window.addEventListener("DOMContentLoaded",(()=>{arguments[0].apply(this,[n])})))},n.prototype=n.fn={constructor:function(t,e){if(this.length=0,void 0!==e){if(e instanceof n)return e.find(t);if(this.isValidNode(e)||"string"==typeof e)return n(e).find(t)}else if("string"==typeof t&&""!==t)this.push(...this._(t));else{if(t instanceof n)return t;this.isValidNode(t)&&this.push(t)}return this},_:function(t){return"<"===t.charAt(0)?n._fn.createElementsFromHTML(t):[...document.querySelectorAll(t)]},isValidNode:t=>t instanceof Element||t instanceof Document||t instanceof Window,push:Array.prototype.push,pop:Array.prototype.pop,sort:Array.prototype.sort,splice:Array.prototype.splice},n.prototype[Symbol.iterator]=Array.prototype[Symbol.iterator],n._fn={},n.version="0.2.5"):n=window.DoMini;const i=n;i.fn.get=function(t){return void 0===t?Array.from(this):this[t]},i.fn.extend=function(){for(let t=1;t0&&this.forEach((function(t){t.classList.add.apply(t.classList,e)})),this},i.fn.removeClass=function(t){if(void 0!==t){let e=t;"string"==typeof t&&(e=t.split(" ")),e=e.filter((function(t){return""!==t.trim()})),e.length>0&&this.forEach((function(t){t.classList.remove.apply(t.classList,e)}))}else this.forEach((function(t){t.classList.length>0&&t.classList.remove.apply(t.classList,t.classList)}));return this},i.fn.isVisible=function(){let t,e=this.get(0),n=!0;for(;null!==e;){if(t=window.getComputedStyle(e),"none"===t.display||"hidden"===t.visibility||0===parseInt(t.opacity)){n=!1;break}e=e.parentElement}return n},i.fn.val=function(t){let e;if(1===arguments.length){for(const e of this)if("select-multiple"===e.type){t="string"==typeof t?t.split(","):t;for(let n,i=0,o=e.options.length;i0?t?parseInt(this.css("height"))+parseInt(this.css("marginTop"))+parseInt(this.css("marginBottom")):parseInt(this.css("height")):0},i.fn.noPaddingWidth=function(t){return t=t||!1,this.length>0?t?parseInt(this.css("width"))+parseInt(this.css("marginLeft"))+parseInt(this.css("marginRight")):parseInt(this.css("width")):0},i.fn.innerWidth=function(){let t=this.get(0);if(null!=t){let e=window.getComputedStyle(t);return this.outerWidth()-parseFloat(e.borderLeftWidth)-parseFloat(e.borderRightWidth)}return 0},i.fn.innerHeight=function(){let t=this.get(0);if(null!=t){let e=window.getComputedStyle(t);return this.outerHeight()-parseFloat(e.borderTopWidth)-parseFloat(e.borderBottomtWidth)}return 0},i.fn.width=function(){return this.outerWidth()},i.fn.height=function(){return this.outerHeight()},i.fn.on=function(){let t=arguments,e=function(t,e){let n;if("mouseenter"===e.type||"mouseleave"===e.type||"mouseover"===e.type){let o=document.elementFromPoint(e.clientX,e.clientY);if(!o.matches(t[1]))for(;(o=o.parentElement)&&!o.matches(t[1]););null!=o&&(n=i(o))}else n=i(e.target).closest(t[1]);if(null!=n&&n.closest(this).length>0){let i=[];if(i.push(e),void 0!==t[4])for(let e=4;e0)if(void 0===t){let t;for(;t=n._domini_events.pop();)n.removeEventListener(t.type,t.func,t.args);n._domini_events=[]}else t.split(" ").forEach((function(t){let i,o=[];for(;i=n._domini_events.pop();)i.type!==t||void 0!==e&&i.trigger!==e?o.push(i):n.removeEventListener(t,i.func,i.args);n._domini_events=o}))})),this},i.fn.offForced=function(){let t=this;return this.forEach((function(e,n){let i=e.cloneNode(!0);e.parentNode.replaceChild(i,e),t[n]=i})),this},i.fn.trigger=function(t,e,n,o){return n=n||!1,o=o||!1,this.forEach((function(r){let s=!1;if(o&&"undefined"!=typeof jQuery&&void 0!==jQuery._data&&void 0!==jQuery._data(r,"events")&&void 0!==jQuery._data(r,"events")[t]&&(jQuery(r).trigger(t,e),s=!0),!s&&n){let n=new Event(t);n.detail=e,r.dispatchEvent(n)}if(void 0!==r._domini_events)r._domini_events.forEach((function(n){if(n.type===t){let i=new Event(t);n.trigger.apply(r,[i].concat(e))}}));else{let n=!1,o=r;for(;o=o.parentElement,null!=o&&(void 0!==o._domini_events&&o._domini_events.forEach((function(s){if(void 0!==s.selector){let f=i(o).find(s.selector);if(f.length>0&&f.get().indexOf(r)>=0&&s.type===t){let i=new Event(t);s.trigger.apply(r,[i].concat(e)),n=!0}}})),!n););}})),this},i.fn.clear=function(){for(const t of this)delete t._domini_events;return this},i.fn.clone=function(){let t=[];for(const e of this)t.push(e.cloneNode(!0));return i().add(t)},i.fn.detach=function(t){let e=this,n=[];void 0!==t&&(e=this.find(t));for(const t of e)null!=t.parentElement&&n.push(t.parentElement.removeChild(t));return i().add(n)},i.fn.remove=function(t){return this.detach(t).off().clear()},i.fn.prepend=function(t){if((t=i._fn.elementArrayFromAny(t)).length>0)for(const e of this)for(const n of t)e.insertBefore(n,e.children[0]);return this},i.fn.append=function(t){if((t=i._fn.elementArrayFromAny(t)).length>0)for(const e of this)for(const n of t)e.appendChild(n);return this},i.fn.is=function(t){let e=!1;for(const n of this)if(n.matches(t)){e=!0;break}return e},i.fn.parent=function(t){let e=[];for(const n of this){let i=n.parentElement;"string"==typeof t&&(null==i||i.matches(t)||(i=null)),e.push(i)}return i().add(e)},i.fn.copy=function(t,e){let n,i,o;if("object"!=typeof t||null===t)return n=t,n;for(i in n=new t.constructor,t)t.hasOwnProperty(i)&&(o=typeof t[i],e&&"object"===o&&null!==t[i]?n[i]=this.copy(t[i]):n[i]=t[i]);return n},i.fn.first=function(){return i(this[0])},i.fn.last=function(){return i(this[this.length-1])},i.fn.prev=function(t){let e=[];for(const n of this){let i;if("string"==typeof t)for(i=n.previousElementSibling;null!=i;){if(i.matches(t)){e.push(i);break}i=i.previousElementSibling}else e.push(n.previousElementSibling)}return i(null).add(e)},i.fn.next=function(t){let e=[];for(const n of this){let i;if("string"==typeof t)for(i=n.nextElementSibling;null!=i;){if(i.matches(t)){e.includes(i)||e.push(i);break}i=i.nextElementSibling}else e.push(n.nextElementSibling)}return i(null).add(e)},i.fn.closest=function(t){let e=[];for(let n of this)if("string"==typeof t&&""!==t){for(;!n.matches(t)&&(n=n.parentElement););e.includes(n)||e.push(n)}else{if((t=t instanceof i?t.get(0):t)instanceof Element)for(;n!==t&&(n=n.parentElement););else n=null;e.includes(n)||e.push(n)}return i().add(e)},i.fn.add=function(t){let e=i._fn.elementArrayFromAny(t);for(const t of e)Array.from(this).includes(t)||this.push(t);return this},i.fn.find=function(t){const e=new i;if("string"==typeof t){let n=[];this.get().forEach((function(e){const i=e.querySelectorAll?.(t)??[];n=n.concat(Array.from(i))})),n.length>0&&e.add(n)}return e},i._fn.bodyTransform=function(){let t=0,e=0;if("undefined"!=typeof WebKitCSSMatrix){let n=window.getComputedStyle(document.body);if(void 0!==n.transform){let i=new WebKitCSSMatrix(n.transform);"undefined"!==i.m41&&(t=i.m41),"undefined"!==i.m42&&(e=i.m42)}}return{x:t,y:e}},i._fn.bodyTransformY=function(){return this.bodyTransform().y},i._fn.bodyTransformX=function(){return this.bodyTransform().x},i._fn.hasFixedParent=function(t){if(0!=i._fn.bodyTransformY())return!1;do{if("fixed"==window.getComputedStyle(t).position)return!0}while(t=t.parentElement);return!1},i._fn.hasEventListener=function(t,e,n){if(void 0===t._domini_events)return!1;for(let i=0;it instanceof Element))}return t},i._fn.ElementArrayFromAny=i._fn.elementArrayFromAny,i._fn.absolutePosition=function(t){if(!t.getClientRects().length)return{top:0,left:0};let e=t.getBoundingClientRect(),n=t.ownerDocument.defaultView;return{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}},i._fn.plugin=function(t,e){i.fn[t]=function(n){return void 0!==n&&e[n]?e[n].apply(this,Array.prototype.slice.call(arguments,1)):this.forEach((function(i){i["domini_"+t]=Object.create(e).init(n,i)}))}},document.dispatchEvent(new Event("domini-dom-core-loaded"));const o=i;window.DoMini=e.default})(); \ No newline at end of file diff --git a/dist/domini-highlight.js b/dist/domini-highlight.js index b169473..05643e6 100644 --- a/dist/domini-highlight.js +++ b/dist/domini-highlight.js @@ -1 +1 @@ -(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>l});const n=window.DoMini;var i=e.n(n);i().fn.unhighlight=function(e){let t={className:"highlight",element:"span"};return i().fn.extend(t,e),this.find(t.element+"."+t.className).forEach((function(){let e=this.parentNode;e.replaceChild(this.firstChild,this),e.normalize()}))},i().fn.highlight=function(e,t){this.defaults={className:"highlight",element:"span",caseSensitive:!1,wordsOnly:!1,excludeParents:".excludeFromHighlight"};const n=i(),l={...this.defaults,...t};if(e.constructor===String&&(e=[e]),(e=e.filter((function(e){return""!=e}))).forEach((function(e,t,n){n[t]=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").normalize("NFD").replace(/[\u0300-\u036f]/g,"")})),0==e.length)return this;let s=l.caseSensitive?"":"i",a="("+e.join("|")+")";l.wordsOnly&&(a="(?:,|^|\\s)"+a+"(?:,|$|\\s)");let r=new RegExp(a,s);function o(e,t,i,l,s){if(s=""==s?n.fn.highlight.defaults:s,3===e.nodeType){if(!n(e.parentNode).is(s)){let n=e.data.normalize("NFD").replace(/[\u0300-\u036f]/g,"").match(t);if(n){let t,s=document.createElement(i||"span");s.className=l||"highlight",t=/\.|,|\s/.test(n[0].charAt(0))?n.index+1:n.index;let a=e.splitText(t);a.splitText(n[1].length);let r=a.cloneNode(!0);return s.appendChild(r),a.parentNode.replaceChild(s,a),1}}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&!n(e).closest(s).length>0&&(e.tagName!==i.toUpperCase()||e.className!==l))for(let n=0;n{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>l});const n=window.DoMini;var i=e.n(n);i().fn.unhighlight=function(e){let t={className:"highlight",element:"span"};return i().fn.extend(t,e),this.find(t.element+"."+t.className).forEach((function(){let e=this.parentNode;e.replaceChild(this.firstChild,this),e.normalize()}))},i().fn.highlight=function(e,t){this.defaults={className:"highlight",element:"span",caseSensitive:!1,wordsOnly:!1,excludeParents:".excludeFromHighlight"};const n=i(),l={...this.defaults,...t};if(e.constructor===String&&(e=[e]),(e=e.filter((function(e){return""!==e}))).forEach((function(e,t,n){n[t]=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").normalize("NFD").replace(/[\u0300-\u036f]/g,"")})),0===e.length)return this;let s=l.caseSensitive?"":"i",a="("+e.join("|")+")";l.wordsOnly&&(a="(?:,|^|\\s)"+a+"(?:,|$|\\s)");let r=new RegExp(a,s);function o(e,t,i,l,s){if(s=""===s?n.fn.highlight.defaults:s,3===e.nodeType){if(!n(e.parentNode).is(s)){let n=e.data.normalize("NFD").replace(/[\u0300-\u036f]/g,"").match(t);if(n){let t,s=document.createElement(i||"span");s.className=l||"highlight",t=/\.|,|\s/.test(n[0].charAt(0))?n.index+1:n.index;let a=e.splitText(t);a.splitText(n[1].length);let r=a.cloneNode(!0);return s.appendChild(r),a.parentNode.replaceChild(s,a),1}}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&!n(e).closest(s).length>0&&(e.tagName!==i.toUpperCase()||e.className!==l))for(let n=0;n{"use strict";var t={n:e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return t.d(a,{a}),a},d:(e,a)=>{for(var n in a)t.o(a,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:a[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>s});const a=window.DoMini;var n=t.n(a);n().fn.ajax=function(t){if("cors"==(t=this.extend({url:"",method:"GET",cors:"cors",data:{},success:null,fail:null,accept:"text/html",contentType:"application/x-www-form-urlencoded; charset=UTF-8"},t)).cors){let e=new XMLHttpRequest;return e.onreadystatechange=function(){null!=t.success&&4==this.readyState&&this.status>=200&&this.status<400&&t.success(this.responseText),null!=t.fail&&4==this.readyState&&this.status>=400&&t.fail(this)},e.open(t.method.toUpperCase(),t.url,!0),e.setRequestHeader("Content-type",t.contentType),e.setRequestHeader("Accept",t.accept),e.send(this.serializeObject(t.data)),e}{let e="ajax_cb_"+"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})).replaceAll("-","");n().fn[e]=function(){t.success.apply(this,arguments),delete n().fn[t.data.fn]},t.data.callback="DoMini.fn."+e,t.data.fn=e;let a=document.createElement("script");a.type="text/javascript",a.src=t.url+"?"+this.serializeObject(t.data),a.onload=function(){this.remove()},document.body.appendChild(a)}};const s=n();window.DoMini=e.default})(); \ No newline at end of file +(()=>{"use strict";var t={n:e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return t.d(a,{a}),a},d:(e,a)=>{for(var n in a)t.o(a,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:a[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>s});const a=window.DoMini;var n=t.n(a);n().fn.ajax=function(t){if("cors"===(t=this.extend({url:"",method:"GET",cors:"cors",data:{},success:null,fail:null,accept:"text/html",contentType:"application/x-www-form-urlencoded; charset=UTF-8"},t)).cors){let e=new XMLHttpRequest;return e.onreadystatechange=function(){null!=t.success&&4===this.readyState&&this.status>=200&&this.status<400&&t.success(this.responseText),null!=t.fail&&4===this.readyState&&this.status>=400&&t.fail(this)},e.open(t.method.toUpperCase(),t.url,!0),e.setRequestHeader("Content-type",t.contentType),e.setRequestHeader("Accept",t.accept),e.send(this.serializeObject(t.data)),e}{let e="ajax_cb_"+"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})).replaceAll("-","");n().fn[e]=function(){t.success.apply(this,arguments),delete n().fn[t.data.fn]},t.data.callback="DoMini.fn."+e,t.data.fn=e;let a=document.createElement("script");a.type="text/javascript",a.src=t.url+"?"+this.serializeObject(t.data),a.onload=function(){this.remove()},document.body.appendChild(a)}};const s=n();window.DoMini=e.default})(); \ No newline at end of file diff --git a/dist/domini.js b/dist/domini.js index f1996e1..b77dc72 100644 --- a/dist/domini.js +++ b/dist/domini.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DoMini",[],t):"object"==typeof exports?exports.DoMini=t():e.DoMini=t()}(window,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};if(e.d(t,{default:()=>r}),void 0===window.DoMini){var n=function(e,t){return void 0!==arguments[2]?this.constructor.call(this,e,t):1!=arguments.length||"function"!=typeof arguments[0]?new n(e,t,!0):void("complete"===document.readyState||"loaded"===document.readyState||"interactive"===document.readyState?arguments[0].apply(this,[n]):window.addEventListener("DOMContentLoaded",(()=>{arguments[0].apply(this,[n])})))};n.prototype=n.fn={constructor:function(e,t){if(this.length=0,void 0!==t){if(t instanceof n)return t.find(e);if(this.isValidNode(t)||"string"==typeof t)return n(t).find(e)}else if("string"==typeof e&&""!=e)this.push(...this._(e));else{if(e instanceof n)return e;this.isValidNode(e)&&this.push(e)}return this},_:function(e){return"<"===e.charAt(0)?n._fn.createElementsFromHTML(e):[...document.querySelectorAll(e)]},isValidNode:e=>e instanceof Element||e instanceof Document||e instanceof Window,push:Array.prototype.push,pop:Array.prototype.pop,sort:Array.prototype.sort,splice:Array.prototype.splice},n.prototype[Symbol.iterator]=Array.prototype[Symbol.iterator],n._fn={}}else n=window.DoMini;const i=n;i.fn.get=function(e){return void 0===e?Array.from(this):this[e]},i.fn.extend=function(){for(let e=1;e0&&this.forEach((function(e){e.classList.add.apply(e.classList,t)})),this},i.fn.removeClass=function(e){if(void 0!==e){let t=e;"string"==typeof e&&(t=e.split(" ")),t=t.filter((function(e){return""!==e.trim()})),t.length>0&&this.forEach((function(e){e.classList.remove.apply(e.classList,t)}))}else this.forEach((function(e){e.classList.length>0&&e.classList.remove.apply(e.classList,e.classList)}));return this},i.fn.isVisible=function(){let e,t=this.get(0),n=!0;for(;null!==t;){if(e=window.getComputedStyle(t),"none"==e.display||"hidden"==e.visibility||0==e.opacity){n=!1;break}t=t.parentElement}return n},i.fn.val=function(e){let t;if(1==arguments.length){for(const t of this)if("select-multiple"==t.type){e="string"==typeof e?e.split(","):e;for(let n,i=0,o=t.options.length;i0?e?parseInt(this.css("height"))+parseInt(this.css("marginTop"))+parseInt(this.css("marginBottom")):parseInt(this.css("height")):0},i.fn.noPaddingWidth=function(e){return e=e||!1,this.length>0?e?parseInt(this.css("width"))+parseInt(this.css("marginLeft"))+parseInt(this.css("marginRight")):parseInt(this.css("width")):0},i.fn.innerWidth=function(){let e=this.get(0);if(null!=e){let t=window.getComputedStyle(e);return this.outerWidth()-parseFloat(t.borderLeftWidth)-parseFloat(t.borderRightWidth)}return 0},i.fn.innerHeight=function(){let e=this.get(0);if(null!=e){let t=window.getComputedStyle(e);return this.outerHeight()-parseFloat(t.borderTopWidth)-parseFloat(t.borderBottomtWidth)}return 0},i.fn.width=function(){return this.outerWidth()},i.fn.height=function(){return this.outerHeight()},i.fn.on=function(){let e=arguments,t=function(e,t){let n;if("mouseenter"==t.type||"mouseleave"==t.type||"mouseover"==t.type){let o=document.elementFromPoint(t.clientX,t.clientY);if(!o.matches(e[1]))for(;(o=o.parentElement)&&!o.matches(e[1]););null!=o&&(n=i(o))}else n=i(t.target).closest(e[1]);if(null!=n&&n.closest(this).length>0){let i=[];if(i.push(t),void 0!==e[4])for(let t=4;t0)if(void 0===e){let e;for(;e=n._domini_events.pop();)n.removeEventListener(e.type,e.func,e.args);n._domini_events=[]}else e.split(" ").forEach((function(e){let i,o=[];for(;i=n._domini_events.pop();)i.type!=e||void 0!==t&&i.trigger!=t?o.push(i):n.removeEventListener(e,i.func,i.args);n._domini_events=o}))})),this},i.fn.offForced=function(){let e=this;return this.forEach((function(t,n){let i=t.cloneNode(!0);t.parentNode.replaceChild(i,t),e[n]=i})),this},i.fn.trigger=function(e,t,n,o){return n=n||!1,o=o||!1,this.forEach((function(r){let s=!1;if(o&&"undefined"!=typeof jQuery&&void 0!==jQuery._data&&void 0!==jQuery._data(r,"events")&&void 0!==jQuery._data(r,"events")[e]&&(jQuery(r).trigger(e,t),s=!0),!s&&n){let n=new Event(e);n.detail=t,r.dispatchEvent(n)}if(void 0!==r._domini_events)r._domini_events.forEach((function(n){if(n.type==e){let i=new Event(e);n.trigger.apply(r,[i].concat(t))}}));else{let n=!1,o=r;for(;o=o.parentElement,null!=o&&(void 0!==o._domini_events&&o._domini_events.forEach((function(s){if(void 0!==s.selector){let l=i(o).find(s.selector);if(l.length>0&&l.get().indexOf(r)>=0&&s.type==e){let i=new Event(e);s.trigger.apply(r,[i].concat(t)),n=!0}}})),!n););}})),this},i.fn.clear=function(){for(const e of this)delete e._domini_events;return this},i.fn.clone=function(){let e=[];for(const t of this)e.push(t.cloneNode(!0));return i().add(e)},i.fn.detach=function(e){let t=this,n=[];void 0!==e&&(t=this.find(e));for(const e of t)null!=e.parentElement&&n.push(e.parentElement.removeChild(e));return i().add(n)},i.fn.remove=function(e){return this.detach(e).off().clear()},i.fn.prepend=function(e){if((e=i._fn.ElementArrayFromAny(e)).length>0)for(const t of this)for(const n of e)t.insertBefore(n,t.children[0]);return this},i.fn.append=function(e){if((e=i._fn.ElementArrayFromAny(e)).length>0)for(const t of this)for(const n of e)t.appendChild(n);return this},i.fn.is=function(e){let t=!1;for(const n of this)if(n.matches(e)){t=!0;break}return t},i.fn.parent=function(e){let t=[];for(const n of this){let i=n.parentElement;"string"==typeof e&&(null==i||i.matches(e)||(i=null)),t.push(i)}return i().add(t)},i.fn.copy=function(e,t){let n,i,o;if("object"!=typeof e||null===e)return n=e,n;for(i in n=new e.constructor,e)e.hasOwnProperty(i)&&(o=typeof e[i],t&&"object"===o&&null!==e[i]?n[i]=this.copy(e[i]):n[i]=e[i]);return n},i.fn.first=function(){return i(this[0])},i.fn.last=function(){return i(this[this.length-1])},i.fn.prev=function(e){let t=[];for(const n of this){let i;if("string"==typeof e)for(i=n.previousElementSibling;null!=i;){if(i.matches(e)){t.push(i);break}i=i.previousElementSibling}else t.push(n.previousElementSibling)}return i(null).add(t)},i.fn.next=function(e){let t=[];for(const n of this){let i;if("string"==typeof e)for(i=n.nextElementSibling;null!=i;){if(i.matches(e)){t.includes(i)||t.push(i);break}i=i.nextElementSibling}else t.push(n.nextElementSibling)}return i(null).add(t)},i.fn.closest=function(e){let t=[];for(let n of this)if("string"==typeof e&&""!==e){for(;!n.matches(e)&&(n=n.parentElement););t.includes(n)||t.push(n)}else{if((e=e instanceof i?e.get(0):e)instanceof Element)for(;n!==e&&(n=n.parentElement););else n=null;t.includes(n)||t.push(n)}return i().add(t)},i.fn.add=function(e){let t=i._fn.ElementArrayFromAny(e);for(const e of t)Array.from(this).includes(e)||this.push(e);return this},i.fn.find=function(e){const t=new i;if("string"==typeof e){let n=[];this.get().forEach((function(t){const i=t.querySelectorAll?.(e)??[];n=n.concat(Array.from(i))})),n.length>0&&t.add(n)}return t},i._fn.bodyTransform=function(){let e=0,t=0;if("undefined"!=typeof WebKitCSSMatrix){let n=window.getComputedStyle(document.body);if(void 0!==n.transform){let i=new WebKitCSSMatrix(n.transform);"undefined"!=i.m41&&(e=i.m41),"undefined"!=i.m42&&(t=i.m42)}}return{x:e,y:t}},i._fn.bodyTransformY=function(){return this.bodyTransform().y},i._fn.bodyTransformX=function(){return this.bodyTransform().x},i._fn.hasFixedParent=function(e){if(0!=i._fn.bodyTransformY())return!1;do{if("fixed"==window.getComputedStyle(e).position)return!0}while(e=e.parentElement);return!1},i._fn.hasEventListener=function(e,t,n){if(void 0===e._domini_events)return!1;for(let i=0;ie instanceof Element))}return e},i._fn.absolutePosition=function(e){if(!e.getClientRects().length)return{top:0,left:0};let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView;return{top:t.top+n.pageYOffset,left:t.left+n.pageXOffset}},i._fn.plugin=function(e,t){i.fn[e]=function(n){return void 0!==n&&t[n]?t[n].apply(this,Array.prototype.slice.call(arguments,1)):this.forEach((function(i){i["domini_"+e]=Object.create(t).init(n,i)}))}},document.dispatchEvent(new Event("domini-dom-core-loaded"));const o=i;i.fn.animate=function(e,t,n){t=t||200,n=n||"easeInOutQuad";for(const o of this){let r,s,l,f,a,c=0,u=60,h={},d={};if(l=this.prop("_domini_animations"),l=null==l?[]:l,!1===e)l.forEach((function(e){clearInterval(e)}));else{function p(){c++,c>r?clearInterval(f):(s=a(c/r),Object.keys(d).forEach((function(e){e.indexOf("scroll")>-1?o[e]=h[e]+d[e]*s:o.style[e]=h[e]+d[e]*s+"px"})))}a=i.fn.animate.easing[n]??i.fn.animate.easing.easeInOutQuad,Object.keys(e).forEach((function(t){t.indexOf("scroll")>-1?(h[t]=o[t],d[t]=e[t]-h[t]):(h[t]=parseInt(window.getComputedStyle(o)[t]),d[t]=e[t]-h[t])})),r=t/1e3*u,f=setInterval(p,1e3/u),l.push(f),this.prop("_domini_animations",l)}}return this},i.fn.animate.easing={linear:function(e){return e},easeInOutQuad:function(e){return e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2},easeOutQuad:function(e){return 1-(1-e)*(1-e)}},i.fn.unhighlight=function(e){let t={className:"highlight",element:"span"};return i.fn.extend(t,e),this.find(t.element+"."+t.className).forEach((function(){let e=this.parentNode;e.replaceChild(this.firstChild,this),e.normalize()}))},i.fn.highlight=function(e,t){this.defaults={className:"highlight",element:"span",caseSensitive:!1,wordsOnly:!1,excludeParents:".excludeFromHighlight"};const n=i,o={...this.defaults,...t};if(e.constructor===String&&(e=[e]),(e=e.filter((function(e){return""!=e}))).forEach((function(e,t,n){n[t]=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").normalize("NFD").replace(/[\u0300-\u036f]/g,"")})),0==e.length)return this;let r=o.caseSensitive?"":"i",s="("+e.join("|")+")";o.wordsOnly&&(s="(?:,|^|\\s)"+s+"(?:,|$|\\s)");let l=new RegExp(s,r);function f(e,t,i,o,r){if(r=""==r?n.fn.highlight.defaults:r,3===e.nodeType){if(!n(e.parentNode).is(r)){let n=e.data.normalize("NFD").replace(/[\u0300-\u036f]/g,"").match(t);if(n){let t,r=document.createElement(i||"span");r.className=o||"highlight",t=/\.|,|\s/.test(n[0].charAt(0))?n.index+1:n.index;let s=e.splitText(t);s.splitText(n[1].length);let l=s.cloneNode(!0);return r.appendChild(l),s.parentNode.replaceChild(r,s),1}}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&!n(e).closest(r).length>0&&(e.tagName!==i.toUpperCase()||e.className!==o))for(let n=0;n=0;t-=1)if(""!==e.elements[t].name)switch(e.elements[t].nodeName){case"INPUT":switch(e.elements[t].type){case"checkbox":case"radio":e.elements[t].checked&&i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value));break;case"file":break;default:i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value))}break;case"TEXTAREA":i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value));break;case"SELECT":switch(e.elements[t].type){case"select-one":i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value));break;case"select-multiple":for(n=e.elements[t].options.length-1;n>=0;n-=1)e.elements[t].options[n].selected&&i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].options[n].value))}break;case"BUTTON":switch(e.elements[t].type){case"reset":case"submit":case"button":i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value))}}return i.join("&")},i.fn.serializeObject=function(e,t){let n,o=[];for(n in e)if(e.hasOwnProperty(n)){let r=t?t+"["+n+"]":n,s=e[n];o.push(null!==s&&"object"==typeof s?i.fn.serializeObject(s,r):encodeURIComponent(r)+"="+encodeURIComponent(s))}return o.join("&")},i.fn.inViewPort=function(e,t){let n,i,o=this.get(0);if(null==o)return!1;e=void 0===e?0:e,t=void 0===t?window:"string"==typeof t?document.querySelector(t):t;let r=o.getBoundingClientRect(),s=r.top,l=r.bottom,f=r.left,a=r.right,c=!1;if(null==t&&(t=window),t===window)n=window.innerWidth||0,i=window.innerHeight||0;else{n=t.clientWidth,i=t.clientHeight;let e=t.getBoundingClientRect();s-=e.top,l-=e.top,f-=e.left,a-=e.left}return e=~~Math.round(parseFloat(e)),a<=0||f>=n||(c=e>0?s>=e&&l0&&s<=i-e)|(s<=0&&l>e)),c},i.fn.ajax=function(e){if("cors"==(e=this.extend({url:"",method:"GET",cors:"cors",data:{},success:null,fail:null,accept:"text/html",contentType:"application/x-www-form-urlencoded; charset=UTF-8"},e)).cors){let t=new XMLHttpRequest;return t.onreadystatechange=function(){null!=e.success&&4==this.readyState&&this.status>=200&&this.status<400&&e.success(this.responseText),null!=e.fail&&4==this.readyState&&this.status>=400&&e.fail(this)},t.open(e.method.toUpperCase(),e.url,!0),t.setRequestHeader("Content-type",e.contentType),t.setRequestHeader("Accept",e.accept),t.send(this.serializeObject(e.data)),t}{let t="ajax_cb_"+"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){let t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})).replaceAll("-","");i.fn[t]=function(){e.success.apply(this,arguments),delete i.fn[e.data.fn]},e.data.callback="DoMini.fn."+t,e.data.fn=t;let n=document.createElement("script");n.type="text/javascript",n.src=e.url+"?"+this.serializeObject(e.data),n.onload=function(){this.remove()},document.body.appendChild(n)}};const r=o;return t.default})())); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DoMini",[],t):"object"==typeof exports?exports.DoMini=t():e.DoMini=t()}(window,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};let n;e.d(t,{default:()=>r}),void 0===window.DoMini?(n=function(e,t){return void 0!==arguments[2]?this.constructor.call(this,e,t):1!==arguments.length||"function"!=typeof arguments[0]?new n(e,t,!0):void("complete"===document.readyState||"loaded"===document.readyState||"interactive"===document.readyState?arguments[0].apply(this,[n]):window.addEventListener("DOMContentLoaded",(()=>{arguments[0].apply(this,[n])})))},n.prototype=n.fn={constructor:function(e,t){if(this.length=0,void 0!==t){if(t instanceof n)return t.find(e);if(this.isValidNode(t)||"string"==typeof t)return n(t).find(e)}else if("string"==typeof e&&""!==e)this.push(...this._(e));else{if(e instanceof n)return e;this.isValidNode(e)&&this.push(e)}return this},_:function(e){return"<"===e.charAt(0)?n._fn.createElementsFromHTML(e):[...document.querySelectorAll(e)]},isValidNode:e=>e instanceof Element||e instanceof Document||e instanceof Window,push:Array.prototype.push,pop:Array.prototype.pop,sort:Array.prototype.sort,splice:Array.prototype.splice},n.prototype[Symbol.iterator]=Array.prototype[Symbol.iterator],n._fn={},n.version="0.2.5"):n=window.DoMini;const i=n;i.fn.get=function(e){return void 0===e?Array.from(this):this[e]},i.fn.extend=function(){for(let e=1;e0&&this.forEach((function(e){e.classList.add.apply(e.classList,t)})),this},i.fn.removeClass=function(e){if(void 0!==e){let t=e;"string"==typeof e&&(t=e.split(" ")),t=t.filter((function(e){return""!==e.trim()})),t.length>0&&this.forEach((function(e){e.classList.remove.apply(e.classList,t)}))}else this.forEach((function(e){e.classList.length>0&&e.classList.remove.apply(e.classList,e.classList)}));return this},i.fn.isVisible=function(){let e,t=this.get(0),n=!0;for(;null!==t;){if(e=window.getComputedStyle(t),"none"===e.display||"hidden"===e.visibility||0===parseInt(e.opacity)){n=!1;break}t=t.parentElement}return n},i.fn.val=function(e){let t;if(1===arguments.length){for(const t of this)if("select-multiple"===t.type){e="string"==typeof e?e.split(","):e;for(let n,i=0,o=t.options.length;i0?e?parseInt(this.css("height"))+parseInt(this.css("marginTop"))+parseInt(this.css("marginBottom")):parseInt(this.css("height")):0},i.fn.noPaddingWidth=function(e){return e=e||!1,this.length>0?e?parseInt(this.css("width"))+parseInt(this.css("marginLeft"))+parseInt(this.css("marginRight")):parseInt(this.css("width")):0},i.fn.innerWidth=function(){let e=this.get(0);if(null!=e){let t=window.getComputedStyle(e);return this.outerWidth()-parseFloat(t.borderLeftWidth)-parseFloat(t.borderRightWidth)}return 0},i.fn.innerHeight=function(){let e=this.get(0);if(null!=e){let t=window.getComputedStyle(e);return this.outerHeight()-parseFloat(t.borderTopWidth)-parseFloat(t.borderBottomtWidth)}return 0},i.fn.width=function(){return this.outerWidth()},i.fn.height=function(){return this.outerHeight()},i.fn.on=function(){let e=arguments,t=function(e,t){let n;if("mouseenter"===t.type||"mouseleave"===t.type||"mouseover"===t.type){let o=document.elementFromPoint(t.clientX,t.clientY);if(!o.matches(e[1]))for(;(o=o.parentElement)&&!o.matches(e[1]););null!=o&&(n=i(o))}else n=i(t.target).closest(e[1]);if(null!=n&&n.closest(this).length>0){let i=[];if(i.push(t),void 0!==e[4])for(let t=4;t0)if(void 0===e){let e;for(;e=n._domini_events.pop();)n.removeEventListener(e.type,e.func,e.args);n._domini_events=[]}else e.split(" ").forEach((function(e){let i,o=[];for(;i=n._domini_events.pop();)i.type!==e||void 0!==t&&i.trigger!==t?o.push(i):n.removeEventListener(e,i.func,i.args);n._domini_events=o}))})),this},i.fn.offForced=function(){let e=this;return this.forEach((function(t,n){let i=t.cloneNode(!0);t.parentNode.replaceChild(i,t),e[n]=i})),this},i.fn.trigger=function(e,t,n,o){return n=n||!1,o=o||!1,this.forEach((function(r){let s=!1;if(o&&"undefined"!=typeof jQuery&&void 0!==jQuery._data&&void 0!==jQuery._data(r,"events")&&void 0!==jQuery._data(r,"events")[e]&&(jQuery(r).trigger(e,t),s=!0),!s&&n){let n=new Event(e);n.detail=t,r.dispatchEvent(n)}if(void 0!==r._domini_events)r._domini_events.forEach((function(n){if(n.type===e){let i=new Event(e);n.trigger.apply(r,[i].concat(t))}}));else{let n=!1,o=r;for(;o=o.parentElement,null!=o&&(void 0!==o._domini_events&&o._domini_events.forEach((function(s){if(void 0!==s.selector){let l=i(o).find(s.selector);if(l.length>0&&l.get().indexOf(r)>=0&&s.type===e){let i=new Event(e);s.trigger.apply(r,[i].concat(t)),n=!0}}})),!n););}})),this},i.fn.clear=function(){for(const e of this)delete e._domini_events;return this},i.fn.clone=function(){let e=[];for(const t of this)e.push(t.cloneNode(!0));return i().add(e)},i.fn.detach=function(e){let t=this,n=[];void 0!==e&&(t=this.find(e));for(const e of t)null!=e.parentElement&&n.push(e.parentElement.removeChild(e));return i().add(n)},i.fn.remove=function(e){return this.detach(e).off().clear()},i.fn.prepend=function(e){if((e=i._fn.elementArrayFromAny(e)).length>0)for(const t of this)for(const n of e)t.insertBefore(n,t.children[0]);return this},i.fn.append=function(e){if((e=i._fn.elementArrayFromAny(e)).length>0)for(const t of this)for(const n of e)t.appendChild(n);return this},i.fn.is=function(e){let t=!1;for(const n of this)if(n.matches(e)){t=!0;break}return t},i.fn.parent=function(e){let t=[];for(const n of this){let i=n.parentElement;"string"==typeof e&&(null==i||i.matches(e)||(i=null)),t.push(i)}return i().add(t)},i.fn.copy=function(e,t){let n,i,o;if("object"!=typeof e||null===e)return n=e,n;for(i in n=new e.constructor,e)e.hasOwnProperty(i)&&(o=typeof e[i],t&&"object"===o&&null!==e[i]?n[i]=this.copy(e[i]):n[i]=e[i]);return n},i.fn.first=function(){return i(this[0])},i.fn.last=function(){return i(this[this.length-1])},i.fn.prev=function(e){let t=[];for(const n of this){let i;if("string"==typeof e)for(i=n.previousElementSibling;null!=i;){if(i.matches(e)){t.push(i);break}i=i.previousElementSibling}else t.push(n.previousElementSibling)}return i(null).add(t)},i.fn.next=function(e){let t=[];for(const n of this){let i;if("string"==typeof e)for(i=n.nextElementSibling;null!=i;){if(i.matches(e)){t.includes(i)||t.push(i);break}i=i.nextElementSibling}else t.push(n.nextElementSibling)}return i(null).add(t)},i.fn.closest=function(e){let t=[];for(let n of this)if("string"==typeof e&&""!==e){for(;!n.matches(e)&&(n=n.parentElement););t.includes(n)||t.push(n)}else{if((e=e instanceof i?e.get(0):e)instanceof Element)for(;n!==e&&(n=n.parentElement););else n=null;t.includes(n)||t.push(n)}return i().add(t)},i.fn.add=function(e){let t=i._fn.elementArrayFromAny(e);for(const e of t)Array.from(this).includes(e)||this.push(e);return this},i.fn.find=function(e){const t=new i;if("string"==typeof e){let n=[];this.get().forEach((function(t){const i=t.querySelectorAll?.(e)??[];n=n.concat(Array.from(i))})),n.length>0&&t.add(n)}return t},i._fn.bodyTransform=function(){let e=0,t=0;if("undefined"!=typeof WebKitCSSMatrix){let n=window.getComputedStyle(document.body);if(void 0!==n.transform){let i=new WebKitCSSMatrix(n.transform);"undefined"!==i.m41&&(e=i.m41),"undefined"!==i.m42&&(t=i.m42)}}return{x:e,y:t}},i._fn.bodyTransformY=function(){return this.bodyTransform().y},i._fn.bodyTransformX=function(){return this.bodyTransform().x},i._fn.hasFixedParent=function(e){if(0!=i._fn.bodyTransformY())return!1;do{if("fixed"==window.getComputedStyle(e).position)return!0}while(e=e.parentElement);return!1},i._fn.hasEventListener=function(e,t,n){if(void 0===e._domini_events)return!1;for(let i=0;ie instanceof Element))}return e},i._fn.ElementArrayFromAny=i._fn.elementArrayFromAny,i._fn.absolutePosition=function(e){if(!e.getClientRects().length)return{top:0,left:0};let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView;return{top:t.top+n.pageYOffset,left:t.left+n.pageXOffset}},i._fn.plugin=function(e,t){i.fn[e]=function(n){return void 0!==n&&t[n]?t[n].apply(this,Array.prototype.slice.call(arguments,1)):this.forEach((function(i){i["domini_"+e]=Object.create(t).init(n,i)}))}},document.dispatchEvent(new Event("domini-dom-core-loaded"));const o=i;i.fn.animate=function(e,t,n){t=t||200,n=n||"easeInOutQuad";for(const o of this){let r,s,l,f,a,c=0,u=60,h={},d={};if(l=this.prop("_domini_animations"),l=null==l?[]:l,!1===e)l.forEach((function(e){clearInterval(e)}));else{function p(){c++,c>r?clearInterval(f):(s=a(c/r),Object.keys(d).forEach((function(e){e.indexOf("scroll")>-1?o[e]=h[e]+d[e]*s:o.style[e]=h[e]+d[e]*s+"px"})))}a=i.fn.animate.easing[n]??i.fn.animate.easing.easeInOutQuad,Object.keys(e).forEach((function(t){t.indexOf("scroll")>-1?(h[t]=o[t],d[t]=e[t]-h[t]):(h[t]=parseInt(window.getComputedStyle(o)[t]),d[t]=e[t]-h[t])})),r=t/1e3*u,f=setInterval(p,1e3/u),l.push(f),this.prop("_domini_animations",l)}}return this},i.fn.animate.easing={linear:function(e){return e},easeInOutQuad:function(e){return e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2},easeOutQuad:function(e){return 1-(1-e)*(1-e)}},i.fn.unhighlight=function(e){let t={className:"highlight",element:"span"};return i.fn.extend(t,e),this.find(t.element+"."+t.className).forEach((function(){let e=this.parentNode;e.replaceChild(this.firstChild,this),e.normalize()}))},i.fn.highlight=function(e,t){this.defaults={className:"highlight",element:"span",caseSensitive:!1,wordsOnly:!1,excludeParents:".excludeFromHighlight"};const n=i,o={...this.defaults,...t};if(e.constructor===String&&(e=[e]),(e=e.filter((function(e){return""!==e}))).forEach((function(e,t,n){n[t]=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").normalize("NFD").replace(/[\u0300-\u036f]/g,"")})),0===e.length)return this;let r=o.caseSensitive?"":"i",s="("+e.join("|")+")";o.wordsOnly&&(s="(?:,|^|\\s)"+s+"(?:,|$|\\s)");let l=new RegExp(s,r);function f(e,t,i,o,r){if(r=""===r?n.fn.highlight.defaults:r,3===e.nodeType){if(!n(e.parentNode).is(r)){let n=e.data.normalize("NFD").replace(/[\u0300-\u036f]/g,"").match(t);if(n){let t,r=document.createElement(i||"span");r.className=o||"highlight",t=/\.|,|\s/.test(n[0].charAt(0))?n.index+1:n.index;let s=e.splitText(t);s.splitText(n[1].length);let l=s.cloneNode(!0);return r.appendChild(l),s.parentNode.replaceChild(r,s),1}}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&!n(e).closest(r).length>0&&(e.tagName!==i.toUpperCase()||e.className!==o))for(let n=0;n=0;t-=1)if(""!==e.elements[t].name)switch(e.elements[t].nodeName){case"INPUT":switch(e.elements[t].type){case"checkbox":case"radio":e.elements[t].checked&&i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value));break;case"file":break;default:i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value))}break;case"TEXTAREA":i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value));break;case"SELECT":switch(e.elements[t].type){case"select-one":i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value));break;case"select-multiple":for(n=e.elements[t].options.length-1;n>=0;n-=1)e.elements[t].options[n].selected&&i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].options[n].value))}break;case"BUTTON":switch(e.elements[t].type){case"reset":case"submit":case"button":i.push(e.elements[t].name+"="+encodeURIComponent(e.elements[t].value))}}return i.join("&")},i.fn.serializeObject=function(e,t){let n,o=[];for(n in e)if(e.hasOwnProperty(n)){let r=t?t+"["+n+"]":n,s=e[n];o.push(null!==s&&"object"==typeof s?i.fn.serializeObject(s,r):encodeURIComponent(r)+"="+encodeURIComponent(s))}return o.join("&")},i.fn.inViewPort=function(e,t){let n,i,o=this.get(0);if(null==o)return!1;e=void 0===e?0:e,t=void 0===t?window:"string"==typeof t?document.querySelector(t):t;let r=o.getBoundingClientRect(),s=r.top,l=r.bottom,f=r.left,a=r.right,c=!1;if(null==t&&(t=window),t===window)n=window.innerWidth||0,i=window.innerHeight||0;else{n=t.clientWidth,i=t.clientHeight;let e=t.getBoundingClientRect();s-=e.top,l-=e.top,f-=e.left,a-=e.left}return e=~~Math.round(parseFloat(e)),a<=0||f>=n||(c=e>0?s>=e&&l0&&s<=i-e)|(s<=0&&l>e)),c},i.fn.ajax=function(e){if("cors"===(e=this.extend({url:"",method:"GET",cors:"cors",data:{},success:null,fail:null,accept:"text/html",contentType:"application/x-www-form-urlencoded; charset=UTF-8"},e)).cors){let t=new XMLHttpRequest;return t.onreadystatechange=function(){null!=e.success&&4===this.readyState&&this.status>=200&&this.status<400&&e.success(this.responseText),null!=e.fail&&4===this.readyState&&this.status>=400&&e.fail(this)},t.open(e.method.toUpperCase(),e.url,!0),t.setRequestHeader("Content-type",e.contentType),t.setRequestHeader("Accept",e.accept),t.send(this.serializeObject(e.data)),t}{let t="ajax_cb_"+"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){let t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})).replaceAll("-","");i.fn[t]=function(){e.success.apply(this,arguments),delete i.fn[e.data.fn]},e.data.callback="DoMini.fn."+t,e.data.fn=t;let n=document.createElement("script");n.type="text/javascript",n.src=e.url+"?"+this.serializeObject(e.data),n.onload=function(){this.remove()},document.body.appendChild(n)}};const r=o;return t.default})())); \ No newline at end of file diff --git a/domini.d.ts b/domini.d.ts index cff049f..0342681 100644 --- a/domini.d.ts +++ b/domini.d.ts @@ -1,15 +1,59 @@ declare module "domini" { - type HTMLElementWithFields = HTMLElement&{[otherFields: string]: unknown;}; + type ElementWithFields = Element&{[otherFields: string]: unknown;}; - interface DOMini extends Array { - (selector?: string|HTMLElement): this; + interface DOMini extends Array { + (selector?: string|Element): this; fn: { - _: (selector: string) => Array + _: (selector: string) => Array, + + ajax: (args: { + 'url': string, + 'method'?: XMLHttpRequest.HttpMethod, + 'cors'?: 'cors'|'no-cors', // cors, no-cors + 'data'?: unknown, + 'success'?: (response_text: string) => void, + 'fail'?: (request: XMLHttpRequest) => void, + 'accept'?: string, + 'contentType'?: XMLHttpRequest.ContentType + } = { + 'url': '', + 'method': 'GET', + 'cors': 'cors', // cors, no-cors + 'data': {}, + 'success': null, + 'fail': null, + 'accept': 'text/html', + 'contentType': 'application/x-www-form-urlencoded; charset=UTF-8' + }) => void, }, _fn: { - plugin: (name: string, object: Object) => this + plugin: (name: string, object: Object) => this, + + bodyTransform: () => { + top: number, + left: number, + }, + + bodyTransformY: () => number, + + bodyTransformX: () => number, + + hasFixedParent: (element: Element) => boolean, + + hasEventListener: (element: Element, event_type: string, func: Function) => boolean, + + allDescendants: (element: Element) => Array, + + createElementsFromHTML: (html_string: string) => Array, + + elementArrayFromAny: (anything: string|Element|Element[]|DOMini) => Array, + + absolutePosition: (element: Element) => { + top: number, + left: number, + }, } - add: (selector: string|HTMLElement) => this, + add: (selector: string|Element) => this, css: { (properties: Record): this; @@ -62,11 +106,11 @@ declare module "domini" { extend: (...args: Object) => Object, - each: (callback: (index?: number, node?: HTMLElementWithFields, array?: HTMLElementWithFields[])=>unknown) => this + each: (callback: (index?: number, node?: ElementWithFields, array?: ElementWithFields[])=>unknown) => this - forEach: (callback: (node?: HTMLElementWithFields, index?: number, array?: HTMLElementWithFields[])=>unknown) => this + forEach: (callback: (node?: ElementWithFields, index?: number, array?: ElementWithFields[])=>unknown) => this - get: (n: number) => HTMLElementWithFields, + get: (n: number) => ElementWithFields, offset: ()=> { top: number, @@ -119,13 +163,64 @@ declare module "domini" { clone: () => this, - detach: (context?: string|HTMLElement) => this, + detach: (context?: string|Element) => this, + + remove: (context?: string|Element) => this, + + prepend: (prepend: string|Element|Element[]|DOMini) => this, - remove: (context?: string|HTMLElement) => this, + append: (prepend: string|Element|Element[]|DOMini) => this, - prepend: (prepend: string|HTMLElement|HTMLElement[]|DOMini) => this, + is: (selectors: string) => boolean, + + parent: (selectors?: string) => this, + + copy: (source: Object|Array, deep?: boolean = false) => typeof source, + + first: () => this, + + last: () => this, + + prev: (selectors?: string) => this, + + next: (selectors?: string) => this, + + closest: (selectors?: string|Element|DOMini) => this, + + find: (selectors?: string) => this, + + animate: { + (props: false|Record, duration?: number = 200, easing?: keyof DOMini.animate.easing), + easing: Recordnumber>, + }, - append: (prepend: string|HTMLElement|HTMLElement[]|DOMini) => this, + unhighlight: (options?: { + className?: string, + element?: 'span' + } = { + className: 'highlight', + element: 'span' + }) => this, + + highlight: (word: string, options?: { + className?: string, + element?: string, + caseSensitive?: boolean, + wordsOnly?: boolean, + excludeParents?: string + } = { + className: 'highlight', + element: 'span', + caseSensitive: false, + wordsOnly: false, + excludeParents: '.excludeFromHighlight' + }) => this, + + serialize: () => string, + + serializeObject: (object: Object, prefix: string) => string, + + inViewPort: (tolerance: number = 0, viewport: Element = window) => boolean, /** * Addons and other possibly dynamically added fields diff --git a/package.json b/package.json index 24fce6f..fb21af6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "domini", - "version": "0.2.4", + "version": "0.2.5", "description": "Minimalistic DOM manipulation tool", "main": "dist/domini.js", "types": "domini.d.ts", diff --git a/src/base.js b/src/base.js index 289a5ee..0c643e7 100644 --- a/src/base.js +++ b/src/base.js @@ -20,7 +20,7 @@ if ( typeof window.DoMini == 'undefined' ) { //if ( arguments.length >= 1 ) { // Case of DoMini(function($){..}) - if ( arguments.length == 1 && typeof arguments[0] == 'function' ) { + if ( arguments.length === 1 && typeof arguments[0] == 'function' ) { if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") { arguments[0].apply(this, [DoMini]); } else { @@ -78,7 +78,7 @@ if ( typeof window.DoMini == 'undefined' ) { push: Array.prototype.push, pop: Array.prototype.pop, sort: Array.prototype.sort, - splice: Array.prototype.splice + splice: Array.prototype.splice, } // Define the iterator symbol to the array iterator, allows "for of.." and derivates @@ -86,6 +86,8 @@ if ( typeof window.DoMini == 'undefined' ) { // Utility functions container DoMini._fn = {}; + + DoMini.version = "0.2.5"; } else { DoMini = window.DoMini; } diff --git a/src/core/manipulation.js b/src/core/manipulation.js index faa035f..a37c9f1 100644 --- a/src/core/manipulation.js +++ b/src/core/manipulation.js @@ -36,7 +36,7 @@ DoMini.fn.remove = function(selector) { }; DoMini.fn.prepend = function(prepend) { - prepend = DoMini._fn.ElementArrayFromAny(prepend); + prepend = DoMini._fn.elementArrayFromAny(prepend); if ( prepend.length > 0 ) { for ( const el of this ) { for ( const pre of prepend ) { @@ -48,7 +48,7 @@ DoMini.fn.prepend = function(prepend) { }; DoMini.fn.append = function(append) { - append = DoMini._fn.ElementArrayFromAny(append); + append = DoMini._fn.elementArrayFromAny(append); if ( append.length > 0 ) { for ( const el of this ) { for ( const ap of append ) { diff --git a/src/core/selector.js b/src/core/selector.js index 3399640..e2acf01 100644 --- a/src/core/selector.js +++ b/src/core/selector.js @@ -123,7 +123,7 @@ DoMini.fn.closest = function (s) { }; DoMini.fn.add = function( el ) { - let elements = DoMini._fn.ElementArrayFromAny(el); + let elements = DoMini._fn.elementArrayFromAny(el); for (const element of elements) { if ( !Array.from(this).includes(element) ) { this.push(element); diff --git a/src/core/utils.js b/src/core/utils.js index 9b89dc6..bc1dbc0 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -6,10 +6,10 @@ DoMini._fn.bodyTransform = function() { let style = window.getComputedStyle(document.body); if ( typeof style.transform != 'undefined' ) { let matrix = new WebKitCSSMatrix(style.transform); - if ( matrix.m41 != 'undefined' ) { + if ( matrix.m41 !== 'undefined' ) { x = matrix.m41; } - if ( matrix.m42 != 'undefined' ) { + if ( matrix.m42 !== 'undefined' ) { y = matrix.m42; } } @@ -47,7 +47,7 @@ DoMini._fn.hasEventListener = function(el, type, trigger) { return false; } for (let i = 0; i < el._domini_events.length; i++) { - if ( el._domini_events[i].trigger == trigger && el._domini_events[i].type == type ) { + if ( el._domini_events[i].trigger === trigger && el._domini_events[i].type === type ) { return true; } } @@ -81,7 +81,7 @@ DoMini._fn.createElementsFromHTML = function(htmlString) { * @param {String|DoMini|Element|Array} any * @returns {Array} */ -DoMini._fn.ElementArrayFromAny = function(any) { +DoMini._fn.elementArrayFromAny = function(any) { if ( typeof any == 'string' ) { any = DoMini(any).get(); } else if ( any instanceof DoMini ) { @@ -98,6 +98,11 @@ DoMini._fn.ElementArrayFromAny = function(any) { return any; }; +/** + * Backwards compatibility because of typo in 0.2.4 + */ +DoMini._fn.ElementArrayFromAny = DoMini._fn.elementArrayFromAny; + DoMini._fn.absolutePosition = function(el) { if ( !el.getClientRects().length ) { return { top: 0, left: 0 }; diff --git a/src/modules/highlight.js b/src/modules/highlight.js index 3d4a23b..1e514e3 100644 --- a/src/modules/highlight.js +++ b/src/modules/highlight.js @@ -41,13 +41,13 @@ DoMini.fn.highlight = function (words, options) { words = [words]; } words = words.filter(function(el){ - return el != ''; + return el !== ''; }); words.forEach(function(w, i, o){ o[i] = w.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&").normalize("NFD").replace(/[\u0300-\u036f]/g, ""); }); - if (words.length == 0) { + if (words.length === 0) { return this; } @@ -58,7 +58,7 @@ DoMini.fn.highlight = function (words, options) { } let re = new RegExp(pattern, flag); function highlight(node, re, nodeName, className, excludeParents) { - excludeParents = excludeParents == '' ? $.fn.highlight.defaults : excludeParents; + excludeParents = excludeParents === '' ? $.fn.highlight.defaults : excludeParents; if (node.nodeType === 3) { if ( !$(node.parentNode).is(excludeParents) ) { let normalized = node.data.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); diff --git a/src/modules/xhttp.js b/src/modules/xhttp.js index 9aa360f..654eb6c 100644 --- a/src/modules/xhttp.js +++ b/src/modules/xhttp.js @@ -3,7 +3,7 @@ import DoMini from "../base"; DoMini.fn.ajax = function(args) { let uuidv4 = function() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); + let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); }; @@ -19,7 +19,7 @@ DoMini.fn.ajax = function(args) { } args = this.extend(defaults, args); - if ( args.cors != 'cors' ) { + if ( args.cors !== 'cors' ) { let fn = 'ajax_cb_' + uuidv4().replaceAll('-', ''); DoMini.fn[fn] = function() { args.success.apply(this, arguments); @@ -36,12 +36,12 @@ DoMini.fn.ajax = function(args) { let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if ( args.success != null ) { - if ( this.readyState == 4 && (this.status >= 200 && this.status < 400) ) { + if ( this.readyState === 4 && (this.status >= 200 && this.status < 400) ) { args.success(this.responseText); } } if ( args.fail != null ) { - if ( this.readyState == 4 && this.status >= 400 ) { + if ( this.readyState === 4 && this.status >= 400 ) { args.fail(this); } } diff --git a/test/core/data.js b/test/core/data.js index 3c5a2de..140f946 100644 --- a/test/core/data.js +++ b/test/core/data.js @@ -1,12 +1,10 @@ -import * as $ from "domini"; - QUnit.module("data.js tests", function(hooks) { + var $ = DoMini; hooks.beforeEach(function() { var f = document.getElementById('qunit-fixture'); f.innerHTML = fixture; }); - - QUnit.test('val()', function(assert) { + QUnit.test('val()', function(assert) { assert.equal($().val(), undefined, 'invalid element #1'); assert.equal($('div').val(), undefined, 'invalid element #2'); assert.equal($('select[name=single_select]').val(), 'value 4', 'single select value'); @@ -16,7 +14,8 @@ QUnit.module("data.js tests", function(hooks) { ); }); - QUnit.test('attr()', function(assert) { + + QUnit.test('attr()', function(assert) { assert.equal($().attr('id'), undefined, 'invalid element #1'); assert.equal($().attr('id', 'fakeId'), undefined, 'invalid element #2'); assert.equal($('#node').attr('id'), 'node', 'ID test'); @@ -29,7 +28,7 @@ QUnit.module("data.js tests", function(hooks) { $('*[id=yolo]').removeAttr('id'); }); - QUnit.test('prop()', function(assert) { + QUnit.test('prop()', function(assert) { assert.equal($().prop('randomProp'), undefined, 'invalid element #1'); assert.deepEqual($().prop('randomProp', 'propValue'), $(), 'invalid element #2'); assert.equal($('#node').prop('randomProp'), undefined, 'propValue test'); @@ -39,14 +38,14 @@ QUnit.module("data.js tests", function(hooks) { $('#list-container li').prop('randomProp', 'yolo'); assert.deepEqual($('#list-container li').prop('randomProp'), 'yolo', 'Multiple Attributes check'); - + document.querySelectorAll("#list-container li").forEach(function(el, i){ assert.equal(el['randomProp'], 'yolo', "Deep check el #" + i); assert.equal($($('#list-container li').get(i)).prop('randomProp'), 'yolo', "Deep check via DoMini #" + i); }); }); - QUnit.test('data()', function(assert) { + QUnit.test('data()', function(assert) { assert.equal($().data('id'), '', 'invalid element #1'); assert.deepEqual($().data('id', 'fakeDataId'), $(), 'invalid element #2'); assert.equal($('#node').attr('id'), 'node', 'ID test'); @@ -59,7 +58,7 @@ QUnit.module("data.js tests", function(hooks) { }); - QUnit.test('html()', function(assert) { + QUnit.test('html()', function(assert) { var nodeContent = document.getElementById('node').innerHTML; assert.equal($().html(), '', 'invalid element #1'); assert.equal($('null').html(), '', 'invalid element #2'); @@ -68,7 +67,7 @@ QUnit.module("data.js tests", function(hooks) { assert.notEqual($('#node').html(), ''); }); - QUnit.test('text()', function(assert) { + QUnit.test('text()', function(assert) { var title = document.getElementById('title').textContent; assert.equal($().text(), '', 'invalid element #1'); assert.equal($('null').text(), '', 'invalid element #2'); diff --git a/test/core/selector.js b/test/core/selector.js index e580a5a..a9f49f2 100644 --- a/test/core/selector.js +++ b/test/core/selector.js @@ -120,6 +120,7 @@ QUnit.module("selector.js tests", function(hooks) { assert.true($(null).prev().length == 0, 'on null'); assert.true($({}).prev().length == 0, 'on empty object'); assert.true($(undefined).prev().length == 0, 'on undefined'); + assert.true($(undefined).prev().prev().prev().length == 0, 'on undefined chained'); // 3 items, 2nd and 3rd have previous neighbors assert.equal(