123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- function PageTurn(config){
- var instance = this;
- var o = $.extend(true,{},config);
- var $pageWrap = $(o.element);
- var $list = $pageWrap.find('[data-page-role="list"] li');
- var $btnPrev = $pageWrap.find('.btn-page-prev');
- var $btnNext = $pageWrap.find('.btn-page-next');
- var $pageIndex = $pageWrap.find('.page-index');
- var $pageNum = $pageWrap.find('.page-num');
- var $txt = $pageWrap.find('.txt-page');
- this.len = $list.length;
- this.index = 0;
- this.pageNum = Math.ceil(this.len/o.showNum);
- PageTurn = function(){
- return instance;
- }
- var _renderPage = function(){
- $list.addClass("u-hide");
- for(var i=0; i<o.showNum && i<instance.len; i++){
- $list.eq(instance.index * o.showNum + i).removeClass("u-hide");
- }
- if (instance.index <= 0) {
- $btnPrev.addClass("is-disabled");
- } else {
- $btnPrev.removeClass("is-disabled");
- }
- if (instance.index >= instance.pageNum-1) {
- $btnNext.addClass("is-disabled");
- } else {
- $btnNext.removeClass("is-disabled");
- }
- $pageIndex.text(instance.index+1);
- }
- var _initEvent = function(){
- //上一页
- $pageWrap.on("click",'[data-page-role="nav"] .btn-page-prev',function(){
- var $this = $(this);
- if ($this.hasClass("is-disabled")) {
- return;
- }
-
- --instance.index;
- _renderPage();
- $txt.val("");
- })
- //下一页
- $pageWrap.on("click",'[data-page-role="nav"] .btn-page-next',function(){
- var $this = $(this);
- if ($this.hasClass("is-disabled")) {
- return;
- }
- ++instance.index;
- _renderPage();
- $txt.val("");
- })
- //跳转页
- $pageWrap.on("click",'[data-page-role="nav"] .btn-page-go',function(){
- var reg = /^\d*$/;
- var value = $pageWrap.find('[name="pageIndex"]').val();
- var $this = $(this);
- if (reg && !reg.test(value)) {
- return;
- }
- if ($this.hasClass("is-disabled")) {
- return;
- }
- if(value<=0 || value>instance.pageNum){
- return;
- }
- instance.index = value-1;
- _renderPage();
- })
- }
- var _init = function(){
- _initEvent();
- }
- _init();
- }
- function Select(config){
- var instance = this;
- var o = $.extend(true,{},config);
- var $select = $(o.element);
- Select = function(){
- return instance;
- }
- var _initEvent = function(){
- $select.on("click","dt",function(){
- var $this = $(this);
- var $parent = $this.parent();
- if ($parent.hasClass("is-open")){
- $parent.removeClass("is-open");
- } else {
- $parent.addClass("is-open");
- }
- });
- $select.on("click","dd",function(){
- var $this = $(this);
- var $parent = $this.parent();
- var sortBy = $this.attr("data-val");
- $parent.removeClass("is-open").find("dt span").text($this.text());
- o.callback && o.callback(sortBy);
- });
- $select.on("mouseleave",function(){
- $(this).removeClass("is-open");
- });
- }
- var _init = function(){
- _initEvent();
- }
- _init();
- }
- function getParam (name) {
- //先获取#后面的参数
- var str = document.location.hash.substr(2);
- var value = getParam2(name, str);
- if (value == null) {
- str = document.location.search.substr(1);
- value = getParam2(name, str);
- }
- return value;
- }
- function getParam2 (name, str) {
- //获取参数name的值
- var reg = new RegExp("(^|!|&|\\?)" + name + "=([^&]*)(&|$)");
- //再获取?后面的参数
- r = str.match(reg);
- if (r != null) {
- try {
- return decodeURIComponent(r[2]);
- } catch (e) {
- // console.log(e + "r[2]:" + r[2]);
- return null;
- }
- }
- return null;
- }
- function setCookie(key,val) {
- document.cookie = key+"="+val;
- }
- function getCookie(name) {
- var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
- if(arr=document.cookie.match(reg))
- return unescape(arr[2]);
- else
- return null;
- }
- function checkPlatform(){
- var platform = navigator.platform;
- var os = 5;
- if (platform.indexOf("Mac") ==0 ) {
- os = 3;
- }
- if (platform.indexOf("Win") ==0 ) {
- os = 4;
- }
- if ((platform.indexOf("X11") ==0) || (platform.indexOf( "Linux") ==0)) {
- os = 5;
- }
- return os;
- }
- function _initHeziLink(heziType){
- $(".g-header ul a").each(function(i,e){
- $(e).attr("href",$(e).attr("href")+"?hezi="+heziType);
- });
- $(".mod-hot-game .link-more").attr("href","./simulatorGame.html?hezi="+heziType);
- $(".search-wrap form").append('<input name="hezi" type="hidden" value="'+heziType+'">')
- }
- //识别盒子类型lol,dnf默认lol
- function initHezi(heziType){
- var heziType = getParam("hezi");
- switch(heziType){
- case("dnf")://dnf盒子
- $("body").addClass("hezi-dnf");
- _initHeziLink(heziType);
- break;
- case("td")://天刀盒子
- _initHeziLink(heziType);
- break;
- case("tksj")://坦克世界盒子
- $("body").addClass("hezi-tksj");
- _initHeziLink(heziType);
- break;
- default :
- break;
- }
- }
- window.commonUtil = {
- PageTurn : PageTurn,
- Select : Select,
- getParam : getParam,
- setCookie : setCookie,
- getCookie : getCookie,
- checkPlatform : checkPlatform,
- initHezi : initHezi
- }
|