Good art is a taste, good design is an opinion.


Come as guest, stay as family.
Board Index

Come as guest, stay as family.


You are not connected. Please login or register

Foto

[Javascript] "Add as friend" option in topic



View previous topic View next topic Go down Message [Page 1 of 1]

1
Offline

  Shadow

avatar
Administrator
Administrator


Tutorial: "Add as friend" option in topic

This tutorial will allow you to add people as friends from the topics, rather than visiting their profiles and clicking add as friend button.

Credits: @JScript


--> Tutorials, tips and tricks <--
"Add as friend" option in topic



- Javascript
Placement In the topic

Code:
[panda=js]$(function() {
       if (!_userdata.session_logged_in) {
          return false;
       }
       var FFinPosts = {
          sFriend: "Add As Friend",
          sFoes: "Add To Foes",
          oTarget: $('.post'),
          iLen: 0,
          sUser_name: "",
          oFF_list: null,
          aFF_list: [],
          vTemp: null,
          oThis: null
       };
       FFinPosts.iLen = FFinPosts.oTarget.length;

       $.ajax({
          url: "/u" + _userdata.user_id + 'friends',
          cache: false,
          type: "get",
          dataType: "text",
          success: function(response, status, xhr) {
             if (xhr.status == 200) {
                FFinPosts.oFF_list = $('#profile-advanced-details ol .message-header > a[href^="/u"]', response);

                for (var i = 0; i < FFinPosts.oFF_list.length; i++) {
                   FFinPosts.aFF_list[FFinPosts.aFF_list.length] = $(FFinPosts.oFF_list[i]).text();
                }

                for (var i = 0; i < FFinPosts.iLen; i++) {
                   FFinPosts.oThis = $(FFinPosts.oTarget[i]);
                   FFinPosts.sUser_name = FFinPosts.oThis.find('.author a, .name, .user a[href^="/u"]').text();

                   if (FFinPosts.sUser_name !== _userdata.username) {
                      FFinPosts.vTemp = FFinPosts.oThis.find('.postprofile dd:last, .postdetails.poster-profile, .user-contact');

                      if (FFinPosts.aFF_list.indexOf(FFinPosts.sUser_name) == -1) {

                         FFinPosts.vTemp.append(
                            '<a class="profile-icon" href="/profile?friend=' + encodeURIComponent(FFinPosts.sUser_name) + '&mode=editprofile&page_profil=friendsfoes">' +
                            '   <img title="Add As Friend" alt="Add As Friend" src="https://cdn2.iconfinder.com/data/icons/gnomeicontheme/16x16/apps/im-msn.png" width="16" height="16">' +
                            '</a>'
                         )
                      } else {
                         FFinPosts.vTemp.append(
                            '<a class="profile-icon" href="/profile?foe=' + encodeURIComponent(FFinPosts.sUser_name) + '&mode=editprofile&page_profil=friendsfoes">' +
                            '   <img title="Add To Foes" alt="Add To Foes" src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/16/Actions-list-remove-user-icon.png">' +
                            '</a>'
                         )
                      }
                   }
                }
             }
          }
       });
    });


- Preview





© PunBB Design


If you have any questions related to this topic create a topic with the following title:
"Add as friend" option in topic

Powered by PunBB
Currently 0 users have thanked Shadow for this post:

2
Offline

  Nickname1

avatar
Punbb Rookie
Punbb Rookie
Yay new codes! Very Happy

Powered by PunBB
Currently 0 users have thanked Nickname1 for this post:

3
Offline

  Andrei34

avatar
Punbb Rookie
Punbb Rookie
very good tuto thx

Powered by PunBB
Currently 0 users have thanked Andrei34 for this post:

View previous topic View next topic Back to top Message [Page 1 of 1]


Topic URL's

URL
BBcode
HTML" />

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