上次在《instantclick 实现的全站无刷新》中大致说了一下实现方式,但是随着大家对文章的关注,我发现有些细节被我遗漏了,同时也发现了存在的问题,下面就接着上篇文章在说一说。

搜索功能这样的非超链接怎么实现不刷新
上篇文章的代码不兼容火狐浏览器,所以将上篇文章中提到的这个代码

$.extend({
getKey: function() {
 if(event.keyCode==13){  
$('#soux').get(0).click();
    } 
},
})

改为

$.extend({
getKey: function() {
  var theEvent = window.event || arguments.callee.caller.arguments[0];
        var code = theEvent.keyCode;
        if(code == 13){    
$('#soux').get(0).click();
        }
},
})

instantclick的情况添加ajax评论
需要将typecho的模板header.php中的

<?php $this->header('); ?>

改成

<?php $this->header('commentReply='); ?>

干掉模板自动输出的评论相关的js代码

然后手动将刚刚屏蔽的代码加入到comments.php里面

<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('<?php echo $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('<?php echo $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>
版权属于:泽泽社长
本文链接:https://blog.zezeshe.com/archives/instantclick-without-refresh-two.html
本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!