Skip to content

Commit

Permalink
#77 | Go to field doesn't work for fields with custom section title
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-null committed Mar 7, 2017
1 parent e951fd8 commit c16aaae
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions app/sc_ext/modules/fieldInspector/FieldInspectorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,21 @@ namespace SitecoreExtensions.Modules.FieldInspector {
for (let j = 0; j < fieldLabels.length; j++) {
var child = fieldLabels[j] as HTMLTableRowElement;
if (child.innerText == label.innerText) {
label.dataset["sectionid"] = sectionElement.innerText + "-" + j;
let sectionName = this.getSectionName(sectionElement);
label.dataset["sectionid"] = sectionName + "-" + j;

let spanGoToField = HTMLHelpers.createElement("a", { class: "sc-ext-gotofield scContentButton" }) as HTMLSpanElement;
spanGoToField.innerText = "Go to field";
spanGoToField.onclick = (e) => {
this.ensureFieldsInitialized();
if (e.ctrlKey) {
this.getFieldID(this.getActiveNodeID(), sectionElement.innerText, j, (fieldID) => {
this.getFieldID(this.getActiveNodeID(), sectionName, j, (fieldID) => {
var url = window.top.location.origin + "/sitecore/shell/Applications/Content%20Editor.aspx?sc_bw=1&fo=" + fieldID;
new Launcher.Providers.NavigationCommand(null, null, url).execute(e);
});

} else {
this.getFieldID(this.getActiveNodeID(), sectionElement.innerText, j, (fieldID) => {
this.getFieldID(this.getActiveNodeID(), sectionName, j, (fieldID) => {
let contentTree = new PageObjects.ContentTree();
contentTree.loadItem(fieldID);
});
Expand Down Expand Up @@ -194,7 +195,8 @@ namespace SitecoreExtensions.Modules.FieldInspector {
private writeDownFieldName(e, sectionElement, j) {
let elemenet = HTMLHelpers.getElement(e.srcElement, (e) => { return e.dataset['fieldid'] != null; }) as HTMLDivElement;
let fieldID = elemenet.dataset['fieldid'];
this.getFieldName(fieldID, sectionElement.innerText, j, (fieldName) => {
let sectionName = this.getSectionName(sectionElement);
this.getFieldName(fieldID, sectionName, j, (fieldName) => {
let node = this.getFirstElementWithClass(e.srcElement, this.classFieldNameSpan) as HTMLDivElement;
let currentElement = new FieldNameElement(node);
currentElement.Initialize(fieldName);
Expand Down Expand Up @@ -261,7 +263,7 @@ namespace SitecoreExtensions.Modules.FieldInspector {

let allSections = doc.querySelector(".FieldsScroller").querySelectorAll("td.FieldSection,td.FieldLabel .ItemPathTemplate");
let currentSection;
for (var index = 0; index < allSections.length; ) {
for (var index = 0; index < allSections.length;) {
var section = allSections[index] as HTMLTableDataCellElement;

if (section.className == "FieldSection") {
Expand All @@ -281,9 +283,10 @@ namespace SitecoreExtensions.Modules.FieldInspector {
let fieldIndex = 0;

let getSectionID = (tempIndex: number): string => {
let id = currentSection.innerText + "-" + tempIndex;
let sectionName = this.getSectionName(currentSection);
let id = sectionName + "-" + tempIndex;
while (document.querySelector("[data-sectionid='" + id + "']:not([data-fieldid])") == null) {
id = currentSection.innerText + "-" + (++tempIndex);
id = sectionName + "-" + (++tempIndex);
}
return id;
};
Expand All @@ -304,6 +307,10 @@ namespace SitecoreExtensions.Modules.FieldInspector {
request.execute();
}

private getSectionName(section: HTMLElement): string {
return section.onclick.toString().match(/,(.)*(?='\))/)[0].substring(2);
}

private getFirstElementWithClass(parent: any, className: string): Node {
return HTMLHelpers.getElement(parent, (e) => {
return e.classList.contains(className);
Expand Down

0 comments on commit c16aaae

Please sign in to comment.