X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/ecd9fa68ea62902f79744b458e4ea2ed95ce00ac..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 c78367b..487b1db 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -49,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'); @@ -163,6 +160,8 @@ function show_dialog (extern) { $dialog = $(html); $('body').append($dialog); + var message = $('.dialog-content')[0]; + message.style.visibility = "hidden"; if (options.dim === false) { $dialog.css({ @@ -189,8 +188,10 @@ function show_dialog (extern) { left: "-=" + (options.dim.w / 2), width: options.dim.w, height: options.dim.h - }, 200); - + }, 200, function() { + message.style.visibility = "visible"; + }); + $dialog.find('.dialog-no').click(function() { default_close_function($dialog); }); @@ -225,12 +226,11 @@ function show_message(evt, msg, callback) { }); } -function load_prompt(evt, url) { +function load_prompt(evt, el, url) { $.get(url, function(data) { - var $dialog = show_dialog({ - html: data, + var doptions = { + html: data, extra_class: 'prompt', - event: evt, yes_callback: function() { var postvars = {}; $dialog.find('input, textarea, select').each(function() { @@ -244,7 +244,13 @@ function load_prompt(evt, url) { }, 'json'); }, show_no: true - }); + } + + if (!el.is('.centered')) { + doptions.event = evt; + } + + var $dialog = show_dialog(doptions); }); } @@ -290,15 +296,16 @@ $(function() { $('a.ajax-command').live('click', function(evt) { if (running) return false; + $('.context-menu-dropdown').slideUp('fast'); + var el = $(this); if (el.is('.withprompt')) { - load_prompt(evt, el.attr('href')); + load_prompt(evt, el, el.attr('href')); } else if(el.is('.confirm')) { - $dialog = show_dialog({ + var doptions = { html: messages.confirm, extra_class: 'confirm', - event: evt, yes_callback: function() { start_command(); $.getJSON(el.attr('href'), function(data) { @@ -311,7 +318,12 @@ $(function() { 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) { @@ -331,7 +343,8 @@ $(function() { $dropdown.slideToggle('fast', function() { if ($dropdown.is(':visible')) { $dropdown.one('clickoutside', function() { - $dropdown.slideUp('fast') + if ($dropdown.is(':visible')) + $dropdown.slideUp('fast'); }); } }); @@ -340,175 +353,182 @@ $(function() { $('div.comment-form-container').each(function() { var $container = $(this); - var $form = $container.find('form'); - 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'); - 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 chars_limits = $chars_counter.html().split('|'); + 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'); - 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 $add_comment_link = $comment_tools.find('.add-comment-link'); - var hcheck = !($.browser.msie || $.browser.opera); + var chars_limits = $chars_counter.html().split('|'); - $textarea.css("padding-top", 0).css("padding-bottom", 0).css("resize", "none"); - textarea.style.overflow = 'hidden'; - + var min_length = parseInt(chars_limits[0]); + var max_length = parseInt(chars_limits[1]); - 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(); - - $chars_counter.removeClass('warn'); - $chars_counter.html(min_length); - $button.attr("disabled","disabled"); - - interval = null; - } + var warn_length = max_length - 30; + var current_length = 0; + var comment_in_form = false; + var interval = null; - cleanup_form(); + var hcheck = !($.browser.msie || $.browser.opera); - function process_form_changes() { - var length = $textarea.val().length; + $textarea.css("padding-top", 0).css("padding-bottom", 0).css("resize", "none"); + textarea.style.overflow = 'hidden'; - 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'); - } + 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; - if (length < min_length) { $chars_left_message.hide(); $chars_togo_message.show(); - $chars_counter.html(min_length - length); - } else { - $chars_togo_message.hide(); - $chars_left_message.show(); - $chars_counter.html(max_length - length); - } - if (length > max_length || length < min_length) { + $chars_counter.removeClass('warn'); + $chars_counter.html(min_length); $button.attr("disabled","disabled"); - } else { - $button.removeAttr("disabled"); + + interval = null; } - var current_height = textarea.style.height; - if (hcheck) - textarea.style.height = "0px"; + cleanup_form(); - var h = Math.max(80, textarea.scrollHeight); - textarea.style.height = current_height; - $textarea.animate({height: h + 'px'}, 50); + function process_form_changes() { + var length = $textarea.val().replace(/[ ]{2,}/g," ").length; - current_length = length; - } + if (current_length == length) + return; - function show_comment_form() { - $container.slideDown('slow'); - $add_comment_link.fadeOut('slow'); - window.setInterval(function() { - process_form_changes(); - }, 200); - } + 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'); + } - function hide_comment_form() { - if (interval != null) { - window.clearInterval(interval); - interval = null; + if (length < min_length) { + $chars_left_message.hide(); + $chars_togo_message.show(); + $chars_counter.html(min_length - length); + } else { + length = $textarea.val().length; + $chars_togo_message.hide(); + $chars_left_message.show(); + $chars_counter.html(max_length - length); + } + + 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; } - $container.slideUp('slow'); - $add_comment_link.fadeIn('slow'); - } - $add_comment_link.click(function(){ - cleanup_form(); - show_comment_form(); - return false; - }); + function show_comment_form() { + $container.slideDown('slow'); + $add_comment_link.fadeOut('slow'); + $textarea.focus(); + window.setInterval(function() { + process_form_changes(); + }, 200); + } - $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; - }); + function hide_comment_form() { + if (interval != null) { + window.clearInterval(interval); + interval = null; + } + $container.slideUp('slow'); + $add_comment_link.fadeIn('slow'); + } + + $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); + $('#' + $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_in_form = comment_id; + comment_in_form = comment_id; - $.get($link.attr('href'), function(data) { - $textarea.val(data); + $.get($link.attr('href'), function(data) { + $textarea.val(data); + }); + + $comment.slideUp('slow'); + show_comment_form(); + return false; }); - - $comment.slideUp('slow'); - show_comment_form(); - return false; - }); - $button.click(function(evt) { - if (running) return false; + $button.click(function(evt) { + if (running) return false; - var post_data = { - comment: $textarea.val() - } + var post_data = { + comment: $textarea.val() + } - if (comment_in_form) { - post_data['id'] = comment_in_form; - } + if (comment_in_form) { + post_data['id'] = comment_in_form; + } - start_command(); - $.post($form.attr('action'), post_data, function(data) { - process_ajax_response(data, evt, function(error) { - if (!error) { - cleanup_form(); - hide_comment_form(); - } - }); + start_command(); + $.post($form.attr('action'), post_data, function(data) { + process_ajax_response(data, evt, function(error) { + if (!error) { + cleanup_form(); + hide_comment_form(); + } + }); - }, "json"); - - return false; - }); + }, "json"); - $cancel.click(function() { - if (comment_in_form) { - $comment = $('#comment-' + comment_in_form).slideDown('slow'); - } - hide_comment_form(); + 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(); + } + return false; + }); + } + + $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, $; @@ -532,7 +552,8 @@ function pickedTags(){ var call_settings = { type:'POST', - url:url + url:url, + data: '' }; if (callback !== false){ call_settings.success = callback; @@ -659,7 +680,7 @@ function pickedTags(){ init: function(){ collectPickedTags(); setupHideIgnoredQuestionsControl(); - $("#interestingTagInput, #ignoredTagInput").autocomplete("/matching_tags", { + $("#interestingTagInput, #ignoredTagInput").autocomplete(messages.matching_tags_url, { minChars: 1, matchContains: true, max: 20, @@ -681,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){ @@ -1030,4 +1046,35 @@ var notify = function() { * 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"); \ No newline at end of file +(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