Passed
Push — master ( 52bf93...8fa3ac )
by Kishan
02:14
created

$(document).ready   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 1
dl 0
loc 19
rs 9.65
c 0
b 0
f 0
1
$(window).on('load',function(){
2
  $('.loader').css('display','none');
3
})
4
5
$(document).ready(function() {
6
    //Init side nav
7
    $(".button-collapse").sideNav();
8
    $('#modal').modal(); 
9
10
    //Hide Download Selected Album button
11
    $(".selectedAlbums").hide(function() {
12
      $("#profile")
13
        .removeClass("section-profile")
14
        .addClass("profile");
15
    });
16
17
    //==================================================================================
18
      $('.card-image').click(function() {
19
        var albumId = $(this).attr('album-id');
20
        $('.loader').css('display','block');
21
        $.ajax({
22
            url: "slider.php?albumId=" + albumId,
23
            success: function(result) {
24
              $('.loader').css('display','none');   
25
              $('.overlay').css('width','100%');
26
              $('.slideshow-container').html(result);
27
              flag = 1;
28
            }
29
        });
30
      })
31
32
    //===============
33
    function append_download_link(url) {
34
      $('.download-process').css('display','block');
35
      $('.loadermessage').text("Please wait... Albums are downloading");
36
      $.ajax({
37
        url: url,
38
        success: function(result) {
39
          $('.download-process').css('display','none');
40
          $(".modal-content").html(result);
41
          $('#modal').modal('open');
42
        }
43
      });
44
    }
45
46
    var count = 0;
47
    $(".select-album").on("change", function() {
48
      if ($(this).is(":checked")) {
49
        count++;
50
      } else {
51
        count--;
52
      }
53
      if (count > 0) {
54
        $(".selectedAlbums").show(function() {
55
          $("#profile")
56
            .removeClass("profile")
57
            .addClass("section-profile");
58
        });
59
      } else {
60
        $(".selectedAlbums").hide(function() {
61
          $("#profile")
62
            .removeClass("section-profile")
63
            .addClass("profile");
64
        });
65
      }
66
    });
67
68
    function get_all_selected_albums() {
69
      var selected_albums;
70
      var i = 0;
0 ignored issues
show
Unused Code introduced by
The variable i seems to be never used. Consider removing it.
Loading history...
71
      $(".select-album").each(function() {
72
        if ($(this).is(":checked")) {
73
          if (!selected_albums) {
74
            selected_albums = $(this).val();
75
          } else {
76
            selected_albums = selected_albums + "-" + $(this).val();
77
          }
78
        }
79
      });
80
81
      return selected_albums;
82
    }
83
84
    $(".single-export").on("click", function() {
85
        var rel = $(this).attr("rel");
86
        var album = rel.split(",");
87
        append_download_link(
88
          "download-album.php?single_export=" + album[0] + "," + album[1]
89
        );
90
    });
91
92
    $(".single-download").on("click", function() {
93
      var rel = $(this).attr("rel");
94
      var album = rel.split(",");
95
      append_download_link(
96
        "download-album.php?zip=1&single_album=" + album[0] + "," + album[1]
97
      );
98
    });
99
100
    $("#download-selected-albums").on("click", function() {
101
      var selected_albums = get_all_selected_albums();
102
      append_download_link(
103
        "download-album.php?zip=1&selected_albums=" + selected_albums
104
      );
105
    });
106
107
    $(".download-all-albums").on("click", function() {
108
      append_download_link("download-album.php?zip=1&all_albums=all_albums");
109
    });
110
111
112
    function move_to_drive(param1, param2) {
113
114
        var google_access_token = $('.g-access-token').text();
115
        if(google_access_token === "Hello") {
116
            $('.download-process').css('display','block');
117
            $('.loadermessage').text("Please wait... File is moving in to google drive");
118
            $.ajax({
119
                url: "https://localhost:8443/SociaManager/google_drive/google_login.php?" + param1 + "=" + param2,
120
                success: function (result) {
121
                    $('.download-process').css('display','none');
122
                    $(".modal-content").html(result);
123
                    $('#modal').modal('open');
124
                }
125
            });
126
        } else {
127
            window.location = "https://localhost:8443/SociaManager/google_drive/google_login.php";
128
        }
129
    }
130
131
    $(".move-single-album").on("click", function() {
132
        var single_album = $(this).attr("rel");
133
        move_to_drive("single_album", single_album);
134
    });
135
136
    $("#move-selected-albums").on("click", function() {
137
        var selected_albums = get_all_selected_albums();
138
        move_to_drive("selected_albums", selected_albums);
139
    });
140
141
    $(".move_all").on("click", function() {
142
        move_to_drive("all_albums", "all_albums");
143
    });
144
145
    $("#uploadimage").on('submit',(function(e) {
146
        e.preventDefault();
147
        $('.download-process').css('display','block');
148
        $('.loadermessage').text("Please wait... Album photo uploading!!");
149
        $.ajax({
150
            url: "ajax_php_file.php", // Url to which the request is send
151
            type: "POST",             // Type of request to be send, called as method
152
            data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
153
            contentType: false,       // The content type used when sending data to the server.
154
            cache: false,             // To unable request pages to be cached
155
            processData:false,        // To send DOMDocument or non processed data file it is set to false
156
            success: function(data)   // A function to be called if request succeeds
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
157
            {
158
              $('.download-process').css('display','none');
159
              $(".modal-content").html(result);
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. If this is a global, consider adding a /** global: result */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
160
              $('#modal').modal('open');
161
            }
162
        });
163
    }));
164
165
});
166
167
// Slider Script in vanilla java script
168
169
var flag =0;
170
function closeNav() {
171
  document.getElementById("myNav").style.width = "0%";
172
}
173
174
var slideIndex = 1;
175
showSlides(slideIndex);
176
177
function plusSlides(n) {
178
  showSlides(slideIndex += n);
179
}
180
181
function currentSlide(n) {
182
  showSlides(slideIndex = n);
183
}
184
185
var y = 0;
186
setInterval(function displaySlider(){
187
    var slides = document.getElementsByClassName("mySlides");
188
    showSlides(slideIndex = y);
189
    y++;
190
    if (y > slides.length) {
191
        slideIndex = 1
192
        y = 1;
193
    }    
194
}, 3000);
195
196
function showSlides(n) {
197
  var i;
198
  var slides = document.getElementsByClassName("mySlides");
199
  if (n > slides.length) {slideIndex = 1}    
200
  if (n < 1) {slideIndex = slides.length}
201
  for (i = 0; i < slides.length; i++) {
202
      slides[i].style.display = "none";  
203
  }
204
  
205
  if(flag != 0){
0 ignored issues
show
Best Practice introduced by
Comparing flag to 0 using the != operator is not safe. Consider using !== instead.
Loading history...
206
    flag =1;
207
    slides[slideIndex-1].style.display = "block"; 
208
  }
209
}