⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dropwatcherbehavior.js

📁 AJAX 应用 实现页面的无刷新
💻 JS
📖 第 1 页 / 共 3 页
字号:
            var nodeRect;
            var hitInsertNode = false;
            var e = this.get_element();
            for (var node = e.firstChild; node != null && !hitInsertNode; node = node.nextSibling) {
                
                if (!node.id) continue;
            
                nodeRect = $common.getBounds(node);
                
                if (dragVisualRect.y <= nodeRect.y) {                
                    break;
                }
                
                hitInsertNode = (node.id.lastIndexOf("Insert", node.id.length - 6) != -1);           
            }       
            dropOk = !hitInsertNode;
        }    
        return dropOk;
    },
    
    drop : function(dragMode, dataType, data) {
                
        AjaxControlToolkit.DragDropWatcher.callBaseMethod(this, 'drop',[dragMode,dataType,data]);
        var childId = data.id;
        if (!this._postbackCode || !childId) return;
    
        // figure out which child index we're moving to
        //
        var newIndex = this.findChild(this.get_element(), childId);
        Sys.Debug.assert(newIndex != -1, String.format(AjaxControlToolkit.Resources.ReorderList_DropWatcherBehavior_NoChild, childId));
        
        var oldIndex = this._getSavedChildIndex(childId);
        if (newIndex != -1 && newIndex != oldIndex) {            
            this._saveChildOrder();
            this.doPostBack(childId, newIndex, oldIndex);              
        }    
    }  ,
    
    _setupDropState : function(childId, newIndex, oldIndex) {
        if (childId) {
            var child = $get(childId);        
            this._inProgressDrops[childId] = {"oldCss": child.className, "newIndex":newIndex, "oldIndex":oldIndex};
            
            if (this._callbackCssStyle) {                 
                   child.className = this._callbackCssStyle;           
            }        
        }
    },
    
    _onDropCallback : function(childId) {
    
        if (childId) {
            
            this.set_ClientState("true");
            
            var item = this._inProgressDrops[childId];
            
            if (item) {
                var child = $get(childId);        
                if (this._callbackCssStyle) {                 
                   child.className = item.oldCss;           
                }    
                delete this._inProgressDrops[childId];
            }
            return item;
        }
    },

    
    doPostBack : function(childId, newIndex, oldIndex) {
        
            var item = this._inProgressDrops[childId];
            
            if (item) {
                // don't allow recursive drops.                
                return;
            }
        
            // setup the postback string
            //
            var postbackArg = "reorder:" + childId + ":" + oldIndex.toString() + ":" + newIndex.toString();       
            
            // replace the specified replace string with the arg and build the full postback string
            //            
            var postbackCode = this._postbackCode.replace(this._argReplaceString, postbackArg);            
            
            if (this._argSuccessString) {
                postbackCode = postbackCode.replace(this._argSuccessString, "callbackSuccessStub");
            }
            if (this._argErrorString) {
                postbackCode = postbackCode.replace(this._argErrorString, "callbackErrorStub");
            }
            if (this._argContextString) {
                postbackCode = postbackCode.replace(this._argContextString, this.get_id() + ":" + childId);
            }
            
            this._setupDropState(childId, newIndex, oldIndex);
                                
            window.setTimeout(postbackCode, 0);                    
    } ,
    
    _onCallbackSuccess : function(response, context) {
    
        if (response && response.length > 0) {
            this._onCallbackError(response, context);
        }
        else {    
            this._onDropCallback(context);            
            this.raiseReorderComplete();
        }
        
    },
    
    _onCallbackError : function(response, context) {
    
        var item = this._onDropCallback(context);
        
        // undo the move
        //        
        if (item.oldIndex || item.newIndex) {
            this._saveChildOrder();
            this.doReorder(item.newIndex, item.oldIndex, true);                                    
        }        
        
        alert(String.format(AjaxControlToolkit.Resources.ReorderList_DropWatcherBehavior_CallbackError, response));
    },
    
    doReorder : function(oldIndex, newIndex, skipPostback) {   
        var e = this.get_element();   
        var children = this._childList;  
        if (oldIndex >= 0 && children.length > oldIndex && oldIndex != newIndex) {
        
            
        
            var child = $get(children[oldIndex]);
            
            var item = this._inProgressDrops[child.id];
            
            if (item) {
                // don't allow recursive drops.                
                return;
            }           
            
            if (child) {
            
                if (newIndex > oldIndex) {
                    // if the destination element is after the source element
                    // we can't insert after, we need to insert after.  
                    // so we increment the newIndex.
                    // 
                    // 
                    newIndex++;
                }
                                
                var append = newIndex >= children.length;
                
                try {
                   e.removeChild(child);
                }
                catch(e) {
                    // Safari likes to throw NOT_FOUND_ERR (DOMException 8)
                    // but it seems to work fine anyway.
                    //
                }               
                
                if (append) {
                    e.appendChild(child);
                }
                else {                
                    var childAtNewIndex = $get(children[newIndex]);                                                   
                    e.insertBefore(child, childAtNewIndex);                            
                }
                if (!skipPostback) {                 
                    this.doPostBack(child.id, newIndex, oldIndex);
                }
                else {
                    this._saveChildOrder();
                    this.raiseReorderComplete();
                }
            }
        }
    }  , 
    
    getItem : function(index) {
        
        if (!this._childList) {
            this._saveChildOrder();
        }
    
        return this._childList[index];
    },
    
    _getSavedChildIndex : function(childId) {
        if (this._childList && childId) {            
            for (var i = 0; i < this._childList.length; i++) {
                if (childId == this._childList[i]) {            
                    return i;
                }
            }
        }
        return -1;
    },
    
    _saveChildOrder : function() {
        var e = this.get_element();
        if (!e) return;
        var children = e.childNodes;
        this._childList = [];
        var childCount = 0;
       
        for (var i = 0; i < children.length; i++) {
            // note Safari is returning all children, not just direct ones
            //
            if (children[i] && children[i].parentNode === e && children[i].tagName && children[i].tagName.toLowerCase() == "li") {
                this._childList[childCount++] = children[i].id;                
            }
        }        
    },
    
    
    get_argReplaceString : function() {
        return this._argReplaceString;
    },
    
    set_argReplaceString : function(value) {             
        if (this._argReplaceString != value) {
           this._argReplaceString = value;        
           this.raisePropertyChanged('argReplaceString');
        }
    },
    
    get_argContextString : function() {
        return this._argContextString;
    },
    
    set_argContextString : function(value) {             
        if (this._argContextString != value) {
            this._argContextString = value;        
            this.raisePropertyChanged('argContextString');
        }
    },
    
    get_argErrorString : function() {
        return this._argErrorString;
    },
    
    set_argErrorString : function(value) {             
        if (this._argErrorString != value) {
            this._argErrorString = value;        
            this.raisePropertyChanged('argErrorString');
        }
    },
    
    get_argSuccessString : function() {
        return this._argSuccessString;
    },
    
    set_argSuccessString : function(value) {             
        if (this._argSuccessString != value) {
            this._argSuccessString = value;        
            this.raisePropertyChanged('argSuccessString');
        }
    },
    
    get_postbackCode : function() {
        return this._postbackCode;
    },
    
    set_postbackCode : function(value) {             
        if (this._postbackCode != value) {
            this._postbackCode = value;        
            this.raisePropertyChanged('postbackCode');
        }
    },
    
    get_callbackCssStyle : function() {
        return this._callbackCssStyle;
    },
    
    set_callbackCssStyle : function(value) { 
        if (this._callbackCssStyle != value) {             
            this._callbackCssStyle = value;        
            this.raisePropertyChanged('callbackCssStyle');
        }
    }
     
    
}
AjaxControlToolkit.DragDropWatcher.registerClass('AjaxControlToolkit.DragDropWatcher', AjaxControlToolkit.DragDropList);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -