📄 pagingbulletedlistbehavior.js
字号:
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.
/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference path="../ExtenderBase/BaseScripts.js" />
Type.registerNamespace('AjaxControlToolkit');
AjaxControlToolkit.PagingBulletedListBehavior = function(element) {
/// <summary>
/// The PagingBulletedListBehavior provides sorting and paging of a bulleted list
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element the behavior is associated with
/// </param>
AjaxControlToolkit.PagingBulletedListBehavior.initializeBase(this, [element]);
this._indexSizeValue = 1;
this._separatorValue = ' - ';
//From Server Componant
this._heightValue = null;
this._maxItemPerPage = null;
this._clientSortValue = false;
this._selectIndexCssClassValue = null;
this._unselectIndexCssClassValue = null;
// Local
this._tabValue = new Array();
this._tabValueObject = new Array();
this._tabIndex = new Array();
this._divContent = null;
this._divContentIndex = null;
this._divContentUl = null;
this._prevIndexSelected = null;
this._indexSelected = 0;
// Event
this._clickIndex = null;
}
AjaxControlToolkit.PagingBulletedListBehavior.prototype = {
initialize : function() {
/// <summary>
/// Initialize the behavior
/// </summary>
AjaxControlToolkit.PagingBulletedListBehavior.callBaseMethod(this, 'initialize');
// ClientState
var clientState = this.get_ClientState();
if (clientState){
var stateItems = clientState.split(";");
if (stateItems.length) {
this._indexSelected = stateItems[0];
if (stateItems[1] == "null")
this._indexSizeValue = null;
else
this._indexSizeValue = stateItems[1];
if (stateItems[2] == "null")
this._maxItemPerPage = null;
else
this._maxItemPerPage = stateItems[2];
if (stateItems[3] == "true"){
this._clientSortValue = true;
}else{
this._clientSortValue = false;
}
}
}
var e = this.get_element();
//Div Content
this._divContent = document.createElement('div');
//insert Div
e.parentNode.insertBefore(this._divContent, e);
var liElements = e.childNodes;
// Create the OnClick Index
this._clickIndex = Function.createDelegate(this, this._onIndexClick);
var inner;
var index;
this._divContentIndex = document.createElement('DIV');
this._divContentIndex.style.marginBottom = '5px';
this._divContent.appendChild(this._divContentIndex);
//Extract LI elements in _tabValueObject
for (var i = 0 ; i < liElements.length; i++) {
if (liElements[i].nodeName == 'LI') {
if ((liElements[i].firstChild) && (liElements[i].firstChild.innerHTML)) {
inner = liElements[i].firstChild.innerHTML;
} else {
inner = liElements[i].innerHTML;
}
this._tabValueObject[this._tabValueObject.length] = {text : inner, obj : liElements[i], index : i};
}
}
//Sort if need
if(this._clientSortValue) {
this._tabValueObject.sort(this.liElementSortText);
}
//Generate Index and dispatch in TabIndex and TabValue
this._generateIndexAndTabForView();
//Remove LI
this._removeChilds(e.childNodes);
//Add DIV for Index
this._divContentUl = document.createElement('DIV');
//Height of DivContent
this._changeHeightDivContent();
//Re-insert LI
this._divContentUl.appendChild(e);
this._divContent.appendChild(this._divContentUl);
this._updateIndexAndView(this._indexSelected);
},
_changeHeightDivContent : function() {
/// <summary>
/// Change the height of the list
/// </summary>
if (this._heightValue) {
this._divContentUl.style.overflow = 'scroll';
this._divContentUl.style.height = (this._heightValue) + 'px';
} else {
this._divContentUl.style.overflow = '';
this._divContentUl.style.height = '';
}
},
_createAHrefIndex : function(indexText, indexNumber) {
/// <summary>
/// Create an index and display it above the list
/// </summary>
/// <param name="indexText" type="String">
/// Text of the index
/// </param>
/// <param name="indexNumber" type="Number" integer="true">
/// Index
/// </param>
/// <returns type="Sys.UI.DomElement" domElement="true">
/// Seperator element appended after the new index (so it can be removed later if last)
/// </returns>
var spanSeparator;
var aIndex;
//Create a for Index
aIndex = document.createElement('a');
aIndex.href = '';
//Add _unSelectIndexCssClass by default
Sys.UI.DomElement.addCssClass(aIndex, this._unselectIndexCssClassValue);
aIndex.innerHTML = indexText;
aIndex.tag = indexNumber;
//Attach event
$addHandler(aIndex, 'click',this._clickIndex);
//Save a Object in _tabIndex
this._tabIndex[this._tabIndex.length] = aIndex;
this._divContentIndex.appendChild(aIndex);
//Add SPAN
spanSeparator = document.createElement('SPAN');
//Add FEFF carater for not delete the first or last space
spanSeparator.innerHTML = '\uFEFF' + this._separatorValue + '\uFEFF';
this._divContentIndex.appendChild(spanSeparator);
//Return Separator for remove the last one
return spanSeparator;
},
liElementSortText : function(x, y) {
/// <summary>
/// Sort function to compare two strings
/// </summary>
/// <param name="x" type="Object">
/// Object (of the form {text, index})
/// </param>
/// <param name="y" type="Object">
/// Object (of the form {text, index})
/// </param>
/// <returns type="Number" integer="true">
/// -1 if the first is less than the second, 0 if they are equal, 1 if the first is greater than the second
/// </returns>
//Sort by text
if (x.text.toLowerCase() == y.text.toLowerCase()) {
return 0;
} else {
if (x.text.toLowerCase() < y.text.toLowerCase()) {
return -1;
} else {
return 1;
}
}
},
liElementSortIndex : function(x, y) {
/// <summary>
/// Sort function to compare two indices
/// </summary>
/// <param name="x" type="Object">
/// Object (of the form {text, index})
/// </param>
/// <param name="y" type="Object">
/// Object (of the form {text, index})
/// </param>
/// <returns type="Number" integer="true">
/// -1 if the first is less than the second, 0 if they are equal, 1 if the first is greater than the second
/// </returns>
//Sort by index (init order)
return x.index - y.index;
},
_generateIndexAndTabForView : function() {
/// <summary>
/// Create the indices
/// </summary>
this._deleteTabIndexAndTabValue();
this._tabValue = new Array();
this._tabIndex = new Array();
var lastSpanSeparator;
this._removeChilds(this._divContentIndex.childNodes);
//Cut array _tabValueObject in _tabValue with 1 dimension per 1 index
if(this._maxItemPerPage) {
//if _maxItemPerPage index generation become automatique
if (this._maxItemPerPage > 0) {
var j = -1;
for(var i = 0; i < this._tabValueObject.length; i++) {
if((i % this._maxItemPerPage) == 0) {
j++;
index = this._tabValueObject[i].text;
this._tabValue[j] = new Array();
lastSpanSeparator = this._createAHrefIndex(index, j);
}
this._tabValue[j][this._tabValue[j].length] = this._tabValueObject[i].obj;
}
}
} else {
//if Generate index with _indexSizeValue
if (this._indexSizeValue > 0) {
var currentIndex = '';
var j = -1;
for(var i = 0; i < this._tabValueObject.length; i++) {
index = this._tabValueObject[i].text.substr(0, this._indexSizeValue).toUpperCase();
if (currentIndex != index) {
j++;
this._tabValue[j] = new Array();
lastSpanSeparator = this._createAHrefIndex(index, j);
currentIndex = index;
}
this._tabValue[j][this._tabValue[j].length] = this._tabValueObject[i].obj;
}
}
}
//Remove last SpanSeparator
if (lastSpanSeparator) {
this._divContentIndex.removeChild(lastSpanSeparator);
}
},
_deleteTabIndexAndTabValue : function() {
/// <summary>
/// Delete the indices
/// </summary>
//Remove Event
if (this._clickIndex) {
for(var i = 0; i < this._tabIndex.length; i++) {
var aIndex = this._tabIndex[i];
if(aIndex) {
$removeHandler(aIndex, 'click', this._clickIndex);
}
}
this._changeHandler = null;
}
//Delete _tabIndex
delete this._tabIndex;
//Delete Dimention two _tabValue[x]
for(var i = 0; i < this._tabValue.length; i++) {
delete this._tabValue[i];
}
//Delete _tabValue
delete this._tabValue;
},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -