-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/// <reference path='../../_all.ts'/> | ||
|
||
namespace SitecoreExtensions.Modules.TreeAutoExpand { | ||
export class TreeAutoExpandModule extends ModuleBase implements ISitecoreExtensionsModule { | ||
|
||
constructor(name: string, description: string, rawOptions: Options.ModuleOptionsBase) { | ||
super(name, description, rawOptions); | ||
} | ||
|
||
canExecute(): boolean { | ||
return this.options.enabled && Context.Location() == Enums.Location.ContentEditor; | ||
} | ||
|
||
initialize(): void { | ||
this.addTreeNodeHandlers('scContentTree'); | ||
} | ||
|
||
addTreeNodeHandlers(className: string): void { | ||
var nodes = document.getElementsByClassName(className); | ||
for (var i = 0; i < nodes.length; i++) { | ||
nodes[i].addEventListener('click', (evt: MouseEvent) => { | ||
setTimeout(() => { | ||
this.expandSubTree(evt); | ||
}, 10); | ||
}); | ||
} | ||
} | ||
|
||
expandSubTree(evt: MouseEvent): void { | ||
let glyphId = evt.srcElement.id; | ||
let icon = new TreeNodeGlyph(glyphId); | ||
|
||
if (icon.isExpandable()) { | ||
HTMLHelpers.postponeAction(_ => { return this.predicate(glyphId); }, _ => { this.action(glyphId); }, 100, 10); | ||
} | ||
} | ||
|
||
private predicate(glyphId: string): boolean { | ||
return new TreeNodeGlyph(glyphId).isExpanded(); | ||
} | ||
|
||
private action(glyphId: string): void { | ||
let icon = new TreeNodeGlyph(glyphId); | ||
let childNodeds = icon.getChildren(); | ||
if (childNodeds.length == 1) { | ||
(childNodeds[0].querySelector(".scContentTreeNodeGlyph") as HTMLImageElement).click(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// <reference path='../../_all.ts'/> | ||
|
||
namespace SitecoreExtensions.Modules.TreeAutoExpand { | ||
export class TreeNodeGlyph { | ||
private iconExpanded: string = "/sitecore/shell/themes/standard/images/treemenu_expanded.png"; | ||
private iconNonExpand: string = "/sitecore/shell/themes/standard/images/noexpand15x15.gif"; | ||
private iconCollapsed: string = "sitecore/shell/themes/standard/images/treemenu_collapsed.png"; | ||
private treeNodeGlyphElement: HTMLImageElement; | ||
|
||
constructor(elementId: string) { | ||
this.treeNodeGlyphElement = document.getElementById(elementId) as HTMLImageElement; | ||
} | ||
|
||
isExpanded(): boolean { | ||
let isExpanded = this.treeNodeGlyphElement.src.endsWith(this.iconExpanded); | ||
return isExpanded; | ||
} | ||
|
||
isExpandable(): boolean { | ||
if (this.treeNodeGlyphElement && this.treeNodeGlyphElement.src) { | ||
return !this.treeNodeGlyphElement.src.endsWith(this.iconNonExpand) && !this.treeNodeGlyphElement.src.endsWith(this.iconCollapsed); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
getChildren() { | ||
return this.treeNodeGlyphElement.parentElement.querySelectorAll(".scContentTreeNode"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// <reference path='../../_all.ts'/> | ||
|
||
/// <reference path='TreeAutoExpandModule.ts'/> | ||
/// <reference path='TreeNodeGlyph.ts'/> |