Elgg  Version 2.2
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  //console.log(use_element_data);
67 
68  // Allow direct binding to allow grouping by rel attribute
69  if (use_element_data === false) {
70  $(selector).colorbox(lightbox.getOptions(opts));
71  return;
72  }
73 
74  $(document)
75  .off('click.lightbox', selector)
76  .on('click.lightbox', selector, function (e) {
77  e.preventDefault();
78  var $this = $(this),
79  href = $this.prop('href') || $this.prop('src'),
80  // Note: data-colorbox was reserved https://github.com/jackmoore/colorbox/issues/435
81  dataOpts = $this.data('colorboxOpts');
82 
83  if (!$.isPlainObject(dataOpts)) {
84  dataOpts = {};
85  }
86 
87  if (!dataOpts.href && href) {
88  dataOpts.href = href;
89  }
90 
91  // merge data- options into opts
92  $.extend(opts, dataOpts);
93  if (opts.inline && opts.href) {
94  opts.href = elgg.getSelectorFromUrlFragment(opts.href);
95  }
96 
97  lightbox.open(opts);
98  });
99  },
100 
107  open: function (opts) {
108  $.colorbox(lightbox.getOptions(opts));
109  },
110 
115  close: $.colorbox.close,
116 
121  resize: $.colorbox.resize
122  };
123 
124  lightbox.bind(".elgg-lightbox");
125  lightbox.bind(".elgg-lightbox-photo", {photo: true});
126  lightbox.bind(".elgg-lightbox-inline", {inline: true});
127  lightbox.bind(".elgg-lightbox-iframe", {iframe: true});
128 
129  return lightbox;
130 });
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:596
friends picker navigation li a current
Definition: admin.css.php:825
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:620