Elgg  Version 5.1
lightbox.js
Go to the documentation of this file.
1 
24 define(['jquery', 'elgg', 'elgg/Ajax', 'elgg/hooks', 'jquery.colorbox'], function ($, elgg, Ajax, hooks) {
25 
26  var lightbox = {
27 
35  getOptions: function (opts) {
36  if (!$.isPlainObject(opts)) {
37  opts = {};
38  }
39 
40  // data set server side using elgg.data,site hook
41  var defaults = elgg.data.lightbox;
42 
43  if (!defaults.reposition) {
44  // don't move colorbox on small viewports https://github.com/Elgg/Elgg/issues/5312
45  defaults.reposition = $(window).height() > 600;
46  }
47 
48  var settings = $.extend({}, defaults, opts);
49 
50  return hooks.trigger('getOptions', 'ui.lightbox', null, settings);
51  },
52 
62  bind: function (selector, opts, use_element_data) {
63  if (!$.isPlainObject(opts)) {
64  opts = {};
65  }
66 
67  // Allow direct binding to allow grouping by rel attribute
68  if (use_element_data === false) {
69  $(selector).colorbox(lightbox.getOptions(opts));
70  return;
71  }
72 
73  $(document)
74  .off('click.lightbox', selector)
75  .on('click.lightbox', selector, function (e) {
76  // trigger a click event on document to close open menus / dropdowns like the entity menu #11748
77  $(document).click();
78 
79  // remove system messages when opening a lightbox
80  $('.elgg-system-messages .elgg-message').remove();
81 
82  e.preventDefault();
83  var $this = $(this),
84  href = $this.prop('href') || $this.prop('src'),
85  // Note: data-colorbox was reserved https://github.com/jackmoore/colorbox/issues/435
86  dataOpts = $this.data('colorboxOpts'),
87  currentOpts = {};
88 
89  if (!$.isPlainObject(dataOpts)) {
90  dataOpts = {};
91  }
92 
93  if (!dataOpts.href && href) {
94  dataOpts.href = href;
95  }
96 
97  // merge data- options into opts
98  $.extend(currentOpts, opts, dataOpts);
99  if (currentOpts.inline && currentOpts.href) {
100  currentOpts.href = elgg.getSelectorFromUrlFragment(currentOpts.href);
101  }
102 
103  if (currentOpts.photo || currentOpts.inline || currentOpts.iframe || currentOpts.html) {
104  lightbox.open(currentOpts);
105  return;
106  }
107 
108  currentOpts.ajaxLoadWithDependencies = true;
109  lightbox.open(currentOpts);
110  });
111 
112  $(window)
113  .off('resize.lightbox')
114  .on('resize.lightbox', function() {
115  elgg.data.lightbox.reposition = $(window).height() > 600;
116  lightbox.resize();
117  });
118  },
119 
127  open: function (opts) {
128  var currentOpts = lightbox.getOptions(opts);
129 
130  if (!currentOpts.ajaxLoadWithDependencies) {
131  $.colorbox(currentOpts);
132  return;
133  }
134 
135  var href = currentOpts.href;
136  currentOpts.href = false;
137  var data = currentOpts.data;
138  currentOpts.data = undefined;
139 
140  // open lightbox without a href so we get a loader
141  $.colorbox(currentOpts);
142 
143  var ajax = new Ajax(false);
144  ajax.path(href, {
145  data: data
146  }).done(function(output) {
147  currentOpts.html = output;
148  $.colorbox(currentOpts);
149 
150  // clear data so next fetch will refresh contents
151  currentOpts.html = undefined;
152  }).fail(function() {
153  $.colorbox.close();
154  });
155  },
156 
162  close: $.colorbox.close,
163 
169  resize: $.colorbox.resize
170  };
171 
172  lightbox.bind(".elgg-lightbox");
173  lightbox.bind(".elgg-lightbox-photo", {photo: true});
174  lightbox.bind(".elgg-lightbox-inline", {inline: true});
175  lightbox.bind(".elgg-lightbox-iframe", {iframe: true});
176 
177  return lightbox;
178 });
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})
var elgg
Definition: elgglib.js:4