From b4e5f49e7569563e369566fcf144f8b7c3840ac1 Mon Sep 17 00:00:00 2001 From: brettp Date: Sat, 19 Feb 2011 03:46:50 +0000 Subject: Pulled the confirm link output view's JS into elgg.us. Any links with elgg-requires-confirmation will get a confirm box with the title of the anchor tag as the question, or the default "Are you sure?" if that doesn't exist. git-svn-id: http://code.elgg.org/elgg/trunk@8310 36083f99-b078-4883-b0ff-0f9b5a30f544 --- js/lib/ui.js | 29 ++++++++++++++++++++++------- views/default/output/confirmlink.php | 12 ++++++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/js/lib/ui.js b/js/lib/ui.js index 7b67c5586..3448d6b35 100644 --- a/js/lib/ui.js +++ b/js/lib/ui.js @@ -3,7 +3,7 @@ elgg.provide('elgg.ui'); elgg.ui.init = function () { elgg.ui.initHoverMenu(); - + //if the user clicks a system message, make it disappear $('.elgg-system-messages li').live('click', function() { $(this).stop().fadeOut('fast'); @@ -14,11 +14,13 @@ elgg.ui.init = function () { $('.elgg-toggle').live('click', elgg.ui.toggle); $('.elgg-toggler').live('click', elgg.ui.toggles); - + $('.elgg-menu-page .elgg-menu-parent').live('click', elgg.ui.toggleMenu); $('.elgg-like-toggle').live('click', elgg.ui.toggleLikes); -} + + $('.elgg-requires-confirmation').live('click', elgg.ui.requiresConfirmation); +} /** * Toggles an element based on clicking a separate element @@ -32,9 +34,9 @@ elgg.ui.init = function () { */ elgg.ui.toggle = function(event) { event.preventDefault(); - + var id = $(this).toggleClass('elgg-state-active').attr('id').replace('toggler', 'togglee'); - + $('#' + id).slideToggle('medium'); } @@ -42,9 +44,9 @@ elgg.ui.toggles = function(event) { event.preventDefault(); $(this).toggleClass('elgg-state-active'); - + var togglees = $(this).attr('class').match(/elgg-toggles-[^ ]*/i); - + $('#' + togglees[0].replace('elgg-toggles-', '')).slideToggle('medium'); } @@ -134,4 +136,17 @@ elgg.ui.initHoverMenu = function(parent) { }); } +/** + * Calls a confirm() and prevents default if denied. + * + * @param {Object} event + * @return void + */ +elgg.ui.requiresConfirmation = function(e) { + var confirmText = $(this).attr('title') || elgg.echo('question:areyousure'); + if (!confirm(confirmText)) { + e.preventDefault(); + } +}; + elgg.register_event_handler('init', 'system', elgg.ui.init); \ No newline at end of file diff --git a/views/default/output/confirmlink.php b/views/default/output/confirmlink.php index aef33ab1f..20431e5a7 100644 --- a/views/default/output/confirmlink.php +++ b/views/default/output/confirmlink.php @@ -13,7 +13,6 @@ */ $confirm = elgg_extract('confirm', $vars, elgg_echo('question:areyousure')); - $encode = elgg_extract('text_encode', $vars, true); // always generate missing action tokens @@ -24,7 +23,16 @@ if ($encode) { $text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8', false); } -$vars['onclick'] = "return confirm('" . addslashes($confirm) . "')"; +$vars['title'] = addslashes($confirm); +if (isset($vars['class'])) { + if (!is_array($vars['class'])) { + $vars['class'] = array($vars['class']); + } + $vars['class'][] = 'elgg-requires-confirmation'; +} else { + $vars['class'] = 'elgg-requires-confirmation'; +} +//$vars['onclick'] = "return confirm('" . addslashes($confirm) . "')"; unset($vars['encode_text']); unset($vars['text']); -- cgit v1.2.3