Skip to content

Commit

Permalink
feat: Refactored structure, making use of @angular/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
flauc committed Jan 5, 2019
1 parent b23e460 commit 7fbb810
Show file tree
Hide file tree
Showing 54 changed files with 13,787 additions and 5,299 deletions.
107 changes: 107 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
version: 2

job_defaults: &job_defaults
docker:
- image: circleci/node:latest
working_directory: ~/project/repo

cache_key: &cache_key ng-image-preload-deps-cache-{{ .Branch }}-{{ checksum "package-lock.json" }}
dist_key: &dist_key ng-image-preload-dist-{{ .Revision }}

jobs:
install:
<<: *job_defaults
steps:
- checkout
- restore_cache:
key: *cache_key
- run:
name: install-dependencies
command: npm ci
- save_cache:
key: *cache_key
paths:
- node_modules

lint:
<<: *job_defaults
steps:
- checkout
- restore_cache:
key: *cache_key
- run:
name: lint
command: npm run lint

test-lib:
<<: *job_defaults
steps:
- checkout
- restore_cache:
key: *cache_key
- run:
name: test
command: npm run test

build-lib:
<<: *job_defaults
steps:
- checkout
- restore_cache:
key: *cache_key
- run:
name: test
command: npm run build
- save_cache:
key: *dist_key
paths:
- dist

test-app:
<<: *job_defaults
steps:
- checkout
- restore_cache:
key: *cache_key
- restore_cache:
key: *dist_key
- run:
name: test
command: npm run test:app

release:
<<: *job_defaults
steps:
- checkout
- restore_cache:
key: *cache_key
- restore_cache:
key: *dist_key
- run:
name: release
command: npm run semantic-release || true

workflows:
version: 2
build-release:
jobs:
- install
- lint:
requires:
- install
- test-lib:
requires:
- install
- build-lib:
requires:
- lint
- test-lib
- test-app:
requires:
- build-lib
- release:
requires:
- test-app
filters:
branches:
only: master
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
59 changes: 35 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
# Node
node_modules/*
npm-debug.log
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# TypeScript
src/*.js
src/*.map
src/*.d.ts
# dependencies
/node_modules

# JetBrains
.idea
# profiling files
chrome-profiler-events.json
speed-measure-plugin.json

# IDEs and editors
/.idea
.project
.settings
.idea/*
*.iml
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# VS Code
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Windows
Thumbs.db
Desktop.ini
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# Mac
# System Files
.DS_Store
**/.DS_Store

# Ngc generated files
**/*.ngfactory.ts

# Build files
dist/*
Thumbs.db
34 changes: 0 additions & 34 deletions .npmignore

This file was deleted.

10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .yo-rc.json

This file was deleted.

10 changes: 5 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Jaspero team
Copyright (c) 2019 Jaspero Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 21 additions & 17 deletions README.MD → README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
[![Build Status](https://travis-ci.org/Jaspero/ng-image-preload.svg?branch=master)](https://travis-ci.org/jaspero/ng-image-preload)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![CircleCI](https://circleci.com/gh/Jaspero/ng-slider/tree/master.svg?style=svg)](https://circleci.com/gh/Jaspero/ng-image/preload/tree/master)
[![NPM Version](https://img.shields.io/npm/v/@jaspero/ng-image-preload.svg)](https://www.npmjs.com/package/@jaspero/ng-image-preload)

# NG Image Preload

An image preload module for Angular using [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) in favour of scroll listener's.

```
npm install --save @jaspero/ng-image-preloader
```

## Setup
Import `JasperoImagePreloaderModule` in your `@NgModule`:

Import `JpImagePreloaderModule` in your `@NgModule`:

```ts
@NgModule({
imports: [
JasperoImagePreloaderModule.forRoot();
JpImagePreloaderModule.forRoot();
],
declarations: [AppComponent],
bootstrap: [AppComponent]
Expand All @@ -26,32 +29,32 @@ Then in your component initialize the service:

```ts
class AppComponent implements OnInit {
constructor(
private _preload: PreloadService
) {}
constructor(private _preload: PreloadService) {}

ngOnInit() {
this._preload.initialize();
}
ngOnInit() {
this._preload.initialize();
}
}
```

The `initialize` method accepts an optional `options` object:

### Options
|Name|Type|Default|
|---|---|---|
|rootMargin|string|0 50px|
|threshold|number|0.1|

| Name | Type | Default |
| ---------- | ------ | ------- |
| rootMargin | string | 0 50px |
| threshold | number | 0.1 |

A description for this options can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).

## How To Use

There are two ways to consume the library. Using the service or the directive.

### Service
Inject the `PreloadService` in to a component.

Inject the `PreloadService` in to a component.

```ts
constructor(
Expand All @@ -65,19 +68,20 @@ addImage(element: HTMLElement) {
```

### Directive

You can add the `jaspero-preload` directive to an `img` element like this:

```html
<img src="initialImage.jpg" jaspero-preload="someImage.jpg"></img>
<img src="initialImage.jpg" jp-preload="someImage.jpg"></img>
```

The `initialImage.jpg` will not be preloaded, this is usually a spinner or some other light image.
The `someImage.jpg` image will be shown when the element is in view.

If you need to preload a background image the `jaspero-preload` directive can be placed on any html element like this:
If you need to preload a background image the `jp-preload` directive can be placed on any html element like this:

```html
<div class="some-element" [loadBg]="true" jaspero-preload="someImage.jpg"></div>
<div class="some-element" jp-preload="someImage.jpg"></div>
```

To show an image initially you can add a css background-image to the class. This image will then be replaced when the element is in view.
Loading

0 comments on commit 7fbb810

Please sign in to comment.