xhr.onload = function(){ if(xhr.status >= 200 && xhr.status < 400){ var data; try{data = JSON.parse(xhr.responseText);}catch(e){data = xhr.responseText} if(data && data.status === 'success'){ /** do not use srcset */ data.comment = data.comment.replace('srcset','data-srcset'); var $new_comment = parseHTML(data.comment); $new_comment.classList.add('new'); /** * if children respond */ if(_cache.$comment_parent.value != 0){ var $parent_comment_body = I(_config.prefix_comment_body_id + _cache.$comment_parent.value); $parent_comment_body.insertAdjacentHTML('afterend','<ul class="children">' + $new_comment.innerHTML + '</ul>'); /** restore respond */ addComment.cancelMove(); }else{ cache.$comment_list_container.appendChild($new_comment); } /** clear comment textarea */ _cache.$comment_ta.value = ''; /** hide comment loading */ var $comment_loading = cache.$comments.querySelector('.comment-loading'); if($comment_loading) $comment_loading.parentNode.removeChild($comment_loading); /** set comment number */ var $badge = I('comment-number-' + data.post_id); if($badge){ if(isNaN($badge.innerHTML)){ $badge.innerHTML = 1; }else{ $badge.innerHTML++; } } /** * show $comments */ cache.$comments.style.display = 'block'; /** show success tip */ ajax_loading_tip(data.status,data.msg,3); }else if(data && data.status === 'error'){ ajax_loading_tip(data.status,data.msg); /** focus */ _cache.$comment_ta.focus(); }else{ ajax_loading_tip('error',data); /** focus, select */ _cache.$comment_ta.select(); } }else{ ajax_loading_tip('error',window.THEME_CONFIG.lang.E01); } /** enable submit btn */ _cache.$submit_btn.removeAttribute('disabled'); };
function event_click_add(e){ e.preventDefault(); var tpl = that.$container.getAttribute('data-tpl').replace(/\%placeholder\%/ig, +new Date()), $new_item = paseHTML(tpl.trim()); /** bind del */ bind_click_del($new_item.querySelector('.del')); /** add callback */ if(typeof(that.new_tpl_callback) == 'function') that.new_tpl_callback($new_item); that.$container.appendChild($new_item); /** focus first input */ var $first_input = $new_item.querySelector('input'); if($first_input) $first_input.focus(); }
function set_cache(cpage,comments){ //console.log('set ' +cpage); if(!_cache.comments) _cache.comments = []; /** * for cache imgs */ var $tmp = parseHTML(comments), imgs = []; for(var i = 0, len = $tmp.length; i < len; i++){ var tmp_imgs = $tmp[i].querySelectorAll('img'); if(!tmp_imgs[0]) continue; for(var j = 0, j_len = tmp_imgs.length; j < j_len; j++){ imgs[j] = new Image(); imgs[j].src = tmp_imgs[j].src; } } _cache.comments[cpage] = comments; }
restore : function(){ var data = this.get(); if(!data || !data.can_restore) return false; /** post title */ if(data.title) cache.$post_title.value = data.title; /** post excerpt */ if(data.excerpt) cache.$post_excerpt.value = data.excerpt; /** post content */ if(data.content) set_editor_content(data.content); /** storage */ if(data.storage && document.querySelector('.theme_custom_storage-group')){ var $storage_container = I('theme_custom_storage-container'); var tpl = $storage_container.getAttribute('data-tpl'); $storage_container.innerHTML = ''; for(var i in data.storage){ var $tpl = paseHTML(tpl.replace(/\%placeholder\%/g,i)); /** name */ var $name = $tpl.querySelector('#theme_custom_storage-' + i + '-name'); if($name){ $name.value = data.storage[i].name; } /** url */ var $url = $tpl.querySelector('#theme_custom_storage-' + i + '-url'); $url.value = data.storage[i].url; /** url */ var $download_pwd = $tpl.querySelector('#theme_custom_storage-' + i + '-download-pwd'); $download_pwd.value = data.storage[i].download_pwd; /** url */ var $extract_pwd = $tpl.querySelector('#theme_custom_storage-' + i + '-extract-pwd'); $extract_pwd.value = data.storage[i].extract_pwd; $storage_container.appendChild($tpl); } } /** download_point henson add */ if(data.download_point) cache.$download_point.value = data.download_point; /** download_demourl henson add */ if(data.download_demourl) cache.$download_demourl.value = data.download_demourl; /** preset tags */ if(data.preset_tags){ for(var i in data.preset_tags){ var $preset_tag = I(data.preset_tags[i]); if($preset_tag) $preset_tag.checked = true; } } /** custom tags */ if(data.custom_tags){ for(var i in data.custom_tags){ var $custom_tag = I(i); if($custom_tag) $custom_tag.value = data.custom_tags[i]; } } /** source */ if(data.source){ if(data.source.source){ var $item = I('theme_custom_post_source-source-' + data.source.source), $reprint_url = I('theme_custom_post_source-reprint-url'), $reprint_author = I('theme_custom_post_source-reprint-author'); if($reprint_url) $reprint_url.value = data.source.reprint_url; if($reprint_url) $reprint_author.value = data.source.reprint_author; if($item) $item.checked = true; } } /** Preview */ if(data.preview){ /** set cover id */ if(data.cover_id) config.thumbnail_id = data.cover_id; for(var i in data.preview){ append_tpl(convert_to_preview_tpl_args(data.preview[i])); } } }