Elgg  Version 5.1
item_toggle.js
Go to the documentation of this file.
1 
4 define(['jquery', 'elgg/hooks', 'elgg/Ajax'], function ($, hooks, Ajax) {
5 
6  $(document).on('click', '.elgg-menu a[data-toggle]', function() {
7  var $item_clicked = $(this).closest('li');
8  var $menu = $item_clicked.closest('.elgg-menu');
9  var other_menuitem_name = $(this).data().toggle.replace('_', '-');
10  var $other_item = $menu.find('.elgg-menu-item-' + other_menuitem_name).eq(0);
11 
12  if (!$other_item) {
13  return;
14  }
15 
16  var $both_items = $item_clicked.add($other_item);
17  // Be optimistic about success
18  $both_items.toggleClass('hidden');
19  $other_item.children('a').focus();
20 
21  // Send the ajax request
22 
23  var ajax = new Ajax();
24  ajax.action($(this).attr('href'), {
25  success: function(result) {
26  // let others know we toggled the menu item
27  hooks.trigger('toggle', 'menu_item', {
28  itemClicked: $item_clicked,
29  itemToggled: $other_item,
30  menu: $menu,
31  data: result
32  });
33  },
34  error: function() {
35  // Something went wrong, so undo the optimistic changes
36  $both_items.toggleClass('hidden');
37  $item_clicked.children('a').focus();
38  }
39  });
40 
41  // Don't want to actually click the link
42  return false;
43  });
44 });
$menu
Admin sidebar – just outputs the page menus.
Definition: sidebar.php:6
$result error
define(['jquery', 'elgg/hooks', 'elgg/Ajax'], function($, hooks, Ajax){$(document).on('click', '.elgg-menu a[data-toggle]', function(){var $item_clicked=$(this).closest('li');var $menu=$item_clicked.closest('.elgg-menu');var other_menuitem_name=$(this).data().toggle.replace('_', '-');var $other_item=$menu.find('.elgg-menu-item-'+other_menuitem_name).eq(0);if(!$other_item){return;}var $both_items=$item_clicked.add($other_item);$both_items.toggleClass('hidden');$other_item.children('a').focus();var ajax=new Ajax();ajax.action($(this).attr('href'),{success:function(result){hooks.trigger('toggle', 'menu_item',{itemClicked:$item_clicked, itemToggled:$other_item, menu:$menu, data:result});}, error:function(){$both_items.toggleClass('hidden');$item_clicked.children('a').focus();}});return false;});})
Adds menu item toggle features.
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