Skip to content
Permalink
Browse files

Ajoute l'option Usability.betterMessageInput

Permet de faire grandir la textarea du message au fur-et-à-mesure
que du texte y est ajouté.

(Utilise une fonction de jevin9@gmail.com)
  • Loading branch information...
dorian-marchal committed Jan 27, 2015
1 parent a540134 commit f529986d3db3b00065aaf9fcf41252aa1a12db41
Showing with 129 additions and 6 deletions.
  1. +70 −1 jquery-plugins.js
  2. +1 −0 modules/Quote.js
  3. +58 −5 modules/Usability.js
@@ -65,4 +65,73 @@ $.fn.isOversized = function(coefficient) {
var maxHeight = windowHeight * coefficient;

return elementHeight > maxHeight;
};
};

/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <jevin9@gmail.com> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Jevin O. Sewaruth
* ----------------------------------------------------------------------------
*
* Autogrow Textarea Plugin Version v3.0
* http://www.technoreply.com/autogrow-textarea-plugin-3-0
*
* THIS PLUGIN IS DELIVERD ON A PAY WHAT YOU WHANT BASIS. IF THE PLUGIN WAS USEFUL TO YOU, PLEASE CONSIDER BUYING THE PLUGIN HERE :
* https://sites.fastspring.com/technoreply/instant/autogrowtextareaplugin
*
* Date: October 15, 2012
*/
jQuery.fn.autoGrow = function() {
return this.each(function() {

var createMirror = function(textarea) {
$(textarea).after("<div class=\"autogrow-textarea-mirror\"></div>");
return $(textarea).next(".autogrow-textarea-mirror")[0];
};

var sendContentToMirror = function (textarea) {
mirror.innerHTML = String(textarea.value)
.replace(/&/g, "&amp;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/ /g, "&nbsp;")
.replace(/\n/g, "<br />") +
".<br/>."
;

if ($(textarea).height() != $(mirror).height()) {
$(textarea).height($(mirror).height());
}
};

var growTextarea = function () {
sendContentToMirror(this);
};

var mirror = createMirror(this);

mirror.style.display = "none";
mirror.style.wordWrap = "break-word";
mirror.style.whiteSpace = "normal";
mirror.style.padding = $(this).css("padding");
mirror.style.width = $(this).css("width");
mirror.style.fontFamily = $(this).css("font-family");
mirror.style.fontSize = $(this).css("font-size");
mirror.style.lineHeight = $(this).css("line-height");

// Style the textarea
this.style.overflow = "hidden";
this.style.minHeight = this.rows + "em";

// Bind the textarea's event
this.onkeyup = growTextarea;

// Fire the event for text already present
sendContentToMirror(this);

});
};
@@ -189,6 +189,7 @@ SK.moduleConstructors.Quote.prototype.addToResponseThenFocus = function(citation
var response = $responseBox.val();
$responseBox.val("");
$responseBox.val(response);
$responseBox.keyup();

//Scroll tout en bas du textarea
$responseBox.scrollTop($responseBox[0].scrollHeight - $responseBox.height());
@@ -29,6 +29,12 @@ SK.moduleConstructors.Usability.prototype.init = function() {
if (this.getSetting("focusOnNewMessage")) {
this.bindFocusOnNewMessage();
}

if (this.getSetting("betterMessageInput")) {

$("#message_topic").autoGrow();
this.overrideQuoteButton();
}
};

/**
@@ -83,6 +89,45 @@ SK.moduleConstructors.Usability.prototype.bindFocusOnNewMessage = function() {
});
};

/**
* Remplace l'événement onclick du bouton de citation par un nouvel
* événement permettant de faire fonctionner autoGrow
*/
SK.moduleConstructors.Usability.prototype.overrideQuoteButton = function() {

this.queueFunction(function() {

unsafeWindow.$(".picto-msg-quote").off();
$(".picto-msg-quote").on("click", function() {
var $msg = $(this).parents(".bloc-message-forum");
var postId = $msg .attr("data-id");
var pseudo = $msg.find(".bloc-pseudo-msg").text().replace(/[\r\n]/g, "");
var date = $msg.find(".bloc-date-msg").text().replace(/[\r\n]/g, "").replace(/[\r\n]/g, "").replace(/#[0-9]+$/g, "");

$.ajax({
type: "POST",
url: "/forums/ajax_citation.php",
dataType: "json",
data: {
id_message: postId,
ajax_timestamp: $("#ajax_timestamp_liste_messages").val(),
ajax_hash: $("#ajax_hash_liste_messages").val(),
},
success: function (data) {
if (data.erreur.length === 0) {
unsafeWindow.$("#message_topic")
.insertStartLine("> Le " + date + " " + pseudo + " a écrit :\n>" + data.txt.split("\n").join("\n> ") + "\n\n")
.get(0).dispatchEvent(new Event("keyup"))
;
$("#message_topic").scrollThere();
}
}
});
});
});
};


SK.moduleConstructors.Usability.prototype.settings = {
refreshToLastPost: {
title: "Rafraîchir au dernier message",
@@ -96,16 +141,24 @@ SK.moduleConstructors.Usability.prototype.settings = {
type: "boolean",
default: true,
},
betterMessageInput: {
title: "Améliorer la saisie des messages",
description: "Redimensionne automatiquement la boîte de saisie des messages/topics et change le curseur au survol de la preview",
type: "boolean",
default: true,
}
};

SK.moduleConstructors.Usability.prototype.getCss = function() {
var css = "";

css += "\
.jv-editor .previsu-editor {\
cursor: not-allowed;\
}\
";
if (this.getSetting("betterMessageInput")) {
css += "\
.jv-editor .previsu-editor {\
cursor: not-allowed;\
}\
";
}

return css;
};

0 comments on commit f529986

Please sign in to comment.
You can’t perform that action at this time.