}\r
}\r
\r
-function show_message(object, msg, callback) {\r
- var div = $('<div class="vote-notification"><h3>' + msg + '</h3>(' +\r
- 'click to close' + ')</div>');\r
-\r
- div.click(function(event) {\r
- $(".vote-notification").fadeOut("fast", function() {\r
- $(this).remove();\r
- if (callback) {\r
- callback();\r
- }\r
+function show_dialog (extern) {\r
+ var default_close_function = function($diag) {\r
+ $diag.fadeOut('fast', function() {\r
+ $diag.remove();\r
});\r
- });\r
+ }\r
\r
- object.parent().append(div);\r
- div.fadeIn("fast");\r
-}\r
+ var options = {\r
+ extra_class: '',\r
+ pos: {\r
+ x: ($(window).width() / 2) + $(window).scrollLeft(),\r
+ y: ($(window).height() / 2) + $(window).scrollTop()\r
+ },\r
+ dim: false, \r
+ yes_text: messages.ok,\r
+ yes_callback: default_close_function,\r
+ no_text: messages.cancel,\r
+ show_no: false,\r
+ close_on_clickoutside: false\r
+ }\r
\r
-function load_prompt(object, url) {\r
- var $box = $('<div class="vote-notification">' +\r
- '<img src="/m/default/media/images/indicator.gif" />' +\r
- '</div>');\r
+ $.extend(options, extern);\r
\r
+ if (options.event != undefined) {\r
+ options.pos = {x: options.event.pageX, y: options.event.pageY};\r
+ }\r
\r
- object.parent().append($box);\r
- $box.fadeIn("fast");\r
+ var html = '<div class="dialog ' + options.extra_class + '" style="display: none;">'\r
+ + '<div class="dialog-content">' + options.html + '</div><div class="dialog-buttons">';\r
\r
- $box.load(url, function() {\r
- $box.find('.prompt-cancel').click(function() {\r
- $box.fadeOut('fast', function() {\r
- $box.remove();\r
- });\r
- return false;\r
+ if (options.show_no) {\r
+ html += '<button class="dialog-no">' + options.no_text + '</button>';\r
+ }\r
+\r
+ html += '<button class="dialog-yes">' + options.yes_text + '</button>'\r
+ + '</div></div>';\r
+\r
+ $dialog = $(html);\r
+ $('body').append($dialog);\r
+\r
+ if (options.dim === false) {\r
+ $dialog.css({\r
+ visibility: 'hidden',\r
+ display: 'block'\r
});\r
\r
- $box.find('.prompt-submit').click(function() {\r
- start_command();\r
- $.post(url, {prompt: $box.find('textarea').val()}, function(data) {\r
- $box.fadeOut('fast', function() {\r
- $box.remove();\r
- });\r
- process_ajax_response(data, object);\r
- }, 'json');\r
- return false;\r
+ options.dim = {w: $dialog.width(), h: $dialog.height()};\r
+\r
+ $dialog.css({\r
+ width: 1,\r
+ height: 1,\r
+ visibility: 'visible'\r
});\r
+ }\r
+\r
+ $dialog.css({\r
+ top: options.pos.y,\r
+ left: options.pos.x\r
+ });\r
+\r
+ $dialog.animate({\r
+ top: "-=" + (options.dim.h / 2),\r
+ left: "-=" + (options.dim.w / 2),\r
+ width: options.dim.w,\r
+ height: options.dim.h\r
+ }, 200);\r
+ \r
+ $dialog.find('.dialog-no').click(function() {\r
+ default_close_function($dialog);\r
});\r
-}\r
\r
-function show_prompt(object, msg, callback) {\r
- var div = $('<div class="vote-notification">' + msg + '<br />' +\r
- '<textarea class="command-prompt"></textarea><br />' +\r
- '<button class="prompt-cancel">Cancel</button>' +\r
- '<button class="prompt-ok">OK</button>' +\r
- '</div>');\r
+ $dialog.find('.dialog-yes').click(function() {\r
+ options.yes_callback($dialog);\r
+ });\r
\r
- function fade_out() {\r
- div.fadeOut("fast", function() { div.remove(); });\r
+ if (options.close_on_clickoutside) {\r
+ $dialog.one('clickoutside', function() {\r
+ default_close_function($dialog);\r
+ });\r
}\r
\r
- div.find('.prompt-cancel').click(fade_out);\r
+ return $dialog;\r
+}\r
\r
- div.find('.prompt-ok').click(function(event) {\r
- callback(div.find('.command-prompt').val());\r
- fade_out();\r
+function show_message(evt, msg, callback) {\r
+ var $dialog = show_dialog({\r
+ html: msg,\r
+ extra_class: 'warning',\r
+ event: evt,\r
+ yes_callback: function() {\r
+ $dialog.fadeOut('fast', function() {\r
+ $dialog.remove();\r
+ });\r
+ if (callback) {\r
+ callback();\r
+ }\r
+ },\r
+ close_on_clickoutside: true\r
});\r
+}\r
\r
- object.parent().append(div);\r
- div.fadeIn("fast"); \r
+function load_prompt(evt, url) {\r
+ $.get(url, function(data) {\r
+ var $dialog = show_dialog({\r
+ html: data,\r
+ extra_class: 'prompt',\r
+ event: evt,\r
+ yes_callback: function() {\r
+ var postvars = {};\r
+ $dialog.find('input, textarea, select').each(function() {\r
+ postvars[$(this).attr('name')] = $(this).val();\r
+ });\r
+ $.post(url, postvars, function(data) {\r
+ $dialog.fadeOut('fast', function() {\r
+ $dialog.remove();\r
+ });\r
+ process_ajax_response(data, evt);\r
+ }, 'json');\r
+ },\r
+ show_no: true\r
+ });\r
+ });\r
}\r
\r
-function process_ajax_response(data, el, callback) {\r
+function process_ajax_response(data, evt, callback) {\r
if (!data.success && data['error_message'] != undefined) {\r
- show_message(el, data.error_message, function() {if (callback) callback(true);});\r
+ show_message(evt, data.error_message, function() {if (callback) callback(true);});\r
end_command(false);\r
} else if (typeof data['commands'] != undefined){\r
for (var command in data.commands) {\r
}\r
\r
if (data['message'] != undefined) {\r
- show_message(el, data.message, function() {if (callback) callback(false);})\r
+ show_message(evt, data.message, function() {if (callback) callback(false);})\r
} else {\r
if (callback) callback(false);\r
}\r
}\r
\r
$(function() {\r
- $('a.ajax-command').live('click', function() {\r
+ $('a.ajax-command').live('click', function(evt) {\r
if (running) return false;\r
\r
var el = $(this);\r
\r
if (el.is('.withprompt')) {\r
- load_prompt(el, el.attr('href'));\r
+ load_prompt(evt, el.attr('href'));\r
+ } else if(el.is('.confirm')) {\r
+ $dialog = show_dialog({\r
+ html: messages.confirm,\r
+ extra_class: 'confirm',\r
+ event: evt,\r
+ yes_callback: function() {\r
+ start_command();\r
+ $.getJSON(el.attr('href'), function(data) {\r
+ process_ajax_response(data, evt);\r
+ $dialog.fadeOut('fast', function() {\r
+ $dialog.remove();\r
+ });\r
+ });\r
+ },\r
+ yes_text: messages.yes,\r
+ show_no: true,\r
+ no_text: messages.no\r
+ });\r
} else {\r
start_command();\r
$.getJSON(el.attr('href'), function(data) {\r
- process_ajax_response(data, el);\r
+ process_ajax_response(data, evt);\r
});\r
}\r
\r
return false\r
});\r
\r
+ $('.context-menu').each(function() {\r
+ var $menu = $(this);\r
+ var $trigger = $menu.find('.context-menu-trigger');\r
+ var $dropdown = $menu.find('.context-menu-dropdown');\r
+\r
+ $trigger.click(function() {\r
+ $dropdown.slideToggle('fast', function() {\r
+ if ($dropdown.is(':visible')) {\r
+ $dropdown.one('clickoutside', function() {\r
+ $dropdown.slideUp('fast')\r
+ });\r
+ }\r
+ }); \r
+ });\r
+ });\r
+\r
$('div.comment-form-container').each(function() {\r
var $container = $(this);\r
var $form = $container.find('form');\r
cleanup_form();\r
\r
function process_form_changes() {\r
- var length = $textarea.val().length;\r
+ var length = $textarea.val().replace(/[ ]{2,}/g," ").length;\r
\r
if (current_length == length)\r
return;\r
$chars_togo_message.show();\r
$chars_counter.html(min_length - length);\r
} else {\r
+ length = $textarea.val().length;\r
$chars_togo_message.hide();\r
$chars_left_message.show();\r
$chars_counter.html(max_length - length);\r
return false;\r
});\r
\r
- $button.click(function() {\r
+ $button.click(function(evt) {\r
if (running) return false;\r
\r
var post_data = {\r
\r
start_command();\r
$.post($form.attr('action'), post_data, function(data) {\r
- process_ajax_response(data, $button, function(error) {\r
+ process_ajax_response(data, evt, function(error) {\r
if (!error) {\r
cleanup_form();\r
hide_comment_form();\r
visible = true;\r
},\r
close: function(doPostback) {\r
- if (doPostback) {\r
- $.post(scriptUrl + $.i18n._("messages/") +\r
- $.i18n._("markread/"), { formdata: "required" });\r
- }\r
$(".notify").fadeOut("fast");\r
$("body").css("margin-top", "0");\r
visible = false;\r
isVisible: function() { return visible; }\r
};\r
} ();\r
+\r
+/*\r
+ * jQuery outside events - v1.1 - 3/16/2010\r
+ * http://benalman.com/projects/jquery-outside-events-plugin/\r
+ *\r
+ * Copyright (c) 2010 "Cowboy" Ben Alman\r
+ * Dual licensed under the MIT and GPL licenses.\r
+ * http://benalman.com/about/license/\r
+ */\r
+(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