Skip to content

Commit

Permalink
#9 | Ability to open navigation commands in new window
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Plocieniak committed Jun 22, 2016
1 parent 9c6dbd7 commit e32dfcd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 59 deletions.
1 change: 1 addition & 0 deletions app/sc_ext/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/// <reference path='modules/Launcher/ICommand.ts'/>
/// <reference path='modules/Launcher/models/SearchResult.ts'/>
/// <reference path='modules/Launcher/providers/ICommandsProvider.ts'/>
/// <reference path='modules/Launcher/providers/NavigationCommand.ts'/>
/// <reference path='modules/Launcher/providers/ContentEditorRibbonCommandsProvider.ts'/>
/// <reference path='modules/Launcher/providers/AdminShortcutsCommandsProvider.ts'/>
/// <reference path='modules/Launcher/providers/LaunchpadCommandsProvider.ts'/>
Expand Down
6 changes: 3 additions & 3 deletions app/sc_ext/modules/launcher/LauncherModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ namespace SitecoreExtensions.Modules.Launcher {
});
}

executeSelectedCommand(): void {
executeSelectedCommand(evt?: KeyboardEvent): void {
var command = <ICommand>this.commands.find((cmd: ICommand) => {
var selectedComandId = parseInt((<HTMLLIElement>this.selectedCommand[0]).dataset['id'])
return cmd.id == selectedComandId
});
command.execute();
command.execute(evt);
this.hideLauncher()
}

inputKeyUpEvent(evt: KeyboardEvent): void {
if (evt.keyCode == this.launcherOptions.shortcuts.executeCommand && this.selectedCommand[0]) {
this.executeSelectedCommand();
this.executeSelectedCommand(evt);
return;
}
if (evt.keyCode == this.launcherOptions.shortcuts.selectPrevResult || evt.keyCode == this.launcherOptions.shortcuts.selectNextResult) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
/// <reference path='../../../_all.ts'/>

namespace SitecoreExtensions.Modules.Launcher.Providers {
class ShortcutCommand implements ICommand {
id: number;
name: string;
description: string;
aspx: string;

constructor(name, description, aspx) {
this.id = 0;
this.aspx = aspx;
this.name = name;
this.description = description;
}

navigate(aspx: string): void {
var location = window.top.location.origin + '/sitecore/admin/' + aspx + '.aspx'
window.top.document.location.href = location;
}

canExecute(): boolean {
return true;
}

execute(): void {
this.navigate(this.aspx)
class ShortcutCommand extends NavigationCommand implements ICommand {
constructor(name: string, description: string, aspx: string) {
super(name, description, window.top.location.origin + '/sitecore/admin/' + aspx + '.aspx')
}
}
export class AdminShortcutsCommandsProvider implements ICommandsProvider {
Expand Down
27 changes: 3 additions & 24 deletions app/sc_ext/modules/launcher/providers/LaunchPadCommandsProvider.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
/// <reference path='../../../_all.ts'/>

namespace SitecoreExtensions.Modules.Launcher.Providers {
class LaunchpadShortcutCommand implements ICommand {
id: number;
name: string;
description: string;
url: string;

constructor(name, description, url) {
this.id = 0;
this.url = url;
this.name = name;
this.description = description;
}

public canExecute(): boolean {
return true;
}

public execute(): void {
this.navigate(this.url)
}

private navigate(url: string): void {
let location: string = window.top.location.origin + url;
window.top.document.location.href = location;
class LaunchpadShortcutCommand extends NavigationCommand implements ICommand {
constructor(name: string, description: string, url: string) {
super(name, description, url)
}
}

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

namespace SitecoreExtensions.Modules.Launcher.Providers {
export class NavigationCommand implements ICommand {
id: number;
name: string;
description: string;
url: string;

constructor(name: string, description: string, url: string) {
this.id = 0;
this.name = name;
this.description = description;
this.url = url;
}

private openInCurrentTab(): void {
window.top.document.location.href = this.url;
}

private openInNewTab(): void {
var virtualLink = HTMLHelpers.createElement("a", {
target: "_blank",
href: this.url
}) as HTMLLinkElement;
virtualLink.click();
}

canExecute(): boolean {
return true;
}

execute(evt: KeyboardEvent): void {
if (evt && evt.ctrlKey) {
this.openInNewTab();
} else {
this.openInCurrentTab();
}
}
}
}
11 changes: 6 additions & 5 deletions app/sc_ext/modules/shortcutsRunner/ShortcutRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ namespace SitecoreExtensions.Modules.ShortcutsRunner {
this.token = this.tokenService.getToken();
}

public runShortcutCommand(shortcutId: string): void {
public runShortcutCommand(shortcutId: string, evt?: KeyboardEvent): void {
this.getShortcutUrl((e) => {
if (e.currentTarget.status == 500) {
this.handleErrorAndRetry(shortcutId);
} else {
var data = JSON.parse(e.currentTarget.responseText);
this.invokeCommand(data);
this.invokeCommand(data, evt);
}
}, shortcutId)
}

private invokeCommand(data): void {
private invokeCommand(data, evt?: KeyboardEvent): void {
var lastCommandIndex = data.commands.length - 1;
var iFrame = data.commands[lastCommandIndex].value;
var urls = iFrame.match(/\/sitecore\/shell(.)*png/)
if (urls) {
var url = urls[0]
window.top.document.location.href = window.top.location.origin + url;
var url = window.top.location.origin + urls[0]
var command = new Launcher.Providers.NavigationCommand(null, null, url)
command.execute(evt);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SitecoreExtensions.Modules.ShortcutsRunner.Providers {
runner: ShortcutRunner;
shortcutID: string;

constructor(name, description, runner, shortcutID) {
constructor(name: string, description: string, runner: ShortcutRunner, shortcutID: string) {
this.id = 0;
this.runner = runner;
this.name = name;
Expand All @@ -22,8 +22,8 @@ namespace SitecoreExtensions.Modules.ShortcutsRunner.Providers {
return true;
}

public execute(): void {
this.runner.runShortcutCommand(this.shortcutID);
public execute(evt?: KeyboardEvent): void {
this.runner.runShortcutCommand(this.shortcutID, evt);
}
}
}

0 comments on commit e32dfcd

Please sign in to comment.