Hozzászólás sablon

Tud valaki olyan pluginról, vagy megoldásról, ami bizonyos - sűrűn előforduló - hozzászólás írását segíti?





Pl.: gombok, melyek megnyomásával a hozzászólás mezőjét automatikusan kitölti a gombhoz rendelt szöveggel.











Köszönöm!

szentem js-el megoldhato siman





sajnos nem nagyon vagom annyira, valami hozzaerto biztos meg tudja mondani pontosan hogyan erdemes megcsinalni (=


Török Zoltán wrote:

szentem js-el megoldhato siman...








Köszönöm a választ!


Sajnos én egyáltalán nem vágom, úgyhogy bízom a többiek segítségében.





Amúgy szentem, vagy szerintem?

insertAtCursor() függvény segíthet.





Itt közvetlenül az input mező objektumot várja a javascript, de egy sor beszúrásával, és a függvény fejléc átírásával átírtam, hogy id-t kelljen megadni, mert nekem így jobban tetszik:



Code:



//modified version of http://www.webmasterworld.com/forum91/4686.htm

//myField accepts an object reference, myValue accepts the text string to add

function insertAtCursor(myFieldId, myValue) {

var myField = document.getElementById(myFieldId);

//IE support

if (document.selection) {

myField.focus();



//in effect we are creating a text range with zero

//length at the cursor location and replacing it

//with myValue

sel = document.selection.createRange();

sel.text = myValue;



//Mozilla/Firefox/Netscape 7+ support

} else if (myField.selectionStart || myField.selectionStart == '0') {



myField.focus();

//Here we get the start and end points of the

//selection. Then we create substrings up to the

//start of the selection and from the end point

//of the selection to the end of the field value.

//Then we concatenate the first substring, myValue,

//and the second substring to get the new value.

var startPos = myField.selectionStart;

var endPos = myField.selectionEnd;

myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);

myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length);

} else {

myField.value += myValue;

}

}











html-ben pedig egy egyszerű példa a használatára:


Code:

Teszt








A textarea pedig ahogy elnézem az adott téma comments.php- jében van. és az id comment





sima link helyett pedig képlinket is be lehet tenni, és szebb lesz.