Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Feat: copyUrl 添加 window.location.href 为默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Mar 18, 2021
1 parent 16bf5ec commit b5da5ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
'xmlLink': 'https://img-xxxxxxxxxx.cos.ap-chengdu.myqcloud.com',
'prependTo': '.cos-album',
'viewNum': 8,
'copyUrl': 'https://img.lruihao.cn'
'copyUrl': '//img.lruihao.cn'
});
</script>
```

## Params
| param | type | description |
| :-------- | :----- | :--------------------------------- |
| xmlLink | String | 需要解析的騰訊云COS桶XML鏈接 |
| prependTo | String | 可選解析相冊到某個節點,默認: 'body' |
| viewNum | Number | 每個相冊顯示的照片數目,默認: 4 |
| copyUrl | String | CDN 链接,雙擊複製 URL Since: 1.1.6 |
| imgType | String | 图片類型 Since: 1.1.6 |
| videoType | String | 視頻類型 Since: 1.1.6 |
| param | type | default | description |
| :-------- | :----- | :------ | :-------------------------------- |
| xmlLink | String | | 需要解析的騰訊云COS桶XML鏈接 |
| prependTo | String | 'body' | 可選解析相冊到某個節點 |
| viewNum | Number | 4 | 每個相冊顯示的照片數目 |
| copyUrl | String | href | CDN 链接,雙擊複製 URL Since: 1.1.6 |
| imgType | String | ['jpg', 'jpeg', 'png', 'gif', 'svg'] | 图片類型 Since: 1.1.6 |
| videoType | String | ['mp4', 'mp3', 'avi', 'mov', 'qt'] | 視頻類型 Since: 1.1.6 |

> [**详细说明**](https://lruihao.cn/posts/cos-album.html)
9 changes: 5 additions & 4 deletions public/js/cos-album.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ Cosalbum = function Cosalbum() {
$photoBox.className = 'photoBox';
$cosAlbumEle.appendChild($photoBox);
for (let j = 1; j < content[i].length && j <= cosAlbum.viewNum; j++) {
let url = content[i][j].url;
let $photo = document.createElement('div');
let $desc = document.createElement('span');
let $upDate = document.createElement('span');
let $media;
$photo.className = 'photo';
let contentDetail = content[i][j].url.split('.');
let contentDetail = url.split('.');
if (cosAlbum.imgType.includes(contentDetail[1])) {
$media = document.createElement('img');
$media.setAttribute('alt', content[i][j].url);
Expand All @@ -56,9 +57,9 @@ Cosalbum = function Cosalbum() {
} else {
continue;
}
$media.setAttribute('src', `${cosAlbum.xmlLink}/${titleContent}/${content[i][j].url}`);
$media.setAttribute('src', `${cosAlbum.xmlLink}/${titleContent}/${url}`);
if (cosAlbum.copyUrl) {
_addCopyListener($media, `${cosAlbum.copyUrl}/${titleContent}/${content[i][j].url}`, cosAlbum);
_addCopyListener($media, `${cosAlbum.copyUrl}/${titleContent}/${url}`, cosAlbum);
}
$desc.innerHTML = $desc.title = contentDetail[0];
$upDate.innerHTML = _timeSince(content[i][j].date);
Expand Down Expand Up @@ -317,7 +318,7 @@ Cosalbum = function Cosalbum() {
this.xmlLink = this.option.xmlLink || '';
this.prependTo = this.option.prependTo || 'body';
this.viewNum = this.option.viewNum || 4;
this.copyUrl = this.option.copyUrl || '';
this.copyUrl = this.option.copyUrl || window.location.href;
this.imgType = _str2Array(this.option.imgType) || ['jpg', 'jpeg', 'png', 'gif', 'svg'];
this.videoType = _str2Array(this.option.videoType) || ['mp4', 'mp3', 'avi', 'mov', 'qt'];
if (this.copyUrl) {
Expand Down
20 changes: 10 additions & 10 deletions public/js/cos-album.min.js

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

0 comments on commit b5da5ad

Please sign in to comment.