1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
var WebDeveloper = WebDeveloper || {};
WebDeveloper.ElementAncestors = WebDeveloper.ElementAncestors || {};
WebDeveloper.ElementAncestors.element = null;
// Returns the ancestor information for an element
WebDeveloper.ElementAncestors.getAncestorInformation = function(element, contentDocument)
{
var ancestorInformation = contentDocument.createElement("ul");
var parentElement = null;
ancestorInformation.setAttribute("class", "breadcrumb");
WebDeveloper.Common.insertAsFirstChild(ancestorInformation, WebDeveloper.ElementAncestors.getElementDescription(element, contentDocument, true));
// While there is a parent element
while((parentElement = element.parentNode) !== null)
{
element = parentElement;
WebDeveloper.Common.insertAsFirstChild(ancestorInformation, WebDeveloper.ElementAncestors.getElementDescription(element, contentDocument, false));
}
return ancestorInformation;
};
// Returns the description for an element
WebDeveloper.ElementAncestors.getElementDescription = function(element, contentDocument, active)
{
var description = null;
// If the element and tag name are set
if(element && element.tagName)
{
var classList = element.className.split(" ");
description = contentDocument.createElement("li");
// If this is the active element
if(active)
{
description.setAttribute("class", "active");
}
description.setAttribute("data-web-developer-element-tag", element.tagName.toLowerCase());
// If the element has an id attribute
if(element.hasAttribute("id"))
{
description.setAttribute("data-web-developer-element-id", "#" + element.getAttribute("id"));
}
// If the element has an class attribute
if(element.hasAttribute("class"))
{
var className = null;
var classes = "";
// Loop through the classes
for(var i = 0, l = classList.length; i < l; i++)
{
className = classList[i].trim();
// If the class name is set
if(className)
{
classes += "." + className;
}
}
description.setAttribute("data-web-developer-element-classes", classes);
}
// If this is not the active element
if(!active)
{
var childElement = contentDocument.createElement("a");
childElement.setAttribute("href", "#");
childElement.setAttribute("class", "web-developer-ancestor");
description.appendChild(childElement);
childElement = contentDocument.createElement("span");
childElement.appendChild(contentDocument.createTextNode(">"));
childElement.setAttribute("class", "divider");
description.appendChild(childElement);
}
}
return description;
};
// Handles the mouse over event
WebDeveloper.ElementAncestors.mouseOver = function(event)
{
var eventTarget = event.target;
// If the event target is set
if(eventTarget)
{
var ownerDocument = eventTarget.ownerDocument;
// If the owner document is set
if(ownerDocument)
{
// If the event target is not the element
if(eventTarget != WebDeveloper.ElementAncestors.element)
{
// If the event target has a style property
if(eventTarget.style)
{
WebDeveloper.ElementAncestors.removeOutline(ownerDocument);
eventTarget.style.outline = "1px solid #b94a48";
WebDeveloper.ElementAncestors.element = eventTarget;
WebDeveloper.ElementAncestors.displayElementAncestors(eventTarget);
// Needed for Chrome to keep track of
eventTarget.setAttribute("data-web-developer-element-ancestors-outline", "true");
}
}
}
}
};
// Removes the outline
WebDeveloper.ElementAncestors.removeOutline = function(contentDocument)
{
var element = contentDocument.querySelector("[data-web-developer-element-ancestors-outline=true]");
// If the element is set
if(element)
{
element.style.outline = "";
// If the element has an empty style attribute
if(element.hasAttribute("style") && element.getAttribute("style").trim() === "")
{
element.removeAttribute("style");
}
// Needed for Chrome to keep track of
element.removeAttribute("data-web-developer-element-ancestors-outline");
}
};
var WebDeveloper = WebDeveloper || {};
WebDeveloper.ElementAncestors = WebDeveloper.ElementAncestors || {};
// Creates the element information toolbar
WebDeveloper.ElementAncestors.createToolbar = function()
{
WebDeveloper.Common.configureElement(WebDeveloper.Common.getMainWindow().document.getElementById("web-developer-element-ancestors-toolbar"), "hidden", false);
};
// Displays the ancestors of an element
WebDeveloper.ElementAncestors.displayElementAncestors = function(element)
{
var contentDocument = WebDeveloper.Common.getMainWindow().document.getElementById("web-developer-element-ancestors-browser").contentDocument;
contentDocument.defaultView.WebDeveloper.Generated.populateAncestors(WebDeveloper.ElementAncestors.getAncestorInformation(element, contentDocument));
};
// Generates ancestor information for an element
WebDeveloper.ElementAncestors.generateAncestorInformation = function(element, contentDocument)
{
var ancestorInformation = contentDocument.createElement("div");
var buttonElement = contentDocument.createElement("button");
buttonElement.appendChild(contentDocument.createTextNode(WebDeveloper.Locales.getString("copyAncestorPath")));
buttonElement.setAttribute("class", "btn btn-primary");
buttonElement.setAttribute("id", "web-developer-copy-ancestor-path");
ancestorInformation.appendChild(buttonElement);
ancestorInformation.appendChild(WebDeveloper.ElementAncestors.getAncestorInformation(element, contentDocument));
ancestorInformation.setAttribute("id", "web-developer-ancestors");
return ancestorInformation;
};
// Removes the element information toolbar
WebDeveloper.ElementAncestors.removeToolbar = function()
{
WebDeveloper.Common.configureElement(WebDeveloper.Common.getMainWindow().document.getElementById("web-developer-element-ancestors-toolbar"), "hidden", true);
};
|