Форумы / Cotonti / Extensions / Tag search working more like a search engine

Macik
#39500 02.05.2014 18:13

It's done this way because while you click tag link you get search result for tag with default parameters (pages order and search scope — pages|forum). And while you makes search from the Tags form you can specify addition parameters like scope and order. 

So if we want use /tags/bruce-willis, we can not add addition params, and on the other side if we add params we get it in URL — /tags/bruce-willis/&order=…

 

but… This quest can be partially solved with addition javascript:

file `tags.php` line ~80 (remove `a` parameter, adding `t` parameter):

	'TAGS_ACTION' => cot_url('plug', 'e=tags&t=-searchtag-'),

in `tags.tpl` (add input named `a`, and add script for target url substitution):

	<form action="{TAGS_ACTION}" method="post">
		<input id="tags-sq" type="text" name="t" value="{TAGS_QUERY}" />
		<input type="submit" value="&raquo;&raquo;" />
		<input type="hidden" name="a" value="{PHP.a}">
		<select name="order">
			<option value="">{PHP.L.tags_Orderby}</option>
			<option value="">--</option>
			{TAGS_ORDER}
		</select>
	</form>
	<script type="text/javascript">
		$(function() {
	  	$('form').submit(function(e){
	  		var url = $(this).attr('action'),
	  				tag = $(this).find('input[name="t"]').val();
	  		$(this).attr('action',url.replace(/\-searchtag\-/g,encodeURIComponent(tag)));
	  	});
    });
	</script>

This code works only with javascript and jQuery enabled.

p/s/ By pressing back button or F5 you still get browser query to resend request as we use addition parameters.

p.p.s. if you dont care about addition params or it «hardcoded» in plugin we can use simple redirect:

		$(function() {
	  	$('form').submit(function(e){
	  		var url = $(this).attr('action'),
	  				tag = $(this).find('input[name="t"]').val();
	  		window.location.assign(getBaseHref() + url.replace(/\-searchtag\-/g,encodeURIComponent(tag)));
	  	});
    });

As you suppose it should be..

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F