BuddyDev

Search

MediaPress provides an easy to use API for opening media, gallery or activity attachments in lightbox. Internally, we use Magnific Popup for the lightbox.

This API is for javascript based applications.

API Functions

  • mpp.lightbox.isLoaded() – Check if lightbox js/css is loaded
  • mpp.lightbox.gallery(gallery_id, position, fallback_url, media_id)  :- Open all media in a gallery in the lightbox.
  • mpp.lightbox.media(media_ids, position, fallback_url) :- Open one or more photo in the lightbox
  • mpp.lightox.activity(activity_id, position, fallback_url) :- Open activity attachments in the lightbox.
  • mpp.lightbox.open(items, position, fallback_url) :- Open any thing inside the lightbox
  • mpp.lightbox.isOpen() :- check if the lightbox is open.
  • mpp.lightbox.update(content) :- Update the content of the current lightbox view with the given html. Only works if lightbox is open.
  • mpp.lightbox.getCurrentMediaID() :- Gives the id of the media currently being viewed in the lightbox
  • mpp.lightbox.reloadCurrentMedia():- reloads the lightbox with the content of current media. It is helpful for reloading after updating media etc.
  • mpp.lightbox.reloadMedia(media_id):- Loads the given media id’s content in currenly opened lightbox view. If you want to open a lightbox with a given media, please use mpp.lightbox.media() instead.

In all the functions, the position determines which of the photo from the collection will be displayed when the lightbox opens.

fallback_url ats as a fallback. When there is no media or some error, the user will be redirected to the fallback url.

Event:-

mpp:lightbox:opened event is triggered on the document object when the lightbox opens. The even listener should be attached on document object and will receive three arguements

  • Event Object
  • media items collection(array)
  • position(integer):- The position of the item which will be shown first.

The event mpp_lightbox_opened is deprecated and we strongly recommend to use  mpp:lightbox:opened instead. mpp_lightbox_opened will be removed in 1.5.0.

API details:-

mpp.lightbox.isLoaded()

Usage: – It is used to check if the lightbox is loaded or not.

Returns:- boolean, true if lightbox is loaded else false.

mpp.lightbox.gallery(gallery_id, position, fallback_url, media_id)

Usage:- Open all media from the gallery into the lightbox.

Parameters:-

  • gallery_id (integer, required)  The gallery id whose photos will be displayed in the lightbox.
  • position(integer, required) Index of the photo which will be displayed from the collection(0 means first).
  • fallback_url(string, required) Where to redirect the user if there is an error. you should use it to provide the link to the single gallery page.
  • media_id(integer, optional):- Ff specified, It is used to determine the position(and this media will be opened as the first inside the gallery).

mpp.lightbox.media(media_ids, position, fallback_url)

Usage:- Open one or more photo in the lightbox.

Parameters:-

  • media_ids(comma separated string of ids, required):- One or more media ids separated by comma. These media will be displayed in the lightbox.
  •  position:- which media from the collection should be displayed as the first entry in the lightbox( 0 means first)
  • fallback_url(string, required):- where to redirect when there is an error.

mpp.lightox.activity(activity_id, position, fallback_url)

Usage:- Open all MediaPress image attachment from the activity in a lightbox

Parameters:-

  • activity_id(integer, required):- The activity id.
  •  position(integer, required):- Which media from the collection should be opened first(0 means first).
  • fallback_url(string, required) :- Where to redirect if there is an error.

mpp.lightbox.open(items, position, fallback_url)

Usage:- Open arbitrary content in the lightbox.

Parameters:- 

  • items(object or array of objects):- Please see the Magnific Popup documentation for the allowed values.
  • position:- Which one from the list should be opened first.
  • fallback_url:- Where to redirect if there is an error.

 mpp.lightbox.isOpen()

Usage: – It is used to check if the lightbox is open.

Returns:- boolean, true if lightbox is open else false.

 mpp.lightbox.update(content):-

Usage:- Update the content of current lightbox item with the given html.

Parameters:- 

  • content(string) :- Arbitrary html.

mpp.lightbox.getCurrentMediaID()

Usage:- Get the id of the media currently being viewed in the lightbox.

Returns:- media id if valid else 0.

mpp.lightbox.reloadCurrentMedia()

Usage:- Reload the current lightbox media item. Useful to reload after updating media details etc.

mpp.lightbox.reloadMedia(media_id)

Usage:- Load the given media  into currenly opened lightbox view. It replaces the current lightbox media item(which is being viewed) with the content for the given media id.

Parameters:- 

  • media_id(integer) :- any valid media id.