Skip to content

Commit

Permalink
feat: Emit load event of mip-img (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
yenshih authored and craigchencc committed Dec 20, 2018
1 parent 27f731e commit fb52e2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/mip/src/components/mip-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/* eslint-disable no-new */

import util from '../util/index'
import {customEmit} from '../util/custom-event'
import CustomElement from '../custom-element'
import viewport from '../viewport'
import viewer from '../viewer'
Expand Down Expand Up @@ -316,6 +317,7 @@ class MipImg extends CustomElement {
// 标识资源已加载完成
this.resourcesComplete()
this.element.classList.add('mip-img-loaded')
customEmit(this.element, 'load')
}).catch(reason => {
/* istanbul ignore if */
if (!viewer.isIframed) {
Expand Down
3 changes: 3 additions & 0 deletions packages/mip/test/specs/components/mip-img.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import dom from 'src/util/dom/dom'
import {event} from 'src/util'

/* eslint-disable no-unused-expressions */
/* globals describe, before, it, expect, after, Event */
Expand Down Expand Up @@ -111,10 +112,12 @@ describe('mip-img', function () {
<mip-img src="https://www.mipengine.org/static/img/sample_01.jpg"></mip-img>
`
let mipImg = mipImgWrapper.querySelector('mip-img')
let loading = new Promise(resolve => event.listen(mipImg, 'load', resolve))
mipImg.viewportCallback(true)
let img = mipImg.querySelector('img')
expect(img.classList.contains('mip-replaced-content')).to.equal(true)
expect(img.getAttribute('src')).to.equal('https://www.mipengine.org/static/img/sample_01.jpg')
return loading
})

it('should change src and reload img', function () {
Expand Down

0 comments on commit fb52e2e

Please sign in to comment.