Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-event-object

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-event-object - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

tests/config.json

6

dist/dom-event-object.d.ts

@@ -10,7 +10,9 @@ export declare type EventListenerCallback = (event: Event) => any;

constructor(target?: EventTarget);
readonly childEventObjects: EventObject[];
readonly parentEventObject: EventObject;
appendChild(target: EventObject): EventObject;
removeChild(target: EventObject): EventObject;
addEventListener(type: string, callback: EventListenerCallback, options?: (EventListenerOptions | boolean)): void;
dispatchEvent(event: Event): boolean;
removeEventListener(type: string, callback: EventListenerCallback, options?: (EventListenerOptions | boolean)): void;
appendChild(target: (EventObject | any)): void;
removeChild(target: (EventObject | any)): void;
}

@@ -5,4 +5,38 @@ "use strict";

function EventObject(target) {
this._eventTarget = target || document.createDocumentFragment();
this._eventTarget = target || document.createElement('div') || document.createDocumentFragment();
Object.defineProperty(this._eventTarget, '_eventObject', {
value: this
});
}
Object.defineProperty(EventObject.prototype, "childEventObjects", {
get: function () {
var target = this._eventTarget;
return Array.prototype.concat.apply([], target.childNodes).map(function (child) {
return child['_eventObject'];
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(EventObject.prototype, "parentEventObject", {
get: function () {
var target = this._eventTarget;
if (('parentElement' in target) && (target.parentNode !== null) && ('_eventObject' in target.parentNode)) {
return target.parentNode['_eventObject'];
}
else {
return null;
}
},
enumerable: true,
configurable: true
});
EventObject.prototype.appendChild = function (target) {
this._eventTarget.appendChild(target._eventTarget);
return target;
};
EventObject.prototype.removeChild = function (target) {
this._eventTarget.removeChild(target._eventTarget);
return target;
};
EventObject.prototype.addEventListener = function (type, callback, options) {

@@ -18,31 +52,5 @@ this._eventTarget.addEventListener(type, callback, options);

};
EventObject.prototype.appendChild = function (target) {
if ('appendChild' in this._eventTarget) {
if (target instanceof EventObject) {
this._eventTarget.appendChild(target._eventTarget);
}
else {
this._eventTarget.appendChild(target);
}
}
else {
throw new Error('Target doen\'t support appendChild');
}
};
EventObject.prototype.removeChild = function (target) {
if ('removeChild' in this._eventTarget) {
if (target instanceof EventObject) {
this._eventTarget.removeChild(target._eventTarget);
}
else {
this._eventTarget.removeChild(target);
}
}
else {
throw new Error('Target doen\'t support removeChild');
}
};
return EventObject;
}());
exports.EventObject = EventObject;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9tLWV2ZW50LW9iamVjdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9kb20tZXZlbnQtb2JqZWN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBUUE7SUFHRSxxQkFBWSxNQUFvQjtRQUM5QixJQUFJLENBQUMsWUFBWSxHQUFHLE1BQU0sSUFBSSxRQUFRLENBQUMsc0JBQXNCLEVBQUUsQ0FBQztJQUNsRSxDQUFDO0lBRUQsc0NBQWdCLEdBQWhCLFVBQWlCLElBQVksRUFBRSxRQUErQixFQUFFLE9BQTBDO1FBQ3hHLElBQUksQ0FBQyxZQUFZLENBQUMsZ0JBQWdCLENBQUMsSUFBSSxFQUFFLFFBQVEsRUFBTyxPQUFPLENBQUMsQ0FBQztJQUNuRSxDQUFDO0lBRUQsbUNBQWEsR0FBYixVQUFjLEtBQVk7UUFDeEIsTUFBTSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsYUFBYSxDQUFDLEtBQUssQ0FBQyxDQUFDO0lBQ2hELENBQUM7SUFBQSxDQUFDO0lBRUYseUNBQW1CLEdBQW5CLFVBQW9CLElBQVksRUFBRSxRQUErQixFQUFFLE9BQTBDO1FBQzNHLElBQUksQ0FBQyxZQUFZLENBQUMsbUJBQW1CLENBQUMsSUFBSSxFQUFFLFFBQVEsRUFBTyxPQUFPLENBQUMsQ0FBQztJQUN0RS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dmVudE9iamVjdCB7XHJcbiAgICAodGhpcy5fZXZlbnRUYXJnZXQgYXMgTm9kZSkucmVtb3ZlQ2hpbGQodGFyZ2V0Ll9ldmVudFRhcmdldCBhcyBOb2RlKTtcclxuICAgIHJldHVybiB0YXJnZXQ7XHJcbiAgfVxyXG5cclxuICBhZGRFdmVudExpc3RlbmVyKHR5cGU6IHN0cmluZywgY2FsbGJhY2s6IEV2ZW50TGlzdGVuZXJDYWxsYmFjaywgb3B0aW9ucz86IChFdmVudExpc3RlbmVyT3B0aW9ucyB8IGJvb2xlYW4pKTogdm9pZCB7XHJcbiAgICB0aGlzLl9ldmVudFRhcmdldC5hZGRFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrLCBvcHRpb25zIGFzIGFueSk7XHJcbiAgfVxyXG5cclxuICBkaXNwYXRjaEV2ZW50KGV2ZW50OiBFdmVudCk6IGJvb2xlYW4ge1xyXG4gICAgcmV0dXJuIHRoaXMuX2V2ZW50VGFyZ2V0LmRpc3BhdGNoRXZlbnQoZXZlbnQpO1xyXG4gIH07XHJcblxyXG4gIHJlbW92ZUV2ZW50TGlzdGVuZXIodHlwZTogc3RyaW5nLCBjYWxsYmFjazogRXZlbnRMaXN0ZW5lckNhbGxiYWNrLCBvcHRpb25zPzogKEV2ZW50TGlzdGVuZXJPcHRpb25zIHwgYm9vbGVhbikpOiB2b2lkIHtcclxuICAgIHRoaXMuX2V2ZW50VGFyZ2V0LnJlbW92ZUV2ZW50TGlzdGVuZXIodHlwZSwgY2FsbGJhY2ssIG9wdGlvbnMgYXMgYW55KTtcclxuICB9XHJcbiAgXHJcbn1cclxuIl19
{
"name": "dom-event-object",
"version": "1.0.1",
"version": "1.0.2",
"description": "Allow any class to have EventTarget methods (addEventListener, removeEventLister and dispatchEvent)",

@@ -8,4 +8,7 @@ "main": "dist/dom-event-object.js",

"scripts": {
"start": "tsc && npm run min",
"min": "uglifyjs ./dist/dom-event-object.js --stats -m -o ./dist/dom-event-object.min.js"
"start": "npm run build && npm run minimify",
"build": "tsc",
"minimify": "uglifyjs ./dist/dom-event-object.js --stats -m -o ./dist/dom-event-object.min.js",
"test": "mocha ./tests/test.js",
"serve": "http-server ./"
},

@@ -20,5 +23,8 @@ "repository": {

"typescript": "latest",
"uglify-js": "^3.0.1"
"uglify-js": "latest",
"http-server": "latest",
"mocha": "latest",
"selenium-webdriver": "latest"
},
"dependencies": {}
}

@@ -12,6 +12,14 @@ ### Add EventTarget methods to any class by extending them with EventObject

export declare class EventObject implements EventTarget {
protected _eventTarget: EventTarget; // the true element which will receive events binding
constructor(target?: EventTarget); // if required a specific target can be selected
protected _eventTarget: EventTarget; // the original element which will receive events binding
constructor(target?: EventTarget); // if required a specific target can be selected
// because Events can bubbles, you can append or remove children like in a Node tree
readonly childEventObjects: EventObject[];
readonly parentEventObject: EventObject;
appendChild(target: EventObject): EventObject;
removeChild(target: EventObject): EventObject;
// standard EventTarget methods

@@ -22,5 +30,2 @@ addEventListener(type: string, callback: EventListenerCallback, options?: (EventListenerOptions | boolean)): void;

// because Events can bubbles, you can had or remove children
appendChild(target: (EventObject | any)): void;
removeChild(target: (EventObject | any)): void;
```

@@ -13,7 +13,36 @@ export type EventListenerCallback = (event: Event) => any;

constructor(target?: EventTarget) {
this._eventTarget = target || document.createDocumentFragment();
this._eventTarget = target || document.createElement('div') || document.createDocumentFragment();
Object.defineProperty(this._eventTarget, '_eventObject', {
value: this
});
}
get childEventObjects(): EventObject[] {
const target = this._eventTarget as Node;
return Array.prototype.concat.apply([], target.childNodes).map((child: Node) => {
return child['_eventObject'];
});
}
get parentEventObject(): EventObject {
const target = this._eventTarget as Node;
if(('parentElement' in target) && (target.parentNode !== null) && ('_eventObject' in target.parentNode)) {
return target.parentNode['_eventObject'];
} else {
return null;
}
}
appendChild(target: EventObject): EventObject {
(this._eventTarget as Node).appendChild(target._eventTarget as Node);
return target;
}
removeChild(target: EventObject): EventObject {
(this._eventTarget as Node).removeChild(target._eventTarget as Node);
return target;
}
addEventListener(type: string, callback: EventListenerCallback, options?: (EventListenerOptions | boolean)): void {
this._eventTarget.addEventListener(type, callback, <any>options);
this._eventTarget.addEventListener(type, callback, options as any);
}

@@ -26,29 +55,5 @@

removeEventListener(type: string, callback: EventListenerCallback, options?: (EventListenerOptions | boolean)): void {
this._eventTarget.removeEventListener(type, callback, <any>options);
this._eventTarget.removeEventListener(type, callback, options as any);
}
appendChild(target: (EventObject | any)) {
if('appendChild' in this._eventTarget) {
if(target instanceof EventObject) {
(<Element>this._eventTarget).appendChild((<Element>target._eventTarget));
} else {
(<Element>this._eventTarget).appendChild(target);
}
} else {
throw new Error('Target doen\'t support appendChild');
}
}
removeChild(target: (EventObject | any)) {
if('removeChild' in this._eventTarget) {
if(target instanceof EventObject) {
(<Element>this._eventTarget).removeChild((<Element>target._eventTarget));
} else {
(<Element>this._eventTarget).removeChild(target);
}
} else {
throw new Error('Target doen\'t support removeChild');
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc