Skip to content

Commit

Permalink
Bumped version to 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed May 8, 2019
1 parent 0726f62 commit dca2db7
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 221 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Version 4.0.0
- Removed `$.fn.removeData`
- Removed `$.hasData`
- `$.fn.data`: removed caching mechanism
- `$.fn.data`: added a missing TypeScript method overload

### Version 3.2.0
- Readme: updated sizes
- $.fn.off: added support for removing delegated handlers
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,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/3.2.0/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@3.2.0/dist/cash.min.js) and use it like this:
Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/4.0.0/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@4.0.0/dist/cash.min.js) and use it like this:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/3.2.0/cash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/4.0.0/cash.min.js"></script>
<script>
$(function () {
$('html').addClass ( 'dom-loaded' );
Expand Down
7 changes: 1 addition & 6 deletions dist/cash.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,12 @@ interface Cash {
css(prop: string, value: any): this;
css(props: plainObject): this;
}
interface CashStatic {
hasData(ele: HTMLElement): boolean;
}
interface Cash {
data(): plainObject | undefined;
data(name: string): any;
data(name: string, value: any): this;
data(datas: plainObject): this;
}
interface Cash {
removeData(key: string): this;
}
interface Cash {
innerWidth(): number;
innerHeight(): number;
Expand Down
62 changes: 19 additions & 43 deletions dist/cash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,61 +344,41 @@ function css(prop, value) {
;
Cash.prototype.css = css;
// @optional ./css.ts
const dataNamespace = '__cashData', dataAttributeRe = /^data-(.*)/;
// @require core/cash.ts
// @require ./helpers/variables.ts
function hasData(ele) {
return dataNamespace in ele;
}
cash.hasData = hasData;
// @require ./variables.ts
function getDataCache(ele) {
return ele[dataNamespace] = (ele[dataNamespace] || {});
}
// @require attributes/attr.ts
// @require ./get_data_cache.ts
// @require core/camel_case.ts
function getData(ele, key) {
const cache = getDataCache(ele);
if (key) {
if (!(key in cache)) {
let value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : cash(ele).attr(`data-${key}`);
if (value !== undefined) {
try {
value = JSON.parse(value);
}
catch (e) { }
cache[key] = value;
}
}
return cache[key];
const value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : ele.getAttribute(`data-${key}`);
try {
return JSON.parse(value);
}
return cache;
catch (_a) { }
return value;
}
// @require ./variables.ts
// @require ./get_data_cache.ts
function removeData(ele, key) {
if (key === undefined) {
delete ele[dataNamespace];
// @require core/camel_case.ts
function setData(ele, key, value) {
try {
value = JSON.stringify(value);
}
catch (_a) { }
if (ele.dataset) {
ele.dataset[camelCase(key)] = value;
}
else {
delete getDataCache(ele)[key];
ele.setAttribute(`data-${key}`, value);
}
}
// @require ./get_data_cache.ts
function setData(ele, key, value) {
getDataCache(ele)[key] = value;
}
const dataAttributeRe = /^data-(.+)/;
function data(name, value) {
if (!name) {
if (!this[0])
return;
const datas = {};
each(this[0].attributes, (i, attr) => {
const match = attr.name.match(dataAttributeRe);
if (!match)
return;
this.data(match[1]);
datas[match[1]] = this.data(match[1]);
});
return getData(this[0]);
return datas;
}
if (isString(name)) {
if (value === undefined)
Expand All @@ -411,11 +391,7 @@ function data(name, value) {
return this;
}
Cash.prototype.data = data;
Cash.prototype.removeData = function (key) {
return this.each((i, ele) => removeData(ele, key));
};
// @optional ./data.ts
// @optional ./remove_data.ts
// @require css/helpers/compute_style_int.ts
function getExtraSpace(ele, xAxis) {
return computeStyleInt(ele, `border${xAxis ? 'Left' : 'Top'}Width`) + computeStyleInt(ele, `padding${xAxis ? 'Left' : 'Top'}`) + computeStyleInt(ele, `padding${xAxis ? 'Right' : 'Bottom'}`) + computeStyleInt(ele, `border${xAxis ? 'Right' : 'Bottom'}Width`);
Expand Down
75 changes: 20 additions & 55 deletions dist/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,72 +445,45 @@ function css(prop, value) {

;
Cash.prototype.css = css; // @optional ./css.ts

var dataNamespace = '__cashData',
dataAttributeRe = /^data-(.*)/; // @require core/cash.ts
// @require ./helpers/variables.ts

function hasData(ele) {
return dataNamespace in ele;
}

cash.hasData = hasData; // @require ./variables.ts

function getDataCache(ele) {
return ele[dataNamespace] = ele[dataNamespace] || {};
} // @require attributes/attr.ts
// @require ./get_data_cache.ts

// @require core/camel_case.ts

function getData(ele, key) {
var cache = getDataCache(ele);
var value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : ele.getAttribute("data-" + key);

if (key) {
if (!(key in cache)) {
var value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : cash(ele).attr("data-" + key);
try {
return JSON.parse(value);
} catch (_a) {}

if (value !== undefined) {
try {
value = JSON.parse(value);
} catch (e) {}

cache[key] = value;
}
}
return value;
} // @require core/camel_case.ts

return cache[key];
}

return cache;
} // @require ./variables.ts
// @require ./get_data_cache.ts

function setData(ele, key, value) {
try {
value = JSON.stringify(value);
} catch (_a) {}

function removeData(ele, key) {
if (key === undefined) {
delete ele[dataNamespace];
if (ele.dataset) {
ele.dataset[camelCase(key)] = value;
} else {
delete getDataCache(ele)[key];
ele.setAttribute("data-" + key, value);
}
} // @require ./get_data_cache.ts


function setData(ele, key, value) {
getDataCache(ele)[key] = value;
}

var dataAttributeRe = /^data-(.+)/;

function data(name, value) {
var _this = this;

if (!name) {
if (!this[0]) return;
var datas_1 = {};
each(this[0].attributes, function (i, attr) {
var match = attr.name.match(dataAttributeRe);
if (!match) return;

_this.data(match[1]);
datas_1[match[1]] = _this.data(match[1]);
});
return getData(this[0]);
return datas_1;
}

if (isString(name)) {
Expand All @@ -527,17 +500,9 @@ function data(name, value) {
return this;
}

Cash.prototype.data = data;

Cash.prototype.removeData = function (key) {
return this.each(function (i, ele) {
return removeData(ele, key);
});
}; // @optional ./data.ts
// @optional ./remove_data.ts
Cash.prototype.data = data; // @optional ./data.ts
// @require css/helpers/compute_style_int.ts


function getExtraSpace(ele, xAxis) {
return computeStyleInt(ele, "border" + (xAxis ? 'Left' : 'Top') + "Width") + computeStyleInt(ele, "padding" + (xAxis ? 'Left' : 'Top')) + computeStyleInt(ele, "padding" + (xAxis ? 'Right' : 'Bottom')) + computeStyleInt(ele, "border" + (xAxis ? 'Right' : 'Bottom') + "Width");
}
Expand Down
Loading

0 comments on commit dca2db7

Please sign in to comment.