X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/2c0d3ce5ba9e6e7cd64570028683be4bdb52f52a..493f5c31bcaf9f89774a9ab5489581ca4729d4a6:/forum/skins/default/media/js/osqa.main.js
diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js
index c5d0a43..17de794 100644
--- a/forum/skins/default/media/js/osqa.main.js
+++ b/forum/skins/default/media/js/osqa.main.js
@@ -1,3 +1,32 @@
+/**
+ * We do not want the CSRF protection enabled for the AJAX post requests, it causes only trouble.
+ * Get the csrftoken cookie and pass it to the X-CSRFToken HTTP request property.
+ */
+
+$('html').ajaxSend(function(event, xhr, settings) {
+ function getCookie(name) {
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ }
+ try {
+ if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
+ // Only send the token to relative URLs i.e. locally.
+ xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
+ }
+ } catch (e) {}
+});
+
var response_commands = {
refresh_page: function() {
window.location.reload(true)
@@ -53,12 +82,14 @@ var response_commands = {
var $answer = $('#answer-container-' + id);
$answer.addClass('accepted-answer');
$answer.find('.accept-answer').addClass('on');
+ $answer.find('.accept-answer').attr('title', $answer.find('.accept-answer').attr('bn:on'));
},
unmark_accepted: function(id) {
var $answer = $('#answer-container-' + id);
$answer.removeClass('accepted-answer');
$answer.find('.accept-answer').removeClass('on');
+ $answer.find('.accept-answer').attr('title', $answer.find('.accept-answer').attr('bn:off'));
},
remove_comment: function(id) {
@@ -69,7 +100,11 @@ var response_commands = {
});
},
- insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url) {
+ award_points: function(id) {
+ alert('ok');
+ },
+
+ insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url, can_convert) {
var $container = $('#comments-container-' + post_id);
var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();
@@ -78,9 +113,15 @@ var response_commands = {
.replace(new RegExp('%USERNAME%', 'g'), username)
.replace(new RegExp('%PROFILE_URL%', 'g'), profile_url)
.replace(new RegExp('%DELETE_URL%', 'g'), delete_url)
- .replace(new RegExp('%EDIT_URL%', 'g'), edit_url);
+ .replace(new RegExp('%EDIT_URL%', 'g'), edit_url)
+ .replace(new RegExp('%CONVERT_URL%', 'g'), convert_url);
+
+ $container.prepend(skeleton);
- $container.append(skeleton);
+ // Show the convert comment to answer tool only if the current comment can be converted
+ if (can_convert == true) {
+ $('#comment-' + comment_id + '-convert').show();
+ }
$('#comment-' + comment_id).slideDown('slow');
},
@@ -93,12 +134,12 @@ var response_commands = {
},
mark_deleted: function(post_type, post_id) {
- if (post_type == 'answer') {
- var $answer = $('#answer-container-' + post_id);
- $answer.addClass('deleted');
- } else {
+ if (post_type == 'question') {
var $container = $('#question-table');
$container.addClass('deleted');
+ } else {
+ var $el = $('#' + post_type + '-container-' + post_id);
+ $el.addClass('deleted');
}
},
@@ -118,6 +159,9 @@ var response_commands = {
set_subscription_status: function(text) {
$('.subscription-status').html(text);
+ },
+
+ copy_url: function(url) {
}
}
@@ -139,11 +183,17 @@ function show_dialog (extern) {
yes_callback: default_close_function,
no_text: messages.cancel,
show_no: false,
- close_on_clickoutside: false
+ close_on_clickoutside: false,
+ copy: false
}
$.extend(options, extern);
+ var copy_id = '';
+ if (options.copy) {
+ copy_id = ' id="copy_clip_button"'
+ }
+
if (options.event != undefined) {
options.pos = {x: options.event.pageX, y: options.event.pageY};
}
@@ -155,8 +205,7 @@ function show_dialog (extern) {
html += '';
}
- html += ''
- + '';
+ html += '' + '';
$dialog = $(html);
$('body').append($dialog);
@@ -182,10 +231,29 @@ function show_dialog (extern) {
top: options.pos.y,
left: options.pos.x
});
-
+
+ top_position_change = (options.dim.h / 2)
+ left_position_change = (options.dim.w / 2)
+
+ new_top_position = options.pos.y - top_position_change
+ new_left_position = options.pos.x - left_position_change
+
+ if (new_left_position < 0) {
+ left_position_change = 0
+ }
+ if (($(window).scrollTop() - new_top_position) > 0) {
+ top_position_change = 0
+ }
+ if ((options.event.pageY + options.dim.h) > ($(window).height() + $(window).scrollTop())) {
+ top_position_change = options.dim.h
+ }
+ if ((options.event.pageX + options.dim.w) > ($(window).width() + $(window).scrollLeft())) {
+ left_position_change = options.dim.w
+ }
+
$dialog.animate({
- top: "-=" + (options.dim.h / 2),
- left: "-=" + (options.dim.w / 2),
+ top: "-=" + top_position_change,
+ left: "-=" + left_position_change,
width: options.dim.w,
height: options.dim.h
}, 200, function() {
@@ -243,7 +311,12 @@ function load_prompt(evt, el, url) {
process_ajax_response(data, evt);
}, 'json');
},
- show_no: true
+ show_no: true,
+ copy: false
+ }
+
+ if (el.hasClass('copy')) {
+ $.extend(doptions, { yes_text : 'Copy', copy: true});
}
if (!el.is('.centered')) {
@@ -258,9 +331,12 @@ function process_ajax_response(data, evt, callback) {
if (!data.success && data['error_message'] != undefined) {
show_message(evt, data.error_message, function() {if (callback) callback(true);});
end_command(false);
- } else if (typeof data['commands'] != undefined){
+ }
+ if (typeof data['commands'] != undefined){
for (var command in data.commands) {
response_commands[command].apply(null, data.commands[command])
+
+
}
if (data['message'] != undefined) {
@@ -292,23 +368,47 @@ function end_command(success) {
}
}
+var comment_box_cursor_position = 0;
+function canned_comment(post_id, comment) {
+ textarea = $('#comment-' + post_id + '-form textarea')
+
+ // Get the text from the beginning to the caret
+ textarea_start = textarea.val().substr(0, comment_box_cursor_position)
+
+ // Get the text from the caret to the end
+ textarea_end = textarea.val().substr(comment_box_cursor_position, textarea.val().length)
+
+ textarea.val(textarea_start + comment + textarea_end);
+}
+
$(function() {
+ $('textarea.commentBox').bind('keydown keyup mousedown mouseup mousemove', function(evt) {
+ comment_box_cursor_position = $(this).caret().start;
+ });
+
+ $('textarea.commentBox').blur(function() {
+ //alert(comment_box_cursor_position);
+ });
+
$('a.ajax-command').live('click', function(evt) {
if (running) return false;
- $('.context-menu-dropdown').slideUp('fast');
-
var el = $(this);
+ var ajax_url = el.attr('href')
+ ajax_url = ajax_url + "?nocache=" + new Date().getTime()
+
+ $('.context-menu-dropdown').slideUp('fast');
+
if (el.is('.withprompt')) {
- load_prompt(evt, el, el.attr('href'));
+ load_prompt(evt, el, ajax_url);
} else if(el.is('.confirm')) {
var doptions = {
html: messages.confirm,
extra_class: 'confirm',
yes_callback: function() {
start_command();
- $.getJSON(el.attr('href'), function(data) {
+ $.getJSON(ajax_url, function(data) {
process_ajax_response(data, evt);
$dialog.fadeOut('fast', function() {
$dialog.remove();
@@ -326,7 +426,7 @@ $(function() {
var $dialog = show_dialog(doptions);
} else {
start_command();
- $.getJSON(el.attr('href'), function(data) {
+ $.getJSON(ajax_url, function(data) {
process_ajax_response(data, evt);
});
}
@@ -449,7 +549,7 @@ $(function() {
$container.slideDown('slow');
$add_comment_link.fadeOut('slow');
$textarea.focus();
- window.setInterval(function() {
+ interval = window.setInterval(function() {
process_form_changes();
}, 200);
}
@@ -510,11 +610,22 @@ $(function() {
return false;
});
- $cancel.click(function() {
- if (comment_in_form) {
- $comment = $('#comment-' + comment_in_form).slideDown('slow');
+ // Submit comment with CTRL + Enter
+ $textarea.keydown(function(e) {
+ if (e.ctrlKey && e.keyCode == 13 && !$button.attr('disabled')) {
+ // console.log('submit');
+ $(this).parent().find('input.comment-submit').click();
+ }
+ });
+
+ $cancel.click(function(event) {
+ if (confirm("You will lose all of your changes in this comment. Do you still wish to proceed?")){
+ if (comment_in_form) {
+ $comment = $('#comment-' + comment_in_form).slideDown('slow');
+ }
+ hide_comment_form();
+ cleanup_form();
}
- hide_comment_form();
return false;
});
}
@@ -526,6 +637,39 @@ $(function() {
return false;
});
});
+
+ if ($('#editor').length) {
+ var $editor = $('#editor');
+ var $previewer = $('#previewer');
+ var $container = $('#editor-metrics');
+
+ var initial_whitespace_rExp = /^[^A-Za-zÐ-Яа-Ñ0-9]+/gi;
+ var non_alphanumerics_rExp = rExp = /[^A-Za-zÐ-Яа-Ñ0-9]+/gi;
+ var editor_interval = null;
+
+ $editor.focus(function() {
+ if (editor_interval == null) {
+ editor_interval = window.setInterval(function() {
+ recalc_metrics();
+ }, 200);
+ }
+ });
+
+ function recalc_metrics() {
+ var text = $previewer.text();
+
+ var char_count = text.length;
+ var fullStr = text + " ";
+ var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
+ var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
+ var splitString = cleanedStr.split(" ");
+ var word_count = splitString.length - 1;
+
+ var metrics = char_count + " " + (char_count == 1 ? messages.character : messages.characters);
+ metrics += " / " + word_count + " " + (word_count == 1 ? messages.word : messages.words);
+ $container.html(metrics);
+ }
+ }
});
//var scriptUrl, interestingTags, ignoredTags, tags, $;
@@ -615,11 +759,11 @@ function pickedTags(){
new_tag.addClass('deletable-tag');
var tag_link = $('');
tag_link.attr('rel','tag');
- tag_link.attr('href', scriptUrl + $.i18n._('tags/') + tagname);
+ tag_link.attr('href', scriptUrl + $.i18n._('tags/') + tagname + '/');
tag_link.html(tagname);
- var del_link = $('');
+ var del_link = $('
');
del_link.addClass('delete-icon');
- del_link.attr('src', mediaUrl('/media/images/close-small-dark.png'));
+ del_link.attr('src', mediaUrl('media/images/close-small-dark.png'));
setupTagDeleteEvents(del_link, to_target, tagname, reason, true);
@@ -685,11 +829,11 @@ function pickedTags(){
multipleSeparator: " "*/
formatItem: function(row, i, max, value) {
- return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")";
+ return row[1] + " (" + row[2] + ")";
},
formatResult: function(row, i, max, value){
- return row[0];
+ return row[1];
}
});
@@ -856,8 +1000,8 @@ var i18nZh = {
'please confirm offensive':"??????????????????????",
'anonymous users cannot flag offensive posts':'???????????',
'cannot flag message as offensive twice':'???????',
- 'flag offensive cap exhausted':'?????????????5??????',
- 'need >15 points to report spam':"??+15??????????",
+ 'flag offensive cap exhausted':'?????????????5?Â??Â???',
+ 'need >15 points to report spam':"??+15??????Â???Â?",
'confirm delete':"?????/????????",
'anonymous users cannot delete/undelete':"???????????????",
'post recovered':"?????????????",
@@ -935,8 +1079,8 @@ var i18nEs = {
'insufficient privilege':'privilegio insuficiente',
'cannot pick own answer as best':'no puede escoger su propia respuesta como la mejor',
'anonymous users cannot select favorite questions':'usuarios anonimos no pueden seleccionar',
- 'please login':'por favor inicie sesión',
- 'anonymous users cannot vote':'usuarios anónimos no pueden votar',
+ 'please login':'por favor inicie sesión',
+ 'anonymous users cannot vote':'usuarios anónimos no pueden votar',
'>15 points requried to upvote': '>15 puntos requeridos para votar positivamente',
'>100 points required to downvote':'>100 puntos requeridos para votar negativamente',
'please see': 'por favor vea',
@@ -944,31 +1088,31 @@ var i18nEs = {
'daily vote cap exhausted':'cuota de votos diarios excedida',
'cannot revoke old vote':'no puede revocar un voto viejo',
'please confirm offensive':"por favor confirme ofensiva",
- 'anonymous users cannot flag offensive posts':'usuarios anónimos no pueden marcar publicaciones como ofensivas',
+ 'anonymous users cannot flag offensive posts':'usuarios anónimos no pueden marcar publicaciones como ofensivas',
'cannot flag message as offensive twice':'no puede marcar mensaje como ofensivo dos veces',
'flag offensive cap exhausted':'cuota para marcar ofensivas ha sido excedida',
'need >15 points to report spam':"necesita >15 puntos para reportar spam",
- 'confirm delete':"¿Está seguro que desea borrar esto?",
- 'anonymous users cannot delete/undelete':"usuarios anónimos no pueden borrar o recuperar publicaciones",
- 'post recovered':"publicación recuperada",
- 'post deleted':"publicación borrada?",
+ 'confirm delete':"¿Está seguro que desea borrar esto?",
+ 'anonymous users cannot delete/undelete':"usuarios anónimos no pueden borrar o recuperar publicaciones",
+ 'post recovered':"publicación recuperada",
+ 'post deleted':"publicación borrada?",
'add comment':'agregar comentario',
- 'community karma points':'reputación comunitaria',
- 'to comment, need':'para comentar, necesita reputación',
+ 'community karma points':'reputación comunitaria',
+ 'to comment, need':'para comentar, necesita reputación',
'delete this comment':'borrar este comentario',
'hide comments':"ocultar comentarios",
'add a comment':"agregar comentarios",
'comments':"comentarios",
- 'confirm delete comment':"¿Realmente desea borrar este comentario?",
+ 'confirm delete comment':"¿Realmente desea borrar este comentario?",
'characters':'caracteres faltantes',
'can write':'tiene ',
'click to close':'haga click para cerrar',
'loading...':'cargando...',
- 'tags cannot be empty':'las etiquetas no pueden estar vacías',
+ 'tags cannot be empty':'las etiquetas no pueden estar vacÃas',
'tablimits info':"hasta 5 etiquetas de no mas de 20 caracteres cada una",
- 'content cannot be empty':'el contenido no puede estar vacío',
+ 'content cannot be empty':'el contenido no puede estar vacÃo',
'content minchars': 'por favor introduzca mas de {0} caracteres',
- 'please enter title':'por favor ingrese un título',
+ 'please enter title':'por favor ingrese un tÃtulo',
'title minchars':"por favor introduzca al menos {0} caracteres",
'delete':'borrar',
'undelete': 'recuperar',
@@ -1005,15 +1149,16 @@ var i18n_dict = i18n[i18nLang];
Version 1.0.4
*/(function($){var textarea,staticOffset;var iLastMousePos=0;var iMin=32;var grip;$.fn.TextAreaResizer=function(){return this.each(function(){textarea=$(this).addClass('processed'),staticOffset=null;$(this).wrap('