X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/e8fe07136af2115ec92747acc68321062a6dd262..6d48df570d9b759d0fd18001fbcacc5c5a36a7e0:/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 20ecf93..8326eb0 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -124,78 +124,133 @@ var response_commands = { } } -function show_message(object, msg, callback) { - var div = $('

' + msg + '

(' + - 'click to close' + ')
'); - - div.click(function(event) { - $(".vote-notification").fadeOut("fast", function() { - $(this).remove(); - if (callback) { - callback(); - } +function show_dialog (extern) { + var default_close_function = function($diag) { + $diag.fadeOut('fast', function() { + $diag.remove(); }); - }); + } - object.parent().append(div); - div.fadeIn("fast"); -} + 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 + } -function load_prompt(object, url) { - var $box = $('
' + - '' + - '
'); + $.extend(options, extern); + if (options.event != undefined) { + options.pos = {x: options.event.pageX, y: options.event.pageY}; + } - object.parent().append($box); - $box.fadeIn("fast"); + var html = ''; + + $dialog = $(html); + $('body').append($dialog); + + if (options.dim === false) { + $dialog.css({ + visibility: 'hidden', + display: 'block' }); - $box.find('.prompt-submit').click(function() { - start_command(); - $.post(url, {prompt: $box.find('textarea').val()}, function(data) { - $box.fadeOut('fast', function() { - $box.remove(); - }); - process_ajax_response(data, object); - }, 'json'); - return false; + 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 }); -} -function show_prompt(object, msg, callback) { - var div = $('
' + msg + '
' + - '
' + - '' + - '' + - '
'); + $dialog.animate({ + top: "-=" + (options.dim.h / 2), + left: "-=" + (options.dim.w / 2), + width: options.dim.w, + height: options.dim.h + }, 200); + + $dialog.find('.dialog-no').click(function() { + default_close_function($dialog); + }); + + $dialog.find('.dialog-yes').click(function() { + options.yes_callback($dialog); + }); - function fade_out() { - div.fadeOut("fast", function() { div.remove(); }); + if (options.close_on_clickoutside) { + $dialog.one('clickoutside', function() { + default_close_function($dialog); + }); } - div.find('.prompt-cancel').click(fade_out); + return $dialog; +} - div.find('.prompt-ok').click(function(event) { - callback(div.find('.command-prompt').val()); - fade_out(); +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 }); +} - object.parent().append(div); - div.fadeIn("fast"); +function load_prompt(evt, url) { + $.get(url, function(data) { + var $dialog = show_dialog({ + html: data, + extra_class: 'prompt', + event: evt, + 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 + }); + }); } -function process_ajax_response(data, el, callback) { +function process_ajax_response(data, evt, callback) { if (!data.success && data['error_message'] != undefined) { - show_message(el, data.error_message, function() {if (callback) callback(true);}); + 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) { @@ -203,7 +258,7 @@ function process_ajax_response(data, el, callback) { } if (data['message'] != undefined) { - show_message(el, data.message, function() {if (callback) callback(false);}) + show_message(evt, data.message, function() {if (callback) callback(false);}) } else { if (callback) callback(false); } @@ -232,23 +287,57 @@ function end_command(success) { } $(function() { - $('a.ajax-command').live('click', function() { + $('a.ajax-command').live('click', function(evt) { if (running) return false; var el = $(this); if (el.is('.withprompt')) { - load_prompt(el, el.attr('href')); + load_prompt(evt, el.attr('href')); + } else if(el.is('.confirm')) { + $dialog = show_dialog({ + html: messages.confirm, + extra_class: 'confirm', + event: evt, + 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 + }); } else { start_command(); $.getJSON(el.attr('href'), function(data) { - process_ajax_response(data, el); + 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() { + $dropdown.slideUp('fast') + }); + } + }); + }); + }); + $('div.comment-form-container').each(function() { var $container = $(this); var $form = $container.find('form'); @@ -301,7 +390,7 @@ $(function() { cleanup_form(); function process_form_changes() { - var length = $textarea.val().length; + var length = $textarea.val().replace(/[ ]{2,}/g," ").length; if (current_length == length) return; @@ -317,6 +406,7 @@ $(function() { $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); @@ -385,7 +475,7 @@ $(function() { return false; }); - $button.click(function() { + $button.click(function(evt) { if (running) return false; var post_data = { @@ -398,7 +488,7 @@ $(function() { start_command(); $.post($form.attr('action'), post_data, function(data) { - process_ajax_response(data, $button, function(error) { + process_ajax_response(data, evt, function(error) { if (!error) { cleanup_form(); hide_comment_form(); @@ -925,10 +1015,6 @@ 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; @@ -937,21 +1023,12 @@ var notify = function() { }; } (); - -function changeSideBar(enabled_bar) { - $(currentSideBar).hide(); - currentSideBar = enabled_bar; - $(currentSideBar).fadeIn('slow'); - -} - -var currentSideBar = 'div#title_side_bar'; -$(function () { - $('div#editor_side_bar').hide(); - $('div#tags_side_bar').hide(); - - $('input#id_title').focus(function(){changeSideBar('div#title_side_bar')}); - $('textarea#editor').focus(function(){changeSideBar('div#editor_side_bar')}); - $('input#id_tags').focus(function(){changeSideBar('div#tags_side_bar')}); -}); - +/* + * 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"); \ No newline at end of file