JQuery Initialization on Listings Pages: Difference between revisions
Jump to navigation
Jump to search
| Line 44: | Line 44: | ||
====JavaScript/jQuery/AJAX==== | ====JavaScript/jQuery/AJAX==== | ||
===Operations buttons=== | |||
====Markup==== | |||
Sample: | |||
<syntaxhighlight lang="html4strict" enclose="div"> | |||
<td class="centered"> | |||
<div class="listops"><!-- | |||
--><button class="edit-btn" data-id="<?=$so->id?>" data-tid="<?=ShippingOption::SECTION_ID?>" data-op="edit" title="edit shipping option">edit shipping option</button><!-- | |||
--><button class="trash-btn" data-id="<?=$so->id?>" data-tid="<?=ShippingOption::SECTION_ID?>" data-op="delete" title="delete shipping option">delete shipping option</button> | |||
</div> | |||
</td> | |||
</syntaxhighlight> | |||
* Use the <code>button</code> element when the button will trigger a JQuery handler. | |||
* Use the <code>anchor</code> element when the button links to another page. | |||
* Buttons are wrapped in a <code>div</code> container with <code>listops</code> class. | |||
* The <code>class</code> attribute value of the button/anchor determines the icon that is loaded and (optionally) the AJAX handler that is invoked upon clicking the button. | |||
* Required attributes for AJAX handlers: | |||
** <code>data-id</code> | |||
** <code>data-tid</code> | |||
==Keywords JQuery handlers== | ==Keywords JQuery handlers== | ||
Revision as of 13:08, 5 June 2012
Listings JQuery handlers
$('#listings-container').listings('bindListingsHandlers')$('#listings-container')targets the element containing the listings.#listings-containeris the most common element for this, but any appropriate selector can be specified.- Inline edits:
.inline-edit-celldouble-click - Pagination & paging button handlers (
.page-btn) - Update cache:
.update-cache-btnclick - Delete records:
.trash-btnclick - Makes button icons for the following elements:
.details-btn,.preview-btn,.edit-btn,.print-btn,.update-cache-btn,.trash-btn. - Button element handlers should persist after listings content is refreshed.
$.listings('bindListingsHandlers')in turn calles$.listings('bindListingsButtons'). The two routines are separated so$.listings('bindListingsHandlers')doesn't need to be called multiple times to avoid attaching duplicate handlers to listings elements.- This routine does not refresh the handlers or buttons after the listings are refreshed. This can be achieved with
$(document).ready(function() {
$('#listings-container').listings('bindListingsHandlers');
LITTLED.init({setSortables: function() {
$('#listings-container').listings('bindListingsButtons');
}
});
});
Pagination
Content CMS
- Specify a listings handler script with the "listings uri" setting.
- Default handler is
/hostmgr/_ajax/utils/listings.php- Default handler requires that the content and filters objects for that type of content have been defined within the local
cache_class.
- Default handler requires that the content and filters objects for that type of content have been defined within the local
HTML
<table id="listings-table" data-tid="<?=$filters->site_section->id->value?>" data-p="<?=$filters->calc_rec_position()?>">
- The listings container is a table.
- Attributes of
tableelement:iddefault value#listings-table. Used as jQuery selector for paging functionality.data-tidcontent type contained within table. Used to retrieve paging content.data-pIndex of the first record on the page. E.g. on the 2nd page with 50 records per page the value would be 51.
PHP
include (COMMON_TEMPLATE_DIR."framework/navigation/listings_page_links.php");
- This include is placed outside the
table id="listings-table"element and inside thediv id="listings-container"element. - Upldate local
cache_classto support the content type. See Adding Content Types to the Local Cache Class
JavaScript/jQuery/AJAX
Operations buttons
Markup
Sample:
<td class="centered"> <div class="listops"><!-- --><button class="edit-btn" data-id="<?=$so->id?>" data-tid="<?=ShippingOption::SECTION_ID?>" data-op="edit" title="edit shipping option">edit shipping option</button><!-- --><button class="trash-btn" data-id="<?=$so->id?>" data-tid="<?=ShippingOption::SECTION_ID?>" data-op="delete" title="delete shipping option">delete shipping option</button> </div> </td>
- Use the
buttonelement when the button will trigger a JQuery handler. - Use the
anchorelement when the button links to another page. - Buttons are wrapped in a
divcontainer withlistopsclass. - The
classattribute value of the button/anchor determines the icon that is loaded and (optionally) the AJAX handler that is invoked upon clicking the button. - Required attributes for AJAX handlers:
data-iddata-tid
Keywords JQuery handlers
$('#listings-container').keywords('bindListingsHandlers')targets the element containing the listings. It's the most common element to use in this case, but any appropriate selector may be used.#listings-container- Loading inline editor:
.edit-kw-btnclick - Submitting and canceling inline edits:
.kw-commit-btnand.kw-cancel-btnclick - Button icons:
.ui-icon-edit $.keywords('bindListingsHandlers')in turn calles$.keywords('bindListingsButtons'). The two routines are separated so$.keywords('bindListingsHandlers')doesn't need to be called multiple times to avoid attaching duplicate handlers to listings elements.- Button element handlers should persist after listings content is refreshed.
- The routine doesn't handle refreshing the button elements when the listings content is refreshed.
- See also Keywords
Keyword filter autocomplete
$(selector).galleries('keywordAutocomplete')
Datepicker
$('.datepicker').datepicker();