/** * 加载专题图widget * @author Wenyb * @date 2015/6/30 */ define([ "dojo", "dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!controls/page/template.html", "dojo/_base/lang", "dojo/query", "dojo/dom-construct", "dojo/dom-style", "dojo/on", "dojo/dom-class", "dojo/window", "dojo/_base/array", "dojo/dom-attr", "dojo/aspect", "dojo/domReady!" ], function ( dojo, declare, _WidgetBase, _TemplatedMixin, template, lang, query, domConstruct, domStyle, on, domClass, win, array, domAttr, aspect ){ var Widget = declare([_WidgetBase,_TemplatedMixin], { templateString: template, /** * 一共的页数 */ totalCount:10, /** * 一次显示的页码数 */ pageCount:5, _refNode:null, pageSpanlist:[], pageSpanEventHandlers:[], currentPage:1, constructor:function(options,srcNodeRef) { //this._refNode=refNode; var csspath = require.toUrl("controls/page/PageControl.css"); lang.mixin(this, options); dojo.create("link", {href:csspath, type:'text/css', rel:'stylesheet'}, document.getElementsByTagName('head')[0]); }, postCreate:function() { //this.placeAt(this._refNode); this.createPage(); }, createPage:function(option) { if(option !== undefined && option != null) { this.totalCount = option.totalCount; this.pageCount=option.pageCount; } domConstruct.empty(this.pagelist); if(this.totalCount < 1) { this.switchPreButton(false); this.switchNextButton(false); return; } this.pageSpanlist=[]; this.pageSpanlist.push(this.createPageSpan("1",true)); var tmpTotal; if(this.totalCount1) { this.switchPreButton(true); } //如果点击的是第一项,那么把点击的按钮移到中间 if(domAttr.get(this.pageSpanlist[this.pageSpanlist.length-1],"page") == nPage.toString()) { strFlag = "last"; } //如果点击的是最后一项,那么把点击的按钮移到中间 else if(domAttr.get(this.pageSpanlist[0],"page") == nPage.toString()) { strFlag = "first"; } switch(strFlag) { case "last": var thisPageCount = -1; if(this.pageCount>this.totalCount) thisPageCount = this.totalCount; else thisPageCount = this.pageCount; var step = parseInt((thisPageCount-1)/2); this.pageSpanlist = []; //当前按钮可以放到中间 if(step<(this.totalCount-this.currentPage)) { for(i=step;i>=0;i--) { if(i == 0) { this.pageSpanlist.push(this.createPageSpan((this.currentPage - i).toString(),true)); } else { this.pageSpanlist.push(this.createPageSpan((this.currentPage - i).toString(),false)); } } //如果页面数是偶数,则需要再加1 if(this.pageCount%2 == 0) { step++; } for(i=1;i<=step;i++) { this.pageSpanlist.push(this.createPageSpan((this.currentPage + i).toString(),false)); } } //当前按钮不可放在中间 else { for(i = this.totalCount-thisPageCount+1;i<=this.totalCount;i++) { if(i == this.currentPage) { this.pageSpanlist.push(this.createPageSpan(i.toString(),true)); } else { this.pageSpanlist.push(this.createPageSpan(i.toString(),false)); } } } break; case "first": thisPageCount= -1; if(this.pageCount>this.totalCount) thisPageCount = this.totalCount; else thisPageCount = this.pageCount; step = parseInt((thisPageCount-1)/2); this.pageSpanlist = []; //当前按钮可以放到中间 if(step=0;i--) { if(i == 0) { this.pageSpanlist.push(this.createPageSpan((this.currentPage - i).toString(),true)); } else { this.pageSpanlist.push(this.createPageSpan((this.currentPage - i).toString(),false)); } } //如果页面数是偶数,则需要再加1 if(thisPageCount%2 == 0) { step++; } for(i=1;i<=step;i++) { this.pageSpanlist.push(this.createPageSpan((this.currentPage + i).toString(),false)); } } //当前按钮不可放在中间 else { for(i = 1;i<=thisPageCount;i++) { if(i == this.currentPage) { this.pageSpanlist.push(this.createPageSpan(i.toString(),true)); } else { this.pageSpanlist.push(this.createPageSpan(i.toString(),false)); } } } break; default: //array.forEach(this.pageSpanlist,this.updatePageSpan,this); break; } for(i=0;i< this.pageSpanlist.length;i++) { var pagevalue = domAttr.get(this.pageSpanlist[i],"page"); this.pageSpanlist[i].innerHTML=pagevalue; domConstruct.place(this.pageSpanlist[i],this.pagelist); } array.forEach(this.pageSpanlist,this.updatePageSpan,this); //需要显示“下一页” if(this.currentPage