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

feat(lib): allow img attributes #111

Merged
merged 14 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Attribute object definition
  • Loading branch information
jamesatfish committed Oct 24, 2017
commit 7e75de8d0c64bb5e78c419809f0def508fa917f0
5 changes: 5 additions & 0 deletions dist/components/image-attribute.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare class ImageAttribute {
element: string;
value: string;
encapsulateWithBrackets: boolean;
}
10 changes: 10 additions & 0 deletions dist/components/image-attribute.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/components/image-attribute.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/components/image-attribute.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"__symbolic":"module","version":3,"metadata":{"ImageAttribute":{"__symbolic":"class"}}},{"__symbolic":"module","version":1,"metadata":{"ImageAttribute":{"__symbolic":"class"}}}]
3 changes: 2 additions & 1 deletion dist/components/img-loader.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ElementRef, Renderer, OnInit, EventEmitter } from '@angular/core';
import { ImageLoader } from '../providers/image-loader';
import { ImageLoaderConfig } from '../providers/image-loader-config';
import { ImageAttribute } from './image-attribute';
export declare class ImgLoader implements OnInit {
private _element;
private _renderer;
Expand Down Expand Up @@ -31,7 +32,7 @@ export declare class ImgLoader implements OnInit {
/**
* Attributes to pass through to img tag if _useImg == true
*/
imgAttributes: {};
imgAttributes: ImageAttribute[];
/**
* Convenience attribute to disable caching
* @param val
Expand Down
16 changes: 10 additions & 6 deletions dist/components/img-loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/components/img-loader.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/components/image-attribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class ImageAttribute {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an interface

element: string = "";
value: string = "";
encapsulateWithBrackets: boolean = false;
}
19 changes: 13 additions & 6 deletions src/components/img-loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Input, Output, ElementRef, Renderer, OnInit, EventEmitter } from '@angular/core';
import { ImageLoader } from '../providers/image-loader';
import { ImageLoaderConfig } from '../providers/image-loader-config';
import { ImageAttribute } from './image-attribute';

const propMap: any = {
display: 'display',
Expand Down Expand Up @@ -62,7 +63,7 @@ export class ImgLoader implements OnInit {
/**
* Attributes to pass through to img tag if _useImg == true
*/
@Input('imgAttributes') imgAttributes: {} = {};
@Input('imgAttributes') imgAttributes: ImageAttribute[] = [];

/**
* Convenience attribute to disable caching
Expand Down Expand Up @@ -204,12 +205,18 @@ export class ImgLoader implements OnInit {
this._renderer.setElementAttribute(this.element, 'src', imageUrl);

// if imgAttributes are defined, add them here
if (this.imgAttributes != '') {
if (this.imgAttributes.length > 0) {

this.imgAttributes.forEach((attribute) => {
var value = attribute.value;
var element = attribute.element;
if (attribute.encapsulateWithBrackets == true) {
element = '(' + element + ')';
}
this._renderer.setElementAttribute(this.element, element, value);

});

for (var key in this.imgAttributes) {
var value = this.imgAttributes[key];
this._renderer.setElementAttribute(this.element, key, value);
}
}


Expand Down