Skip to content

Commit

Permalink
Bumped version to 8.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Apr 13, 2023
1 parent ac0108c commit 61e3b8f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### [v8.1.5](https://github.com/fabiospampinato/cash/releases/tag/8.1.5) (2023-04-13)

- Fixed support for using a selector as context
- $.hide: ensuring calling it multiple times sequentially works too

### [v8.1.4](https://github.com/fabiospampinato/cash/releases/tag/8.1.4) (2023-03-08)

- Updatd contribution guide
Expand Down
2 changes: 1 addition & 1 deletion dist/cash.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Ele = Window | Document | HTMLElement | Element | Node;
type EleLoose = HTMLElement & Element & Node;
type Selector = falsy | string | Function | HTMLCollection | NodeList | Ele | Ele[] | ArrayLike<Ele> | Cash;
type Comparator = string | Ele | Cash | ((this: EleLoose, index: number, ele: EleLoose) => boolean);
type Context = Document | HTMLElement | Element;
type Context = Document | HTMLElement | Element | string;
type PlainObject<T> = Record<string, T>;
type EventCallback = {
(event: any, data?: any): any;
Expand Down
15 changes: 10 additions & 5 deletions dist/cash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ class Cash {
return selector;
let eles = selector;
if (isString(selector)) {
const ctx = (isCash(context) ? context[0] : context) || doc;
eles = idRe.test(selector) && 'getElementById' in ctx
const ctx = context || doc;
eles = idRe.test(selector) && isDocument(ctx)
? ctx.getElementById(selector.slice(1).replace(/\\/g, ''))
: htmlRe.test(selector)
? parseHTML(selector)
: find(selector, ctx);
: isCash(ctx)
? ctx.find(selector)
: isString(ctx)
? cash(ctx).find(selector)
: find(selector, ctx);
if (!eles)
return;
}
Expand Down Expand Up @@ -876,14 +880,15 @@ fn.toggle = function (force) {
return this.each((i, ele) => {
if (!isElement(ele))
return;
const show = isUndefined(force) ? isHidden(ele) : force;
const hidden = isHidden(ele);
const show = isUndefined(force) ? hidden : force;
if (show) {
ele.style.display = ele[displayProperty] || '';
if (isHidden(ele)) {
ele.style.display = getDefaultDisplay(ele.tagName);
}
}
else {
else if (!hidden) {
ele[displayProperty] = computeStyle(ele, 'display');
ele.style.display = 'none';
}
Expand Down
15 changes: 10 additions & 5 deletions dist/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ var Cash = /** @class */ (function () {
return selector;
var eles = selector;
if (isString(selector)) {
var ctx = (isCash(context) ? context[0] : context) || doc;
eles = idRe.test(selector) && 'getElementById' in ctx
var ctx = context || doc;
eles = idRe.test(selector) && isDocument(ctx)
? ctx.getElementById(selector.slice(1).replace(/\\/g, ''))
: htmlRe.test(selector)
? parseHTML(selector)
: find(selector, ctx);
: isCash(ctx)
? ctx.find(selector)
: isString(ctx)
? cash(ctx).find(selector)
: find(selector, ctx);
if (!eles)
return;
}
Expand Down Expand Up @@ -885,14 +889,15 @@ fn.toggle = function (force) {
return this.each(function (i, ele) {
if (!isElement(ele))
return;
var show = isUndefined(force) ? isHidden(ele) : force;
var hidden = isHidden(ele);
var show = isUndefined(force) ? hidden : force;
if (show) {
ele.style.display = ele[displayProperty] || '';
if (isHidden(ele)) {
ele.style.display = getDefaultDisplay(ele.tagName);
}
}
else {
else if (!hidden) {
ele[displayProperty] = computeStyle(ele, 'display');
ele.style.display = 'none';
}
Expand Down
4 changes: 2 additions & 2 deletions dist/cash.min.js

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions dist/cash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Ele = Window | Document | HTMLElement | Element | Node;
type EleLoose = HTMLElement & Element & Node; //UGLY: Trick to remove some kind-of useless type errors //URL: https://github.com/fabiospampinato/cash/issues/278
type Selector = falsy | string | Function | HTMLCollection | NodeList | Ele | Ele[] | ArrayLike<Ele> | Cash;
type Comparator = string | Ele | Cash | (( this: EleLoose, index: number, ele: EleLoose ) => boolean);
type Context = Document | HTMLElement | Element;
type Context = Document | HTMLElement | Element | string;

type PlainObject<T> = Record<string, T>; //FIXME: Arrays can be assigned to this type, for whatever reason

Expand Down Expand Up @@ -86,13 +86,17 @@ class Cash {

if ( isString ( selector ) ) {

const ctx = ( isCash ( context ) ? context[0] : context ) || doc;
const ctx = context || doc;

eles = idRe.test ( selector ) && 'getElementById' in ctx
? ( ctx as Document ).getElementById ( selector.slice ( 1 ).replace ( /\\/g, '' ) )
eles = idRe.test ( selector ) && isDocument ( ctx )
? ctx.getElementById ( selector.slice ( 1 ).replace ( /\\/g, '' ) )
: htmlRe.test ( selector )
? parseHTML ( selector )
: find ( selector, ctx );
: isCash ( ctx )
? ctx.find ( selector )
: isString ( ctx )
? cash ( ctx ).find ( selector )
: find ( selector, ctx );

if ( !eles ) return;

Expand Down Expand Up @@ -2259,7 +2263,8 @@ fn.toggle = function ( this: Cash, force?: boolean ) {

if ( !isElement ( ele ) ) return;

const show = isUndefined ( force ) ? isHidden ( ele ) : force;
const hidden = isHidden ( ele );
const show = isUndefined ( force ) ? hidden : force;

if ( show ) {

Expand All @@ -2271,7 +2276,7 @@ fn.toggle = function ( this: Cash, force?: boolean ) {

}

} else {
} else if ( !hidden ) {

ele[displayProperty] = computeStyle ( ele, 'display' );

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cash-dom",
"repository": "github:fabiospampinato/cash",
"description": "An absurdly small jQuery alternative for modern browsers.",
"version": "8.1.4",
"version": "8.1.5",
"license": "MIT",
"browser": "./dist/cash.js",
"main": "./dist/cash.js",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ If you're migrating from jQuery be sure to read our [migration guide](https://gi

## Usage

Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.4/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@8.1.4/dist/cash.min.js) and use it like this:
Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.5/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@8.1.5/dist/cash.min.js) and use it like this:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.4/cash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.5/cash.min.js"></script>
<script>
$(function () {
$('html').addClass ( 'dom-loaded' );
Expand Down

0 comments on commit 61e3b8f

Please sign in to comment.