The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Next and previous buttons for private messages

View previous topic View next topic Go down

Next and previous buttons for private messages

Post by Ange Tuteur on July 3rd 2015, 12:32 pm

Next and previous buttons for private messages


This tutorial lets you add 2 buttons that allow you to move to another private message without going back to the inbox. Smile

Overview




The JavaScript


Go to Administration Panel > Modules > JavaScript codes management and create a new script.

Title : Your choice
Placement : In all the pages
Paste the following code and submit :
Code:
        $(function(){
            "use strict";
            var a=["inbox","savebox"],b,dl=document.location.search;
            for(b in a){
                if(dl.indexOf("folder="+a[b]+"&mode=read&p=")!=-1){
                    (function(box){
                        $.get("/privmsg?folder="+box,function(mpStart){
                            var messages=$("a[href^='/privmsg?folder="+box+"&mode=read&p=']",mpStart).toArray();
                            var linkToObject=function(lc){return {"href":lc.href,"title":lc.title,"text":lc.textContent}};
                            var setButtons=function(){
                                var getPid=function(a){return /p=(\d+)/.exec(a)[1]},message;
                                for(i=0;i<messages.length;i++){
                                    message=messages[i];
                                    if(getPid(dl)==getPid(message.href)){
                                        if(i||i<messages.length-1){
                                            var $navMP=$("<div>",{id:"navMP"});
                                            if(i<messages.length-1)$navMP.append($('<a>',{"id":"navMP-precedent","href":messages[i+1].href,"title":messages[i+1].title||messages[i+1].text}));
                                            if(i)$navMP.append($('<a>',{"id":"navMP-suivant","href":messages[i-1].href,"title":messages[i-1].title||messages[i-1].text}));
                                            $("#navMP").length?$("#navMP").html($navMP.html()):$("form[action^='/privmsg']").before($navMP);
                                        }
                                        break;
                                    }
                                }
                            };
                            var requests=$("a[href^='/privmsg?folder="+box+"&start=']",mpStart).slice(0,-1).toArray();
                            if(requests.length){
                                requests=requests.map(function(e){return $.get(e.href)});
                                $.when.apply(null,requests).done(function(){
                                    var d_msg,requestData;
                                    if(requests.length>1){
                                        for(i=0;i<arguments.length;i++){
                                            requestData=arguments[i][0];
                                            d_msg=$("a[href^='/privmsg?folder="+box+"&mode=read&p=']",requestData).toArray();
                                            messages=messages.concat(d_msg);
                                        }
                                        messages.map(linkToObject);
                                        setButtons();
                                    }else{
                                        requestData=arguments[0];
                                        d_msg=$("a[href^='/privmsg?folder="+box+"&mode=read&p=']",requestData).toArray();
                                        messages=messages.concat(d_msg).map(linkToObject);
                                        setButtons();
                                    }
                                });
                            }else{
                                messages=messages.map(linkToObject);
                                setButtons();
                            }
                        });
                    }(a[b]));
                }
            }
        });


The JavaScript code is designed to be compatible with all forum versions ( phpbb2, phpbb3, punbb, invision ). If you want to decide for yourself where to place the next and previous buttons, you can simply edit your privmsgs_read_body template and add the following code wherever you want :
Code:
<div id="navMP"></div>

The display of the buttons may take more or less time depending on your connection speed and configuration of the number of topics per page on your forum. The greater the number of topics per page, the less requests the script will send, as it will be slower.

You can check the total number of topics per page here :
Administration Panel > General > Messages and Emails > Configuration, find the option topics per page.


The CSS


Go to Administration Panel > Display > Colors > CSS stylesheet, and add the following code to your stylesheet :
Code:
#navMP>a{
  display:inline-block;
  padding-left:10px;
  padding-right:10px;
  font-size:16px;
  line-height:16px;
  color:#eee;
  background:#BDC8D0;
  text-decoration:none !important;
  border:1px solid #aaa;
}
#navMP>a:hover{
  color:#fff;
  background:#CDD8E0;
  text-decoration:none !important;
}
#navMP-precedent{
  border-radius:8px 0 0 8px;
}
#navMP-suivant{
  float:right;
  border-radius:0 8px 8px 0;
}
 
#navMP-precedent::before{
  content:"Previous"
}
#navMP-suivant::before{
  content:"Next"
}

You can of course modify this code to your liking.

avatar
Ange Tuteur
Forumaster

Male Posts : 13174
Reputation : 2872
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Re: Next and previous buttons for private messages

Post by SLGray on July 28th 2017, 6:47 pm

The JavaScript has been updated.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 39685
Reputation : 2678
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum