(options, pos = true)
| 138 | } |
| 139 | |
| 140 | setOptions(options, pos = true) { |
| 141 | const defaults = { |
| 142 | offset: '0 0', |
| 143 | targetOffset: '0 0', |
| 144 | targetAttachment: 'auto auto', |
| 145 | classPrefix: 'tether', |
| 146 | bodyElement: document.body |
| 147 | }; |
| 148 | |
| 149 | this.options = extend(defaults, options); |
| 150 | |
| 151 | let { element, target, targetModifier, bodyElement } = this.options; |
| 152 | this.element = element; |
| 153 | this.target = target; |
| 154 | this.targetModifier = targetModifier; |
| 155 | |
| 156 | if (typeof bodyElement === 'string') { |
| 157 | bodyElement = document.querySelector(bodyElement); |
| 158 | } |
| 159 | this.bodyElement = bodyElement; |
| 160 | |
| 161 | if (this.target === 'viewport') { |
| 162 | this.target = document.body; |
| 163 | this.targetModifier = 'visible'; |
| 164 | } else if (this.target === 'scroll-handle') { |
| 165 | this.target = document.body; |
| 166 | this.targetModifier = 'scroll-handle'; |
| 167 | } |
| 168 | |
| 169 | ['element', 'target'].forEach((key) => { |
| 170 | if (isUndefined(this[key])) { |
| 171 | throw new Error( |
| 172 | 'Tether Error: Both element and target must be defined' |
| 173 | ); |
| 174 | } |
| 175 | |
| 176 | if (!isUndefined(this[key].jquery)) { |
| 177 | this[key] = this[key][0]; |
| 178 | } else if (isString(this[key])) { |
| 179 | this[key] = document.querySelector(this[key]); |
| 180 | } |
| 181 | }); |
| 182 | |
| 183 | this._addClasses(); |
| 184 | |
| 185 | if (!this.options.attachment) { |
| 186 | throw new Error('Tether Error: You must provide an attachment'); |
| 187 | } |
| 188 | |
| 189 | this.targetAttachment = parseTopLeft(this.options.targetAttachment); |
| 190 | this.attachment = parseTopLeft(this.options.attachment); |
| 191 | this.offset = parseTopLeft(this.options.offset); |
| 192 | this.targetOffset = parseTopLeft(this.options.targetOffset); |
| 193 | |
| 194 | if (!isUndefined(this.scrollParents)) { |
| 195 | this.disable(); |
| 196 | } |
| 197 |
no test coverage detected