/*! * 版本:MYUI Copyright © 2019 * 作者:QQ726662013版权所有 * 官网:https://www.mytheme.cn */ var MyTheme = { 'Browser': { url: document.URL, domain: document.domain, title: document.title, language: (navigator.browserLanguage || navigator.language).toLowerCase(), canvas: function() { return !!document.createElement("canvas").getContext }(), useragent: function() { var a = navigator.userAgent; return { mobile: !! a.match(/AppleWebKit.*Mobile.*/), ios: !! a.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), android: -1 < a.indexOf("Android") || -1 < a.indexOf("Linux"), iPhone: -1 < a.indexOf("iPhone") || -1 < a.indexOf("Mac"), iPad: -1 < a.indexOf("iPad"), trident: -1 < a.indexOf("Trident"), presto: -1 < a.indexOf("Presto"), webKit: -1 < a.indexOf("AppleWebKit"), gecko: -1 < a.indexOf("Gecko") && -1 == a.indexOf("KHTML"), weixin: -1 < a.indexOf("MicroMessenger") } }() }, 'Cookie': { 'Set':function(name,value,days){ var expires; if (days) { expires = days; } else{ expires = ""; } $.cookie(name,value,{expires:expires,path:'/'}); }, 'Get':function(name){ var styles = $.cookie(name); return styles; }, 'Del':function(name,tips){ if(window.confirm(tips)){ $.cookie(name,null,{expires:-1,path: '/'}); location.reload(); }else{ return false; } } }, 'Ajax':function(url,type,dataType,data,sfun,efun,cfun){ type=type||'get'; dataType=dataType||'json'; data=data||''; efun=efun||''; cfun=cfun||''; $.ajax({ url:url, type:type, dataType:dataType, data:data, timeout: 5000, beforeSend:function(XHR){ }, error:function(XHR,textStatus,errorThrown){ if(efun) efun(XHR,textStatus,errorThrown); }, success:function(data){ sfun(data); }, complete:function(XHR, TS){ if(cfun) cfun(XHR, TS); } }) }, 'Mobile': { 'Nav': { 'Init': function() { if($(".nav-slide").length){ $(".nav-slide").each(function(){ var $that = $(this); MyTheme.Mobile.Nav.Set($that,$that.attr('data-align')); }); } }, 'Set': function(id,align) { $index = id.find('.active').index()*1; if($index > 3){ $index = $index-3; }else{ $index = 0; } id.flickity({ cellAlign: align, freeScroll: true, contain: true, prevNextButtons: false, pageDots: false, percentPosition: true, initialIndex: $index }); } }, 'Mshare': function() { $(".open-share").click(function() { MyTheme.Browser.useragent.weixin ? $("body").append('
') : $("body").append(''); $(".mobile-share").click(function() { $(".mobile-share").remove(); $("body").removeClass("modal-open"); }); }); } }, 'Images': { 'Lazyload': function() { $(".lazyload").lazyload({ effect: "fadeIn", threshold: 200, failure_limit : 1, skip_invisible : false, }); }, 'Qrcode': { 'Init': function() { if($("#qrcode").length){ var $that = $("#qrcode"); MyTheme.Images.Qrcode.Set($that.attr('data-link'),$that.attr('data-dark'),$that.attr('data-light')); $that.attr("class","img-responsive"); } }, 'Set': function(url,dark,light) { url=0||location.href; var qrcode = new QRCode('qrcode', { text: url, width: 160, height: 160, colorDark : dark, colorLight : light, correctLevel : QRCode.CorrectLevel.H }); } }, 'Flickity': { 'Init': function() { if($(".flickity").length){ $(".flickity").each(function(){ var $that = $(this); MyTheme.Images.Flickity.Set($that,$that.attr('data-align'),$that.attr('data-dots'),$that.attr('data-next')); }); } }, 'Set': function(id,align,dots,next) { dots=dots||false; next=next||false; id.flickity({ cellAlign: align, wrapAround: true, contain: true, pageDots: dots, percentPosition: true, prevNextButtons: next }); } } }, 'Link': { 'Copy': { 'Init': function() { $(".myui-copy-link").each(function(){ var links = $(this).attr("data-url"); MyTheme.Link.Copy.Set(this,links); }); $(".myui-copy-html").each(function(){ var html = $(this).parent().find(".content").html(); MyTheme.Link.Copy.Set(this,html); }); }, 'Set': function(id,content) { var clipboard = new Clipboard(id, { text: function() { return content; } }); clipboard.on('success', function(e) { layer.msg('复制成功'); }); clipboard.on("error",function(e){ layer.msg('复制失败,请手动复制'); }); } }, 'Short': function(){ $(".myui-short").each(function(){ var codyId = this; var shortId = $(this); var shortUrl = shortId.val() || shortId.attr("data-url"); $.ajax({ type : 'GET', url : myui.shortapi+encodeURIComponent(shortUrl), dataType : 'jsonp', success : function(r) { url_short = r.data.urls[0].url_short; if(shortId.val()){ shortId.val(url_short); }else if(shortId.attr("data-url")){ shortId.attr("data-url",url_short); MyTheme.Link.Copy.Set(codyId,url_short); } } }); }); } }, 'Layer': { 'Img': function(title,src,text) { layer.open({ type: 1, title: title, skin: 'layui-layer-rim', content: ''+text+'