Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Remove BCC without Autosuggest-errors

Aloittaja Ahadawan, tammikuu 31, 2014, 01:56:49 IP

« edellinen - seuraava »

Ahadawan

Hi,

I'm trying to make this change on my SMF 1.1.19 forum, as well as my 2.0.7 board. Right now i have more problem with my SMF 1.1.19 forum, so I will focus on that code. I have tried to search for a mod or a hidden setting but cannot really find one.

The problem is I want to disable the BCC (blind carbon copy) on PMs for all members, but when I just remove the lines, the darn autosuggester in the To-fields stops working, giving errors as I try to write. I think this is related to the javascript-function and just so no-one has to dig through their files I'll add both code snippets below.

Koodi (This is the fields for To and BCC) [Valitse]
// To and bcc. Include a button to search for members.
echo '
<tr>
<td align="right"><b', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' style="color: red;"' : ''), '>', $txt[150], ':</b></td>
<td class="smalltext">
<input type="text" name="to" id="to" value="', $context['to'], '" tabindex="', $context['tabindex']++, '" size="40" />&nbsp;
<a href="', $scripturl, '?action=findmember;input=to;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);"><img src="', $settings['images_url'], '/icons/assist.gif" alt="', $txt['find_members'], '" /></a> <a href="', $scripturl, '?action=findmember;input=to;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);">', $txt['find_members'], '</a>
</td>
</tr><tr>
<td align="right"><b', (isset($context['post_error']['bad_bcc']) ? ' style="color: red;"' : ''), '>', $txt[1502], ':</b></td>
<td class="smalltext">
<input type="text" name="bcc" id="bcc" value="', $context['bcc'], '" tabindex="', $context['tabindex']++, '" size="40" />&nbsp;
<a href="', $scripturl, '?action=findmember;input=bcc;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);"><img src="', $settings['images_url'], '/icons/assist.gif" alt="', $txt['find_members'], '" /></a> ', $txt[748], '
</td>
</tr>';


Koodi (Here is the JavaScript) [Valitse]

<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function autocompleter(element)
{
if (typeof(element) != "object")
element = document.getElementById(element);

this.element = element;
this.key = null;
this.request = null;
this.source = null;
this.lastSearch = "";
this.oldValue = "";
this.cache = [];

this.change = function (ev, force)
{
if (window.event)
this.key = window.event.keyCode + 0;
else
this.key = ev.keyCode + 0;
if (this.key == 27)
return true;
if (this.key == 34 || this.key == 8 || this.key == 13 || (this.key >= 37 && this.key <= 40))
force = false;

if (isEmptyText(this.element))
return true;

if (this.request != null && typeof(this.request) == "object")
this.request.abort();

var element = this.element, search = this.element.value.replace(/^("[^"]+",[ ]*)+/, "").replace(/^([^,]+,[ ]*)+/, "");
this.oldValue = this.element.value.substr(0, this.element.value.length - search.length);
if (search.substr(0, 1) == \'"\')
search = search.substr(1);

if (search == "" || search.substr(search.length - 1) == \'"\')
return true;

if (this.lastSearch == search)
{
if (force)
this.select(this.cache[0]);

return true;
}
else if (search.substr(0, this.lastSearch.length) == this.lastSearch && this.cache.length != 100)
{
// Instead of hitting the server again, just narrow down the results...
var newcache = [], j = 0;
for (var k = 0; k < this.cache.length; k++)
{
if (this.cache[k].substr(0, search.length) == search)
newcache[j++] = this.cache[k];
}

if (newcache.length != 0)
{
this.lastSearch = search;
this.cache = newcache;

if (force)
this.select(newcache[0]);

return true;
}
}

this.request = new XMLHttpRequest();
this.request.onreadystatechange = function ()
{
element.autocompleter.handler(force);
}

this.request.open("GET", this.source + escape(textToEntities(search).replace(/&#(\d+);/g, "%#$1%")).replace(/%26/g, "%25%23038%25") + ";" + (new Date().getTime()), true);
this.request.send(null);

return true;
}
this.keyup = function (ev)
{
this.change(ev, true);

return true;
}
this.keydown = function ()
{
if (this.request != null && typeof(this.request) == "object")
this.request.abort();
}
this.handler = function (force)
{
if (this.request.readyState != 4)
return true;

var response = this.request.responseText.split("\n");
this.lastSearch = this.element.value;
this.cache = response;

if (response.length < 2)
return true;

if (force)
this.select(response[0]);

return true;
}
this.select = function (value)
{
if (value == "")
return;

var i = this.element.value.length + (this.element.value.substr(this.oldValue.length, 1) == \'"\' ? 0 : 1);
this.element.value = this.oldValue + \'"\' + value + \'"\';

if (typeof(this.element.createTextRange) != "undefined")
{
var d = this.element.createTextRange();
d.moveStart("character", i);
d.select();
}
else if (this.element.setSelectionRange)
{
this.element.focus();
this.element.setSelectionRange(i, this.element.value.length);
}
}

this.element.autocompleter = this;
this.element.setAttribute("autocomplete", "off");

this.element.onchange = function (ev)
{
this.autocompleter.change(ev);
}
this.element.onkeyup = function (ev)
{
this.autocompleter.keyup(ev);
}
this.element.onkeydown = function (ev)
{
this.autocompleter.keydown(ev);
}
}

if (window.XMLHttpRequest)
{
var toComplete = new autocompleter("to"), bccComplete = new autocompleter("bcc");
toComplete.source = "', $scripturl, '?action=requestmembers;sesc=', $context['session_id'], ';search=";
bccComplete.source = "', $scripturl, '?action=requestmembers;sesc=', $context['session_id'], ';search=";
}

function saveEntities()
{
var textFields = ["subject", "message"];
for (i in textFields)
if (document.forms.postmodify.elements[textFields[i]])
document.forms.postmodify[textFields[i]].value = document.forms.postmodify[textFields[i]].value.replace(/&#/g, "&#38;#");
}
// ]]></script>


I believe the issue is in the "if (window.XMLHttpRequest)" part of the javascript, since that mentions bccComplete = new autocompleter("bcc"), however when it comes to javascript I'm lost. It might be that I need to make more changes.

Koodi (This is the specific lines) [Valitse]
if (window.XMLHttpRequest)
{
var toComplete = new autocompleter("to"), bccComplete = new autocompleter("bcc");
toComplete.source = "', $scripturl, '?action=requestmembers;sesc=', $context['session_id'], ';search=";
bccComplete.source = "', $scripturl, '?action=requestmembers;sesc=', $context['session_id'], ';search=";
}

Advertisement: