Skip to content

Commit

Permalink
feat(html events): added isHTMLEventAttribute method
Browse files Browse the repository at this point in the history
  • Loading branch information
LCluber committed Jul 31, 2019
1 parent e407e2f commit beaf7ac
Show file tree
Hide file tree
Showing 12 changed files with 750 additions and 78 deletions.
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ git clone https://github.com/LCluber/Ch.js.git
Install global dependencies :

```bash
$ npm i -G typescript rollup uglify-js jest commitizen
$ npm i -G typescript rollup uglify-js jest commitizen semantic-release-cli
```

Install project dependencies :
Expand Down
3 changes: 2 additions & 1 deletion dist/ch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ declare function isFloat(number: any): boolean;
declare function isNumber(number: any): boolean;
declare function isString(string: any): boolean;
declare function isHtmlElement(htmlElement: any): boolean;
declare function isHtmlEventAttribute(htmlEventAttribute: any): boolean;
declare function isNode(node: any): boolean;
declare function isEven(number: any): boolean;
declare function isOdd(number: any): boolean;
declare function isOrigin(number: any): boolean;
declare function isPositive(number: any): boolean;
declare function isNegative(number: any): boolean;
export { isBoolean, isJson, isFunction, isObject, isArray, isAscii, isInteger, isFloat, isNumber, isString, isHtmlElement, isNode, isEven, isOdd, isOrigin, isPositive, isNegative };
export { isBoolean, isJson, isFunction, isObject, isArray, isAscii, isInteger, isFloat, isNumber, isString, isHtmlElement, isHtmlEventAttribute, isNode, isEven, isOdd, isOrigin, isPositive, isNegative };
80 changes: 80 additions & 0 deletions dist/ch.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,85 @@ var Ch = (function (exports) {
}
return false;
}
function isHtmlEventAttribute(htmlEventAttribute) {
switch (htmlEventAttribute) {
case "onafterprint":
case "onbeforeprint":
case "onbeforeunload":
case "onerror":
case "onhashchange":
case "onload":
case "onmessage":
case "onoffline":
case "ononline":
case "onpagehide":
case "onpageshow":
case "onpopstate":
case "onresize":
case "onstorage":
case "onunload":
case "onblur":
case "onchange":
case "oncontextmenu":
case "onfocus":
case "oninput":
case "oninvalid":
case "onreset":
case "onsearch":
case "onselect":
case "onsubmit":
case "onkeydown":
case "onkeypress":
case "onkeyup":
case "onclick":
case "ondblclick":
case "onmousedown":
case "onmousemove":
case "onmouseout":
case "onmouseover":
case "onmouseup":
case "onmousewheel":
case "onwheel":
case "ondrag":
case "ondragend":
case "ondragenter":
case "ondragleave":
case "ondragover":
case "ondragstart":
case "ondrop":
case "onscroll":
case "oncopy":
case "oncut":
case "onpaste":
case "onabort":
case "oncanplay":
case "oncanplaythrough":
case "oncuechange":
case "ondurationchange":
case "onemptied":
case "onended":
case "onerror":
case "onloadeddata":
case "onloadedmetadata":
case "onloadstart":
case "onpause":
case "onplay":
case "onplaying":
case "onprogress":
case "onratechange":
case "onseeked":
case "onseeking":
case "onstalled":
case "onsuspend":
case "ontimeupdate":
case "onvolumechange":
case "onwaiting":
case "ontoggle":
return true;
default:
return false;
}
}
function isNode(node) {
if (node) {
return typeof Node === "object"
Expand Down Expand Up @@ -105,6 +184,7 @@ var Ch = (function (exports) {
exports.isFloat = isFloat;
exports.isFunction = isFunction;
exports.isHtmlElement = isHtmlElement;
exports.isHtmlEventAttribute = isHtmlEventAttribute;
exports.isInteger = isInteger;
exports.isJson = isJson;
exports.isNegative = isNegative;
Expand Down
2 changes: 1 addition & 1 deletion dist/ch.iife.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 80 additions & 1 deletion dist/ch.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,85 @@ function isHtmlElement(htmlElement) {
}
return false;
}
function isHtmlEventAttribute(htmlEventAttribute) {
switch (htmlEventAttribute) {
case "onafterprint":
case "onbeforeprint":
case "onbeforeunload":
case "onerror":
case "onhashchange":
case "onload":
case "onmessage":
case "onoffline":
case "ononline":
case "onpagehide":
case "onpageshow":
case "onpopstate":
case "onresize":
case "onstorage":
case "onunload":
case "onblur":
case "onchange":
case "oncontextmenu":
case "onfocus":
case "oninput":
case "oninvalid":
case "onreset":
case "onsearch":
case "onselect":
case "onsubmit":
case "onkeydown":
case "onkeypress":
case "onkeyup":
case "onclick":
case "ondblclick":
case "onmousedown":
case "onmousemove":
case "onmouseout":
case "onmouseover":
case "onmouseup":
case "onmousewheel":
case "onwheel":
case "ondrag":
case "ondragend":
case "ondragenter":
case "ondragleave":
case "ondragover":
case "ondragstart":
case "ondrop":
case "onscroll":
case "oncopy":
case "oncut":
case "onpaste":
case "onabort":
case "oncanplay":
case "oncanplaythrough":
case "oncuechange":
case "ondurationchange":
case "onemptied":
case "onended":
case "onerror":
case "onloadeddata":
case "onloadedmetadata":
case "onloadstart":
case "onpause":
case "onplay":
case "onplaying":
case "onprogress":
case "onratechange":
case "onseeked":
case "onseeking":
case "onstalled":
case "onsuspend":
case "ontimeupdate":
case "onvolumechange":
case "onwaiting":
case "ontoggle":
return true;
default:
return false;
}
}
function isNode(node) {
if (node) {
return typeof Node === "object"
Expand All @@ -94,4 +173,4 @@ function isPositive(number) {
function isNegative(number) {
return number < 0 ? true : false;
}
export { isBoolean, isJson, isFunction, isObject, isArray, isAscii, isInteger, isFloat, isNumber, isString, isHtmlElement, isNode, isEven, isOdd, isOrigin, isPositive, isNegative };
export { isBoolean, isJson, isFunction, isObject, isArray, isAscii, isInteger, isFloat, isNumber, isString, isHtmlElement, isHtmlEventAttribute, isNode, isEven, isOdd, isOrigin, isPositive, isNegative };
81 changes: 81 additions & 0 deletions src/ts/ch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,86 @@ function isHtmlElement(htmlElement: any): boolean {
return false;
}

function isHtmlEventAttribute(htmlEventAttribute: any): boolean {
switch (htmlEventAttribute) {
case "onafterprint": // run after the document is printed
case "onbeforeprint": // run before the document is printed
case "onbeforeunload": // run when the document is about to be unloaded
case "onerror": // run when an error occurs
case "onhashchange": // run when there has been changes to the anchor part of the a URL
case "onload": // Fires after page is finished loading
case "onmessage": // run when the message is triggered
case "onoffline": // run when the browser starts to work offline
case "ononline": // run when the browser starts to work case "online
case "onpagehide": // run when a user navigates away from a page
case "onpageshow": // run when a user navigates to a page
case "onpopstate": // run when the window's history changes
case "onresize": // Fires whene browser window is resized
case "onstorage": // run when a Web Storage area is updated
case "onunload": // Fires once a page has unloaded (or the browser window has been closed)
case "onblur": // Fires the moment that the element loses focus
case "onchange": // Fires the moment when the value of the element is changed
case "oncontextmenu": // Script to be run when a context menu is triggered
case "onfocus": // Fires the moment when the element gets focus
case "oninput": // Script to be run when an element gets user input
case "oninvalid": // Script to be run when an element is invalid
case "onreset": // Fires when the Reset button in a form is clicked
case "onsearch": // Fires when the user writes something in a search field (for <input="search">)
case "onselect": // Fires after some text has been selected in an element
case "onsubmit": // Fires when a form is submitted
case "onkeydown": // script Fires when a user is pressing a key
case "onkeypress": // script Fires when a user presses a key
case "onkeyup": // script Fires when a user releases a key
case "onclick": // Fires on a mouse click on the element
case "ondblclick": // Fires on a mouse double-click on the element
case "onmousedown": // Fires when a mouse button is pressed down on an element
case "onmousemove": // Fires when the mouse pointer is moving while it is over an element
case "onmouseout": // Fires when the mouse pointer moves out of an element
case "onmouseover": // Fires when the mouse pointer moves over an element
case "onmouseup": // Fires when a mouse button is released over an element
case "onmousewheel": // Deprecated. Use the onwheel attribute instead
case "onwheel": // Fires when the mouse wheel rolls up or down over an element
case "ondrag": // Script to be run when an element is dragged
case "ondragend": // Script to be run at the end of a drag operation
case "ondragenter": // Script to be run when an element has been dragged to a valid drop target
case "ondragleave": // Script to be run when an element leaves a valid drop target
case "ondragover": // Script to be run when an element is being dragged over a valid drop target
case "ondragstart": // Script to be run at the start of a drag operation
case "ondrop": // Script to be run when dragged element is being dropped
case "onscroll": // Script to be run when an element's scrollbar is being scrolled
case "oncopy": // Fires when the user copies the content of an element
case "oncut": // Fires when the user cuts the content of an element
case "onpaste": // Fires when the user pastes some content in an element
case "onabort": // run on abort
case "oncanplay": // run when a file is ready to start playing (when it has buffered enough to begin)
case "oncanplaythrough": // run when a file can be played all the way to the end without pausing for buffering
case "oncuechange": // run when the cue changes in a <track> element
case "ondurationchange": // run when the length of the media changes
case "onemptied": // run when something bad happens and the file is suddenly unavailable (like unexpectedly disconnects)
case "onended": // run when the media has reach the end (a useful event for messages like "thanks for listening")
case "onerror": // run when an error occurs when the file is being loaded
case "onloadeddata": // run when media data is loaded
case "onloadedmetadata": // run when meta data (like dimensions and duration) are loaded
case "onloadstart": // run just as the file begins to load before anything is actually loaded
case "onpause": // run when the media is paused either by the user or programmatically
case "onplay": // run when the media is ready to start playing
case "onplaying": // run when the media actually has started playing
case "onprogress": // run when the browser is in the process of getting the media data
case "onratechange": // run each time the playback rate changes (like when a user switches to a slow motion or fast "forward mode)
case "onseeked": // run when the seeking attribute is set to false indicating that seeking has ended
case "onseeking": // run when the seeking attribute is set to true indicating that seeking is active
case "onstalled": // run when the browser is unable to fetch the media data for whatever reason
case "onsuspend": // run when fetching the media data is stopped before it is completely loaded for whatever reason
case "ontimeupdate": // run when the playing position has changed (like when the user fast forwards to a different point in the media)
case "onvolumechange": // run each time the volume is changed which (includes setting the volume to "mute")
case "onwaiting": // run when the media has paused but is expected to resume (like when the media pauses to buffer more data)
case "ontoggle": // Fires when the user opens or closes the <details> element"
return true;
default:
return false;
}
}

function isNode(node: any): boolean {
if (node) {
return typeof Node === "object"
Expand Down Expand Up @@ -113,6 +193,7 @@ export {
isNumber,
isString,
isHtmlElement,
isHtmlEventAttribute,
isNode,
isEven,
isOdd,
Expand Down
27 changes: 15 additions & 12 deletions tests/coverage/clover.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1563710561979" clover="3.2.0">
<project timestamp="1563710561979" name="All files">
<metrics statements="31" coveredstatements="31" conditionals="53" coveredconditionals="51" methods="17" coveredmethods="17" elements="101" coveredelements="99" complexity="0" loc="31" ncloc="31" packages="1" files="1" classes="1"/>
<coverage generated="1564575576701" clover="3.2.0">
<project timestamp="1564575576701" name="All files">
<metrics statements="34" coveredstatements="34" conditionals="126" coveredconditionals="96" methods="18" coveredmethods="18" elements="178" coveredelements="148" complexity="0" loc="34" ncloc="34" packages="1" files="1" classes="1"/>
<file name="ch.js" path="/Users/lcluber/Projects/github/Ch.js/dist/ch.js">
<metrics statements="31" coveredstatements="31" conditionals="53" coveredconditionals="51" methods="17" coveredmethods="17"/>
<metrics statements="34" coveredstatements="34" conditionals="126" coveredconditionals="96" methods="18" coveredmethods="18"/>
<line num="14" count="19" type="stmt"/>
<line num="17" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="18" count="16" type="stmt"/>
Expand All @@ -27,14 +27,17 @@
<line num="60" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="61" count="16" type="cond" truecount="1" falsecount="1"/>
<line num="69" count="3" type="stmt"/>
<line num="72" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="73" count="16" type="cond" truecount="1" falsecount="1"/>
<line num="80" count="3" type="stmt"/>
<line num="83" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="86" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="89" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="92" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="95" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="72" count="21" type="cond" truecount="45" falsecount="28"/>
<line num="145" count="1" type="stmt"/>
<line num="147" count="20" type="stmt"/>
<line num="151" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="152" count="16" type="cond" truecount="1" falsecount="1"/>
<line num="159" count="3" type="stmt"/>
<line num="162" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="165" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="168" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="171" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="174" count="19" type="cond" truecount="2" falsecount="0"/>
</file>
</project>
</coverage>
Loading

0 comments on commit beaf7ac

Please sign in to comment.