Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce filesize and performance optimization #429

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/attributes/attr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require collection/each.ts
// @require ./remove_attr.ts
Expand Down Expand Up @@ -35,7 +36,7 @@ function attr ( this: Cash, attr?: string | Record<string, string>, value?: stri

if ( isNull ( value ) ) return this.removeAttr ( attr );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
3 changes: 2 additions & 1 deletion src/attributes/prop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require collection/each.ts
// @require ./helpers/variables.ts
Expand All @@ -20,7 +21,7 @@ fn.prop = function ( this: Cash, prop: string | Record<string, any>, value?: any

if ( arguments.length < 2 ) return this[0] && this[0][prop];

return this.each ( ( i, ele ) => { ele[prop] = value } );
return each ( this, ( i, ele ) => { ele[prop] = value } );

}

Expand Down
3 changes: 2 additions & 1 deletion src/attributes/remove_attr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/get_split_values.ts
// @require collection/each.ts

Expand All @@ -11,7 +12,7 @@ fn.removeAttr = function ( this: Cash, attr: string ) {

const attrs = getSplitValues ( attr );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
3 changes: 2 additions & 1 deletion src/attributes/remove_prop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require collection/each.ts
// @require ./helpers/variables.ts

Expand All @@ -9,6 +10,6 @@ interface Cash {

fn.removeProp = function ( this: Cash, prop: string ) {

return this.each ( ( i, ele ) => { delete ele[propMap[prop] || prop] } );
return each ( this, ( i, ele ) => { delete ele[propMap[prop] || prop] } );

};
2 changes: 1 addition & 1 deletion src/attributes/toggle_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn.toggleClass = function ( this: Cash, cls: string, force?: boolean ) {
const classes = getSplitValues ( cls );
const isForce = !isUndefined ( force );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
3 changes: 2 additions & 1 deletion src/css/css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require collection/each.ts
// @require ./helpers/compute_style.ts
Expand Down Expand Up @@ -30,7 +31,7 @@ function css ( this: Cash, prop: string | Record<string, number | string>, value

value = getSuffixedValue ( prop, value, isVariable );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
3 changes: 2 additions & 1 deletion src/data/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require collection/each.ts
// @require ./helpers/get_data.ts
Expand Down Expand Up @@ -40,7 +41,7 @@ function data ( this: Cash, name?: string | Record<string, any>, value?: any ) {

if ( isUndefined ( value ) ) return this;

return this.each ( ( i, ele ) => { setData ( ele, name, value ) } );
return each ( this, ( i, ele ) => { setData ( ele, name, value ) } );

}

Expand Down
4 changes: 1 addition & 3 deletions src/data/helpers/set_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

function setData ( ele: EleLoose, key: string, value: any ): void {

value = attempt ( JSON.stringify, value );

ele.dataset[camelCase ( key )] = value;
ele.dataset[camelCase ( key )] = attempt ( JSON.stringify, value );

}
2 changes: 1 addition & 1 deletion src/dimensions/normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ each ( ['Width', 'Height'], ( index: number, prop: 'Width' | 'Height' ) => {

const valueNumber = parseInt ( value, 10 );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
2 changes: 1 addition & 1 deletion src/effects/helpers/get_default_display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getDefaultDisplay ( tagName: string ): string {

const ele = createElement ( tagName );

doc.body.insertBefore ( ele, null );
doc.body.appendChild ( ele );

const display = computeStyle ( ele, 'display' );

Expand Down
3 changes: 2 additions & 1 deletion src/effects/toggle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require css/helpers/compute_style.ts
// @require ./helpers/get_default_display.ts
Expand All @@ -12,7 +13,7 @@ interface Cash {

fn.toggle = function ( this: Cash, force?: boolean ) {

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
4 changes: 2 additions & 2 deletions src/events/off.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn.off = function ( this: Cash, eventFullName?: string | Record<string, EventCal

if ( isUndefined ( eventFullName ) ) {

this.each ( ( i, ele ) => {
each ( this, ( i, ele ) => {

if ( !isElement ( ele ) && !isDocument ( ele ) && !isWindow ( ele ) ) return;

Expand Down Expand Up @@ -49,7 +49,7 @@ fn.off = function ( this: Cash, eventFullName?: string | Record<string, EventCal
const [nameOriginal, namespaces] = parseEventName ( eventFullName );
const name = getEventNameBubbling ( nameOriginal );

this.each ( ( i, ele ) => {
each ( this, ( i, ele ) => {

if ( !isElement ( ele ) && !isDocument ( ele ) && !isWindow ( ele ) ) return;

Expand Down
3 changes: 2 additions & 1 deletion src/events/on.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/get_split_values.ts
// @require core/guid.ts
// @require core/matches.ts
Expand Down Expand Up @@ -84,7 +85,7 @@ function on ( this: Cash, eventFullName: Record<string, EventCallback> | string,

if ( !name ) return;

this.each ( ( i, ele ) => {
each ( this, ( i, ele ) => {

if ( !isElement ( ele ) && !isDocument ( ele ) && !isWindow ( ele ) ) return;

Expand Down
3 changes: 2 additions & 1 deletion src/events/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require core/variables.ts
// @require collection/each.ts
Expand Down Expand Up @@ -33,7 +34,7 @@ fn.trigger = function ( this: Cash, event: Event | string, data?: any ) {

const isEventFocus = ( event.___ot in eventsFocus );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( isEventFocus && isFunction ( ele[event.___ot] ) ) {

Expand Down
2 changes: 1 addition & 1 deletion src/forms/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn.serialize = function ( this: Cash ) {

let query = '';

this.each ( ( i, ele ) => {
each ( this, ( i, ele ) => {

each ( ele.elements || [ele], ( i, ele: EleLoose ) => {

Expand Down
2 changes: 1 addition & 1 deletion src/forms/val.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function val ( this: Cash, value?: string | string[] ) {

if ( !arguments.length ) return this[0] && getValue ( this[0] );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

const isSelect = ele.multiple && ele.options;

Expand Down
3 changes: 2 additions & 1 deletion src/manipulation/empty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require collection/each.ts

interface Cash {
Expand All @@ -8,7 +9,7 @@ interface Cash {

fn.empty = function ( this: Cash ) {

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

while ( ele.firstChild ) {

Expand Down
2 changes: 1 addition & 1 deletion src/manipulation/helpers/eval_scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function evalScripts ( node: Node, doc: Document ): void {

});

doc.head.insertBefore ( script, null );
doc.head.appendChild ( script );
doc.head.removeChild ( script );

}
Expand Down
3 changes: 2 additions & 1 deletion src/manipulation/html.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require collection/each.ts
// @require manipulation/append.ts
Expand All @@ -20,7 +21,7 @@ function html ( this: Cash, html?: string ) {

const hasScript = /<script[\s>]/.test ( html );

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
3 changes: 2 additions & 1 deletion src/manipulation/text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require core/type_checking.ts
// @require collection/each.ts
// @require collection/get.ts
Expand All @@ -19,7 +20,7 @@ function text ( this: Cash, text?: string ) {

}

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

if ( !isElement ( ele ) ) return;

Expand Down
5 changes: 3 additions & 2 deletions src/manipulation/wrap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require collection/each.ts
// @require ./wrap_all.ts

Expand All @@ -9,11 +10,11 @@ interface Cash {

fn.wrap = function ( this: Cash, selector?: Selector ) {

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

const wrapper = cash ( selector )[0];

cash ( ele ).wrapAll ( !i ? wrapper : wrapper.cloneNode ( true ) );
cash ( ele ).wrapAll ( i ? wrapper.cloneNode ( true ) : wrapper );

});

Expand Down
3 changes: 2 additions & 1 deletion src/manipulation/wrap_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ fn.wrapAll = function ( this: Cash, selector?: Selector ) {

let structure = cash ( selector );
let wrapper: Element = structure[0];
let t: Element | undefined;

while ( wrapper.children.length ) wrapper = wrapper.firstElementChild;
while ( t = wrapper.firstElementChild ) wrapper = t;

this.first ().before ( structure );

Expand Down
3 changes: 2 additions & 1 deletion src/manipulation/wrap_inner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// @require core/cash.ts
// @require core/each.ts
// @require collection/first.ts
// @require manipulation/append_to.ts

Expand All @@ -9,7 +10,7 @@ interface Cash {

fn.wrapInner = function ( this: Cash, selector?: Selector ) {

return this.each ( ( i, ele ) => {
return each ( this, ( i, ele ) => {

const $ele = cash ( ele );
const contents = $ele.contents ();
Expand Down
6 changes: 4 additions & 2 deletions src/offset/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ fn.position = function ( this: Cash ) {

const doc = ele.ownerDocument;

let offsetParent = ele.offsetParent || doc.documentElement;
const root = doc.documentElement;

let offsetParent = ele.offsetParent || root;

while ( ( offsetParent === doc.body || offsetParent === doc.documentElement ) && computeStyle ( offsetParent, 'position' ) === 'static' ) {
while ( ( offsetParent === doc.body || offsetParent === root ) && computeStyle ( offsetParent, 'position' ) === 'static' ) {

offsetParent = offsetParent.parentNode;

Expand Down