Elgg  Version 5.1
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  // close the popup when clicked outside the popup
21  if (e.isDefaultPrevented()) {
22  return;
23  }
24 
25  var $eventTargets = $(e.target).parents().addBack();
26  if ($eventTargets.is('.elgg-state-popped')) {
27  return;
28  }
29 
30  popup.close();
31  });
32 
33  $(document).on('keydown', function (e) {
34  // close the popup when the escape key is pressed
35  if (e.isDefaultPrevented() || e.key !== "Escape") {
36  return;
37  }
38 
39  popup.close();
40  });
41 
42  // Bind events only once
43  popup.init = function() {};
44  },
58  bind: function ($triggers) {
59  $triggers.off('click.popup')
60  .on('click.popup', function (e) {
61  if (e.isDefaultPrevented()) {
62  return;
63  }
64 
65  e.preventDefault();
66  e.stopPropagation();
67  popup.open($(this));
68  });
69  },
89  open: function ($trigger, $target, position) {
90  if (typeof $trigger === 'undefined' || !$trigger.length) {
91  return;
92  }
93 
94  if (typeof $target === 'undefined') {
95  var href = $trigger.attr('href') || $trigger.data('href') || '';
96  var targetSelector = elgg.getSelectorFromUrlFragment(href);
97  $target = $(targetSelector);
98  } else {
99  $target.uniqueId();
100  var targetSelector = '#' + $target.attr('id');
101  }
102 
103  if (!$target.length) {
104  return;
105  }
106 
107  // emit a hook to allow plugins to position and control popups
108  var params = {
109  targetSelector: targetSelector,
110  target: $target,
111  source: $trigger
112  };
113 
114  position = position || {
115  my: 'center top',
116  at: 'center bottom',
117  of: $trigger,
118  collision: 'fit fit'
119  };
120 
121  $.extend(position, $trigger.data('position'));
122 
123  position = hooks.trigger('getOptions', 'ui.popup', params, position);
124 
125  if (!position) {
126  return;
127  }
128 
129  popup.init();
130 
131  // If the user is clicking on the trigger while the popup is open
132  // we should just close the popup
133  if ($target.is('.elgg-state-popped')) {
134  popup.close($target);
135  return;
136  }
137 
138  popup.close(); // close any open popup modules
139 
140  $target.data('trigger', $trigger); // used to remove elgg-state-active class when popup is closed
141  $target.data('position', position); // used to reposition the popup module on window manipulations
142 
143  if (!$trigger.is('.elgg-popup-inline')) {
144  $target.appendTo('body');
145  }
146 
147  // need to do a double position because of positioning issues during fadeIn() in Opera
148  // https://github.com/Elgg/Elgg/issues/6452
149  $target.position(position).fadeIn()
150  .addClass('elgg-state-active elgg-state-popped')
151  .position(position);
152 
153  $trigger.addClass('elgg-state-active');
154 
155  $target.trigger('open');
156 
157  if ($trigger.is('a')) {
158  $target.on('close', function() {
159  if ($target.find(':focus').length) {
160  $trigger.focus();
161  }
162  });
163  }
164  },
172  close: function ($targets) {
173  if (typeof $targets === 'undefined') {
174  $targets = $('.elgg-state-popped');
175  }
176 
177  if (!$targets.length) {
178  return;
179  }
180 
181  $targets.each(function () {
182  var $target = $(this);
183  if (!$target.is(':visible')) {
184  return;
185  }
186 
187  var $trigger = $target.data('trigger');
188  if ($trigger.length) {
189  $trigger.removeClass('elgg-state-active');
190  }
191 
192  $target.fadeOut().removeClass('elgg-state-active elgg-state-popped');
193 
194  $target.trigger('close');
195  });
196  }
197  };
198 
199  popup.bind($('.elgg-popup'));
200 
201  return popup;
202 });
if(!$comment instanceof\ElggComment||!$comment->canEdit()) $target
Definition: edit.php:15
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