aboutsummaryrefslogtreecommitdiff
path: root/views/default/js/walled_garden.php
blob: 09a478e93429d839196e943c2db1aad15b528846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
 * Walled garden JavaScript
 *
 * @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',
));
$cancel_button = json_encode($cancel_button);

if (0) { ?><script><?php }
?>

elgg.provide('elgg.walled_garden');

elgg.walled_garden.init = function () {

	$('.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) {
		var $wgs = $('.elgg-walledgarden-single');
		if ($wgs.is(':visible')) {
			$('.elgg-walledgarden-double').fadeToggle();
			$wgs.fadeToggle();
			$wgs.remove();
		}
		event.preventDefault();
	});
};

/**
 * 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('_', '-');
		//@todo display some visual element that indicates that loading of content is running
		elgg.get('walled_garden/' + view, {
			'success' : function(data) {
				var $wg = $('.elgg-body-walledgarden');
				$wg.append(data);
				$(id).find('input.elgg-button-submit').after(<?php echo $cancel_button; ?>);

				if (view == 'register' && $wg.hasClass('hidden')) {
					// this was a failed register, display the register form ASAP
					$('#elgg-walledgarden-login').toggle();
					$(id).toggle();
					$wg.removeClass('hidden');
				} else {
					$('#elgg-walledgarden-login').fadeToggle();
					$(id).fadeToggle();
				}

				if (view == 'register') {
					$('.elgg-form-register').submit(function () {
						// set short cookie indicating JS support
						var date = new Date();
						date.setTime(date.getTime() + (60 * 1000));
						elgg.session.cookie('elgg_js_support', '1', { expires: date });
					});
				}
			}
		});
		event.preventDefault();
	};
};

elgg.register_hook_handler('init', 'system', elgg.walled_garden.init);