Album/Gallery Listings: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
No edit summary
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
==PHP templates==
[[Category:CMS Documentation]] [[Category:Littled Libraries]] [[Category:Albums CMS]] [[Category:jQuery/AJAX]] [[Category:Web Development]]
===Listings pages===


This comes into play in album listings where there is an expand button for each of the albums which reveals the album's gallery.
== Application ==
 
See also: [[Albums CMS Design Principles]]
 
=== PHP ===
 
==== Album listings pages ====


===Album details and edit pages===
* Add shared album listings template on the page, enclosed in a `<nowiki><div></nowiki>`
** class `listings album-listings`
** `data-tid` attribute
*** Value is the `site_section` representing the listings content.
*** Used for all shared AJAX scripts.
** `data-p` attribute
*** Value is the position of the first record on the page within the entire set of matching records.
*** Used for sorting.


PHP include that inserts the gallery container element into the page. It allows for either default listing content, or custom gallery listings content:
Example:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
<? include (COMMON_TEMPLATE_DIR."forms/images/gallery_listings_container.php"); ?>
<div class="listings album-listings" data-tid="<?=$filters->site_section->id->value ?>" data-p="<?=$filters->calc_rec_position()?>">
<? include (CMS_COMMON_TEMPLATE_DIR."content/albums/album_listings.php"); ?>
</div>
</syntaxhighlight>
</syntaxhighlight>


The content is then loaded into the page on the page onload handler:
==== Album details pages ====
 
~~TK~~
 
=== Javascript ===
 
==== Album listings pages ====


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
$(document).ready(function(){
$(document).ready(function() {
LITTLED.Gallery.retrieveGallery({pid: <?=$input->id->value?>});
/* Binds AJAX functionality to album listings elements */
$('.album-listings').galleries('bindAlbumListingsHandlers');
});
});
</syntaxhighlight>
</syntaxhighlight>


*<code>LITTLED.Gallery.retrieveGallery()</code> in turn calls <code>LITTLED.Gallery.bindGalleryHandlers()</code> which in turn calls <code>LITTLED.Gallery.configureSorting()</code>.
==== Album details pages ====
*<code>LITTLED.Gallery.retrieveGallery()</code> uses the AJAX handler script specified with Sections CMS > Content Type > Listings URI.
**The default listings handler for galleries is <code>/_ajax/images/gallery_listings.php</code>.


==JavaScript/JQuery handlers==
<syntaxhighlight lang="javascript">
$(document).ready(function() {
/* retrieves gallery content */
$('.gallery-listings').galleries('retrieveGallery');
});
</syntaxhighlight>


===Listings selectors===
=== AJAX ===
The default container for galleries is <code>#gallery-listings</code>.
* If the parent element is a <code><nowiki><table></nowiki></code> the sortable elements are specified with <code>tr.page-row</code>.
* If the parent element is a <code><nowiki><div></nowiki></code> the sortable elements are marked with <code>.page-cell</code>.


===Album listings===
Assign AJAX handlers through the [[Littled Content Properties CMS|Content Properties CMS]].
<syntaxhighlight lang="javascript">
$([LISTINGS_SELECTOR]).galleries('bindAlbumListingsHandlers');
</syntaxhighlight>


<code>bindAlbumListingsHandlers</code> binds
* '''Listings''' `/_ajax/utils/listings.php`
* Content refresh events
* '''Delete record''' `/_ajax/utils/delete_record.php`
* Persistent highlighting of line items within listings after being clicked
* '''Resort''' `/_ajax/utils/resort.php`
* Page navigation
* '''Update Cache''' `/_ajax/utils/update_cache.php`
* Toggling galleries
* Image details lightbox dialogs
* Image preview tooltips
* Inline editing of images
* Cache update buttons
* Inline deletion of albums
* Cache update buttons
* Inline edits of things like titles, status, dates, etc.


===Gallery listings===
== PHP templates ==
<syntaxhighlight lang="javascript">
$([GALLERY_SELECTOR]).galleries('bindGalleryHandlers');
</syntaxhighlight>


<code>bindGalleryHandlers</code> binds
=== Listings pages ===
*Image details lightbox
*Image preview rollovers
*Line-item edit operation buttons (details,edit,delete)
*Page navigation within the gallery
*Gallery filters interactivity
*Inline data edits
*Inline keyword edits
*Record sorting
*Calendar popups


===Refreshing listings content===
This comes into play in album listings where there is an expand button for each of the albums which reveals the album's gallery.
Listings content refreshes for either Album listings or Gallery listings is achieved with


<syntaxhighlight lang="javascript">
=== Album details and edit pages ===
$([LISTINGS_SELECTOR]).trigger('contentRefresh');
</syntaxhighlight>


==Image rollovers==
PHP include that inserts the gallery container element into the page. It allows for either default listing content, or custom gallery listings content:


===JavaScript===
<syntaxhighlight lang="php">
* Requires “poshytip” JavaScript library in addition to the JQuery libraries.
<? include (CMS_COMMON_TEMPLATE_DIR."forms/images/gallery_listings_container.php"); ?>
* JQuery handlers
* Handler assigned via <code>$('#listings-container').galleries('bindAlbumListingsButtons')</code> or <code>$('#listings-container').galleries('bindGalleryButtons')</code><br /><syntaxhighlight lang="javascript">
$('.album-tn').poshytip(imagePreviewSettings);
</syntaxhighlight>
</syntaxhighlight>


===Markup===
== Image rollovers ==
==== Thumbnail <code><nowiki><img></nowiki></code> element ====
 
* <code>class="album-tn"</code><br />The <code>album-tn</code> class is the hook for the jQuery/poshytip handlers.
See [[Image Rollovers (Poshytip)]]
* This <code><nowiki><img></nowiki></code> must have a <code>title</code> attribute with some non-empty string value. If not, a JavaScript error is thrown within the PosyTip library.
* When no thumbnail is available for the record:<br /><syntaxhighlight lang="html4strict">
<div class="error" style="text-align:center;">no thumbnail</div>
</syntaxhighlight>
==== Preview <code><nowiki><img></nowiki></code> element ====
* Follow the thumbnail <code><nowiki><img class="album-tn"></nowiki></code> element with an <code><nowiki><img></nowiki></code> element containing the medium or full-sized image wrapped in <code><nowiki><span></nowiki></code> tags, depending on which size should appear on rollover.
** <code><nowiki><span></nowiki></code> tag attributes:
** <code><nowiki><span class="tooltip-content"></nowiki></code><br />The <code>tooltip-content</code> class will hide the full-sized image until a rollover event is captured by the thumbnail.
** The <code><nowiki><span></nowiki></code> element doesn’t require any class attributes.


==Image lightbox==
==Image lightbox==


===JavaScript===
=== Markup ===
* Surround thumbnail <code><nowiki><img></nowiki></code> element in <code><nowiki><a></nowiki></code> tags with the following attributes:
** <code>href="javascript:void(0)" rel="nofollow"</code>
** <code>class="img-details-link"</code><br />This is the selector used to assign the <code>onclick</code> handler.
** <code>data-id="[IMAGE_LINK_ID]"</code>
** <code>data-tid="[GALLERY_SECTION_ID]"</code>
** <code>data-op="view"</code> or <code>data-op="details"</code><br />This allows the jQuery handler to retrieve the correct AJAX script to call to retrieve the details dialog content.
* Note that it doesn't seem to work having this link around the preview image. I.e. it's not immediately apparent that it's possible to click on the tooltip preview of the image to open up a full-sized version of the image in a lightbox.
 
=== JavaScript ===
* <code>$('img-details-link')</code> <code>onclick</code> handler opens a dialog containing the full-resolution version of the image.  
* <code>$('img-details-link')</code> <code>onclick</code> handler opens a dialog containing the full-resolution version of the image.  
* <code>onclick</code> handler defined in <code>$.galleries('bindAlbumListingsHandlers')</code>
* <code>onclick</code> handler defined in <code>$.galleries('bindAlbumListingsHandlers')</code>
* The <code>onclick</code> handler invokes <code>$.formDialog('open', {dialogClass, 'gallery-dialog'})</code>
* The <code>onclick</code> handler invokes <code>$.formDialog('open', {dialogClass, 'gallery-dialog'})</code>


===Markup===
=== CMS ===
* <code><nowiki><img></nowiki></code> tag attributes
* '''Details URI''': <code>/_ajax/images/image_details.php</code><br />This returns markup containing the full-resolution version of the image to be displayed in the lightbox dialog.
** <code>class="img-details-link"</code><br />This is the selector used to assign the <code>onclick</code> handler.
* Surround <code><nowiki><img></nowiki></code> element in <code><nowiki><a></nowiki></code> tags.
** <code><nowiki><a></nowiki></code> tag attributes:
** <code>data-op="view"</code><br />This allows the jQuery handler to retrieve the correct AJAX script to call to retrieve the details dialog content.
** <code>data-id="[IMAGE_LINK_ID]"</code>
** <code>data-tid="[GALLERY_SECTION_ID]"</code>
** <code>href="javascript:void(0)" rel="nofollow"</code>
 
===CMS===
* Details URI: <code>/_ajax/images/image_details.php</code><br />This returns markup containing the full-resolution version of the image to be displayed in the lightbox dialog.


==Inserting an "add image" button==
==Inserting an "add image" button==
Line 148: Line 130:
</syntaxhighlight>
</syntaxhighlight>
<code>.alb-nav</code> click > <code>$.galleries('gotoAlbumPage')</code>
<code>.alb-nav</code> click > <code>$.galleries('gotoAlbumPage')</code>
==Refreshing content==
The default container for gallery listings has <code>id="pages-[PARENT_ID]"</code>.
This is the selector used to locate the gallery listings in the DOM after an AJAX content edit has been performed.
The AJAX handler script will pass back the DOM selector of the gallery listings in the <code>container_id</code> field of the JSON data. The default image upload and edit scripts will pass back <code>pages-[PARENT_ID]</code> as the selector if it's determined that the control that invoked the AJAX handler script resided within gallery listings.
<syntaxhighlight lang="html4strict">
<div id="pages-34">
    <div><!--// GALLERY LISTINGS CONTENT GOES HERE //--></div>
</div>
</syntaxhighlight>
The actual content used to refresh the content container is determined in the PHP routine <code>cache_cache::refresh_content_after_image_edit()</code>. The content type id determines which content template is selected. By default the include file <code>[COMMON_TEMPLATE_DIR]content/albums/gallery_listings.php</code> is used. Other cases can be added to select other templates.
<syntaxhighlight lang="php">
/* defaults to image listings */
$json->container_id->value = "pages-{$content->parent_id->value}";
$filters = new gallery_filters_class($content->site_section->id->value);
$filters->parse_filters();
ob_start();
include (COMMON_TEMPLATE_DIR."content/albums/gallery_listings.php");
$json->content->value = ob_get_contents();
ob_end_clean();
</syntaxhighlight>


==Sorting==
==Sorting==
Line 197: Line 148:
*[[Albums CMS Configuration]]
*[[Albums CMS Configuration]]
*[[Sorting Listings]]
*[[Sorting Listings]]
[[Category:Albums CMS]]
[[Category:CMS Documentation]]

Latest revision as of 20:37, 11 September 2014


Application[edit]

See also: Albums CMS Design Principles

PHP[edit]

Album listings pages[edit]

  • Add shared album listings template on the page, enclosed in a `<div>
    • class listings album-listings
    • data-tid attribute
      • Value is the site_section representing the listings content.
      • Used for all shared AJAX scripts.
    • data-p` attribute
      • Value is the position of the first record on the page within the entire set of matching records.
      • Used for sorting.

Example:

<div class="listings album-listings" data-tid="<?=$filters->site_section->id->value ?>" data-p="<?=$filters->calc_rec_position()?>">
<? include (CMS_COMMON_TEMPLATE_DIR."content/albums/album_listings.php"); ?>
	</div>

Album details pages[edit]

~~TK~~

Javascript[edit]

Album listings pages[edit]

$(document).ready(function() {
	/* Binds AJAX functionality to album listings elements */
	$('.album-listings').galleries('bindAlbumListingsHandlers');
});

Album details pages[edit]

$(document).ready(function() {
	/* retrieves gallery content */
	$('.gallery-listings').galleries('retrieveGallery');	
});

AJAX[edit]

Assign AJAX handlers through the Content Properties CMS.

  • Listings /_ajax/utils/listings.php
  • Delete record /_ajax/utils/delete_record.php
  • Resort /_ajax/utils/resort.php
  • Update Cache /_ajax/utils/update_cache.php

PHP templates[edit]

Listings pages[edit]

This comes into play in album listings where there is an expand button for each of the albums which reveals the album's gallery.

Album details and edit pages[edit]

PHP include that inserts the gallery container element into the page. It allows for either default listing content, or custom gallery listings content:

<? include (CMS_COMMON_TEMPLATE_DIR."forms/images/gallery_listings_container.php"); ?>

Image rollovers[edit]

See Image Rollovers (Poshytip)

Image lightbox[edit]

Markup[edit]

  • Surround thumbnail <img> element in <a> tags with the following attributes:
    • href="javascript:void(0)" rel="nofollow"
    • class="img-details-link"
      This is the selector used to assign the onclick handler.
    • data-id="[IMAGE_LINK_ID]"
    • data-tid="[GALLERY_SECTION_ID]"
    • data-op="view" or data-op="details"
      This allows the jQuery handler to retrieve the correct AJAX script to call to retrieve the details dialog content.
  • Note that it doesn't seem to work having this link around the preview image. I.e. it's not immediately apparent that it's possible to click on the tooltip preview of the image to open up a full-sized version of the image in a lightbox.

JavaScript[edit]

  • $('img-details-link') onclick handler opens a dialog containing the full-resolution version of the image.
  • onclick handler defined in $.galleries('bindAlbumListingsHandlers')
  • The onclick handler invokes $.formDialog('open', {dialogClass, 'gallery-dialog'})

CMS[edit]

  • Details URI: /_ajax/images/image_details.php
    This returns markup containing the full-resolution version of the image to be displayed in the lightbox dialog.

Inserting an "add image" button[edit]

Markup[edit]

<button class="add-img-btn" data-id="<?=$img->id->value?>" data-pid="<?=$input->id->value?>" data-tid="<?=$img->type_id->value ?>" title="add image">add image</button>

JavaScript[edit]

$('.add-img-btn', $p)
.iconButton('addchild')
.on('click', methods.editImage); /* "methods" in the context of $.galleries() */

The $('.add-img-btn') handler is rolled into $.galleries('bindGalleryHandlers').

AJAX handler script[edit]

The handler script is determined by section_properties.upload_uri. If no value is found in that column, the code falls back on section_properties.edit_uri.

That page will expect a combination of values to be passed in via the id, pid, and tid arguments. Only tid (type id) is strictly required. pid (parent id) can be null in cases when creating a new parent record and uploading images simultaneously. id (image link record id) can be null in cases when uploading a new image.

Pagination[edit]

PHP[edit]

Album listings:

include (COMMON_TEMPLATE_DIR."framework/navigation/listings_page_links.php");

JavaScript[edit]

Handlers rolled into Album listings:

$('#listings-container').galleries('bindListingsHandlers');

.alb-nav click > $.galleries('gotoAlbumPage')

Sorting[edit]

JavaScript[edit]

LITTLED.Gallery.configureSorting(parent_dom_id) which is rolled into LITTLED.Gallery.bindGalleryHandlers(parent_dom_id).

Markup[edit]

Container and sortable elements selectors are table.gallery-listings and tr.page-row or any div selector passed to LITTLED.Gallery.configureSorting() and .page-cell for the sortable selector.

AJAX handler script[edit]

Specified through with "Sections" CMS > Content Type > Sorting URI. The generic shared script is /_ajax/utils/resort.php. See Sorting Listings for more details.

See also[edit]