From 77c2d19bc36450ce6f5bc6ddf6b2ddea510bd19b Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Fri, 10 Feb 2012 08:06:33 -0500 Subject: updated the walled garden js to use new js lib --- views/default/js/walled_garden.php | 52 +++++++++++++++++----------- views/default/page/layouts/walled_garden.php | 2 ++ 2 files changed, 33 insertions(+), 21 deletions(-) (limited to 'views') diff --git a/views/default/js/walled_garden.php b/views/default/js/walled_garden.php index e761e5869..13ec83c04 100644 --- a/views/default/js/walled_garden.php +++ b/views/default/js/walled_garden.php @@ -2,9 +2,10 @@ /** * Walled garden JavaScript * - * @todo update for new JS lib + * @since 1.8 */ +// note that this assumes the button view is not using single quotes $cancel_button = elgg_view('input/button', array( 'value' => elgg_echo('cancel'), 'class' => 'elgg-button-cancel mlm', @@ -13,27 +14,12 @@ $cancel_button = trim($cancel_button); ?> -$(document).ready(function() { +elgg.provide('elgg.walled_garden'); - $('.forgot_link').click(function(event) { - $.get('walled_garden/lost_password', function(data) { - $('.elgg-walledgarden-double').fadeToggle(); - $('.elgg-body-walledgarden').append(data); - $(".elgg-form-user-requestnewpassword").find('input.elgg-button-submit').after(''); - $('.elgg-walledgarden-single').fadeToggle(); - }); - event.preventDefault(); - }); +elgg.walled_garden.init = function () { - $('.registration_link').click(function(event) { - $.get('walled_garden/register', function(data) { - $('.elgg-walledgarden-double').fadeToggle(); - $('.elgg-body-walledgarden').append(data); - $('.elgg-form-register').find('input.elgg-button-submit').after(''); - $('.elgg-walledgarden-single').fadeToggle(); - }); - event.preventDefault(); - }); + $('.forgot_link').click(elgg.walled_garden.load('lost_password')); + $('.registration_link').click(elgg.walled_garden.load('register')); $('input.elgg-button-cancel').live('click', function(event) { if ($('.elgg-walledgarden-single').is(':visible')) { @@ -43,4 +29,28 @@ $(document).ready(function() { } event.preventDefault(); }); -}); \ No newline at end of file +}; + +/** + * Creates a closure for loading walled garden content through ajax + * + * @param {String} view Name of the walled garden view + * @return {Object} + */ +elgg.walled_garden.load = function(view) { + return function(event) { + var id = '#elgg-walledgarden-' + view; + id = id.replace('_', '-'); + elgg.get('walled_garden/' + view, { + 'success' : function(data) { + $('.elgg-body-walledgarden').append(data); + $(id).find('input.elgg-button-submit').after(''); + $('#elgg-walledgarden-login').fadeToggle(); + $(id).fadeToggle(); + }, + }); + event.preventDefault(); + }; +}; + +elgg.register_hook_handler('init', 'system', elgg.walled_garden.init); \ No newline at end of file diff --git a/views/default/page/layouts/walled_garden.php b/views/default/page/layouts/walled_garden.php index 5cddcbb77..6ecd941ef 100644 --- a/views/default/page/layouts/walled_garden.php +++ b/views/default/page/layouts/walled_garden.php @@ -4,11 +4,13 @@ * * @uses $vars['content'] Main content * @uses $vars['class'] CSS classes + * @uses $vars['id'] CSS id */ $class = elgg_extract('class', $vars, 'elgg-walledgarden-single'); echo elgg_view_module('walledgarden', '', $vars['content'], array( 'class' => $class, + 'id' => elgg_extract('id', $vars, ''), 'header' => ' ', 'footer' => ' ', )); -- cgit v1.2.3