-
Notifications
You must be signed in to change notification settings - Fork 0
Adding pointer-events_touch-events recipe. #3
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
8f08aea
2ee9842
84e12a8
e795a5b
f9cee4b
a8d1655
b1d070f
8dd32ed
367bc7f
598ac29
f5bcd8d
88430ad
9c5ebcd
105bcc7
8692352
2160e80
1de5d22
65381ff
22d8fff
17d7db1
5931c02
a12c222
557b571
9083634
edc7f0c
447ac53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1540,6 +1540,64 @@ void function() { try { | |
|
||
} catch (ex) { /* do something maybe */ throw ex; } }(); | ||
|
||
/* | ||
RECIPE: Pointer events and touch events | ||
------------------------------------------------------------- | ||
Author: joevery | ||
Description: Find instances of listening for pointer and touch events. | ||
*/ | ||
|
||
void function() { | ||
window.CSSUsage.StyleWalker.recipesToRun.push( | ||
function pointer_events_touch_events(/*HTML DOM Element*/ element, results) { | ||
var nodeName = element.nodeName; | ||
// We want to catch all instances of listening for these events. | ||
|
||
var eventsToCheckFor = ["pointerup", "pointerdown", "pointermove", "pointercancel", "pointerout", "pointerleave", "pointerenter", "pointerover", | ||
"touchstart", "touchend", "touchmove", "touchcancel"]; | ||
|
||
var isExternalJSAndNotRecipeJS = (element.src !== undefined && element.src !== "" && !element.src.includes("Recipe.min.js")); | ||
var xhr; | ||
if (isExternalJSAndNotRecipeJS) | ||
{ | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", element.src, false); | ||
xhr.send(); | ||
} | ||
|
||
for (const event of eventsToCheckFor) { | ||
|
||
// Attribute specified on element, although this does not work at present. | ||
if (element.getAttribute(".on" + event)) { | ||
results[event] = results[event] || { count: 0, }; | ||
results[event].count++; | ||
} | ||
|
||
if (nodeName === "SCRIPT") { | ||
// if inline script. ensure that it's not our recipe script and look for string of interest | ||
|
||
if ((element.text !== undefined) && (element.text.indexOf(event) !== -1)) { | ||
var regex = new RegExp(event, 'g'); | ||
var instances = element.text.match(regex); | ||
|
||
results[event] = results[event] || { count: 0, }; | ||
results[event].count += instances.length; | ||
} | ||
// if external script, then we have to go and get it and ensure it is not our recipe script. | ||
else if (isExternalJSAndNotRecipeJS) | ||
{ | ||
if (xhr.status === 200 && xhr.responseText.indexOf(event) !== -1) { | ||
var regex = new RegExp(event, 'g'); | ||
|
||
var instances = xhr.responseText.match(regex); | ||
|
||
results[event] = results[event] || { count: 0, }; | ||
results[event].count += instances.length; | ||
} | ||
} | ||
} | ||
} | ||
return results; | ||
}); | ||
}(); | ||
// | ||
// This file is only here to create the TSV | ||
// necessary to collect the data from the crawler | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
RECIPE: Pointer events and touch events | ||
------------------------------------------------------------- | ||
Author: joevery | ||
Description: Find instances of listening for pointer and touch events. | ||
*/ | ||
|
||
void function() { | ||
window.CSSUsage.StyleWalker.recipesToRun.push( | ||
function pointer_events_touch_events(/*HTML DOM Element*/ element, results) { | ||
var nodeName = element.nodeName; | ||
// We want to catch all instances of listening for these events. | ||
|
||
var eventsToCheckFor = ["pointerup", "pointerdown", "pointermove", "pointercancel", "pointerout", "pointerleave", "pointerenter", "pointerover", | ||
"touchstart", "touchend", "touchmove", "touchcancel"]; | ||
|
||
var isExternalJSAndNotRecipeJS = (element.src !== undefined && element.src !== "" && !element.src.includes("Recipe.min.js")); | ||
var xhr; | ||
if (isExternalJSAndNotRecipeJS) | ||
{ | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", element.src, false); | ||
xhr.send(); | ||
} | ||
|
||
for (const event of eventsToCheckFor) { | ||
|
||
// Attribute specified on element, although this does not work at present. | ||
if (element.getAttribute(".on" + event)) { | ||
results[event] = results[event] || { count: 0, }; | ||
results[event].count++; | ||
} | ||
|
||
if (nodeName === "SCRIPT") { | ||
// if inline script. ensure that it's not our recipe script and look for string of interest | ||
if ((element.text !== undefined) && (element.text.indexOf(event) !== -1)) { | ||
var regex = new RegExp(event, 'g'); | ||
var instances = element.text.match(regex); | ||
|
||
results[event] = results[event] || { count: 0, }; | ||
results[event].count += instances.length; | ||
} | ||
// if external script, then we have to go and get it and ensure it is not our recipe script. | ||
else if (isExternalJSAndNotRecipeJS) | ||
{ | ||
if (xhr.status === 200 && xhr.responseText.indexOf(event) !== -1) { | ||
var regex = new RegExp(event, 'g'); | ||
var instances = xhr.responseText.match(regex); | ||
|
||
results[event] = results[event] || { count: 0, }; | ||
results[event].count += instances.length; | ||
} | ||
} | ||
} | ||
} | ||
return results; | ||
}); | ||
}(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>Pointer and touch events listening test</title> | ||
<link type="text/css" href="../test-page/style.css" media="all" rel="stylesheet" /> | ||
<script src="../../Recipe.min.js"></script> | ||
<style> | ||
.square { | ||
position: absolute; | ||
left: 20px; | ||
top: 10px; | ||
bottom: 0px; | ||
height: 200px; | ||
width: 200px; | ||
border: 5px blue solid; | ||
-webkit-filter: blur(10px); | ||
filter: blur(10px); | ||
} | ||
#square1 { | ||
background-color: yellow; | ||
left: 500px; | ||
} | ||
#square2 { | ||
background-color: blue; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<!--Cannot test onpointerup on tag, but can test everything else.--> | ||
<div class="wrapper"> | ||
<h1>Pointer and touch events listening test</h1> | ||
<div id="shapes"> | ||
<div class="square" id="square1"></div> | ||
<div class="square" id="square2" onload="func"></div> | ||
</div> | ||
</div> | ||
<script src="../test-page/pointerevents.js"></script> | ||
<script> | ||
var square1 = document.getElementById("square1"); | ||
square1.ontouchstart = func2; | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function func() | ||
{ | ||
var square2 = document.getElementById("square2"); | ||
|
||
square2.addEventListener("pointerup", func2); | ||
} | ||
|
||
function func2() | ||
{ | ||
alert("Point!!") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this making XHRs for every single element with a src? (An image from an img tag, for example, would be pulled down as part of this). I think you'll want to do a check for nodeName == "SCRIPT" here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or move this into the block of code where we know for sure we have an external script
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's a good spot, I did not think of that case at all.