move popOut to popupUtils service
This commit is contained in:
parent
814e43999b
commit
733033e472
|
@ -6,8 +6,6 @@ import {
|
||||||
|
|
||||||
import { Angulartics2 } from 'angulartics2';
|
import { Angulartics2 } from 'angulartics2';
|
||||||
|
|
||||||
import { BrowserApi } from '../../browser/browserApi';
|
|
||||||
|
|
||||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
|
|
||||||
import { PopupUtilsService } from '../services/popup-utils.service';
|
import { PopupUtilsService } from '../services/popup-utils.service';
|
||||||
|
@ -33,45 +31,6 @@ export class PopOutComponent implements OnInit {
|
||||||
|
|
||||||
expand() {
|
expand() {
|
||||||
this.analytics.eventTrack.next({ action: 'Pop Out Window' });
|
this.analytics.eventTrack.next({ action: 'Pop Out Window' });
|
||||||
|
this.popupUtilsService.popOut(window);
|
||||||
let href = window.location.href;
|
|
||||||
if (this.platformUtilsService.isEdge()) {
|
|
||||||
const popupIndex = href.indexOf('/popup/');
|
|
||||||
if (popupIndex > -1) {
|
|
||||||
href = href.substring(popupIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((typeof chrome !== 'undefined') && chrome.windows && chrome.windows.create) {
|
|
||||||
if (href.indexOf('?uilocation=') > -1) {
|
|
||||||
href = href.replace('uilocation=popup', 'uilocation=popout')
|
|
||||||
.replace('uilocation=tab', 'uilocation=popout')
|
|
||||||
.replace('uilocation=sidebar', 'uilocation=popout');
|
|
||||||
} else {
|
|
||||||
const hrefParts = href.split('#');
|
|
||||||
href = hrefParts[0] + '?uilocation=popout' + (hrefParts.length > 0 ? '#' + hrefParts[1] : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
const bodyRect = document.querySelector('body').getBoundingClientRect();
|
|
||||||
chrome.windows.create({
|
|
||||||
url: href,
|
|
||||||
type: 'popup',
|
|
||||||
width: Math.round(bodyRect.width ? bodyRect.width + 60 : 375),
|
|
||||||
height: Math.round(bodyRect.height || 600),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.popupUtilsService.inPopup(window)) {
|
|
||||||
BrowserApi.closePopup(window);
|
|
||||||
}
|
|
||||||
} else if ((typeof chrome !== 'undefined') && chrome.tabs && chrome.tabs.create) {
|
|
||||||
href = href.replace('uilocation=popup', 'uilocation=tab')
|
|
||||||
.replace('uilocation=popout', 'uilocation=tab')
|
|
||||||
.replace('uilocation=sidebar', 'uilocation=tab');
|
|
||||||
chrome.tabs.create({
|
|
||||||
url: href,
|
|
||||||
});
|
|
||||||
} else if ((typeof safari !== 'undefined')) {
|
|
||||||
// Safari can't open popup in full page tab :(
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
import { BrowserApi } from '../../browser/browserApi';
|
||||||
|
|
||||||
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PopupUtilsService {
|
export class PopupUtilsService {
|
||||||
|
constructor(private platformUtilsService: PlatformUtilsService) {}
|
||||||
|
|
||||||
inSidebar(win: Window): boolean {
|
inSidebar(win: Window): boolean {
|
||||||
return win.location.search !== '' && win.location.search.indexOf('uilocation=sidebar') > -1;
|
return win.location.search !== '' && win.location.search.indexOf('uilocation=sidebar') > -1;
|
||||||
}
|
}
|
||||||
|
@ -30,4 +36,46 @@ export class PopupUtilsService {
|
||||||
content.scrollTop = scrollY;
|
content.scrollTop = scrollY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
popOut(win: Window): void {
|
||||||
|
let href = win.location.href;
|
||||||
|
if (this.platformUtilsService.isEdge()) {
|
||||||
|
const popupIndex = href.indexOf('/popup/');
|
||||||
|
if (popupIndex > -1) {
|
||||||
|
href = href.substring(popupIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((typeof chrome !== 'undefined') && chrome.windows && chrome.windows.create) {
|
||||||
|
if (href.indexOf('?uilocation=') > -1) {
|
||||||
|
href = href.replace('uilocation=popup', 'uilocation=popout')
|
||||||
|
.replace('uilocation=tab', 'uilocation=popout')
|
||||||
|
.replace('uilocation=sidebar', 'uilocation=popout');
|
||||||
|
} else {
|
||||||
|
const hrefParts = href.split('#');
|
||||||
|
href = hrefParts[0] + '?uilocation=popout' + (hrefParts.length > 0 ? '#' + hrefParts[1] : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
const bodyRect = document.querySelector('body').getBoundingClientRect();
|
||||||
|
chrome.windows.create({
|
||||||
|
url: href,
|
||||||
|
type: 'popup',
|
||||||
|
width: Math.round(bodyRect.width ? bodyRect.width + 60 : 375),
|
||||||
|
height: Math.round(bodyRect.height || 600),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.inPopup(win)) {
|
||||||
|
BrowserApi.closePopup(win);
|
||||||
|
}
|
||||||
|
} else if ((typeof chrome !== 'undefined') && chrome.tabs && chrome.tabs.create) {
|
||||||
|
href = href.replace('uilocation=popup', 'uilocation=tab')
|
||||||
|
.replace('uilocation=popout', 'uilocation=tab')
|
||||||
|
.replace('uilocation=sidebar', 'uilocation=tab');
|
||||||
|
chrome.tabs.create({
|
||||||
|
url: href,
|
||||||
|
});
|
||||||
|
} else if ((typeof safari !== 'undefined')) {
|
||||||
|
// Safari can't open popup in full page tab :(
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue