Elgg  Version 2.3
lightbox.js
Go to the documentation of this file.
1 
8 define('elgg/lightbox', function (require) {
9 
10  var elgg = require('elgg');
11  var $ = require('jquery');
12  require('elgg/init');
13  require('jquery.colorbox');
14 
15  var lightbox = {
16 
23  getOptions: function (opts) {
24  if (!$.isPlainObject(opts)) {
25  opts = {};
26  }
27 
28  // Note: keep these in sync with /views/default/lightbox.js.php
29  var settings = {
30  current: elgg.echo('js:lightbox:current', ['{current}', '{total}']),
31  previous: elgg.echo('previous'),
32  next: elgg.echo('next'),
33  close: elgg.echo('close'),
34  xhrError: elgg.echo('error:default'),
35  imgError: elgg.echo('error:default'),
36  opacity: 0.5,
37  maxWidth: '100%',
38  // don't move colorbox on small viewports https://github.com/Elgg/Elgg/issues/5312
39  reposition: $(window).height() > 600
40  };
41 
42  elgg.provide('elgg.ui.lightbox');
43 
44  if ($.isPlainObject(elgg.ui.lightbox.deprecated_settings)) {
45  $.extend(settings, elgg.ui.lightbox.deprecated_settings, opts);
46  } else {
47  $.extend(settings, opts);
48  }
49 
50  return elgg.trigger_hook('getOptions', 'ui.lightbox', null, settings);
51  },
52 
61  bind: function (selector, opts, use_element_data) {
62  if (!$.isPlainObject(opts)) {
63  opts = {};
64  }
65 
66  // Allow direct binding to allow grouping by rel attribute
67  if (use_element_data === false) {
68  $(selector).colorbox(lightbox.getOptions(opts));
69  return;
70  }
71 
72  $(document)
73  .off('click.lightbox', selector)
74  .on('click.lightbox', selector, function (e) {
75  e.preventDefault();
76  var $this = $(this),
77  href = $this.prop('href') || $this.prop('src'),
78  // Note: data-colorbox was reserved https://github.com/jackmoore/colorbox/issues/435
79  dataOpts = $this.data('colorboxOpts'),
80  currentOpts = {};
81 
82  if (!$.isPlainObject(dataOpts)) {
83  dataOpts = {};
84  }
85 
86  if (!dataOpts.href && href) {
87  dataOpts.href = href;
88  }
89 
90  // merge data- options into opts
91  $.extend(currentOpts, opts, dataOpts);
92  if (currentOpts.inline && currentOpts.href) {
93  currentOpts.href = elgg.getSelectorFromUrlFragment(currentOpts.href);
94  }
95 
96  lightbox.open(currentOpts);
97  });
98  },
99 
106  open: function (opts) {
107  $.colorbox(lightbox.getOptions(opts));
108  },
109 
114  close: $.colorbox.close,
115 
120  resize: $.colorbox.resize
121  };
122 
123  lightbox.bind(".elgg-lightbox");
124  lightbox.bind(".elgg-lightbox-photo", {photo: true});
125  lightbox.bind(".elgg-lightbox-inline", {inline: true});
126  lightbox.bind(".elgg-lightbox-iframe", {iframe: true});
127 
128  return lightbox;
129 });
elgg
Definition: install.js:23
elgg isPlainObject
Check if the value is a "plain" object (i.e., created by {} or new Object())
Definition: elgglib.js:75
line height
Definition: admin.css.php:82
elgg form settings
Definition: admin.css.php:627
friends picker navigation li a current
Definition: admin.css.php:856
elgg require
Throw an error if the required package isn't present.
Definition: elgglib.js:164
GNU GENERAL PUBLIC LICENSE June Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license document
Definition: GPL-LICENSE.txt:4
ui datepicker ui datepicker next
Definition: admin.css.php:651