1. #1
    Ext JS Premium Member
    Join Date
    Aug 2010
    Posts
    25
    Vote Rating
    0
    sntial is on a distinguished road

      0  

    Default override Ext.dd.Registry

    override Ext.dd.Registry


    I'm trying to override a few methods related to tree nodes and dragging. I don't have regular tree labels. They are HTML with images, etc.

    I have the following overrides working properly:

    Code:
    Ext.override(Ext.tree.TreeNodeUI, {
       onSelectedChange : function(state) {
          if (state){
             this.focus();
             this.addClass("x-tree-selected");
             // 20101120 MB - added this call to remove stale row selection colors
             this.onOut(null); 
          } else {
             //this.blur();
             this.removeClass("x-tree-selected");
          }
       }
    });
    
    Ext.override(Ext.tree.TreeDragZone, {
       onInitDrag : function(e) {
          var data = this.dragData;
          // 20101120 MB - removed next two calls - selection handled by controller
          //this.tree.getSelectionModel().select(data.node);
          //this.tree.eventModel.disable();
          this.proxy.update("");
          data.node.ui.appendDDGhost(this.proxy.ghost.dom);
          this.tree.fireEvent("startdrag", this.tree, data.node, e);
       }
    });
    I'd like to override Ext.dd.Registry.getHandleFromEvent as follows:

    Code:
    Ext.override(Ext.dd.Registry, {
       getHandleFromEvent : function(e) {
          var t = Ext.lib.Event.getTarget(e);
          // 20101120 MB - added this while loop to handle tree labels with html children instead of raw text
          while (!t.id && t.parentNode) {
             t = t.parentNode;
          }
          return t ? handles[t.id] : null;
       }
    });
    However, this does not take effect (working code below). I'm stuck with replacing the entire Ext.dd.Registry object. It seems like this object does not follow the standard Ext prototyping scheme. Am I missing something?

    Code:
    Ext.dd.Registry = function(){
        var elements = {}; 
        var handles = {}; 
        var autoIdSeed = 0;
    
        var getId = function(el, autogen){
            if(typeof el == "string"){
                return el;
            }
            var id = el.id;
            if(!id && autogen !== false){
                id = "extdd-" + (++autoIdSeed);
                el.id = id;
            }
            return id;
        };
        
        return {
        
            register : function(el, data){
                data = data || {};
                if(typeof el == "string"){
                    el = document.getElementById(el);
                }
                data.ddel = el;
                elements[getId(el)] = data;
                if(data.isHandle !== false){
                    handles[data.ddel.id] = data;
                }
                if(data.handles){
                    var hs = data.handles;
                    for(var i = 0, len = hs.length; i < len; i++){
                    	handles[getId(hs[i])] = data;
                    }
                }
            },
    
        
            unregister : function(el){
                var id = getId(el, false);
                var data = elements[id];
                if(data){
                    delete elements[id];
                    if(data.handles){
                        var hs = data.handles;
                        for(var i = 0, len = hs.length; i < len; i++){
                        	delete handles[getId(hs[i], false)];
                        }
                    }
                }
            },
    
        
            getHandle : function(id){
                if(typeof id != "string"){ 
                    id = id.id;
                }
                return handles[id];
            },
    
        
            getHandleFromEvent : function(e){
                var t = Ext.lib.Event.getTarget(e);
                // 20101120 MB - added this while loop to handle tree labels with html children instead of raw text
                while (!t.id && t.parentNode) {
                   t = t.parentNode;
                }
                return t ? handles[t.id] : null;
            },
    
        
            getTarget : function(id){
                if(typeof id != "string"){ 
                    id = id.id;
                }
                return elements[id];
            },
    
        
            getTargetFromEvent : function(e){
                var t = Ext.lib.Event.getTarget(e);
                return t ? elements[t.id] || handles[t.id] : null;
            }
        };
    }();

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    2
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    Yeah, you can't override a singleton using Ext.override, since there is no prototype to modify in this case. However, since Ext.dd.Registry is an instantiated object, you can simply override the method directly:

    PHP Code:
            Ext.dd.Registry.getHandleFromEvent = function(e){
                var 
    Ext.lib.Event.getTarget(e);
                
    // 20101120 MB - added this while loop to handle tree labels with html children instead of raw text
                
    while (!t.id && t.parentNode) {
                   
    t.parentNode;
                }
                return 
    handles[t.id] : null;
            }; 

  3. #3
    Ext JS Premium Member
    Join Date
    Aug 2010
    Posts
    25
    Vote Rating
    0
    sntial is on a distinguished road

      0  

    Default


    I have tried that already. The handles variable is undefined at runtime.

    this.handles and Ext.dd.Registry.handles does not work either.

    I'm thinking it's because the getHandleFromEvent method is in the return block instead of explicitly defined.

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    2
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    Ah sorry, didn't notice that. If you need access to anything declared privately in the singleton's scope you're going to have to redeclare the entire thing just as you did. Not much way around that.

  5. #5
    Ext JS Premium Member
    Join Date
    Aug 2010
    Posts
    25
    Vote Rating
    0
    sntial is on a distinguished road

      0  

    Default


    Oh, right. It all makes sense now.

    I guess it's just a little odd how this class was implemented (compared to the other ExtJs stuff I've overridden).

    Thanks for the explanation. That was driving me crazy.

  6. #6
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    2
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    It's implemented just like any other singleton. You'd run into the same type of issue overriding Ext.MessageBox, Ext.ComponentMgr, etc. if you needed access to their private scopes. If you just want to change the behavior and don't need to rely on anything in the private scope you can directly override methods on the singleton instance as I showed.

  7. #7
    Ext JS Premium Member
    Join Date
    Aug 2010
    Posts
    25
    Vote Rating
    0
    sntial is on a distinguished road

      0  

    Default


    Got it. Thanks.

Similar Threads

  1. Override override Ext.lib.Dom
    By armaghedon in forum Ext: Q&A
    Replies: 2
    Last Post: 1 Nov 2010, 8:25 AM
  2. override Ext.override
    By thaiat in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 13 May 2009, 6:40 AM
  3. [2.??] Ext.dd.Registry unregister bug
    By keith.chew in forum Ext 2.x: Bugs
    Replies: 1
    Last Post: 25 Jan 2009, 5:31 PM
  4. override Ext.override?
    By cboden in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 15 May 2008, 7:48 AM
  5. [1.1.1] Ext.dd.Registry.register/unregister broken
    By malraux in forum Ext 1.x: Bugs
    Replies: 2
    Last Post: 5 Nov 2007, 8:07 PM

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi