2024-07-11 10:34:42 +08:00
|
|
|
// 定义pjax 预设pjax
|
|
|
|
|
var pjax = new Pjax({
|
|
|
|
|
// 这里填写页面中改变的部分(和 CSS 选择器用法一样)
|
|
|
|
|
selectors: ["#pjax-container"],
|
|
|
|
|
cacheBust: false,
|
|
|
|
|
elements: "a",
|
|
|
|
|
});
|
|
|
|
|
// 设置图片灯箱回调函数
|
|
|
|
|
function lazyimg_pjax(){
|
|
|
|
|
;(function($){
|
|
|
|
|
|
|
|
|
|
var defaults = {
|
|
|
|
|
coverColor:"#dfdfdf",
|
|
|
|
|
coverDiv:"",
|
|
|
|
|
showTime:300,
|
|
|
|
|
offsetBottom:0,
|
|
|
|
|
offsetTopm:50,
|
|
|
|
|
onLoadBackEnd:function(index,dom){},
|
|
|
|
|
onLoadBackStart:function(index,dom){}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//所有待load src
|
|
|
|
|
var srcList = []
|
|
|
|
|
var lazyLoadCoutn = 0;
|
|
|
|
|
var windowHeight = $(window).height();
|
|
|
|
|
var windowWidth = $(window).width();
|
|
|
|
|
var lazyImgList = $("img[data-lazy-src]");
|
|
|
|
|
var default_base64_src ="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
|
|
|
|
|
|
|
|
|
|
//获取img
|
|
|
|
|
function getImgNaturalDimensions(src, callback,lazyLoadCoutn) {
|
|
|
|
|
var nWidth, nHeight
|
|
|
|
|
var image = new Image()
|
|
|
|
|
image.src = src;
|
|
|
|
|
image.onload = function() {
|
|
|
|
|
callback(image.width, image.height);
|
|
|
|
|
defaults.onLoadBackStart(lazyLoadCoutn,$("img[data-lazy-src]:eq("+lazyLoadCoutn+")"));
|
|
|
|
|
}
|
|
|
|
|
return [nWidth, nHeight];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showImg(lazyLoadCoutn,callback){
|
|
|
|
|
|
|
|
|
|
var src = lazyImgList.eq(lazyLoadCoutn).attr("data-lazy-src")
|
|
|
|
|
getImgNaturalDimensions(src, function () {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
meng($("img[data-lazy-src]:eq("+lazyLoadCoutn+")") ,lazyLoadCoutn,callback)
|
|
|
|
|
}catch(error) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},lazyLoadCoutn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function meng(jDom,lazyLoadCoutn,callback){
|
|
|
|
|
if(jDom.attr("data-comp")){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
jDom.css("visibility","hidden");
|
|
|
|
|
jDom.attr("src",jDom.attr("data-lazy-src"))
|
|
|
|
|
var w = jDom.width();
|
|
|
|
|
var h = jDom.height();
|
|
|
|
|
var offsetTop = jDom.offset().top;
|
|
|
|
|
var offsetLeft = jDom.offset().left;
|
|
|
|
|
|
|
|
|
|
jDom.css("visibility","visible");
|
|
|
|
|
$("body").append("<div class='meng-lazy-div"+lazyLoadCoutn+"' style='background-color: "+defaults.coverColor+";position:absolute;width:"+w+"px;height:"+h+"px;top:"+offsetTop+"px;left:"+offsetLeft+"px;z-index:500'>"+defaults.coverDiv+"</div>");
|
|
|
|
|
noneM(lazyLoadCoutn,callback,jDom);
|
|
|
|
|
jDom.attr("data-comp","true");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function noneM(lazyLoadCoutn,callback,jDom){
|
|
|
|
|
if(true){
|
|
|
|
|
$(".meng-lazy-div"+lazyLoadCoutn).animate({opacity:"0"},defaults.showTime,function(){
|
|
|
|
|
$(this).remove();
|
|
|
|
|
defaults.onLoadBackEnd(lazyLoadCoutn,jDom)
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkOffset(){
|
|
|
|
|
var scrollTop = $(document).scrollTop();
|
|
|
|
|
var onlazyList = [];
|
|
|
|
|
lazyImgList.each(function(index){
|
|
|
|
|
var dom = $(this);
|
|
|
|
|
if(!dom.attr("data-comp")){
|
|
|
|
|
if(dom.offset().top-scrollTop+defaults.offsetTopm>=0&&dom.offset().top-scrollTop<(windowHeight+defaults.offsetBottom)){
|
|
|
|
|
onlazyList.push(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if(onlazyList.length!=0){
|
|
|
|
|
showImg(onlazyList[0],function(){
|
|
|
|
|
checkOffset();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function range(){
|
|
|
|
|
checkOffset();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init(setting){
|
|
|
|
|
lazyImgList = $("img[data-lazy-src]");
|
|
|
|
|
defaults = $.extend(defaults,setting);
|
|
|
|
|
|
|
|
|
|
lazyImgList.each(function(){
|
|
|
|
|
var sr = $(this).attr("data-lazy-src");
|
|
|
|
|
srcList.push(sr);
|
|
|
|
|
|
|
|
|
|
$(this).attr("src",default_base64_src);
|
|
|
|
|
});
|
|
|
|
|
range();
|
|
|
|
|
window.onscroll=function(){
|
|
|
|
|
range()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function tryAgain(){
|
|
|
|
|
$("img[data-lazy-src]").removeAttr("data-comp")
|
|
|
|
|
init(defaults)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.lazyLoadInit = init;
|
|
|
|
|
|
|
|
|
|
window.lazyLoadAgain = tryAgain;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})($)
|
|
|
|
|
}
|
|
|
|
|
function message_pjax(){
|
|
|
|
|
!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b:"function"==typeof define&&define.amd?define([],function(){return b(a)}):a.Qmsg=b(a)}(this,function(a){"use strict";function h(){var b,a=c;for(b=0;b<arguments.length;++b)a+="-"+arguments[b];return a}function i(a){var g,i,k,l,m,o,p,q,r,s,b=this;b.settings=Object.assign({},e,a||{}),b.id=n.instanceCount,g=b.settings.timeout,g=g&&parseInt(g>=0)&&parseInt(g)<=Math.NEGATIVE_INFINITY?parseInt(g):e.timeout,b.timeout=g,b.settings.timeout=g,b.timer=null,i=document.createElement("div"),k=f[b.settings.type||"info"],l=h("content-"+b.settings.type||"info"),l+=b.settings.showClose?" "+h("content-with-close"):"",m=b.settings.content||"",o=f["close"],p=b.settings.showClose?'<i class="qmsg-icon qmsg-icon-close">'+o+"</i>":"",q=document.createElement("span"),b.settings.html?q.innerHTML=m:q.innerText=m,i.innerHTML='<div class="qmsg-content"> <div class="'+l+'"> <i class="qmsg-icon">'+k+"</i>"+q.outerHTML+p+"</div> </div>",i.classList.add(h("item")),i.style.textAlign=b.settings.position,r=document.querySelector("."+c),r||(r=document.createElement("div"),r.classList.add(c),r.classList.add(h("wrapper")),r.classList.add(h("is-initialized")),document.body.appendChild(r)),r.appendChild(i),b.$wrapper=r,b.$elem=i,j(b,"opening"),b.settings.showClose&&i.querySelector(".qmsg-icon-close").addEventListener("click",function(){b.close()}.bind(i)),i.addEventListener("animationend",function(a){var b=a.target,c=a.animationName;c===d["closing"]&&(clearInterval(this.timer),this.destroy()),b.style.animationName=""}.bind(b)),b.settings.autoClose&&(s=10,b.timer=setInterval(function(){this.timeout-=s,this.timeout<=0&&(clearInterval(this.timer),this.close())}.bind(b),s),b.$elem.addEventListener("mouseover",function(){clearInterval(this.timer)}.bind(b)),b.$elem.addEventListener("mouseout",function(){"closing"!==this.state&&(this.timer=setInterval(function(){this.timeout-=s,this.timeout<=0&&(clearInterval(this.timer),this.close())}.bind(b),s))}.bind(b)))}function j(a,b){b&&d[b]&&(a.state=b,a.$elem.style.animationName=d[b])}function k(a){var b=h("count"),c=a.$elem.querySelector('[class^="qmsg-content-"]'),d=c.querySelector("."+b);d||(d=document.createElement("span"),d.classList.add(b),c.appendChild(d)),d.innerHTML=a.count,d.style.animationName="",d.style.animationName="MessageShake",a.timeout=a.settings.timeout||e.timeout}function l(a,b){var c=Object.assign({},e);return 0===arguments.length?c:a instanceof Object?Object.assign(c,a):(c.content=a.toString(),b instanceof Object?Object.assign(c,b):c)}function m(a){var b,c,d,e,f,g,h,j,l,m;a=a||{},b=JSON.stringify(a),c=-1;for(e in this.oMsgs)if(f=this.oMsgs[e],f.config===b){c=e,d=f.inst;break}if(0>c){if(this.instanceCount++,g={},g.id=this.instanceCount,g.config=b,d=new i(a),d.id=this.instanceCount,d.count="",g.inst=d,this.oMsgs[this.instanceCount]=g,h=this.oMsgs.length,j=this.maxNums,h>j)for(l=0,m=this.oMsgs,l;h-j>l;l++)m[l]&&m[l].inst.settings.autoClose&&m[l].inst.close()}else d.count=d.count?d.count>=99?d.count:d.count+1:2,k(d);return d.$elem.setAttribute("data-count",d.count),d}var b,c,d,e,f,g,n;return"function"!=typeof Object.assign&&(Object.assign=function(a){var b,c,d;if(null==a)throw new TypeError("Cannot convert undefined or null to object");for(a=Object(a),b=1;b<arguments.length;b++)if(c=arguments[b],null!=c)for(d in c)Object.prototype.hasOwnProperty.call(c,d)&&(a[d]=c[d]);return a}),"classList"in document.documentElement||Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){function b(b){return function(c){var d=a.className.split(/\s+/g),e=d.indexOf(c);b(d,e,c),a.className=d.join(" ")}}var a=this;return{add:b(function(a,b,c){~b||a.push(c)}),remove:b(function(a,b){~b&&a.splice(b,1)}),toggle:b(function(a,b,c){~b?a.splice(b,1):a.push(c)}),contains:function(b){return!!~a.className.split(/\s+/g).indexOf(b)},item:function(b){return a.className.split(/\s+/g)[b]||null}}}}),b="qmsg",c=a&&a.QMSG_GLOBALS&&a.QMSG_GLOBALS.NAMESPACE||b,d={opening:"MessageMoveIn",done:"",closing:"MessageM
|
|
|
|
|
}
|
|
|
|
|
// 设置pjax预先加载代码
|
|
|
|
|
function pjax_reload() {
|
|
|
|
|
// 给pjax容器加入css过渡动画
|
|
|
|
|
$("#pjax-container").addClass("uk-animation-slide-bottom-small");
|
|
|
|
|
// 评论区过渡动画
|
|
|
|
|
$(".comment-meta").attr("uk-scrollspy", "cls: uk-animation-fade; delay: 100");
|
|
|
|
|
$(".comment-author vcard").attr("uk-scrollspy", "cls: uk-animation-fade; delay: 100");
|
|
|
|
|
$(".comment-metadata").attr("uk-scrollspy", "cls: uk-animation-fade; delay: 100");
|
|
|
|
|
$(".comment-content").attr("uk-scrollspy", "cls: uk-animation-fade; delay: 100");
|
|
|
|
|
$(".reply").attr("uk-scrollspy", "cls: uk-animation-fade; delay: 100");
|
|
|
|
|
// 说说页面过渡动画
|
|
|
|
|
$("#shuoshuo_body").attr("uk-scrollspy", "target: > .shuoshuo; cls: uk-animation-fade; delay: 250");
|
|
|
|
|
}
|
|
|
|
|
// pjax发送时期
|
|
|
|
|
document.addEventListener("pjax:send", function () {
|
|
|
|
|
// pjax动画减少圆圈动画
|
|
|
|
|
NProgress.configure({
|
|
|
|
|
showSpinner: false
|
|
|
|
|
});
|
|
|
|
|
// pjax执行动画开始
|
|
|
|
|
NProgress.start(); //加载动画效果开始
|
|
|
|
|
});
|
|
|
|
|
// Pjax 成功后,重新加载下面的函数
|
|
|
|
|
document.addEventListener("pjax:success", function () {
|
|
|
|
|
// 重载图片懒加载插件的js
|
|
|
|
|
lazyimg_pjax()
|
|
|
|
|
lazyLoadInit({
|
|
|
|
|
coverColor: "white",
|
|
|
|
|
coverDiv: "<div style='display: flex; justify-content: center; align-items: center; height: 200px;color: #000000;'><span>优世界·一个记录生活点滴的小站</span></div>",
|
|
|
|
|
offsetBottom: 0,
|
|
|
|
|
offsetTopm: 0,
|
|
|
|
|
showTime: 1100
|
|
|
|
|
});
|
|
|
|
|
// 激活文章图片灯箱
|
|
|
|
|
window.ViewImage && ViewImage.init('#writing_content img,.text img , .memos-photo img , .gallery-thumbnail img');
|
|
|
|
|
});
|
|
|
|
|
// pjax加载完成
|
|
|
|
|
document.addEventListener("pjax:complete", function () {
|
|
|
|
|
// pjax完成动画
|
|
|
|
|
NProgress.done();
|
|
|
|
|
// 重载一些js样式调整
|
|
|
|
|
pjax_reload()
|
|
|
|
|
// 激活返回顶部插件
|
|
|
|
|
$(function () {
|
|
|
|
|
$.scrollUp({
|
|
|
|
|
animation: 'fade',
|
|
|
|
|
scrollImg: true
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-07-13 11:42:38 +08:00
|
|
|
|
2024-07-11 10:34:42 +08:00
|
|
|
});
|