(el, binding, vnode)
| 126 | * @return |
| 127 | */ |
| 128 | add(el, binding, vnode) { |
| 129 | if (this.listeners.some((item) => item.el === el)) { |
| 130 | this.update(el, binding); |
| 131 | return nextTick(this.lazyLoadHandler); |
| 132 | } |
| 133 | |
| 134 | const value = this.valueFormatter(binding.value); |
| 135 | let { src } = value; |
| 136 | |
| 137 | nextTick(() => { |
| 138 | src = getBestSelectionFromSrcset(el, this.options.scale) || src; |
| 139 | this.observer && this.observer.observe(el); |
| 140 | |
| 141 | const container = Object.keys(binding.modifiers)[0]; |
| 142 | let $parent; |
| 143 | |
| 144 | if (container) { |
| 145 | $parent = vnode.context.$refs[container]; |
| 146 | // if there is container passed in, try ref first, then fallback to getElementById to support the original usage |
| 147 | $parent = $parent |
| 148 | ? $parent.$el || $parent |
| 149 | : document.getElementById(container); |
| 150 | } |
| 151 | |
| 152 | if (!$parent) { |
| 153 | $parent = getScrollParent(el); |
| 154 | } |
| 155 | |
| 156 | const newListener = new ReactiveListener({ |
| 157 | bindType: binding.arg, |
| 158 | $parent, |
| 159 | el, |
| 160 | src, |
| 161 | loading: value.loading, |
| 162 | error: value.error, |
| 163 | cors: value.cors, |
| 164 | elRenderer: this.elRenderer.bind(this), |
| 165 | options: this.options, |
| 166 | imageCache: this.imageCache, |
| 167 | }); |
| 168 | |
| 169 | this.listeners.push(newListener); |
| 170 | |
| 171 | if (inBrowser) { |
| 172 | this.addListenerTarget(window); |
| 173 | this.addListenerTarget($parent); |
| 174 | } |
| 175 | |
| 176 | this.lazyLoadHandler(); |
| 177 | nextTick(() => this.lazyLoadHandler()); |
| 178 | }); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * update image src |
no test coverage detected