Skip to content

Commit afa2047

Browse files
authored
Fixed responsive with lazy on Firefox (#255)
1 parent 3f55bf6 commit afa2047

5 files changed

Lines changed: 40 additions & 7 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@
3434
"@types/jasmine": "~2.8.6",
3535
"@types/jasminewd2": "~2.0.3",
3636
"@types/node": "~8.9.4",
37+
"cloudinary-core": "^2.8.1",
3738
"codelyzer": "~4.2.1",
38-
"cloudinary-core": "^2.8.0",
3939
"jasmine-core": "~2.99.1",
4040
"jasmine-spec-reporter": "~4.2.1",
4141
"karma": "~1.7.1",
4242
"karma-chrome-launcher": "~2.2.0",
4343
"karma-coverage-istanbul-reporter": "~2.0.0",
44+
"karma-firefox-launcher": "^1.3.0",
4445
"karma-jasmine": "~1.1.1",
4546
"karma-jasmine-html-reporter": "^0.2.2",
4647
"ng-packagr": "^3.0.0-rc.2",

projects/angular-cld/karma.conf.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = function (config) {
1010
require('karma-chrome-launcher'),
1111
require('karma-jasmine-html-reporter'),
1212
require('karma-coverage-istanbul-reporter'),
13-
require('@angular-devkit/build-angular/plugins/karma')
13+
require('@angular-devkit/build-angular/plugins/karma'),
14+
require('karma-firefox-launcher')
1415
],
1516
client: {
1617
clearContext: false // leave Jasmine Spec Runner output visible in browser
@@ -25,7 +26,7 @@ module.exports = function (config) {
2526
colors: true,
2627
logLevel: config.LOG_INFO,
2728
autoWatch: true,
28-
browsers: ['Chrome'],
29+
browsers: ['Chrome', 'Firefox'],
2930
singleRun: true
3031
});
3132
};

projects/angular-cld/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@angular/core": "^6.0.0"
77
},
88
"devDependencies": {
9-
"cloudinary-core": "^2.8.0",
9+
"cloudinary-core": "^2.8.1",
1010
"typescript": "^2.9.2"
1111
}
1212
}

projects/angular-cld/src/lib/cloudinary-image.component.spec.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,8 @@ describe('CloudinaryImage', () => {
824824
tick();
825825
fixture.detectChanges();
826826
const img = des[0].children[0].nativeElement as HTMLImageElement;
827-
expect(img.attributes.getNamedItem('src').value).toEqual(jasmine.stringMatching('image/upload/c_fit,w_30/ar_1,b_auto,' +
828-
'c_pad,w_iw_div_2/c_crop,g_north_east,h_10,w_10/c_fill,h_ih,w_iw/f_auto,q_auto/bear'));
827+
expect(img.attributes.getNamedItem('src').value).toEqual('http://res.cloudinary.com/' +
828+
'@@fake_angular2_sdk@@/image/upload/c_fit,w_30/ar_1,b_auto,c_pad,w_iw_div_2/c_crop,g_north_east,h_10,w_10/c_fill,h_ih,w_iw/f_auto,q_auto/bear');
829829
}));
830830
});
831831
describe('placeholder type vectorize', () => {
@@ -947,4 +947,35 @@ describe('CloudinaryImage', () => {
947947
expect(img.attributes.getNamedItem('src').value).toEqual(jasmine.stringMatching('e_sepia/e_grayscale,l_sample/e_tint:75:black/bear'));
948948
}));
949949
});
950+
describe('cl-image with responsive and lazy-load', async () => {
951+
@Component({
952+
template: `<cl-image loading="lazy" width="300" public-id="bear"></cl-image>`
953+
})
954+
class TestComponent {}
955+
956+
let fixture: ComponentFixture<TestComponent>;
957+
let des: DebugElement[]; // the elements w/ the directive
958+
let placeholder: DebugElement[];
959+
let testLocalCloudinary: Cloudinary = new Cloudinary(require('cloudinary-core'),
960+
{ cloud_name: '@@fake_angular2_sdk@@', client_hints: true } as CloudinaryConfiguration);
961+
beforeEach(fakeAsync(() => {
962+
fixture = TestBed.configureTestingModule({
963+
declarations: [CloudinaryTransformationDirective, CloudinaryImage, TestComponent, LazyLoadDirective],
964+
providers: [{ provide: Cloudinary, useValue: testLocalCloudinary }]
965+
}).createComponent(TestComponent);
966+
967+
fixture.detectChanges(); // initial binding
968+
// all elements with an attached CloudinaryImage
969+
des = fixture.debugElement.queryAll(By.directive(CloudinaryImage));
970+
tick();
971+
fixture.detectChanges();
972+
}));
973+
it('src should not exist on Firefox', () => {
974+
const img = des[0].children[0].nativeElement as HTMLImageElement;
975+
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
976+
expect(img).not.toContain('src');
977+
}
978+
});
979+
});
950980
});
981+

projects/angular-cld/src/lib/cloudinary-placeholder.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class CloudinaryPlaceHolder implements AfterContentChecked {
4343
if (this.type === 'predominant-color' && this.itemHeight && this.itemWidth) {
4444
return this.cloudinary.url(this.publicId, {transformation: [this.options, ...predominantColorTransformPxl]});
4545
} else {
46-
return this.cloudinary.url(this.publicId, {transformation: [this.options, ...placeholderImageOptions[this.type] || placeholderImageOptions['blur']]})
46+
return this.cloudinary.url(this.publicId, {transformation: [this.options, ...placeholderImageOptions[this.type] || placeholderImageOptions['blur']]});
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)