Index: branches/1.0.x/inc/js/list_manager.js =================================================================== diff -u --- branches/1.0.x/inc/js/list_manager.js (revision 0) +++ branches/1.0.x/inc/js/list_manager.js (revision 14890) @@ -0,0 +1,187 @@ +function ListManager() {} + +ListManager.containerSelector = ''; // selector id of container +ListManager.url = ''; // url to template with list contents +ListManager.urlParams = {layout: 'list'}; +ListManager.filters = {}; +ListManager.xhrRequests = []; +ListManager.reloadTimer = null; +ListManager.reloadTimeout = 1000; + +ListManager.getUrl = function () { + var $url = this.url; +} + +ListManager.cancelXHRRequests = function () { + while ( this.xhrRequests.length > 0 ) { + this.xhrRequests.shift().abort(); + } +} + +ListManager.reload = function ($now) { + this.cancelXHRRequests(); + + if ( $now === undefined || $now === false ) { + this.updateAnchor(); + + return; + } + + var $container = $(this.containerSelector); + + $container.fadeTo('fast', 0.7); + + var $request = $.post( + this.url, + this.urlParams, + function ($data) { + $container.html($data).fadeTo('fast', 1.0); + } + ); + + this.xhrRequests.push($request); +} + +ListManager.scheduleReload = function () { + var $me = this; + + clearTimeout(this.reloadTimer); + + this.reloadTimer = setTimeout(function() { $me.reload(); }, this.reloadTimeout); +} + +ListManager.setParam = function ($name, $value, $reload) { + if ( $value === undefined || $value === '' ) { + // don't pass empty parameters + delete this.urlParams[$name]; + } + else { + this.urlParams[$name] = $value; + } + + if ( $reload === true ) { + this.reload(); + } +} + +ListManager.updateAnchor = function () { + var $query_string = [], + $url_params = sort_object(this.urlParams); + + for (var $param_name in $url_params) { + $query_string.push( $param_name + '=' + encodeURIComponent(this.urlParams[$param_name]) ); + } + + window.location.hash = '#' + $query_string.join('&'); +} + +ListManager.parseAnchor = function ($anchor) { + var $query_string = {}; + + $anchor.replace( + new RegExp('([^?=&]+)(=([^&]*))?', 'g'), + function($0, $1, $2, $3) { + $query_string[$1] = decodeURIComponent($3); + } + ); + + this.urlParams = $query_string; + this.reload(true); +} + +ListManager.replaceFilter = function ($form_id, $form_html) { + $('#' + $form_id).replaceWith($form_html); +} + +ListManager.registerFilter = function ($form_id) { + var $manager = this, + $form = $('#' + $form_id), + $field = $form.attr('filter_field'); + + $manager.filters[$field] = {'type': $form.attr('filter_type')}; + + $('h2:first a', $form).click( + function ($e) { + var $header = $(this).parent(), + $active = $header.hasClass('active'); + + $header.toggleClass('active', !$active); + $header.next().toggleClass('noactive', $active); + + return false; + } + ); + + switch( $manager.filters[$field].type ) { + case 'radio': + $("input[type='radio']", $form).click( + function ($e) { + $manager.updateFilterParams(); + } + ); + break; + + case 'checkbox': + $("input[type='checkbox']", $form).click( + function ($e) { + var $checkbox = $(this), + $hidden_id = $checkbox.attr('id').replace(/_([\d\w-=]|)+$/, ''), + $regexp = new RegExp(jq($hidden_id) + '_([\\d\\w-=]+)'); + + if ( $checkbox.val() == '' ) { + // "All" checkbox + $("input[type='checkbox']", $form).not($checkbox).attr('checked', false); + } + else if ( $checkbox.is(':checked') ) { + $("input[type='checkbox'][value='']", $form).attr('checked', false); + } + + update_checkbox_options($regexp, $hidden_id, $form); + + $manager.updateFilterParams(); + } + ); + break; + } +} + +ListManager.syncChecked = function ($checkboxes) { + $checkboxes.each( + function () { + var $me = $(this), + $checked = $me.is(':checked'), + $dt = $me.parent(), + $dd = $dt.next(); + + $dt.toggleClass('active', $checked); + $dd.toggleClass('active', $checked); + } + ); +} + +ListManager.updateFilterParams = function () { + var $form_fields; + + for (var $field in this.filters) { + $form_fields = $('#filter-form-' + $field).serializeArray(); + + for (var $i = 0; $i < $form_fields.length; $i++) { + this.setParam($form_fields[$i].name, $form_fields[$i].value); + } + + this.syncChecked( $("input[type=checkbox], input[type=radio]", '#filter-form-' + $field) ); + } + + this.scheduleReload(); +} + +ListManager.init = function () { + var $manager = this; + + $('body').bind( + 'anchorchanged', + function ($e, $anchor) { + $manager.parseAnchor($anchor); + } + ); +} \ No newline at end of file Index: branches/1.0.x/elements/side_boxes/filter_range.elm.tpl =================================================================== diff -u -r14733 -r14890 --- branches/1.0.x/elements/side_boxes/filter_range.elm.tpl (.../filter_range.elm.tpl) (revision 14733) +++ branches/1.0.x/elements/side_boxes/filter_range.elm.tpl (.../filter_range.elm.tpl) (revision 14890) @@ -31,4 +31,19 @@
- \ No newline at end of file + + + \ No newline at end of file Index: branches/1.0.x/elements/sorting.elm.tpl =================================================================== diff -u -r14864 -r14890 --- branches/1.0.x/elements/sorting.elm.tpl (.../sorting.elm.tpl) (revision 14864) +++ branches/1.0.x/elements/sorting.elm.tpl (.../sorting.elm.tpl) (revision 14890) @@ -1,27 +1,24 @@