* 条件分支 * * 与 end() 配对使用。 * 条件为 true 时执行 when...end 之间的操作,否则跳过。 * * 支持两种用法: * 1. when(selector, result?) - 检查 DOM 元素是否存在(result=false 时检查不存在) * 2. when(fn, ...args) - 执行函数,检查返回值是否为 true * * @param {string|Function} selectorOrFn - CSS 选择器或判断函数 * @param {boolean} [result]
(...args)
| 192 | * @returns {ZBrowserClient} this |
| 193 | */ |
| 194 | when(...args) { |
| 195 | if (typeof args[0] === 'string') { |
| 196 | const checkNotExists = args[1] === false |
| 197 | this._queue.push({ |
| 198 | method: 'when', |
| 199 | args: [ |
| 200 | jsCodeTemplate( |
| 201 | (selector, checkNotExists) => { |
| 202 | const exists = !!document.querySelector(selector) |
| 203 | return checkNotExists ? !exists : exists |
| 204 | }, |
| 205 | [args[0], checkNotExists] |
| 206 | ) |
| 207 | ] |
| 208 | }) |
| 209 | return this |
| 210 | } |
| 211 | |
| 212 | if (typeof args[0] === 'function') { |
| 213 | const fn = args.shift() |
| 214 | this._queue.push({ |
| 215 | method: 'when', |
| 216 | args: [jsCodeTemplate(fn, args)] |
| 217 | }) |
| 218 | return this |
| 219 | } |
| 220 | |
| 221 | throw new Error('when: parameter error') |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * 模拟鼠标事件(选择器模式 - JS 事件分发) |
nothing calls this directly
no test coverage detected