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

📄 listsearchbehavior.js

📁 AJAX 应用 实现页面的无刷新
💻 JS
📖 第 1 页 / 共 3 页
字号:
            var compareResult = this._compareStrings(value, option);
            if (compareResult > 0) {
                left = mid+1
            } else if(compareResult < 0) {
                right = mid-1;
            } else {
                // We've found a match, but it might not be the first -- do a linear search backwards
                while(mid > 0 && options[mid - 1].text.toLowerCase().startsWith(value)) {
                    mid--;
                }
                return mid;
            }
        }
        return -1;
    },
    
    _doLinearSearch : function(options, value, left, right) {
        /// <summary>
        /// Does a linear search for a value in the Select's options
        /// </summary>
        /// <param name="options" type="Object">
        /// The collection of options in the Select
        /// </param>
        /// <param name="value" type="String">
        /// The value being searched for
        /// </param>
        /// <param name="left" type="Int">
        /// The left bounds of the search
        /// </param>
        /// <param name="right" type="Right">
        /// The right bounds of the search
        /// </param>
        
        if (this._queryPattern == AjaxControlToolkit.ListSearchQueryPattern.Contains) {
            for(var i = left; i <= right; i++) {
                if(options[i].text.toLowerCase().indexOf(value) >= 0) {
                    return i;
                }
            }
        } else if (this._queryPattern == AjaxControlToolkit.ListSearchQueryPattern.StartsWith) {
            for(var i = left; i <= right; i++) {
                if(options[i].text.toLowerCase().startsWith(value)) {
                    return i;
                }
            }
        }

        return -1;
    },
    
    _onTimerTick : function() {
        /// <summary>
        /// On timer tick since user is not responsive, so reset search text if no match is found.
        /// </summary>    
        this._stopTimer();
      
        // reset search text only if no match was found        
        if (!this._matchFound) {
            this._searchText = '';
            this._updatePromptDiv();
        }
    },
    
    _startTimer : function() {
        /// <summary>
        /// Starts timer to monitor user interaction only if greater than zero.
        /// </summary>     
        if (this._queryTimeout > 0) {
            this._timer = window.setTimeout(Function.createDelegate(this, this._onTimerTick), this._queryTimeout);
        }
    },

    _stopTimer : function() {
        /// <summary>
        /// Stops and clears previously created timer.
        /// </summary>     
        if(this._timer != null) {
            window.clearTimeout(this._timer);
        }
        this._timer = null;
    },
    
    get_onShow : function() {
        /// <value type="String" mayBeNull="true">
        /// Generic OnShow Animation's JSON definition
        /// </value>
        return this._popupBehavior ? this._popupBehavior.get_onShow() : this._onShowJson;
    },
    set_onShow : function(value) {
        if (this._popupBehavior) {
            this._popupBehavior.set_onShow(value)
        } else {
            this._onShowJson = value;
        }
        this.raisePropertyChanged('onShow');
    },
    get_onShowBehavior : function() {
        /// <value type="AjaxControlToolkit.Animation.GenericAnimationBehavior">
        /// Generic OnShow Animation's behavior
        /// </value>
        return this._popupBehavior ? this._popupBehavior.get_onShowBehavior() : null;
    },
    onShow : function() {
        /// <summary>
        /// Play the OnShow animation
        /// </summary>
        /// <returns />
        if (this._popupBehavior) {
            this._popupBehavior.onShow();
        }
    },
    
    get_onHide : function() {
        /// <value type="String" mayBeNull="true">
        /// Generic OnHide Animation's JSON definition
        /// </value>
        return this._popupBehavior ? this._popupBehavior.get_onHide() : this._onHideJson;
    },
    set_onHide : function(value) {
        if (this._popupBehavior) {
            this._popupBehavior.set_onHide(value)
        } else {
            this._onHideJson = value;
        }
        this.raisePropertyChanged('onHide');
    },
    get_onHideBehavior : function() {
        /// <value type="AjaxControlToolkit.Animation.GenericAnimationBehavior">
        /// Generic OnHide Animation's behavior
        /// </value>
        return this._popupBehavior ? this._popupBehavior.get_onHideBehavior() : null;
    },
    onHide : function() {
        /// <summary>
        /// Play the OnHide animation
        /// </summary>
        /// <returns />
        if (this._popupBehavior) {
            this._popupBehavior.onHide();
        }
    },
    
    get_promptText : function() {
        /// <summary>
        /// The prompt text displayed when user clicks the list
        /// </summary>
        /// <value type="String" />
        return this._promptText;
    },              

    set_promptText : function(value) {
        if (this._promptText != value) {
            this._promptText = value;
            this.raisePropertyChanged('promptText');
        }
    },              

    get_promptCssClass : function() {
        /// <summary>
        /// CSS class applied to prompt when user clicks list.
        /// </summary>
        /// <value type="String" />
        return this._promptCssClass;
    },              

    set_promptCssClass : function(value) {
        if (this._promptCssClass != value) {
            this._promptCssClass = value;
            this.raisePropertyChanged('promptCssClass');
        }
    },

    get_promptPosition : function() {
        /// <value type="AjaxControlToolkit.ListSearchPromptPosition">
        /// Where the prompt should be positioned relative to the target control.
        /// Can be Top (default) or Bottom
        /// </value>
        return this._promptPosition;
    },

    set_promptPosition : function(value) {
        if (this._promptPosition != value) {
            this._promptPosition = value;
            this.raisePropertyChanged('promptPosition');
        }
    },

    get_raiseImmediateOnChange : function() {
        /// <summary>
        /// Boolean indicating whether an OnChange event should be fired as soon as the selected element
        /// is changed, or only when the list loses focus or the user hits enter.
        /// </summary>
        /// <value type="String" />
        return this._raiseImmediateOnChange;
    },

    set_raiseImmediateOnChange : function(value) {
        if (this._raiseImmediateOnChange != value) {
            this._raiseImmediateOnChange = value;
            this.raisePropertyChanged('raiseImmediateOnChange');
        }
    },
    
    get_queryTimeout : function() {
        /// <summary>
        /// Value indicating timeout in milliseconds after which search query will be cleared.
        /// Zero means no auto reset at all.
        /// </summary>
        /// <value type="Number" />    
        return this._queryTimeout;
    },

    set_queryTimeout : function(value) {
        if (this._queryTimeout != value) {
            this._queryTimeout = value;
            this.raisePropertyChanged('queryTimeout');    
        }
    },
    
    get_isSorted : function() {
        /// <value type="Boolean">
        /// When setting this to true, we instruct search routines that
        /// all values in List are already sorted on population,
        /// so binary search can be used if on StartsWith criteria is set.
        /// </value>
        return this._isSorted;
    },
    
    set_isSorted : function(value) {
        if (this._isSorted != value) {
            this._isSorted = value;
            this.raisePropertyChanged('isSorted');
        }
    },
    
    get_queryPattern : function() {
        /// <value type="AjaxControlToolkit.ListSearchQueryPattern">
        /// Search query pattern to be used to find items.
        /// Can be StartsWith (default) or Contains
        /// </value>
        return this._queryPattern;
    },

    set_queryPattern : function(value) {
        if (this._queryPattern != value) {
            this._queryPattern = value;
            this.raisePropertyChanged('queryPattern');
        }
    }    
}

AjaxControlToolkit.ListSearchBehavior.registerClass('AjaxControlToolkit.ListSearchBehavior', AjaxControlToolkit.BehaviorBase);

AjaxControlToolkit.ListSearchPromptPosition = function() {
    throw Error.invalidOperation();
}

AjaxControlToolkit.ListSearchPromptPosition.prototype = {
    Top: 0,
    Bottom: 1
}
AjaxControlToolkit.ListSearchPromptPosition.registerEnum('AjaxControlToolkit.ListSearchPromptPosition');

AjaxControlToolkit.ListSearchQueryPattern = function() {
    /// <summary>
    /// Choose what query pattern to use to search for matching words.
    /// </summary>
    /// <field name="StartsWith" type="Number" integer="true" />
    /// <field name="Contains" type="Number" integer="true" />
    throw Error.invalidOperation();
}

AjaxControlToolkit.ListSearchQueryPattern.prototype = {
    StartsWith: 0,
    Contains: 1
}
AjaxControlToolkit.ListSearchQueryPattern.registerEnum('AjaxControlToolkit.ListSearchQueryPattern');

⌨️ 快捷键说明

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