preface
Project address jquery-pjax
text
Introduce resources
<script src="path/to/jquery.js"></script> <script src="path/to/jquery.pjax.js"></script>
Basic use
$(document).pjax(selector, [container], options)
-
Selector: the selector of the element of the click event to be bound -
container: only The selector for the Ajax container. -
options:
| | |
---|---|---|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
$(document).pjax( 'a[href^="' + THEME_CONFIG.SITE_URL + '"]:not(a[target="_blank"], [no-pjax],a[rel~="nofollow"])', { container: '#pjax-container', fragment: '#pjax-container', timeout: 8000 })
send
and complete
event
| | |
---|---|---|
| | |
| | |
$(document).on('pjax:send', function () { NProgress.start(); }).on('pjax:complete', function () { NProgress.done(); });
Overloading of some JS
//#Animation of header and # body $('#header').removeClass('slideOutUp').addClass('slideInDown'); $('#body').removeClass('fadeOut').addClass('fadeIn'); fancybox(); // Picture light box effect hitokoto(); // One word recapture lazyload(); // Image lazy loading hljs.init(); // Highlight. js code commentPlus.init(); // Some enhancements to comments, such as facial expressions postOther.init(); // Some enhancements in the article closeNav(); // Close navigation bar /**Overload part of the statistical code comes from QQ blog*/ /** baidu */ if (typeof _hmt !== ' undefined') { _hmt.push(['_trackPageview', location.pathname + location.search]); } /** google */ if (typeof ga !== ' undefined') { ga('send', 'pageview', location.pathname + location.search); }
Complete code
var doPjaxStartAction = function () { $("#header").toggleClass('slideOutUp'); $("#body").toggleClass('fadeOut'); $("#wrapper").hide(); } var doPjaxCompleteAction = function () { ('#header').removeClass('slideOutUp').addClass('slideInDown'); $('#body').removeClass('fadeOut').addClass('fadeIn'); fancybox(); // Picture light box effect hitokoto(); // One word recapture lazyload(); // Image lazy loading hljs.init(); // Highlight. js code commentPlus.init(); // Some enhancements to comments, such as facial expressions postOther.init(); // Some enhancements in the article closeNav(); // Close navigation bar /**Overload part of the statistical code comes from QQ blog*/ /** baidu */ if (typeof _hmt !== ' undefined') { _hmt.push(['_trackPageview', location.pathname + location.search]); } /** google */ if (typeof ga !== ' undefined') { ga('send', 'pageview', location.pathname + location.search); } } $(document).pjax('a[href^="' + THEME_CONFIG.SITE_URL + '"]:not(a[target="_blank"], [no-pjax],a[rel~="nofollow"])', { container: '#pjax-container', fragment: '#pjax-container', timeout: 8000 }).on('pjax:send', function () { NProgress.start(); doPjaxStartAction(); }).on('pjax:complete', function () { NProgress.done(); doPjaxCompleteAction(); })
Resolve comment can't be replied
$header .= "<script type=\"text/javascript\"> (function () { window.TypechoComment = { dom : function (id) { return document.getElementById(id); }, create : function (tag, attr) { var el = document.createElement(tag); for (var key in attr) { el.setAttribute(key, attr[key]); } return el; }, reply : function (cid, coid) { var comment = this.dom(cid), parent = comment.parentNode, response = this.dom('" . $this->respondId . "'), input = this.dom('comment-parent'), form = 'form' == response.tagName ? response : response.getElementsByTagName('form')[0], textarea = response.getElementsByTagName('textarea')[0]; if (null == input) { input = this.create('input', { 'type' : 'hidden', 'name' : 'parent', 'id' : 'comment-parent' }); form.appendChild(input); } input.setAttribute('value', coid); if (null == this.dom('comment-form-place-holder')) { var holder = this.create('div', { 'id' : 'comment-form-place-holder' }); response.parentNode.insertBefore(holder, response); } comment.appendChild(response); this.dom('cancel-comment-reply-link').style.display = ''; if (null != textarea && 'text' == textarea.name) { textarea.focus(); } return false; }, cancelReply : function () { var response = this.dom('{$this->respondId}'), holder = this.dom('comment-form-place-holder'), input = this.dom('comment-parent'); if (null != input) { input.parentNode.removeChild(input); } if (null == holder) { return true; } this.dom('cancel-comment-reply-link').style.display = 'none'; holder.parentNode.insertBefore(response, holder); return false; } }; })(); </script> ";
$this->respondId
other
Postscript
Not limited to one container It does not depend on jQuery and is very small