Elgg  Version 3.0
ui.js
Go to the documentation of this file.
1 elgg.provide('elgg.ui');
2 
3 elgg.ui.init = function () {
4  // @todo we need better documentation for this hack
5  // iOS Hover Event Class Fix
6  $('.elgg-page').attr("onclick", "return true");
7 
8  // add user hover menus
9  elgg.ui.initHoverMenu();
10 
11  // if the user clicks a system message (not a link inside one), make it disappear
12  $(document).on('click', '.elgg-system-messages .elgg-message', function(e) {
13  if (!$(e.target).is('a')) {
14  var $this = $(this);
15 
16  // slideUp allows dismissals without notices shifting around unpredictably
17  $this.clearQueue().slideUp(100, function () {
18  $this.remove();
19  });
20  }
21  });
22 
23  $('.elgg-page-default .elgg-system-messages .elgg-message').parent().animate({opacity: 0.9}, 6000);
24  $('.elgg-page-default .elgg-system-messages .elgg-message-success').parent().fadeOut('slow');
25 
26  $(document).on('click', '[rel=toggle]', elgg.ui.toggles);
27 
28  require(['elgg/popup'], function(popup) {
29  popup.bind($('[rel="popup"]'));
30  });
31 
32  $(document).on('click', '*[data-confirm]', elgg.ui.requiresConfirmation);
33 
34  // Allow element to be highlighted using CSS if its id is found from the URL
35  var elementId = elgg.getSelectorFromUrlFragment(document.URL);
36  $(elementId).addClass('elgg-state-highlight');
37 };
38 
52 elgg.ui.toggles = function(event) {
53  event.preventDefault();
54  var $this = $(this),
55  selector = $this.data().toggleSelector;
56 
57  if (!selector) {
58  // @todo we can switch to elgg.getSelectorFromUrlFragment() in 1.x if
59  // we also extend it to support href=".some-class"
60  selector = $this.attr('href');
61  }
62 
63  var $elements = $(selector);
64 
65  $this.toggleClass('elgg-state-active');
66 
67  $elements.each(function(index, elem) {
68  var $elem = $(elem);
69  if ($elem.data().toggleSlide != false) {
70  $elem.slideToggle('medium');
71  } else {
72  $elem.toggle();
73  }
74  });
75 
76  $this.trigger('elgg_ui_toggle', [{
77  $toggled_elements: $elements
78  }]);
79 };
80 
87 elgg.ui.initHoverMenu = function(parent) {
88 
95  function loadMenu(mac, callback) {
96  var $all_placeholders = $(".elgg-menu-hover[rel='" + mac + "']");
97 
98  // find the <ul> that contains data for this menu
99  var $ul = $all_placeholders.filter('[data-elgg-menu-data]');
100 
101  if (!$ul.length) {
102  return;
103  }
104 
105  require(['elgg/Ajax'], function(Ajax) {
106  var ajax = new Ajax();
107  ajax.view('navigation/menu/user_hover/contents', {
108  data: $ul.data('elggMenuData'),
109  success: function(data) {
110  if (data) {
111  // replace all existing placeholders with new menu
112  $all_placeholders.html($(data));
113  }
114 
115  if (typeof callback === 'function') {
116  callback();
117  }
118  },
119  complete: function() {
120  $all_placeholders.removeAttr('data-menu-placeholder');
121  }
122  });
123  });
124  };
125 
131  function showPopup($icon) {
132  // check if we've attached the menu to this element already
133  var $hovermenu = $icon.data('hovermenu') || null;
134 
135  if (!$hovermenu) {
136  $hovermenu = $icon.parent().find(".elgg-menu-hover");
137  $icon.data('hovermenu', $hovermenu);
138  }
139 
140  require(['elgg/popup'], function(popup) {
141  if ($hovermenu.is(':visible')) {
142  // close hovermenu if arrow is clicked & menu already open
143  popup.close($hovermenu);
144  } else {
145  popup.open($icon, $hovermenu, {
146  'my': 'left top',
147  'at': 'left top',
148  'of': $icon.closest(".elgg-avatar"),
149  'collision': 'fit fit'
150  });
151  }
152  });
153  };
154 
155  if (!parent) {
156  parent = document;
157  }
158 
159  // avatar contextual menu
160  $(document).on('click', ".elgg-avatar-menu > a", function(e) {
161  e.preventDefault();
162 
163  var $icon = $(this);
164 
165  var $placeholder = $icon.parent().find(".elgg-menu-hover[data-menu-placeholder]");
166 
167  if ($placeholder.length) {
168  loadMenu($placeholder.attr("rel"), function() {
169  showPopup($icon);
170  });
171  } else {
172  showPopup($icon);
173  }
174  });
175 
176 };
177 
184 elgg.ui.requiresConfirmation = function(e) {
185  var confirmText = $(this).data('confirm') || elgg.echo('question:areyousure');
186  if (!confirm(confirmText)) {
187  e.preventDefault();
188  e.stopPropagation();
189  e.stopImmediatePropagation();
190  return false;
191  }
192 };
193 
201 elgg.ui.registerTogglableMenuItems = function(menuItemNameA, menuItemNameB) {
202  require(['navigation/menu/elements/item_toggle'], function() {
203  menuItemNameA = menuItemNameA.replace('_', '-');
204  menuItemNameB = menuItemNameB.replace('_', '-');
205 
206  $('.elgg-menu-item-' + menuItemNameA + ' a').not('[data-toggle]').attr('data-toggle', menuItemNameB);
207  $('.elgg-menu-item-' + menuItemNameB + ' a').not('[data-toggle]').attr('data-toggle', menuItemNameA);
208  });
209 };
210 
211 elgg.register_hook_handler('init', 'system', elgg.ui.init);
if(!$owner) $icon
Definition: default.php:16
elgg ajax
Wrapper function for jQuery.ajax which ensures that the url being called is relative to the elgg site...
Definition: ajax.js:19
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
Bundled plugins(the contents of the"/mod"directory) are available only under the GPLv2 license.The remainder of the project is available under either MIT or GPLv2.Both licenses can be found below.More info and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on
Definition: LICENSE.txt:96
var elgg
Definition: elgglib.js:4