Skip to content

Commit

Permalink
#116 | Add here - placeholder name
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-null committed Oct 11, 2020
1 parent 2f2e553 commit 0ac142c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ Sitecore Extensions is a google chrome/firefox extension which provides small im
- Database colour - Change the global header colour depending on current database,
- Icon colour - changes colour to red when using Sitecore on current tab, otherwise will be grayed,
- Field Search - quickly find a field or section in the Content view in Content Editor,
- Restore Last Location - restores last opened item in Content Editor
- Toggle Ribbon - small button which allows you to hide whole ribbon while working in Experience Editor.
- Tree Auto Expand - it will automatically expand tree structure if there is only one child under expanded item.
- Tree Scope - give an ability to scope a content tree to the currently selected item
- Field Inspector - go to field, inspect field name, reset value to `__Standard values`
- Restore Last Location - restores last opened item in Content Editor,
- Toggle Ribbon - small button which allows you to hide whole ribbon while working in Experience Editor,
- Tree Auto Expand - it will automatically expand tree structure if there is only one child under expanded item,
- Tree Scope - give an ability to scope a content tree to the currently selected item,
- Field Inspector - go to field, inspect field name, reset value to `__Standard values`,
- Add Here - extends AddHere button in ExperienceEditor with placeholder name

More information about all available feature with `gif` demos can be found [here](https://github.com/alan-null/sc_ext/wiki)

Expand Down
3 changes: 3 additions & 0 deletions app/sc_ext/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace SitecoreExtensions {
var goToDatasource = new Modules.GoToDatasource.GoToDatasourceModule('Go To Datasource', 'Navigate to a datasource item.', wrapper.getModuleOptions('Go To Datasource'));
var treeAutoExpand = new Modules.TreeAutoExpand.TreeAutoExpandModule('Tree Auto Expand', 'Automatically expand tree deeply if there is only one child.', wrapper.getModuleOptions('Tree Auto Expand'));
var scrollToItem = new Modules.ScrollToItem.ScrollToItemModule('Scroll To Item', 'Scrolls to the active tree node in a Content Editor', wrapper.getModuleOptions('Scroll To Item'));
var addHere = new Modules.AddHere.AddHereModule('Add Here', 'Extends AddHere button in ExperienceEditor with placeholder name', wrapper.getModuleOptions('Add Here'));


scExtManager.addModule(sectionSwitchesModule);
Expand All @@ -45,6 +46,7 @@ namespace SitecoreExtensions {
scExtManager.addModule(goToDatasource);
scExtManager.addModule(treeAutoExpand);
scExtManager.addModule(scrollToItem);
scExtManager.addModule(addHere);

scExtManager.initModules();

Expand Down Expand Up @@ -73,6 +75,7 @@ namespace SitecoreExtensions {
}
})();


function getStatusProvider(type: StatusType): Status.IStatusProvider {
switch (type) {
case StatusType.AvailableCommandsCount:
Expand Down
1 change: 1 addition & 0 deletions app/sc_ext/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
/// <reference path='modules/treeScope/_all.ts'/>
/// <reference path='modules/treeAutoExpand/_all.ts'/>
/// <reference path='modules/scrollToItem/_all.ts'/>
/// <reference path='modules/addHere/_all.ts'/>


// Status
Expand Down
24 changes: 24 additions & 0 deletions app/sc_ext/modules/addHere/AddHereButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path='../../_all.ts'/>

namespace SitecoreExtensions.Modules.AddHere {
export class AddHereButton {
classButtonInitialized: string = "sc-ext-addHere-button-initialized";
innerElement: HTMLDivElement;
textElement: HTMLSpanElement;
placeholderName: string;
constructor(innerElement: HTMLDivElement) {
this.innerElement = innerElement;
this.textElement = this.innerElement.nextElementSibling.firstChild as HTMLSpanElement;
this.placeholderName = this.innerElement.parentElement.title.match(/'.*'/)[0].replace(/'/g, "");
this.innerElement.classList.add(this.classButtonInitialized);
}

public setText(text: string) {
this.textElement.innerText = text;
}

public getText(): string {
return this.textElement.innerText;
}
}
}
41 changes: 41 additions & 0 deletions app/sc_ext/modules/addHere/AddHereModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// <reference path='../../_all.ts'/>

namespace SitecoreExtensions.Modules.AddHere {
export class AddHereModule 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.ExperienceEditor;
}

initialize(): void {
if (window["Sitecore"] != null && Sitecore.PageModes != null) {
HTMLHelpers.addProxy((Sitecore.PageModes.DesignManager as any), 'insertionStart', () => { this.refreshControls(); });
}
}

getAddHereButtons(): Array<AddHereButton> {
var elements = document.querySelectorAll('.scInsertionHandleLeft.scAddToHere:not(.sc-ext-addHere-button-initialized)') as NodeListOf<HTMLDivElement>;
return Array.from(Array.prototype.slice.call(elements) as Array<HTMLDivElement>, e => new AddHereButton(e));
}

refreshControls(): void {
var addHereButtons = this.getAddHereButtons();
if (addHereButtons.length === 0) {
return;
}

addHereButtons.forEach(button => {
let buttons = addHereButtons.filter(function (b) { return b.placeholderName == button.placeholderName; });
let txt = button.getText() + " | " + button.placeholderName;
if (buttons.length > 1) {
let index = buttons.indexOf(button) + 1;
txt = txt + "(" + index + ")";
}
button.setText(txt);
});
}
}
}
4 changes: 4 additions & 0 deletions app/sc_ext/modules/addHere/_all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference path='../../_all.ts'/>

/// <reference path='AddHereButton.ts'/>
/// <reference path='AddHereModule.ts'/>
1 change: 1 addition & 0 deletions app/sc_ext/typings/sitecore.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
declare var scForm: any;
declare var scSitecore: any;
declare var Sitecore: any;
declare var scContentEditor: any;

0 comments on commit 0ac142c

Please sign in to comment.