window.onbeforeunload = function ( e ) { if(jQuery('#posttext').val() || jQuery('#comment').val() == true) { var e = e || window.event; if ( e ) { // For IE and Firefox e.returnValue = p2txt.unsaved_changes; } return p2txt.unsaved_changes; // For Safari } }; jQuery(function($) { /* * Insert new comment inline */ function insertCommentInline(postParent, comment_parent, commentHtml, showNotification) { postParent = "#"+postParent; if (0 == comment_parent) { if (0 == $(postParent).children('ul.commentlist').length) { $(postParent).append('
', loadtext: p2txt.loading, cancel: p2txt.cancel,
submit : p2txt.save, tooltip : '', width: '90%', onblur: 'ignore',
submitdata: {action:'prologue_inline_comment_save',_inline_edit: nonce}});
$(element).find('a.comment-edit-link').click(function() {
thisCommentEditArea.trigger("edit");
return false;
});
}
$(".single #postlist li > div.postcontent, .single #postlist li > h4, li[id^='prologue'] > div.postcontent, li[id^='comment'] > div.commentcontent, li[id^='prologue'] > h4, li[id^='comment'] > h4").hover(function() {
$(this).parents("li").eq(0).addClass('selected');
}, function() {
$(this).parents("li").eq(0).removeClass('selected');
});
break;
case "post" :
var thisPostEditArea;
if (inlineEditPosts != 0 && isUserLoggedIn) {
thisPostEditArea = $(element).children('div.editarea');
thisPostEditArea.editable(ajaxUrl, {event: 'edit',loadurl: ajaxUrl + '?action=prologue_load_post&_inline_edit=' + nonce,
id: 'post_ID', name: 'content', type: 'autogrow', cssclass: 'textedit',rows: '3',
indicator : '
', loadtext: p2txt.loading,
cancel: p2txt.cancel, submit: p2txt.save, tooltip : '', width: '90%', onblur: 'ignore',
submitdata: {action:'prologue_inline_save', _inline_edit: nonce}});
$(element).find('a.post-edit-link').click(function() {
thisPostEditArea.trigger("edit");
return false;
});
}
$(".single #postlist li > div.postcontent, .single #postlist li > h4, li[id^='prologue'] > div.postcontent, li[id^='comment'] > div.commentcontent, li[id^='prologue'] > h4, li[id^='comment'] > h4").hover(function() {
$(this).parents("li").eq(0).addClass('selected');
}, function() {
$(this).parents("li").eq(0).removeClass('selected');
});
break
}
}
/* On-load */
commentsLists = $("ul.commentlist");
$('#posttext').focus();
$(".single #postlist li > div.postcontent, .single #postlist li > h4, li[id^='prologue'] > div.postcontent, li[id^='comment'] > div.commentcontent, li[id^='prologue'] > h4, li[id^='comment'] > h4").hover(function() {
$(this).parents("li").eq(0).addClass('selected');
}, function() {
$(this).parents("li").eq(0).removeClass('selected');
});
$.ajaxSetup({
timeout: updateRate - 2000,
cache: false
});
$("#directions-keyboard").click(function(){
$('#help').toggle();
return false;
});
$("#help").click(function() {
$(this).toggle();
});
$("#togglecomments").click(function(){
hidecomments = !hidecomments;
var hideTxt = p2txt.hide_threads;
var showTxt = p2txt.show_threads;
if (hidecomments) {
commentLoop = false;
commentsLists.hide();
$(this).text(showTxt);
} else {
commentsLists.show();
$(this).text(hideTxt);
}
return false;
});
if (!isFrontPage) $("#togglecomments").click();
// Activate inline editing plugin
if ((inlineEditPosts || inlineEditComments ) && isUserLoggedIn) {
$.editable.addInputType('autogrow', {
element : function(settings, original) {
var textarea = $('');
if (settings.rows) {
textarea.attr('rows', settings.rows);
} else {
textarea.attr('rows', 4);
}
if (settings.cols) {
textarea.attr('cols', settings.cols);
} else {
textarea.attr('cols', 45);
}
textarea.width('95%');
$(this).append(textarea);
return(textarea);
},
plugin : function(settings, original) {
$('textarea', this).keypress(function(e) {autgrow(this, 3);});
$('textarea', this).focus(function(e) {autgrow(this, 3);});
}
});
}
// Set tabindex on all forms
var tabindex = 4;
$('form').each(function() {
$(':input',this).not('input[type=hidden]').each(function() {
var $input = $(this);
var tabname = $input.attr("name");
var tabnum = $input.attr("tabindex");
if(tabnum > 0) {
index = tabnum;
} else {
$input.attr("tabindex", tabindex);
}
tabindex++;
});
});
// Turn on automattic updating
if (prologuePostsUpdates && isUserLoggedIn) {
toggleUpdates('unewposts');
}
if (prologueCommentsUpdates && isUserLoggedIn) {
toggleUpdates('unewcomments');
}
// Check which posts are visibles and add to array and comment querystring
$("#main > ul > li").each(function() {
var thisId = $(this).attr("id");
vpostId = thisId.substring(thisId.indexOf('-') + 1);
postsOnPage.push(thisId);
postsOnPageQS += "&vp[]=" + vpostId;
});
// Bind actions to comments and posts
if (inlineEditPosts && isUserLoggedIn) {
$('div.editarea').editable(ajaxUrl, {event: 'edit', loadurl: ajaxUrl + '?action=prologue_load_post&_inline_edit=' + nonce,
id: 'post_ID', name: 'content', type: 'autogrow', cssclass: 'textedit', rows: '3',
indicator : '
', loadtext: p2txt.loading, cancel: p2txt.cancel,
submit : p2txt.save, tooltip : '', width: '90%', onblur: 'ignore',
submitdata: {action:'prologue_inline_save', _inline_edit: nonce}});
$('#main a.post-edit-link').click(function() {
$(this).parents('li').children('div.editarea').trigger("edit");
return false;
});
}
if (inlineEditComments && isUserLoggedIn) {
$('div.comment-edit').editable(ajaxUrl, {event: 'edit',loadurl: ajaxUrl + '?action=prologue_load_comment&_inline_edit=' + nonce,
id: 'comment_ID',name: 'comment_content', type : 'autogrow', cssclass: 'textedit', rows: '3',
indicator : '
', loadtext: p2txt.loading, cancel: p2txt.cancel, submit: p2txt.save,
tooltip: '', width: '90%', submitdata: {action:'prologue_inline_comment_save', _inline_edit: nonce} } );
$('a.comment-edit-link').click(function() {
$(this).parents('h4').next('div.comment-edit').trigger("edit");
return false;
});
}
$('#cancel-comment-reply-link').click(function() {
$('#comment').val('');
if (!isSingle) $("#respond").hide();
$(this).parents("li").removeClass('replying');
$(this).parents('#respond').prev("li").removeClass('replying');
$("#respond").removeClass('replying');
});
$('a.comment-reply-link').click(function() {
$('#main li').removeClass('replying');
$(this).parents("li").eq(0).addClass('replying');
$("#respond").addClass('replying').show();
$("#comment").focus();
});
function removeYellow() {
$('li.newcomment, tr.newcomment').each(function() {
if (isElementVisible(this)) {
$(this).animate({backgroundColor:'transparent'}, {duration: 2500}, function(){
$(this).removeClass('newcomment');
});
}
});
if (isFirstFrontPage) {
$('#main > ul > li.newupdates').each(function() {
if (isElementVisible(this)) {
$(this).animate({backgroundColor:'transparent'}, {duration: 2500});
$(this).removeClass('newupdates');
}
});
}
titleCount();
}
// Activate keyboard navigation
if (!isSingle) {
document.onkeydown = function(e) {
e = e || window.event;
if (e.target)
element = e.target;
else if (e.srcElement)
element = e.srcElement;
if( element.nodeType == 3)
element = element.parentNode;
if( e.ctrlKey == true || e.altKey == true || e.metaKey == true )
return;
var keyCode = (e.keyCode) ? e.keyCode : e.which;
if (keyCode && (keyCode != 27 && (element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') ) )
return;
switch(keyCode) {
// "c" key
case 67:
if (isFrontPage && isUserLoggedIn) {
if (commentLoop) {
$('#'+commentsOnPost[currComment]).removeClass('keyselected');
$('#'+postsOnPage[currPost]).removeClass('commentloop').addClass('keyselected');
commentLoop = false;
} else {
$('#'+postsOnPage[currPost]).removeClass('keyselected');
currPost =- 1;
}
if (!isElementVisible("#postbox"))
$.scrollTo('#postbox', 50);
$("#posttext").focus();
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
}
break;
// "k" key
case 75:
if (!commentLoop) {
if (currPost > 0) {
$('#'+postsOnPage[currPost]).removeClass('keyselected').children('h4').trigger('mouseleave');
currPost--;
if (0 != $('#'+postsOnPage[currPost]).children('ul.commentlist').length && !hidecomments) {
commentLoop = true;
commentsOnPost.length = 0;
$('#'+postsOnPage[currPost]).find("li[id^='comment']").each(function() {
var thisId = $(this).attr("id");
commentsOnPost.push(thisId);
});
currComment = commentsOnPost.length-1;
$('#'+commentsOnPost[currComment]).addClass('keyselected').children('h4').trigger('mouseenter');
if (!isElementVisible('#'+commentsOnPost[currComment]))
$.scrollTo('#'+commentsOnPost[currComment], 150);
return;
}
if (!isElementVisible('#'+postsOnPage[currPost]))
$.scrollTo('#'+postsOnPage[currPost], 50);
$('#'+postsOnPage[currPost]).addClass('keyselected').children('h4').trigger('mouseenter');
} else {
if (currPost <= 0) {
$('#'+postsOnPage[currPost]).removeClass('keyselected').children('h4').trigger('mouseleave');
$.scrollTo('#'+postsOnPage[postsOnPage.length-1], 50);
currPost = postsOnPage.length-1;
$('#'+postsOnPage[currPost]).addClass('keyselected').children('h4').trigger('mouseenter');
return;
}
}
} else {
if (currComment > 0) {
$('#'+commentsOnPost[currComment]).removeClass('keyselected').children('h4').trigger('mouseleave');
currComment--;
if (!isElementVisible('#'+commentsOnPost[currComment]))
$.scrollTo('#'+commentsOnPost[currComment], 50);
$('#'+commentsOnPost[currComment]).addClass('keyselected').children('h4').trigger('mouseenter');
}
else {
if (currComment <= 0) {
$('#'+commentsOnPost[currComment]).removeClass('keyselected').children('h4').trigger('mouseleave');
$('#'+postsOnPage[currPost]).addClass('keyselected').children('h4').trigger('mouseenter');
if (!isElementVisible('#'+postsOnPage[currPost]))
$.scrollTo('#'+postsOnPage[currPost], 50);
commentLoop = false;
return
}
}
}
break;
// "j" key
case 74:
removeYellow();
if (!commentLoop) {
if (0 != $('#'+postsOnPage[currPost]).children('ul.commentlist').length && !hidecomments) {
$.scrollTo('#'+postsOnPage[currPost], 150);
commentLoop = true;
currComment = 0;
commentsOnPost.length = 0;
$('#'+postsOnPage[currPost]).find("li[id^='comment']").each(function() {
var thisId = $(this).attr("id");
commentsOnPost.push(thisId);
});
$('#'+postsOnPage[currPost]).removeClass('keyselected').children('h4').trigger('mouseleave');
$('#'+commentsOnPost[currComment]).addClass('keyselected').children('h4').trigger('mouseenter');
return;
}
if (currPost < postsOnPage.length-1) {
$('#'+postsOnPage[currPost]).removeClass('keyselected').children('h4').trigger('mouseleave');
currPost++;
if (!isElementVisible('#'+postsOnPage[currPost]))
$.scrollTo('#'+postsOnPage[currPost], 50);
$('#'+postsOnPage[currPost]).addClass('keyselected').children('h4').trigger('mouseenter');
}
else if (currPost >= postsOnPage.length-1){
$('#'+postsOnPage[currPost]).removeClass('keyselected').children('h4').trigger('mouseleave');
$.scrollTo('#'+postsOnPage[0], 50);
currPost = 0;
$('#'+postsOnPage[currPost]).addClass('keyselected').children('h4').trigger('mouseenter');
return;
}
}
else {
if (currComment < commentsOnPost.length-1) {
$('#'+commentsOnPost[currComment]).removeClass('keyselected').children('h4').trigger('mouseleave');
currComment++;
if (!isElementVisible('#'+commentsOnPost[currComment]))
$.scrollTo('#'+commentsOnPost[currComment], 50);
$('#'+commentsOnPost[currComment]).addClass('keyselected').children('h4').trigger('mouseenter');
}
else if (currComment == commentsOnPost.length-1){
$('#'+commentsOnPost[currComment]).removeClass('keyselected').children('h4').trigger('mouseleave');
currPost++;
$('#'+postsOnPage[currPost]).addClass('keyselected').children('h4').trigger('mouseenter');
commentLoop = false;
return
}
}
break;
// "r" key
case 82:
if (!commentLoop) {
$('#'+postsOnPage[currPost]).removeClass('keyselected').children('h4').trigger('mouseleave');
$('#'+postsOnPage[currPost]).find('a.comment-reply-link:first').click();
} else {
$('#'+commentsOnPost[currComment]).removeClass('keyselected').children('h4').trigger('mouseleave');
$('#'+commentsOnPost[currComment]).find('a.comment-reply-link').click();
}
removeYellow();
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
break;
// "e" key
case 69:
if (!commentLoop) {
$('#'+postsOnPage[currPost]).find('a.post-edit-link:first').click();
}
else {
$('#'+commentsOnPost[currComment]).find('a.comment-edit-link:first').click();
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
break;
// "o" key
case 79:
$("#togglecomments").click();
if (typeof postsOnPage[currPost] != "undefined") {
if (!isElementVisible('#'+postsOnPage[currPost])) {
$.scrollTo('#'+postsOnPage[currPost], 150);
}
}
break;
// "t" key
case 84:
jumpToTop();
break;
// "esc" key
case 27:
if (element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') {
$('#cancel-comment-reply-link').click();
$(element).blur();
}
else {
$('#'+commentsOnPost[currComment]).each(function(e) {
$(this).removeClass('keyselected');
});
$('#'+postsOnPage[currPost]).each(function(e) {
$(this).addClass('keyselected');
});
commentLoop = false;
$('#'+postsOnPage[currPost]).each(function(e) {
$(this).removeClass('keyselected');
});
currPost =- 1;
}
$('#help').hide();
break;
case 0,191:
$("#help").toggle();
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
break;
}
}
}
// Check if recent comments widget is loaded
if ($("#recentcommentstable").length != 0) {
lcwidget = true;
}
// Activate Tag Suggestions for logged users on front page
if (isFrontPage && prologueTagsuggest && isUserLoggedIn)
$('input[name="tags"]').suggest(ajaxUrl + '?action=prologue_ajax_tag_search', { delay: 350, minchars: 2, multiple: true, multipleSep: ", " } );
// Actvate autgrow on textareas
if (isFrontPage) {
$('#posttext, #comment').keypress(function(e) {autgrow(this, 3);});
$('#posttext, #comment').focus(function(e) {autgrow(this, 3);});
}
// Activate tooltips on recent-comments widget
tooltip($("#recentcommentstable a.tooltip"));
// Catch new posts submit
$("#new_post").submit(function(trigger) {
newPost(trigger);
trigger.preventDefault();
});
// Catch new comment submit
if (isUserLoggedIn && !isSingle && !isPage)
$("#commentform").submit(function(trigger) {
newComment(trigger);
trigger.preventDefault();
$(this).parents("li").removeClass('replying');
$(this).parents('#respond').prev("li").removeClass('replying');
});
// Hide error messages on load
$('#posttext_error, #commenttext_error').hide();
// Check if new comments or updates appear on scroll and fade out
$(window).scroll(function() { removeYellow(); });
});