Call son's element method from the listener of the parent document

27 views
Skip to first unread message

Gonzalo Tirapegui

unread,
May 10, 2016, 8:55:12 PM5/10/16
to Polymer
Hi! i'm trying to rewrite the source of this drag and drop component from the 0.5 to 1.0 version of Polymer . In the domReady method a listener function is attached to the parent document object to be triggered on the mousedown event , and in the lines 769 and 772 the "focus" and "blur" functions of the drag-resize component are called . Now , if i try to add the event listener by the listen function i get the error "Uncaught TypeError : Invalid value used as weak map key" , and if i try this code :

this.ownerDocument.addEventListener('mousedown', function(event){
        var element = event.srcElement || event.target;
        var filteredElements = element.classList.contains('drag-resize') || element.classList.contains('drag-resize-handlers') || element.getAttribute('drag-resizen') !== null;
        if(!element.classList.contains('drag-resize')){
          if(filteredElements){
            this.focus(element);
          }
          else {
            this.blur(true);
          }          
        }
      });

  the "this" operator on the call to the focus and the blur function executes the parent document functions , not the drag-resize focus and blur methods , and as you can see the drag-resize element on the 0.5 version it execute it's own focus and blur method. So , how can this can be done on Polymer 1.0?

Gonzalo Tirapegui

unread,
May 11, 2016, 8:02:31 AM5/11/16
to Polymer
Hi , i did the trick by changing "this" to document.querySelector('drag-resizen').focus(element); , but i'm not sure if its the best practice . I would like to see some opinions about the implementation , Thanks!
Reply all
Reply to author
Forward
0 new messages