Elgg  Version 5.1
tabs.js
Go to the documentation of this file.
1 
4 define(['jquery', 'elgg/Ajax'], function ($, Ajax) {
5 
6  var ajax = new Ajax(false);
7 
8  function changeTab($link_item, clearing_tab, trigger_open) {
9 
10  clearing_tab = typeof clearing_tab == 'boolean' ? clearing_tab : false;
11  trigger_open = typeof trigger_open == 'boolean' ? trigger_open : true;
12 
13  var $target = $link_item.data('target');
14  if (!$target || !$target.length) {
15  return false;
16  }
17 
18  // only change tab content if not already showing (or if clearing the tab)
19  if ($target.hasClass('elgg-state-active') && !clearing_tab) {
20  return true;
21  }
22 
23  // find the tabs that have the selected state and remove that state
24  var $tabs_component = $target.closest('.elgg-tabs-component');
25  $tabs_component.find('.elgg-tabs').eq(0).find('.elgg-state-selected').removeClass('elgg-state-selected');
26 
27  $link_item.addClass('elgg-state-selected');
28 
29  $target.siblings().addClass('hidden').removeClass('elgg-state-active');
30  $target.removeClass('hidden').addClass('elgg-state-active');
31 
32  require(['elgg/popup'], function(popup) {
33  popup.close();
34  });
35 
36  if (trigger_open) {
37  $link_item.trigger('open');
38 
39  // scroll tabs into view if needed
40  var rect = $link_item[0].getBoundingClientRect();
41 
42  var isInViewport = rect.top >= 0 &&
43  rect.left >= 0 &&
44  rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
45  rect.right <= (window.innerWidth || document.documentElement.clientWidth);
46 
47  if (!isInViewport) {
48  $tabs_component[0].scrollIntoView();
49  }
50  }
51 
52  return true;
53  };
54 
55  function clickLink(event) {
56 
57  var $link = $(this);
58  if ($link.hasClass('elgg-non-link')) {
59  return;
60  }
61 
62  event.preventDefault();
63 
64  var $tab = $(this).parent();
65  var $content = $('.elgg-tabs-content');
66 
67  var href = $link.data('ajaxHref') || $link.attr('href');
68  var $target = $tab.data('target');
69  if (!$target || !$target.length) {
70  // store $tagret for future use
71  $target = $($link.data('target'));
72  $tab.data('target', $target);
73  }
74 
75  if (href.indexOf('#') === 0) {
76  // Open inline tab
77  if (changeTab($tab)) {
78  return;
79  }
80  } else {
81  // Load an ajax tab
82  if ($tab.data('loaded') && !$link.data('ajaxReload')) {
83  if (changeTab($tab)) {
84  return;
85  }
86  }
87 
88  ajax.path(href, {
89  data: $link.data('ajaxQuery') || {},
90  beforeSend: function () {
91  changeTab($tab, true, false);
92  $target.html('');
93  $target.addClass('elgg-ajax-loader');
94  }
95  }).done(function (output, statusText, jqXHR) {
96  $tab.data('loaded', true);
97  $target.removeClass('elgg-ajax-loader').html(output);
98 
99  changeTab($tab, true);
100  }).fail(function() {
101  require(['elgg/i18n'], function(i18n) {
102  $target.removeClass('elgg-ajax-loader').html(i18n.echo('ajax:error'));
103  });
104  });
105  }
106  };
107 
108  // register click event
109  $(document).on('click', '.elgg-components-tab > a', clickLink);
110 
111  // Open selected tabs
112  // This will load any selected tabs that link to ajax views
113  $('.elgg-tabs-component').each(function() {
114  var $tabs = $(this).find('.elgg-components-tab:not(.elgg-menu-item-has-dropdown)');
115  if (!$tabs.length) {
116  return;
117  }
118 
119  if ($tabs.hasClass('elgg-state-selected')) {
120  $tabs.filter('.elgg-state-selected').eq(0).find(' > a').trigger('click');
121  } else {
122  $tabs.eq(0).find(' > a').trigger('click');
123  }
124  });
125 });
define(['jquery', 'elgg/Ajax'], function($, Ajax){var ajax=new Ajax(false);function changeTab($link_item, clearing_tab, trigger_open){clearing_tab=typeof clearing_tab== 'boolean'?clearing_tab:false;trigger_open=typeof trigger_open== 'boolean'?trigger_open:true;var $target=$link_item.data('target');if(!$target||!$target.length){return false;}if($target.hasClass('elgg-state-active')&&!clearing_tab){return true;}var $tabs_component=$target.closest('.elgg-tabs-component');$tabs_component.find('.elgg-tabs').eq(0).find('.elgg-state-selected').removeClass('elgg-state-selected');$link_item.addClass('elgg-state-selected');$target.siblings().addClass('hidden').removeClass('elgg-state-active');$target.removeClass('hidden').addClass('elgg-state-active');require(['elgg/popup'], function(popup){popup.close();});if(trigger_open){$link_item.trigger('open');var rect=$link_item[0].getBoundingClientRect();var isInViewport=rect.top >=0 &&rect.left >=0 &&rect.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&rect.right<=(window.innerWidth||document.documentElement.clientWidth);if(!isInViewport){$tabs_component[0].scrollIntoView();}}return true;};function clickLink(event){var $link=$(this);if($link.hasClass('elgg-non-link')){return;}event.preventDefault();var $tab=$(this).parent();var $content=$('.elgg-tabs-content');var href=$link.data('ajaxHref')||$link.attr('href');var $target=$tab.data('target');if(!$target||!$target.length){$target=$($link.data('target'));$tab.data('target', $target);}if(href.indexOf('#')===0){if(changeTab($tab)){return;}}else{if($tab.data('loaded')&&!$link.data('ajaxReload')){if(changeTab($tab)){return;}}ajax.path(href,{data:$link.data('ajaxQuery')||{}, beforeSend:function(){changeTab($tab, true, false);$target.html('');$target.addClass('elgg-ajax-loader');}}).done(function(output, statusText, jqXHR){$tab.data('loaded', true);$target.removeClass('elgg-ajax-loader').html(output);changeTab($tab, true);}).fail(function(){require(['elgg/i18n'], function(i18n){$target.removeClass('elgg-ajax-loader').html(i18n.echo('ajax:error'));});});}};$(document).on('click', '.elgg-components-tab > a', clickLink);$('.elgg-tabs-component').each(function(){var $tabs=$(this).find('.elgg-components-tab:not(.elgg-menu-item-has-dropdown)');if(!$tabs.length){return;}if($tabs.hasClass('elgg-state-selected')){$tabs.filter('.elgg-state-selected').eq(0).find(' > a').trigger('click');}else{$tabs.eq(0).find(' > a').trigger('click');}});})
Tabbed module.
if(!$comment instanceof\ElggComment||!$comment->canEdit()) $target
Definition: edit.php:15
if(!$item instanceof ElggEntity) $link
Definition: container.php:16
$content
Set robots.txt action.
Definition: set_robots.php:6
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