ng-easycommerce 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/bundles/ng-easycommerce.umd.js +131 -23
- package/bundles/ng-easycommerce.umd.js.map +1 -1
- package/bundles/ng-easycommerce.umd.min.js +1 -1
- package/bundles/ng-easycommerce.umd.min.js.map +1 -1
- package/esm2015/lib/ec-directive/add-action-redirect.directive.js +133 -24
- package/esm5/lib/ec-directive/add-action-redirect.directive.js +133 -25
- package/fesm2015/ng-easycommerce.js +132 -23
- package/fesm2015/ng-easycommerce.js.map +1 -1
- package/fesm5/ng-easycommerce.js +132 -24
- package/fesm5/ng-easycommerce.js.map +1 -1
- package/lib/ec-directive/add-action-redirect.directive.d.ts +14 -2
- package/ng-easycommerce.metadata.json +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pipe, InjectionToken, Injectable, PLATFORM_ID, Inject, ɵɵdefineInjectable, ɵɵinject, Injector, INJECTOR, RendererFactory2, NgZone, Component, Input, HostListener, EventEmitter, Output, Renderer2, ViewChild, ElementRef, ViewChildren, ChangeDetectorRef, Directive, TemplateRef, ViewContainerRef, NgModule } from '@angular/core';
|
|
2
|
-
import { isPlatformBrowser, DOCUMENT, CurrencyPipe, CommonModule } from '@angular/common';
|
|
2
|
+
import { isPlatformBrowser, DOCUMENT, LocationStrategy, CurrencyPipe, CommonModule } from '@angular/common';
|
|
3
3
|
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
|
4
4
|
import { Router, NavigationEnd, NavigationStart, ActivatedRoute, RouterModule } from '@angular/router';
|
|
5
5
|
import { HttpHeaders, HttpParams, HttpClient, HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
|
@@ -23563,18 +23563,20 @@ var __param$d = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
23563
23563
|
class ParamsContext {
|
|
23564
23564
|
}
|
|
23565
23565
|
let AddActionRedirectDirective = class AddActionRedirectDirective {
|
|
23566
|
-
constructor(document, elementRef, renderer, blocksService, router) {
|
|
23566
|
+
constructor(document, elementRef, renderer, blocksService, router, locationStrategy) {
|
|
23567
23567
|
this.document = document;
|
|
23568
23568
|
this.elementRef = elementRef;
|
|
23569
23569
|
this.renderer = renderer;
|
|
23570
23570
|
this.blocksService = blocksService;
|
|
23571
23571
|
this.router = router;
|
|
23572
|
+
this.locationStrategy = locationStrategy;
|
|
23572
23573
|
this.redirectUrl = '';
|
|
23573
23574
|
this.linstenEvent = null;
|
|
23574
23575
|
this.transparent = true;
|
|
23575
|
-
this.
|
|
23576
|
-
|
|
23577
|
-
|
|
23576
|
+
this.targetManaged = false;
|
|
23577
|
+
this.originalTarget = null;
|
|
23578
|
+
this.relManaged = false;
|
|
23579
|
+
this.originalRel = null;
|
|
23578
23580
|
}
|
|
23579
23581
|
set ecAddActionRedirect(value) {
|
|
23580
23582
|
this.banner = value;
|
|
@@ -23588,10 +23590,19 @@ let AddActionRedirectDirective = class AddActionRedirectDirective {
|
|
|
23588
23590
|
ngOnInit() { }
|
|
23589
23591
|
ngOnChanges(changes) {
|
|
23590
23592
|
var _a;
|
|
23593
|
+
const element = this.elementRef.nativeElement;
|
|
23594
|
+
const target = this.targetManaged ? this.originalTarget : element.getAttribute('target');
|
|
23595
|
+
const rel = this.relManaged ? this.originalRel : element.getAttribute('rel');
|
|
23591
23596
|
if (this.linstenEvent) {
|
|
23592
23597
|
this.linstenEvent();
|
|
23593
23598
|
this.linstenEvent = null;
|
|
23594
23599
|
}
|
|
23600
|
+
this.restoreManagedAttribute('target', this.targetManaged, this.originalTarget);
|
|
23601
|
+
this.restoreManagedAttribute('rel', this.relManaged, this.originalRel);
|
|
23602
|
+
this.targetManaged = false;
|
|
23603
|
+
this.originalTarget = null;
|
|
23604
|
+
this.relManaged = false;
|
|
23605
|
+
this.originalRel = null;
|
|
23595
23606
|
this.transparent && this.renderer.setStyle(this.elementRef.nativeElement, 'color', 'transparent');
|
|
23596
23607
|
(_a = this.classStr) === null || _a === void 0 ? void 0 : _a.split(" ").forEach((cl) => {
|
|
23597
23608
|
try {
|
|
@@ -23606,18 +23617,101 @@ let AddActionRedirectDirective = class AddActionRedirectDirective {
|
|
|
23606
23617
|
if (accessibleLabel) {
|
|
23607
23618
|
this.renderer.setAttribute(this.elementRef.nativeElement, 'aria-label', accessibleLabel);
|
|
23608
23619
|
}
|
|
23609
|
-
this.renderer.setProperty(this.elementRef.nativeElement, "href", this.redirectUrl);
|
|
23610
23620
|
if (this.isExternalUrl(this.redirectUrl)) {
|
|
23611
|
-
this.renderer.
|
|
23612
|
-
|
|
23621
|
+
this.renderer.setProperty(element, "href", this.redirectUrl);
|
|
23622
|
+
const effectiveTarget = target === null ? '_blank' : target;
|
|
23623
|
+
if (target === null) {
|
|
23624
|
+
this.renderer.setAttribute(element, "target", "_blank");
|
|
23625
|
+
this.targetManaged = true;
|
|
23626
|
+
this.originalTarget = null;
|
|
23627
|
+
}
|
|
23628
|
+
if (effectiveTarget.trim().toLowerCase() === '_blank') {
|
|
23629
|
+
const relTokens = (rel || '').split(/\s+/).filter(Boolean);
|
|
23630
|
+
const existingRelTokens = relTokens.map(token => token.toLowerCase());
|
|
23631
|
+
if (existingRelTokens.indexOf('noopener') === -1)
|
|
23632
|
+
relTokens.push('noopener');
|
|
23633
|
+
if (existingRelTokens.indexOf('noreferrer') === -1)
|
|
23634
|
+
relTokens.push('noreferrer');
|
|
23635
|
+
const secureRel = relTokens.join(' ');
|
|
23636
|
+
if (secureRel !== rel) {
|
|
23637
|
+
this.renderer.setAttribute(element, "rel", secureRel);
|
|
23638
|
+
this.relManaged = true;
|
|
23639
|
+
this.originalRel = rel;
|
|
23640
|
+
}
|
|
23641
|
+
}
|
|
23613
23642
|
}
|
|
23614
23643
|
else {
|
|
23615
|
-
this.
|
|
23616
|
-
this.renderer.
|
|
23617
|
-
|
|
23618
|
-
|
|
23619
|
-
|
|
23620
|
-
|
|
23644
|
+
const routerUrl = this.toRouterUrl(this.redirectUrl);
|
|
23645
|
+
this.renderer.setProperty(element, "href", this.locationStrategy.prepareExternalUrl(routerUrl));
|
|
23646
|
+
if (target === null) {
|
|
23647
|
+
this.linstenEvent = this.renderer.listen(element, 'click', (evt) => {
|
|
23648
|
+
if (!this.shouldHandleSpaClick(evt))
|
|
23649
|
+
return;
|
|
23650
|
+
evt.preventDefault();
|
|
23651
|
+
this.router.navigateByUrl(routerUrl);
|
|
23652
|
+
});
|
|
23653
|
+
}
|
|
23654
|
+
}
|
|
23655
|
+
}
|
|
23656
|
+
shouldHandleSpaClick(event) {
|
|
23657
|
+
return !event.defaultPrevented && event.button === 0 &&
|
|
23658
|
+
!event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey;
|
|
23659
|
+
}
|
|
23660
|
+
toRouterUrl(url) {
|
|
23661
|
+
let routerUrl;
|
|
23662
|
+
if (this.isAbsoluteUrl(url) || url.startsWith('#') || url.startsWith('?')) {
|
|
23663
|
+
const target = new URL(url, this.getDocumentHref());
|
|
23664
|
+
routerUrl = target.pathname + target.search + target.hash;
|
|
23665
|
+
}
|
|
23666
|
+
else {
|
|
23667
|
+
routerUrl = this.router.serializeUrl(this.router.parseUrl(url));
|
|
23668
|
+
}
|
|
23669
|
+
return this.stripBaseHref(routerUrl);
|
|
23670
|
+
}
|
|
23671
|
+
stripBaseHref(url) {
|
|
23672
|
+
const pathEnd = url.search(/[?#]/);
|
|
23673
|
+
const path = pathEnd === -1 ? url : url.substring(0, pathEnd);
|
|
23674
|
+
const suffix = pathEnd === -1 ? '' : url.substring(pathEnd);
|
|
23675
|
+
const baseHref = this.locationStrategy.getBaseHref();
|
|
23676
|
+
if (!baseHref)
|
|
23677
|
+
return url;
|
|
23678
|
+
try {
|
|
23679
|
+
const current = new URL(this.getDocumentHref());
|
|
23680
|
+
const base = new URL(baseHref, current.href);
|
|
23681
|
+
let basePath = base.origin === current.origin ? base.pathname : '';
|
|
23682
|
+
basePath = basePath.replace(/\/index\.html$/i, '').replace(/\/+$/, '');
|
|
23683
|
+
if (!basePath || basePath === '/')
|
|
23684
|
+
return url;
|
|
23685
|
+
if (path === basePath)
|
|
23686
|
+
return '/' + suffix;
|
|
23687
|
+
if (path.indexOf(basePath + '/') === 0) {
|
|
23688
|
+
return path.substring(basePath.length) + suffix;
|
|
23689
|
+
}
|
|
23690
|
+
}
|
|
23691
|
+
catch (e) {
|
|
23692
|
+
// Keep the URL unchanged when the browser cannot resolve the base href.
|
|
23693
|
+
}
|
|
23694
|
+
return url;
|
|
23695
|
+
}
|
|
23696
|
+
getDocumentHref() {
|
|
23697
|
+
const location = this.document && this.document.location;
|
|
23698
|
+
if (location && location.href)
|
|
23699
|
+
return location.href;
|
|
23700
|
+
if (location && location.origin)
|
|
23701
|
+
return location.origin + '/';
|
|
23702
|
+
return 'http://localhost/';
|
|
23703
|
+
}
|
|
23704
|
+
isAbsoluteUrl(url) {
|
|
23705
|
+
return /^[a-z][a-z\d+.-]*:/i.test(url) || url.indexOf('//') === 0;
|
|
23706
|
+
}
|
|
23707
|
+
restoreManagedAttribute(name, managed, originalValue) {
|
|
23708
|
+
if (!managed)
|
|
23709
|
+
return;
|
|
23710
|
+
if (originalValue === null) {
|
|
23711
|
+
this.renderer.removeAttribute(this.elementRef.nativeElement, name);
|
|
23712
|
+
}
|
|
23713
|
+
else {
|
|
23714
|
+
this.renderer.setAttribute(this.elementRef.nativeElement, name, originalValue);
|
|
23621
23715
|
}
|
|
23622
23716
|
}
|
|
23623
23717
|
getAccessibleLabel() {
|
|
@@ -23637,22 +23731,36 @@ let AddActionRedirectDirective = class AddActionRedirectDirective {
|
|
|
23637
23731
|
return ((_k = (_j = this.banner) === null || _j === void 0 ? void 0 : _j.name) === null || _k === void 0 ? void 0 : _k.trim()) || 'Ver más';
|
|
23638
23732
|
}
|
|
23639
23733
|
isExternalUrl(url) {
|
|
23640
|
-
|
|
23641
|
-
if (!url)
|
|
23642
|
-
return false;
|
|
23643
|
-
if (url.startsWith('/') || url.startsWith('#'))
|
|
23734
|
+
if (!url || !this.isAbsoluteUrl(url))
|
|
23644
23735
|
return false;
|
|
23645
23736
|
try {
|
|
23646
|
-
const
|
|
23647
|
-
const target = new URL(url,
|
|
23648
|
-
if (
|
|
23737
|
+
const current = new URL(this.getDocumentHref());
|
|
23738
|
+
const target = new URL(url, current.href);
|
|
23739
|
+
if (target.origin !== current.origin)
|
|
23649
23740
|
return true;
|
|
23650
|
-
return target.
|
|
23741
|
+
return this.isOutsideBaseHref(target.pathname, current);
|
|
23651
23742
|
}
|
|
23652
23743
|
catch (e) {
|
|
23653
23744
|
return true;
|
|
23654
23745
|
}
|
|
23655
23746
|
}
|
|
23747
|
+
isOutsideBaseHref(pathname, current) {
|
|
23748
|
+
const baseHref = this.locationStrategy.getBaseHref();
|
|
23749
|
+
if (!baseHref)
|
|
23750
|
+
return false;
|
|
23751
|
+
try {
|
|
23752
|
+
const base = new URL(baseHref, current.href);
|
|
23753
|
+
if (base.origin !== current.origin)
|
|
23754
|
+
return false;
|
|
23755
|
+
const basePath = base.pathname.replace(/\/index\.html$/i, '').replace(/\/+$/, '');
|
|
23756
|
+
if (!basePath || basePath === '/')
|
|
23757
|
+
return false;
|
|
23758
|
+
return pathname !== basePath && pathname.indexOf(basePath + '/') !== 0;
|
|
23759
|
+
}
|
|
23760
|
+
catch (e) {
|
|
23761
|
+
return false;
|
|
23762
|
+
}
|
|
23763
|
+
}
|
|
23656
23764
|
ngOnDestroy() {
|
|
23657
23765
|
this.linstenEvent && this.linstenEvent();
|
|
23658
23766
|
}
|
|
@@ -23662,7 +23770,8 @@ AddActionRedirectDirective.ctorParameters = () => [
|
|
|
23662
23770
|
{ type: ElementRef },
|
|
23663
23771
|
{ type: Renderer2 },
|
|
23664
23772
|
{ type: BlocksService },
|
|
23665
|
-
{ type: Router }
|
|
23773
|
+
{ type: Router },
|
|
23774
|
+
{ type: LocationStrategy }
|
|
23666
23775
|
];
|
|
23667
23776
|
__decorate$2a([
|
|
23668
23777
|
Input()
|