Elgg  Version 3.0
tabs.js
Go to the documentation of this file.
1 
6 define(function (require) {
7 
8  var elgg = require('elgg');
9  require('elgg/ready');
10  var $ = require('jquery');
11  var Ajax = require('elgg/Ajax');
12  var ajax = new Ajax(false);
13 
14  function changeTab($link_item) {
15 
16  var $target = $link_item.data('target');
17  if (!$target || !$target.length) {
18  return false;
19  }
20 
21  // find the tabs that have the selected state and remove that state
22  $target.closest('.elgg-tabs-component').find('.elgg-tabs').eq(0).find('.elgg-state-selected').removeClass('elgg-state-selected');
23 
24  $link_item.addClass('elgg-state-selected');
25 
26  $target.siblings().addClass('hidden').removeClass('elgg-state-active');
27  $target.removeClass('hidden').addClass('elgg-state-active');
28 
29  // trigger scroll to close potential open menus
30  // see elgg/popup.js open function
31  $(document).trigger('scroll');
32 
33  return true;
34  };
35 
36  var clickLink = function (event) {
37 
38  var $link = $(this);
39  if ($link.hasClass('elgg-non-link')) {
40  return;
41  }
42 
43  event.preventDefault();
44 
45  var $tab = $(this).parent();
46  var $content = $('.elgg-tabs-content');
47 
48  var href = $link.data('ajaxHref') || $link.attr('href');
49  var $target = $tab.data('target');
50  if (!$target || !$target.length) {
51  // store $tagret for future use
52  $target = $($link.data('target'));
53  $tab.data('target', $target);
54  }
55 
56  if (href.indexOf('#') === 0) {
57  // Open inline tab
58  if (changeTab($tab)) {
59  $tab.trigger('open');
60  return;
61  }
62  } else {
63  // Load an ajax tab
64  if ($tab.data('loaded') && !$link.data('ajaxReload')) {
65  if (changeTab($tab)) {
66  $tab.trigger('open');
67  return;
68  }
69  }
70 
71  ajax.path(href, {
72  data: $link.data('ajaxQuery') || {},
73  beforeSend: function () {
74  changeTab($tab);
75  $target.html('');
76  $target.addClass('elgg-ajax-loader');
77  }
78  }).done(function (output, statusText, jqXHR) {
79  $tab.data('loaded', true);
80  $target.removeClass('elgg-ajax-loader');
81  if (jqXHR.AjaxData.status === -1) {
82  $target.html(elgg.echo('ajax:error'));
83  return;
84  } else {
85  $target.html(output);
86  }
87 
88  if (changeTab($tab)) {
89  $tab.trigger('open');
90  }
91  });
92  }
93  };
94 
95  // register click event
96  $(document).on('click', '.elgg-components-tab > a', clickLink);
97 
98  // Open selected tabs
99  // This will load any selected tabs that link to ajax views
100  $('.elgg-tabs-component .elgg-components-tab.elgg-state-selected > a').trigger('click');
101 });
define(function(require){var elgg=require('elgg');require('elgg/ready');var $=require('jquery');var Ajax=require('elgg/Ajax');var ajax=new Ajax(false);function changeTab($link_item){var $target=$link_item.data('target');if(!$target||!$target.length){return false;}$target.closest('.elgg-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');$(document).trigger('scroll');return true;};var clickLink=function(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)){$tab.trigger('open');return;}}else{if($tab.data('loaded')&&!$link.data('ajaxReload')){if(changeTab($tab)){$tab.trigger('open');return;}}ajax.path(href,{data:$link.data('ajaxQuery')||{}, beforeSend:function(){changeTab($tab);$target.html('');$target.addClass('elgg-ajax-loader');}}).done(function(output, statusText, jqXHR){$tab.data('loaded', true);$target.removeClass('elgg-ajax-loader');if(jqXHR.AjaxData.status===-1){$target.html(elgg.echo('ajax:error'));return;}else{$target.html(output);}if(changeTab($tab)){$tab.trigger('open');}});}};$(document).on('click', '.elgg-components-tab > a', clickLink);$('.elgg-tabs-component.elgg-components-tab.elgg-state-selected > a').trigger('click');})
Tabbed module.
if(!$item instanceof ElggEntity) $link
Definition: container.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
if(!($comment instanceof\ElggComment)||!$comment->canEdit()) $target
Definition: edit.php:17
elgg require
Throw an error if the required package isn't present.
Definition: elgglib.js:164
$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
var elgg
Definition: elgglib.js:4