]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/mod_group.js
17ed9ce4615ff742b20592f568b1de1193954ee3
[friendica.git] / view / theme / frio / js / mod_group.js
1
2 /**
3  * @file view/theme/frio/js/mod_group.js
4  * @brief The javascript for the group module
5  */
6
7
8 $(document).ready(function(){
9         // Add an event listeners on buttons for switching the contact list view
10         $("body").on("click", ".group-list-switcher", function(){
11                 switchGroupViewMode(this);
12         });
13 });
14
15 /**
16  * @brief Change the group membership of the contacts and fetch the new grup list
17  * as html
18  * 
19  * @param {int} gid The group ID
20  * @param {int} cid The contact ID
21  * @param {string} sec_token The security token
22  * 
23  * @returns {undefined}
24  */
25 function groupChangeMember(gid, cid, sec_token) {
26         $(".tooltip").tooltip("hide");
27         $("body").css("cursor", "wait");
28         $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
29                         // Insert the new group member list
30                         $("#group-update-wrapper").html(data);
31
32                         // Apply the actual gropu list view mode to the new
33                         // group list html
34                         var activeMode = $(".group-list-switcher.active");
35                         switchGroupViewMode(activeMode[0]);
36
37                         $("body").css("cursor", "auto");
38         });
39 }
40
41 /**
42  * @brief Change the group list view mode
43  * 
44  * @param {object} elm The button element of the view mode switcher
45  * @returns {undefined}
46  */
47 function switchGroupViewMode(elm) {
48                 // Remove the active class from group list switcher buttons
49                 $(".group-list-switcher").removeClass("active");
50                 // And add it to the active button element
51                 $(elm).addClass("active");
52
53                 // Add or remove the css classes for the group list with regard to the active view mode
54                 if (elm.id === "group-list-small") {                    
55                         $("#contact-group-list > li").addClass("shortmode col-lg-6 col-md-6 col-sm-6 col-xs-12");
56                 } else {
57                         $("#contact-group-list > li").removeClass("shortmode col-lg-6 col-md-6 col-sm-6 col-xs-12");
58                 }
59 }
60
61 /**
62  * @brief Filter the group member list for contacts
63  * 
64  * @returns {undefined}
65  */
66 function filterList() {
67         // Declare variables
68         var input, filter, ul, li, a, i;
69         input = document.getElementById("contacts-search");
70         filter = input.value.toUpperCase();
71         li = document.querySelectorAll("#contact-group-list>li");
72
73         // Loop through all list items, and hide those who don't match the search query
74         for (i = 0; i < li.length; i++) {
75                 // Get the heading element
76                 var mh = li[i].getElementsByClassName("media-heading")[0];
77                 // The first child of the heading element should contain
78                 // the text which we want to filter
79                 a = mh.firstChild;
80                 if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
81                         li[i].style.display = "";
82                 } else {
83                         li[i].style.display = "none";
84                 }
85         }
86 }