Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve url sanitization and refactor code #471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions src/app/services/code-view/angular-code-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,8 @@ export class AngularCodeService extends CodeService {
}

private openLiveEditingSample($button: JQuery<HTMLButtonElement>, $codeView: JQuery<HTMLElement>) {
const codeService = this;
codeService.isButtonClickInProgress = true;
let demosBaseUrl = $codeView.attr(codeService.demosBaseUrlAttrName)!;
let sampleFileUrl = codeService.getGitHubSampleUrl(demosBaseUrl, $codeView.attr(codeService.sampleUrlAttrName)!, $codeView.attr(codeService.githubSrc)!);
let editor = $button.hasClass(codeService.stkbButtonClass) ? "stackblitz" : "codesandbox";
let branch = demosBaseUrl.indexOf("staging.infragistics.com") !== -1 ? "vNext" : "master";
window.open(codeService.getAngularGitHubSampleUrl(editor, sampleFileUrl, branch, demosBaseUrl), '_blank');
codeService.isButtonClickInProgress = false;
const demosBaseUrl = $codeView.attr(this.demosBaseUrlAttrName)!;
this.handleSampleButtonClick(demosBaseUrl, this.sampleUrlAttrName, this.githubSrc, $codeView);
}

private onAngularGithubProjectButtonClicked() {
Expand All @@ -175,18 +169,37 @@ export class AngularCodeService extends CodeService {
private onAngularGithubProjectStandaloneButtonClicked() {
const codeService = this;
return function (this: HTMLButtonElement) {
if (codeService.isButtonClickInProgress) {
return;
}
codeService.isButtonClickInProgress = true;
let $button = $(this);
let demosBaseUrl = $button.attr(codeService.demosBaseUrlAttrName)!;
let sampleFileUrl = codeService.getGitHubSampleUrl(demosBaseUrl, $button.attr(codeService.buttonSampleSourceAttrName)!);
let editor = $button.hasClass(codeService.stkbButtonClass) ? "stackblitz" : "codesandbox";
let branch = demosBaseUrl.indexOf("staging.infragistics.com") !== -1 ? "vNext" : "master";
window.open(codeService.getAngularGitHubSampleUrl(editor, sampleFileUrl, branch, demosBaseUrl), '_blank');
codeService.isButtonClickInProgress = false;
}
const $button = $(this);
const demosBaseUrl = $button.attr(codeService.demosBaseUrlAttrName)!;
codeService.handleSampleButtonClick(
demosBaseUrl,
codeService.buttonSampleSourceAttrName,
codeService.githubSrc,
$button
);
};
}

private handleSampleButtonClick(
demosBaseUrl: string,
sampleUrlAttrName: string,
githubSrcAttrName: string,
$element: JQuery<HTMLElement>
) {
const codeService = this;
if (codeService.isButtonClickInProgress) return;
codeService.isButtonClickInProgress = true;

const sampleFileUrl = codeService.getGitHubSampleUrl(
demosBaseUrl,
$element.attr(sampleUrlAttrName)!,
$element.attr(githubSrcAttrName)!
);
const editor = $element.hasClass(codeService.stkbButtonClass) ? "stackblitz" : "codesandbox";
const branch = new URL(demosBaseUrl).host === "staging.infragistics.com" ? "vNext" : "master";

window.open(codeService.getAngularGitHubSampleUrl(editor, sampleFileUrl, branch, demosBaseUrl), '_blank');
codeService.isButtonClickInProgress = false;
}

private addTimeStamp(url: string, demosTimeStamp?: number): string {
Expand Down
Loading