Elgg  Version 5.0
popup.js
Go to the documentation of this file.
1 
8 define('elgg/popup', ['jquery', 'elgg', 'elgg/hooks', 'jquery-ui/position', 'jquery-ui/unique-id'], function ($, elgg, hooks) {
9  var popup = {
18  init: function () {
19  $(document).on('click', function (e) {
20  if (e.isDefaultPrevented()) {
21  return;
22  }
23 
24  var $eventTargets = $(e.target).parents().addBack();
25  if ($eventTargets.is('.elgg-state-popped')) {
26  return;
27  }
28 
29  popup.close();
30  });
31  // Bind events only once
32  popup.init = function() {};
33  },
47  bind: function ($triggers) {
48  $triggers.off('click.popup')
49  .on('click.popup', function (e) {
50  if (e.isDefaultPrevented()) {
51  return;
52  }
53 
54  e.preventDefault();
55  e.stopPropagation();
56  popup.open($(this));
57  });
58  },
78  open: function ($trigger, $target, position) {
79  if (typeof $trigger === 'undefined' || !$trigger.length) {
80  return;
81  }
82 
83  if (typeof $target === 'undefined') {
84  var href = $trigger.attr('href') || $trigger.data('href') || '';
85  var targetSelector = elgg.getSelectorFromUrlFragment(href);
86  $target = $(targetSelector);
87  } else {
88  $target.uniqueId();
89  var targetSelector = '#' + $target.attr('id');
90  }
91 
92  if (!$target.length) {
93  return;
94  }
95 
96  // emit a hook to allow plugins to position and control popups
97  var params = {
98  targetSelector: targetSelector,
99  target: $target,
100  source: $trigger
101  };
102 
103  position = position || {
104  my: 'center top',
105  at: 'center bottom',
106  of: $trigger,
107  collision: 'fit fit'
108  };
109 
110  $.extend(position, $trigger.data('position'));
111 
112  position = hooks.trigger('getOptions', 'ui.popup', params, position);
113 
114  if (!position) {
115  return;
116  }
117 
118  popup.init();
119 
120  // If the user is clicking on the trigger while the popup is open
121  // we should just close the popup
122  if ($target.is('.elgg-state-popped')) {
123  popup.close($target);
124  return;
125  }
126 
127  popup.close(); // close any open popup modules
128 
129  $target.data('trigger', $trigger); // used to remove elgg-state-active class when popup is closed
130  $target.data('position', position); // used to reposition the popup module on window manipulations
131 
132  if (!$trigger.is('.elgg-popup-inline')) {
133  $target.appendTo('body');
134  }
135 
136  // need to do a double position because of positioning issues during fadeIn() in Opera
137  // https://github.com/Elgg/Elgg/issues/6452
138  $target.position(position).fadeIn()
139  .addClass('elgg-state-active elgg-state-popped')
140  .position(position);
141 
142  $trigger.addClass('elgg-state-active');
143 
144  $target.trigger('open');
145  },
153  close: function ($targets) {
154  if (typeof $targets === 'undefined') {
155  $targets = $('.elgg-state-popped');
156  }
157 
158  if (!$targets.length) {
159  return;
160  }
161 
162  $targets.each(function () {
163  var $target = $(this);
164  if (!$target.is(':visible')) {
165  return;
166  }
167 
168  var $trigger = $target.data('trigger');
169  if ($trigger.length) {
170  $trigger.removeClass('elgg-state-active');
171  }
172 
173  $target.fadeOut().removeClass('elgg-state-active elgg-state-popped');
174 
175  $target.trigger('close');
176  });
177  }
178  };
179 
180  popup.bind($('.elgg-popup'));
181 
182  return popup;
183 });
if(!$comment instanceof\ElggComment||!$comment->canEdit()) $target
Definition: edit.php:13
if(empty($subscriptions)) $targets
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