diff --git a/_build/data/transport.chunks.php b/_build/data/transport.chunks.php index f60ab95..ba2fa7b 100644 --- a/_build/data/transport.chunks.php +++ b/_build/data/transport.chunks.php @@ -1,82 +1,98 @@ - - * - * mSearch is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * mSearch is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * mSearch; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - * - * @package msearch - */ -/** - * Add chunks to build - * - * @package msearch - * @subpackage build - */ -$chunks = array(); - -$chunks[0]= $modx->newObject('modChunk'); -$chunks[0]->fromArray(array( - 'id' => 0, - 'name' => 'tpl.mSearch.row', - 'description' => 'Single row with search result', - 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mSearch.row.tpl'), -),'',true,true); -//$properties = include $sources['build'].'properties/properties.msearch.php'; -//$chunks[0]->setProperties($properties); -//unset($properties); - -$chunks[1]= $modx->newObject('modChunk'); -$chunks[1]->fromArray(array( - 'id' => 0, - 'name' => 'tpl.mFilter.outer', - 'description' => 'Chunk for templating filter outer.', - 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.outer.tpl'), -),'',true,true); - -$chunks[2]= $modx->newObject('modChunk'); -$chunks[2]->fromArray(array( - 'id' => 0, - 'name' => 'tpl.mFilter.param.outer', - 'description' => 'Chunk for templating one parameter in filter', - 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.outer.tpl'), -),'',true,true); - -$chunks[3]= $modx->newObject('modChunk'); -$chunks[3]->fromArray(array( - 'id' => 0, - 'name' => 'tpl.mFilter.param.checkbox', - 'description' => 'Chunk for templating one checkbox item in filter parameter', - 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.checkbox.tpl'), -),'',true,true); - -$chunks[4]= $modx->newObject('modChunk'); -$chunks[4]->fromArray(array( - 'id' => 0, - 'name' => 'tpl.mFilter.param.number', - 'description' => 'Chunk for templating number item in filter parameter. For example, price ("From, to")', - 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.number.tpl'), -),'',true,true); - -$chunks[5]= $modx->newObject('modChunk'); -$chunks[5]->fromArray(array( - 'id' => 0, - 'name' => 'mFilter', - 'description' => 'Example chunk with mFilter call', - 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.tpl'), -),'',true,true); - - -return $chunks; + + * + * mSearch is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * mSearch is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * mSearch; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + * + * @package msearch + */ +/** + * Add chunks to build + * + * @package msearch + * @subpackage build + */ +$chunks = array(); + +$chunks[0]= $modx->newObject('modChunk'); +$chunks[0]->fromArray(array( + 'id' => 0, + 'name' => 'tpl.mSearch.row', + 'description' => 'Single row with search result', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mSearch.row.tpl'), +),'',true,true); +//$properties = include $sources['build'].'properties/properties.msearch.php'; +//$chunks[0]->setProperties($properties); +//unset($properties); + +$chunks[1]= $modx->newObject('modChunk'); +$chunks[1]->fromArray(array( + 'id' => 1, + 'name' => 'tpl.mFilter.outer', + 'description' => 'Chunk for templating filter outer.', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.outer.tpl'), +),'',true,true); + +$chunks[2]= $modx->newObject('modChunk'); +$chunks[2]->fromArray(array( + 'id' => 2, + 'name' => 'tpl.mFilter.param.outer', + 'description' => 'Chunk for templating one parameter in filter', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.outer.tpl'), +),'',true,true); + +$chunks[3]= $modx->newObject('modChunk'); +$chunks[3]->fromArray(array( + 'id' => 3, + 'name' => 'tpl.mFilter.param.checkbox', + 'description' => 'Chunk for templating one checkbox item in filter parameter', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.checkbox.tpl'), +),'',true,true); + +$chunks[4]= $modx->newObject('modChunk'); +$chunks[4]->fromArray(array( + 'id' => 4, + 'name' => 'tpl.mFilter.param.number', + 'description' => 'Chunk for templating number item in filter parameter. For example, price ("From, to")', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.number.tpl'), +),'',true,true); + +$chunks[5]= $modx->newObject('modChunk'); +$chunks[5]->fromArray(array( + 'id' => 5, + 'name' => 'mFilter', + 'description' => 'Example chunk with mFilter call', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.tpl'), +),'',true,true); + + +$chunks[6]= $modx->newObject('modChunk'); +$chunks[6]->fromArray(array( + 'id' => 6, + 'name' => 'tpl.mFilter.param.number.outer', + 'description' => 'Chunk wrapper for number item.', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.number.outer.tpl'), +),'',true,true); + +$chunks[7]= $modx->newObject('modChunk'); +$chunks[7]->fromArray(array( + 'id' => 7, + 'name' => 'tpl.mFilter.param.checkbox.outer', + 'description' => 'Chunk wrapper for templating', + 'snippet' => getSnippetContent($sources['source_core'].'/elements/chunks/mFilter.param.checkbox.outer.tpl'), +),'',true,true); + +return $chunks; diff --git a/_build/properties/properties.php b/_build/properties/properties.php index 04b2d99..9331608 100644 --- a/_build/properties/properties.php +++ b/_build/properties/properties.php @@ -220,6 +220,13 @@ 'value' => 'tpl.mFilter.param.checkbox', 'lexicon' => 'msearch:properties' ), + array( + 'name' => 'tplParamCheckboxOuter', + 'desc' => 'mse.tplParamCheckboxOuter', + 'type' => 'textfield', + 'value' => 'tpl.mFilter.param.checkbox.outer', + 'lexicon' => 'msearch:properties' + ), array( 'name' => 'tplParamNumber', 'desc' => 'mse.tplParamNumber', @@ -227,6 +234,13 @@ 'value' => 'tpl.mFilter.param.number', 'lexicon' => 'msearch:properties' ), + array( + 'name' => 'tplParamNumberOuter', + 'desc' => 'mse.tplParamNumberOuter', + 'type' => 'textfield', + 'value' => 'tpl.mFilter.param.number.outer', + 'lexicon' => 'msearch:properties' + ), array( 'name' => 'tplOuter', 'desc' => 'mse.tplOuter', diff --git a/assets/components/msearch/js/mfilter.js b/assets/components/msearch/js/mfilter.js index 4d8581e..5f153e4 100644 --- a/assets/components/msearch/js/mfilter.js +++ b/assets/components/msearch/js/mfilter.js @@ -1,173 +1,177 @@ -$(document).ready(function() { - - // Слайдеры фильтра - $('.mFilter_slider').each(function() { - var form = $(this).parents('form'); - var idx = $(this).parents('.mFilter_wrapper').data('idx'); - var vmin = Number($('#min_'+idx).val()); - var vmax = Number($('#max_'+idx).val()); - - $(this).slider({ - min: vmin - ,max: vmax - ,values: [vmin, vmax] - ,range: true - ,stop: function(event, ui) { - $('input#min_'+idx).val($(this).slider('values',0)); - $('input#max_'+idx).val($(this).slider('values',1)); - $(form).find('input[name=page]').val(1); - $(form).submit(); - }, - slide: function(event, ui){ - $('input#min_'+idx).val($(this).slider('values',0)); - $('input#max_'+idx).val($(this).slider('values',1)); - } - }) - }) - - $(document).on('change', '#mFilter input', function() { - if ($(this).attr('type') == 'checkbox') { - $('#mFilter input[name=page]').val(1); - $(this).parent().find('sup').toggle(); - } - $(this).parents('form').submit() - }) - - $(document).on('click', '#mItems .mLimit', function(e) { - var limit = $(this).data('limit'); - $('#mFilter input[name=page]').val(1); - $('#mFilter input[name=limit]').val(limit).trigger('change'); - e.preventDefault(); - }) - - $(document).on('click', '#mItems .mSort', function(e) { - var sortby = $(this).data('sort'); - $('#mFilter input[name=sort]').val(sortby).trigger('change'); - e.preventDefault(); - }) - - $(document).on('click', '#mItems .pagination a', function(e) { - var href = $(this).attr('href').split('='); - - $('#mFilter input[name=page]').val(href[href.length - 1]).trigger('change'); - e.preventDefault(); - }) - - $(document).on('submit', '#mFilter', function(e) { - $(this).ajaxSubmit({ - success: function(res,status,form) { - var data = $.parseJSON(res) - - if (data.total) { - if ($('#mFilter_total')) - $('#mFilter_total').text(' ('+data.total+')'); - else - $('h1 span').text(' ('+data.total+')'); - } - $('#mFilter input[type=checkbox]').each(function() { - var name = $(this).attr('name').replace(/\[\]/, ''); - var val = $(this).val(); - - if (data.filter[name] == undefined) {tmp = 0;} - else {tmp = data.filter[name][val];} - - if (tmp != 0) { - $(this).removeAttr('disabled').parent().find('sup').text(tmp); - } - else { - $(this).attr('disabled','disabled').parent().find('sup').text(0); - } - }) - $('#mItems').html(data.rows).css('opacity',1) - } - ,beforeSubmit: function showRequest(formData, jqForm, options) { - $('#mItems').css('opacity',.5) - var tmp = new Object(); - for (var i in formData) { - key = formData[i].name - if (key == 'query' || key == 'action' || key == 'cat_id') {continue;} - if (tmp[key] == undefined) { - tmp[key] = new Array(); - } - tmp[key].push(formData[i].value) - } - var tmp2 = new Object(); - for (var i in tmp) { - tmp2[i] = tmp[i].join('--') - } - document.location.hash = $.param(tmp2) - return true; - } - }) - e.preventDefault(); - }) - $(document).on('change', '#mFilter .minCost, #mFilter .maxCost', function() { - var fieldset = $(this).parents('fieldset'); - var vmin = fieldset.find('.minCost').val(); - var vmax = fieldset.find('.maxCost').val(); - - if (Number(vmin) > Number(vmax)) { - vmin = vmax; - fieldset.find('.minCost').val(vmin); - fieldset.find('.maxCost').val(vmax); - } - fieldset.find('.mFilter_slider').slider("values",0,vmin); - fieldset.find('.mFilter_slider').slider("values",1,vmax); - }) - - - // Если есть хэш в url - пробуем отправить форму - if (vars = getUrlVars()) { - if ($('#mFilter').length == 0) {return;} - - for (i in vars) { - if (/\[\]/.test(i)) { - for (i2 in vars[i]) { - el = $('input[name="'+i+'"][value="'+vars[i][i2]+'"]'); - if (el.length > 0) { - el.attr('checked','checked').parent().find('sup').hide(); - } - else { - var name = i.replace(/\[\]/, ''); - if (i2 == 0) { - $('#mfilter_'+name+' .vmin').val(vars[i][0]).parent().find('.mFilter_slider').slider("values",0,vars[i][0]); - } - else { - $('#mfilter_'+name+' .vmax').val(vars[i][1]).parent().find('.mFilter_slider').slider("values",1,vars[i][1]) - } - } - } - } - else { - $('input[name='+i+']').val(vars[i]); - } - } - $('#mFilter').submit() - } - else if ($('#mFilter').length) { - $('#mFilter').submit(); - } -}) - - -// Разбор хэша url на значения -function getUrlVars() { - var vars = new Object(), hash; - var hashes = decodeURIComponent(window.location.hash.substr(1)); - if (hashes.length == 0) {return false;} - else {hashes = hashes.split('&');} - - for (var i in hashes) { - hash = hashes[i].split('='); - - if (hash[1] != undefined && /\[\]/.test(hash[0])) { - var tmp = hash[1].split('--'); - hash[1] = new Array(); - for (var i2 in tmp) { - hash[1].push(tmp[i2]); - } - } - vars[hash[0]] = hash[1]; - } - return vars; -} \ No newline at end of file +$(document).ready(function() { + + // Слайдеры фильтра + $('.mFilter_slider').each(function() { + var form = $(this).parents('form'); + var idx = $(this).parents('.mFilter_wrapper').data('idx'); + var vmin = Number($('#min_'+idx).val()); + var vmax = Number($('#max_'+idx).val()); + + $(this).slider({ + min: vmin + ,max: vmax + ,values: [vmin, vmax] + ,range: true + ,stop: function(event, ui) { + $('input#min_'+idx).val($(this).slider('values',0)); + $('input#max_'+idx).val($(this).slider('values',1)); + $(form).find('input[name=page]').val(1); + $(form).submit(); + }, + slide: function(event, ui){ + $('input#min_'+idx).val($(this).slider('values',0)); + $('input#max_'+idx).val($(this).slider('values',1)); + } + }) + }) + + $(document).on('change', '#mFilter input, #mFilter select', function() { + if ($(this).attr('type') == 'checkbox') { + $('#mFilter input[name=page]').val(1); + $(this).parent().find('sup').toggle(); + } + $(this).parents('form').submit() + }) + + $(document).on('click', '#mItems .mLimit', function(e) { + var limit = $(this).data('limit'); + $('#mFilter input[name=page]').val(1); + $('#mFilter input[name=limit]').val(limit).trigger('change'); + e.preventDefault(); + }) + + $(document).on('click', '#mItems .mSort', function(e) { + var sortby = $(this).data('sort'); + $('#mFilter input[name=sort]').val(sortby).trigger('change'); + e.preventDefault(); + }) + + $(document).on('click', '#mItems .pagination a', function(e) { + var href = $(this).attr('href').split('='); + + $('#mFilter input[name=page]').val(href[href.length - 1]).trigger('change'); + e.preventDefault(); + }) + + $(document).on('submit', '#mFilter', function(e) { + $(this).ajaxSubmit({ + success: function(res,status,form) { + var data = $.parseJSON(res) + + if (data.total) { + if ($('#mFilter_total')) + $('#mFilter_total').text(' ('+data.total+')'); + else + $('h1 span').text(' ('+data.total+')'); + } + $('#mFilter input[type=checkbox]').each(function() { + var name = $(this).attr('name').replace(/\[\]/, ''); + var val = $(this).val(); + + if (data.filter[name] == undefined) {tmp = 0;} + else {tmp = data.filter[name][val];} + + if (tmp != 0) { + $(this).removeAttr('disabled').parent().find('sup').text(tmp); + } + else { + $(this).attr('disabled','disabled').parent().find('sup').text(0); + } + }) + $('#mItems').html(data.rows).css('opacity',1) + } + ,beforeSubmit: function showRequest(formData, jqForm, options) { + $('#mItems').css('opacity',.5) + var tmp = new Object(); + for (var i=formData.length; i>=0; i--) { + if (typeof formData[i] === "undefined" || formData[i].value=="") { + formData.splice(i,1); + continue; + } + key = formData[i].name + if (key == 'query' || key == 'action' || key == 'cat_id') {continue;} + if (tmp[key] == undefined) { + tmp[key] = new Array(); + } + tmp[key].push(formData[i].value) + } + var tmp2 = new Object(); + for (var i in tmp) { + tmp2[i] = tmp[i].join('--') + } + document.location.hash = $.param(tmp2) + return true; + } + }) + e.preventDefault(); + }) + $(document).on('change', '#mFilter .minCost, #mFilter .maxCost', function() { + var fieldset = $(this).parents('fieldset'); + var vmin = fieldset.find('.minCost').val(); + var vmax = fieldset.find('.maxCost').val(); + + if (Number(vmin) > Number(vmax)) { + vmin = vmax; + fieldset.find('.minCost').val(vmin); + fieldset.find('.maxCost').val(vmax); + } + fieldset.find('.mFilter_slider').slider("values",0,vmin); + fieldset.find('.mFilter_slider').slider("values",1,vmax); + }) + + + // Если есть хэш в url - пробуем отправить форму + if (vars = getUrlVars()) { + if ($('#mFilter').length == 0) {return;} + + for (i in vars) { + if (/\[\]/.test(i)) { + for (i2 in vars[i]) { + el = $('input[name="'+i+'"][value="'+vars[i][i2]+'"]'); + if (el.length > 0) { + el.attr('checked','checked').parent().find('sup').hide(); + } + else { + var name = i.replace(/\[\]/, ''); + if (i2 == 0) { + $('#mfilter_'+name+' .vmin').val(vars[i][0]).parent().find('.mFilter_slider').slider("values",0,vars[i][0]); + } + else { + $('#mfilter_'+name+' .vmax').val(vars[i][1]).parent().find('.mFilter_slider').slider("values",1,vars[i][1]) + } + } + } + } + else { + $('input[name='+i+']').val(vars[i]); + } + } + $('#mFilter').submit() + } + else if ($('#mFilter').length) { + $('#mFilter').submit(); + } +}) + + +// Разбор хэша url на значения +function getUrlVars() { + var vars = new Object(), hash; + var hashes = decodeURIComponent(window.location.hash.substr(1)); + if (hashes.length == 0) {return false;} + else {hashes = hashes.split('&');} + + for (var i in hashes) { + hash = hashes[i].split('='); + + if (hash[1] != undefined && /\[\]/.test(hash[0])) { + var tmp = hash[1].split('--'); + hash[1] = new Array(); + for (var i2 in tmp) { + hash[1].push(tmp[i2]); + } + } + vars[hash[0]] = hash[1]; + } + return vars; +} diff --git a/core/components/msearch/elements/chunks/mFilter.param.checkbox.outer.tpl b/core/components/msearch/elements/chunks/mFilter.param.checkbox.outer.tpl new file mode 100644 index 0000000..50fd003 --- /dev/null +++ b/core/components/msearch/elements/chunks/mFilter.param.checkbox.outer.tpl @@ -0,0 +1 @@ +[[+inner]] \ No newline at end of file diff --git a/core/components/msearch/elements/chunks/mFilter.param.number.outer.tpl b/core/components/msearch/elements/chunks/mFilter.param.number.outer.tpl new file mode 100644 index 0000000..50fd003 --- /dev/null +++ b/core/components/msearch/elements/chunks/mFilter.param.number.outer.tpl @@ -0,0 +1 @@ +[[+inner]] \ No newline at end of file diff --git a/core/components/msearch/elements/snippets/snippet.mfilter.php b/core/components/msearch/elements/snippets/snippet.mfilter.php index 459113f..f982925 100644 --- a/core/components/msearch/elements/snippets/snippet.mfilter.php +++ b/core/components/msearch/elements/snippets/snippet.mfilter.php @@ -107,17 +107,20 @@ if ($v['type'] == 'number') { $tmp = array_keys($v['values']); if (count($tmp) < 2) {continue;} - $rows .= $modx->getChunk($tplParamNumber, array('paramname' => $k, 'min' => min($tmp), 'max' => max($tmp), 'idx' => $idx)); + $row = $modx->getChunk($tplParamNumber, array('paramname' => $k, 'min' => min($tmp), 'max' => max($tmp), 'idx' => $idx)); + $rows .= $modx->getChunk($tplParamNumberOuter, array('inner' => $row)); $idx++; } else { if (count($v['values']) < 2) {continue;} ksort($v['values']); + $row = ''; foreach ($v['values'] as $k2 => $v2) { $num = !empty($modx->mSearch->config['fastMode']) ? '' : count($v2); - $rows .= $modx->getChunk($tplParamCheckbox, array('paramname' => $k, 'value' => $k2, 'num' => $num, 'idx' => $idx)); + $row .= $modx->getChunk($tplParamCheckbox, array('paramname' => $k, 'value' => $k2, 'num' => $num, 'idx' => $idx)); $idx++; } + $rows .= $modx->getChunk($tplParamCheckboxOuter, array('paramname' => $k, 'inner' => $row)); } $v['paramname'] = $k; $v['rows'] = $rows; diff --git a/core/components/msearch/lexicon/en/properties.inc.php b/core/components/msearch/lexicon/en/properties.inc.php index 3f4d2a7..3f8d37e 100644 --- a/core/components/msearch/lexicon/en/properties.inc.php +++ b/core/components/msearch/lexicon/en/properties.inc.php @@ -28,7 +28,9 @@ $_lang['mse.tplParamOuter'] = 'Chunk for templating one parameter in filter.'; $_lang['mse.tplParamCheckbox'] = 'Chunk for templating one checkbox item in filter parameter.'; +$_lang['mse.tplParamCheckboxOuter'] = 'Chunk wprapper for checkbox item'; $_lang['mse.tplParamNumber'] = 'Chunk for templating number item in filter parameter. For example, price ("From, to").'; +$_lang['mse.tplParamNumberOuter'] = 'Chunk wrapper for number item.'; $_lang['mse.tplOuter'] = 'Chunk for templating filter outer.'; $_lang['mse.ids'] = 'Comma-separated list of resources for generating filters and searching. If not specified - resources will be found by snippet mSearch.'; $_lang['mse.sortFilters'] = 'Comma-separated list how to sort filters, with prefix. For example: &filtersOrder=`tv_color,tv_vendor,ms_price,ms_weight,tv_year`. Prefix can be an "tv_" or "ms_" - from miniShop table.'; diff --git a/core/components/msearch/lexicon/ru/properties.inc.php b/core/components/msearch/lexicon/ru/properties.inc.php index 5a581e0..7c54a33 100644 --- a/core/components/msearch/lexicon/ru/properties.inc.php +++ b/core/components/msearch/lexicon/ru/properties.inc.php @@ -1,37 +1,39 @@ -