Galleria Helper
The Galleria Helper file contains functions which assist in generating JavaScript code for Galleria, a JavaScript image gallery you can download at https://galleriajs.github.io/. The helper comes in two flavors. In it's first form the helper generates the required JSON array (based on a static meta data text file) and Galleria initialization code, writes the data to disk and returns either a reference to the JavaScript file or the data itself to be inserted in a view file. In it's second form the helper generates the JSON array based on dynamically created meta data, adds initialization code and returns the JavaScript code enclosed in "script" tags.
The Galleria version currently supported is 1.6.1.
Requirements
- JQuery JavaScript file or a reference to a CDN (recommended).
- The Galleria Javascript file or a reference to the Galleria CDN at cdnjs https://cdnjs.com/libraries/galleria (recommended).
- Galleria theme files (JavaScript and CSS).
- A folder containing at least your gallery images. Optionally include (in case you use static image meta data) a text file (the meta data file) containing an image file name or a video URL or an iFrame URL, optional captions (title and description), an optional image link, optional layer data and an optional reference to the original IMG element for each image you provide. Furthermore you may append a file name (a file name prepended with a root relative path for dynamically generated data respectively) for each video or iFrame your gallery supplies. Note: This folder must be writable. See Using Image Data https://galleriajs.github.io/docs/references/data.html for further information regarding image data properties.
- Optionally you can include in your images folder a folder for thumbnails called "thumb" and a folder for fullscreen mode images called "big". Note: If you need to show your own thumbnails for videos or iFrames the thumbnails folder is mandatory.
Images Folder Structure
/myImagesFolder
myGalleriaCaptions.tsv
myImage1.png
myImage2.png
myImage3.png
/big
myImage1.png
myImage2.png
myImage3.png
/thumb
myImage1.png
myImage2.png
myImage3.png
The file name for your image data properties ("myGalleriaCaptions.tsv" in this case) is arbitrary but the "tsv" (tab-separated-values) suffix is mandatory. This file is only needed if you don't provide the data programmatically. If you want to provide separate images for thumbnails and fullscreen mode (recommended) include them in a folder called "thumb" and "big" respectively.
Note: This folder must be writable. Use identical file names for standard, thumbnail and fullscreen versions of your images.
Galleria Framework Modification
There are minor modifications necessary in order for the helper to work properly.
- Remove the suffix of the css property in the JavaScript file of your theme, for example replace css:"galleria.classic.css" with css:"galleria.classic".
- The following applies to Galleria themes of Galleria versions prior to 1.6: Adjust all URLs in the CSS file of the Galleria theme according to where you store theme related images. Remember: Paths in a CSS file are always relative to the CSS file itself. Alternatively you may use full URLs.
The Image Data File
The image data file you have to provide if you use the helper in it's first form is a simple text file with a "tsv" (tab-separated-values) suffix containing a list of tab delimited Galleria image properties and has the following form for each line:
image file name or video URL or iFrame URL<tab>title<tab>description<tab>image link URL<tab>image HTML layer<tab>IMG element reference[(for videos and iFrames only)<tab>thumbnail file name] (for dynamically generated data prepend the thumbnail file name with a root relative path)
Data File Example
img1.jpg Image img1 Title Image img1 Description <img src="http://mydomain.com/imgs/test.jpg">
img2.jpg Image img2 Title Image img2 Description <img src="http://mydomain.com/imgs/test2.jpg">
img3.jpg Image img3 Title Image img3 Description
http://www.youtube.com/watch?v=GCZrz8siv4Q Video Title Youtube video Description
img4.jpg Image img4 Title Image img4 Description
http://aino.com iFrame Title iFrame Description iFrameThumb.jpg
img5.jpg Image img5 Title Image img5 Description
Keep in mind that, if you provide a data file, the only mandatory property is the image file name, video URL or iFrame Url respectively. See Using Image Data https://galleriajs.github.io/docs/references/data.html for further information regarding image data properties.
Note: Using static meta data gallery images are sorted alphabetically. Videos and iFrames are sorted according to the order determined in your meta data file.
Dynamically Generated Image Data
In case you don't want to use static image meta data saved on disk you may create the meta data programmatically for example from data stored in a database. Dynamically generated meta data has the same form as the static image data described above with two exception:
- The first item in each line of the list is the image file name prepended with a root relative path.
- The name of the thumbnail for videos and iFrames (item number seven) must be prepended with a root relative path.
Note: Using dynamically created meta data gallery images are sorted according to the order determined in your meta data.
Loading this Helper
This helper is loaded using the following code:
rigLoadHelper "galleria"
Handler Reference
rigGalleriaData(pGalleryPath, pOptions, pContainerID, pDataVariableName, pCacheBuster, pReplaceDataFile, pReturnReference, pNonce)
This function generates the required JSON array based on a meta data tsv (tab-separated-values) file, adds Galleria initialization code, writes the data to disk and returns either a file reference or the data itself.
Parameters
- TpGalleryPath: is a root relative path to the folder containing the gallery images and the meta data file. Alternatively you can submit an associative array in the first parameter containing all the values. The array keys are: galleriaPath, options (an associative array), containerID, dataVariableName, cacheBuster, replaceDataFile and returnReference.
- pOptions: (optional) is an array of pairs of Galleria option names and Galleria option values. See List of Options https://galleriajs.github.io/docs/options/index.html#list-of-options. The default key value pair is "height" and 420.
- pContainerID: (optional) is the ID of the <div> tag containing the gallery. The default ID is "galleria".
- pDataVariableName: (optional) is the name of the JSON array data variable needed by Galleria. The default name is "galleriaData".
- pCacheBuster: (optional) is a boolean which determines whether your gallery should be excluded from cache busting in case use_cacheBusters in application/config/config.lc is set to TRUE. Defaults to TRUE.
- pReplaceDataFile: (optional) is a boolean which determines whether the generated JavaScript file should be replaced every time the function is called. Defaults to FALSE.
- pReturnReference: (optional) is a boolean which determines whether the helper should return a file reference or the Galleria data itself. Defaults to TRUE for returning a file reference. Setting this parameter to FALSE comes in handy for example if you are dealing with Ajax requests to dynamically change gallery content by sending just the Galleria data to the browser.
- pNonce: (optional) is a Content Security Policy nonce.
rigDynamicGalleriaData(pMetaData, pOptions, pContainerID, pDataVariableName, pCacheBuster, pNonce)
This function generates the required JSON array based on dynamically created meta data, adds initialization code and returns the JavaScript code enclosed in "script" tags.
Parameters
- pMetaData: is the dynamically generated meta data. Alternatively you can submit an associative array in the first parameter containing all the values. The array keys are: metaData, options (an associative array), containerID, dataVariableName and cacheBuster.
- pOptions: (optional) is an array of pairs of Galleria option names and Galleria option values. See List of Options https://galleriajs.github.io/docs/options/index.html#list-of-options. The default key value pair is "height" and 420.
- pContainerID: (optional) is the ID of the <div> tag containing the gallery. The default ID is "galleria".
- pDataVariableName: (optional) is the name of the JSON array data variable needed by Galleria. The default name is "galleriaData".
- pCacheBuster: (optional) is a boolean which determines whether your gallery should be excluded from cache busting in case use_cacheBusters in application/config/config.lc is set to TRUE. Defaults to TRUE.
- pNonce: (optional) is a Content Security Policy nonce.
Note: If you place more than one gallery on a page you need to include the third and fourth parameter as you need different IDs and variable names for each gallery. This applies to both functions.
Note: Enclose literal Galleria option values with single quotes and double quotes like: put "'galleriaIn'" into tOptions["easing"]. This applies to both functions.
Gallery Example (Using Static Meta Data)
For this example put your gallery images and your image properties file in assets/img/galleriaPics, this path is arbitrary for your own projects though. Download the Galleria framework. Put the file galleria-1.4.7.min.js in assets/js. Assuming you use the Galleria classic theme put a modified version (see above) of galleria.classic.min.js in assets/js. Put a modified version (see above) of galleria.classic.css in assets/css. Create the following view file and let's call it galleriaView.lc:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>[[gData["pageTitle"] ]]</title>
<? return rigCssAsset("galleria.classic.css") ?>
</head>
<body>
<div class="content">
<div id="galleria"></div>
</div>
<? return rigJsAsset("jsGoogleapis-jquery-2.2.4") ?>
<? return rigJsAsset("galleria-1.6.1.min.js") ?>
<? return rigJsAsset("galleria.classic.min.js") ?>
<? return rigGalleriaData("assets/img/galleriaPics") ?>
</body>
</html>
Note: rigGalleriaData("assets/img/galleriaPics") returns a reference to a Galleria JSON array including Galleria initialization code, or false on failure.
Now create a controller called galleria.lc:
<?lc
put "galleria,index" into gControllerHandlers
command galleria
rigLoadHelper "asset"
rigLoadHelper "galleria"
end galleria
command index
# SET PAGE TITLE
put "Galleria Helper Example" into gData["pageTitle"]
# LOAD THE VIEW FILE
get rigLoadView("galleriaView")
end index
--| END OF galleria.lc
--| Location: ./application/controllers/galleria.lc
----------------------------------------------------------------------
Try it!
To view your gallery, visit your site using a URL similar to this one:
example.com/index.lc/galleria/