lightbox.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Elgg lightbox
  4. *
  5. * Usage
  6. * ---------------
  7. * Call elgg_load_js('lightbox') and elgg_load_css('lightbox').
  8. * Then apply the class elgg-lightbox to links.
  9. *
  10. *
  11. * Advanced Usage
  12. * -----------------
  13. * Elgg is distributed with the Colorbox jQuery library. Please go to
  14. * http://www.jacklmoore.com/colorbox for more information on the options of this lightbox.
  15. *
  16. * You can change global options by overriding the js/lightbox/settings view.
  17. *
  18. * You may apply colorbox options to an individual .elgg-lightbox element
  19. * by setting the attribute data-colorbox-opts to a JSON settings object. You
  20. * can also set options in the elgg.ui.lightbox.bind() method, but data
  21. * attributes will take precedence.
  22. *
  23. * To support a hidden div as the source, add "inline: true" as a
  24. * data-colorbox-opts option. For example, using the output/url view, add:
  25. * 'data-colorbox-opts' => '{"inline": true}',
  26. *
  27. *
  28. * Overriding with a different lightbox
  29. * -------------------------------------
  30. * In a plugin, override this view and override the registration for the
  31. * lightbox JavaScript and CSS (@see elgg_views_boot()).
  32. */
  33. ?>
  34. //<script>
  35. elgg.provide('elgg.ui.lightbox');
  36. <?php echo elgg_view('js/lightbox/settings'); ?>
  37. /**
  38. * Lightbox initialization
  39. */
  40. elgg.ui.lightbox.init = function() {
  41. function registerDeprecationError() {
  42. elgg.register_error("fancybox lightbox has been replaced by colorbox", 9999999999999);
  43. }
  44. elgg.ui.lightbox.bind(".elgg-lightbox");
  45. elgg.ui.lightbox.bind(".elgg-lightbox-photo", {photo: true});
  46. if (typeof $.fancybox === 'undefined') {
  47. $.fancybox = {
  48. // error message for firefox users
  49. __noSuchMethod__ : registerDeprecationError,
  50. close: function () {
  51. registerDeprecationError();
  52. $.colorbox.close();
  53. }
  54. };
  55. // support $().fancybox({type:'image'})
  56. $.fn.fancybox = function (arg) {
  57. registerDeprecationError();
  58. if (arg.type === 'image') {
  59. arg.photo = true;
  60. }
  61. this.colorbox(arg);
  62. return this;
  63. };
  64. }
  65. };
  66. /**
  67. * Bind colorbox lightbox click to HTML
  68. *
  69. * @param {Object} selector CSS selector matching colorbox openers
  70. * @param {Object} opts Colorbox options. These are overridden by data-colorbox-opts options
  71. */
  72. elgg.ui.lightbox.bind = function (selector, opts) {
  73. if (!$.isPlainObject(opts)) {
  74. opts = {};
  75. }
  76. // merge opts into defaults
  77. opts = $.extend({}, elgg.ui.lightbox.getSettings(), opts);
  78. $(document).on('click', selector, function (e) {
  79. var $this = $(this),
  80. href = $this.prop('href') || $this.prop('src'),
  81. dataOpts = $this.data('colorboxOpts');
  82. // Note: data-colorbox was reserved https://github.com/jackmoore/colorbox/issues/435
  83. if (!$.isPlainObject(dataOpts)) {
  84. dataOpts = {};
  85. }
  86. if (!dataOpts.href && href) {
  87. dataOpts.href = href;
  88. }
  89. // merge data- options into opts
  90. $.colorbox($.extend({}, opts, dataOpts));
  91. e.preventDefault();
  92. });
  93. };
  94. /**
  95. * Close the colorbox
  96. *
  97. */
  98. elgg.ui.lightbox.close = function() {
  99. $.colorbox.close();
  100. };
  101. elgg.register_hook_handler('init', 'system', elgg.ui.lightbox.init);
  102. <?php
  103. $js_path = elgg_get_config('path');
  104. $js_path = "{$js_path}vendors/jquery/colorbox/jquery.colorbox-min.js";
  105. readfile($js_path);