Index: branches/1.0.x/inc/js/list_manager.js =================================================================== diff -u -N --- 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 -N -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 -N -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 @@
+
+   + Products + - - + + - - + + + out of   + +
- - - out of   - -
- -
Sort by: @@ -88,26 +85,24 @@ } ); - - $('#paginate').change( - function () { - ListManager.setParam('page', $(this).val(), true); - } - ); + $('#paginate').change( + function () { + ListManager.setParam('page', $(this).val(), true); + } + ); - $('.prev, .next', '.paginate').click( - function ($e) { - var $option = $('option:selected', '#paginate')[ $(this).attr('class') ](); + $('.prev, .next', '.paginate').click( + function ($e) { + var $option = $('option:selected', '#paginate')[ $(this).attr('class') ](); - if ( $option.length ) { - $('#paginate').val( $option.attr('value') ).change(); - } - - return false; + if ( $option.length ) { + $('#paginate').val( $option.attr('value') ).change(); } - ); - + return false; + } + ); + $('#sorting').change( function ($e) { ListManager.setParam('sort_by', $(this).val().replace('|', ','), true); @@ -116,7 +111,13 @@ $('#per-page').change( function ($e) { - ListManager.setParam('per_page', $(this).val(), true); + var $per_page = $(this).val(); + + if ( $per_page == -1 ) { + ListManager.setParam('page', ''); + } + + ListManager.setParam('per_page', $per_page, true); } ); Index: branches/1.0.x/designs/section.tpl =================================================================== diff -u -N -r14864 -r14890 --- branches/1.0.x/designs/section.tpl (.../section.tpl) (revision 14864) +++ branches/1.0.x/designs/section.tpl (.../section.tpl) (revision 14890) @@ -13,9 +13,14 @@ - - - + + + + + + @@ -34,7 +39,12 @@ + + Index: branches/1.0.x/inc/js/jquery.scripts.js =================================================================== diff -u -N -r14822 -r14890 --- branches/1.0.x/inc/js/jquery.scripts.js (.../jquery.scripts.js) (revision 14822) +++ branches/1.0.x/inc/js/jquery.scripts.js (.../jquery.scripts.js) (revision 14890) @@ -1,6 +1,6 @@ /* === General usage functions === */ -function jq($selector) { - return $selector.replace(/(\[|\]|\.)/g, '\\$1'); +function jq($selector, $delimiter) { + return ($selector + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + ($delimiter || '') + '-]', 'g'), '\\$&'); } function in_array(needle, haystack) @@ -32,10 +32,10 @@ return document.getElementById( $prepend + $mask.replace('#FIELD_NAME#', $field) + $append ); } -function update_checkbox_options($cb_mask, $hidden_id, $form_id) +function update_checkbox_options($cb_mask, $hidden_id, $form_selector) { var $tmp = '', - $kf = document.getElementById($form_id !== undefined ? $form_id : $form_name); + $kf = $($form_selector !== undefined ? $form_selector : '#' + $form_name).get(0); for (var i = 0; i < $kf.elements.length; i++) { if ( $kf.elements[i].id.match($cb_mask) ) { @@ -52,6 +52,40 @@ document.getElementById($hidden_id).value = $tmp.replace(/,$/, ''); } +function watch_anchor () { + var $last_anchor = ''; + + setInterval( + function () { + if (window.location.hash != $last_anchor) { + $last_anchor = window.location.hash; + var $new_anchor = $last_anchor ? $last_anchor.substring(1) : ''; + + $('body').trigger('anchorchanged', [$new_anchor]); + } + }, 100 + ); +} + +function sort_object($object) { + // Setup Arrays + var $sorted_keys = [], $sorted_object = {}; + + for (var $property_name in $object) { + $sorted_keys.push($property_name); + } + + $sorted_keys.sort(); + + $($sorted_keys).each( + function () { + $sorted_object[this] = $object[this]; + } + ); + + return $sorted_object; +} + /* === DBlocks class === */ function DBlocks() { var $me = this; @@ -137,59 +171,63 @@ ) } -$(document).ready(function() -{ - $('#change-password').click( - function($e) { - $('#password-show').hide(); - $('#password-block').fadeIn(); +/* === Startup === */ +$(document).ready( + function() { + watch_anchor(); - return false; - } - ); + $('#change-password').click( + function($e) { + $('#password-show').hide(); + $('#password-block').fadeIn(); + return false; + } + ); - $('.addtocart, .button-addtocart').click( - function () { - var $me = $(this), - $qty = $me.attr('qty_id') !== undefined ? parseInt($('#' + $me.attr('qty_id')).val()) : 1; + $('.addtocart, .button-addtocart').click( + function () { + var $me = $(this), + $qty = $me.attr('qty_id') !== undefined ? parseInt($('#' + $me.attr('qty_id')).val()) : 1; - if ( $me.hasClass('addedtocart') ) { - // disabled button - return false; - } - if ( isNaN($qty) ) { - $qty = 1; - } + if ( $me.hasClass('addedtocart') ) { + // disabled button + return false; + } - var $bubble = $('.basketStatus'), - $timer_id = $bubble.data('hide_timer'); + if ( isNaN($qty) ) { + $qty = 1; + } - clearTimeout($timer_id); + var $bubble = $('.basketStatus'), + $timer_id = $bubble.data('hide_timer'); - $.get( - $me.attr('href') + '&qty=' + $qty, - function ($bubble_content) { - $('.basketContent', $bubble).html( $bubble_content.replace(/#QTY#/g, $qty) ); - $bubble - .stop(true, true) - .fadeIn( - 'slow', - function () { - var $timer = setTimeout(function(){ $bubble.fadeOut('slow'); }, 2000); - $bubble.data('hide_timer', $timer); - } - ); + clearTimeout($timer_id); - if ( $me.hasClass('addtocart') ) { - $me.removeClass('addtocart').addClass('addedtocart').html('Added to Cart'); + $.get( + $me.attr('href') + '&qty=' + $qty, + function ($bubble_content) { + $('.basketContent', $bubble).html( $bubble_content.replace(/#QTY#/g, $qty) ); + $bubble + .stop(true, true) + .fadeIn( + 'slow', + function () { + var $timer = setTimeout(function(){ $bubble.fadeOut('slow'); }, 2000); + $bubble.data('hide_timer', $timer); + } + ); + + if ( $me.hasClass('addtocart') ) { + $me.removeClass('addtocart').addClass('addedtocart').html('Added to Cart'); + } } - } - ); + ); - return false; - } - ); -}); \ No newline at end of file + return false; + } + ); + } +); \ No newline at end of file Index: branches/1.0.x/elements/content_boxes/products.elm.tpl =================================================================== diff -u -N -r14864 -r14890 --- branches/1.0.x/elements/content_boxes/products.elm.tpl (.../products.elm.tpl) (revision 14864) +++ branches/1.0.x/elements/content_boxes/products.elm.tpl (.../products.elm.tpl) (revision 14890) @@ -1,6 +1,7 @@ + @@ -10,13 +11,26 @@ - -
-
    - -
-
+ + - -
\ No newline at end of file +
+
    + +
+
+ + +
+ + No Products +
+ + + + + + \ No newline at end of file Index: branches/1.0.x/elements/filters.elm.tpl =================================================================== diff -u -N --- branches/1.0.x/elements/filters.elm.tpl (revision 0) +++ branches/1.0.x/elements/filters.elm.tpl (revision 14890) @@ -0,0 +1,115 @@ + + + + + + + + + + + + class="active"> + checked name="" id="_" value=""/>  + + class="active">() + + + +
+ +
+
+
+ + + + class="active"> + checked id="_" value=""/>  + + class="active">() + + + +
+ +
+
+ + +
+ + +
  • + +
  • +
    + + +
  • ()
  • +
    + + +
    +
      + +
    +
    +
      + +
    +
    +
    + + + + +
    + + + + + + + + +
    +

    Filter by

    +
    + +
    +
    + + + +
    + + + ListManager.replaceFilter('filter-form-', ''); + \ No newline at end of file