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
package/fesm5/ng-easycommerce.js
CHANGED
|
@@ -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';
|
|
@@ -27145,19 +27145,20 @@ var ParamsContext = /** @class */ (function () {
|
|
|
27145
27145
|
return ParamsContext;
|
|
27146
27146
|
}());
|
|
27147
27147
|
var AddActionRedirectDirective = /** @class */ (function () {
|
|
27148
|
-
function AddActionRedirectDirective(document, elementRef, renderer, blocksService, router) {
|
|
27149
|
-
var _this = this;
|
|
27148
|
+
function AddActionRedirectDirective(document, elementRef, renderer, blocksService, router, locationStrategy) {
|
|
27150
27149
|
this.document = document;
|
|
27151
27150
|
this.elementRef = elementRef;
|
|
27152
27151
|
this.renderer = renderer;
|
|
27153
27152
|
this.blocksService = blocksService;
|
|
27154
27153
|
this.router = router;
|
|
27154
|
+
this.locationStrategy = locationStrategy;
|
|
27155
27155
|
this.redirectUrl = '';
|
|
27156
27156
|
this.linstenEvent = null;
|
|
27157
27157
|
this.transparent = true;
|
|
27158
|
-
this.
|
|
27159
|
-
|
|
27160
|
-
|
|
27158
|
+
this.targetManaged = false;
|
|
27159
|
+
this.originalTarget = null;
|
|
27160
|
+
this.relManaged = false;
|
|
27161
|
+
this.originalRel = null;
|
|
27161
27162
|
}
|
|
27162
27163
|
Object.defineProperty(AddActionRedirectDirective.prototype, "ecAddActionRedirect", {
|
|
27163
27164
|
set: function (value) {
|
|
@@ -27184,10 +27185,19 @@ var AddActionRedirectDirective = /** @class */ (function () {
|
|
|
27184
27185
|
AddActionRedirectDirective.prototype.ngOnChanges = function (changes) {
|
|
27185
27186
|
var _this = this;
|
|
27186
27187
|
var _a;
|
|
27188
|
+
var element = this.elementRef.nativeElement;
|
|
27189
|
+
var target = this.targetManaged ? this.originalTarget : element.getAttribute('target');
|
|
27190
|
+
var rel = this.relManaged ? this.originalRel : element.getAttribute('rel');
|
|
27187
27191
|
if (this.linstenEvent) {
|
|
27188
27192
|
this.linstenEvent();
|
|
27189
27193
|
this.linstenEvent = null;
|
|
27190
27194
|
}
|
|
27195
|
+
this.restoreManagedAttribute('target', this.targetManaged, this.originalTarget);
|
|
27196
|
+
this.restoreManagedAttribute('rel', this.relManaged, this.originalRel);
|
|
27197
|
+
this.targetManaged = false;
|
|
27198
|
+
this.originalTarget = null;
|
|
27199
|
+
this.relManaged = false;
|
|
27200
|
+
this.originalRel = null;
|
|
27191
27201
|
this.transparent && this.renderer.setStyle(this.elementRef.nativeElement, 'color', 'transparent');
|
|
27192
27202
|
(_a = this.classStr) === null || _a === void 0 ? void 0 : _a.split(" ").forEach(function (cl) {
|
|
27193
27203
|
try {
|
|
@@ -27202,18 +27212,101 @@ var AddActionRedirectDirective = /** @class */ (function () {
|
|
|
27202
27212
|
if (accessibleLabel) {
|
|
27203
27213
|
this.renderer.setAttribute(this.elementRef.nativeElement, 'aria-label', accessibleLabel);
|
|
27204
27214
|
}
|
|
27205
|
-
this.renderer.setProperty(this.elementRef.nativeElement, "href", this.redirectUrl);
|
|
27206
27215
|
if (this.isExternalUrl(this.redirectUrl)) {
|
|
27207
|
-
this.renderer.
|
|
27208
|
-
|
|
27216
|
+
this.renderer.setProperty(element, "href", this.redirectUrl);
|
|
27217
|
+
var effectiveTarget = target === null ? '_blank' : target;
|
|
27218
|
+
if (target === null) {
|
|
27219
|
+
this.renderer.setAttribute(element, "target", "_blank");
|
|
27220
|
+
this.targetManaged = true;
|
|
27221
|
+
this.originalTarget = null;
|
|
27222
|
+
}
|
|
27223
|
+
if (effectiveTarget.trim().toLowerCase() === '_blank') {
|
|
27224
|
+
var relTokens = (rel || '').split(/\s+/).filter(Boolean);
|
|
27225
|
+
var existingRelTokens = relTokens.map(function (token) { return token.toLowerCase(); });
|
|
27226
|
+
if (existingRelTokens.indexOf('noopener') === -1)
|
|
27227
|
+
relTokens.push('noopener');
|
|
27228
|
+
if (existingRelTokens.indexOf('noreferrer') === -1)
|
|
27229
|
+
relTokens.push('noreferrer');
|
|
27230
|
+
var secureRel = relTokens.join(' ');
|
|
27231
|
+
if (secureRel !== rel) {
|
|
27232
|
+
this.renderer.setAttribute(element, "rel", secureRel);
|
|
27233
|
+
this.relManaged = true;
|
|
27234
|
+
this.originalRel = rel;
|
|
27235
|
+
}
|
|
27236
|
+
}
|
|
27209
27237
|
}
|
|
27210
27238
|
else {
|
|
27211
|
-
this.
|
|
27212
|
-
this.renderer.
|
|
27213
|
-
|
|
27214
|
-
|
|
27215
|
-
|
|
27216
|
-
|
|
27239
|
+
var routerUrl_1 = this.toRouterUrl(this.redirectUrl);
|
|
27240
|
+
this.renderer.setProperty(element, "href", this.locationStrategy.prepareExternalUrl(routerUrl_1));
|
|
27241
|
+
if (target === null) {
|
|
27242
|
+
this.linstenEvent = this.renderer.listen(element, 'click', function (evt) {
|
|
27243
|
+
if (!_this.shouldHandleSpaClick(evt))
|
|
27244
|
+
return;
|
|
27245
|
+
evt.preventDefault();
|
|
27246
|
+
_this.router.navigateByUrl(routerUrl_1);
|
|
27247
|
+
});
|
|
27248
|
+
}
|
|
27249
|
+
}
|
|
27250
|
+
};
|
|
27251
|
+
AddActionRedirectDirective.prototype.shouldHandleSpaClick = function (event) {
|
|
27252
|
+
return !event.defaultPrevented && event.button === 0 &&
|
|
27253
|
+
!event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey;
|
|
27254
|
+
};
|
|
27255
|
+
AddActionRedirectDirective.prototype.toRouterUrl = function (url) {
|
|
27256
|
+
var routerUrl;
|
|
27257
|
+
if (this.isAbsoluteUrl(url) || url.startsWith('#') || url.startsWith('?')) {
|
|
27258
|
+
var target = new URL(url, this.getDocumentHref());
|
|
27259
|
+
routerUrl = target.pathname + target.search + target.hash;
|
|
27260
|
+
}
|
|
27261
|
+
else {
|
|
27262
|
+
routerUrl = this.router.serializeUrl(this.router.parseUrl(url));
|
|
27263
|
+
}
|
|
27264
|
+
return this.stripBaseHref(routerUrl);
|
|
27265
|
+
};
|
|
27266
|
+
AddActionRedirectDirective.prototype.stripBaseHref = function (url) {
|
|
27267
|
+
var pathEnd = url.search(/[?#]/);
|
|
27268
|
+
var path = pathEnd === -1 ? url : url.substring(0, pathEnd);
|
|
27269
|
+
var suffix = pathEnd === -1 ? '' : url.substring(pathEnd);
|
|
27270
|
+
var baseHref = this.locationStrategy.getBaseHref();
|
|
27271
|
+
if (!baseHref)
|
|
27272
|
+
return url;
|
|
27273
|
+
try {
|
|
27274
|
+
var current = new URL(this.getDocumentHref());
|
|
27275
|
+
var base = new URL(baseHref, current.href);
|
|
27276
|
+
var basePath = base.origin === current.origin ? base.pathname : '';
|
|
27277
|
+
basePath = basePath.replace(/\/index\.html$/i, '').replace(/\/+$/, '');
|
|
27278
|
+
if (!basePath || basePath === '/')
|
|
27279
|
+
return url;
|
|
27280
|
+
if (path === basePath)
|
|
27281
|
+
return '/' + suffix;
|
|
27282
|
+
if (path.indexOf(basePath + '/') === 0) {
|
|
27283
|
+
return path.substring(basePath.length) + suffix;
|
|
27284
|
+
}
|
|
27285
|
+
}
|
|
27286
|
+
catch (e) {
|
|
27287
|
+
// Keep the URL unchanged when the browser cannot resolve the base href.
|
|
27288
|
+
}
|
|
27289
|
+
return url;
|
|
27290
|
+
};
|
|
27291
|
+
AddActionRedirectDirective.prototype.getDocumentHref = function () {
|
|
27292
|
+
var location = this.document && this.document.location;
|
|
27293
|
+
if (location && location.href)
|
|
27294
|
+
return location.href;
|
|
27295
|
+
if (location && location.origin)
|
|
27296
|
+
return location.origin + '/';
|
|
27297
|
+
return 'http://localhost/';
|
|
27298
|
+
};
|
|
27299
|
+
AddActionRedirectDirective.prototype.isAbsoluteUrl = function (url) {
|
|
27300
|
+
return /^[a-z][a-z\d+.-]*:/i.test(url) || url.indexOf('//') === 0;
|
|
27301
|
+
};
|
|
27302
|
+
AddActionRedirectDirective.prototype.restoreManagedAttribute = function (name, managed, originalValue) {
|
|
27303
|
+
if (!managed)
|
|
27304
|
+
return;
|
|
27305
|
+
if (originalValue === null) {
|
|
27306
|
+
this.renderer.removeAttribute(this.elementRef.nativeElement, name);
|
|
27307
|
+
}
|
|
27308
|
+
else {
|
|
27309
|
+
this.renderer.setAttribute(this.elementRef.nativeElement, name, originalValue);
|
|
27217
27310
|
}
|
|
27218
27311
|
};
|
|
27219
27312
|
AddActionRedirectDirective.prototype.getAccessibleLabel = function () {
|
|
@@ -27233,22 +27326,36 @@ var AddActionRedirectDirective = /** @class */ (function () {
|
|
|
27233
27326
|
return ((_k = (_j = this.banner) === null || _j === void 0 ? void 0 : _j.name) === null || _k === void 0 ? void 0 : _k.trim()) || 'Ver más';
|
|
27234
27327
|
};
|
|
27235
27328
|
AddActionRedirectDirective.prototype.isExternalUrl = function (url) {
|
|
27236
|
-
|
|
27237
|
-
if (!url)
|
|
27238
|
-
return false;
|
|
27239
|
-
if (url.startsWith('/') || url.startsWith('#'))
|
|
27329
|
+
if (!url || !this.isAbsoluteUrl(url))
|
|
27240
27330
|
return false;
|
|
27241
27331
|
try {
|
|
27242
|
-
var
|
|
27243
|
-
var target = new URL(url,
|
|
27244
|
-
if (
|
|
27332
|
+
var current = new URL(this.getDocumentHref());
|
|
27333
|
+
var target = new URL(url, current.href);
|
|
27334
|
+
if (target.origin !== current.origin)
|
|
27245
27335
|
return true;
|
|
27246
|
-
return target.
|
|
27336
|
+
return this.isOutsideBaseHref(target.pathname, current);
|
|
27247
27337
|
}
|
|
27248
27338
|
catch (e) {
|
|
27249
27339
|
return true;
|
|
27250
27340
|
}
|
|
27251
27341
|
};
|
|
27342
|
+
AddActionRedirectDirective.prototype.isOutsideBaseHref = function (pathname, current) {
|
|
27343
|
+
var baseHref = this.locationStrategy.getBaseHref();
|
|
27344
|
+
if (!baseHref)
|
|
27345
|
+
return false;
|
|
27346
|
+
try {
|
|
27347
|
+
var base = new URL(baseHref, current.href);
|
|
27348
|
+
if (base.origin !== current.origin)
|
|
27349
|
+
return false;
|
|
27350
|
+
var basePath = base.pathname.replace(/\/index\.html$/i, '').replace(/\/+$/, '');
|
|
27351
|
+
if (!basePath || basePath === '/')
|
|
27352
|
+
return false;
|
|
27353
|
+
return pathname !== basePath && pathname.indexOf(basePath + '/') !== 0;
|
|
27354
|
+
}
|
|
27355
|
+
catch (e) {
|
|
27356
|
+
return false;
|
|
27357
|
+
}
|
|
27358
|
+
};
|
|
27252
27359
|
AddActionRedirectDirective.prototype.ngOnDestroy = function () {
|
|
27253
27360
|
this.linstenEvent && this.linstenEvent();
|
|
27254
27361
|
};
|
|
@@ -27257,7 +27364,8 @@ var AddActionRedirectDirective = /** @class */ (function () {
|
|
|
27257
27364
|
{ type: ElementRef },
|
|
27258
27365
|
{ type: Renderer2 },
|
|
27259
27366
|
{ type: BlocksService },
|
|
27260
|
-
{ type: Router }
|
|
27367
|
+
{ type: Router },
|
|
27368
|
+
{ type: LocationStrategy }
|
|
27261
27369
|
]; };
|
|
27262
27370
|
__decorate$2a([
|
|
27263
27371
|
Input()
|