Commit fbde1978 authored by Robert Lyon's avatar Robert Lyon

Bug #1660808: Fixing tags.php javascript to work as expected

There were a few problems in the tags.php javascript when changed to
jQuery - and also problems that existed in mochikit due to template
issues

This patch should fix the problems

behatnotneeded - behat test to follow

Change-Id: Iae4e8d868f0fca96f4d8a9bf84df69649bdded00
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 504ee136
......@@ -36,7 +36,7 @@ foreach (array('tags', 'tag', 'sort', 'type') as $v) {
}
$js = <<<EOF
jQuery(function($) {
jQuery(function($) {
var p = null;
var mytags_container = null;
var inittags = {$str['tags']};
......@@ -55,8 +55,8 @@ $js = <<<EOF
}
function sortTagFreq(a, b) {
var aid = $(a).prop('id');
var bid = $(b).prop('id');
var aid = $(a).prop('id');
var bid = $(b).prop('id');
return mytags[bid] - mytags[aid];
}
......@@ -73,11 +73,16 @@ $js = <<<EOF
elems.each(function () {
$(mytags_container).append(this, ' ')
});
$('a.current-tab').each(function() {
$(this).removeClass('current-tab');
// set all tabs to inactive
$('ul.nav-tabs li').each(function() {
$(this).removeClass('active');
$(this).find('a').removeClass('current-tab');
$(this).find('.sr-only').html('(' + get_string_ajax('tab', 'mahara') + ')');
});
// set current one to active
$(this).closest('li').addClass('active');
$(this).addClass('current-tab');
$(this).find('.sr-only').html('(' + get_string_ajax('tab', 'mahara') + ' ' + get_string_ajax('selected', 'mahara') + ')');
return false;
});
......@@ -88,10 +93,17 @@ $js = <<<EOF
$(elem).on('click', function(e) {
e.preventDefault();
var reqparams = {};
reqparams[replace] = getUrlParameter('replace', $(this).prop('href'));
var currenthref = $(this).prop('href');
reqparams[replace] = getUrlParameter(replace, currenthref);
for (var i = 0; i < keep.length; i++) {
if (params[keep[i]]) {
reqparams[keep[i]] = params[keep[i]];
if (getUrlParameter(keep[i], currenthref)) {
reqparams[keep[i]] = getUrlParameter(keep[i], currenthref);
}
else {
reqparams[keep[i]] = params[keep[i]];
}
}
}
......@@ -101,19 +113,17 @@ $js = <<<EOF
if (data.data.tag != params.tag) {
// Update tag links in the My Tags list:
$(mytags_container).find('a.selected', function() {
$(this).removeClass('selected');
});
$(mytags_container).find('a.selected').removeClass('selected');
// Mark the selected tag in the My Tags list:
if (data.data.tag) {
$('[id="tag:' + data.data.tagurl + '""]').addClass('selected');
$('[id="tag:' + data.data.tagurl + '"]').addClass('selected');
}
// Replace the tag in the Search Results heading
var heading_tag = $('#results_heading a.tag').first();
if (heading_tag.length) {
heading_tag.prop('href', href);
heading_tag.prop('href', currenthref);
heading_tag.html(data.data.tagdisplay);
}
var edit_tag_link = $('#results_container a.edit-tag').first();
......@@ -134,14 +144,13 @@ $js = <<<EOF
// Rewrite tag links in the results list:
$('#results a.tag').each(function () {rewriteTagLink(this, [], 'tag')});
// Change selected Sort By links above the Search results:
if (data.data.sort != params.sort) {
$('#results_sort a').each(function () {
if ($(this).hasClass('selected') && data.data.sort != getUrlParameter('sort', $(this).prop('href'))) {
$(this).removeClass('selected');
}
else if (!$(this).removeClass('selected') && data.data.sort == getUrlParameter('sort', $(this).prop('href'))) {
else if (!$(this).hasClass('selected') && data.data.sort == getUrlParameter('sort', $(this).prop('href'))) {
$(this).addClass('selected');
}
});
......@@ -166,19 +175,20 @@ $js = <<<EOF
});
}
$.each(inittags, function(i, tag) {
mytags['tag:' + tag.tagurl] = tag.count;
});
$('a.tag-sort').each(rewriteTagSortLink);
mytags_container = $('#main-column-container .mytags').first();
p = {$data->pagination_js}
mytags_container.find('a.tag').each(function () {rewriteTagLink(this, [], 'tag')});
$('#sb-tags a.tag').each(function () {rewriteTagLink(this, [], 'tag')});
$('#results a.tag').each(function () {rewriteTagLink(this, [], 'tag')});
$('#results_sort a').each(function () {rewriteTagLink(this, ['tag', 'type'], 'tag')});
$('#results_filter a').each(function () {rewriteTagLink(this, ['tag', 'sort'], 'tag')});
$.each(inittags, function(i, tag) {
mytags['tag:' + tag.tagurl] = tag.count;
});
$('ul.nav-tabs a').each(rewriteTagSortLink);
mytags_container = $('#main-column-container .mytags').first();
p = {$data->pagination_js}
mytags_container.find('a.tag').each(function () {rewriteTagLink(this, [], 'tag')});
$('#sb-tags a.tag').each(function () {rewriteTagLink(this, [], 'tag')});
$('#results a.tag').each(function () {rewriteTagLink(this, [], 'tag')});
$('#results_sort a').each(function () {rewriteTagLink(this, ['tag', 'type', 'sort'], 'tag')});
$('#results_filter a').each(function () {rewriteTagLink(this, ['tag', 'type', 'sort'], 'tag')});
});
EOF;
$tagsortoptions = array();
......
......@@ -38,7 +38,7 @@
{/foreach}
<span class="icon icon-caret-down right" role="presentation" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu">
<ul class="dropdown-menu" id="results_filter">
{foreach from=$results->filtercols key=filtername item=filterdisplay name=filtercols}
<li>
<a href="{$results->baseurl}{$results->queryprefix}sort={$results->sort}&type={$filtername}"{if $results->filter == $filtername} class="selected"{/if}>{$filterdisplay}</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment