|
17 | 17 | * the cursor follow the x and the y-position of the mouse. Use `false` to make the
|
18 | 18 | * it only follow the x-position of the mouse.
|
19 | 19 | * @property {function} formatTimeCallback Formats the timestamp on the cursor.
|
| 20 | + * @property {boolean} isDestroyCalled true if called destroy before the ready event fired |
20 | 21 | */
|
21 | 22 |
|
22 | 23 | /**
|
@@ -140,11 +141,19 @@ export default class CursorPlugin {
|
140 | 141 | * @type {?HTMLElement}
|
141 | 142 | */
|
142 | 143 | this.displayTime = null;
|
| 144 | + /** |
| 145 | + * true if call destory before ready event |
| 146 | + * @type {boolean} |
| 147 | + */ |
| 148 | + this.isDestroyCalled = false; |
143 | 149 |
|
144 | 150 | this.params = Object.assign({}, this.defaultParams, params);
|
145 | 151 | }
|
146 | 152 |
|
147 | 153 | _onReady() {
|
| 154 | + if (this.isDestroyCalled) { |
| 155 | + return; |
| 156 | + } |
148 | 157 | this.wrapper = this.wavesurfer.drawer.wrapper;
|
149 | 158 | this.cursor = this.util.withOrientation(this.wrapper.appendChild(
|
150 | 159 | document.createElement('cursor'),
|
@@ -237,10 +246,14 @@ export default class CursorPlugin {
|
237 | 246 | * Destroy the plugin (used by the Plugin API)
|
238 | 247 | */
|
239 | 248 | destroy() {
|
| 249 | + if (!this.cursorTime || !this.showTime){ |
| 250 | + this.isDestroyCalled = true; |
| 251 | + return; |
| 252 | + } |
240 | 253 | if (this.params.showTime) {
|
241 |
| - this.showTime.remove(); |
| 254 | + this.showTime && this.showTime.remove(); |
242 | 255 | }
|
243 |
| - this.cursor.remove(); |
| 256 | + this.cursor && this.cursor.remove(); |
244 | 257 | this.wrapper.removeEventListener('mousemove', this._onMousemove);
|
245 | 258 | if (this.params.hideOnBlur) {
|
246 | 259 | this.wrapper.removeEventListener('mouseenter', this._onMouseenter);
|
@@ -323,7 +336,6 @@ export default class CursorPlugin {
|
323 | 336 | */
|
324 | 337 | formatTime(cursorTime) {
|
325 | 338 | cursorTime = isNaN(cursorTime) ? 0 : cursorTime;
|
326 |
| - |
327 | 339 | if (this.params.formatTimeCallback) {
|
328 | 340 | return this.params.formatTimeCallback(cursorTime);
|
329 | 341 | }
|
|
0 commit comments