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