phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Smilie at the cursor mod


 
Search this topic... | Search MOD Requests... | Search Box
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Author Message
Jim_UK
Board Member



Joined: 19 Nov 2008

Posts: 585
Location: North West UK


flag
PostPosted: Mon Dec 31, 2018 1:46 pm 
Post subject: Smilie at the cursor mod

Does anyone have the modification that enables you to place a smilie at the cursor instead of it appearing after the last bit of text.
I thought I had the mod as I recall installing it for someone on their board but a search of my mods has failed to find it.

Thanks
Jim

_________________
The truth is out there.
Unfortunately they will not let you anywhere near it!
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 439
Location: Qu├ębec


flag
PostPosted: Mon Dec 31, 2018 4:28 pm 
Post subject: Re: Smilie at the cursor mod

I don't have the mod, but it's easy enough to find general JavaScript advice to achieve the same. This snippet in particular seems like it would do the trick.
Back to top
Jim_UK
Board Member



Joined: 19 Nov 2008

Posts: 585
Location: North West UK


flag
PostPosted: Mon Dec 31, 2018 4:30 pm 
Post subject: Re: Smilie at the cursor mod

Salvatos wrote:
I don't have the mod, but it's easy enough to find general JavaScript advice to achieve the same. This snippet in particular seems like it would do the trick.


Thanks - I will check it out.

Jim

_________________
The truth is out there.
Unfortunately they will not let you anywhere near it!
Back to top
drathbun
Board Member



Joined: 24 Jul 2008

Posts: 685
Location: Texas


flag
PostPosted: Tue Jan 01, 2019 3:16 am 
Post subject: Re: Smilie at the cursor mod

If it doesn't work, let me know. I have the code on this site so I would just need to figure out which bits to send to you.
_________________
phpBBDoctor Blog
Back to top
Jim_UK
Board Member



Joined: 19 Nov 2008

Posts: 585
Location: North West UK


flag
PostPosted: Tue Jan 01, 2019 9:21 am 
Post subject: Re: Smilie at the cursor mod

Thanks Dave.
A member on my site has sent me this that I am going to try. He says he has tested it with several browsers. He is a programmer in PHP and other languages as a profession so I am hopeful.

Inside templates/your-template/posting-body.tpl replace this;

Code:
function emoticon(text) {
   var txtarea = document.post.message;
   text = ' ' + text + ' ';
   if (txtarea.createTextRange && txtarea.caretPos) {
      var caretPos = txtarea.caretPos;
      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
      txtarea.focus();
   } else {
      txtarea.value  += text;
      txtarea.focus();
   }
}


with this;

Code:
function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
        myField.focus();
        var sel = document.selection.createRange();
        sel.text = myValue;
    }
    //MOZILLA and others
    else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)
            + myValue
            + myField.value.substring(endPos, myField.value.length);
        myField.selectionStart = startPos + myValue.length;
        myField.selectionEnd = startPos + myValue.length;
    } else {
        myField.value += myValue;
    }
}
function emoticon(text) {
   var txtarea = document.post.message;
   text = ' ' + text + ' ';
   insertAtCursor(txtarea,text);
   txtarea.focus();
}


I have tested this and it does work.

Jim

_________________
The truth is out there.
Unfortunately they will not let you anywhere near it!
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0246 seconds using 15 queries. (SQL 0.0021 Parse 0.0008 Other 0.0217)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo