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(){
var maxMP=50;/*2%/MP*/
var a=["inbox","savebox"],b,dl=document.location.toString(),cc=1,cI=0,collect=[],SPP=false;
var fpidP=function(dossier){var dossier=dossier,stop=stop||false;
if(!stop)$.get("/privmsg?folder="+dossier+"&start="+cI,(function(dossier,d){
    var c,$d=$(d),i,l=dossier,$navMP=$("<div>",{id:"navMP"}),precedent,suivant;
    c=$("form[action^='/privmsg'] a[href^='/privmsg?folder="+l+"&mode=read&p=']",$d);
    if(!SPP){
SPP=$("form[action^='/privmsg'] a[href*='&start=']",$d).length?parseInt(/&start=(\d+)/.exec($("a[href*='&start=']",$d)[0].href)[1]):50;
    }
    for(i=0;i<c.length;i++){
collect[cI+i]=c[i];
}
 for(i=0;i<collect.length;i++){
 if(collect[i].href.indexOf('&p='+pid)!=-1){
  if(i!==collect.length-1)$navMP.append($('<a>',{id:"navMP-precedent",href:collect[i+1].href,title:collect[i+1].textContent}));
  if(i!==0)$navMP.append($('<a>',{id:"navMP-suivant",href:collect[i-1].href,title:collect[i-1].textContent}));
  /*Evitons les requetes inutiles...*/
  stop=i<collect.length-1;
  break;
  };
 }
 cI+=SPP;cc++;
 if(cc<=Math.ceil(maxMP/SPP)&&!stop){fpidP(dossier);}
$("#navMP").length?$("#navMP").html($navMP.html()):$("form[action^='/privmsg']").before($navMP);
   
  }).bind(null,dossier))};
for(b in a){
 if(dl.indexOf("/privmsg\?folder="+a[b]+"&mode=read&p=")!=-1){
  var pid=/&p=(\d+)/.exec(dl)[1];
  fpidP(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.


Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.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