Tilføj submit knap i javascript.
Nogle javascript nørder, der kan hjælpe mig med et lille mysterium?Jeg skal gerne have indsat en button, submit button, link eller lignende, til at sende input feltet, det skal samtidig være muligt at submit ved at indtaste noget i feltet og trykke enter, som koden er opsat til nu.
Jeg er desværre ikke så skarp til javascript :P
php koden:
<input id="lovefactory-shoutbox-submit" type="text" value="Hvad har du på hjertet? Skriv en statusbesked her..." onFocus="this.value=''" onblur="Hvad har du på hjertet? Skriv en statusbesked her..." />
<!-- Link, knap eller lign. -->
<a href="#">Godkend</a>
<button>
<form>
<input type="submit" value="godkend">
</form>
<!-- cstm submit knap slut -->
<br><br>
<?php defined('_JEXEC') or die('Restricted access'); ?>
<div id="lovefactory-shoutbox" class="lovefactory-shoutbox<?php echo $params->get('moduleclass_sfx'); ?>">
<?php foreach ($messages as $i => $message): ?>
<div class="lovefactory-shoutbox-message <?php echo $i % 2 ? '' : 'even'; ?>">
<a href="<?php echo JRoute::_('index.php?option=com_lovefactory&view=profile&id=' . $message->sender_id . '&Itemid=' . $Itemid); ?>"><?php echo $message->username; ?> skrev: </a><?php echo $message->message; ?>
<div class="date"><?php echo $message->created_at; ?></div>
</div>
<?php endforeach; ?>
</div>
<div id="lovefactory-shoutbox-response" style="display: none;"></div>
<?php if (2 == $access): ?>
<div id="lovefactory-shoutbox-loader">
<span style="display: none;" class="lovefactory-button lovefactory-loader-button"><?php echo JText::_('MOD_LOVEFACTORY_SHOUTBOX_SENDING_MESSAGE'); ?></span>
</div>
<?php endif; ?>
JavaScript filen:
jQueryFactory(document).ready(function ($) {
var queue = new Array();
var started = false;
var shoutbox = $("#lovefactory-shoutbox");
var request = false;
// Send message
$("#lovefactory-shoutbox-submit").keypress(function (event) {
var code = (event.keyCode ? event.keyCode : event.which);
var message = $(this).val().trim();
if (code == 13 && !request && '' != message)
{
$(this).val('');
request = true;
$("#lovefactory-shoutbox-loader span").show();
$.ajax({
url: 'index.php?option=com_lovefactory&controller=shoutbox&task=postmessage',
type: 'POST',
data: 'message=' + message,
dataType: 'json',
success: function (response) {
request = false;
$("#lovefactory-shoutbox-loader span").hide();
if (0 == response.status)
{
$("#lovefactory-shoutbox-response")
.hide()
.html(response.message)
.fadeIn(function () {
var info = $(this);
setTimeout(function () {
info.fadeOut();
}, 3000);
});
}
}
});
}
});
// Update shotubox
if (lovefactory_shoutbox_interval)
{
setInterval(function () {
$.ajax({
url: 'index.php?option=com_lovefactory&controller=shoutbox&task=getmessages&format=raw',
type: 'POST',
data: 'lovefactory_shoutbox_last=' + lovefactory_shoutbox_last + '&lovefactory_shoutbox_limit=' + lovefactory_shoutbox_limit,
dataType: "json",
success: function (response)
{
if (1 == response.status)
{
var messages = response.messages;
if (response.last)
{
lovefactory_shoutbox_last = response.last;
}
for (var i = 0, count = messages.length; i < count; i++)
{
var message = messages[i];
queue.push(message);
showQueue();
}
}
}
});
}, lovefactory_shoutbox_interval * 1000);
}
// Show queue
function showQueue()
{
if (started)
{
return false;
}
if (0 == queue.length)
{
started = false;
return false;
}
started = true;
if (lovefactory_shoutbox_limit == shoutbox.find(".lovefactory-shoutbox-message").length)
{
shoutbox.find(".lovefactory-shoutbox-message:last").remove();
}
message = queue[0];
var even = shoutbox.find(".lovefactory-shoutbox-message:first").hasClass("even") ? "" : "even";
shoutbox.attr({ scrollTop: 0 });
shoutbox
.prepend("<div class='lovefactory-shoutbox-message " + even + "' style='display: none;'><a href='" + message.l + "'>" + message.u + "</a>" + message.m + "<div class='date'>" + message.d + "</div></div>")
.find(".lovefactory-shoutbox-message:first")
.effect("highlight", {}, 1000, function () {
queue.splice(0,1);
started = false;
showQueue();
});
}
});