X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/7f14cb747791cc03d44045e2a0fcfb73eed298e4..de421bfc33978f3d11fdbe247d6c34ff205e39eb:/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 e372638..487b1db 100644
--- a/forum/skins/default/media/js/osqa.main.js
+++ b/forum/skins/default/media/js/osqa.main.js
@@ -1,4 +1,8 @@
var response_commands = {
+ refresh_page: function() {
+ window.location.reload(true)
+ },
+
update_post_score: function(id, inc) {
var $score_board = $('#post-' + id + '-score');
var current = parseInt($score_board.html())
@@ -45,10 +49,7 @@ var response_commands = {
}
},
- mark_accepted: function(id) {
- $('.accepted-answer').removeClass('accepted-answer');
- $('.accept-answer.on').removeClass('on');
-
+ mark_accepted: function(id) {
var $answer = $('#answer-container-' + id);
$answer.addClass('accepted-answer');
$answer.find('.accept-answer').addClass('on');
@@ -68,7 +69,7 @@ var response_commands = {
});
},
- insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url) {
+ insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url) {
var $container = $('#comments-container-' + post_id);
var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();
@@ -76,7 +77,8 @@ var response_commands = {
.replace(new RegExp('%COMMENT%', 'g'), comment)
.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('%DELETE_URL%', 'g'), delete_url)
+ .replace(new RegExp('%EDIT_URL%', 'g'), edit_url);
$container.append(skeleton);
@@ -100,6 +102,16 @@ var response_commands = {
}
},
+ unmark_deleted: function(post_type, post_id) {
+ if (post_type == 'answer') {
+ var $answer = $('#answer-container-' + post_id);
+ $answer.removeClass('deleted');
+ } else {
+ var $container = $('#question-table');
+ $container.removeClass('deleted');
+ }
+ },
+
set_subscription_button: function(text) {
$('.subscription_switch').html(text);
},
@@ -109,127 +121,373 @@ var response_commands = {
}
}
-function show_message(object, msg) {
- var div = $('
' + msg + '
(' +
- 'click to close' + ')');
+function show_dialog (extern) {
+ var default_close_function = function($diag) {
+ $diag.fadeOut('fast', function() {
+ $diag.remove();
+ });
+ }
+
+ var options = {
+ extra_class: '',
+ pos: {
+ x: ($(window).width() / 2) + $(window).scrollLeft(),
+ y: ($(window).height() / 2) + $(window).scrollTop()
+ },
+ dim: false,
+ yes_text: messages.ok,
+ yes_callback: default_close_function,
+ no_text: messages.cancel,
+ show_no: false,
+ close_on_clickoutside: false
+ }
+
+ $.extend(options, extern);
+
+ if (options.event != undefined) {
+ options.pos = {x: options.event.pageX, y: options.event.pageY};
+ }
+
+ var html = '';
+
+ $dialog = $(html);
+ $('body').append($dialog);
+ var message = $('.dialog-content')[0];
+ message.style.visibility = "hidden";
+
+ if (options.dim === false) {
+ $dialog.css({
+ visibility: 'hidden',
+ display: 'block'
+ });
+
+ options.dim = {w: $dialog.width(), h: $dialog.height()};
+
+ $dialog.css({
+ width: 1,
+ height: 1,
+ visibility: 'visible'
+ });
+ }
+
+ $dialog.css({
+ top: options.pos.y,
+ left: options.pos.x
+ });
+
+ $dialog.animate({
+ top: "-=" + (options.dim.h / 2),
+ left: "-=" + (options.dim.w / 2),
+ width: options.dim.w,
+ height: options.dim.h
+ }, 200, function() {
+ message.style.visibility = "visible";
+ });
- div.click(function(event) {
- $(".vote-notification").fadeOut("fast", function() { $(this).remove(); });
+ $dialog.find('.dialog-no').click(function() {
+ default_close_function($dialog);
});
- object.parent().append(div);
- div.fadeIn("fast");
+ $dialog.find('.dialog-yes').click(function() {
+ options.yes_callback($dialog);
+ });
+
+ if (options.close_on_clickoutside) {
+ $dialog.one('clickoutside', function() {
+ default_close_function($dialog);
+ });
+ }
+
+ return $dialog;
}
-function process_ajax_response(data, el) {
+function show_message(evt, msg, callback) {
+ var $dialog = show_dialog({
+ html: msg,
+ extra_class: 'warning',
+ event: evt,
+ yes_callback: function() {
+ $dialog.fadeOut('fast', function() {
+ $dialog.remove();
+ });
+ if (callback) {
+ callback();
+ }
+ },
+ close_on_clickoutside: true
+ });
+}
+
+function load_prompt(evt, el, url) {
+ $.get(url, function(data) {
+ var doptions = {
+ html: data,
+ extra_class: 'prompt',
+ yes_callback: function() {
+ var postvars = {};
+ $dialog.find('input, textarea, select').each(function() {
+ postvars[$(this).attr('name')] = $(this).val();
+ });
+ $.post(url, postvars, function(data) {
+ $dialog.fadeOut('fast', function() {
+ $dialog.remove();
+ });
+ process_ajax_response(data, evt);
+ }, 'json');
+ },
+ show_no: true
+ }
+
+ if (!el.is('.centered')) {
+ doptions.event = evt;
+ }
+
+ var $dialog = show_dialog(doptions);
+ });
+}
+
+function process_ajax_response(data, evt, callback) {
if (!data.success && data['error_message'] != undefined) {
- show_message(el, data.error_message)
+ show_message(evt, data.error_message, function() {if (callback) callback(true);});
+ end_command(false);
} else if (typeof data['commands'] != undefined){
for (var command in data.commands) {
response_commands[command].apply(null, data.commands[command])
}
if (data['message'] != undefined) {
- show_message(el, data.message)
+ show_message(evt, data.message, function() {if (callback) callback(false);})
+ } else {
+ if (callback) callback(false);
}
+ end_command(true);
+ }
+}
+
+var running = false;
+
+function start_command() {
+ $('body').append($(''));
+ running = true;
+}
+
+function end_command(success) {
+ if (success) {
+ $('#command-loader').addClass('success');
+ $('#command-loader').fadeOut("slow", function() {
+ $('#command-loader').remove();
+ running = false;
+ });
+ } else {
+ $('#command-loader').remove();
+ running = false;
}
}
$(function() {
- $('a.ajax-command').live('click', function() {
+ $('a.ajax-command').live('click', function(evt) {
+ if (running) return false;
+
+ $('.context-menu-dropdown').slideUp('fast');
+
var el = $(this);
- $.getJSON(el.attr('href'), function(data) {
- process_ajax_response(data, el);
- });
+
+ if (el.is('.withprompt')) {
+ load_prompt(evt, el, el.attr('href'));
+ } else if(el.is('.confirm')) {
+ var doptions = {
+ html: messages.confirm,
+ extra_class: 'confirm',
+ yes_callback: function() {
+ start_command();
+ $.getJSON(el.attr('href'), function(data) {
+ process_ajax_response(data, evt);
+ $dialog.fadeOut('fast', function() {
+ $dialog.remove();
+ });
+ });
+ },
+ yes_text: messages.yes,
+ show_no: true,
+ no_text: messages.no
+ }
+
+ if (!el.is('.centered')) {
+ doptions.event = evt;
+ }
+ var $dialog = show_dialog(doptions);
+ } else {
+ start_command();
+ $.getJSON(el.attr('href'), function(data) {
+ process_ajax_response(data, evt);
+ });
+ }
return false
});
+ $('.context-menu').each(function() {
+ var $menu = $(this);
+ var $trigger = $menu.find('.context-menu-trigger');
+ var $dropdown = $menu.find('.context-menu-dropdown');
+
+ $trigger.click(function() {
+ $dropdown.slideToggle('fast', function() {
+ if ($dropdown.is(':visible')) {
+ $dropdown.one('clickoutside', function() {
+ if ($dropdown.is(':visible'))
+ $dropdown.slideUp('fast');
+ });
+ }
+ });
+ });
+ });
+
$('div.comment-form-container').each(function() {
var $container = $(this);
- var $form = $container.find('form');
- var $textarea = $container.find('textarea');
- var $button = $container.find('input[type="submit"]');
- var $chars_left_message = $('.comment-chars-left');
- var $chars_counter = $container.find('.comments-char-left-count');
-
var $comment_tools = $container.parent().find('.comment-tools');
- var $add_comment_link = $comment_tools.find('.add-comment-link');
var $comments_container = $container.parent().find('.comments-container');
+
+ var $form = $container.find('form');
- var max_length = parseInt($chars_counter.html());
- var comment_in_form = false;
+ if ($form.length) {
+ var $textarea = $container.find('textarea');
+ var textarea = $textarea.get(0);
+ var $button = $container.find('.comment-submit');
+ var $cancel = $container.find('.comment-cancel');
+ var $chars_left_message = $container.find('.comments-chars-left-msg');
+ var $chars_togo_message = $container.find('.comments-chars-togo-msg');
+ var $chars_counter = $container.find('.comments-char-left-count');
- function cleanup_form() {
- $textarea.val('');
- $chars_counter.html(max_length);
- $chars_left_message.removeClass('warn');
- comment_in_form = false;
- }
+ var $add_comment_link = $comment_tools.find('.add-comment-link');
+
+ var chars_limits = $chars_counter.html().split('|');
+
+ var min_length = parseInt(chars_limits[0]);
+ var max_length = parseInt(chars_limits[1]);
+
+ var warn_length = max_length - 30;
+ var current_length = 0;
+ var comment_in_form = false;
+ var interval = null;
+
+ var hcheck = !($.browser.msie || $.browser.opera);
+
+ $textarea.css("padding-top", 0).css("padding-bottom", 0).css("resize", "none");
+ textarea.style.overflow = 'hidden';
+
+
+ function cleanup_form() {
+ $textarea.val('');
+ $textarea.css('height', 80);
+ $chars_counter.html(max_length);
+ $chars_left_message.removeClass('warn');
+ comment_in_form = false;
+ current_length = 0;
+
+ $chars_left_message.hide();
+ $chars_togo_message.show();
- cleanup_form();
+ $chars_counter.removeClass('warn');
+ $chars_counter.html(min_length);
+ $button.attr("disabled","disabled");
- function calculate_chars_left() {
- var length = $textarea.val().length;
- var allow = true;
+ interval = null;
+ }
+
+ cleanup_form();
+
+ function process_form_changes() {
+ var length = $textarea.val().replace(/[ ]{2,}/g," ").length;
+
+ if (current_length == length)
+ return;
+
+ if (length < warn_length && current_length >= warn_length) {
+ $chars_counter.removeClass('warn');
+ } else if (current_length < warn_length && length >= warn_length){
+ $chars_counter.addClass('warn');
+ }
- if (length < max_length) {
- if (length < max_length * 0.75) {
- $chars_left_message.removeClass('warn');
+ if (length < min_length) {
+ $chars_left_message.hide();
+ $chars_togo_message.show();
+ $chars_counter.html(min_length - length);
} else {
- $chars_left_message.addClass('warn');
+ length = $textarea.val().length;
+ $chars_togo_message.hide();
+ $chars_left_message.show();
+ $chars_counter.html(max_length - length);
}
- } else {
- allow = false;
+
+ if (length > max_length || length < min_length) {
+ $button.attr("disabled","disabled");
+ } else {
+ $button.removeAttr("disabled");
+ }
+
+ var current_height = textarea.style.height;
+ if (hcheck)
+ textarea.style.height = "0px";
+
+ var h = Math.max(80, textarea.scrollHeight);
+ textarea.style.height = current_height;
+ $textarea.animate({height: h + 'px'}, 50);
+
+ current_length = length;
}
- $chars_counter.html(max_length - length);
- return allow;
- }
+ function show_comment_form() {
+ $container.slideDown('slow');
+ $add_comment_link.fadeOut('slow');
+ $textarea.focus();
+ window.setInterval(function() {
+ process_form_changes();
+ }, 200);
+ }
- function show_comment_form() {
- $container.slideDown('slow');
- $add_comment_link.fadeOut('slow');
- }
+ function hide_comment_form() {
+ if (interval != null) {
+ window.clearInterval(interval);
+ interval = null;
+ }
+ $container.slideUp('slow');
+ $add_comment_link.fadeIn('slow');
+ }
- function hide_comment_form() {
- $container.slideUp('slow');
- $add_comment_link.fadeIn('slow');
- }
+ $add_comment_link.click(function(){
+ cleanup_form();
+ show_comment_form();
+ return false;
+ });
- $add_comment_link.click(function(){
- cleanup_form();
- show_comment_form();
- return false;
- });
+ $('#' + $comments_container.attr('id') + ' .comment-edit').live('click', function() {
+ var $link = $(this);
+ var comment_id = /comment-(\d+)-edit/.exec($link.attr('id'))[1];
+ var $comment = $('#comment-' + comment_id);
- $comment_tools.find('.show-all-comments-link').click(function() {
- $comments_container.find('.not_top_scorer').slideDown('slow');
- $(this).fadeOut('slow');
- $comment_tools.find('.comments-showing').fadeOut('slow');
- return false;
- });
+ comment_in_form = comment_id;
- $('#' + $comments_container.attr('id') + ' .comment-edit').live('click', function() {
- var $link = $(this);
- var comment_id = /comment-(\d+)-edit/.exec($link.attr('id'))[1];
- var $comment = $link.parents('.comment');
- var comment_text = $comment.find('.comment-text').text().trim();
-
- comment_in_form = comment_id;
- $textarea.val(comment_text);
- calculate_chars_left();
- $comment.slideUp('slow');
- show_comment_form();
- return false;
- });
+ $.get($link.attr('href'), function(data) {
+ $textarea.val(data);
+ });
+
+ $comment.slideUp('slow');
+ show_comment_form();
+ return false;
+ });
- $textarea.keyup(calculate_chars_left);
+ $button.click(function(evt) {
+ if (running) return false;
- $button.click(function() {
- if ($textarea.val().length > max_length) {
- show_message($button, "Your comment exceeds the max number of characters allowed.");
- } else {
var post_data = {
comment: $textarea.val()
}
@@ -238,18 +496,39 @@ $(function() {
post_data['id'] = comment_in_form;
}
+ start_command();
$.post($form.attr('action'), post_data, function(data) {
- process_ajax_response(data, $button);
+ process_ajax_response(data, evt, function(error) {
+ if (!error) {
+ cleanup_form();
+ hide_comment_form();
+ }
+ });
+
+ }, "json");
+
+ return false;
+ });
+
+ $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();
- }, "json")
- }
+ }
+ return false;
+ });
+ }
- hide_comment_form();
+ $comment_tools.find('.show-all-comments-link').click(function() {
+ $comments_container.find('.not_top_scorer').slideDown('slow');
+ $(this).fadeOut('slow');
+ $comment_tools.find('.comments-showing').fadeOut('slow');
return false;
});
});
-
-
});
//var scriptUrl, interestingTags, ignoredTags, tags, $;
@@ -273,7 +552,8 @@ function pickedTags(){
var call_settings = {
type:'POST',
- url:url
+ url:url,
+ data: ''
};
if (callback !== false){
call_settings.success = callback;
@@ -400,17 +680,19 @@ function pickedTags(){
init: function(){
collectPickedTags();
setupHideIgnoredQuestionsControl();
- $("#interestingTagInput, #ignoredTagInput").autocomplete(tags, {
+ $("#interestingTagInput, #ignoredTagInput").autocomplete(messages.matching_tags_url, {
minChars: 1,
matchContains: true,
max: 20,
- multiple: true,
- multipleSeparator: " ",
- formatItem: function(row, i, max) {
- return row.n + " ("+ row.c +")";
+ /*multiple: false, - the favorite tags and ignore tags don't let you do multiple tags
+ multipleSeparator: " "*/
+
+ formatItem: function(row, i, max, value) {
+ return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")";
},
- formatResult: function(row, i, max){
- return row.n;
+
+ formatResult: function(row, i, max, value){
+ return row[0];
}
});
@@ -420,11 +702,6 @@ function pickedTags(){
};
}
-$(document).ready( function(){
- if (window.tags != undefined)
- pickedTags().init();
-});
-
Hilite={elementid:"content",exact:true,max_nodes:1000,onload:true,style_name:"hilite",style_name_suffix:true,debug_referrer:""};Hilite.search_engines=[["local","q"],["cnprog\\.","q"],["google\\.","q"],["search\\.yahoo\\.","p"],["search\\.msn\\.","q"],["search\\.live\\.","query"],["search\\.aol\\.","userQuery"],["ask\\.com","q"],["altavista\\.","q"],["feedster\\.","q"],["search\\.lycos\\.","q"],["alltheweb\\.","q"],["technorati\\.com/search/([^\\?/]+)",1],["dogpile\\.com/info\\.dogpl/search/web/([^\\?/]+)",1,true]];Hilite.decodeReferrer=function(d){var g=null;var e=new RegExp("");for(var c=0;c2&&f[2]){a=decodeURIComponent(a)}a=a.replace(/\'|"/g,"");a=a.split(/[\s,\+\.]+/);return a}break}}return null};Hilite.decodeReferrerQS=function(f,d){var b=f.indexOf("?");var c;if(b>=0){var a=new String(f.substring(b+1));b=0;c=0;while((b>=0)&&((c=a.indexOf("=",b))>=0)){var e,g;e=a.substring(b,c);b=a.indexOf("&",c)+1;if(e==d){if(b<=0){return a.substring(c+1)}else{return a.substring(c+1,b-1)}}else{if(b<=0){return null}}}}return null};Hilite.hiliteElement=function(f,e){if(!e||f.childNodes.length==0){return}var c=new Array();for(var b=0;b0){c++;if(c>=Hilite.max_nodes){var b=function(){Hilite.walkElements(d,f,e)};setTimeout(b,50);return}if(d.nodeType==1){if(!a.test(d.tagName)&&d.childNodes.length>0){d=d.childNodes[0];f++;continue}}else{if(d.nodeType==3){d=e(d)}}if(d.nextSibling){d=d.nextSibling}else{while(f>0){d=d.parentNode;f--;if(d.nextSibling){d=d.nextSibling;break}}}}};if(Hilite.onload){if(window.attachEvent){window.attachEvent("onload",Hilite.hilite)}else{if(window.addEventListener){window.addEventListener("load",Hilite.hilite,false)}else{var __onload=window.onload;window.onload=function(){Hilite.hilite();__onload()}}}};
var mediaUrl = function(resource){
@@ -753,14 +1030,51 @@ var notify = function() {
visible = true;
},
close: function(doPostback) {
- if (doPostback) {
- $.post(scriptUrl + $.i18n._("messages/") +
- $.i18n._("markread/"), { formdata: "required" });
- }
$(".notify").fadeOut("fast");
$("body").css("margin-top", "0");
visible = false;
},
isVisible: function() { return visible; }
};
-} ();
\ No newline at end of file
+} ();
+
+/*
+ * jQuery outside events - v1.1 - 3/16/2010
+ * http://benalman.com/projects/jquery-outside-events-plugin/
+ *
+ * Copyright (c) 2010 "Cowboy" Ben Alman
+ * Dual licensed under the MIT and GPL licenses.
+ * http://benalman.com/about/license/
+ */
+(function($,c,b){$.map("click dblclick mousemove mousedown mouseup mouseover mouseout change select submit keydown keypress keyup".split(" "),function(d){a(d)});a("focusin","focus"+b);a("focusout","blur"+b);$.addOutsideEvent=a;function a(g,e){e=e||g+b;var d=$(),h=g+"."+e+"-special-event";$.event.special[e]={setup:function(){d=d.add(this);if(d.length===1){$(c).bind(h,f)}},teardown:function(){d=d.not(this);if(d.length===0){$(c).unbind(h)}},add:function(i){var j=i.handler;i.handler=function(l,k){l.target=k;j.apply(this,arguments)}}};function f(i){$(d).each(function(){var j=$(this);if(this!==i.target&&!j.has(i.target).length){j.triggerHandler(e,[i.target])}})}}})(jQuery,document,"outside");
+
+$(document).ready( function(){
+ pickedTags().init();
+
+ $('input#bnewaccount').click(function() {
+ $('#bnewaccount').disabled=true;
+ });
+});
+
+function yourWorkWillBeLost(e) {
+ if(browserTester('chrome')) {
+ return "You sure you want to leave? Your work will be lost.";
+ } else if(browserTester('safari')) {
+ return "You sure you want to leave? Your work will be lost.";
+ } else {
+ if(!e) e = window.event;
+ e.cancelBubble = true;
+ e.returnValue = 'If you leave your work will be lost.';
+
+ if (e.stopPropagation) {
+ e.stopPropagation();
+ e.preventDefault();
+ }
+ return e;
+ }
+}
+
+function browserTester(browserString) {
+ var test = navigator.userAgent;
+ return navigator.userAgent.toLowerCase().indexOf(browserString) > -1;
+}
\ No newline at end of file