MCPcopy Index your code
hub / github.com/microsoft/SandDance / setElement

Method setElement

docs/app/js/sanddance-app.js:92290–92341  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

92288 return this.element;
92289 }
92290 setElement(element) {
92291 if (this.element) // unregister all events
92292 this.destroy();
92293 this.element = element;
92294 if (!element) return;
92295 const { options } = this;
92296 const ManagerClass = options.Manager;
92297 this.manager = new ManagerClass(element, {
92298 touchAction: options.touchAction,
92299 recognizers: options.recognizers || (0, _constants.RECOGNIZERS)
92300 }).on("hammer.input", this._onBasicInput);
92301 if (!options.recognizers) // Set default recognize withs
92302 // http://hammerjs.github.io/recognize-with/
92303 Object.keys((0, _constants.RECOGNIZER_COMPATIBLE_MAP)).forEach((name)=>{
92304 const recognizer = this.manager.get(name);
92305 if (recognizer) (0, _constants.RECOGNIZER_COMPATIBLE_MAP)[name].forEach((otherName)=>{
92306 recognizer.recognizeWith(otherName);
92307 });
92308 });
92309 // Set recognizer options
92310 for(const recognizerName in options.recognizerOptions){
92311 const recognizer = this.manager.get(recognizerName);
92312 if (recognizer) {
92313 const recognizerOption = options.recognizerOptions[recognizerName];
92314 // `enable` is managed by the event registrations
92315 delete recognizerOption.enable;
92316 recognizer.set(recognizerOption);
92317 }
92318 }
92319 // Handle events not handled by Hammer.js:
92320 // - mouse wheel
92321 // - pointer/touch/mouse move
92322 this.wheelInput = new (0, _wheelInputDefault.default)(element, this._onOtherEvent, {
92323 enable: false
92324 });
92325 this.moveInput = new (0, _moveInputDefault.default)(element, this._onOtherEvent, {
92326 enable: false
92327 });
92328 this.keyInput = new (0, _keyInputDefault.default)(element, this._onOtherEvent, {
92329 enable: false,
92330 tabIndex: options.tabIndex
92331 });
92332 this.contextmenuInput = new (0, _contextmenuInputDefault.default)(element, this._onOtherEvent, {
92333 enable: false
92334 });
92335 // Register all existing events
92336 for (const [eventAlias, eventRegistrar] of this.events)if (!eventRegistrar.isEmpty()) {
92337 // Enable recognizer for this event.
92338 this._toggleRecognizer(eventRegistrar.recognizerName, true);
92339 this.manager.on(eventAlias, eventRegistrar.handleEvent);
92340 }
92341 }
92342 // Tear down internal event management implementations.
92343 destroy() {
92344 if (this.element) {

Callers 1

constructorMethod · 0.95

Calls 7

destroyMethod · 0.95
_toggleRecognizerMethod · 0.95
onMethod · 0.45
forEachMethod · 0.45
getMethod · 0.45
setMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected