walled_garden.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Walled garden JavaScript
  4. *
  5. * @since 1.8
  6. */
  7. $cancel_button = elgg_view('input/button', array(
  8. 'value' => elgg_echo('cancel'),
  9. 'class' => 'elgg-button-cancel mlm',
  10. ));
  11. $cancel_button = json_encode($cancel_button);
  12. if (0) { ?><script><?php }
  13. ?>
  14. elgg.provide('elgg.walled_garden');
  15. elgg.walled_garden.init = function () {
  16. // make sure it is loaded before using it in the click events
  17. require(['elgg/spinner']);
  18. $('.forgot_link').click(elgg.walled_garden.load('lost_password'));
  19. $('.registration_link').click(elgg.walled_garden.load('register'));
  20. $('input.elgg-button-cancel').live('click', function(event) {
  21. var $wgs = $('.elgg-walledgarden-single');
  22. if ($wgs.is(':visible')) {
  23. $('.elgg-walledgarden-double').fadeToggle();
  24. $wgs.fadeToggle();
  25. $wgs.remove();
  26. }
  27. event.preventDefault();
  28. });
  29. };
  30. /**
  31. * Creates a closure for loading walled garden content through ajax
  32. *
  33. * @param {String} view Name of the walled garden view
  34. * @return {Object}
  35. */
  36. elgg.walled_garden.load = function(view) {
  37. return function(event) {
  38. require(['elgg/spinner'], function(spinner) {
  39. var id = '#elgg-walledgarden-' + view;
  40. id = id.replace('_', '-');
  41. // @todo display some visual element that indicates that loading of content is running
  42. elgg.get('walled_garden/' + view, {
  43. beforeSend: spinner.start,
  44. complete: spinner.stop,
  45. success: function(data) {
  46. var $wg = $('.elgg-body-walledgarden');
  47. $wg.append(data);
  48. $(id).find('input.elgg-button-submit').after(<?php echo $cancel_button; ?>);
  49. if (view == 'register' && $wg.hasClass('hidden')) {
  50. // this was a failed registration, display the register form ASAP
  51. $('#elgg-walledgarden-login').toggle(false);
  52. $(id).toggle();
  53. $wg.removeClass('hidden');
  54. } else {
  55. $('#elgg-walledgarden-login').fadeToggle();
  56. $(id).fadeToggle();
  57. }
  58. }
  59. });
  60. });
  61. event.preventDefault();
  62. };
  63. };
  64. elgg.register_hook_handler('init', 'system', elgg.walled_garden.init);