Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Feature/caret range from point #47

Open
wants to merge 4 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
76 changes: 76 additions & 0 deletions Recipe.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,82 @@ void function() { try {

} catch (ex) { /* do something maybe */ throw ex; } }();

/*
RECIPE: caretRangeFromPoint
-------------------------------------------------------------
Author: Grisha Lyukshin
Description: Find use of caretRangeFromPoint in script.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push( function caretRangeFromPoint(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
var script = ".caretRangeFromPoint"
if (nodeName == "SCRIPT")
{
results[nodeName] = results[nodeName] || { count: 0, };
// if inline script. ensure that it's not our recipe script and look for string of interest
if (element.text !== undefined && element.text.indexOf(script) != -1)
{
results[nodeName].count++;
}
else if (element.src !== undefined && element.src != "")
{
var xhr = new XMLHttpRequest();
xhr.open("GET", element.src, true);
//xhr.setRequestHeader("Content-type", "text/javascript");
xhr.send();
xhr.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED ) {
if (xhr.status === 200 && xhr.responseText.indexOf(script) != -1)
{
results[nodeName].count++;
}
}
}
}
}
return results;
});
}();
/*
RECIPE: elementFromPoint
-------------------------------------------------------------
Author: Grisha Lyukshin
Description: Find use of elementFromPoint in script.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push( function elementFromPointUsage(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
var script = ".elementFromPoint"
if (nodeName == "SCRIPT")
{
results[nodeName] = results[nodeName] || { count: 0, };
// if inline script. ensure that it's not our recipe script and look for string of interest
if (element.text !== undefined && element.text.indexOf(script) != -1)
{
results[nodeName].count++;
}
else if (element.src !== undefined && element.src != "")
{
var xhr = new XMLHttpRequest();
xhr.open("GET", element.src, true);
//xhr.setRequestHeader("Content-type", "text/javascript");
xhr.send();
xhr.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED ) {
if (xhr.status === 200 && xhr.responseText.indexOf(script) != -1)
{
results[nodeName].count++;
}
}
}
}
}
return results;
});
}();
/*
RECIPE: z-index on static flex items
-------------------------------------------------------------
Expand Down
76 changes: 76 additions & 0 deletions cssUsage.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,82 @@ void function() { try {

} catch (ex) { /* do something maybe */ throw ex; } }();

/*
RECIPE: caretRangeFromPoint
-------------------------------------------------------------
Author: Grisha Lyukshin
Description: Find use of caretRangeFromPoint in script.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push( function caretRangeFromPoint(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
var script = ".caretRangeFromPoint"
if (nodeName == "SCRIPT")
{
results[nodeName] = results[nodeName] || { count: 0, };
// if inline script. ensure that it's not our recipe script and look for string of interest
if (element.text !== undefined && element.text.indexOf(script) != -1)
{
results[nodeName].count++;
}
else if (element.src !== undefined && element.src != "")
{
var xhr = new XMLHttpRequest();
xhr.open("GET", element.src, true);
//xhr.setRequestHeader("Content-type", "text/javascript");
xhr.send();
xhr.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED ) {
if (xhr.status === 200 && xhr.responseText.indexOf(script) != -1)
{
results[nodeName].count++;
}
}
}
}
}
return results;
});
}();
/*
RECIPE: elementFromPoint
-------------------------------------------------------------
Author: Grisha Lyukshin
Description: Find use of elementFromPoint in script.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push( function elementFromPointUsage(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
var script = ".elementFromPoint"
if (nodeName == "SCRIPT")
{
results[nodeName] = results[nodeName] || { count: 0, };
// if inline script. ensure that it's not our recipe script and look for string of interest
if (element.text !== undefined && element.text.indexOf(script) != -1)
{
results[nodeName].count++;
}
else if (element.src !== undefined && element.src != "")
{
var xhr = new XMLHttpRequest();
xhr.open("GET", element.src, true);
//xhr.setRequestHeader("Content-type", "text/javascript");
xhr.send();
xhr.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED ) {
if (xhr.status === 200 && xhr.responseText.indexOf(script) != -1)
{
results[nodeName].count++;
}
}
}
}
}
return results;
});
}();
/*
RECIPE: z-index on static flex items
-------------------------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions src/recipes/caretRangeFromPoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
RECIPE: caretRangeFromPoint
-------------------------------------------------------------
Author: Grisha Lyukshin
Description: Find use of caretRangeFromPoint in script.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push( function caretRangeFromPoint(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
var script = ".caretRangeFromPoint"
if (nodeName == "SCRIPT")
{
results[nodeName] = results[nodeName] || { count: 0, };
// if inline script. ensure that it's not our recipe script and look for string of interest
if (element.text !== undefined && element.text.indexOf(script) != -1)
{
results[nodeName].count++;
}
else if (element.src !== undefined && element.src != "")
{
var xhr = new XMLHttpRequest();
xhr.open("GET", element.src, true);
//xhr.setRequestHeader("Content-type", "text/javascript");
xhr.send();
xhr.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED ) {
if (xhr.status === 200 && xhr.responseText.indexOf(script) != -1)
{
results[nodeName].count++;
}
}
}
}
}
return results;
});
}();
38 changes: 38 additions & 0 deletions src/recipes/elementFromPoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
RECIPE: elementFromPoint
-------------------------------------------------------------
Author: Grisha Lyukshin
Description: Find use of elementFromPoint in script.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push( function elementFromPointUsage(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
var script = ".elementFromPoint"
if (nodeName == "SCRIPT")
{
results[nodeName] = results[nodeName] || { count: 0, };
// if inline script. ensure that it's not our recipe script and look for string of interest
if (element.text !== undefined && element.text.indexOf(script) != -1)
{
results[nodeName].count++;
}
else if (element.src !== undefined && element.src != "")
{
var xhr = new XMLHttpRequest();
xhr.open("GET", element.src, true);
//xhr.setRequestHeader("Content-type", "text/javascript");
xhr.send();
xhr.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED ) {
if (xhr.status === 200 && xhr.responseText.indexOf(script) != -1)
{
results[nodeName].count++;
}
}
}
}
}
return results;
});
}();
40 changes: 40 additions & 0 deletions tests/recipes/caretRangeFromPoint.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>elementFromPoint example</title>
<link type="text/css" href="../test-page/style.css" media="all" rel="stylesheet" />
<script src="../../recipe.min.js"></script>
<script>
function insertBreakAtPoint(e) {

var range;
var textNode;
var offset;
if (document.caretRangeFromPoint) {
range = document.caretRangeFromPoint(e.clientX, e.clientY);
textNode = range.startContainer;
offset = range.startOffset;
}

// only split TEXT_NODEs
if (textNode && textNode.nodeType == 3) {
var replacement = textNode.splitText(offset);
var br = document.createElement('br');
textNode.parentNode.insertBefore(br, replacement);
}
}

var paragraphs = document.getElementsByTagName("p");
for (i=0 ; i < paragraphs.length; i++) {
paragraphs[i].addEventListener("click", insertBreakAtPoint, false);
}
</script>
</head>

<body>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</body>
</html>
20 changes: 20 additions & 0 deletions tests/recipes/elementFromPoint.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>elementFromPoint example</title>
<link type="text/css" href="../test-page/style.css" media="all" rel="stylesheet" />
<script src="../../recipe.min.js"></script>
<script>
function changeColor(newColor) {
elem = document.elementFromPoint(2, 2);
elem.style.color = newColor;
}
</script>
</head>

<body>
<p id="para1">Some text here</p>
<button onclick="changeColor('blue');">blue</button>
<button onclick="changeColor('red');">red</button>
</body>
</html>