📄 core_ext.js
字号:
beforeNext:Prototype.emptyFunction,beforeChange:Prototype.emptyFunction,delIterator:Prototype.emptyFunction,updateIterator:Prototype.emptyFunction,needRefreshAfterUpdate:true,RefreshAfterAdd:true,RefreshAfterDel:true,useCache:true,isDiv:false,changeLocationHash:true},arguments[1]||{});this.totalPages=0;this.objName=sObjectName;this.curPage;this.cacheData=[];this.markIDArray=[];this.beforeIDArray=[];this._iTextSpanWidth;this._init();},_init:function(){if(this.options.totalSize>-1)this.totalPages=this._getTotalPages();this.curPage=1;if(this.options.markID)this.markIDArray=this.options.markID.split(":");this._getContainer();if(this.options.beforeID)this.beforeIDArray=this.options.beforeID.split(":");},_getContainer:function(){if(UD==undefined||UD.body==undefined){this.container=window.document.body;return;}var ele=$(this.markIDArray[0]);this.container=UD.body;if(this.options.isDiv&&ele){while(ele!=UD.body&&ele.id!='blog-163-com-body'&&ele!=UD.body&&ele!=document.body)ele=ele.parentNode;if(ele==UD.body||ele.id==document.body)this.container=UD.body;}},reset:function(){this.cacheData=[];this.curPage=1;this.options.totalSize=0;this.totalPages=1;this._generateMarks();},initCacheData:function(oData){this.options.filterFunc(oData);if(this.options.useCache){for(var i=0;i<oData.length;i++){this.cacheData[i]=oData[i];}}},getAllCachedData:function(){var datas=[];this.cacheData.each(function(e){if(e!=null){datas.push(e)}})return datas;},getTotalPages:function(){return this.totalPages;},getCurPageNum:function(){return this.curPage;},getCurOffset:function(){return this.options.pageSize*(this.curPage-1);},getTotalSize:function(){return this.options.totalSize;},setTotalSize:function(iSize){this.options.totalSize=iSize;this.totalPages=this._getTotalPages();},refreshMarks:function(){this._generateMarks();},refreshCurPage:function(){this.show();},nextPage:function(){this.curPage++;if(this.curPage>this.totalPages)this.curPage=this.totalPages;this.show();return false;},prevPage:function(){this.curPage--;if(this.curPage<1)this.curPage=1;this.show();return false;},setPageSize:function(iSize){this.options.pageSize=iSize;this.totalPages=this._getTotalPages();},show:function(){var _iOffset=this.options.pageSize*(this.curPage-1);var _iLimit=this.options.pageSize;if(this.options.useCache){var _data=this._hasFullData(_iOffset,_iLimit)if(_data!=null){this._display(_data);}else{this.options.loadParam.offset=_iOffset;this.options.loadParam.limit=_iLimit*(this.options.prefetchMulti?this.options.prefetchMulti:1);this.options.loadFunc(this.options.loadParam,this._display.bind(this));}}else{this.options.loadParam.offset=_iOffset;this.options.loadParam.limit=_iLimit;this.options.loadFunc(this.options.loadParam,this._display.bind(this));}},_display:function(oData){if(oData==null||oData.length==0){if(this.curPage>1){this.curPage--;this.options.totalSize=this.curPage*this.options.pageSize;this.totalPages=this._getTotalPages();this.cacheData=[];this.show();return false;}}this.options.filterFunc(oData);if(this.options.useCache){var _iOffset=this.options.pageSize*(this.curPage-1);for(var i=0;i<oData.length;i++){this.cacheData[_iOffset+i]=oData[i];}}this.options.presentFunc(oData.slice(0,this.options.pageSize),this.options.userPresentFuncParam);this._generateMarks();},_hasFullData:function(iOffset,iLimit){var _oDataDisplay=[];var _iLen=iOffset+iLimit>this.options.totalSize?this.options.totalSize-iOffset:iLimit;for(var i=0;i<_iLen;i++){var _oData=this.cacheData[iOffset+i];if(_oData==undefined||_oData==null)return null;_oDataDisplay[i]=_oData;}return _oDataDisplay;},_generateMarks:function(){var _iMarkLen=this.markIDArray.length;for(var i=0;i<_iMarkLen;i++){var markId=this.markIDArray[i];var _oMark=$(markId);if(_oMark){_oMark.innerHTML=this._generateHTML(markId);this._setUIEvent(markId);}}return false;},_getTotalPages:function(){if(this.options.pageSize==0){return 1;}var _iLast=(this.options.totalSize%this.options.pageSize==0)?0:1;var _iPages=parseInt(this.options.totalSize/this.options.pageSize+_iLast+'');if(_iPages<1)_iPages=1;return _iPages;},goToPage:function(iPageIndex){if(iPageIndex>this.totalPages||iPageIndex<1)return;this.curPage=iPageIndex;this.show();},addOne:function(item,head,notRefresh){if(this.options.totalSize>-1){this.options.totalSize++;this.totalPages=this._getTotalPages();}if(this.options.useCache){if(head){this.cacheData.unshift(item);}else{this.cacheDate[this.options.totalSize-1]=item;}}if(this.options.RefreshAfterAdd&¬Refresh!=true){this.show();}},removeOne:function(item,notRefresh){var removed=null;if(this.options.useCache){removed=this._removeItem(item);}this._afterRemove(1,notRefresh);return removed;},removeItems:function(items,notRefresh){if(this.options.useCache){items.each(this._removeItem.bind(this));}this._afterRemove(items.length,notRefresh);},_removeItem:function(item){var index=-1;for(var i=0;i<this.options.totalSize;i++){if(this.cacheData[i]==undefined||this.cacheData[i]==null)continue;if(this.options.delIterator(item,this.cacheData[i])){index=i;break;}}if(index==-1){return null;}var removed=this.cacheData[index];if(index+1<this.options.totalSize){this.cacheData[index]=this.cacheData[index+1];this.cacheData[index+1]=null;}else{this.cacheData[index]=null;}for(++index;index<this.options.totalSize-1;index++){if(this.cacheData[index+1]!=undefined&&this.cacheData[index+1]!=null){this.cacheData[index]=this.cacheData[index+1];this.cacheData[index+1]=null;}}return removed;},_afterRemove:function(len,notRefresh){if(this.options.totalSize>-1){this.options.totalSize-=len;this.totalPages=this._getTotalPages();}if(this.curPage==this.totalPages+1&&this.options.totalSize%this.options.pageSize==0){this.curPage--;}if(this.options.RefreshAfterDel&¬Refresh!=true){this.show();}},updateOne:function(oItem,bNotRefresh){if(this.options.useCache){var _iOffset=this.options.pageSize*(this.curPage-1);var index=-1;for(var i=0;i<this.options.pageSize;i++){if(!this.cacheData[i+_iOffset])continue;if(this.options.updateIterator(oItem,this.cacheData[i+_iOffset])){index=i+_iOffset;break;}}if(index==-1){this.cacheData=[];return;}Object.extend(this.cacheData[index],oItem);}if(bNotRefresh!=true&&this.options.needRefreshAfterUpdate){this.show();}},emptyCache:function(){this.cacheData=[];},_generateHTML:function(sMarkId){var s=[];if(this.totalPages==this.curPage){if(this.options.isDiv==false)s.push('<div class="updownPageNolink c09"><span>下页</span></div>');elses.push('<div class="updownPageNolink"><span>下页</span></div>');}else{if(this.options.isDiv==false)s.push('<div class="c06 g_p_right"><a href="#" class="updownPage" id="$$_next_'+sMarkId+'" onclick="'+this.objName+'.clickNext(\''+sMarkId+'\');return false;" onmouseover="'+this.objName+'.updownPageMouseOvr(\'$$_next_'+sMarkId+'\');return false;" onmouseout="'+this.objName+'.updownPageMouseOut(\'$$_next_'+sMarkId+'\');return false;">下页</a></div>');elses.push('<div class="divTxtColr g_p_right"><a href="#" class="updownPage" id="$$_next_'+sMarkId+'" onclick="'+this.objName+'.clickNext(\''+sMarkId+'\');return false;" onmouseover="'+this.objName+'.updownPageMouseOvr(\'$$_next_'+sMarkId+'\');return false;" onmouseout="'+this.objName+'.updownPageMouseOut(\'$$_next_'+sMarkId+'\');return false;">下页</a></div>');}s.push('<div class="pageSelect g_p_right">');s.push('<div id="$$_textBorder_'+sMarkId+'" class="textBorder" onclick="'+this.objName+'.clickTextBorder(\''+sMarkId+'\', event);" onmouseover="'+this.objName+'.textBorderMouseOvr(\''+sMarkId+'\');return false;" onmouseout="'+this.objName+'.textBorderMouseOut(\''+sMarkId+'\');return false;">');if(this.options.isDiv==false)s.push('<span id="$$_pageText_'+sMarkId+'" class="pageText c06">'+this.curPage+'/'+this.totalPages+'</span>');elses.push('<span id="$$_pageText_'+sMarkId+'" class="pageText divTxtColr">'+this.curPage+'/'+this.totalPages+'</span>');s.push('</div></div>');if(this.curPage==1){if(this.options.isDiv==false)s.push('<div class="updownPageNolink c09"><span>上页</span></div>');elses.push('<div class="updownPageNolink"><span>上页</span></div>');}else{if(this.options.isDiv==false)s.push('<div class="c06 g_p_right"><a href="#" class="updownPage" id="$$_prev_'+sMarkId+'" onclick="'+this.objName+'.clickPrev(\''+sMarkId+'\');return false;" onmouseover="'+this.objName+'.updownPageMouseOvr(\'$$_prev_'+sMarkId+'\');return false;" onmouseout="'+this.objName+'.updownPageMouseOut(\'$$_prev_'+sMarkId+'\');return false;">上页</a><div>');elses.push('<div class="divTxtColr g_p_right"><a href="#" class="updownPage" id="$$_prev_'+sMarkId+'" onclick="'+this.objName+'.clickPrev(\''+sMarkId+'\');return false;" onmouseover="'+this.objName+'.updownPageMouseOvr(\'$$_prev_'+sMarkId+'\');return false;" onmouseout="'+this.objName+'.updownPageMouseOut(\'$$_prev_'+sMarkId+'\');return false;">上页</a><div>');}this._addList2Container(sMarkId);return s.join('');},_addList2Container:function(sMarkId){var _oChildren=this.container.childNodes;var _iChildLen=_oChildren.length;var m=null;for(var k=_iChildLen-1;k>=0;k--){if('$$_opt_'+sMarkId==_oChildren[k].id){m=_oChildren[k];break;}}if(m!=null){Element.removeChild(m);delete m;}var o=document.createElement("DIV");o.id='$$_opt_'+sMarkId;if(this.options.isDiv==false)o.className='opt bd01';elseo.className='opt bdblack';o.style.display='none';o.onmouseover=this.optMouseOver.bind(this,sMarkId);var t=[];for(var i=1;i<=this.totalPages;i++){t.push('<a href="#" onclick="'+this.objName+'.clickPageNumber(\''+sMarkId+'\', '+i+', \'$$_opt_'+sMarkId+'\', \'$$_textBorder_'+sMarkId+'\');return false;">');t.push(i);t.push('</a>');}o.innerHTML=t.join('');this.container.appendChild(o);},_setUIEvent:function(sMarkId){var _oTextBorder=$('$$_textBorder_'+sMarkId);var _oPageText=$('$$_pageText_'+sMarkId);var _opt=$('$$_opt_'+sMarkId);var _optA=_opt.getElementsByTagName("a");this._iTextSpanWidth=_oPageText.offsetWidth;_oTextBorder.style.width=this._iTextSpanWidth+18+"px";_opt.style.width=this._iTextSpanWidth+18+"px";Event.observe(window.document,"click",this._clickDocument.bind(this,sMarkId));},_clickDocument:function(sMarkId){var _opt=$('$$_opt_'+sMarkId);var _textBorder=$('$$_textBorder_'+sMarkId);if(_opt)_opt.style.display="none";if(_textBorder){_textBorder.className="textBorder";_textBorder.style.width=this._iTextSpanWidth+18+"px";}},optMouseOver:function(sMarkId){var _opt=$('$$_opt_'+sMarkId);var _optA=_opt.getElementsByTagName("a");var _oA=_optA[this.curPage-1];_oA.className="";},clickTextBorder:function(sMarkId,event){event=event||window.event;var _opt=$('$$_opt_'+sMarkId);if(_opt.style.display=="none"){this.closeAllPopup();_opt.style.display="block";_opt.scrollTop=(this.curPage-1)*14;var _oA=_opt.getElementsByTagName("a")[this.curPage-1];_oA.className="ttt";var _oPageOffset=Position.cumulativeOffset($('$$_textBorder_'+sMarkId));var w;if(UD==undefined||UD.window==undefined)w=window;elsew=UD.window;var iPageTopOffset=_oPageOffset[1]-w.scrollTop;var iPageBottomOffset=document.documentElement.clientHeight-iPageTopOffset;if(_opt.offsetHeight>iPageBottomOffset){_opt.style.left=_oPageOffset[0]+"px";_opt.style.top=_oPageOffset[1]-_opt.offsetHeight+"px";}else{_opt.style.left=_oPageOffset[0]+"px";_opt.style.top=_oPageOffset[1]+24+"px";}Event.stop(event);}else{_opt.style.display="none";}return false;},clickPrev:function(sMarkId){if(this.options.changeLocationHash){window.location.hash='pn'+(this.curPage-1);}if(sMarkId!=null&&this.beforeIDArray!=null){for(var i=0;i<this.beforeIDArray.length;i++){if(this.beforeIDArray[i]==sMarkId){this.options.beforePrev();}}}this.closeAllPopup();this.prevPage();return false;},clickNext:function(sMarkId){if(this.options.changeLocationHash){window.location.hash='pn'+(this.curPage+1);}if(sMarkId!=null&&this.beforeIDArray!=null){for(var i=0;i<this.beforeIDArray.length;i++){if(this.beforeIDArray[i]==sMarkId){this.options.beforeNext();}}}this.closeAllPopup();this.nextPage();return false;},closeAllPopup:function(){var _iMarkLen=this.markIDArray.length;for(var i=0;i<_iMarkLen;i++){var markId=this.markIDArray[i];var _opt=$('$$_opt_'+markId);_opt.style.display="none";}},clickPageNumber:function(sMarkId,iIndex,sOpt,sTextBorder){var oOpt=$(sOpt);var oTextBorder=$(sTextBorder);if(this.options.changeLocationHash){window.location.hash='pn'+iIndex;}oOpt.style.display="none";oTextBorder.className="textBorder";if(iIndex==this.curPage){return false;}if(sMarkId!=null&&this.beforeIDArray!=null){for(var i=0;i<this.beforeIDArray.length;i++){if(this.beforeIDArray[i]==sMarkId){this.options.beforeChange();}}}this.goToPage(iIndex);return false;},textBorderMouseOvr:function(sMarkId){var oElem=$("$$_textBorder_"+sMarkId);if(!oElem)return;if(this.options.isDiv==false)oElem.className="textBorderMouseOvr bd01";elseoElem.className="textBorderMouseOvr bdblack";oElem.style.width=this._iTextSpanWidth+16+"px";},textBorderMouseOut:function(sMarkId){var oElem=$("$$_textBorder_"+sMarkId);if(!oElem)return;var _opt=$('$$_opt_'+sMarkId);if(_opt.style.display=="none"){oElem.className="textBorder";oElem.style.width=this._iTextSpanWidth+18+"px";}},updownPageMouseOvr:function(sElemName){var oElem=$(sElemName);if(!oElem)return;if(this.options.isDiv==false)oElem.className="updownPageMouseOvr bd01";elseoElem.className="updownPageMouseOvr bdblack";},updownPageMouseOut:function(sElemName){var oElem=$(sElemName);if(!oElem)return;oElem.className="updownPage";},pirntData:function(){var s=[];s+=this.options.totalSize+"-------------\n";for(var i=0;i<this.options.totalSize;i++){if((i+1)%9==0&&i!=0)s+="\n";if(undefined==this.cacheData[i]||null==this.cacheData[i])s+="["+i+"]- # ";elses+="<"+i+">- "+this.cacheData[i].title+" ";}alert(s);}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -