WD Instagram Feed – Instagram Gallery - Version 1.1.22

Version Description

New: message displayed on frontend if feed has no media
Fixed: JS errors for media with Instagram's new "Slideshow" feature. This feature is not supported by Instagram's API yet.
Changed: Errors by plugin and Instagram API are alerted in frontend only for admins, otherwise output the message to the Web Console
Changed: Custom attribute "wdi_media_user" added to media containers in frontend. Useful for adding different event listeners, e.g. custom redirects for every user's media.
Changed: Minor style conflicts fixed

Download this release

Release Info

Developer webdorado
Plugin Icon 128x128 WD Instagram Feed – Instagram Gallery
Version 1.1.22
Comparing to
See all releases

Code changes from version 1.1.21 to 1.1.22

admin/views/WDIViewFeeds_wdi.php CHANGED
@@ -297,7 +297,7 @@ public function genarateFeedViews(){
297
  <label for="image_browser"><img src="<?php echo plugins_url('../../images/feed_views/image_browser.png',__FILE__);?>"></label>
298
  </div>
299
 
300
- <br class="clear">
301
  <?php
302
  }
303
  public function generateTabs(){
@@ -306,7 +306,7 @@ public function generateTabs(){
306
  <div class="wdi_feed_tabs" id="wdi_feed_settings" onclick="wdi_controller.switchFeedTabs('feed_settings');"><?php _e('Feed Settings',"wdi")?></div>
307
  <div class="wdi_feed_tabs" id="wdi_lightbox_settings" onclick="wdi_controller.switchFeedTabs('lightbox_settings');"><?php _e('Lightbox Settings',"wdi")?></div>
308
  <div class="wdi_feed_tabs" id="wdi_conditional_filters" onclick="wdi_controller.switchFeedTabs('conditional_filters');"><?php _e('Conditional Filters',"wdi")?></div>
309
- <br class="clear">
310
  </div>
311
  <?php
312
  }
297
  <label for="image_browser"><img src="<?php echo plugins_url('../../images/feed_views/image_browser.png',__FILE__);?>"></label>
298
  </div>
299
 
300
+ <br class="wdi_clear">
301
  <?php
302
  }
303
  public function generateTabs(){
306
  <div class="wdi_feed_tabs" id="wdi_feed_settings" onclick="wdi_controller.switchFeedTabs('feed_settings');"><?php _e('Feed Settings',"wdi")?></div>
307
  <div class="wdi_feed_tabs" id="wdi_lightbox_settings" onclick="wdi_controller.switchFeedTabs('lightbox_settings');"><?php _e('Lightbox Settings',"wdi")?></div>
308
  <div class="wdi_feed_tabs" id="wdi_conditional_filters" onclick="wdi_controller.switchFeedTabs('conditional_filters');"><?php _e('Conditional Filters',"wdi")?></div>
309
+ <br class="wdi_clear">
310
  </div>
311
  <?php
312
  }
css/wdi_backend.css CHANGED
@@ -1,4 +1,4 @@
1
- .clear{
2
  clear: both;
3
  }
4
  #wdi_unistall{
1
+ .wdi_clear{
2
  clear: both;
3
  }
4
  #wdi_unistall{
css/wdi_frontend.css CHANGED
@@ -1,4 +1,4 @@
1
- .clear{
2
  clear: both;
3
  }
4
  .table{
@@ -305,4 +305,13 @@ div[id^="wdi_container"] p {
305
 
306
  .wdi_photo_wrap_inner {
307
  text-align: center;
 
 
 
 
 
 
 
 
 
308
  }
1
+ .wdi_clear{
2
  clear: both;
3
  }
4
  .table{
305
 
306
  .wdi_photo_wrap_inner {
307
  text-align: center;
308
+ }
309
+
310
+ .wdi_feed_item[wdi_type="slideshow"] .fa-clone{
311
+
312
+ -webkit-transform: rotate(180deg);
313
+ -moz-transform: rotate(180deg);
314
+ -o-transform: rotate(180deg);
315
+ -ms-transform: rotate(180deg);
316
+ transform: rotate(180deg);
317
  }
frontend/shortcode.php CHANGED
@@ -148,12 +148,20 @@ function wdi_load_frontend_scripts()
148
  wp_localize_script("wdi_frontend", 'wdi_ajax', array('ajax_url' => admin_url('admin-ajax.php')), WDI_VERSION);
149
  wp_localize_script("wdi_frontend", 'wdi_url', array('plugin_url' => plugin_dir_url(__FILE__),
150
  'ajax_url' => admin_url('admin-ajax.php')), WDI_VERSION);
 
 
 
 
 
 
 
151
  wp_localize_script("wdi_frontend", 'wdi_front_messages',
152
  array('connection_error' => __('Connection Error, try again later :(', 'wdi'),
153
  'user_not_found' => __('Username not found', 'wdi'),
154
  'network_error' => __('Network error, please try again later :(', 'wdi'),
155
  'hashtag_nodata' => __('There is no data for that hashtag', 'wdi'),
156
- 'filter_title' => __('Click to filter images by this user', 'wdi')
 
157
  ), WDI_VERSION);
158
 
159
 
@@ -204,15 +212,14 @@ function wdi_load_frontend_scripts_styles_ajax()
204
  {
205
 
206
  wp_dequeue_script('jquery');
207
-
208
  wp_enqueue_script('wdi_instagram', plugins_url('../js/wdi_instagram.js', __FILE__), array(), WDI_VERSION, true);
209
 
210
  wp_enqueue_script('underscore');
211
- wp_enqueue_script('wdi_frontend', plugins_url('../js/wdi_frontend.js', __FILE__), array('wdi_instagram', 'underscore'), WDI_VERSION, true);
212
  wp_enqueue_script('wdi_responsive', plugins_url('../js/wdi_responsive.js', __FILE__), array("wdi_instagram"), WDI_VERSION, true);
213
 
214
 
215
-
216
  global $wdi_feed_counter_init;
217
  $wdi_feed_counter_init = isset($wdi_feed_counter_init) ? $wdi_feed_counter_init : 0;
218
  wp_localize_script("wdi_frontend", 'wdi_feed_counter_init', array('wdi_feed_counter_init' => $wdi_feed_counter_init), WDI_VERSION);
@@ -220,12 +227,20 @@ function wdi_load_frontend_scripts_styles_ajax()
220
  wp_localize_script("wdi_frontend", 'wdi_ajax', array('ajax_url' => admin_url('admin-ajax.php'), 'ajax_response' => 1), WDI_VERSION);
221
  wp_localize_script("wdi_frontend", 'wdi_url', array('plugin_url' => plugin_dir_url(__FILE__),
222
  'ajax_url' => admin_url('admin-ajax.php')), WDI_VERSION);
 
 
 
 
 
 
 
223
  wp_localize_script("wdi_frontend", 'wdi_front_messages',
224
  array('connection_error' => __('Connection Error, try again later :(', 'wdi'),
225
  'user_not_found' => __('Username not found', 'wdi'),
226
  'network_error' => __('Network error, please try again later :(', 'wdi'),
227
  'hashtag_nodata' => __('There is no data for that hashtag', 'wdi'),
228
- 'filter_title' => __('Click to filter images by this user', 'wdi')
 
229
  ), WDI_VERSION);
230
 
231
  // Styles/Scripts for popup.
148
  wp_localize_script("wdi_frontend", 'wdi_ajax', array('ajax_url' => admin_url('admin-ajax.php')), WDI_VERSION);
149
  wp_localize_script("wdi_frontend", 'wdi_url', array('plugin_url' => plugin_dir_url(__FILE__),
150
  'ajax_url' => admin_url('admin-ajax.php')), WDI_VERSION);
151
+
152
+ $user_is_admin = false;
153
+ $user = wp_get_current_user();
154
+ if (in_array('administrator', (array)$user->roles)) {
155
+ $user_is_admin = true;
156
+ }
157
+
158
  wp_localize_script("wdi_frontend", 'wdi_front_messages',
159
  array('connection_error' => __('Connection Error, try again later :(', 'wdi'),
160
  'user_not_found' => __('Username not found', 'wdi'),
161
  'network_error' => __('Network error, please try again later :(', 'wdi'),
162
  'hashtag_nodata' => __('There is no data for that hashtag', 'wdi'),
163
+ 'filter_title' => __('Click to filter images by this user', 'wdi'),
164
+ 'show_alerts' => $user_is_admin,
165
  ), WDI_VERSION);
166
 
167
 
212
  {
213
 
214
  wp_dequeue_script('jquery');
215
+
216
  wp_enqueue_script('wdi_instagram', plugins_url('../js/wdi_instagram.js', __FILE__), array(), WDI_VERSION, true);
217
 
218
  wp_enqueue_script('underscore');
219
+ wp_enqueue_script('wdi_frontend', plugins_url('../js/wdi_frontend.js', __FILE__), array('wdi_instagram', 'underscore'), WDI_VERSION, true);
220
  wp_enqueue_script('wdi_responsive', plugins_url('../js/wdi_responsive.js', __FILE__), array("wdi_instagram"), WDI_VERSION, true);
221
 
222
 
 
223
  global $wdi_feed_counter_init;
224
  $wdi_feed_counter_init = isset($wdi_feed_counter_init) ? $wdi_feed_counter_init : 0;
225
  wp_localize_script("wdi_frontend", 'wdi_feed_counter_init', array('wdi_feed_counter_init' => $wdi_feed_counter_init), WDI_VERSION);
227
  wp_localize_script("wdi_frontend", 'wdi_ajax', array('ajax_url' => admin_url('admin-ajax.php'), 'ajax_response' => 1), WDI_VERSION);
228
  wp_localize_script("wdi_frontend", 'wdi_url', array('plugin_url' => plugin_dir_url(__FILE__),
229
  'ajax_url' => admin_url('admin-ajax.php')), WDI_VERSION);
230
+
231
+ $user_is_admin = false;
232
+ $user = wp_get_current_user();
233
+ if (in_array('administrator', (array)$user->roles)) {
234
+ $user_is_admin = true;
235
+ }
236
+
237
  wp_localize_script("wdi_frontend", 'wdi_front_messages',
238
  array('connection_error' => __('Connection Error, try again later :(', 'wdi'),
239
  'user_not_found' => __('Username not found', 'wdi'),
240
  'network_error' => __('Network error, please try again later :(', 'wdi'),
241
  'hashtag_nodata' => __('There is no data for that hashtag', 'wdi'),
242
+ 'filter_title' => __('Click to filter images by this user', 'wdi'),
243
+ 'show_alerts' => $user_is_admin,
244
  ), WDI_VERSION);
245
 
246
  // Styles/Scripts for popup.
frontend/views/WDIViewImageBrowser_view.php CHANGED
@@ -40,7 +40,7 @@ public function display(){
40
  }
41
  ?>
42
  <div class="wdi_feed_wrapper <?php echo 'wdi_col_'.$feed_row['number_of_columns']?>" wdi-res='<?php echo 'wdi_col_'.$feed_row['number_of_columns']?>'></div>
43
- <div class="clear"></div>
44
  <?php switch($feed_row['feed_display_view']){
45
  case 'load_more_btn':{
46
  ?><div class="wdi_load_more"><div class="wdi_load_more_container"><div class="wdi_load_more_wrap"><div class="wdi_load_more_wrap_inner"><div class="wdi_load_more_text"><?php echo __('Load More',"wdi");?></div></div></div></div></div><?php
40
  }
41
  ?>
42
  <div class="wdi_feed_wrapper <?php echo 'wdi_col_'.$feed_row['number_of_columns']?>" wdi-res='<?php echo 'wdi_col_'.$feed_row['number_of_columns']?>'></div>
43
+ <div class="wdi_clear"></div>
44
  <?php switch($feed_row['feed_display_view']){
45
  case 'load_more_btn':{
46
  ?><div class="wdi_load_more"><div class="wdi_load_more_container"><div class="wdi_load_more_wrap"><div class="wdi_load_more_wrap_inner"><div class="wdi_load_more_text"><?php echo __('Load More',"wdi");?></div></div></div></div></div><?php
frontend/views/WDIViewThumbnails_view.php CHANGED
@@ -43,7 +43,7 @@ public function display(){
43
  }
44
  ?>
45
  <div class="wdi_feed_wrapper <?php echo 'wdi_col_'.$feed_row['number_of_columns']?>" wdi-res='<?php echo 'wdi_col_'.$feed_row['number_of_columns']?>'></div>
46
- <div class="clear"></div>
47
 
48
  <?php switch($feed_row['feed_display_view']){
49
  case 'load_more_btn':{
43
  }
44
  ?>
45
  <div class="wdi_feed_wrapper <?php echo 'wdi_col_'.$feed_row['number_of_columns']?>" wdi-res='<?php echo 'wdi_col_'.$feed_row['number_of_columns']?>'></div>
46
+ <div class="wdi_clear"></div>
47
 
48
  <?php switch($feed_row['feed_display_view']){
49
  case 'load_more_btn':{
js/gallerybox/wdi_gallery_box.js CHANGED
@@ -1,10 +1,13 @@
1
-
2
  var isPopUpOpened = false;
3
 
4
- function wdi_spider_createpopup(url, current_view, width, height, duration, description, lifetime, currentFeed) {
 
5
 
6
  url = url.replace(/&#038;/g, '&');
7
- if (isPopUpOpened) { return };
 
 
 
8
  isPopUpOpened = true;
9
  if (wdi_spider_hasalreadyreceivedpopup(description) || wdi_spider_isunsupporteduseragent()) {
10
  return;
@@ -14,82 +17,88 @@ function wdi_spider_createpopup(url, current_view, width, height, duration, desc
14
  jQuery("#wdi_spider_popup_loading_" + current_view).css({display: "block"});
15
  jQuery("#wdi_spider_popup_overlay_" + current_view).css({display: "block"});
16
 
17
- // jQuery.get(url, function(data) {
18
- // ;
19
  // var popup = jQuery(
20
- // '<div id="wdi_spider_popup_wrap" class="wdi_spider_popup_wrap" style="' +
21
- // ' width:' + width + 'px;' +
22
- // ' height:' + height + 'px;' +
23
- // ' margin-top:-' + height / 2 + 'px;' +
24
- // ' margin-left: -' + width / 2 + 'px; ">' +
25
- // data +
26
- // '</div>')
27
  // .hide()
28
  // .appendTo("body");
29
-
30
  // wdi_spider_showpopup(description, lifetime, popup, duration);
31
  // }).success(function(jqXHR, textStatus, errorThrown) {
32
- // jQuery("#wdi_spider_popup_loading_" + current_view).css({display: "none !important;"});
33
- // });
34
  ///////////////////////////////////////
35
 
36
  jQuery.ajax({
37
  type: 'POST',
38
  url: url,
39
  dataType: 'text',
40
- data:{
41
- action:'WDIGalleryBox',
42
- image_rows: JSON.stringify(currentFeed.parsedData),
43
- feed_id: currentFeed.feed_row['id'],
44
- feed_counter: currentFeed.feed_row['wdi_feed_counter'],
45
  },
46
- success:function(response){
47
-
48
-
49
- var popup = jQuery(
50
- '<div id="wdi_spider_popup_wrap" class="wdi_spider_popup_wrap" style="' +
51
- ' width:' + width + 'px;' +
52
- ' height:' + height + 'px;' +
53
- ' margin-top:-' + height / 2 + 'px;' +
54
- ' margin-left: -' + width / 2 + 'px; ">' +
55
- response +
56
- '</div>')
57
- .hide()
58
- .appendTo("body");
59
- wdi_spider_showpopup(description, lifetime, popup, duration);
60
- jQuery("#wdi_spider_popup_loading_" + current_view).css({display: "none !important;"});
 
61
  }
62
- });
63
  /////////////////////////////////////////
64
  }
65
 
66
- function wdi_spider_showpopup(description, lifetime, popup, duration) {
 
67
  isPopUpOpened = true;
68
  popup.show();
69
 
70
  wdi_spider_receivedpopup(description, lifetime);
71
  }
72
 
73
- function wdi_spider_hasalreadyreceivedpopup(description) {
 
74
  if (document.cookie.indexOf(description) > -1) {
75
  delete document.cookie[document.cookie.indexOf(description)];
76
  }
77
- return false;
78
  }
79
 
80
- function wdi_spider_receivedpopup(description, lifetime) {
81
- var date = new Date();
 
82
  date.setDate(date.getDate() + lifetime);
83
- document.cookie = description + "=true;expires=" + date.toUTCString() + ";path=/";
84
  }
85
 
86
- function wdi_spider_isunsupporteduseragent() {
87
- return (!window.XMLHttpRequest);
 
88
  }
89
 
90
- function wdi_spider_destroypopup(duration) {
91
-
92
-
 
93
  if (document.getElementById("wdi_spider_popup_wrap") != null) {
94
  wdi_comments_manager.popup_destroyed();
95
 
@@ -101,7 +110,8 @@ function wdi_spider_destroypopup(duration) {
101
  if (typeof enable_addthis != "undefined" && enable_addthis) {
102
  jQuery(".at4-share-outer").hide();
103
  }
104
- setTimeout(function () {
 
105
  jQuery(".wdi_spider_popup_wrap").remove();
106
  jQuery(".wdi_spider_popup_loading").css({display: "none"});
107
  jQuery(".wdi_spider_popup_overlay").css({display: "none"});
@@ -122,19 +132,21 @@ function wdi_spider_destroypopup(duration) {
122
  }
123
 
124
 
125
- Object.size = function(obj) {
126
- var size = 0, key;
127
- for (key in obj) {
128
- if (obj.hasOwnProperty(key)) size++;
129
- }
130
- return size;
 
131
  };
132
- function wdi_spider_ajax_save(form_id,image_id) {
 
 
133
 
134
-
135
  wdi_comments_manager.init(image_id);
136
-
137
-
138
  // var post_data = {};
139
  // post_wdi_data["wdi_name"] = jQuery("#wdi_name").val();
140
  // post_wdi_data["wdi_comment"] = jQuery("#wdi_comment").val();
@@ -169,34 +181,36 @@ function wdi_spider_ajax_save(form_id,image_id) {
169
  // });
170
 
171
  // if (event.preventDefault) {
172
- // event.preventDefault();
173
  // }
174
  // else {
175
- // event.returnValue = false;
176
  // }
177
  return false;
178
  }
179
 
180
 
181
  wdi_comments_manager = {
182
- media_id : '',
183
- mediaComments :[], /*all comments*/
184
- load_more_count : 10,
185
- commentCounter : 0,/* current comments counter*/
186
- currentKey : -1, /*iamge id*/
187
- init : function(image_id){
188
-
189
- if(this.currentKey != image_id){
 
190
  this.currentKey = image_id;
191
 
192
  this.reset_comments();
193
  }
194
- else{
195
  /*open close*/
196
  /*do nothing*/
197
  }
198
  },
199
- reset_comments : function(){
 
200
  jQuery('#wdi_load_more_comments').remove();
201
  jQuery('#wdi_added_comments').html('');
202
  //currentImage = wdi_data[this.currentKey];
@@ -207,46 +221,51 @@ wdi_comments_manager = {
207
 
208
  //this.showComments(currentImage['comments_data']);
209
 
210
-
211
  },
212
- popup_destroyed : function(){
 
213
  this.media_id = '';
214
- this.mediaComments =[]; /*all comments*/
215
- this.commentCounter = 0;/* current comments counter**/
 
 
216
  this.currentKey = -1;
217
 
218
  },
219
 
220
  //function for dispaying comments
221
- showComments: function (comments,count){
222
-
223
- if(Object.size(comments)-this.commentCounter-count<0 || count===undefined){
224
- count = Object.size(comments)-this.commentCounter;
 
225
  }
226
  var counter = this.commentCounter;
227
- for(i=Object.size(comments)-counter-1;i>=Object.size(comments)-counter-count;i--){
228
  this.commentCounter++;
229
  var commentText = (comments[i]['text']);
230
  commentText = this.filterCommentText(commentText);
231
  var username = (comments[i]['from']['username']);
232
  var profile_picture = (comments[i]['from']['profile_picture']);
233
  var singleComment = jQuery('<div class="wdi_single_comment"></div>');
234
- singleComment.append(jQuery('<p class="wdi_comment_header_p"><span class="wdi_comment_header"><a target="_blank" href="//instagram.com/'+username+'"><img style="height:25px;width:25px;border-radius:25px" src="'+profile_picture+'"> '+username+'</a></span><span class="wdi_comment_date">'+wdi_front.convertUnixDate(comments[i]['created_time'])+'</span></p>'));
235
- singleComment.append(jQuery('<div class="wdi_comment_body_p"><span class="wdi_comment_body"><p>'+commentText+'</p></span></div>'));
236
  jQuery('#wdi_added_comments').prepend(singleComment);
237
  }
238
  this.updateScrollbar();
239
-
240
  },
241
 
242
  //function for updating scrollbar
243
- updateScrollbar : function (){
 
244
  var wdi_comments = jQuery('#wdi_comments');
245
  var wdi_added_comments = jQuery('#wdi_added_comments');
246
  //jQuery('#wdi_load_more_comments').remove();
247
- jQuery('.wdi_comments').attr('class','wdi_comments');
248
  jQuery('.wdi_comments').html('');
249
-
250
  /*restore load more button*/
251
 
252
  // if(jQuery('#wdi_load_more_comments').length===0){
@@ -260,53 +279,58 @@ wdi_comments_manager = {
260
  jQuery('.wdi_comments').append(wdi_added_comments);
261
 
262
  if (typeof jQuery().mCustomScrollbar !== 'undefined') {
263
- if (jQuery.isFunction(jQuery().mCustomScrollbar)) {
264
- jQuery(".wdi_comments").mCustomScrollbar({scrollInertia: 250});
265
- }
266
- }
267
-
268
  ////
269
- jQuery('.wdi_comments_close_btn').on('click',wdi_comment);
270
  //binding click event for loading more commetn by ajax
271
-
272
 
273
  },
274
  //get recent media comments
275
- getAjaxComments: function (){
276
- var access_token = wdi_front.access_token;
277
- jQuery.ajax({
 
278
  type: "POST",
279
- url: 'https://api.instagram.com/v1/media/'+this.media_id+'/comments?access_token='+access_token,
280
  dataType: 'jsonp',
281
- success: function(response){
282
- if(response == '' || response == undefined || response == null){
 
283
  errorMessage = 'Network Error, please try again later :(';
284
- alert(errorMessage);
285
  return;
286
  }
287
- if(response['meta']['code']!=200){
288
  errorMessage = response['meta']['error_message'];
289
- alert(errorMessage);
290
  return;
291
  }
292
-
293
  wdi_comments_manager.mediaComments = response['data'];
294
  //ttt
295
  var currentImage = wdi_data[wdi_comments_manager.currentKey];
296
  currentImage['comments_data'] = response['data'];
297
-
298
  wdi_comments_manager.showComments(currentImage['comments_data'], wdi_comments_manager.load_more_count);
299
  wdi_comments_manager.ajax_comments_ready(response['data']);
300
-
301
  }
302
  });
303
  },
304
- ajax_comments_ready:function (response){
305
- this.createLoadMoreAndBindEvent();
 
306
  },
307
- createLoadMoreAndBindEvent:function(){
308
- jQuery('#wdi_added_comments').prepend(jQuery('<p id="wdi_load_more_comments" class="wdi_load_more_comments">load more comments</p>'));
309
- jQuery('.wdi_comment_container #wdi_load_more_comments').on('click',function(){
 
 
310
  jQuery(this).remove();
311
  wdi_comments_manager.showComments(wdi_comments_manager.mediaComments, wdi_comments_manager.load_more_count);
312
  wdi_comments_manager.createLoadMoreAndBindEvent();
@@ -315,25 +339,29 @@ wdi_comments_manager = {
315
  /*
316
  * Filtesrs comment text and makes it instagram like comments
317
  */
318
- filterCommentText: function(comment){
 
319
  var commentArray = comment.split(' ');
320
  var commStr = '';
321
- for(var i=0;i<commentArray.length;i++){
322
- switch(commentArray[i][0]){
323
- case '@':{
324
- commStr+= '<a target="blank" class="wdi_comm_text_link" href="//instagram.com/'+commentArray[i].substring(1,commentArray[i].length)+'">'+commentArray[i]+'</a> ';
 
325
  break;
326
  }
327
- case '#':{
328
- commStr+= '<a target="blank" class="wdi_comm_text_link" href="//instagram.com/explore/tags/'+commentArray[i].substring(1,commentArray[i].length)+'">'+commentArray[i]+'</a> ';
 
329
  break;
330
  }
331
- default:{
332
- commStr+=commentArray[i]+' ';
 
333
  }
334
- }
335
  }
336
- commStr = commStr.substring(0,commStr.length-1);
337
  return commStr;
338
  }
339
 
@@ -367,14 +395,16 @@ wdi_comments_manager = {
367
  // }
368
 
369
  // Set value by ID.
370
- function wdi_spider_set_input_value(input_id, input_value) {
 
371
  if (document.getElementById(input_id)) {
372
  document.getElementById(input_id).value = input_value;
373
  }
374
  }
375
 
376
  // Submit form by ID.
377
- function wdi_spider_form_submit(event, form_id) {
 
378
  if (document.getElementById(form_id)) {
379
  document.getElementById(form_id).submit();
380
  }
@@ -387,9 +417,10 @@ function wdi_spider_form_submit(event, form_id) {
387
  }
388
 
389
  // Check if required field is empty.
390
- function wdi_spider_check_required(id, name) {
 
391
  if (jQuery('#' + id).val() == '') {
392
- alert(name + '* ' + wdi_objectL10n.wdi_field_required);
393
  jQuery('#' + id).attr('style', 'border-color: #FF0000;');
394
  jQuery('#' + id).focus();
395
  return true;
@@ -400,11 +431,12 @@ function wdi_spider_check_required(id, name) {
400
  }
401
 
402
  // Check Email.
403
- function wdi_spider_check_email(id) {
 
404
  if (jQuery('#' + id).val() != '') {
405
  var email = jQuery('#' + id).val().replace(/^\s+|\s+$/g, '');
406
  if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
407
- alert(wdi_objectL10n.wdi_mail_validation);
408
  return true;
409
  }
410
  return false;
@@ -412,7 +444,8 @@ function wdi_spider_check_email(id) {
412
  }
413
 
414
  // Refresh captcha.
415
- function wdi_captcha_refresh(id) {
 
416
  if (document.getElementById(id + "_img") && document.getElementById(id + "_input")) {
417
  srcArr = document.getElementById(id + "_img").src.split("&r=");
418
  document.getElementById(id + "_img").src = srcArr[0] + '&r=' + Math.floor(Math.random() * 100);
@@ -421,20 +454,21 @@ function wdi_captcha_refresh(id) {
421
  }
422
  }
423
 
424
- function wdi_play_pause($this){
 
425
  var video = $this.get(0);
426
  var regex = /firefox/i;
427
  var firefox = false;
428
- if(navigator.userAgent.match(regex)){
429
  firefox = true;
430
  }
431
- if(!firefox){
432
  if (!video.paused) {
433
- video.pause();
434
- }else{
435
- video.play();
436
  }
437
  }
438
-
439
 
440
  }
 
1
  var isPopUpOpened = false;
2
 
3
+ function wdi_spider_createpopup(url, current_view, width, height, duration, description, lifetime, currentFeed)
4
+ {
5
 
6
  url = url.replace(/&#038;/g, '&');
7
+ if (isPopUpOpened) {
8
+ return
9
+ }
10
+ ;
11
  isPopUpOpened = true;
12
  if (wdi_spider_hasalreadyreceivedpopup(description) || wdi_spider_isunsupporteduseragent()) {
13
  return;
17
  jQuery("#wdi_spider_popup_loading_" + current_view).css({display: "block"});
18
  jQuery("#wdi_spider_popup_overlay_" + current_view).css({display: "block"});
19
 
20
+ // jQuery.get(url, function(data) {
21
+ // ;
22
  // var popup = jQuery(
23
+ // '<div id="wdi_spider_popup_wrap" class="wdi_spider_popup_wrap" style="' +
24
+ // ' width:' + width + 'px;' +
25
+ // ' height:' + height + 'px;' +
26
+ // ' margin-top:-' + height / 2 + 'px;' +
27
+ // ' margin-left: -' + width / 2 + 'px; ">' +
28
+ // data +
29
+ // '</div>')
30
  // .hide()
31
  // .appendTo("body");
32
+
33
  // wdi_spider_showpopup(description, lifetime, popup, duration);
34
  // }).success(function(jqXHR, textStatus, errorThrown) {
35
+ // jQuery("#wdi_spider_popup_loading_" + current_view).css({display: "none !important;"});
36
+ // });
37
  ///////////////////////////////////////
38
 
39
  jQuery.ajax({
40
  type: 'POST',
41
  url: url,
42
  dataType: 'text',
43
+ data: {
44
+ action: 'WDIGalleryBox',
45
+ image_rows: JSON.stringify(currentFeed.parsedData),
46
+ feed_id: currentFeed.feed_row['id'],
47
+ feed_counter: currentFeed.feed_row['wdi_feed_counter'],
48
  },
49
+ success: function (response)
50
+ {
51
+
52
+
53
+ var popup = jQuery(
54
+ '<div id="wdi_spider_popup_wrap" class="wdi_spider_popup_wrap" style="' +
55
+ ' width:' + width + 'px;' +
56
+ ' height:' + height + 'px;' +
57
+ ' margin-top:-' + height / 2 + 'px;' +
58
+ ' margin-left: -' + width / 2 + 'px; ">' +
59
+ response +
60
+ '</div>')
61
+ .hide()
62
+ .appendTo("body");
63
+ wdi_spider_showpopup(description, lifetime, popup, duration);
64
+ jQuery("#wdi_spider_popup_loading_" + current_view).css({display: "none !important;"});
65
  }
66
+ });
67
  /////////////////////////////////////////
68
  }
69
 
70
+ function wdi_spider_showpopup(description, lifetime, popup, duration)
71
+ {
72
  isPopUpOpened = true;
73
  popup.show();
74
 
75
  wdi_spider_receivedpopup(description, lifetime);
76
  }
77
 
78
+ function wdi_spider_hasalreadyreceivedpopup(description)
79
+ {
80
  if (document.cookie.indexOf(description) > -1) {
81
  delete document.cookie[document.cookie.indexOf(description)];
82
  }
83
+ return false;
84
  }
85
 
86
+ function wdi_spider_receivedpopup(description, lifetime)
87
+ {
88
+ var date = new Date();
89
  date.setDate(date.getDate() + lifetime);
90
+ document.cookie = description + "=true;expires=" + date.toUTCString() + ";path=/";
91
  }
92
 
93
+ function wdi_spider_isunsupporteduseragent()
94
+ {
95
+ return (!window.XMLHttpRequest);
96
  }
97
 
98
+ function wdi_spider_destroypopup(duration)
99
+ {
100
+
101
+
102
  if (document.getElementById("wdi_spider_popup_wrap") != null) {
103
  wdi_comments_manager.popup_destroyed();
104
 
110
  if (typeof enable_addthis != "undefined" && enable_addthis) {
111
  jQuery(".at4-share-outer").hide();
112
  }
113
+ setTimeout(function ()
114
+ {
115
  jQuery(".wdi_spider_popup_wrap").remove();
116
  jQuery(".wdi_spider_popup_loading").css({display: "none"});
117
  jQuery(".wdi_spider_popup_overlay").css({display: "none"});
132
  }
133
 
134
 
135
+ Object.size = function (obj)
136
+ {
137
+ var size = 0, key;
138
+ for (key in obj) {
139
+ if (obj.hasOwnProperty(key)) size++;
140
+ }
141
+ return size;
142
  };
143
+ function wdi_spider_ajax_save(form_id, image_id)
144
+ {
145
+
146
 
 
147
  wdi_comments_manager.init(image_id);
148
+
149
+
150
  // var post_data = {};
151
  // post_wdi_data["wdi_name"] = jQuery("#wdi_name").val();
152
  // post_wdi_data["wdi_comment"] = jQuery("#wdi_comment").val();
181
  // });
182
 
183
  // if (event.preventDefault) {
184
+ // event.preventDefault();
185
  // }
186
  // else {
187
+ // event.returnValue = false;
188
  // }
189
  return false;
190
  }
191
 
192
 
193
  wdi_comments_manager = {
194
+ media_id: '',
195
+ mediaComments: [], /*all comments*/
196
+ load_more_count: 10,
197
+ commentCounter: 0, /* current comments counter*/
198
+ currentKey: -1, /*iamge id*/
199
+ init: function (image_id)
200
+ {
201
+
202
+ if (this.currentKey != image_id) {
203
  this.currentKey = image_id;
204
 
205
  this.reset_comments();
206
  }
207
+ else {
208
  /*open close*/
209
  /*do nothing*/
210
  }
211
  },
212
+ reset_comments: function ()
213
+ {
214
  jQuery('#wdi_load_more_comments').remove();
215
  jQuery('#wdi_added_comments').html('');
216
  //currentImage = wdi_data[this.currentKey];
221
 
222
  //this.showComments(currentImage['comments_data']);
223
 
224
+
225
  },
226
+ popup_destroyed: function ()
227
+ {
228
  this.media_id = '';
229
+ this.mediaComments = [];
230
+ /*all comments*/
231
+ this.commentCounter = 0;
232
+ /* current comments counter**/
233
  this.currentKey = -1;
234
 
235
  },
236
 
237
  //function for dispaying comments
238
+ showComments: function (comments, count)
239
+ {
240
+
241
+ if (Object.size(comments) - this.commentCounter - count < 0 || count === undefined) {
242
+ count = Object.size(comments) - this.commentCounter;
243
  }
244
  var counter = this.commentCounter;
245
+ for (i = Object.size(comments) - counter - 1; i >= Object.size(comments) - counter - count; i--) {
246
  this.commentCounter++;
247
  var commentText = (comments[i]['text']);
248
  commentText = this.filterCommentText(commentText);
249
  var username = (comments[i]['from']['username']);
250
  var profile_picture = (comments[i]['from']['profile_picture']);
251
  var singleComment = jQuery('<div class="wdi_single_comment"></div>');
252
+ singleComment.append(jQuery('<p class="wdi_comment_header_p"><span class="wdi_comment_header"><a target="_blank" href="//instagram.com/' + username + '"><img style="height:25px;width:25px;border-radius:25px" src="' + profile_picture + '"> ' + username + '</a></span><span class="wdi_comment_date">' + wdi_front.convertUnixDate(comments[i]['created_time']) + '</span></p>'));
253
+ singleComment.append(jQuery('<div class="wdi_comment_body_p"><span class="wdi_comment_body"><p>' + commentText + '</p></span></div>'));
254
  jQuery('#wdi_added_comments').prepend(singleComment);
255
  }
256
  this.updateScrollbar();
257
+
258
  },
259
 
260
  //function for updating scrollbar
261
+ updateScrollbar: function ()
262
+ {
263
  var wdi_comments = jQuery('#wdi_comments');
264
  var wdi_added_comments = jQuery('#wdi_added_comments');
265
  //jQuery('#wdi_load_more_comments').remove();
266
+ jQuery('.wdi_comments').attr('class', 'wdi_comments');
267
  jQuery('.wdi_comments').html('');
268
+
269
  /*restore load more button*/
270
 
271
  // if(jQuery('#wdi_load_more_comments').length===0){
279
  jQuery('.wdi_comments').append(wdi_added_comments);
280
 
281
  if (typeof jQuery().mCustomScrollbar !== 'undefined') {
282
+ if (jQuery.isFunction(jQuery().mCustomScrollbar)) {
283
+ jQuery(".wdi_comments").mCustomScrollbar({scrollInertia: 250});
284
+ }
285
+ }
286
+
287
  ////
288
+ jQuery('.wdi_comments_close_btn').on('click', wdi_comment);
289
  //binding click event for loading more commetn by ajax
290
+
291
 
292
  },
293
  //get recent media comments
294
+ getAjaxComments: function ()
295
+ {
296
+ var access_token = wdi_front.access_token;
297
+ jQuery.ajax({
298
  type: "POST",
299
+ url: 'https://api.instagram.com/v1/media/' + this.media_id + '/comments?access_token=' + access_token,
300
  dataType: 'jsonp',
301
+ success: function (response)
302
+ {
303
+ if (response == '' || response == undefined || response == null) {
304
  errorMessage = 'Network Error, please try again later :(';
305
+ wdi_front.show_alert(errorMessage);
306
  return;
307
  }
308
+ if (response['meta']['code'] != 200) {
309
  errorMessage = response['meta']['error_message'];
310
+ wdi_front.show_alert(errorMessage);
311
  return;
312
  }
313
+
314
  wdi_comments_manager.mediaComments = response['data'];
315
  //ttt
316
  var currentImage = wdi_data[wdi_comments_manager.currentKey];
317
  currentImage['comments_data'] = response['data'];
318
+
319
  wdi_comments_manager.showComments(currentImage['comments_data'], wdi_comments_manager.load_more_count);
320
  wdi_comments_manager.ajax_comments_ready(response['data']);
321
+
322
  }
323
  });
324
  },
325
+ ajax_comments_ready: function (response)
326
+ {
327
+ this.createLoadMoreAndBindEvent();
328
  },
329
+ createLoadMoreAndBindEvent: function ()
330
+ {
331
+ jQuery('#wdi_added_comments').prepend(jQuery('<p id="wdi_load_more_comments" class="wdi_load_more_comments">load more comments</p>'));
332
+ jQuery('.wdi_comment_container #wdi_load_more_comments').on('click', function ()
333
+ {
334
  jQuery(this).remove();
335
  wdi_comments_manager.showComments(wdi_comments_manager.mediaComments, wdi_comments_manager.load_more_count);
336
  wdi_comments_manager.createLoadMoreAndBindEvent();
339
  /*
340
  * Filtesrs comment text and makes it instagram like comments
341
  */
342
+ filterCommentText: function (comment)
343
+ {
344
  var commentArray = comment.split(' ');
345
  var commStr = '';
346
+ for (var i = 0; i < commentArray.length; i++) {
347
+ switch (commentArray[i][0]) {
348
+ case '@':
349
+ {
350
+ commStr += '<a target="blank" class="wdi_comm_text_link" href="//instagram.com/' + commentArray[i].substring(1, commentArray[i].length) + '">' + commentArray[i] + '</a> ';
351
  break;
352
  }
353
+ case '#':
354
+ {
355
+ commStr += '<a target="blank" class="wdi_comm_text_link" href="//instagram.com/explore/tags/' + commentArray[i].substring(1, commentArray[i].length) + '">' + commentArray[i] + '</a> ';
356
  break;
357
  }
358
+ default:
359
+ {
360
+ commStr += commentArray[i] + ' ';
361
  }
362
+ }
363
  }
364
+ commStr = commStr.substring(0, commStr.length - 1);
365
  return commStr;
366
  }
367
 
395
  // }
396
 
397
  // Set value by ID.
398
+ function wdi_spider_set_input_value(input_id, input_value)
399
+ {
400
  if (document.getElementById(input_id)) {
401
  document.getElementById(input_id).value = input_value;
402
  }
403
  }
404
 
405
  // Submit form by ID.
406
+ function wdi_spider_form_submit(event, form_id)
407
+ {
408
  if (document.getElementById(form_id)) {
409
  document.getElementById(form_id).submit();
410
  }
417
  }
418
 
419
  // Check if required field is empty.
420
+ function wdi_spider_check_required(id, name)
421
+ {
422
  if (jQuery('#' + id).val() == '') {
423
+ wdi_front.show_alert(name + '* ' + wdi_objectL10n.wdi_field_required);
424
  jQuery('#' + id).attr('style', 'border-color: #FF0000;');
425
  jQuery('#' + id).focus();
426
  return true;
431
  }
432
 
433
  // Check Email.
434
+ function wdi_spider_check_email(id)
435
+ {
436
  if (jQuery('#' + id).val() != '') {
437
  var email = jQuery('#' + id).val().replace(/^\s+|\s+$/g, '');
438
  if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
439
+ wdi_front.show_alert(wdi_objectL10n.wdi_mail_validation);
440
  return true;
441
  }
442
  return false;
444
  }
445
 
446
  // Refresh captcha.
447
+ function wdi_captcha_refresh(id)
448
+ {
449
  if (document.getElementById(id + "_img") && document.getElementById(id + "_input")) {
450
  srcArr = document.getElementById(id + "_img").src.split("&r=");
451
  document.getElementById(id + "_img").src = srcArr[0] + '&r=' + Math.floor(Math.random() * 100);
454
  }
455
  }
456
 
457
+ function wdi_play_pause($this)
458
+ {
459
  var video = $this.get(0);
460
  var regex = /firefox/i;
461
  var firefox = false;
462
+ if (navigator.userAgent.match(regex)) {
463
  firefox = true;
464
  }
465
+ if (!firefox) {
466
  if (!video.paused) {
467
+ video.pause();
468
+ } else {
469
+ video.play();
470
  }
471
  }
472
+
473
 
474
  }
js/wdi_frontend.js CHANGED
@@ -1,185 +1,195 @@
1
  if (typeof wdi_front == 'undefined') {
2
- wdi_front = {
3
- type: 'not_declared'
4
- };
5
  }
6
 
7
 
8
-
9
  wdi_front.detectEvent = function ()
10
  {
11
- var isMobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
12
- if (isMobile) {
13
- return "touchend";
14
- } else {
15
- return 'click';
16
- }
 
 
 
 
 
 
 
 
 
 
17
  }
18
 
 
19
  wdi_front.globalInit = function ()
20
  {
21
- var num = wdi_front['feed_counter'];
22
-
23
- if(typeof wdi_ajax.ajax_response != "undefined"){
24
- var init_feed_counter = wdi_feed_counter_init.wdi_feed_counter_init;
25
- }
26
- else{
27
- var init_feed_counter = 0;
28
- }
29
- for (var i = init_feed_counter; i <= num; i++) {
30
-
31
- var currentFeed = new WDIFeed(window['wdi_feed_' + i]);
32
-
33
- /*initializing instagram object which will handle all instagram api requests*/
34
- currentFeed.instagram = new WDIInstagram();
35
-
36
- /**
37
- * this object will be passed to filtering function of currentFeed.instagram as second parameter
38
- * @type {Object}
39
- */
40
- currentFeed.instagram.filterArguments = {
41
- feed: currentFeed
42
- };
43
-
44
- currentFeed.instagram.filters = [
45
- {
46
- 'where': 'getUserRecentMedia',
47
- 'what': function (response, args, cArgs)
48
- {
49
- return args.feed.conditionalFilter(response, cArgs);
50
- }
51
- },
52
- {
53
- 'where': 'getTagRecentMedia',
54
- 'what': function (response, args, cArgs)
55
- {
56
- return args.feed.conditionalFilter(response, cArgs);
57
- }
58
- },
59
- {
60
- 'where': 'getRecentLikedMedia',
61
- 'what': function (response, args, cArgs)
62
- {
63
- return args.feed.conditionalFilter(response, cArgs);
64
- }
65
- },
66
-
67
-
68
- {
69
- 'where': 'requestByUrl',
70
- 'what': function (response, args, cArgs)
71
- {
72
- return args.feed.conditionalFilter(response, cArgs);
73
- }
74
- },];
75
-
76
-
77
- currentFeed.instagram.addToken(currentFeed['feed_row']['access_token']);
78
-
79
- wdi_front.access_token = currentFeed['feed_row']['access_token'];
80
-
81
- currentFeed.dataStorageRaw = []; //stores all getted data from instagram api
82
-
83
- currentFeed.dataStorage = []; //stores all avialable data
84
- currentFeed.dataStorageList = []; //?
85
- currentFeed.allResponseLength = 0; //?
86
- //number of instagram objects which has been got by single request
87
- currentFeed.currentResponseLength = 0;
88
-
89
- //temprorary usersData which is uses in case when getted data is smaller then needed
90
- currentFeed.temproraryUsersData = [];
91
-
92
- currentFeed.removedUsers = 0;
93
- currentFeed.nowLoadingImages = true;
94
- currentFeed.imageIndex = 0; //index for image indexes
95
- currentFeed.resIndex = 0; //responsive indexes used for pagination
96
- currentFeed.currentPage = 1; //pagination page number
97
- currentFeed.userSortFlags = []; //array for descripbing user based filter options
98
- currentFeed.customFilterChanged = false; //flag to notice filter change, onclick on username
99
-
100
-
101
- /**
102
- * This variable describes after how many requests program will stop searching for content
103
- * this number is very important and should not be set too high, because when feed has conditional filter
104
- * and filtered items are rare then the program will recursively request new photos and will filter them
105
- * if no image was fount it will go into infinite loop if feed images are "infinite" ( very huge number )
106
- * and if requests count in 1 hour exeed 5000 instagram will block access token for one hour
107
- *
108
- * @type {Number}
109
- */
110
- currentFeed.maxConditionalFiltersRequestCount = 10;
111
-
112
- /**
113
- * This variable shows us how many times program has been recursively called,
114
- * it changes it value within filtering function, and resets itself to 0 when feed is being displayed
115
- *
116
- * @type {Number}
117
- */
118
- currentFeed.instagramRequestCounter = 0;
119
-
120
- /**
121
- * This array stores data from each request,
122
- * it is used to determine and remove duplicate photos caused by multiple hashtags
123
- * it is resetted to its inital [] value after displaying feed
124
- *
125
- * @type {Array}
126
- */
127
- currentFeed.conditionalFilterBuffer = [];
128
-
129
-
130
- currentFeed.stopInfiniteScrollFlag = false;
131
-
132
- window.onload = function ()
133
- {
134
- for (var i = init_feed_counter; i <= wdi_front.feed_counter; i++) {
135
- window['wdi_feed_' + i]['nowLoadingImages'] = false;
136
- }
137
- }
138
-
139
- if (currentFeed.feed_row.feed_type == 'masonry') {
140
- currentFeed.displayedData = [];
141
- }
142
-
143
-
144
- //if pagination is on then set pagination parameters
145
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
146
- currentFeed.feed_row.resort_after_load_more = 0;
147
- if (currentFeed.feed_row.feed_type != 'image_browser') {
148
- currentFeed.feed_row.load_more_number = parseInt(currentFeed.feed_row.pagination_per_page_number);
149
- currentFeed.feed_row.number_of_photos = (1 + parseInt(currentFeed.feed_row.pagination_preload_number)) * currentFeed.feed_row.load_more_number;
150
- } else {
151
- currentFeed.feed_row.number_of_photos = 1 + parseInt(currentFeed.feed_row.image_browser_preload_number);
152
- currentFeed.feed_row.load_more_number = parseInt(currentFeed.feed_row.image_browser_load_number);
153
- }
154
-
155
-
156
- currentFeed.freeSpaces = (Math.floor(currentFeed.feed_row.pagination_per_page_number / currentFeed.feed_row.number_of_columns) + 1) * currentFeed.feed_row.number_of_columns - currentFeed.feed_row.pagination_per_page_number;
157
- } else {
158
- currentFeed.freeSpaces = 0;
159
- }
160
 
161
 
162
- //initializing function for lightbox
163
- currentFeed.galleryBox = function (image_id)
164
- {
165
- wdi_spider_createpopup(wdi_url.ajax_url + '?gallery_id=' + this.feed_row['id'] + '&image_id=' + image_id, wdi_front.feed_counter, this.feed_row['lightbox_width'], this.feed_row['lightbox_height'], 1, 'testpopup', 5, this);
166
- }
167
- //calling responive javascript
168
- wdi_responsive.columnControl(currentFeed);
169
 
170
- //if feed type is masonry then trigger resize event for building proper column layout
171
- if (currentFeed.feed_row.feed_type == 'masonry') {
172
- jQuery(window).trigger('resize');
173
- }
174
 
175
- wdi_front.bindEvents(currentFeed);
176
 
177
- window['wdi_feed_' + i] = currentFeed;
178
 
179
 
180
- //initializing each feed
181
- wdi_front.init(currentFeed);
182
- } //endfor
183
 
184
  }
185
 
@@ -187,60 +197,60 @@ wdi_front.init = function (currentFeed)
187
  {
188
 
189
 
190
- //some varables used in code
191
- currentFeed.photoCounter = currentFeed.feed_row["number_of_photos"];
192
 
193
 
194
- if (currentFeed.feed_row.liked_feed == 'liked') {
195
- currentFeed.feed_users = ['self'];
196
- // do nothing,
197
- }
198
- else
199
- if (wdi_front.isJsonString(currentFeed.feed_row.feed_users)) {
200
- /**
201
- * Contains username and user_id of each user
202
- * @type {[Array}
203
- */
204
- currentFeed.feed_users = JSON.parse(currentFeed.feed_row.feed_users);
205
 
206
- /**
207
- * Check if feed user has no id for some reason then update user
208
- * and after updating them initialize feed
209
- */
210
- if (wdi_front.updateUsersIfNecessary(currentFeed)) {
211
- return;
212
- }
213
- ;
214
 
215
 
216
- } else {
217
- alert('provided feed users are invalid or obsolete for this version of plugin');
218
- return;
219
- }
220
 
221
 
222
- //wdi_front.loadInstagramMedia( currentFeed, currentFeed.feed_row.number_of_photos);
223
 
224
- currentFeed.dataCount = currentFeed.feed_users.length; //1 in case of self feed
225
 
226
 
227
- for (var i = 0; i < currentFeed.dataCount; i++) {
228
- wdi_front.instagramRequest(i, currentFeed);
229
- }
230
 
231
 
232
- if (currentFeed.feed_row["number_of_photos"] > 0) {
233
- wdi_front.ajaxLoader(currentFeed);
234
- }
235
 
236
 
237
- //setting feed name
238
- if (currentFeed['feed_row']['display_header'] === '1') {
239
- wdi_front.show('header', currentFeed);
240
- }
241
- if (currentFeed['feed_row']['show_usernames'] === '1') {
242
- wdi_front.show('users', currentFeed);
243
- }
244
 
245
 
246
  }
@@ -253,12 +263,12 @@ wdi_front.init = function (currentFeed)
253
  */
254
  wdi_front.isJsonString = function (str)
255
  {
256
- try {
257
- JSON.parse(str);
258
- } catch (e) {
259
- return false;
260
- }
261
- return true;
262
  }
263
 
264
 
@@ -272,43 +282,43 @@ wdi_front.isJsonString = function (str)
272
  wdi_front.instagramRequest = function (id, currentFeed)
273
  {
274
 
275
- var feed_users = currentFeed.feed_users,
276
- _this = this;
277
- if (typeof feed_users[id] === 'string' && feed_users[id] === 'self') { // self liked media
278
- currentFeed.instagram.getRecentLikedMedia({
279
- success: function (response)
280
- {
281
- response = _this.checkMediaResponse(response);
282
- if (response != false) {
283
- _this.saveSelfUserData(response, currentFeed);
284
- }
285
- }
286
- });
287
- }
288
- else
289
- if (this.getInputType(feed_users[id]['username']) == 'hashtag') {
290
- currentFeed.instagram.getTagRecentMedia(this.stripHashtag(feed_users[id]['username']), {
291
- success: function (response)
292
- {
293
- response = _this.checkMediaResponse(response);
294
- if (response != false) {
295
- _this.saveUserData(response, currentFeed.feed_users[id], currentFeed);
296
- }
297
- }
298
- });
299
- }
300
- else
301
- if (this.getInputType(feed_users[id]['username']) == 'user') {
302
- currentFeed.instagram.getUserRecentMedia(feed_users[id]['id'], {
303
- success: function (response)
304
- {
305
- response = _this.checkMediaResponse(response);
306
- if (response != false) {
307
- _this.saveUserData(response, currentFeed.feed_users[id], currentFeed);
308
- }
309
- }
310
- });
311
- }
312
 
313
  }
314
 
@@ -319,7 +329,7 @@ wdi_front.instagramRequest = function (id, currentFeed)
319
  */
320
  wdi_front.isHashtag = function (str)
321
  {
322
- return (str[0] === '#');
323
  }
324
 
325
 
@@ -330,56 +340,56 @@ wdi_front.isHashtag = function (str)
330
  wdi_front.saveUserData = function (data, user, currentFeed)
331
  {
332
 
333
- data['username'] = user.username;
334
- data['user_id'] = user.id;
335
 
336
- //checking if user type is hashtag then manually add hashtag to each object, for later use
337
- //hashtag based filters
338
- if (data['user_id'][0] === '#') {
339
- data['data'] = wdi_front.appendRequestHashtag(data['data'], data['user_id']);
340
- }
341
 
342
 
343
- currentFeed.usersData.push(data);
344
 
345
 
346
- currentFeed.currentResponseLength = wdi_front.getArrayContentLength(currentFeed.usersData, 'data');
347
- currentFeed.allResponseLength += currentFeed.currentResponseLength;
348
 
349
 
350
- if (currentFeed.dataCount == currentFeed.usersData.length) {
351
 
352
- //if getted objects is not enough then recuest new ones
353
- if (currentFeed.currentResponseLength < currentFeed.feed_row.number_of_photos && !wdi_front.userHasNoPhoto(currentFeed)) {
354
- //console.log('initial recursion');
355
- /*here we are calling loadMore function out of recursion cylce, after this initial-keep call
356
- loadMore will be called with 'initial' recursivly until the desired number of photos is reached
357
- if possible*/
358
 
359
- wdi_front.loadMore('initial-keep', currentFeed);
360
- } else {
361
 
362
 
363
- //display feed
364
- wdi_front.displayFeed(currentFeed);
365
- //when all data us properly displayed check for any active filters and then apply them
366
- wdi_front.applyFilters(currentFeed);
367
 
368
 
369
- /*removing load more button of feed has finished*/
370
- if (!wdi_front.activeUsersCount(currentFeed)) {
371
- if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
372
- var feed_container = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter);
373
- feed_container.find('.wdi_load_more').addClass('wdi_hidden');
374
- feed_container.find('.wdi_spinner').addClass('wdi_hidden');
375
- }
376
- }
377
- ;
378
 
379
- }
380
 
381
 
382
- }
383
 
384
  }
385
 
@@ -391,51 +401,51 @@ wdi_front.saveUserData = function (data, user, currentFeed)
391
  wdi_front.saveSelfUserData = function (data, currentFeed)
392
  {
393
 
394
- //keep empty for self feed
395
- data['username'] = '';
396
- data['user_id'] = '';
397
 
398
- currentFeed.usersData.push(data);
399
 
400
 
401
- currentFeed.currentResponseLength = wdi_front.getArrayContentLength(currentFeed.usersData, 'data');
402
- currentFeed.allResponseLength += currentFeed.currentResponseLength;
403
 
404
 
405
- if (currentFeed.dataCount == currentFeed.usersData.length) {
406
 
407
- //if retrieved objects are not enough then request new ones
408
 
409
- if (currentFeed.currentResponseLength < currentFeed.feed_row.number_of_photos && !wdi_front.userHasNoPhoto(currentFeed)) {
410
- //console.log('initial recursion');
411
- /*here we are calling loadMore function out of recursion cycle, after this initial-keep call
412
- loadMore will be called with 'initial' recursively until the desired number of photos is reached
413
- if possible*/
414
 
415
- wdi_front.loadMore('initial-keep', currentFeed);
416
- } else {
417
 
418
 
419
- //display feed
420
- wdi_front.displayFeed(currentFeed);
421
- //when all data us properly displayed check for any active filters and then apply them
422
- wdi_front.applyFilters(currentFeed);
423
 
424
 
425
- /*removing load more button of feed has finished*/
426
- if (!wdi_front.activeUsersCount(currentFeed)) {
427
- if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
428
- var feed_container = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter);
429
- feed_container.find('.wdi_load_more').addClass('wdi_hidden');
430
- feed_container.find('.wdi_spinner').addClass('wdi_hidden');
431
- }
432
- }
433
- ;
434
 
435
- }
436
 
437
 
438
- }
439
 
440
  }
441
 
@@ -445,29 +455,29 @@ wdi_front.saveSelfUserData = function (data, currentFeed)
445
  wdi_front.userHasNoPhoto = function (currentFeed, cstData)
446
  {
447
 
448
- var counter = 0;
449
- var data = currentFeed.usersData;
450
- if (typeof cstData != 'undefined') {
451
- data = cstData;
452
- }
453
- for (var i = 0; i < data.length; i++) {
454
- if (currentFeed.feed_row.liked_feed === 'liked') {
455
- if (typeof data[i]['pagination']['next_max_like_id'] == 'undefined') {
456
- counter++
457
- }
458
- }
459
- else {
460
- if (typeof data[i]['pagination']['next_max_id'] == 'undefined') {
461
- counter++
462
- }
463
- }
464
-
465
- }
466
- if (counter == data.length) {
467
- return 1;
468
- } else {
469
- return 0;
470
- }
471
  }
472
 
473
  /*
@@ -475,10 +485,10 @@ wdi_front.userHasNoPhoto = function (currentFeed, cstData)
475
  */
476
  wdi_front.appendRequestHashtag = function (data, hashtag)
477
  {
478
- for (var i = 0; i < data.length; i++) {
479
- data[i]['wdi_hashtag'] = hashtag;
480
- }
481
- return data;
482
  }
483
 
484
 
@@ -491,110 +501,110 @@ wdi_front.displayFeed = function (currentFeed, load_more_number)
491
  {
492
 
493
 
494
- if (currentFeed.customFilterChanged == false) {
495
- //sorting data...
496
- var data = wdi_front.feedSort(currentFeed, load_more_number);
497
- }
498
 
499
 
500
- //becomes true when user clicks in frontend filter
501
- //if isset to true then loadmore recursion would not start
502
- var frontendCustomFilterClicked = currentFeed.customFilterChanged;
503
 
504
 
505
- // if custom filter changed then display custom data
506
- if (currentFeed.customFilterChanged == true) {
507
- var data = currentFeed.customFilteredData;
508
 
509
- //parsing data for lightbox
510
- currentFeed.parsedData = wdi_front.parseLighboxData(currentFeed, true);
511
- }
512
 
513
 
514
- //storing all sorted data in array for later use in user based filters
515
- if (currentFeed.feed_row.resort_after_load_more != '1') {
516
- // filter changes when user clicks to usernames in header
517
- // at that point displayFeed triggers but we don't have any new data so
518
- // we are not adding new data to our list
519
- if (currentFeed.customFilterChanged == false) {
520
- currentFeed.dataStorageList = currentFeed.dataStorageList.concat(data);
521
- }
522
- } else {
523
- // filter changes when user clicks to usernames in header
524
- // at that point displayFeed triggers but we don't have any new data so
525
- // we are not adding new data to our list
526
- if (currentFeed.customFilterChanged == false) {
527
- currentFeed.dataStorageList = data;
528
- }
529
- }
530
 
531
- //checking feed_type and calling proper rendering functions
532
- if (currentFeed.feed_row.feed_type == 'masonry') {
533
- wdi_front.masonryDisplayFeedItems(data, currentFeed);
534
- }
535
- if (currentFeed.feed_row.feed_type == 'thumbnails' || currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
536
- wdi_front.displayFeedItems(data, currentFeed);
537
- }
538
 
539
 
540
- //recursively calling load more to get photos
541
- var dataLength = wdi_front.getDataLength(currentFeed);
542
 
543
 
544
- if (dataLength < currentFeed.photoCounter && !frontendCustomFilterClicked && currentFeed.instagramRequestCounter <= currentFeed.maxConditionalFiltersRequestCount && !wdi_front.allDataHasFinished(currentFeed)) {
545
- wdi_front.loadMore('', currentFeed);
546
 
547
- } else {
548
- wdi_front.allImagesLoaded(currentFeed);
549
- }
550
 
551
 
552
- /**
553
- * if maximum number of requests are reached then stop laoding more images and show images which are available
554
- * @param {Number} currentFeed.instagramRequestCounter > currentFeed.maxConditionalFiltersRequestCount [description]
555
- * @return {Boolean}
556
- */
557
- if (currentFeed.instagramRequestCounter > currentFeed.maxConditionalFiltersRequestCount) {
558
- wdi_front.allImagesLoaded(currentFeed);
559
 
560
- //if no data was received then
561
- if (data.length == 0) {
562
- //if feed_display_view is set to infinite scroll then after reaching the limit once set this flag to false
563
- //this will stop infinite scrolling and will not load any images even when scrolling
564
- currentFeed.stopInfiniteScrollFlag = true;
565
- }
566
- }
567
 
568
- //checking if display_view is pagination and we are not on the last page then enable
569
- //last page button
570
- if (currentFeed.feed_row.feed_display_view == 'pagination' && currentFeed.currentPage < currentFeed.paginator) {
571
- jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter).find('#wdi_last_page').removeClass('wdi_disabled');
572
- }
573
 
574
 
575
- // reset instagram request counter to zero for next set of requests
576
- currentFeed.instagramRequestCounter = 0;
577
 
578
- //reset conditional filter buffer for the next bunch of requests
579
- currentFeed.conditionalFilterBuffer = [];
580
 
581
- //if there are any missing images in header then replace them with new ones if possible
582
- wdi_front.updateUsersImages(currentFeed);
583
 
584
 
585
- // /**
586
- // * Enable image lazy laoding if pagination is not enabeled because pagination has option for preloading images
587
- // * which is the opposide of lazy load
588
- // */
589
- // if( currentFeed.feed_row.feed_display_view != 'pagination' ){
590
- // jQuery(function() {
591
- // jQuery('img.wdi_img').lazyload({
592
- // skip_invisible : false,
593
- // threshold : 400
594
- // });
595
- // });
596
 
597
- // }
598
 
599
  }
600
 
@@ -605,26 +615,26 @@ wdi_front.displayFeed = function (currentFeed, load_more_number)
605
  */
606
  wdi_front.updateUsersImages = function (currentFeed)
607
  {
608
- var elements = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter).find('.wdi_single_user .wdi_user_img_wrap img');
609
- elements.each(function ()
610
- {
611
- if (jQuery(this).attr('src') == wdi_url.plugin_url + '../images/missing.png' || jQuery(this).attr('src') == '') {
612
- //console.log('missing');
613
 
614
- if (currentFeed.feed_row.liked_feed == 'liked') {
615
- return;
616
- }
617
 
618
 
619
- for (var j = 0; j < currentFeed.usersData.length; j++) {
620
- if (currentFeed.usersData[j]['username'] == jQuery(this).parent().parent().find('h3').text()) {
621
- if (currentFeed.usersData[j]['data'].length != 0) {
622
- jQuery(this).attr('src', currentFeed.usersData[j]['data'][0]['images']['thumbnail']['url']);
623
- }
624
- }
625
- }
626
- }
627
- });
628
  }
629
 
630
 
@@ -635,137 +645,141 @@ wdi_front.updateUsersImages = function (currentFeed)
635
  */
636
  wdi_front.masonryDisplayFeedItems = function (data, currentFeed)
637
  {
638
- var masonryColEnds = [];
639
- var masonryColumns = [];
640
- if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + " .wdi_feed_wrapper").length == 0) {
641
- //no feed in DOM, ignore
642
- return;
643
- }
644
- jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_masonry_column').each(function ()
645
- {
646
-
647
- //if resorte after load more is on then reset columns on every load more
648
- if (currentFeed.feed_row.resort_after_load_more == 1) {
649
- jQuery(this).html('');
650
- currentFeed.imageIndex = 0;
651
- }
652
-
653
- //if custom filter is set or changed then reset masonry columns
654
- if (currentFeed.customFilterChanged == true) {
655
- jQuery(this).html('');
656
- currentFeed.imageIndex = 0;
657
- }
658
-
659
- //check if pagination is enabled then each page should have resetted colEnds
660
- //else give previous colEnds
661
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
662
- masonryColEnds.push(0);
663
- } else {
664
- masonryColEnds.push(jQuery(this).height());
665
- }
666
-
667
- masonryColumns.push(jQuery(this));
668
- });
669
-
670
- //if custom filter is set or changed then reset masonry columns
671
- if (currentFeed.customFilterChanged == true) {
672
- currentFeed.customFilterChanged = false;
673
- }
674
-
675
-
676
- //loop for displaying items
677
- for (var i = 0; i < data.length; i++) {
678
-
679
- currentFeed.displayedData.push(data[i]);
680
- if (data[i]['type'] == 'image') {
681
- var photoTemplate = wdi_front.getPhotoTemplate(currentFeed);
682
- } else {
683
- var photoTemplate = wdi_front.getVideoTemplate(currentFeed);
684
- }
685
-
686
- var rawItem = data[i];
687
- var item = wdi_front.createObject(rawItem, currentFeed);
688
- var html = photoTemplate(item);
689
-
690
- //find column with minumum height and append to it new object
691
- var shortCol = wdi_front.array_min(masonryColEnds);
692
- var imageResolution = wdi_front.getImageResolution(data[i]);
693
-
694
- masonryColumns[shortCol['index']].html(masonryColumns[shortCol['index']].html() + html);
695
- masonryColEnds[shortCol['index']] += masonryColumns[shortCol['index']].width() * imageResolution;
696
- currentFeed.imageIndex++;
697
-
698
-
699
- //changing responsive indexes for pagination
700
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
701
- if ((i + 1) % currentFeed.feed_row.pagination_per_page_number === 0) {
702
- currentFeed.resIndex += currentFeed.freeSpaces + 1;
703
- } else {
704
- currentFeed.resIndex++;
705
- }
706
- }
707
- }
708
-
709
-
710
- //binding onload event for ajax loader
711
- currentFeed.wdi_loadedImages = 0;
712
- var columnFlag = false;
713
- currentFeed.wdi_load_count = i;
714
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
715
- var feed_wrapper = jQuery('#wdi_feed_' + wdi_feed_counter + ' img.wdi_img').on('load', function ()
716
- {
717
- currentFeed.wdi_loadedImages++;
718
- checkLoaded();
719
-
720
- //calls wdi_responsive.columnControl() which calculates column number on page
721
- //and gives feed_wrapper proper column class
722
- if (columnFlag === false) {
723
- wdi_responsive.columnControl(currentFeed, 1);
724
- columnFlag = true;
725
- }
726
-
727
- //Binds caption opening and closing event to each image photo_title/mmmmmm
728
- // if (currentFeed.feed_row.feed_type != 'blog_style') {
729
- // wdi_responsive.bindMasonryCaptionEvent(jQuery(this).parent().parent().parent().parent().find('.wdi_photo_title'), currentFeed);
730
- // }
731
-
732
- });
733
-
734
-
735
- /**
736
- * if feed type is not blog style then after displaying images assign click evetns to their captions
737
- * this part of code is a bit differenet from free version because of image lazy loading feature
738
- *
739
- * in free version events are assigned directly in onload event, but when lazy loading added it cased duplicate event fireing
740
- * so event assigning moved to here
741
- *
742
- */
743
- // if ( currentFeed.feed_row.feed_type != 'blog_style' ){
744
- // jQuery('#wdi_feed_'+currentFeed.feed_row.wdi_feed_counter+' .wdi_photo_title').each(function(){
745
- // wdi_responsive.bindMasonryCaptionEvent(jQuery(this),currentFeed);
746
- // });
747
- // }
748
-
749
-
750
- //checks if all iamges have been succesfully loaded then it updates variables for next time use
751
- function checkLoaded()
752
- {
753
-
754
- if (currentFeed.wdi_load_count === currentFeed.wdi_loadedImages && currentFeed.wdi_loadedImages != 0) {
755
- currentFeed.loadedImages = 0;
756
- currentFeed.wdi_load_count = 0;
757
- wdi_front.allImagesLoaded(currentFeed);
758
-
759
- }
760
- }
 
 
 
 
761
 
762
- //checking if pagination next button was clicked then change page
763
- if (currentFeed.paginatorNextFlag == true) {
764
- wdi_front.updatePagination(currentFeed, 'next');
765
- }
766
-
767
- //check if load more done successfully then set infinite scroll flag to false
768
- currentFeed.infiniteScrollFlag = false;
769
 
770
 
771
  }
@@ -777,10 +791,10 @@ wdi_front.masonryDisplayFeedItems = function (data, currentFeed)
777
  wdi_front.getImageResolution = function (data)
778
  {
779
 
780
- var originalWidth = data['images']['standard_resolution']['width'];
781
- var originalHeight = data['images']['standard_resolution']['height'];
782
- var resolution = originalHeight / originalWidth;
783
- return resolution;
784
  }
785
 
786
  /*
@@ -790,30 +804,30 @@ wdi_front.getImageResolution = function (data)
790
  wdi_front.getDataLength = function (currentFeed, customStorage)
791
  {
792
 
793
- var length = 0;
794
- if (typeof customStorage === 'undefined') {
795
- for (var j = 0; j < currentFeed.dataStorage.length; j++) {
796
- length += currentFeed.dataStorage[j].length;
797
- }
798
- } else {
799
- for (var j = 0; j < customStorage.length; j++) {
800
- length += customStorage[j].length;
801
- }
802
- }
803
 
804
- return length;
805
  }
806
 
807
  wdi_front.getArrayContentLength = function (array, data)
808
  {
809
- var sum = 0;
810
- for (var i = 0; i < array.length; i++) {
811
- if (array[i]['finished'] == 'finished') {
812
- continue;
813
- }
814
- sum += array[i][data].length;
815
- }
816
- return sum;
817
  }
818
 
819
 
@@ -824,233 +838,237 @@ wdi_front.getArrayContentLength = function (array, data)
824
  */
825
  wdi_front.displayFeedItems = function (data, currentFeed)
826
  {
827
- if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + " .wdi_feed_wrapper").length == 0) {
828
- //no feed in DOM, ignore
829
- return;
830
- }
831
 
832
- //gets ready data, gets data template, and appens it into feed_wrapper
833
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
834
- var feed_wrapper = jQuery('#wdi_feed_' + wdi_feed_counter + ' .wdi_feed_wrapper');
835
-
836
- //if resort_after_pagination is on then rewrite feed data
837
- if (currentFeed.feed_row['resort_after_load_more'] === '1') {
838
- feed_wrapper.html('');
839
- currentFeed.imageIndex = 0;
840
- }
841
 
842
- //if custom filter is set or changed then reset masonry columns
843
- if (currentFeed.customFilterChanged == true) {
844
- feed_wrapper.html('');
845
- currentFeed.imageIndex = 0;
846
- currentFeed.customFilterChanged = false;
847
- }
848
-
849
-
850
- var lastIndex = wdi_front.getImgCount(currentFeed) - data.length - 1;
851
-
852
- /**
853
- * if feed display view is set to pagination then check if the current page has not enough photos to be a complete page then
854
- * --currentPage so that after loading new images we stay on the same page and see new images which will be located in that page
855
- * also do the same thing when recievied data has lenght equal to zero
856
- */
857
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
858
- if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + ' [wdi_page="' + (currentFeed.currentPage - 1) + '"]').length < currentFeed.feed_row.load_more_number || data.length == 0) {
859
- currentFeed.currentPage = (--currentFeed.currentPage <= 1) ? 1 : currentFeed.currentPage;
860
- }
861
- }
862
 
863
 
864
- for (var i = 0; i < data.length; i++) {
865
- if (data[i]['type'] == 'image') {
866
- var photoTemplate = wdi_front.getPhotoTemplate(currentFeed);
867
- } else {
868
- var photoTemplate = wdi_front.getVideoTemplate(currentFeed);
869
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
 
871
- var rawItem = data[i];
872
- var item = wdi_front.createObject(rawItem, currentFeed);
873
- var html = photoTemplate(item);
874
- feed_wrapper.html(feed_wrapper.html() + html);
875
 
876
- currentFeed.imageIndex++;
877
 
878
 
879
- //changing responsive indexes for pagination
880
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
881
- if ((i + 1) % currentFeed.feed_row.pagination_per_page_number === 0) {
882
- currentFeed.resIndex += currentFeed.freeSpaces + 1;
883
- } else {
884
- currentFeed.resIndex++;
885
- }
886
 
887
- }
888
 
889
- }
890
 
891
 
892
- //fixing last row in case of full caption is open
893
- //for that triggering click twice to open and close caption text that will fix last row
894
- /*ttt 1.1.12*/
895
- //jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_feed_wrapper [wdi_index=' + lastIndex + '] .wdi_photo_title').trigger(wdi_front.clickOrTouch);
896
- //jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_feed_wrapper [wdi_index=' + lastIndex + '] .wdi_photo_title').trigger(wdi_front.clickOrTouch);
897
 
898
 
899
- //binding onload event for ajax loader
900
- currentFeed.wdi_loadedImages = 0;
901
- var columnFlag = false;
902
- currentFeed.wdi_load_count = i;
903
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
904
- var feed_wrapper = jQuery('#wdi_feed_' + wdi_feed_counter + ' img.wdi_img').on('load', function ()
905
- {
906
- currentFeed.wdi_loadedImages++;
907
- checkLoaded();
908
 
909
- //calls wdi_responsive.columnControl() which calculates column number on page
910
- //and gives feed_wrapper proper column class
911
- if (columnFlag === false) {
912
 
913
 
914
- wdi_responsive.columnControl(currentFeed, 1);
915
- columnFlag = true;
916
- }
917
 
918
 
919
- // //Binds caption opening and closing event to each image photo_title/mmmmmm
920
- // if (currentFeed.feed_row.feed_type != 'blog_style') {
921
- // wdi_responsive.bindCaptionEvent(jQuery(this).parent().parent().parent().parent().find('.wdi_photo_title'), currentFeed);
922
- // }
923
- });
924
 
925
 
926
- /**
927
- * if feed type is not blog style then after displaying images assign click evetns to their captions
928
- * this part of code is a bit differenet from free version because of image lazy loading feature
929
- *
930
- * in free version events are assigned directly in onload event, but when lazy loading added it cased duplicate event fireing
931
- * so event assigning moved to here
932
- *
933
- */
934
- // if ( currentFeed.feed_row.feed_type != 'blog_style' ){
935
- // jQuery('#wdi_feed_'+currentFeed.feed_row.wdi_feed_counter+' .wdi_photo_title').each(function(){
936
- // wdi_responsive.bindCaptionEvent(jQuery(this),currentFeed);
937
- // });
938
 
939
- // }
940
 
941
 
942
- //checks if all iamges have been succesfully loaded then it updates variables for next time use
943
- function checkLoaded()
944
- {
945
- if (currentFeed.wdi_load_count === currentFeed.wdi_loadedImages && currentFeed.wdi_loadedImages != 0) {
946
- currentFeed.loadedImages = 0;
947
- currentFeed.wdi_load_count = 0;
948
- wdi_front.allImagesLoaded(currentFeed);
949
 
950
- }
951
- }
952
 
953
- //checking if pagination next button was clicked then change page
954
- if (currentFeed.paginatorNextFlag == true) {
955
- wdi_front.updatePagination(currentFeed, 'next');
956
- }
957
 
958
- //check if load more done successfully then set infinite scroll flag to false
959
- currentFeed.infiniteScrollFlag = false;
960
 
961
  }
962
 
963
  wdi_front.checkFeedFinished = function (currentFeed)
964
  {
965
- for (var i = 0; i < currentFeed.usersData.length; i++) {
966
- if (typeof currentFeed.usersData[i]['finished'] == 'undefined') {
967
- return false;
968
- }
969
- }
970
- return true;
971
  }
972
 
973
  wdi_front.sortingOperator = function (sortImagesBy, sortOrder)
974
  {
975
- var operator;
976
- switch (sortImagesBy) {
977
- case 'date':
978
- {
979
- switch (sortOrder) {
980
- case 'asc':
981
- {
982
- operator = function (a, b)
983
- {
984
- return (a['created_time'] > b['created_time']) ? 1 : -1;
985
- }
986
- break;
987
- }
988
- case 'desc':
989
- {
990
- operator = function (a, b)
991
- {
992
- return (a['created_time'] > b['created_time']) ? -1 : 1;
993
- }
994
- break;
995
- }
996
- }
997
- break;
998
- }
999
- case 'likes':
1000
- {
1001
- switch (sortOrder) {
1002
- case 'asc':
1003
- {
1004
- operator = function (a, b)
1005
- {
1006
- return (a['likes']['count'] < b['likes']['count']) ? -1 : 1;
1007
- }
1008
- break;
1009
- }
1010
- case 'desc':
1011
- {
1012
- operator = function (a, b)
1013
- {
1014
- return (a['likes']['count'] < b['likes']['count']) ? 1 : -1;
1015
- }
1016
- break;
1017
- }
1018
- }
1019
- break;
1020
- }
1021
- case 'comments':
1022
- {
1023
- switch (sortOrder) {
1024
- case 'asc':
1025
- {
1026
- operator = function (a, b)
1027
- {
1028
- return (a['comments']['count'] < b['comments']['count']) ? -1 : 1;
1029
- }
1030
- break;
1031
- }
1032
- case 'desc':
1033
- {
1034
- operator = function (a, b)
1035
- {
1036
- return (a['comments']['count'] < b['comments']['count']) ? 1 : -1;
1037
- }
1038
- break;
1039
- }
1040
- }
1041
- break;
1042
- }
1043
- case 'random':
1044
- {
1045
- operator = function (a, b)
1046
- {
1047
- var num = Math.random();
1048
- return (num > 0.5) ? 1 : -1;
1049
- }
1050
- break;
1051
- }
1052
- }
1053
- return operator;
1054
  }
1055
 
1056
  /*
@@ -1059,19 +1077,19 @@ wdi_front.sortingOperator = function (sortImagesBy, sortOrder)
1059
  wdi_front.feedSort = function (currentFeed, load_more_number)
1060
  {
1061
 
1062
- var sortImagesBy = currentFeed.feed_row['sort_images_by'];
1063
- var sortOrder = currentFeed.feed_row['display_order'];
1064
 
1065
- if (currentFeed.feed_row['resort_after_load_more'] === '1') {
1066
- currentFeed['data'] = currentFeed['data'].concat(wdi_front.smartPicker(currentFeed, load_more_number));
1067
- } else {
1068
- currentFeed['data'] = wdi_front.smartPicker(currentFeed, load_more_number);
1069
- }
1070
 
1071
 
1072
- var operator = wdi_front.sortingOperator(sortImagesBy, sortOrder);
1073
- currentFeed['data'].sort(operator);
1074
- return currentFeed['data'];
1075
 
1076
  }
1077
 
@@ -1082,155 +1100,155 @@ wdi_front.feedSort = function (currentFeed, load_more_number)
1082
  wdi_front.smartPicker = function (currentFeed, load_more_number)
1083
  {
1084
 
1085
- var dataStorage = [];
1086
- var dataLength = 0;
1087
- var readyData = [];
1088
- var perUser = Math.ceil(currentFeed['feed_row']['number_of_photos'] / currentFeed['usersData'].length);
1089
- var number_of_photos = parseInt(currentFeed['feed_row']['number_of_photos']);
1090
- var remainder = 0;
1091
 
1092
- //check if loadmore was clicked
1093
- if (load_more_number != '' && typeof load_more_number != 'undefined' && load_more_number != null) {
1094
- number_of_photos = parseInt(load_more_number);
1095
- perUser = Math.ceil(number_of_photos / wdi_front.activeUsersCount(currentFeed));
1096
- }
1097
 
1098
 
1099
- var sortOperator = function (a, b)
1100
- {
1101
- return (a['data'].length > b['data'].length) ? 1 : -1;
1102
- }
1103
 
1104
- var sortOperator1 = function (a, b)
1105
- {
1106
- return (a.length() > b.length()) ? 1 : -1;
1107
- }
1108
 
1109
 
1110
- // storing user data in global dataStoreageRaw variable
1111
- currentFeed.storeRawData(currentFeed.usersData, 'dataStorageRaw');
1112
 
1113
- //dataStorageRaw
1114
- var dataStorageRaw = currentFeed['dataStorageRaw'].sort(sortOperator1);
1115
 
1116
- //sorts user data desc
1117
- var usersData = currentFeed['usersData'].sort(sortOperator);
1118
 
1119
 
1120
- //picks data from users and updates pagination in request json
1121
- //for next time call
1122
- for (var i = 0; i < usersData.length; i++) {
1123
 
1124
- remainder += perUser;
1125
 
1126
- /* if data is less then amount for each user then pick all data */
1127
- if (dataStorageRaw[i].length() <= remainder) {
1128
 
1129
- /* update remainder */
1130
- remainder -= dataStorageRaw[i].length();
1131
 
1132
- /* get and store data */
1133
- dataStorage.push(dataStorageRaw[i].getData(dataStorageRaw[i].length()));
1134
- /* update data length */
1135
- dataLength += dataStorage[dataStorage.length - 1].length;
1136
 
1137
 
1138
- } else {
1139
- if (dataLength + remainder > number_of_photos) {
1140
- remainder = number_of_photos - dataLength;
1141
- }
1142
 
1143
- var pickedData = [];
1144
 
1145
 
1146
- if (currentFeed['auto_trigger'] === false) {
1147
- pickedData = pickedData.concat(dataStorageRaw[i].getData(remainder));
1148
- } else {
1149
- if (pickedData.length + wdi_front.getDataLength(currentFeed) + wdi_front.getDataLength(currentFeed, dataStorage) < currentFeed['feed_row']['number_of_photos']) {
1150
- pickedData = pickedData.concat(dataStorageRaw[i].getData(remainder));
1151
- }
1152
- }
1153
 
1154
- remainder = 0;
1155
 
1156
- dataLength += pickedData.length;
1157
- dataStorage.push(pickedData);
1158
 
1159
 
1160
- }
1161
 
1162
 
1163
- /*if (usersData[i]['data'].length <= remainder) {
1164
 
1165
- var pagination = usersData[i]['pagination']['next_url'];
1166
- if (usersData[i]['finished'] === undefined) {
1167
- dataStorage.push(usersData[i]['data']);
1168
- remainder -= usersData[i]['data'].length;
1169
- dataLength += usersData[i]['data'].length;
1170
- }
1171
 
1172
- if (usersData[i]['finished'] === undefined) {
1173
- if (pagination === undefined || pagination === '' || pagination === null) {
1174
- usersData[i]['finished'] = 'finished';
1175
- }
1176
- }
1177
- } else {
1178
- if ((dataLength + remainder) > number_of_photos) {
1179
- remainder = number_of_photos - dataLength;
1180
- }
1181
- var pickedData = [];
1182
- var indexPuller = 0;
1183
- for (var j = 0; j < remainder; j++) {
1184
- if (currentFeed['auto_trigger'] === false) {
1185
- if (usersData[i]['finished'] === undefined) {
1186
- pickedData.push(usersData[i]['data'][j]);
1187
- }
1188
- } else {
1189
- if (pickedData.length + wdi_front.getDataLength(currentFeed) + wdi_front.getDataLength(currentFeed, dataStorage) < currentFeed['feed_row']['number_of_photos']) {
1190
- if (usersData[i]['finished'] === undefined) {
1191
- pickedData.push(usersData[i]['data'][j]);
1192
- }
1193
- } else {
1194
- indexPuller++;
1195
- }
1196
- }
1197
 
1198
- }
1199
- j -= indexPuller;
1200
 
1201
- remainder = 0;
1202
 
1203
 
1204
 
1205
- //updating pagination
1206
 
1207
 
1208
 
1209
- //pushes picked data into local storage
1210
- dataLength += pickedData.length;
1211
- dataStorage.push(pickedData);
1212
 
1213
- }*/
1214
- }
1215
- //checks if in golbal storage user already exisit then it adds new data to user old data
1216
- //else it simple puches new user with it's data to global storage
1217
- for (i = 0; i < dataStorage.length; i++) {
1218
- if (typeof currentFeed.dataStorage[i] === 'undefined') {
1219
- currentFeed.dataStorage.push(dataStorage[i]);
1220
- } else {
1221
- currentFeed.dataStorage[i] = currentFeed.dataStorage[i].concat(dataStorage[i]);
1222
- }
1223
- }
1224
 
1225
- //parsing data for lightbox
1226
- currentFeed.parsedData = wdi_front.parseLighboxData(currentFeed);
1227
 
1228
- //combines together all avialable data in global storage and returns it
1229
- for (i = 0; i < dataStorage.length; i++) {
1230
- readyData = readyData.concat(dataStorage[i]);
1231
- }
1232
 
1233
- return readyData;
1234
  }
1235
 
1236
  /*
@@ -1239,55 +1257,59 @@ wdi_front.smartPicker = function (currentFeed, load_more_number)
1239
  wdi_front.createObject = function (obj, currentFeed)
1240
  {
1241
 
1242
- var caption = (obj['caption'] != null) ? obj['caption']['text'] : '&nbsp';
1243
-
1244
- var image_url = '';
1245
- var videoUrl = '';
1246
-
1247
- if (window.innerWidth >= currentFeed.feed_row.mobile_breakpoint) {
1248
- image_url = obj['images']['standard_resolution']['url'];
1249
- if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1250
- image_url = obj['link'] + 'media?size=l';
1251
- }
1252
- if (obj['type'] == 'video') {
1253
- videoUrl = obj['videos']['standard_resolution']['url'];
1254
- }
1255
- }
1256
- if (window.innerWidth >= currentFeed.feed_row.mobile_breakpoint/4 && window.innerWidth < currentFeed.feed_row.mobile_breakpoint) {
1257
- image_url = obj['images']['low_resolution']['url'];
1258
- if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1259
- image_url = obj['link'] + 'media?size=l';
1260
- }
1261
- if (obj['type'] == 'video') {
1262
- videoUrl = obj['videos']['low_bandwidth']['url'];
1263
- }
1264
- }
1265
- if (window.innerWidth < currentFeed.feed_row.mobile_breakpoint/4) {
1266
- image_url = obj['images']['thumbnail']['url'];
1267
- if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1268
- image_url = obj['link'] + 'media?size=m';
1269
- }
1270
- if (obj['type'] == 'video') {
1271
- videoUrl = obj['videos']['low_resolution']['url'];
1272
- }
1273
- }
1274
-
1275
-
1276
- var imageIndex = currentFeed.imageIndex;
1277
-
1278
- var photoObject = {
1279
- 'id': obj['id'],
1280
- 'caption': caption,
1281
- 'image_url': image_url,
1282
- 'likes': obj['likes']['count'],
1283
- 'comments': obj['comments']['count'],
1284
- 'wdi_index': imageIndex,
1285
- 'wdi_res_index': currentFeed.resIndex,
1286
- 'link': obj['link'],
1287
- 'video_url': videoUrl,
1288
- 'wdi_username': obj['user']['username']
1289
- };
1290
- return photoObject;
 
 
 
 
1291
  }
1292
 
1293
  /*
@@ -1295,22 +1317,22 @@ wdi_front.createObject = function (obj, currentFeed)
1295
  */
1296
  wdi_front.setPage = function (currentFeed)
1297
  {
1298
- var display_type = currentFeed.feed_row.feed_display_view;
1299
- var feed_type = currentFeed.feed_row.feed_type;
1300
- if (display_type != 'pagination') {
1301
- return '';
1302
- }
1303
- var imageIndex = currentFeed.imageIndex;
1304
- if (feed_type == 'image_browser') {
1305
- var divider = 1;
1306
- } else {
1307
- var divider = Math.abs(currentFeed.feed_row.pagination_per_page_number);
1308
- }
1309
 
1310
- currentFeed.paginator = Math.ceil((imageIndex + 1) / divider);
1311
 
1312
 
1313
- return currentFeed.paginator;
1314
  }
1315
 
1316
  /*
@@ -1318,117 +1340,225 @@ wdi_front.setPage = function (currentFeed)
1318
  */
1319
  wdi_front.getPhotoTemplate = function (currentFeed)
1320
  {
1321
- var page = wdi_front.setPage(currentFeed);
1322
- var customClass = '';
1323
- var pagination = '';
1324
- var onclick = '';
1325
- var overlayCustomClass = '';
1326
- var thumbClass = 'fa-arrows-alt';
1327
- var showUsernameOnThumb = '';
1328
- if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1329
- thumbClass = '';
1330
- }
1331
- if (page != '') {
1332
- pagination = 'wdi_page="' + page + '"';
1333
- sourceAttr = 'src';
1334
- } else {
1335
- sourceAttr = 'src';
1336
- }
1337
-
1338
- if (page != '' && page != 1) {
1339
- customClass = 'wdi_hidden';
1340
- }
1341
-
1342
-
1343
- if (currentFeed.feed_row.show_username_on_thumb == '1') {
1344
- showUsernameOnThumb = '<span class="wdi_media_user">@<%= wdi_username%></span>';
1345
- }
1346
-
1347
- //checking if caption is opend by default then add wdi_full_caption class
1348
- //only in masonry
1349
- if (currentFeed.feed_row.show_full_description == 1 && currentFeed.feed_row.feed_type == 'masonry') {
1350
- customClass += ' wdi_full_caption';
1351
- }
1352
-
1353
- var onclickevent = "";
1354
- if (currentFeed.feed_row.feed_type !== "blog_style") {
1355
- if (currentFeed.feed_row.feed_type == 'masonry') {
1356
- onclickevent = "wdi_responsive.showMasonryCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");"
1357
- } else {
1358
- onclickevent = "wdi_responsive.showCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");";
1359
- }
1360
-
1361
- }
1362
-
1363
-
1364
- //creating onclick string for different options
1365
- switch (currentFeed.feed_row.feed_item_onclick) {
1366
- case 'lightbox':
1367
- {
1368
- onclick = "onclick=wdi_feed_" + currentFeed.feed_row.wdi_feed_counter + ".galleryBox('<%=id%>')";
1369
- break;
1370
- }
1371
- case 'instagram':
1372
- {
1373
- onclick = 'onclick="window.open (\'<%= link%>\',\'_blank\')"';
1374
- overlayCustomClass = 'wdi_hover_off';
1375
- thumbClass = '';
1376
- break;
1377
- }
1378
- case 'none':
1379
- {
1380
- onclick = '';
1381
- overlayCustomClass = 'wdi_cursor_off wdi_hover_off';
1382
- thumbClass = '';
1383
- }
1384
- }
1385
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
1386
- var source = '<div class="wdi_feed_item ' + customClass + '" wdi_index=<%= wdi_index%> wdi_res_index=<%= wdi_res_index%> ' + pagination + ' wdi_type="image" id="wdi_' + wdi_feed_counter + '_<%=id%>">' +
1387
- '<div class="wdi_photo_wrap">' +
1388
- '<div class="wdi_photo_wrap_inner">' +
1389
- '<div class="wdi_photo_img">' +
1390
- '<img class="wdi_img" ' + sourceAttr + '="<%=image_url%>" alt="feed_image" onerror="wdi_front.brokenImageHandler(this);">' +
1391
- '<div class="wdi_photo_overlay ' + overlayCustomClass + '" >' + showUsernameOnThumb +
1392
- '<div class="wdi_thumb_icon" ' + onclick + ' style="display:table;width:100%;height:100%;">' +
1393
- '<div style="display:table-cell;vertical-align:middle;text-align:center;color:white;">' +
1394
- '<i class="fa ' + thumbClass + '"></i>' +
1395
- '</div>' +
1396
- '</div>' +
1397
- '</div>' +
1398
- '</div>' +
1399
- '</div>' +
1400
- '</div>';
1401
- if (currentFeed['feed_row']['show_likes'] === '1' || currentFeed['feed_row']['show_comments'] === '1' || currentFeed['feed_row']['show_description'] === '1') {
1402
- source += '<div class="wdi_photo_meta">';
1403
- if (currentFeed['feed_row']['show_likes'] === '1') {
1404
- source += '<div class="wdi_thumb_likes"><i class="fa fa-heart-o">&nbsp;<%= likes%></i></div>';
1405
- }
1406
- if (currentFeed['feed_row']['show_comments'] === '1') {
1407
- source += '<div class="wdi_thumb_comments"><i class="fa fa-comment-o">&nbsp;<%= comments%></i></div>';
1408
- }
1409
- source += '<div class="clear"></div>';
1410
- if (currentFeed['feed_row']['show_description'] === '1') {
1411
- source += '<div class="wdi_photo_title" onclick=' + onclickevent + ' >' +
1412
- '<%=caption%>' +
1413
- '</div>';
1414
- }
1415
- source += '</div>';
1416
- }
1417
-
1418
- source += '</div>';
1419
- var template = _.template(source);
1420
- return template;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1421
  }
1422
 
1423
  wdi_front.replaceToVideo = function (url, index, feed_counter)
1424
  {
1425
 
1426
- overlayHtml = "<video style='width:auto !important; height:auto !important; max-width:100% !important; max-height:100% !important; margin:0 !important;' controls=''>" +
1427
- "<source src='" + url + "' type='video/mp4'>" +
1428
- "Your browser does not support the video tag. </video>";
1429
 
1430
- jQuery('#wdi_feed_' + feed_counter + ' [wdi_index="' + index + '"] .wdi_photo_wrap_inner').html(overlayHtml);
1431
- jQuery('#wdi_feed_' + feed_counter + ' [wdi_index="' + index + '"] .wdi_photo_wrap_inner video').get(0).play();
1432
  }
1433
 
1434
  /*
@@ -1436,158 +1566,158 @@ wdi_front.replaceToVideo = function (url, index, feed_counter)
1436
  */
1437
  wdi_front.getVideoTemplate = function (currentFeed)
1438
  {
1439
- var page = wdi_front.setPage(currentFeed);
1440
- var customClass = '';
1441
- var pagination = '';
1442
- var thumbClass = 'fa-play';
1443
- var onclick = '';
1444
- var overlayCustomClass = '';
1445
- var sourceAttr;
1446
- var showUsernameOnThumb = '';
1447
-
1448
-
1449
- if (page != '') {
1450
- pagination = 'wdi_page="' + page + '"';
1451
- sourceAttr = 'src';
1452
- } else {
1453
- sourceAttr = 'src';
1454
- }
1455
- if (page != '' && page != 1) {
1456
- customClass = 'wdi_hidden';
1457
- }
1458
-
1459
- if (currentFeed.feed_row.show_username_on_thumb == '1') {
1460
- showUsernameOnThumb = '<span class="wdi_media_user">@<%= wdi_username%></span>';
1461
- }
1462
-
1463
- //checking if caption is opend by default then add wdi_full_caption class
1464
- //only in masonry
1465
- if (currentFeed.feed_row.show_full_description == 1 && currentFeed.feed_row.feed_type == 'masonry') {
1466
- customClass += ' wdi_full_caption';
1467
- }
1468
-
1469
- var onclickevent = "";
1470
- if (currentFeed.feed_row.feed_type !== "blog_style") {
1471
- if (currentFeed.feed_row.feed_type == 'masonry') {
1472
- onclickevent = "wdi_responsive.showMasonryCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");"
1473
- } else {
1474
- onclickevent = "wdi_responsive.showCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");";
1475
- }
1476
-
1477
- }
1478
-
1479
- //creating onclick string for different options
1480
- switch (currentFeed.feed_row.feed_item_onclick) {
1481
- case 'lightbox':
1482
- {
1483
- onclick = "onclick=wdi_feed_" + currentFeed.feed_row.wdi_feed_counter + ".galleryBox('<%=id%>')";
1484
- break;
1485
- }
1486
- case 'instagram':
1487
- {
1488
- onclick = 'onclick="window.open (\'<%= link%>\',\'_blank\')"';
1489
- overlayCustomClass = 'wdi_hover_off';
1490
- thumbClass = 'fa-play';
1491
- break;
1492
- }
1493
- case 'none':
1494
- {
1495
- overlayCustomClass = 'wdi_cursor_off wdi_hover_off';
1496
- thumbClass = '';
1497
- if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1498
- onclick = "onclick=wdi_front.replaceToVideo('<%= video_url%>','<%= wdi_index%>'," + currentFeed.feed_row.wdi_feed_counter + ")";
1499
- overlayCustomClass = '';
1500
- thumbClass = 'fa-play';
1501
- }
1502
- }
1503
- }
1504
-
1505
-
1506
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
1507
- var source = '<div class="wdi_feed_item ' + customClass + '" wdi_index=<%= wdi_index%> wdi_res_index=<%= wdi_res_index%> ' + pagination + ' wdi_type="image" id="wdi_' + wdi_feed_counter + '_<%=id%>">' +
1508
- '<div class="wdi_photo_wrap">' +
1509
- '<div class="wdi_photo_wrap_inner">' +
1510
- '<div class="wdi_photo_img">' +
1511
- '<img class="wdi_img" ' + sourceAttr + '="<%=image_url%>" alt="feed_image" onerror="wdi_front.brokenImageHandler(this);">' +
1512
- '<div class="wdi_photo_overlay ' + overlayCustomClass + '" ' + onclick + '>' + showUsernameOnThumb +
1513
- '<div class="wdi_thumb_icon" style="display:table;width:100%;height:100%;">' +
1514
- '<div style="display:table-cell;vertical-align:middle;text-align:center;color:white;">' +
1515
- '<i class="fa ' + thumbClass + '"></i>' +
1516
- '</div>' +
1517
- '</div>' +
1518
- '</div>' +
1519
- '</div>' +
1520
- '</div>' +
1521
- '</div>';
1522
- if (currentFeed['feed_row']['show_likes'] === '1' || currentFeed['feed_row']['show_comments'] === '1' || currentFeed['feed_row']['show_description'] === '1') {
1523
- source += '<div class="wdi_photo_meta">';
1524
- if (currentFeed['feed_row']['show_likes'] === '1') {
1525
- source += '<div class="wdi_thumb_likes"><i class="fa fa-heart-o">&nbsp;<%= likes%></i></div>';
1526
- }
1527
- if (currentFeed['feed_row']['show_comments'] === '1') {
1528
- source += '<div class="wdi_thumb_comments"><i class="fa fa-comment-o">&nbsp;<%= comments%></i></div>';
1529
- }
1530
- source += '<div class="clear"></div>';
1531
- if (currentFeed['feed_row']['show_description'] === '1') {
1532
- source += '<div class="wdi_photo_title" onclick=' + onclickevent + ' >' +
1533
- '<%=caption%>' +
1534
- '</div>';
1535
- }
1536
- source += '</div>';
1537
- }
1538
- source += '</div>';
1539
- var template = _.template(source);
1540
- return template;
1541
  }
1542
 
1543
  wdi_front.bindEvents = function (currentFeed)
1544
  {
1545
 
1546
- if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + " .wdi_feed_wrapper").length == 0) {
1547
- //no feed in DOM, ignore
1548
- return;
1549
- }
1550
-
1551
- if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
1552
- //binding load more event
1553
- jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_load_more_container').on(wdi_front.clickOrTouch, function ()
1554
- {
1555
- //do the actual load more operation
1556
- wdi_front.loadMore(jQuery(this).find('.wdi_load_more_wrap'));
1557
-
1558
- });
1559
- }
1560
-
1561
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
1562
- //binding pagination events
1563
- jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_next').on(wdi_front.clickOrTouch, function ()
1564
- {
1565
- wdi_front.paginatorNext(jQuery(this), currentFeed);
1566
- });
1567
- jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_prev').on(wdi_front.clickOrTouch, function ()
1568
- {
1569
- wdi_front.paginatorPrev(jQuery(this), currentFeed);
1570
- });
1571
- jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_last_page').on(wdi_front.clickOrTouch, function ()
1572
- {
1573
- wdi_front.paginationLastPage(jQuery(this), currentFeed);
1574
- });
1575
- jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_first_page').on(wdi_front.clickOrTouch, function ()
1576
- {
1577
- wdi_front.paginationFirstPage(jQuery(this), currentFeed);
1578
- });
1579
- //setting pagiantion flags
1580
- currentFeed.paginatorNextFlag = false;
1581
- }
1582
- if (currentFeed.feed_row.feed_display_view == 'infinite_scroll') {
1583
- //binding infinite scroll Events
1584
- jQuery(window).on('scroll', function ()
1585
- {
1586
- wdi_front.infiniteScroll(currentFeed);
1587
- });
1588
- //infinite scroll flags
1589
- currentFeed.infiniteScrollFlag = false;
1590
- }
1591
 
1592
 
1593
  }
@@ -1595,152 +1725,152 @@ wdi_front.bindEvents = function (currentFeed)
1595
  wdi_front.infiniteScroll = function (currentFeed)
1596
  {
1597
 
1598
- if (jQuery(window).scrollTop() <= jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_infinite_scroll').offset().top) {
1599
- if (currentFeed.infiniteScrollFlag === false && currentFeed.stopInfiniteScrollFlag == false) {
1600
- currentFeed.infiniteScrollFlag = true;
1601
- wdi_front.loadMore(jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_infinite_scroll'), currentFeed);
1602
- } else
1603
- if (currentFeed.stopInfiniteScrollFlag) {
1604
- wdi_front.allImagesLoaded(currentFeed);
1605
- }
1606
 
1607
- }
1608
  }
1609
 
1610
 
1611
  wdi_front.paginationFirstPage = function (btn, currentFeed)
1612
  {
1613
- if (currentFeed.paginator == 1 || currentFeed.currentPage == 1) {
1614
- btn.addClass('wdi_disabled');
1615
- return;
1616
- }
1617
- var oldPage = currentFeed.currentPage;
1618
- currentFeed.currentPage = 1;
1619
- wdi_front.updatePagination(currentFeed, 'custom', oldPage);
1620
 
1621
- //enable last page button
1622
- var last_page_btn = btn.parent().find('#wdi_last_page');
1623
- last_page_btn.removeClass('wdi_disabled');
1624
 
1625
- //disabling first page button
1626
- btn.addClass('wdi_disabled');
1627
 
1628
  }
1629
 
1630
  wdi_front.paginationLastPage = function (btn, currentFeed)
1631
  {
1632
- if (currentFeed.paginator == 1 || currentFeed.currentPage == currentFeed.paginator) {
1633
- return;
1634
- }
1635
- var oldPage = currentFeed.currentPage;
1636
- currentFeed.currentPage = currentFeed.paginator;
1637
- wdi_front.updatePagination(currentFeed, 'custom', oldPage);
1638
 
1639
- //disableing last page button
1640
- btn.addClass('wdi_disabled');
1641
 
1642
- //enabling first page button
1643
- var first_page_btn = btn.parent().find('#wdi_first_page');
1644
- first_page_btn.removeClass('wdi_disabled');
1645
  }
1646
 
1647
  wdi_front.paginatorNext = function (btn, currentFeed)
1648
  {
1649
- var last_page_btn = btn.parent().find('#wdi_last_page');
1650
- var first_page_btn = btn.parent().find('#wdi_first_page');
1651
- currentFeed.paginatorNextFlag = true;
1652
- if (currentFeed.paginator == currentFeed.currentPage && !wdi_front.checkFeedFinished(currentFeed)) {
1653
- currentFeed.currentPage++;
1654
- var number_of_photos = currentFeed.feed_row.number_of_photos;
1655
- wdi_front.loadMore(btn, currentFeed, number_of_photos);
1656
- //on the last page don't show got to last page button
1657
- last_page_btn.addClass('wdi_disabled');
1658
- } else
1659
- if (currentFeed.paginator > currentFeed.currentPage) {
1660
- currentFeed.currentPage++;
1661
- wdi_front.updatePagination(currentFeed, 'next');
1662
- //check if new page isn't the last one then enable last page button
1663
- if (currentFeed.paginator > currentFeed.currentPage) {
1664
- last_page_btn.removeClass('wdi_disabled');
1665
- } else {
1666
- last_page_btn.addClass('wdi_disabled');
1667
- }
1668
- }
1669
-
1670
- //enable first page button
1671
- first_page_btn.removeClass('wdi_disabled');
1672
 
1673
 
1674
  }
1675
 
1676
  wdi_front.paginatorPrev = function (btn, currentFeed)
1677
  {
1678
- var last_page_btn = btn.parent().find('#wdi_last_page');
1679
- var first_page_btn = btn.parent().find('#wdi_first_page');
1680
- if (currentFeed.currentPage == 1) {
1681
- first_page_btn.addClass('wdi_disabled');
1682
- return;
1683
- }
1684
 
1685
- currentFeed.currentPage--;
1686
- wdi_front.updatePagination(currentFeed, 'prev');
1687
 
1688
- //enable last page button
1689
- last_page_btn.removeClass('wdi_disabled');
1690
 
1691
- if (currentFeed.currentPage == 1) {
1692
- first_page_btn.addClass('wdi_disabled');
1693
- }
1694
 
1695
  }
1696
 
1697
  //displays proper images for specific page after pagination buttons click event
1698
  wdi_front.updatePagination = function (currentFeed, dir, oldPage)
1699
  {
1700
- var currentFeedString = '#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'];
1701
- jQuery(currentFeedString + ' [wdi_page="' + currentFeed.currentPage + '"]').each(function ()
1702
- {
1703
- jQuery(this).removeClass('wdi_hidden');
1704
- });
1705
- switch (dir) {
1706
- case 'next':
1707
- {
1708
- var oldPage = currentFeed.currentPage - 1;
1709
- jQuery(currentFeedString + ' .wdi_feed_wrapper').height(jQuery('.wdi_feed_wrapper').height());
1710
- jQuery(currentFeedString + ' [wdi_page="' + oldPage + '"]').each(function ()
1711
- {
1712
- jQuery(this).addClass('wdi_hidden');
1713
- });
1714
- break;
1715
- }
1716
- case 'prev':
1717
- {
1718
- var oldPage = currentFeed.currentPage + 1;
1719
- jQuery(currentFeedString + ' .wdi_feed_wrapper').height(jQuery('.wdi_feed_wrapper').height());
1720
- jQuery(currentFeedString + ' [wdi_page="' + oldPage + '"]').each(function ()
1721
- {
1722
- jQuery(this).addClass('wdi_hidden');
1723
- });
1724
- break;
1725
- }
1726
- case 'custom':
1727
- {
1728
- var oldPage = oldPage;
1729
- if (oldPage != currentFeed.currentPage) {
1730
- jQuery(currentFeedString + ' .wdi_feed_wrapper').height(jQuery('.wdi_feed_wrapper').height());
1731
- jQuery(currentFeedString + ' [wdi_page="' + oldPage + '"]').each(function ()
1732
- {
1733
- jQuery(this).addClass('wdi_hidden');
1734
- });
1735
- }
1736
-
1737
- break;
1738
- }
1739
- }
1740
- currentFeed.paginatorNextFlag = false;
1741
-
1742
- jQuery(currentFeedString + ' .wdi_feed_wrapper').css('height', 'auto');
1743
- jQuery(currentFeedString + ' #wdi_current_page').text(currentFeed.currentPage);
1744
  }
1745
 
1746
 
@@ -1748,94 +1878,94 @@ wdi_front.loadMore = function (button, _currentFeed)
1748
  {
1749
 
1750
 
1751
- var dataCounter = 0;
1752
- if (button != '' && typeof button != 'undefined' && button != 'initial' && button != 'initial-keep') {
1753
- var currentFeed = window[button.parent().parent().parent().parent().attr('id')];
1754
- }
1755
- if (typeof _currentFeed != 'undefined') {
1756
- var currentFeed = _currentFeed;
1757
- }
1758
- //check if any filter is enabled and filter user images has finished
1759
- //then stop any load more action
1760
- var activeFilter = 0,
1761
- finishedFilter = 0;
1762
- for (var i = 0; i < currentFeed.userSortFlags.length; i++) {
1763
- if (currentFeed.userSortFlags[i].flag === true) {
1764
- activeFilter++;
1765
- for (var j = 0; j < currentFeed.usersData.length; j++) {
1766
- if (currentFeed.userSortFlags[i]['id'] === currentFeed.usersData[j]['user_id']) {
1767
- if (currentFeed.usersData[j]['finished'] === 'finished') {
1768
- finishedFilter++;
1769
- }
1770
- }
1771
- }
1772
- }
1773
- }
1774
- if (activeFilter === finishedFilter && activeFilter != 0) {
1775
- return;
1776
- }
1777
-
1778
-
1779
- //if button is not provided than it enables auto_tiggering and recursively loads images
1780
- if (button === '') {
1781
- currentFeed['auto_trigger'] = true;
1782
- } else {
1783
- currentFeed['auto_trigger'] = false;
1784
- }
1785
- //ading ajax loading
1786
- wdi_front.ajaxLoader(currentFeed);
1787
-
1788
-
1789
- //check if masonry view is on and and feed display type is pagination then
1790
- //close all captions before loading more pages for porper pagination rendering
1791
- if (currentFeed.feed_row.feed_type === 'masonry' && currentFeed.feed_row.feed_display_view == 'pagination') {
1792
- jQuery('#wdi_feed_' + wdi_front.feed_counter + ' .wdi_full_caption').each(function ()
1793
- {
1794
- jQuery(this).find('.wdi_photo_title').trigger(wdi_front.clickOrTouch);
1795
- });
1796
- }
1797
-
1798
-
1799
- //check if all data loaded then remove ajaxLoader
1800
- for (var i = 0; i < currentFeed.usersData.length; i++) {
1801
- if (currentFeed.usersData[i]['finished'] === 'finished') {
1802
- dataCounter++;
1803
- }
1804
- }
1805
- if (dataCounter === currentFeed.usersData.length) {
1806
- wdi_front.allImagesLoaded(currentFeed);
1807
- jQuery('#wdi_feed_' + currentFeed['feed_row']['wdi_feed_counter'] + ' .wdi_load_more').remove();
1808
-
1809
- }
1810
-
1811
- var usersData = currentFeed['usersData'];
1812
-
1813
- currentFeed.loadMoreDataCount = currentFeed.feed_users.length;
1814
-
1815
- for (var i = 0; i < usersData.length; i++) {
1816
-
1817
- var pagination = usersData[i]['pagination'];
1818
- var user = {
1819
- user_id: usersData[i]['user_id'],
1820
- username: usersData[i]['username']
1821
- }
1822
-
1823
- //checking if pagination url exists then load images, else skip
1824
- if (pagination['next_url'] != '' && pagination['next_url'] != null && typeof pagination['next_url'] != 'undefined') {
1825
- var next_url = pagination['next_url'];
1826
- wdi_front.loadMoreRequest(user, next_url, currentFeed, button);
1827
- } else {
1828
-
1829
- if (button == 'initial-keep') {
1830
- currentFeed.temproraryUsersData[i] = currentFeed.usersData[i];
1831
- }
1832
- currentFeed.loadMoreDataCount--;
1833
-
1834
-
1835
- wdi_front.checkForLoadMoreDone(currentFeed, button);
1836
- continue;
1837
- }
1838
- }
1839
 
1840
 
1841
  }
@@ -1846,136 +1976,136 @@ wdi_front.loadMore = function (button, _currentFeed)
1846
  wdi_front.loadMoreRequest = function (user, next_url, currentFeed, button)
1847
  {
1848
 
1849
- var usersData = currentFeed['usersData'];
1850
- var errorMessage = '';
1851
-
1852
- currentFeed.instagram.requestByUrl(next_url, {
1853
- success: function (response)
1854
- {
1855
- if (response === '' || typeof response == 'undefined' || response == null) {
1856
- errorMessage = wdi_front_messages.network_error;
1857
- currentFeed.loadMoreDataCount--;
1858
- alert(errorMessage);
1859
- return;
1860
- }
1861
- if (response['meta']['code'] != 200) {
1862
- errorMessage = response['meta']['error_message'];
1863
- currentFeed.loadMoreDataCount--;
1864
- alert(errorMessage);
1865
- return;
1866
- }
1867
-
1868
- response['user_id'] = user.user_id;
1869
- response['username'] = user.username;
1870
-
1871
- for (var i = 0; i < currentFeed['usersData'].length; i++) {
1872
- if (response['user_id'] === currentFeed['usersData'][i]['user_id']) {
1873
-
1874
- ///mmm!!!
1875
- if (response['user_id'][0] === '#') {
1876
- response['data'] = wdi_front.appendRequestHashtag(response['data'], response['user_id']);
1877
- }
1878
- ////////////////
1879
- /*if button is initial-keep then we will lose currentFeed['usersData'][i]
1880
- for not loosing it we keep it in currentFeed.temproraryUsersData, which value will be
1881
- used later in wdi_front.checkForLoadMoreDone(), in other cases when button is set to
1882
- initial we already keep data in that variable, so we don't deed to keep it again, it will give us duplicate value
1883
- */
1884
-
1885
- if (button == 'initial-keep') {
1886
- currentFeed.temproraryUsersData[i] = currentFeed.usersData[i];
1887
- }
1888
- currentFeed['usersData'][i] = response;
1889
-
1890
- currentFeed.loadMoreDataCount--;
1891
- }
1892
- }
1893
-
1894
- //checks if load more done then displays feed
1895
- wdi_front.checkForLoadMoreDone(currentFeed, button);
1896
- }
1897
- })
1898
 
1899
  }
1900
 
1901
  wdi_front.checkForLoadMoreDone = function (currentFeed, button)
1902
  {
1903
- var load_more_number = currentFeed.feed_row['load_more_number'];
1904
- var number_of_photos = currentFeed.feed_row['number_of_photos'];
1905
 
1906
- if (currentFeed.loadMoreDataCount == 0) {
1907
 
1908
- currentFeed.temproraryUsersData = wdi_front.mergeData(currentFeed.temproraryUsersData, currentFeed.usersData);
1909
- var gettedDataLength = wdi_front.getArrayContentLength(currentFeed.temproraryUsersData, 'data');
1910
- /*this will happen when we call loadMore first time
1911
- initial-keep is the same as initial except that if loadMore is called
1912
- with initial-keep we store data on currentFeed.temproraryUsersData before checkLoadMoreDone()
1913
- function call*/
1914
- if (button == 'initial-keep') {
1915
- button = 'initial';
1916
- }
1917
- //if button is set to inital load number_of_photos photos
1918
- if (button == 'initial') {
1919
 
1920
- /*if existing data length is smaller then load_more_number then get more objects until desired number is reached
1921
- also if it is not possible to reach the desired number (this will happen when all users has no more photos) then
1922
- displayFeed()*/
1923
- if (gettedDataLength < number_of_photos && !wdi_front.userHasNoPhoto(currentFeed, currentFeed.temproraryUsersData) && currentFeed.instagramRequestCounter <= currentFeed.maxConditionalFiltersRequestCount) {
1924
- //console.log('checkForLoadMoreDone recursion');
1925
 
1926
- wdi_front.loadMore('initial', currentFeed);
1927
- } else {
1928
 
1929
- currentFeed.usersData = currentFeed.temproraryUsersData;
1930
 
1931
- wdi_front.displayFeed(currentFeed);
1932
- //when all data us properly displayed check for any active filters and then apply them
1933
- wdi_front.applyFilters(currentFeed);
1934
 
1935
- //resetting temprorary users data array for the next loadmoer call
1936
- currentFeed.temproraryUsersData = [];
1937
 
1938
 
1939
- }
1940
 
1941
- } else {
1942
- //else load load_more_number photos
1943
- //if existing data length is smaller then load_more_number then get more objects until desired number is reached
1944
 
1945
- if (gettedDataLength < load_more_number && !wdi_front.userHasNoPhoto(currentFeed, currentFeed.temproraryUsersData) && currentFeed.instagramRequestCounter <= currentFeed.maxConditionalFiltersRequestCount) {
1946
- //console.log('load more recursion');
1947
- wdi_front.loadMore(undefined, currentFeed);
1948
- } else {
1949
 
1950
- currentFeed.usersData = currentFeed.temproraryUsersData;
1951
 
1952
- if (!wdi_front.activeUsersCount(currentFeed)) {
1953
- return;
1954
- }
1955
 
1956
- wdi_front.displayFeed(currentFeed, load_more_number);
1957
- //when all data us properly displayed check for any active filters and then apply them
1958
- wdi_front.applyFilters(currentFeed);
1959
 
1960
- //resetting temprorary users data array for the next loadmoer call
1961
- currentFeed.temproraryUsersData = [];
1962
- }
1963
- }
1964
 
1965
 
1966
- }
1967
  }
1968
 
1969
  wdi_front.allDataHasFinished = function (currentFeed)
1970
  {
1971
- var c = 0;
1972
- for (var j = 0; j < currentFeed.dataStorageRaw.length; j++) {
1973
- if (currentFeed.dataStorageRaw[j].length() == 0 && currentFeed.dataStorageRaw[j].locked == true) {
1974
- c++;
1975
- }
1976
- }
1977
 
1978
- return (c == currentFeed.dataStorageRaw.length);
1979
  }
1980
 
1981
 
@@ -1983,37 +2113,37 @@ wdi_front.mergeData = function (array1, array2)
1983
  {
1984
 
1985
 
1986
- for (var i = 0; i < array2.length; i++) {
1987
- if (typeof array1[i] != 'undefined') {
1988
- if (array2[i]['finished'] == 'finished') {
1989
- continue;
1990
- }
1991
 
1992
- //if user data is finished then dont add duplicate data
1993
- if (typeof array1[i]['pagination']['next_max_id'] == 'undefined' &&
1994
- typeof array1[i]['pagination']['next_max_like_id'] == 'undefined') {
1995
- continue;
1996
- }
1997
- //extend data
1998
- array1[i]['data'] = array1[i]['data'].concat(array2[i]['data']);
1999
- array1[i]['pagination'] = array2[i]['pagination'];
2000
- array1[i]['user_id'] = array2[i]['user_id'];
2001
- array1[i]['username'] = array2[i]['username'];
2002
- array1[i]['meta'] = array2[i]['meta'];
2003
- } else {
2004
- array1.push(array2[i]);
2005
- }
2006
- }
2007
- return array1;
2008
  }
2009
 
2010
 
2011
  //broken image handling
2012
  wdi_front.brokenImageHandler = function (source)
2013
  {
2014
- source.src = wdi_url.plugin_url + "../images/missing.png";
2015
- source.onerror = "";
2016
- return true;
2017
 
2018
  }
2019
 
@@ -2021,57 +2151,61 @@ wdi_front.brokenImageHandler = function (source)
2021
  //ajax loading
2022
  wdi_front.ajaxLoader = function (currentFeed)
2023
  {
2024
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
2025
 
2026
- var feed_container = jQuery('#wdi_feed_' + wdi_feed_counter);
2027
- if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
2028
- feed_container.find('.wdi_load_more').addClass('wdi_hidden');
2029
- feed_container.find('.wdi_spinner').removeClass('wdi_hidden');
2030
- }
2031
- /////////////////////////////////////////////////////
2032
- if (currentFeed.feed_row.feed_display_view == 'infinite_scroll') {
2033
- var loadingDiv;
2034
- if (feed_container.find('.wdi_ajax_loading').length == 0) {
2035
- loadingDiv = jQuery('<div class="wdi_ajax_loading"><div><div><img class="wdi_load_more_spinner" src="' + wdi_url.plugin_url + '../images/ajax_loader.png"></div></div></div>');
2036
- feed_container.append(loadingDiv);
2037
- } else {
2038
- loadingDiv = feed_container.find('.wdi_ajax_loading');
2039
- }
2040
- loadingDiv.removeClass('wdi_hidden');
2041
- }
2042
 
2043
 
2044
- ////////////////////////////////////////////////////
2045
 
2046
  }
2047
 
2048
  //if all images loaded then clicking load more causes it's removal
2049
  wdi_front.allImagesLoaded = function (currentFeed)
2050
  {
2051
- ////////////////////////////////////////////////////////////////////
2052
-
2053
- //clearInterval(currentFeed.loadingInterval);
2054
- //jQuery('#wdi_feed_'+currentFeed.feed_row['wdi_feed_counter']+' .wdi_ajax_loading').remove();
2055
 
2056
- ////////////////////////////////////////////////////
2057
 
 
 
 
 
 
2058
 
2059
- //if all images loaded then enable load more button and hide spinner
2060
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
2061
- var feed_container = jQuery('#wdi_feed_' + wdi_feed_counter);
2062
 
2063
- if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
2064
- feed_container.find('.wdi_load_more').removeClass('wdi_hidden');
2065
- feed_container.find('.wdi_spinner').addClass('wdi_hidden');
2066
- }
2067
 
2068
- if (currentFeed.feed_row.feed_display_view == 'infinite_scroll') {
2069
- jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_ajax_loading').addClass('wdi_hidden');
2070
- }
2071
 
2072
 
2073
- //custom event fired for user based custom js
2074
- feed_container.trigger('wdi_feed_loaded');
2075
 
2076
 
2077
  }
@@ -2080,190 +2214,190 @@ wdi_front.allImagesLoaded = function (currentFeed)
2080
  //shows different parts of the feed based user choice
2081
  wdi_front.show = function (name, currentFeed)
2082
  {
2083
- var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
2084
- var feed_container = jQuery('#wdi_feed_' + wdi_feed_counter + ' .wdi_feed_container');
2085
- var _this = this;
2086
- switch (name) {
2087
- case 'header':
2088
- {
2089
- show_header();
2090
- break;
2091
- }
2092
- case 'users':
2093
- {
2094
- show_users(currentFeed);
2095
- break;
2096
- }
2097
-
2098
- }
2099
-
2100
- function show_header()
2101
- {
2102
-
2103
- var templateData = {
2104
- 'feed_thumb': currentFeed['feed_row']['feed_thumb'],
2105
- 'feed_name': currentFeed['feed_row']['feed_name'],
2106
- };
2107
-
2108
- var headerTemplate = wdi_front.getHeaderTemplate(),
2109
- html = headerTemplate(templateData),
2110
- containerHtml = feed_container.find('.wdi_feed_header').html();
2111
-
2112
- feed_container.find('.wdi_feed_header').html(containerHtml + html);
2113
-
2114
-
2115
- }
2116
-
2117
- function show_users(currentFeed)
2118
- {
2119
- feed_container.find('.wdi_feed_users').html('');
2120
- var users = currentFeed['feed_users'];
2121
- var access_token = currentFeed['feed_row']['access_token'];
2122
- var i = 0;
2123
- currentFeed.headerUserinfo = [];
2124
- getThumb();
2125
- //recursively calls itself until all user data is ready then displyes it with escapeRequest
2126
- function getThumb()
2127
- {
2128
-
2129
- if (currentFeed.headerUserinfo.length == users.length) {
2130
- escapeRequest(currentFeed.headerUserinfo, currentFeed);
2131
- return;
2132
- }
2133
- var _user = users[currentFeed.headerUserinfo.length];
2134
-
2135
-
2136
- if (typeof _user === 'string' && _user === 'self') {
2137
- currentFeed.instagram.getSelfInfo({
2138
- success: function (response)
2139
- {
2140
- response = _this.checkMediaResponse(response);
2141
- if (response != false) {
2142
- var obj = {
2143
- id: response['data']['id'],
2144
- name: response['data']['username'],
2145
- url: response['data']['profile_picture'],
2146
- bio: response['data']['bio'],
2147
- counts: response['data']['counts'],
2148
- website: response['data']['website'],
2149
- full_name: response['data']['full_name']
2150
- }
2151
- currentFeed.headerUserinfo.push(obj);
2152
- i++;
2153
- getThumb();
2154
- }
2155
- },
2156
- args: {
2157
- ignoreFiltering: true,
2158
- }
2159
- });
2160
- }
2161
- else
2162
- if (_this.getInputType(_user.username) == 'hashtag') {
2163
- currentFeed.instagram.searchForTagsByName(_this.stripHashtag(_user.username), {
2164
- /*currentFeed.instagram.getTagRecentMedia(_this.stripHashtag(_user.username), {*/
2165
- success: function (response)
2166
- {
2167
- response = _this.checkMediaResponse(response);
2168
- if (response != false) {
2169
- if (response['data'].length == 0) {
2170
- var thumb_img = '';
2171
- var counts = {media:''};
2172
- } else {
2173
- var thumb_img = '';// we will get image src later when will have all the sources
2174
- //thumb_img = response['data'][0]['images']['thumbnail']['url'];
2175
- var counts = {media: response['data'][0]['media_count']};
2176
- }
2177
-
2178
- var obj = {
2179
- name: users[i]['username'],
2180
- url: thumb_img,
2181
- counts: counts,
2182
- };
2183
- i++;
2184
- currentFeed.headerUserinfo.push(obj);
2185
- getThumb();
2186
- }
2187
- },
2188
- args: {
2189
- ignoreFiltering: true,
2190
- }
2191
- });
2192
- }
2193
- else
2194
- if (_this.getInputType(_user.username) == 'user') {
2195
- currentFeed.instagram.getUserInfo(_user.id, {
2196
- success: function (response)
2197
- {
2198
- response = _this.checkMediaResponse(response);
2199
- if (response != false) {
2200
- var obj = {
2201
- id: response['data']['id'],
2202
- name: response['data']['username'],
2203
- url: response['data']['profile_picture'],
2204
- bio: response['data']['bio'],
2205
- counts: response['data']['counts'],
2206
- website: response['data']['website'],
2207
- full_name: response['data']['full_name']
2208
- }
2209
- currentFeed.headerUserinfo.push(obj);
2210
- i++;
2211
- getThumb();
2212
- }
2213
- },
2214
- args: {
2215
- ignoreFiltering: true,
2216
- }
2217
- });
2218
- }
2219
-
2220
- }
2221
-
2222
- //when all user data is ready break recursion and create user elements
2223
- function escapeRequest(info, currentFeed)
2224
- {
2225
- feed_container.find('.wdi_feed_users').html('');
2226
- for (var k = 0; k < info.length; k++) {
2227
- //setting all user filters to false
2228
-
2229
- var userFilter = {
2230
- 'flag': false,
2231
- 'id': info[k]['id'],
2232
- 'name': info[k]['name']
2233
- };
2234
-
2235
-
2236
- //user inforamtion
2237
- var hashtagClass = (info[k]['name'][0] == '#') ? 'wdi_header_hashtag' : '';
2238
-
2239
- var templateData = {
2240
- 'user_index': k,
2241
- 'user_img_url': info[k]['url'],
2242
- 'counts': info[k]["counts"],
2243
- 'feed_counter': currentFeed.feed_row.wdi_feed_counter,
2244
- 'user_name': info[k]['name'],
2245
- 'bio': info[k]['bio'],
2246
- 'usersCount': currentFeed.feed_row.feed_users.length,
2247
- 'hashtagClass': hashtagClass
2248
-
2249
- };
2250
-
2251
- var userTemplate = wdi_front.getUserTemplate(currentFeed, info[k]['name']),
2252
- html = userTemplate(templateData),
2253
- containerHtml = feed_container.find('.wdi_feed_users').html();
2254
-
2255
- feed_container.find('.wdi_feed_users').html(containerHtml + html);
2256
-
2257
-
2258
- currentFeed.userSortFlags.push(userFilter);
2259
-
2260
- var clearFloat = jQuery('<div class="clear"></div>');
2261
-
2262
- }
2263
- feed_container.find('.wdi_feed_users').append(clearFloat);
2264
- wdi_front.updateUsersImages(currentFeed);
2265
- };
2266
- }
2267
 
2268
  }
2269
 
@@ -2271,316 +2405,323 @@ wdi_front.show = function (name, currentFeed)
2271
  wdi_front.getUserTemplate = function (currentFeed, username)
2272
  {
2273
 
2274
- var usersCount = currentFeed.dataCount,
2275
- instagramLink, instagramLinkOnClick, js;
2276
-
2277
- switch (username[0]) {
2278
- case '#':
2279
- {
2280
- instagramLink = '//instagram.com/explore/tags/' + username.substr(1, username.length);
2281
- break;
2282
- }
2283
- default:
2284
- {
2285
- instagramLink = '//instagram.com/' + username;
2286
- break;
2287
- }
2288
- }
2289
- js = 'window.open("' + instagramLink + '","_blank")';
2290
- instagramLinkOnClick = "onclick='" + js + "'";
2291
-
2292
- var source = '<div class="wdi_single_user" user_index="<%=user_index%>">' +
2293
- '<div class="wdi_header_user_text <%=hashtagClass%>">' +
2294
-
2295
- '<div class="wdi_user_img_wrap">' +
2296
- '<img onerror="wdi_front.brokenImageHandler(this);" src="<%= user_img_url%>">';
2297
- if (usersCount > 1) {
2298
- source += '<div title="' + wdi_front_messages.filter_title + '" class="wdi_filter_overlay">' +
2299
- '<div class="wdi_filter_icon">' +
2300
- '<span onclick="wdi_front.addFilter(<%=user_index%>,<%=feed_counter%>);" class="fa fa-filter"></span>' +
2301
- '</div>' +
2302
- '</div>';
2303
- }
2304
- source += '</div>';
2305
- source += '<h3 ' + instagramLinkOnClick + '><%= user_name%></h3>';
2306
-
2307
- if (username[0] !== '#') {
2308
- if (currentFeed.feed_row.follow_on_instagram_btn == '1') {
2309
- source += '<div class="wdi_user_controls">' +
2310
- '<div class="wdi_follow_btn" onclick="window.open(\'//instagram.com/<%= user_name%>\',\'_blank\')"><span> Follow</span></div>' +
2311
- '</div>';
2312
- }
2313
- source += '<div class="wdi_media_info">' +
2314
- '<p class="wdi_posts"><span class="fa fa-camera-retro"><%= counts.media%></span></p>' +
2315
- '<p class="wdi_followers"><span class="fa fa-user"><%= counts.followed_by%></span></p>' +
2316
- '</div>';
2317
- } else {
2318
- source += '<div class="wdi_user_controls">' +
2319
- '</div>' +
2320
- '<div class="wdi_media_info">' +
2321
- '<p class="wdi_posts"><span class="fa fa-camera-retro"><%= counts.media%></span></p>' +
2322
- '<p class="wdi_followers"><span></span></p>' +
2323
- '</div>';
2324
- }
2325
- source += '<div class="clear"></div>';
2326
-
2327
- if (usersCount == 1 && username[0] !== '#' && currentFeed.feed_row.display_user_info == '1') {
2328
- source += '<div class="wdi_bio"><%= bio%></div>';
2329
-
2330
- }
2331
-
2332
-
2333
- source += '</div>' +
2334
- '</div>';
2335
-
2336
- var template = _.template(source);
2337
- return template;
2338
  }
2339
 
2340
 
2341
  wdi_front.getHeaderTemplate = function ()
2342
  {
2343
- var source = '<div class="wdi_header_wrapper">' +
2344
- '<div class="wdi_header_img_wrap">' +
2345
- '<img src="<%=feed_thumb%>">' +
2346
- '</div>' +
2347
- '<div class="wdi_header_text"><%=feed_name%></div>' +
2348
- '<div class="clear">' +
2349
- '</div>';
2350
- var template = _.template(source);
2351
- return template;
2352
  }
2353
 
2354
 
2355
  //sets user filter to true and applys filter to feed
2356
  wdi_front.addFilter = function (index, feed_counter)
2357
  {
2358
- var currentFeed = window['wdi_feed_' + feed_counter];
2359
- var usersCount = currentFeed.dataCount;
2360
- if (usersCount < 2) {
2361
- return;
2362
- }
2363
-
2364
- if (currentFeed.nowLoadingImages != false) {
2365
- return;
2366
- } else {
2367
-
2368
- var userDiv = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + '_users [user_index="' + index + '"]');
2369
- userDiv.find('.wdi_filter_overlay').toggleClass('wdi_filter_active_bg');
2370
- userDiv.find('.wdi_header_user_text h3').toggleClass('wdi_filter_active_col');
2371
- userDiv.find('.wdi_media_info').toggleClass('wdi_filter_active_col');
2372
- userDiv.find('.wdi_follow_btn').toggleClass('wdi_filter_active_col');
2373
-
2374
- currentFeed.customFilterChanged = true;
2375
- //setting filter flag to true
2376
- if (currentFeed.userSortFlags[index]['flag'] == false) {
2377
- currentFeed.userSortFlags[index]['flag'] = true;
2378
- } else {
2379
- currentFeed.userSortFlags[index]['flag'] = false;
2380
- }
2381
- //getting active filter count
2382
- var activeFilterCount = 0;
2383
- for (var j = 0; j < currentFeed.userSortFlags.length; j++) {
2384
- if (currentFeed.userSortFlags[j]['flag'] == true) {
2385
- activeFilterCount++;
2386
- }
2387
- }
2388
-
2389
-
2390
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
2391
- //reset responsive indexes because number of feed images may change after using filter
2392
- currentFeed.resIndex = 0;
2393
- }
2394
-
2395
- //applying filters
2396
- if (activeFilterCount != 0) {
2397
- wdi_front.filterData(currentFeed);
2398
- wdi_front.displayFeed(currentFeed);
2399
- } else {
2400
- currentFeed.customFilteredData = currentFeed.dataStorageList;
2401
- wdi_front.displayFeed(currentFeed);
2402
- }
2403
-
2404
-
2405
- if (currentFeed.feed_row.feed_display_view == 'pagination') {
2406
- //reset paginator because while filtering images become more or less so pages also become more or less
2407
- currentFeed.paginator = Math.ceil((currentFeed.imageIndex) / parseInt(currentFeed.feed_row.pagination_per_page_number));
2408
- //setting current page as the last loaded page when filter is active
2409
- currentFeed.currentPage = currentFeed.paginator; //pagination page number
2410
- //when feed is displayed we are by default in the first page
2411
- //so we are navigating from page 1 to current page using custom navigation method
2412
- wdi_front.updatePagination(currentFeed, 'custom', 1);
2413
-
2414
- jQuery('#wdi_first_page').removeClass('wdi_disabled');
2415
- jQuery('#wdi_last_page').addClass('wdi_disabled');
2416
- }
2417
-
2418
- }
2419
  }
2420
 
2421
  wdi_front.filterData = function (currentFeed)
2422
  {
2423
 
2424
- var users = currentFeed.userSortFlags;
2425
- currentFeed.customFilteredData = [];
2426
- for (var i = 0; i < currentFeed.dataStorageList.length; i++) {
2427
- for (var j = 0; j < users.length; j++) {
2428
- if ((currentFeed.dataStorageList[i]['user']['id'] == users[j]['id'] || currentFeed.dataStorageList[i]['wdi_hashtag'] == users[j]['name']) && users[j]['flag'] == true) {
2429
- currentFeed.customFilteredData.push(currentFeed.dataStorageList[i]);
2430
- }
2431
 
2432
- }
2433
- }
2434
 
2435
  }
2436
 
2437
  wdi_front.applyFilters = function (currentFeed)
2438
  {
2439
- for (var i = 0; i < currentFeed.userSortFlags.length; i++) {
2440
- if (currentFeed.userSortFlags[i]['flag'] == true) {
2441
- var userDiv = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + '[user_index="' + i + '"]');
2442
- wdi_front.addFilter(i, currentFeed.feed_row.wdi_feed_counter);
2443
- wdi_front.addFilter(i, currentFeed.feed_row.wdi_feed_counter);
2444
- }
2445
- }
2446
 
2447
  }
2448
 
2449
  //gets data Count from global storage
2450
  wdi_front.getImgCount = function (currentFeed)
2451
  {
2452
- var dataStorage = currentFeed.dataStorage;
2453
- var count = 0;
2454
- for (var i = 0; i < dataStorage.length; i++) {
2455
- count += dataStorage[i].length;
2456
- }
2457
- return count;
2458
  }
2459
 
2460
  //parses image data for lightbox popup
2461
  wdi_front.parseLighboxData = function (currentFeed, filterFlag)
2462
  {
2463
 
2464
- var dataStorage = currentFeed.dataStorage;
2465
- var sortImagesBy = currentFeed.feed_row['sort_images_by'];
2466
- var sortOrder = currentFeed.feed_row['display_order'];
2467
- var sortOperator = wdi_front.sortingOperator(sortImagesBy, sortOrder);
2468
- var data = [];
2469
-
2470
- var popupData = [];
2471
- var obj = {};
2472
-
2473
- //if filterFlag is true, it means that some filter for frontend content is enabled so give
2474
- //lightbox only those images which are visible at that moment else give all avialable
2475
- if (filterFlag == true) {
2476
- data = currentFeed.customFilteredData;
2477
- } else {
2478
- for (var i = 0; i < dataStorage.length; i++) {
2479
- for (var j = 0; j < dataStorage[i].length; j++) {
2480
- data.push(dataStorage[i][j]);
2481
- }
2482
- }
2483
- data.sort(sortOperator);
2484
- }
2485
-
2486
-
2487
- for (i = 0; i < data.length; i++) {
2488
- obj = {
2489
- 'alt': '',
2490
- 'avg_rating': '',
2491
- 'comment_count': data[i]['comments']['count'],
2492
- 'date': wdi_front.convertUnixDate(data[i]['created_time']),
2493
- 'description': wdi_front.getDescription((data[i]['caption'] !== null) ? data[i]['caption']['text'] : ''),
2494
- 'filename': wdi_front.getFileName(data[i]),
2495
- 'filetype': wdi_front.getFileType(data[i]['type']),
2496
- 'hit_count': '0',
2497
- 'id': data[i]['id'],
2498
- 'image_url': data[i]['link'],
2499
- 'number': 0,
2500
- 'rate': '',
2501
- 'rate_count': '0',
2502
- 'username': data[i]['user']['username'],
2503
- 'profile_picture': data[i]['user']['profile_picture'],
2504
- 'thumb_url': data[i]['link'] + 'media/?size=t',
2505
- 'comments_data': data[i]['comments']['data']
2506
- }
2507
- popupData.push(obj);
2508
- }
2509
- return popupData;
2510
  }
2511
 
2512
  wdi_front.convertUnixDate = function (date)
2513
  {
2514
- var utcSeconds = parseInt(date);
2515
- var newDate = new Date(0);
2516
- newDate.setUTCSeconds(utcSeconds);
2517
- var str = newDate.getFullYear() + '-' + newDate.getMonth() + '-' + newDate.getDate();
2518
- str += ' ' + newDate.getHours() + ':' + newDate.getMinutes();
2519
- return str;
2520
  }
2521
 
2522
  wdi_front.getDescription = function (desc)
2523
  {
2524
- desc = desc.replace(/\r?\n|\r/g, ' ');
2525
 
2526
 
2527
- return desc;
2528
  }
2529
 
 
 
 
 
 
2530
  wdi_front.getFileName = function (data)
2531
  {
2532
- var link = data['link'];
2533
- var type = data['type'];
2534
- if (type === 'image') {
2535
- var linkFragments = link.split('/');
2536
- return linkFragments[linkFragments.length - 2];
2537
- } else {
2538
- return data['videos']['standard_resolution']['url'];
2539
- }
 
2540
 
2541
  }
2542
 
2543
- wdi_front.getFileType = function (type)
2544
  {
2545
- if (type === 'image') {
2546
- return "EMBED_OEMBED_INSTAGRAM_IMAGE";
2547
- }
2548
- if (type === 'video') {
2549
- return "EMBED_OEMBED_INSTAGRAM_VIDEO";
2550
- }
 
2551
  }
2552
 
2553
 
2554
  wdi_front.array_max = function (array)
2555
  {
2556
- var max = array[0];
2557
- var minIndex = 0;
2558
- for (var i = 1; i < array.length; i++) {
2559
- if (max < array[i]) {
2560
- max = array[i];
2561
- minIndex = i;
2562
- }
2563
- }
2564
- return {
2565
- 'value': max,
2566
- 'index': minIndex
2567
- };
2568
  }
2569
 
2570
  wdi_front.array_min = function (array)
2571
  {
2572
- var min = array[0];
2573
- var minIndex = 0;
2574
- for (var i = 1; i < array.length; i++) {
2575
- if (min > array[i]) {
2576
- min = array[i];
2577
- minIndex = i;
2578
- }
2579
- }
2580
- return {
2581
- 'value': min,
2582
- 'index': minIndex
2583
- };
2584
  }
2585
 
2586
  /*
@@ -2588,13 +2729,13 @@ wdi_front.array_min = function (array)
2588
  */
2589
  wdi_front.activeUsersCount = function (currentFeed)
2590
  {
2591
- var counter = 0;
2592
- for (var i = 0; i < currentFeed.usersData.length; i++) {
2593
- if (currentFeed.usersData[i].finished != 'finished') {
2594
- counter++;
2595
- }
2596
- }
2597
- return counter;
2598
  }
2599
 
2600
 
@@ -2606,17 +2747,17 @@ wdi_front.activeUsersCount = function (currentFeed)
2606
  wdi_front.checkMediaResponse = function (response)
2607
  {
2608
 
2609
- if (response == '' || typeof response == 'undefined' || response == null) {
2610
- errorMessage = wdi_front_messages.connection_error;
2611
- alert(errorMessage);
2612
- return false;
2613
- }
2614
- if (response['meta']['code'] != 200) {
2615
- errorMessage = response['meta']['error_message'];
2616
- alert(errorMessage);
2617
- return false;
2618
- }
2619
- return response;
2620
  }
2621
 
2622
 
@@ -2627,18 +2768,18 @@ wdi_front.checkMediaResponse = function (response)
2627
  */
2628
  wdi_front.stripHashtag = function (hashtag)
2629
  {
2630
- switch (hashtag[0]) {
2631
- case '#':
2632
- {
2633
- return hashtag.substr(1, hashtag.length);
2634
- break;
2635
- }
2636
- default:
2637
- {
2638
- return hashtag;
2639
- break;
2640
- }
2641
- }
2642
  }
2643
 
2644
  /**
@@ -2649,24 +2790,24 @@ wdi_front.stripHashtag = function (hashtag)
2649
  wdi_front.getInputType = function (input)
2650
  {
2651
 
2652
- switch (input[0]) {
2653
- case '#':
2654
- {
2655
- return 'hashtag';
2656
- break;
2657
- }
2658
- case '%':
2659
- {
2660
- return 'location';
2661
- break;
2662
- }
2663
- default:
2664
- {
2665
- return 'user';
2666
- break;
2667
- }
2668
 
2669
- }
2670
  }
2671
 
2672
  /**
@@ -2678,27 +2819,27 @@ wdi_front.getInputType = function (input)
2678
  */
2679
  wdi_front.regexpTestCaption = function (captionText, searchkey)
2680
  {
2681
- var flag1 = false,
2682
- flag2 = false,
2683
- matchIndexes = [],
2684
- escKey = searchkey.replace(/[-[\]{}()*+?.,\\^$|]/g, "\\$&"),
2685
- regexp1 = new RegExp("(?:^|\\s)" + escKey + "(?:^|\\s)"),
2686
- regexp2 = new RegExp("(?:^|\\s)" + escKey, 'g');
2687
- if (regexp1.exec(captionText) != null) {
2688
- flag1 = true;
2689
- }
2690
 
2691
- while (( match = regexp2.exec(captionText) ) != null) {
2692
- if (match.index == captionText.length - searchkey.length - 1) {
2693
- flag2 = true;
2694
- }
2695
- }
2696
 
2697
- if (flag1 == true || flag2 == true) {
2698
- return true;
2699
- } else {
2700
- return false;
2701
- }
2702
 
2703
  }
2704
 
@@ -2711,55 +2852,55 @@ wdi_front.regexpTestCaption = function (captionText, searchkey)
2711
  */
2712
  wdi_front.replaceNewLines = function (string)
2713
  {
2714
- var delimeter = "vUkCJvN2ps3t",
2715
- matchIndexes = [],
2716
- regexp;
2717
- string = string.replace(/\r?\n|\r/g, delimeter);
2718
 
2719
- regexp = new RegExp(delimeter, 'g');
2720
- while (( match = regexp.exec(string) ) != null) {
2721
- matchIndexes.push(match.index);
2722
- }
2723
 
2724
- var pieces = string.split(delimeter);
2725
- var foundFlag = 0;
2726
 
2727
- for (var i = 0; i < pieces.length; i++) {
2728
 
2729
- if (pieces[i] == '') {
2730
- foundFlag++;
2731
- } else {
2732
- foundFlag = 0;
2733
- }
2734
 
2735
- if (foundFlag > 0) {
2736
- pieces.splice(i, 1);
2737
- foundFlag--;
2738
- i--;
2739
- }
2740
 
2741
- }
2742
- string = pieces.join(' ');
2743
- return string;
2744
  }
2745
 
2746
 
2747
  wdi_front.isEmptyObject = function (obj)
2748
  {
2749
- for (var prop in obj) {
2750
- if (obj.hasOwnProperty(prop))
2751
- return false;
2752
- }
2753
- return true
2754
  }
2755
 
2756
 
2757
  var WDIFeed = function (obj)
2758
  {
2759
- this['data'] = obj['data']
2760
- this['dataCount'] = obj['dataCount']
2761
- this['feed_row'] = obj['feed_row']
2762
- this['usersData'] = obj['usersData']
2763
  };
2764
 
2765
  /**
@@ -2771,67 +2912,67 @@ var WDIFeed = function (obj)
2771
  WDIFeed.prototype.conditionalFilter = function (response, args)
2772
  {
2773
 
2774
- var currentFeed = this,
2775
- conditional_filter_type = currentFeed.feed_row.conditional_filter_type,
2776
- filters = currentFeed.feed_row.conditional_filters;
2777
 
2778
 
2779
- if (args.ignoreFiltering == true) {
2780
 
2781
- } else {
2782
 
2783
- /**
2784
- * Get rid of duplicate media
2785
- */
2786
- response = this.avoidDuplicateMedia(response);
2787
- }
2788
 
2789
 
2790
- //if filters json is invalid then return response without filtering
2791
- if (!wdi_front.isJsonString(filters)) {
2792
- return response;
2793
- } else {
2794
- filters = JSON.parse(filters);
2795
- if (filters.length == 0) {
2796
- return response;
2797
- }
2798
- }
2799
 
2800
 
2801
- if (currentFeed.feed_row.conditional_filter_enable == '0') {
2802
- return response;
2803
- }
2804
 
2805
 
2806
- //console.log('filtering');
2807
- //increase counter for determing request count if this counter is more then
2808
- //currentFeed.maxConditionalFiltersRequestCount then program will terminate recursion loop
2809
- currentFeed.instagramRequestCounter++;
2810
 
2811
- switch (conditional_filter_type) {
2812
- case 'AND':
2813
- {
2814
- response = this.applyANDLogic(response, filters, currentFeed);
2815
- break;
2816
- }
2817
- case 'OR':
2818
- {
2819
- response = this.applyORLogic(response, filters, currentFeed)
2820
- break;
2821
- }
2822
- case 'NOR':
2823
- {
2824
- response = this.applyNORLogic(response, filters, currentFeed)
2825
- break;
2826
- }
2827
- default:
2828
- {
2829
- break;
2830
- }
2831
- }
2832
 
2833
 
2834
- return response;
2835
  }
2836
 
2837
 
@@ -2843,12 +2984,12 @@ WDIFeed.prototype.conditionalFilter = function (response, args)
2843
  */
2844
  WDIFeed.prototype.applyANDLogic = function (response, filters)
2845
  {
2846
- var currentFeed = this;
2847
- for (var i = 0; i < filters.length; i++) {
2848
- response = this.filterResponse(response, filters[i]);
2849
- }
2850
 
2851
- return response;
2852
  }
2853
 
2854
  /**
@@ -2859,32 +3000,32 @@ WDIFeed.prototype.applyANDLogic = function (response, filters)
2859
  */
2860
  WDIFeed.prototype.applyORLogic = function (response, filters)
2861
  {
2862
- var currentFeed = this;
2863
- var allData = [],
2864
- res,
2865
- mergedData = [],
2866
- returnObject,
2867
- media;
2868
 
2869
- for (var i = 0; i < filters.length; i++) {
2870
- res = this.filterResponse(response, filters[i]);
2871
- allData = allData.concat(res['data']);
2872
- res = {};
2873
- }
2874
 
2875
- for (i = 0; i < allData.length; i++) {
2876
- media = allData[i];
2877
- if (!this.mediaExists(media, mergedData) && !this.mediaExists(media, currentFeed.dataStorageList)) {
2878
- mergedData.push(media);
2879
- }
2880
- }
2881
 
2882
- returnObject = {
2883
- data: mergedData,
2884
- meta: response['meta'],
2885
- pagination: response['pagination']
2886
- }
2887
- return returnObject;
2888
  }
2889
 
2890
 
@@ -2897,36 +3038,36 @@ WDIFeed.prototype.applyORLogic = function (response, filters)
2897
  WDIFeed.prototype.applyNORLogic = function (response, filters)
2898
  {
2899
 
2900
- var res = response,
2901
- currentFeed = this,
2902
- matchedData = this.applyORLogic(response, filters, currentFeed),
2903
- mergedData = [],
2904
- returnObject;
2905
 
2906
- for (var i = 0; i < res['data'].length; i++) {
2907
- if (!this.mediaExists(res['data'][i], matchedData['data'])) {
2908
- mergedData.push(res['data'][i]);
2909
- }
2910
- }
2911
 
2912
- returnObject = {
2913
- data: mergedData,
2914
- meta: res['meta'],
2915
- pagination: res['pagination']
2916
- }
2917
- return returnObject;
2918
  }
2919
 
2920
 
2921
  WDIFeed.prototype.mediaExists = function (media, array)
2922
  {
2923
 
2924
- for (var i = 0; i < array.length; i++) {
2925
- if (media['id'] == array[i]['id']) {
2926
- return true;
2927
- }
2928
- }
2929
- return false;
2930
  }
2931
 
2932
 
@@ -2939,38 +3080,38 @@ WDIFeed.prototype.mediaExists = function (media, array)
2939
  WDIFeed.prototype.filterResponse = function (response, filter)
2940
  {
2941
 
2942
- switch (filter.filter_type) {
2943
- case 'hashtag':
2944
- {
2945
- return this.filterByHashtag(response, filter);
2946
- break;
2947
- }
2948
- case 'username':
2949
- {
2950
- return this.filterByUsername(response, filter);
2951
- break;
2952
- }
2953
- case 'mention':
2954
- {
2955
- return this.filterByMention(response, filter);
2956
- break;
2957
- }
2958
- case 'description':
2959
- {
2960
- return this.filterByDescription(response, filter);
2961
- break;
2962
- }
2963
- case 'location':
2964
- {
2965
- return this.filterByLocation(response, filter);
2966
- break;
2967
- }
2968
- case 'url':
2969
- {
2970
- return this.filterByUrl(response, filter);
2971
- break;
2972
- }
2973
- }
2974
  }
2975
 
2976
 
@@ -2982,29 +3123,29 @@ WDIFeed.prototype.filterResponse = function (response, filter)
2982
  */
2983
  WDIFeed.prototype.filterByHashtag = function (response, filter)
2984
  {
2985
- var filteredResponse = [],
2986
- currentTag,
2987
- media,
2988
- returnObject;
2989
 
2990
- for (var i = 0; i < response['data'].length; i++) {
2991
- media = response['data'][i];
2992
- for (var j = 0; j < media['tags'].length; j++) {
2993
- tag = media['tags'][j];
2994
- if (tag.toLowerCase() == filter.filter_by.toLowerCase()) {
2995
 
2996
- filteredResponse.push(media);
2997
- }
2998
- }
2999
- }
3000
 
3001
 
3002
- returnObject = {
3003
- data: filteredResponse,
3004
- meta: response['meta'],
3005
- pagination: response['pagination']
3006
- }
3007
- return returnObject;
3008
  }
3009
 
3010
  /**
@@ -3015,24 +3156,24 @@ WDIFeed.prototype.filterByHashtag = function (response, filter)
3015
  */
3016
  WDIFeed.prototype.filterByUsername = function (response, filter)
3017
  {
3018
- var filteredResponse = [],
3019
- media,
3020
- returnObject;
3021
 
3022
- for (var i = 0; i < response['data'].length; i++) {
3023
- media = response['data'][i];
3024
- if (media.user.username.toLowerCase() == filter.filter_by.toLowerCase()) {
3025
- filteredResponse.push(media);
3026
- }
3027
- }
3028
 
3029
 
3030
- returnObject = {
3031
- data: filteredResponse,
3032
- meta: response['meta'],
3033
- pagination: response['pagination']
3034
- }
3035
- return returnObject;
3036
  }
3037
 
3038
 
@@ -3044,25 +3185,25 @@ WDIFeed.prototype.filterByUsername = function (response, filter)
3044
  */
3045
  WDIFeed.prototype.filterByMention = function (response, filter)
3046
  {
3047
- var filteredResponse = [],
3048
- media, captionText, returnObject;
3049
- for (var i = 0; i < response['data'].length; i++) {
3050
- media = response['data'][i];
3051
- if (media['caption'] !== null) {
3052
- captionText = media['caption']['text'].toLowerCase();
3053
- if (captionText.indexOf('@' + filter.filter_by.toLowerCase()) != -1) {
3054
 
3055
- filteredResponse.push(media);
3056
- }
3057
- }
3058
- }
3059
 
3060
- returnObject = {
3061
- data: filteredResponse,
3062
- meta: response['meta'],
3063
- pagination: response['pagination']
3064
- }
3065
- return returnObject;
3066
  }
3067
 
3068
 
@@ -3074,30 +3215,30 @@ WDIFeed.prototype.filterByMention = function (response, filter)
3074
  */
3075
  WDIFeed.prototype.filterByDescription = function (response, filter)
3076
  {
3077
- var filteredResponse = [],
3078
- media, captionText, returnObject;
3079
 
3080
- for (var i = 0; i < response['data'].length; i++) {
3081
- media = response['data'][i];
3082
- if (media['caption'] !== null) {
3083
 
3084
- captionText = media['caption']['text'].toLowerCase();
3085
- captionText = wdi_front.replaceNewLines(captionText);
3086
- var searchkey = filter.filter_by.toLowerCase();
3087
 
3088
- if (wdi_front.regexpTestCaption(captionText, searchkey)) {
3089
- filteredResponse.push(media);
3090
- }
3091
- }
3092
- }
3093
 
3094
- returnObject = {
3095
- data: filteredResponse,
3096
- meta: response['meta'],
3097
- pagination: response['pagination']
3098
- }
3099
 
3100
- return returnObject;
3101
  }
3102
 
3103
 
@@ -3109,25 +3250,25 @@ WDIFeed.prototype.filterByDescription = function (response, filter)
3109
  */
3110
  WDIFeed.prototype.filterByLocation = function (response, filter)
3111
  {
3112
- var filteredResponse = [],
3113
- media, locationId, returnObject;
3114
- for (var i = 0; i < response['data'].length; i++) {
3115
- media = response['data'][i];
3116
 
3117
- if (media['location'] !== null) {
3118
- locationId = media['location']['id'];
3119
- if (locationId == filter.filter_by) {
3120
- filteredResponse.push(media);
3121
- }
3122
- }
3123
- }
3124
 
3125
- returnObject = {
3126
- data: filteredResponse,
3127
- meta: response['meta'],
3128
- pagination: response['pagination']
3129
- }
3130
- return returnObject;
3131
  }
3132
 
3133
 
@@ -3140,28 +3281,28 @@ WDIFeed.prototype.filterByLocation = function (response, filter)
3140
 
3141
  WDIFeed.prototype.filterByUrl = function (response, filter)
3142
  {
3143
- var filteredResponse = [],
3144
- media, id, returnObject, filter_by;
3145
 
3146
- filter.filter_by = this.getIdFromUrl(filter.filter_by);
3147
 
3148
- for (var i = 0; i < response['data'].length; i++) {
3149
- media = response['data'][i];
3150
 
3151
- if (media['link'] !== null) {
3152
- id = this.getIdFromUrl(media['link']);
3153
- if (id == filter.filter_by) {
3154
- filteredResponse.push(media);
3155
- }
3156
- }
3157
- }
3158
 
3159
- returnObject = {
3160
- data: filteredResponse,
3161
- meta: response['meta'],
3162
- pagination: response['pagination']
3163
- }
3164
- return returnObject;
3165
  }
3166
 
3167
  /**
@@ -3171,18 +3312,18 @@ WDIFeed.prototype.filterByUrl = function (response, filter)
3171
  */
3172
  WDIFeed.prototype.getIdFromUrl = function (url)
3173
  {
3174
- var url_parts = url.split('/'),
3175
- id = false;
3176
- for (var i = 0; i < url_parts.length; i++) {
3177
- if (url_parts[i] == 'p') {
3178
- if (typeof url_parts[i + 1] != 'undefined') {
3179
- id = url_parts[i + 1];
3180
- break;
3181
- }
3182
- }
3183
- }
3184
- ;
3185
- return id;
3186
  }
3187
 
3188
 
@@ -3193,25 +3334,28 @@ WDIFeed.prototype.getIdFromUrl = function (url)
3193
  */
3194
  WDIFeed.prototype.avoidDuplicateMedia = function (response)
3195
  {
3196
- var data = response['data'],
3197
- uniqueData = [],
3198
- returnObject = {};
 
 
 
3199
 
3200
- for (var i = 0; i < data.length; i++) {
3201
- if (!this.mediaExists(data[i], this.dataStorageList) && !this.mediaExists(data[i], uniqueData) && !this.mediaExists(data[i], this.conditionalFilterBuffer)) {
3202
- uniqueData.push(data[i]);
3203
- }
3204
- }
3205
 
3206
- this.conditionalFilterBuffer = this.conditionalFilterBuffer.concat(uniqueData);
3207
 
3208
- returnObject = {
3209
- data: uniqueData,
3210
- meta: response['meta'],
3211
- pagination: response['pagination']
3212
- }
3213
 
3214
- return returnObject;
3215
 
3216
  }
3217
 
@@ -3219,182 +3363,178 @@ WDIFeed.prototype.avoidDuplicateMedia = function (response)
3219
  /* stores data from objects array into global variable */
3220
  WDIFeed.prototype.storeRawData = function (objects, variable)
3221
  {
3222
- var _this = this;
3223
- if (typeof this[variable] == "object" && typeof this[variable].length == "number") {
3224
- //checks if in golbal storage user already exisit then it adds new data to user old data
3225
- //else it simple puches new user with it's data to global storage
3226
- for (var i = 0; i < objects.length; i++) {
3227
-
3228
-
3229
- var hash_id = "";
3230
- if (wdi_front.isHashtag(objects[i].user_id)) {
3231
- hash_id = objects[i].pagination.next_max_tag_id;
3232
- }
3233
- else
3234
- if (_this.feed_row.liked_feed == 'liked') {
3235
- hash_id = objects[i].pagination.next_max_like_id;
3236
- if (typeof hash_id == "undefined") {
3237
- hash_id = "";
3238
- }
3239
- }
3240
- else {
3241
-
3242
- /*strange bug sometimes happening in instagram API when user feed pagination is null*/
3243
- if(objects[i].pagination == null){
3244
- objects[i].pagination = [];
3245
- }
3246
-
3247
- hash_id = objects[i].pagination.next_max_id;
3248
- if (typeof hash_id == "undefined") {
3249
- hash_id = "";
3250
- }
3251
-
3252
-
3253
- }
3254
-
3255
- if (typeof this[variable][i] == "undefined") {
3256
- this[variable].push({
3257
- data: objects[i].data,
3258
- index: 0,
3259
- locked: false,
3260
- hash_id: hash_id,
3261
- usersDataFinished: false,
3262
- userId: objects[i].user_id,
3263
- length: function ()
3264
- {
3265
- return this.data.length - this.index;
3266
- },
3267
- getData: function (num)
3268
- {
3269
- var data = this.data.slice(this.index, this.index + num);
3270
- this.index += Math.min(num, this.length());
3271
-
3272
- if (this.index == this.data.length && this.locked == true && this.usersDataFinished == false) {
3273
-
3274
- for (var j = 0; j < _this.usersData.length; j++) {
3275
- if (_this.usersData[j]['user_id'] == this.userId) {
3276
- _this.usersData[j].finished = "finished";
3277
- this.usersDataFinished = true;
3278
- break;
3279
- }
3280
- }
3281
- }
3282
- return data;
3283
- }
3284
- });
3285
- } else {
3286
- if (this[variable][i].locked == false) {
3287
-
3288
- if (hash_id != this[variable][i].hash_id) {
3289
- this[variable][i].data = this[variable][i].data.concat(objects[i].data);
3290
- this[variable][i].hash_id = hash_id;
3291
- } else {
3292
- this[variable][i].locked = true;
3293
-
3294
- }
3295
- }
3296
-
3297
- }
3298
- }
3299
- }
3300
 
3301
  }
3302
 
3303
 
3304
  wdi_front.updateUsersIfNecessary = function (currentFeed)
3305
  {
3306
- var users = currentFeed.feed_users;
3307
- var ifUpdateNecessary = false;
3308
 
3309
- for (var i = 0; i < users.length; i++) {
3310
- if ("#" == users[i].username.substr(0, 1)) {
3311
- users[i].id = users[i].username;
3312
- continue;
3313
- }
3314
- if ("" == users[i].id || 'username' == users[i].id) {
3315
 
3316
- ifUpdateNecessary = true;
3317
- currentFeed.instagram.searchForUsersByName(users[i].username, {
3318
- success: function (res)
3319
- {
3320
- if (res.meta.code == 200 && res.data.length > 0) {
3321
 
3322
- var found = false;
3323
 
3324
- for (var k = 0; k < res.data.length; k++) {
3325
- if (res.data[k].username == res.args.username) {
3326
- found = true;
3327
- break;
3328
- }
3329
- }
3330
 
3331
- if (found) {
3332
- for (var j = 0; j < users.length; j++) {
3333
- if (res.data[k].username == users[j].username) {
3334
- users[j].id = res.data[k].id;
3335
- }
3336
- }
3337
- }
3338
 
3339
 
3340
- }
3341
 
3342
- var noid_user_left = false;
3343
- for (var m = 0; m < users.length; m++) {
3344
- if (users[m].id == "" || users[m].id == "username") {
3345
- noid_user_left = true;
3346
- break;
3347
- }
3348
- }
3349
- if (!noid_user_left) {
3350
- currentFeed.feed_row.feed_users = JSON.stringify(users);
3351
- wdi_front.init(currentFeed);
3352
- }
3353
 
3354
- },
3355
- username: users[i].username
3356
- });
3357
- }
3358
- }
3359
 
3360
- return ifUpdateNecessary;
3361
  }
3362
 
3363
 
 
 
 
3364
 
 
3365
 
3366
-
3367
-
3368
-
3369
-
3370
- if(typeof wdi_ajax.ajax_response != "undefined"){
3371
- jQuery( document ).one('ajaxStop', function() {
3372
-
3373
- if (wdi_front['type'] != 'not_declared') {
3374
-
3375
- wdi_front.clickOrTouch = wdi_front.detectEvent();
3376
- //initializing all feeds in the page
3377
- wdi_front.globalInit();
3378
- } else {
3379
- return;
3380
- }
3381
- });
3382
 
3383
 
3384
  }
3385
- else{
3386
- jQuery(document).ready(function ()
3387
- {
3388
 
3389
 
3390
- if (wdi_front['type'] != 'not_declared') {
3391
- wdi_front.clickOrTouch = wdi_front.detectEvent();
3392
- //initializing all feeds in the page
3393
- wdi_front.globalInit();
3394
- } else {
3395
- return;
3396
- }
3397
 
3398
- });
3399
  }
3400
 
 
1
  if (typeof wdi_front == 'undefined') {
2
+ wdi_front = {
3
+ type: 'not_declared'
4
+ };
5
  }
6
 
7
 
 
8
  wdi_front.detectEvent = function ()
9
  {
10
+ var isMobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
11
+ if (isMobile) {
12
+ return "touchend";
13
+ } else {
14
+ return 'click';
15
+ }
16
+ }
17
+
18
+ wdi_front.show_alert = function (message)
19
+ {
20
+ if (wdi_front_messages.show_alerts) {
21
+ alert(message);
22
+ }
23
+ else {
24
+ console.log('%c' + message, "color:#cc0000;");
25
+ }
26
  }
27
 
28
+
29
  wdi_front.globalInit = function ()
30
  {
31
+ var num = wdi_front['feed_counter'];
32
+
33
+ if (typeof wdi_ajax.ajax_response != "undefined") {
34
+ var init_feed_counter = wdi_feed_counter_init.wdi_feed_counter_init;
35
+ }
36
+ else {
37
+ var init_feed_counter = 0;
38
+ }
39
+ for (var i = init_feed_counter; i <= num; i++) {
40
+
41
+ var currentFeed = new WDIFeed(window['wdi_feed_' + i]);
42
+
43
+ /*initializing instagram object which will handle all instagram api requests*/
44
+ currentFeed.instagram = new WDIInstagram();
45
+
46
+ /**
47
+ * this object will be passed to filtering function of currentFeed.instagram as second parameter
48
+ * @type {Object}
49
+ */
50
+ currentFeed.instagram.filterArguments = {
51
+ feed: currentFeed
52
+ };
53
+
54
+ currentFeed.instagram.filters = [
55
+ {
56
+ 'where': 'getUserRecentMedia',
57
+ 'what': function (response, args, cArgs)
58
+ {
59
+ return args.feed.conditionalFilter(response, cArgs);
60
+ }
61
+ },
62
+ {
63
+ 'where': 'getTagRecentMedia',
64
+ 'what': function (response, args, cArgs)
65
+ {
66
+ return args.feed.conditionalFilter(response, cArgs);
67
+ }
68
+ },
69
+ {
70
+ 'where': 'getRecentLikedMedia',
71
+ 'what': function (response, args, cArgs)
72
+ {
73
+ return args.feed.conditionalFilter(response, cArgs);
74
+ }
75
+ },
76
+
77
+
78
+ {
79
+ 'where': 'requestByUrl',
80
+ 'what': function (response, args, cArgs)
81
+ {
82
+ return args.feed.conditionalFilter(response, cArgs);
83
+ }
84
+ },];
85
+
86
+
87
+ currentFeed.instagram.addToken(currentFeed['feed_row']['access_token']);
88
+
89
+ wdi_front.access_token = currentFeed['feed_row']['access_token'];
90
+
91
+ currentFeed.dataStorageRaw = []; //stores all getted data from instagram api
92
+
93
+ currentFeed.dataStorage = []; //stores all avialable data
94
+ currentFeed.dataStorageList = []; //?
95
+ currentFeed.allResponseLength = 0; //?
96
+ //number of instagram objects which has been got by single request
97
+ currentFeed.currentResponseLength = 0;
98
+
99
+ //temprorary usersData which is uses in case when getted data is smaller then needed
100
+ currentFeed.temproraryUsersData = [];
101
+
102
+ currentFeed.removedUsers = 0;
103
+ currentFeed.nowLoadingImages = true;
104
+ currentFeed.imageIndex = 0; //index for image indexes
105
+ currentFeed.resIndex = 0; //responsive indexes used for pagination
106
+ currentFeed.currentPage = 1; //pagination page number
107
+ currentFeed.userSortFlags = []; //array for descripbing user based filter options
108
+ currentFeed.customFilterChanged = false; //flag to notice filter change, onclick on username
109
+
110
+
111
+ /**
112
+ * This variable describes after how many requests program will stop searching for content
113
+ * this number is very important and should not be set too high, because when feed has conditional filter
114
+ * and filtered items are rare then the program will recursively request new photos and will filter them
115
+ * if no image was fount it will go into infinite loop if feed images are "infinite" ( very huge number )
116
+ * and if requests count in 1 hour exeed 5000 instagram will block access token for one hour
117
+ *
118
+ * @type {Number}
119
+ */
120
+ currentFeed.maxConditionalFiltersRequestCount = 10;
121
+
122
+ /**
123
+ * This variable shows us how many times program has been recursively called,
124
+ * it changes it value within filtering function, and resets itself to 0 when feed is being displayed
125
+ *
126
+ * @type {Number}
127
+ */
128
+ currentFeed.instagramRequestCounter = 0;
129
+
130
+ /**
131
+ * This array stores data from each request,
132
+ * it is used to determine and remove duplicate photos caused by multiple hashtags
133
+ * it is resetted to its inital [] value after displaying feed
134
+ *
135
+ * @type {Array}
136
+ */
137
+ currentFeed.conditionalFilterBuffer = [];
138
+
139
+
140
+ currentFeed.stopInfiniteScrollFlag = false;
141
+
142
+ window.onload = function ()
143
+ {
144
+ for (var i = init_feed_counter; i <= wdi_front.feed_counter; i++) {
145
+ window['wdi_feed_' + i]['nowLoadingImages'] = false;
146
+ }
147
+ }
148
+
149
+ if (currentFeed.feed_row.feed_type == 'masonry') {
150
+ currentFeed.displayedData = [];
151
+ }
152
+
153
+
154
+ //if pagination is on then set pagination parameters
155
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
156
+ currentFeed.feed_row.resort_after_load_more = 0;
157
+ if (currentFeed.feed_row.feed_type != 'image_browser') {
158
+ currentFeed.feed_row.load_more_number = parseInt(currentFeed.feed_row.pagination_per_page_number);
159
+ currentFeed.feed_row.number_of_photos = (1 + parseInt(currentFeed.feed_row.pagination_preload_number)) * currentFeed.feed_row.load_more_number;
160
+ } else {
161
+ currentFeed.feed_row.number_of_photos = 1 + parseInt(currentFeed.feed_row.image_browser_preload_number);
162
+ currentFeed.feed_row.load_more_number = parseInt(currentFeed.feed_row.image_browser_load_number);
163
+ }
164
+
165
+
166
+ currentFeed.freeSpaces = (Math.floor(currentFeed.feed_row.pagination_per_page_number / currentFeed.feed_row.number_of_columns) + 1) * currentFeed.feed_row.number_of_columns - currentFeed.feed_row.pagination_per_page_number;
167
+ } else {
168
+ currentFeed.freeSpaces = 0;
169
+ }
170
 
171
 
172
+ //initializing function for lightbox
173
+ currentFeed.galleryBox = function (image_id)
174
+ {
175
+ wdi_spider_createpopup(wdi_url.ajax_url + '?gallery_id=' + this.feed_row['id'] + '&image_id=' + image_id, wdi_front.feed_counter, this.feed_row['lightbox_width'], this.feed_row['lightbox_height'], 1, 'testpopup', 5, this);
176
+ }
177
+ //calling responive javascript
178
+ wdi_responsive.columnControl(currentFeed);
179
 
180
+ //if feed type is masonry then trigger resize event for building proper column layout
181
+ if (currentFeed.feed_row.feed_type == 'masonry') {
182
+ jQuery(window).trigger('resize');
183
+ }
184
 
185
+ wdi_front.bindEvents(currentFeed);
186
 
187
+ window['wdi_feed_' + i] = currentFeed;
188
 
189
 
190
+ //initializing each feed
191
+ wdi_front.init(currentFeed);
192
+ } //endfor
193
 
194
  }
195
 
197
  {
198
 
199
 
200
+ //some varables used in code
201
+ currentFeed.photoCounter = currentFeed.feed_row["number_of_photos"];
202
 
203
 
204
+ if (currentFeed.feed_row.liked_feed == 'liked') {
205
+ currentFeed.feed_users = ['self'];
206
+ // do nothing,
207
+ }
208
+ else
209
+ if (wdi_front.isJsonString(currentFeed.feed_row.feed_users)) {
210
+ /**
211
+ * Contains username and user_id of each user
212
+ * @type {[Array}
213
+ */
214
+ currentFeed.feed_users = JSON.parse(currentFeed.feed_row.feed_users);
215
 
216
+ /**
217
+ * Check if feed user has no id for some reason then update user
218
+ * and after updating them initialize feed
219
+ */
220
+ if (wdi_front.updateUsersIfNecessary(currentFeed)) {
221
+ return;
222
+ }
223
+ ;
224
 
225
 
226
+ } else {
227
+ wdi_front.show_alert('provided feed users are invalid or obsolete for this version of plugin');
228
+ return;
229
+ }
230
 
231
 
232
+ //wdi_front.loadInstagramMedia( currentFeed, currentFeed.feed_row.number_of_photos);
233
 
234
+ currentFeed.dataCount = currentFeed.feed_users.length; //1 in case of self feed
235
 
236
 
237
+ for (var i = 0; i < currentFeed.dataCount; i++) {
238
+ wdi_front.instagramRequest(i, currentFeed);
239
+ }
240
 
241
 
242
+ if (currentFeed.feed_row["number_of_photos"] > 0) {
243
+ wdi_front.ajaxLoader(currentFeed);
244
+ }
245
 
246
 
247
+ //setting feed name
248
+ if (currentFeed['feed_row']['display_header'] === '1') {
249
+ wdi_front.show('header', currentFeed);
250
+ }
251
+ if (currentFeed['feed_row']['show_usernames'] === '1') {
252
+ wdi_front.show('users', currentFeed);
253
+ }
254
 
255
 
256
  }
263
  */
264
  wdi_front.isJsonString = function (str)
265
  {
266
+ try {
267
+ JSON.parse(str);
268
+ } catch (e) {
269
+ return false;
270
+ }
271
+ return true;
272
  }
273
 
274
 
282
  wdi_front.instagramRequest = function (id, currentFeed)
283
  {
284
 
285
+ var feed_users = currentFeed.feed_users,
286
+ _this = this;
287
+ if (typeof feed_users[id] === 'string' && feed_users[id] === 'self') { // self liked media
288
+ currentFeed.instagram.getRecentLikedMedia({
289
+ success: function (response)
290
+ {
291
+ response = _this.checkMediaResponse(response);
292
+ if (response != false) {
293
+ _this.saveSelfUserData(response, currentFeed);
294
+ }
295
+ }
296
+ });
297
+ }
298
+ else
299
+ if (this.getInputType(feed_users[id]['username']) == 'hashtag') {
300
+ currentFeed.instagram.getTagRecentMedia(this.stripHashtag(feed_users[id]['username']), {
301
+ success: function (response)
302
+ {
303
+ response = _this.checkMediaResponse(response);
304
+ if (response != false) {
305
+ _this.saveUserData(response, currentFeed.feed_users[id], currentFeed);
306
+ }
307
+ }
308
+ });
309
+ }
310
+ else
311
+ if (this.getInputType(feed_users[id]['username']) == 'user') {
312
+ currentFeed.instagram.getUserRecentMedia(feed_users[id]['id'], {
313
+ success: function (response)
314
+ {
315
+ response = _this.checkMediaResponse(response);
316
+ if (response != false) {
317
+ _this.saveUserData(response, currentFeed.feed_users[id], currentFeed);
318
+ }
319
+ }
320
+ });
321
+ }
322
 
323
  }
324
 
329
  */
330
  wdi_front.isHashtag = function (str)
331
  {
332
+ return (str[0] === '#');
333
  }
334
 
335
 
340
  wdi_front.saveUserData = function (data, user, currentFeed)
341
  {
342
 
343
+ data['username'] = user.username;
344
+ data['user_id'] = user.id;
345
 
346
+ //checking if user type is hashtag then manually add hashtag to each object, for later use
347
+ //hashtag based filters
348
+ if (data['user_id'][0] === '#') {
349
+ data['data'] = wdi_front.appendRequestHashtag(data['data'], data['user_id']);
350
+ }
351
 
352
 
353
+ currentFeed.usersData.push(data);
354
 
355
 
356
+ currentFeed.currentResponseLength = wdi_front.getArrayContentLength(currentFeed.usersData, 'data');
357
+ currentFeed.allResponseLength += currentFeed.currentResponseLength;
358
 
359
 
360
+ if (currentFeed.dataCount == currentFeed.usersData.length) {
361
 
362
+ //if getted objects is not enough then recuest new ones
363
+ if (currentFeed.currentResponseLength < currentFeed.feed_row.number_of_photos && !wdi_front.userHasNoPhoto(currentFeed)) {
364
+ //console.log('initial recursion');
365
+ /*here we are calling loadMore function out of recursion cylce, after this initial-keep call
366
+ loadMore will be called with 'initial' recursivly until the desired number of photos is reached
367
+ if possible*/
368
 
369
+ wdi_front.loadMore('initial-keep', currentFeed);
370
+ } else {
371
 
372
 
373
+ //display feed
374
+ wdi_front.displayFeed(currentFeed);
375
+ //when all data us properly displayed check for any active filters and then apply them
376
+ wdi_front.applyFilters(currentFeed);
377
 
378
 
379
+ /*removing load more button of feed has finished*/
380
+ if (!wdi_front.activeUsersCount(currentFeed)) {
381
+ if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
382
+ var feed_container = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter);
383
+ feed_container.find('.wdi_load_more').addClass('wdi_hidden');
384
+ feed_container.find('.wdi_spinner').addClass('wdi_hidden');
385
+ }
386
+ }
387
+ ;
388
 
389
+ }
390
 
391
 
392
+ }
393
 
394
  }
395
 
401
  wdi_front.saveSelfUserData = function (data, currentFeed)
402
  {
403
 
404
+ //keep empty for self feed
405
+ data['username'] = '';
406
+ data['user_id'] = '';
407
 
408
+ currentFeed.usersData.push(data);
409
 
410
 
411
+ currentFeed.currentResponseLength = wdi_front.getArrayContentLength(currentFeed.usersData, 'data');
412
+ currentFeed.allResponseLength += currentFeed.currentResponseLength;
413
 
414
 
415
+ if (currentFeed.dataCount == currentFeed.usersData.length) {
416
 
417
+ //if retrieved objects are not enough then request new ones
418
 
419
+ if (currentFeed.currentResponseLength < currentFeed.feed_row.number_of_photos && !wdi_front.userHasNoPhoto(currentFeed)) {
420
+ //console.log('initial recursion');
421
+ /*here we are calling loadMore function out of recursion cycle, after this initial-keep call
422
+ loadMore will be called with 'initial' recursively until the desired number of photos is reached
423
+ if possible*/
424
 
425
+ wdi_front.loadMore('initial-keep', currentFeed);
426
+ } else {
427
 
428
 
429
+ //display feed
430
+ wdi_front.displayFeed(currentFeed);
431
+ //when all data us properly displayed check for any active filters and then apply them
432
+ wdi_front.applyFilters(currentFeed);
433
 
434
 
435
+ /*removing load more button of feed has finished*/
436
+ if (!wdi_front.activeUsersCount(currentFeed)) {
437
+ if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
438
+ var feed_container = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter);
439
+ feed_container.find('.wdi_load_more').addClass('wdi_hidden');
440
+ feed_container.find('.wdi_spinner').addClass('wdi_hidden');
441
+ }
442
+ }
443
+ ;
444
 
445
+ }
446
 
447
 
448
+ }
449
 
450
  }
451
 
455
  wdi_front.userHasNoPhoto = function (currentFeed, cstData)
456
  {
457
 
458
+ var counter = 0;
459
+ var data = currentFeed.usersData;
460
+ if (typeof cstData != 'undefined') {
461
+ data = cstData;
462
+ }
463
+ for (var i = 0; i < data.length; i++) {
464
+ if (currentFeed.feed_row.liked_feed === 'liked') {
465
+ if (typeof data[i]['pagination']['next_max_like_id'] == 'undefined') {
466
+ counter++
467
+ }
468
+ }
469
+ else {
470
+ if (typeof data[i]['pagination']['next_max_id'] == 'undefined') {
471
+ counter++
472
+ }
473
+ }
474
+
475
+ }
476
+ if (counter == data.length) {
477
+ return 1;
478
+ } else {
479
+ return 0;
480
+ }
481
  }
482
 
483
  /*
485
  */
486
  wdi_front.appendRequestHashtag = function (data, hashtag)
487
  {
488
+ for (var i = 0; i < data.length; i++) {
489
+ data[i]['wdi_hashtag'] = hashtag;
490
+ }
491
+ return data;
492
  }
493
 
494
 
501
  {
502
 
503
 
504
+ if (currentFeed.customFilterChanged == false) {
505
+ //sorting data...
506
+ var data = wdi_front.feedSort(currentFeed, load_more_number);
507
+ }
508
 
509
 
510
+ //becomes true when user clicks in frontend filter
511
+ //if isset to true then loadmore recursion would not start
512
+ var frontendCustomFilterClicked = currentFeed.customFilterChanged;
513
 
514
 
515
+ // if custom filter changed then display custom data
516
+ if (currentFeed.customFilterChanged == true) {
517
+ var data = currentFeed.customFilteredData;
518
 
519
+ //parsing data for lightbox
520
+ currentFeed.parsedData = wdi_front.parseLighboxData(currentFeed, true);
521
+ }
522
 
523
 
524
+ //storing all sorted data in array for later use in user based filters
525
+ if (currentFeed.feed_row.resort_after_load_more != '1') {
526
+ // filter changes when user clicks to usernames in header
527
+ // at that point displayFeed triggers but we don't have any new data so
528
+ // we are not adding new data to our list
529
+ if (currentFeed.customFilterChanged == false) {
530
+ currentFeed.dataStorageList = currentFeed.dataStorageList.concat(data);
531
+ }
532
+ } else {
533
+ // filter changes when user clicks to usernames in header
534
+ // at that point displayFeed triggers but we don't have any new data so
535
+ // we are not adding new data to our list
536
+ if (currentFeed.customFilterChanged == false) {
537
+ currentFeed.dataStorageList = data;
538
+ }
539
+ }
540
 
541
+ //checking feed_type and calling proper rendering functions
542
+ if (currentFeed.feed_row.feed_type == 'masonry') {
543
+ wdi_front.masonryDisplayFeedItems(data, currentFeed);
544
+ }
545
+ if (currentFeed.feed_row.feed_type == 'thumbnails' || currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
546
+ wdi_front.displayFeedItems(data, currentFeed);
547
+ }
548
 
549
 
550
+ //recursively calling load more to get photos
551
+ var dataLength = wdi_front.getDataLength(currentFeed);
552
 
553
 
554
+ if (dataLength < currentFeed.photoCounter && !frontendCustomFilterClicked && currentFeed.instagramRequestCounter <= currentFeed.maxConditionalFiltersRequestCount && !wdi_front.allDataHasFinished(currentFeed)) {
555
+ wdi_front.loadMore('', currentFeed);
556
 
557
+ } else {
558
+ wdi_front.allImagesLoaded(currentFeed);
559
+ }
560
 
561
 
562
+ /**
563
+ * if maximum number of requests are reached then stop laoding more images and show images which are available
564
+ * @param {Number} currentFeed.instagramRequestCounter > currentFeed.maxConditionalFiltersRequestCount [description]
565
+ * @return {Boolean}
566
+ */
567
+ if (currentFeed.instagramRequestCounter > currentFeed.maxConditionalFiltersRequestCount) {
568
+ wdi_front.allImagesLoaded(currentFeed);
569
 
570
+ //if no data was received then
571
+ if (data.length == 0) {
572
+ //if feed_display_view is set to infinite scroll then after reaching the limit once set this flag to false
573
+ //this will stop infinite scrolling and will not load any images even when scrolling
574
+ currentFeed.stopInfiniteScrollFlag = true;
575
+ }
576
+ }
577
 
578
+ //checking if display_view is pagination and we are not on the last page then enable
579
+ //last page button
580
+ if (currentFeed.feed_row.feed_display_view == 'pagination' && currentFeed.currentPage < currentFeed.paginator) {
581
+ jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter).find('#wdi_last_page').removeClass('wdi_disabled');
582
+ }
583
 
584
 
585
+ // reset instagram request counter to zero for next set of requests
586
+ currentFeed.instagramRequestCounter = 0;
587
 
588
+ //reset conditional filter buffer for the next bunch of requests
589
+ currentFeed.conditionalFilterBuffer = [];
590
 
591
+ //if there are any missing images in header then replace them with new ones if possible
592
+ wdi_front.updateUsersImages(currentFeed);
593
 
594
 
595
+ // /**
596
+ // * Enable image lazy laoding if pagination is not enabeled because pagination has option for preloading images
597
+ // * which is the opposide of lazy load
598
+ // */
599
+ // if( currentFeed.feed_row.feed_display_view != 'pagination' ){
600
+ // jQuery(function() {
601
+ // jQuery('img.wdi_img').lazyload({
602
+ // skip_invisible : false,
603
+ // threshold : 400
604
+ // });
605
+ // });
606
 
607
+ // }
608
 
609
  }
610
 
615
  */
616
  wdi_front.updateUsersImages = function (currentFeed)
617
  {
618
+ var elements = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter).find('.wdi_single_user .wdi_user_img_wrap img');
619
+ elements.each(function ()
620
+ {
621
+ if (jQuery(this).attr('src') == wdi_url.plugin_url + '../images/missing.png' || jQuery(this).attr('src') == '') {
622
+ //console.log('missing');
623
 
624
+ if (currentFeed.feed_row.liked_feed == 'liked') {
625
+ return;
626
+ }
627
 
628
 
629
+ for (var j = 0; j < currentFeed.usersData.length; j++) {
630
+ if (currentFeed.usersData[j]['username'] == jQuery(this).parent().parent().find('h3').text()) {
631
+ if (currentFeed.usersData[j]['data'].length != 0) {
632
+ jQuery(this).attr('src', currentFeed.usersData[j]['data'][0]['images']['thumbnail']['url']);
633
+ }
634
+ }
635
+ }
636
+ }
637
+ });
638
  }
639
 
640
 
645
  */
646
  wdi_front.masonryDisplayFeedItems = function (data, currentFeed)
647
  {
648
+ var masonryColEnds = [];
649
+ var masonryColumns = [];
650
+ if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + " .wdi_feed_wrapper").length == 0) {
651
+ //no feed in DOM, ignore
652
+ return;
653
+ }
654
+ jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_masonry_column').each(function ()
655
+ {
656
+
657
+ //if resorte after load more is on then reset columns on every load more
658
+ if (currentFeed.feed_row.resort_after_load_more == 1) {
659
+ jQuery(this).html('');
660
+ currentFeed.imageIndex = 0;
661
+ }
662
+
663
+ //if custom filter is set or changed then reset masonry columns
664
+ if (currentFeed.customFilterChanged == true) {
665
+ jQuery(this).html('');
666
+ currentFeed.imageIndex = 0;
667
+ }
668
+
669
+ //check if pagination is enabled then each page should have resetted colEnds
670
+ //else give previous colEnds
671
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
672
+ masonryColEnds.push(0);
673
+ } else {
674
+ masonryColEnds.push(jQuery(this).height());
675
+ }
676
+
677
+ masonryColumns.push(jQuery(this));
678
+ });
679
+
680
+ //if custom filter is set or changed then reset masonry columns
681
+ if (currentFeed.customFilterChanged == true) {
682
+ currentFeed.customFilterChanged = false;
683
+ }
684
+
685
+
686
+ //loop for displaying items
687
+ for (var i = 0; i < data.length; i++) {
688
+
689
+ currentFeed.displayedData.push(data[i]);
690
+ /*carousel feature*/
691
+ if (data[i]['type'] == 'image') {
692
+ var photoTemplate = wdi_front.getPhotoTemplate(currentFeed);
693
+ } else if(data[i].hasOwnProperty('videos')) {
694
+ var photoTemplate = wdi_front.getVideoTemplate(currentFeed);
695
+ }
696
+ else{
697
+ var photoTemplate = wdi_front.getSliderTemplate(currentFeed);
698
+ }
699
+
700
+ var rawItem = data[i];
701
+ var item = wdi_front.createObject(rawItem, currentFeed);
702
+ var html = photoTemplate(item);
703
+
704
+ //find column with minumum height and append to it new object
705
+ var shortCol = wdi_front.array_min(masonryColEnds);
706
+ var imageResolution = wdi_front.getImageResolution(data[i]);
707
+
708
+ masonryColumns[shortCol['index']].html(masonryColumns[shortCol['index']].html() + html);
709
+ masonryColEnds[shortCol['index']] += masonryColumns[shortCol['index']].width() * imageResolution;
710
+ currentFeed.imageIndex++;
711
+
712
+
713
+ //changing responsive indexes for pagination
714
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
715
+ if ((i + 1) % currentFeed.feed_row.pagination_per_page_number === 0) {
716
+ currentFeed.resIndex += currentFeed.freeSpaces + 1;
717
+ } else {
718
+ currentFeed.resIndex++;
719
+ }
720
+ }
721
+ }
722
+
723
+
724
+ //binding onload event for ajax loader
725
+ currentFeed.wdi_loadedImages = 0;
726
+ var columnFlag = false;
727
+ currentFeed.wdi_load_count = i;
728
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
729
+ var feed_wrapper = jQuery('#wdi_feed_' + wdi_feed_counter + ' img.wdi_img').on('load', function ()
730
+ {
731
+ currentFeed.wdi_loadedImages++;
732
+ checkLoaded();
733
+
734
+ //calls wdi_responsive.columnControl() which calculates column number on page
735
+ //and gives feed_wrapper proper column class
736
+ if (columnFlag === false) {
737
+ wdi_responsive.columnControl(currentFeed, 1);
738
+ columnFlag = true;
739
+ }
740
+
741
+ //Binds caption opening and closing event to each image photo_title/mmmmmm
742
+ // if (currentFeed.feed_row.feed_type != 'blog_style') {
743
+ // wdi_responsive.bindMasonryCaptionEvent(jQuery(this).parent().parent().parent().parent().find('.wdi_photo_title'), currentFeed);
744
+ // }
745
+
746
+ });
747
+
748
+
749
+ /**
750
+ * if feed type is not blog style then after displaying images assign click evetns to their captions
751
+ * this part of code is a bit differenet from free version because of image lazy loading feature
752
+ *
753
+ * in free version events are assigned directly in onload event, but when lazy loading added it cased duplicate event fireing
754
+ * so event assigning moved to here
755
+ *
756
+ */
757
+ // if ( currentFeed.feed_row.feed_type != 'blog_style' ){
758
+ // jQuery('#wdi_feed_'+currentFeed.feed_row.wdi_feed_counter+' .wdi_photo_title').each(function(){
759
+ // wdi_responsive.bindMasonryCaptionEvent(jQuery(this),currentFeed);
760
+ // });
761
+ // }
762
+
763
+
764
+ //checks if all iamges have been succesfully loaded then it updates variables for next time use
765
+ function checkLoaded()
766
+ {
767
+
768
+ if (currentFeed.wdi_load_count === currentFeed.wdi_loadedImages && currentFeed.wdi_loadedImages != 0) {
769
+ currentFeed.loadedImages = 0;
770
+ currentFeed.wdi_load_count = 0;
771
+ wdi_front.allImagesLoaded(currentFeed);
772
+
773
+ }
774
+ }
775
 
776
+ //checking if pagination next button was clicked then change page
777
+ if (currentFeed.paginatorNextFlag == true) {
778
+ wdi_front.updatePagination(currentFeed, 'next');
779
+ }
780
+
781
+ //check if load more done successfully then set infinite scroll flag to false
782
+ currentFeed.infiniteScrollFlag = false;
783
 
784
 
785
  }
791
  wdi_front.getImageResolution = function (data)
792
  {
793
 
794
+ var originalWidth = data['images']['standard_resolution']['width'];
795
+ var originalHeight = data['images']['standard_resolution']['height'];
796
+ var resolution = originalHeight / originalWidth;
797
+ return resolution;
798
  }
799
 
800
  /*
804
  wdi_front.getDataLength = function (currentFeed, customStorage)
805
  {
806
 
807
+ var length = 0;
808
+ if (typeof customStorage === 'undefined') {
809
+ for (var j = 0; j < currentFeed.dataStorage.length; j++) {
810
+ length += currentFeed.dataStorage[j].length;
811
+ }
812
+ } else {
813
+ for (var j = 0; j < customStorage.length; j++) {
814
+ length += customStorage[j].length;
815
+ }
816
+ }
817
 
818
+ return length;
819
  }
820
 
821
  wdi_front.getArrayContentLength = function (array, data)
822
  {
823
+ var sum = 0;
824
+ for (var i = 0; i < array.length; i++) {
825
+ if (array[i]['finished'] == 'finished') {
826
+ continue;
827
+ }
828
+ sum += array[i][data].length;
829
+ }
830
+ return sum;
831
  }
832
 
833
 
838
  */
839
  wdi_front.displayFeedItems = function (data, currentFeed)
840
  {
841
+ if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + " .wdi_feed_wrapper").length == 0) {
842
+ //no feed in DOM, ignore
843
+ return;
844
+ }
845
 
846
+ //gets ready data, gets data template, and appens it into feed_wrapper
847
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
848
+ var feed_wrapper = jQuery('#wdi_feed_' + wdi_feed_counter + ' .wdi_feed_wrapper');
 
 
 
 
 
 
849
 
850
+ //if resort_after_pagination is on then rewrite feed data
851
+ if (currentFeed.feed_row['resort_after_load_more'] === '1') {
852
+ feed_wrapper.html('');
853
+ currentFeed.imageIndex = 0;
854
+ }
855
+
856
+ //if custom filter is set or changed then reset masonry columns
857
+ if (currentFeed.customFilterChanged == true) {
858
+ feed_wrapper.html('');
859
+ currentFeed.imageIndex = 0;
860
+ currentFeed.customFilterChanged = false;
861
+ }
 
 
 
 
 
 
 
 
862
 
863
 
864
+ var lastIndex = wdi_front.getImgCount(currentFeed) - data.length - 1;
865
+
866
+ /**
867
+ * if feed display view is set to pagination then check if the current page has not enough photos to be a complete page then
868
+ * --currentPage so that after loading new images we stay on the same page and see new images which will be located in that page
869
+ * also do the same thing when recievied data has lenght equal to zero
870
+ */
871
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
872
+ if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + ' [wdi_page="' + (currentFeed.currentPage - 1) + '"]').length < currentFeed.feed_row.load_more_number || data.length == 0) {
873
+ currentFeed.currentPage = (--currentFeed.currentPage <= 1) ? 1 : currentFeed.currentPage;
874
+ }
875
+ }
876
+
877
+
878
+ for (var i = 0; i < data.length; i++) {
879
+
880
+ if (data[i]['type'] == 'image') {
881
+ var photoTemplate = wdi_front.getPhotoTemplate(currentFeed);
882
+ } else if(data[i].hasOwnProperty('videos')) {
883
+ var photoTemplate = wdi_front.getVideoTemplate(currentFeed);
884
+ }
885
+ else{
886
+ var photoTemplate = wdi_front.getSliderTemplate(currentFeed);
887
+ }
888
 
889
+ var rawItem = data[i];
890
+ var item = wdi_front.createObject(rawItem, currentFeed);
891
+ var html = photoTemplate(item);
892
+ feed_wrapper.html(feed_wrapper.html() + html);
893
 
894
+ currentFeed.imageIndex++;
895
 
896
 
897
+ //changing responsive indexes for pagination
898
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
899
+ if ((i + 1) % currentFeed.feed_row.pagination_per_page_number === 0) {
900
+ currentFeed.resIndex += currentFeed.freeSpaces + 1;
901
+ } else {
902
+ currentFeed.resIndex++;
903
+ }
904
 
905
+ }
906
 
907
+ }
908
 
909
 
910
+ //fixing last row in case of full caption is open
911
+ //for that triggering click twice to open and close caption text that will fix last row
912
+ /*ttt 1.1.12*/
913
+ //jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_feed_wrapper [wdi_index=' + lastIndex + '] .wdi_photo_title').trigger(wdi_front.clickOrTouch);
914
+ //jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_feed_wrapper [wdi_index=' + lastIndex + '] .wdi_photo_title').trigger(wdi_front.clickOrTouch);
915
 
916
 
917
+ //binding onload event for ajax loader
918
+ currentFeed.wdi_loadedImages = 0;
919
+ var columnFlag = false;
920
+ currentFeed.wdi_load_count = i;
921
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
922
+ var feed_wrapper = jQuery('#wdi_feed_' + wdi_feed_counter + ' img.wdi_img').on('load', function ()
923
+ {
924
+ currentFeed.wdi_loadedImages++;
925
+ checkLoaded();
926
 
927
+ //calls wdi_responsive.columnControl() which calculates column number on page
928
+ //and gives feed_wrapper proper column class
929
+ if (columnFlag === false) {
930
 
931
 
932
+ wdi_responsive.columnControl(currentFeed, 1);
933
+ columnFlag = true;
934
+ }
935
 
936
 
937
+ // //Binds caption opening and closing event to each image photo_title/mmmmmm
938
+ // if (currentFeed.feed_row.feed_type != 'blog_style') {
939
+ // wdi_responsive.bindCaptionEvent(jQuery(this).parent().parent().parent().parent().find('.wdi_photo_title'), currentFeed);
940
+ // }
941
+ });
942
 
943
 
944
+ /**
945
+ * if feed type is not blog style then after displaying images assign click evetns to their captions
946
+ * this part of code is a bit differenet from free version because of image lazy loading feature
947
+ *
948
+ * in free version events are assigned directly in onload event, but when lazy loading added it cased duplicate event fireing
949
+ * so event assigning moved to here
950
+ *
951
+ */
952
+ // if ( currentFeed.feed_row.feed_type != 'blog_style' ){
953
+ // jQuery('#wdi_feed_'+currentFeed.feed_row.wdi_feed_counter+' .wdi_photo_title').each(function(){
954
+ // wdi_responsive.bindCaptionEvent(jQuery(this),currentFeed);
955
+ // });
956
 
957
+ // }
958
 
959
 
960
+ //checks if all iamges have been succesfully loaded then it updates variables for next time use
961
+ function checkLoaded()
962
+ {
963
+ if (currentFeed.wdi_load_count === currentFeed.wdi_loadedImages && currentFeed.wdi_loadedImages != 0) {
964
+ currentFeed.loadedImages = 0;
965
+ currentFeed.wdi_load_count = 0;
966
+ wdi_front.allImagesLoaded(currentFeed);
967
 
968
+ }
969
+ }
970
 
971
+ //checking if pagination next button was clicked then change page
972
+ if (currentFeed.paginatorNextFlag == true) {
973
+ wdi_front.updatePagination(currentFeed, 'next');
974
+ }
975
 
976
+ //check if load more done successfully then set infinite scroll flag to false
977
+ currentFeed.infiniteScrollFlag = false;
978
 
979
  }
980
 
981
  wdi_front.checkFeedFinished = function (currentFeed)
982
  {
983
+ for (var i = 0; i < currentFeed.usersData.length; i++) {
984
+ if (typeof currentFeed.usersData[i]['finished'] == 'undefined') {
985
+ return false;
986
+ }
987
+ }
988
+ return true;
989
  }
990
 
991
  wdi_front.sortingOperator = function (sortImagesBy, sortOrder)
992
  {
993
+ var operator;
994
+ switch (sortImagesBy) {
995
+ case 'date':
996
+ {
997
+ switch (sortOrder) {
998
+ case 'asc':
999
+ {
1000
+ operator = function (a, b)
1001
+ {
1002
+ return (a['created_time'] > b['created_time']) ? 1 : -1;
1003
+ }
1004
+ break;
1005
+ }
1006
+ case 'desc':
1007
+ {
1008
+ operator = function (a, b)
1009
+ {
1010
+ return (a['created_time'] > b['created_time']) ? -1 : 1;
1011
+ }
1012
+ break;
1013
+ }
1014
+ }
1015
+ break;
1016
+ }
1017
+ case 'likes':
1018
+ {
1019
+ switch (sortOrder) {
1020
+ case 'asc':
1021
+ {
1022
+ operator = function (a, b)
1023
+ {
1024
+ return (a['likes']['count'] < b['likes']['count']) ? -1 : 1;
1025
+ }
1026
+ break;
1027
+ }
1028
+ case 'desc':
1029
+ {
1030
+ operator = function (a, b)
1031
+ {
1032
+ return (a['likes']['count'] < b['likes']['count']) ? 1 : -1;
1033
+ }
1034
+ break;
1035
+ }
1036
+ }
1037
+ break;
1038
+ }
1039
+ case 'comments':
1040
+ {
1041
+ switch (sortOrder) {
1042
+ case 'asc':
1043
+ {
1044
+ operator = function (a, b)
1045
+ {
1046
+ return (a['comments']['count'] < b['comments']['count']) ? -1 : 1;
1047
+ }
1048
+ break;
1049
+ }
1050
+ case 'desc':
1051
+ {
1052
+ operator = function (a, b)
1053
+ {
1054
+ return (a['comments']['count'] < b['comments']['count']) ? 1 : -1;
1055
+ }
1056
+ break;
1057
+ }
1058
+ }
1059
+ break;
1060
+ }
1061
+ case 'random':
1062
+ {
1063
+ operator = function (a, b)
1064
+ {
1065
+ var num = Math.random();
1066
+ return (num > 0.5) ? 1 : -1;
1067
+ }
1068
+ break;
1069
+ }
1070
+ }
1071
+ return operator;
1072
  }
1073
 
1074
  /*
1077
  wdi_front.feedSort = function (currentFeed, load_more_number)
1078
  {
1079
 
1080
+ var sortImagesBy = currentFeed.feed_row['sort_images_by'];
1081
+ var sortOrder = currentFeed.feed_row['display_order'];
1082
 
1083
+ if (currentFeed.feed_row['resort_after_load_more'] === '1') {
1084
+ currentFeed['data'] = currentFeed['data'].concat(wdi_front.smartPicker(currentFeed, load_more_number));
1085
+ } else {
1086
+ currentFeed['data'] = wdi_front.smartPicker(currentFeed, load_more_number);
1087
+ }
1088
 
1089
 
1090
+ var operator = wdi_front.sortingOperator(sortImagesBy, sortOrder);
1091
+ currentFeed['data'].sort(operator);
1092
+ return currentFeed['data'];
1093
 
1094
  }
1095
 
1100
  wdi_front.smartPicker = function (currentFeed, load_more_number)
1101
  {
1102
 
1103
+ var dataStorage = [];
1104
+ var dataLength = 0;
1105
+ var readyData = [];
1106
+ var perUser = Math.ceil(currentFeed['feed_row']['number_of_photos'] / currentFeed['usersData'].length);
1107
+ var number_of_photos = parseInt(currentFeed['feed_row']['number_of_photos']);
1108
+ var remainder = 0;
1109
 
1110
+ //check if loadmore was clicked
1111
+ if (load_more_number != '' && typeof load_more_number != 'undefined' && load_more_number != null) {
1112
+ number_of_photos = parseInt(load_more_number);
1113
+ perUser = Math.ceil(number_of_photos / wdi_front.activeUsersCount(currentFeed));
1114
+ }
1115
 
1116
 
1117
+ var sortOperator = function (a, b)
1118
+ {
1119
+ return (a['data'].length > b['data'].length) ? 1 : -1;
1120
+ }
1121
 
1122
+ var sortOperator1 = function (a, b)
1123
+ {
1124
+ return (a.length() > b.length()) ? 1 : -1;
1125
+ }
1126
 
1127
 
1128
+ // storing user data in global dataStoreageRaw variable
1129
+ currentFeed.storeRawData(currentFeed.usersData, 'dataStorageRaw');
1130
 
1131
+ //dataStorageRaw
1132
+ var dataStorageRaw = currentFeed['dataStorageRaw'].sort(sortOperator1);
1133
 
1134
+ //sorts user data desc
1135
+ var usersData = currentFeed['usersData'].sort(sortOperator);
1136
 
1137
 
1138
+ //picks data from users and updates pagination in request json
1139
+ //for next time call
1140
+ for (var i = 0; i < usersData.length; i++) {
1141
 
1142
+ remainder += perUser;
1143
 
1144
+ /* if data is less then amount for each user then pick all data */
1145
+ if (dataStorageRaw[i].length() <= remainder) {
1146
 
1147
+ /* update remainder */
1148
+ remainder -= dataStorageRaw[i].length();
1149
 
1150
+ /* get and store data */
1151
+ dataStorage.push(dataStorageRaw[i].getData(dataStorageRaw[i].length()));
1152
+ /* update data length */
1153
+ dataLength += dataStorage[dataStorage.length - 1].length;
1154
 
1155
 
1156
+ } else {
1157
+ if (dataLength + remainder > number_of_photos) {
1158
+ remainder = number_of_photos - dataLength;
1159
+ }
1160
 
1161
+ var pickedData = [];
1162
 
1163
 
1164
+ if (currentFeed['auto_trigger'] === false) {
1165
+ pickedData = pickedData.concat(dataStorageRaw[i].getData(remainder));
1166
+ } else {
1167
+ if (pickedData.length + wdi_front.getDataLength(currentFeed) + wdi_front.getDataLength(currentFeed, dataStorage) < currentFeed['feed_row']['number_of_photos']) {
1168
+ pickedData = pickedData.concat(dataStorageRaw[i].getData(remainder));
1169
+ }
1170
+ }
1171
 
1172
+ remainder = 0;
1173
 
1174
+ dataLength += pickedData.length;
1175
+ dataStorage.push(pickedData);
1176
 
1177
 
1178
+ }
1179
 
1180
 
1181
+ /*if (usersData[i]['data'].length <= remainder) {
1182
 
1183
+ var pagination = usersData[i]['pagination']['next_url'];
1184
+ if (usersData[i]['finished'] === undefined) {
1185
+ dataStorage.push(usersData[i]['data']);
1186
+ remainder -= usersData[i]['data'].length;
1187
+ dataLength += usersData[i]['data'].length;
1188
+ }
1189
 
1190
+ if (usersData[i]['finished'] === undefined) {
1191
+ if (pagination === undefined || pagination === '' || pagination === null) {
1192
+ usersData[i]['finished'] = 'finished';
1193
+ }
1194
+ }
1195
+ } else {
1196
+ if ((dataLength + remainder) > number_of_photos) {
1197
+ remainder = number_of_photos - dataLength;
1198
+ }
1199
+ var pickedData = [];
1200
+ var indexPuller = 0;
1201
+ for (var j = 0; j < remainder; j++) {
1202
+ if (currentFeed['auto_trigger'] === false) {
1203
+ if (usersData[i]['finished'] === undefined) {
1204
+ pickedData.push(usersData[i]['data'][j]);
1205
+ }
1206
+ } else {
1207
+ if (pickedData.length + wdi_front.getDataLength(currentFeed) + wdi_front.getDataLength(currentFeed, dataStorage) < currentFeed['feed_row']['number_of_photos']) {
1208
+ if (usersData[i]['finished'] === undefined) {
1209
+ pickedData.push(usersData[i]['data'][j]);
1210
+ }
1211
+ } else {
1212
+ indexPuller++;
1213
+ }
1214
+ }
1215
 
1216
+ }
1217
+ j -= indexPuller;
1218
 
1219
+ remainder = 0;
1220
 
1221
 
1222
 
1223
+ //updating pagination
1224
 
1225
 
1226
 
1227
+ //pushes picked data into local storage
1228
+ dataLength += pickedData.length;
1229
+ dataStorage.push(pickedData);
1230
 
1231
+ }*/
1232
+ }
1233
+ //checks if in golbal storage user already exisit then it adds new data to user old data
1234
+ //else it simple puches new user with it's data to global storage
1235
+ for (i = 0; i < dataStorage.length; i++) {
1236
+ if (typeof currentFeed.dataStorage[i] === 'undefined') {
1237
+ currentFeed.dataStorage.push(dataStorage[i]);
1238
+ } else {
1239
+ currentFeed.dataStorage[i] = currentFeed.dataStorage[i].concat(dataStorage[i]);
1240
+ }
1241
+ }
1242
 
1243
+ //parsing data for lightbox
1244
+ currentFeed.parsedData = wdi_front.parseLighboxData(currentFeed);
1245
 
1246
+ //combines together all avialable data in global storage and returns it
1247
+ for (i = 0; i < dataStorage.length; i++) {
1248
+ readyData = readyData.concat(dataStorage[i]);
1249
+ }
1250
 
1251
+ return readyData;
1252
  }
1253
 
1254
  /*
1257
  wdi_front.createObject = function (obj, currentFeed)
1258
  {
1259
 
1260
+ var caption = (obj['caption'] != null) ? obj['caption']['text'] : '&nbsp';
1261
+
1262
+ var image_url = '';
1263
+ var videoUrl = '';
1264
+
1265
+ if (window.innerWidth >= currentFeed.feed_row.mobile_breakpoint) {
1266
+ image_url = obj['images']['standard_resolution']['url'];
1267
+ if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1268
+ image_url = obj['link'] + 'media?size=l';
1269
+ }
1270
+ if (obj['type'] == 'video') {
1271
+ /*if pure video, not carousel*/
1272
+ videoUrl = obj.hasOwnProperty('videos') ? obj['videos']['standard_resolution']['url'] : '';
1273
+ }
1274
+ }
1275
+ if (window.innerWidth >= currentFeed.feed_row.mobile_breakpoint / 4 && window.innerWidth < currentFeed.feed_row.mobile_breakpoint) {
1276
+ image_url = obj['images']['low_resolution']['url'];
1277
+ if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1278
+ image_url = obj['link'] + 'media?size=l';
1279
+ }
1280
+ if (obj['type'] == 'video') {
1281
+ /*if pure video, not carousel*/
1282
+ videoUrl = obj.hasOwnProperty('videos') ? obj['videos']['low_bandwidth']['url'] : '';
1283
+ }
1284
+ }
1285
+ if (window.innerWidth < currentFeed.feed_row.mobile_breakpoint / 4) {
1286
+ image_url = obj['images']['thumbnail']['url'];
1287
+ if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1288
+ image_url = obj['link'] + 'media?size=m';
1289
+ }
1290
+ if (obj['type'] == 'video') {
1291
+ /*if pure video, not carousel*/
1292
+ videoUrl = obj.hasOwnProperty('videos') ? obj['videos']['low_resolution']['url'] : '';
1293
+ }
1294
+ }
1295
+
1296
+
1297
+ var imageIndex = currentFeed.imageIndex;
1298
+
1299
+ var photoObject = {
1300
+ 'id': obj['id'],
1301
+ 'caption': caption,
1302
+ 'image_url': image_url,
1303
+ 'likes': obj['likes']['count'],
1304
+ 'comments': obj['comments']['count'],
1305
+ 'wdi_index': imageIndex,
1306
+ 'wdi_res_index': currentFeed.resIndex,
1307
+ 'wdi_media_user': obj['user']['username'],
1308
+ 'link': obj['link'],
1309
+ 'video_url': videoUrl,
1310
+ 'wdi_username': obj['user']['username']
1311
+ };
1312
+ return photoObject;
1313
  }
1314
 
1315
  /*
1317
  */
1318
  wdi_front.setPage = function (currentFeed)
1319
  {
1320
+ var display_type = currentFeed.feed_row.feed_display_view;
1321
+ var feed_type = currentFeed.feed_row.feed_type;
1322
+ if (display_type != 'pagination') {
1323
+ return '';
1324
+ }
1325
+ var imageIndex = currentFeed.imageIndex;
1326
+ if (feed_type == 'image_browser') {
1327
+ var divider = 1;
1328
+ } else {
1329
+ var divider = Math.abs(currentFeed.feed_row.pagination_per_page_number);
1330
+ }
1331
 
1332
+ currentFeed.paginator = Math.ceil((imageIndex + 1) / divider);
1333
 
1334
 
1335
+ return currentFeed.paginator;
1336
  }
1337
 
1338
  /*
1340
  */
1341
  wdi_front.getPhotoTemplate = function (currentFeed)
1342
  {
1343
+ var page = wdi_front.setPage(currentFeed);
1344
+ var customClass = '';
1345
+ var pagination = '';
1346
+ var onclick = '';
1347
+ var overlayCustomClass = '';
1348
+ var thumbClass = 'fa-arrows-alt';
1349
+ var showUsernameOnThumb = '';
1350
+ if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1351
+ thumbClass = '';
1352
+ }
1353
+ if (page != '') {
1354
+ pagination = 'wdi_page="' + page + '"';
1355
+ sourceAttr = 'src';
1356
+ } else {
1357
+ sourceAttr = 'src';
1358
+ }
1359
+
1360
+ if (page != '' && page != 1) {
1361
+ customClass = 'wdi_hidden';
1362
+ }
1363
+
1364
+
1365
+ if (currentFeed.feed_row.show_username_on_thumb == '1') {
1366
+ showUsernameOnThumb = '<span class="wdi_media_user">@<%= wdi_username%></span>';
1367
+ }
1368
+
1369
+ //checking if caption is opend by default then add wdi_full_caption class
1370
+ //only in masonry
1371
+ if (currentFeed.feed_row.show_full_description == 1 && currentFeed.feed_row.feed_type == 'masonry') {
1372
+ customClass += ' wdi_full_caption';
1373
+ }
1374
+
1375
+ var onclickevent = "";
1376
+ if (currentFeed.feed_row.feed_type !== "blog_style") {
1377
+ if (currentFeed.feed_row.feed_type == 'masonry') {
1378
+ onclickevent = "wdi_responsive.showMasonryCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");"
1379
+ } else {
1380
+ onclickevent = "wdi_responsive.showCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");";
1381
+ }
1382
+
1383
+ }
1384
+
1385
+
1386
+ //creating onclick string for different options
1387
+ switch (currentFeed.feed_row.feed_item_onclick) {
1388
+ case 'lightbox':
1389
+ {
1390
+ onclick = "onclick=wdi_feed_" + currentFeed.feed_row.wdi_feed_counter + ".galleryBox('<%=id%>')";
1391
+ break;
1392
+ }
1393
+ case 'instagram':
1394
+ {
1395
+ onclick = 'onclick="window.open (\'<%= link%>\',\'_blank\')"';
1396
+ overlayCustomClass = 'wdi_hover_off';
1397
+ thumbClass = '';
1398
+ break;
1399
+ }
1400
+ case 'none':
1401
+ {
1402
+ onclick = '';
1403
+ overlayCustomClass = 'wdi_cursor_off wdi_hover_off';
1404
+ thumbClass = '';
1405
+ }
1406
+ }
1407
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
1408
+ var source = '<div class="wdi_feed_item ' + customClass + '" wdi_index=<%= wdi_index%> wdi_res_index=<%= wdi_res_index%> wdi_media_user=<%= wdi_media_user%> ' + pagination + ' wdi_type="image" id="wdi_' + wdi_feed_counter + '_<%=id%>">' +
1409
+ '<div class="wdi_photo_wrap">' +
1410
+ '<div class="wdi_photo_wrap_inner">' +
1411
+ '<div class="wdi_photo_img">' +
1412
+ '<img class="wdi_img" ' + sourceAttr + '="<%=image_url%>" alt="feed_image" onerror="wdi_front.brokenImageHandler(this);">' +
1413
+ '<div class="wdi_photo_overlay ' + overlayCustomClass + '" >' + showUsernameOnThumb +
1414
+ '<div class="wdi_thumb_icon" ' + onclick + ' style="display:table;width:100%;height:100%;">' +
1415
+ '<div style="display:table-cell;vertical-align:middle;text-align:center;color:white;">' +
1416
+ '<i class="fa ' + thumbClass + '"></i>' +
1417
+ '</div>' +
1418
+ '</div>' +
1419
+ '</div>' +
1420
+ '</div>' +
1421
+ '</div>' +
1422
+ '</div>';
1423
+ if (currentFeed['feed_row']['show_likes'] === '1' || currentFeed['feed_row']['show_comments'] === '1' || currentFeed['feed_row']['show_description'] === '1') {
1424
+ source += '<div class="wdi_photo_meta">';
1425
+ if (currentFeed['feed_row']['show_likes'] === '1') {
1426
+ source += '<div class="wdi_thumb_likes"><i class="fa fa-heart-o">&nbsp;<%= likes%></i></div>';
1427
+ }
1428
+ if (currentFeed['feed_row']['show_comments'] === '1') {
1429
+ source += '<div class="wdi_thumb_comments"><i class="fa fa-comment-o">&nbsp;<%= comments%></i></div>';
1430
+ }
1431
+ source += '<div class="wdi_clear"></div>';
1432
+ if (currentFeed['feed_row']['show_description'] === '1') {
1433
+ source += '<div class="wdi_photo_title" onclick=' + onclickevent + ' >' +
1434
+ '<%=caption%>' +
1435
+ '</div>';
1436
+ }
1437
+ source += '</div>';
1438
+ }
1439
+
1440
+ source += '</div>';
1441
+ var template = _.template(source);
1442
+ return template;
1443
+ }
1444
+
1445
+
1446
+ /*
1447
+ * Template for all feed items which have type=image
1448
+ */
1449
+ wdi_front.getSliderTemplate = function (currentFeed)
1450
+ {
1451
+ var page = wdi_front.setPage(currentFeed);
1452
+ var customClass = '';
1453
+ var pagination = '';
1454
+ var onclick = '';
1455
+ var overlayCustomClass = '';
1456
+ var thumbClass = 'fa-clone';
1457
+ var showUsernameOnThumb = '';
1458
+ if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1459
+ thumbClass = '';
1460
+ }
1461
+ if (page != '') {
1462
+ pagination = 'wdi_page="' + page + '"';
1463
+ sourceAttr = 'src';
1464
+ } else {
1465
+ sourceAttr = 'src';
1466
+ }
1467
+
1468
+ if (page != '' && page != 1) {
1469
+ customClass = 'wdi_hidden';
1470
+ }
1471
+
1472
+
1473
+ if (currentFeed.feed_row.show_username_on_thumb == '1') {
1474
+ showUsernameOnThumb = '<span class="wdi_media_user">@<%= wdi_username%></span>';
1475
+ }
1476
+
1477
+ //checking if caption is opend by default then add wdi_full_caption class
1478
+ //only in masonry
1479
+ if (currentFeed.feed_row.show_full_description == 1 && currentFeed.feed_row.feed_type == 'masonry') {
1480
+ customClass += ' wdi_full_caption';
1481
+ }
1482
+
1483
+ var onclickevent = "";
1484
+ if (currentFeed.feed_row.feed_type !== "blog_style") {
1485
+ if (currentFeed.feed_row.feed_type == 'masonry') {
1486
+ onclickevent = "wdi_responsive.showMasonryCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");"
1487
+ } else {
1488
+ onclickevent = "wdi_responsive.showCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");";
1489
+ }
1490
+
1491
+ }
1492
+
1493
+
1494
+ //creating onclick string for different options
1495
+ switch (currentFeed.feed_row.feed_item_onclick) {
1496
+ case 'lightbox':
1497
+ {
1498
+ onclick = "onclick=wdi_feed_" + currentFeed.feed_row.wdi_feed_counter + ".galleryBox('<%=id%>')";
1499
+ break;
1500
+ }
1501
+ case 'instagram':
1502
+ {
1503
+ onclick = 'onclick="window.open (\'<%= link%>\',\'_blank\')"';
1504
+ overlayCustomClass = 'wdi_hover_off';
1505
+ thumbClass = 'fa-clone';
1506
+ break;
1507
+ }
1508
+ case 'none':
1509
+ {
1510
+ onclick = '';
1511
+ overlayCustomClass = 'wdi_cursor_off wdi_hover_off';
1512
+ thumbClass = '';
1513
+ }
1514
+ }
1515
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
1516
+ var source = '<div class="wdi_feed_item ' + customClass + '" wdi_index=<%= wdi_index%> wdi_res_index=<%= wdi_res_index%> wdi_media_user=<%= wdi_media_user%> ' + pagination + ' wdi_type="slideshow" id="wdi_' + wdi_feed_counter + '_<%=id%>">' +
1517
+ '<div class="wdi_photo_wrap">' +
1518
+ '<div class="wdi_photo_wrap_inner">' +
1519
+ '<div class="wdi_photo_img">' +
1520
+ '<img class="wdi_img" ' + sourceAttr + '="<%=image_url%>" alt="feed_image" onerror="wdi_front.brokenImageHandler(this);">' +
1521
+ '<div class="wdi_photo_overlay ' + overlayCustomClass + '" >' + showUsernameOnThumb +
1522
+ '<div class="wdi_thumb_icon" ' + onclick + ' style="display:table;width:100%;height:100%;">' +
1523
+ '<div style="display:table-cell;vertical-align:middle;text-align:center;color:white;">' +
1524
+ '<i class="fa ' + thumbClass + '"></i>' +
1525
+ '</div>' +
1526
+ '</div>' +
1527
+ '</div>' +
1528
+ '</div>' +
1529
+ '</div>' +
1530
+ '</div>';
1531
+ if (currentFeed['feed_row']['show_likes'] === '1' || currentFeed['feed_row']['show_comments'] === '1' || currentFeed['feed_row']['show_description'] === '1') {
1532
+ source += '<div class="wdi_photo_meta">';
1533
+ if (currentFeed['feed_row']['show_likes'] === '1') {
1534
+ source += '<div class="wdi_thumb_likes"><i class="fa fa-heart-o">&nbsp;<%= likes%></i></div>';
1535
+ }
1536
+ if (currentFeed['feed_row']['show_comments'] === '1') {
1537
+ source += '<div class="wdi_thumb_comments"><i class="fa fa-comment-o">&nbsp;<%= comments%></i></div>';
1538
+ }
1539
+ source += '<div class="wdi_clear"></div>';
1540
+ if (currentFeed['feed_row']['show_description'] === '1') {
1541
+ source += '<div class="wdi_photo_title" onclick=' + onclickevent + ' >' +
1542
+ '<%=caption%>' +
1543
+ '</div>';
1544
+ }
1545
+ source += '</div>';
1546
+ }
1547
+
1548
+ source += '</div>';
1549
+ var template = _.template(source);
1550
+ return template;
1551
  }
1552
 
1553
  wdi_front.replaceToVideo = function (url, index, feed_counter)
1554
  {
1555
 
1556
+ overlayHtml = "<video style='width:auto !important; height:auto !important; max-width:100% !important; max-height:100% !important; margin:0 !important;' controls=''>" +
1557
+ "<source src='" + url + "' type='video/mp4'>" +
1558
+ "Your browser does not support the video tag. </video>";
1559
 
1560
+ jQuery('#wdi_feed_' + feed_counter + ' [wdi_index="' + index + '"] .wdi_photo_wrap_inner').html(overlayHtml);
1561
+ jQuery('#wdi_feed_' + feed_counter + ' [wdi_index="' + index + '"] .wdi_photo_wrap_inner video').get(0).play();
1562
  }
1563
 
1564
  /*
1566
  */
1567
  wdi_front.getVideoTemplate = function (currentFeed)
1568
  {
1569
+ var page = wdi_front.setPage(currentFeed);
1570
+ var customClass = '';
1571
+ var pagination = '';
1572
+ var thumbClass = 'fa-play';
1573
+ var onclick = '';
1574
+ var overlayCustomClass = '';
1575
+ var sourceAttr;
1576
+ var showUsernameOnThumb = '';
1577
+
1578
+
1579
+ if (page != '') {
1580
+ pagination = 'wdi_page="' + page + '"';
1581
+ sourceAttr = 'src';
1582
+ } else {
1583
+ sourceAttr = 'src';
1584
+ }
1585
+ if (page != '' && page != 1) {
1586
+ customClass = 'wdi_hidden';
1587
+ }
1588
+
1589
+ if (currentFeed.feed_row.show_username_on_thumb == '1') {
1590
+ showUsernameOnThumb = '<span class="wdi_media_user">@<%= wdi_username%></span>';
1591
+ }
1592
+
1593
+ //checking if caption is opend by default then add wdi_full_caption class
1594
+ //only in masonry
1595
+ if (currentFeed.feed_row.show_full_description == 1 && currentFeed.feed_row.feed_type == 'masonry') {
1596
+ customClass += ' wdi_full_caption';
1597
+ }
1598
+
1599
+ var onclickevent = "";
1600
+ if (currentFeed.feed_row.feed_type !== "blog_style") {
1601
+ if (currentFeed.feed_row.feed_type == 'masonry') {
1602
+ onclickevent = "wdi_responsive.showMasonryCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");"
1603
+ } else {
1604
+ onclickevent = "wdi_responsive.showCaption(jQuery(this)," + currentFeed.feed_row.wdi_feed_counter + ");";
1605
+ }
1606
+
1607
+ }
1608
+
1609
+ //creating onclick string for different options
1610
+ switch (currentFeed.feed_row.feed_item_onclick) {
1611
+ case 'lightbox':
1612
+ {
1613
+ onclick = "onclick=wdi_feed_" + currentFeed.feed_row.wdi_feed_counter + ".galleryBox('<%=id%>')";
1614
+ break;
1615
+ }
1616
+ case 'instagram':
1617
+ {
1618
+ onclick = 'onclick="window.open (\'<%= link%>\',\'_blank\')"';
1619
+ overlayCustomClass = 'wdi_hover_off';
1620
+ thumbClass = 'fa-play';
1621
+ break;
1622
+ }
1623
+ case 'none':
1624
+ {
1625
+ overlayCustomClass = 'wdi_cursor_off wdi_hover_off';
1626
+ thumbClass = '';
1627
+ if (currentFeed.feed_row.feed_type == 'blog_style' || currentFeed.feed_row.feed_type == 'image_browser') {
1628
+ onclick = "onclick=wdi_front.replaceToVideo('<%= video_url%>','<%= wdi_index%>'," + currentFeed.feed_row.wdi_feed_counter + ")";
1629
+ overlayCustomClass = '';
1630
+ thumbClass = 'fa-play';
1631
+ }
1632
+ }
1633
+ }
1634
+
1635
+
1636
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
1637
+ var source = '<div class="wdi_feed_item ' + customClass + '" wdi_index=<%= wdi_index%> wdi_res_index=<%= wdi_res_index%> wdi_media_user=<%= wdi_media_user%> ' + pagination + ' wdi_type="image" id="wdi_' + wdi_feed_counter + '_<%=id%>">' +
1638
+ '<div class="wdi_photo_wrap">' +
1639
+ '<div class="wdi_photo_wrap_inner">' +
1640
+ '<div class="wdi_photo_img">' +
1641
+ '<img class="wdi_img" ' + sourceAttr + '="<%=image_url%>" alt="feed_image" onerror="wdi_front.brokenImageHandler(this);">' +
1642
+ '<div class="wdi_photo_overlay ' + overlayCustomClass + '" ' + onclick + '>' + showUsernameOnThumb +
1643
+ '<div class="wdi_thumb_icon" style="display:table;width:100%;height:100%;">' +
1644
+ '<div style="display:table-cell;vertical-align:middle;text-align:center;color:white;">' +
1645
+ '<i class="fa ' + thumbClass + '"></i>' +
1646
+ '</div>' +
1647
+ '</div>' +
1648
+ '</div>' +
1649
+ '</div>' +
1650
+ '</div>' +
1651
+ '</div>';
1652
+ if (currentFeed['feed_row']['show_likes'] === '1' || currentFeed['feed_row']['show_comments'] === '1' || currentFeed['feed_row']['show_description'] === '1') {
1653
+ source += '<div class="wdi_photo_meta">';
1654
+ if (currentFeed['feed_row']['show_likes'] === '1') {
1655
+ source += '<div class="wdi_thumb_likes"><i class="fa fa-heart-o">&nbsp;<%= likes%></i></div>';
1656
+ }
1657
+ if (currentFeed['feed_row']['show_comments'] === '1') {
1658
+ source += '<div class="wdi_thumb_comments"><i class="fa fa-comment-o">&nbsp;<%= comments%></i></div>';
1659
+ }
1660
+ source += '<div class="wdi_clear"></div>';
1661
+ if (currentFeed['feed_row']['show_description'] === '1') {
1662
+ source += '<div class="wdi_photo_title" onclick=' + onclickevent + ' >' +
1663
+ '<%=caption%>' +
1664
+ '</div>';
1665
+ }
1666
+ source += '</div>';
1667
+ }
1668
+ source += '</div>';
1669
+ var template = _.template(source);
1670
+ return template;
1671
  }
1672
 
1673
  wdi_front.bindEvents = function (currentFeed)
1674
  {
1675
 
1676
+ if (jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + " .wdi_feed_wrapper").length == 0) {
1677
+ //no feed in DOM, ignore
1678
+ return;
1679
+ }
1680
+
1681
+ if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
1682
+ //binding load more event
1683
+ jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_load_more_container').on(wdi_front.clickOrTouch, function ()
1684
+ {
1685
+ //do the actual load more operation
1686
+ wdi_front.loadMore(jQuery(this).find('.wdi_load_more_wrap'));
1687
+
1688
+ });
1689
+ }
1690
+
1691
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
1692
+ //binding pagination events
1693
+ jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_next').on(wdi_front.clickOrTouch, function ()
1694
+ {
1695
+ wdi_front.paginatorNext(jQuery(this), currentFeed);
1696
+ });
1697
+ jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_prev').on(wdi_front.clickOrTouch, function ()
1698
+ {
1699
+ wdi_front.paginatorPrev(jQuery(this), currentFeed);
1700
+ });
1701
+ jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_last_page').on(wdi_front.clickOrTouch, function ()
1702
+ {
1703
+ wdi_front.paginationLastPage(jQuery(this), currentFeed);
1704
+ });
1705
+ jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_first_page').on(wdi_front.clickOrTouch, function ()
1706
+ {
1707
+ wdi_front.paginationFirstPage(jQuery(this), currentFeed);
1708
+ });
1709
+ //setting pagiantion flags
1710
+ currentFeed.paginatorNextFlag = false;
1711
+ }
1712
+ if (currentFeed.feed_row.feed_display_view == 'infinite_scroll') {
1713
+ //binding infinite scroll Events
1714
+ jQuery(window).on('scroll', function ()
1715
+ {
1716
+ wdi_front.infiniteScroll(currentFeed);
1717
+ });
1718
+ //infinite scroll flags
1719
+ currentFeed.infiniteScrollFlag = false;
1720
+ }
1721
 
1722
 
1723
  }
1725
  wdi_front.infiniteScroll = function (currentFeed)
1726
  {
1727
 
1728
+ if (jQuery(window).scrollTop() <= jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_infinite_scroll').offset().top) {
1729
+ if (currentFeed.infiniteScrollFlag === false && currentFeed.stopInfiniteScrollFlag == false) {
1730
+ currentFeed.infiniteScrollFlag = true;
1731
+ wdi_front.loadMore(jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' #wdi_infinite_scroll'), currentFeed);
1732
+ } else
1733
+ if (currentFeed.stopInfiniteScrollFlag) {
1734
+ wdi_front.allImagesLoaded(currentFeed);
1735
+ }
1736
 
1737
+ }
1738
  }
1739
 
1740
 
1741
  wdi_front.paginationFirstPage = function (btn, currentFeed)
1742
  {
1743
+ if (currentFeed.paginator == 1 || currentFeed.currentPage == 1) {
1744
+ btn.addClass('wdi_disabled');
1745
+ return;
1746
+ }
1747
+ var oldPage = currentFeed.currentPage;
1748
+ currentFeed.currentPage = 1;
1749
+ wdi_front.updatePagination(currentFeed, 'custom', oldPage);
1750
 
1751
+ //enable last page button
1752
+ var last_page_btn = btn.parent().find('#wdi_last_page');
1753
+ last_page_btn.removeClass('wdi_disabled');
1754
 
1755
+ //disabling first page button
1756
+ btn.addClass('wdi_disabled');
1757
 
1758
  }
1759
 
1760
  wdi_front.paginationLastPage = function (btn, currentFeed)
1761
  {
1762
+ if (currentFeed.paginator == 1 || currentFeed.currentPage == currentFeed.paginator) {
1763
+ return;
1764
+ }
1765
+ var oldPage = currentFeed.currentPage;
1766
+ currentFeed.currentPage = currentFeed.paginator;
1767
+ wdi_front.updatePagination(currentFeed, 'custom', oldPage);
1768
 
1769
+ //disableing last page button
1770
+ btn.addClass('wdi_disabled');
1771
 
1772
+ //enabling first page button
1773
+ var first_page_btn = btn.parent().find('#wdi_first_page');
1774
+ first_page_btn.removeClass('wdi_disabled');
1775
  }
1776
 
1777
  wdi_front.paginatorNext = function (btn, currentFeed)
1778
  {
1779
+ var last_page_btn = btn.parent().find('#wdi_last_page');
1780
+ var first_page_btn = btn.parent().find('#wdi_first_page');
1781
+ currentFeed.paginatorNextFlag = true;
1782
+ if (currentFeed.paginator == currentFeed.currentPage && !wdi_front.checkFeedFinished(currentFeed)) {
1783
+ currentFeed.currentPage++;
1784
+ var number_of_photos = currentFeed.feed_row.number_of_photos;
1785
+ wdi_front.loadMore(btn, currentFeed, number_of_photos);
1786
+ //on the last page don't show got to last page button
1787
+ last_page_btn.addClass('wdi_disabled');
1788
+ } else
1789
+ if (currentFeed.paginator > currentFeed.currentPage) {
1790
+ currentFeed.currentPage++;
1791
+ wdi_front.updatePagination(currentFeed, 'next');
1792
+ //check if new page isn't the last one then enable last page button
1793
+ if (currentFeed.paginator > currentFeed.currentPage) {
1794
+ last_page_btn.removeClass('wdi_disabled');
1795
+ } else {
1796
+ last_page_btn.addClass('wdi_disabled');
1797
+ }
1798
+ }
1799
+
1800
+ //enable first page button
1801
+ first_page_btn.removeClass('wdi_disabled');
1802
 
1803
 
1804
  }
1805
 
1806
  wdi_front.paginatorPrev = function (btn, currentFeed)
1807
  {
1808
+ var last_page_btn = btn.parent().find('#wdi_last_page');
1809
+ var first_page_btn = btn.parent().find('#wdi_first_page');
1810
+ if (currentFeed.currentPage == 1) {
1811
+ first_page_btn.addClass('wdi_disabled');
1812
+ return;
1813
+ }
1814
 
1815
+ currentFeed.currentPage--;
1816
+ wdi_front.updatePagination(currentFeed, 'prev');
1817
 
1818
+ //enable last page button
1819
+ last_page_btn.removeClass('wdi_disabled');
1820
 
1821
+ if (currentFeed.currentPage == 1) {
1822
+ first_page_btn.addClass('wdi_disabled');
1823
+ }
1824
 
1825
  }
1826
 
1827
  //displays proper images for specific page after pagination buttons click event
1828
  wdi_front.updatePagination = function (currentFeed, dir, oldPage)
1829
  {
1830
+ var currentFeedString = '#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'];
1831
+ jQuery(currentFeedString + ' [wdi_page="' + currentFeed.currentPage + '"]').each(function ()
1832
+ {
1833
+ jQuery(this).removeClass('wdi_hidden');
1834
+ });
1835
+ switch (dir) {
1836
+ case 'next':
1837
+ {
1838
+ var oldPage = currentFeed.currentPage - 1;
1839
+ jQuery(currentFeedString + ' .wdi_feed_wrapper').height(jQuery('.wdi_feed_wrapper').height());
1840
+ jQuery(currentFeedString + ' [wdi_page="' + oldPage + '"]').each(function ()
1841
+ {
1842
+ jQuery(this).addClass('wdi_hidden');
1843
+ });
1844
+ break;
1845
+ }
1846
+ case 'prev':
1847
+ {
1848
+ var oldPage = currentFeed.currentPage + 1;
1849
+ jQuery(currentFeedString + ' .wdi_feed_wrapper').height(jQuery('.wdi_feed_wrapper').height());
1850
+ jQuery(currentFeedString + ' [wdi_page="' + oldPage + '"]').each(function ()
1851
+ {
1852
+ jQuery(this).addClass('wdi_hidden');
1853
+ });
1854
+ break;
1855
+ }
1856
+ case 'custom':
1857
+ {
1858
+ var oldPage = oldPage;
1859
+ if (oldPage != currentFeed.currentPage) {
1860
+ jQuery(currentFeedString + ' .wdi_feed_wrapper').height(jQuery('.wdi_feed_wrapper').height());
1861
+ jQuery(currentFeedString + ' [wdi_page="' + oldPage + '"]').each(function ()
1862
+ {
1863
+ jQuery(this).addClass('wdi_hidden');
1864
+ });
1865
+ }
1866
+
1867
+ break;
1868
+ }
1869
+ }
1870
+ currentFeed.paginatorNextFlag = false;
1871
+
1872
+ jQuery(currentFeedString + ' .wdi_feed_wrapper').css('height', 'auto');
1873
+ jQuery(currentFeedString + ' #wdi_current_page').text(currentFeed.currentPage);
1874
  }
1875
 
1876
 
1878
  {
1879
 
1880
 
1881
+ var dataCounter = 0;
1882
+ if (button != '' && typeof button != 'undefined' && button != 'initial' && button != 'initial-keep') {
1883
+ var currentFeed = window[button.parent().parent().parent().parent().attr('id')];
1884
+ }
1885
+ if (typeof _currentFeed != 'undefined') {
1886
+ var currentFeed = _currentFeed;
1887
+ }
1888
+ //check if any filter is enabled and filter user images has finished
1889
+ //then stop any load more action
1890
+ var activeFilter = 0,
1891
+ finishedFilter = 0;
1892
+ for (var i = 0; i < currentFeed.userSortFlags.length; i++) {
1893
+ if (currentFeed.userSortFlags[i].flag === true) {
1894
+ activeFilter++;
1895
+ for (var j = 0; j < currentFeed.usersData.length; j++) {
1896
+ if (currentFeed.userSortFlags[i]['id'] === currentFeed.usersData[j]['user_id']) {
1897
+ if (currentFeed.usersData[j]['finished'] === 'finished') {
1898
+ finishedFilter++;
1899
+ }
1900
+ }
1901
+ }
1902
+ }
1903
+ }
1904
+ if (activeFilter === finishedFilter && activeFilter != 0) {
1905
+ return;
1906
+ }
1907
+
1908
+
1909
+ //if button is not provided than it enables auto_tiggering and recursively loads images
1910
+ if (button === '') {
1911
+ currentFeed['auto_trigger'] = true;
1912
+ } else {
1913
+ currentFeed['auto_trigger'] = false;
1914
+ }
1915
+ //ading ajax loading
1916
+ wdi_front.ajaxLoader(currentFeed);
1917
+
1918
+
1919
+ //check if masonry view is on and and feed display type is pagination then
1920
+ //close all captions before loading more pages for porper pagination rendering
1921
+ if (currentFeed.feed_row.feed_type === 'masonry' && currentFeed.feed_row.feed_display_view == 'pagination') {
1922
+ jQuery('#wdi_feed_' + wdi_front.feed_counter + ' .wdi_full_caption').each(function ()
1923
+ {
1924
+ jQuery(this).find('.wdi_photo_title').trigger(wdi_front.clickOrTouch);
1925
+ });
1926
+ }
1927
+
1928
+
1929
+ //check if all data loaded then remove ajaxLoader
1930
+ for (var i = 0; i < currentFeed.usersData.length; i++) {
1931
+ if (currentFeed.usersData[i]['finished'] === 'finished') {
1932
+ dataCounter++;
1933
+ }
1934
+ }
1935
+ if (dataCounter === currentFeed.usersData.length) {
1936
+ wdi_front.allImagesLoaded(currentFeed);
1937
+ jQuery('#wdi_feed_' + currentFeed['feed_row']['wdi_feed_counter'] + ' .wdi_load_more').remove();
1938
+
1939
+ }
1940
+
1941
+ var usersData = currentFeed['usersData'];
1942
+
1943
+ currentFeed.loadMoreDataCount = currentFeed.feed_users.length;
1944
+
1945
+ for (var i = 0; i < usersData.length; i++) {
1946
+
1947
+ var pagination = usersData[i]['pagination'];
1948
+ var user = {
1949
+ user_id: usersData[i]['user_id'],
1950
+ username: usersData[i]['username']
1951
+ }
1952
+
1953
+ //checking if pagination url exists then load images, else skip
1954
+ if (pagination['next_url'] != '' && pagination['next_url'] != null && typeof pagination['next_url'] != 'undefined') {
1955
+ var next_url = pagination['next_url'];
1956
+ wdi_front.loadMoreRequest(user, next_url, currentFeed, button);
1957
+ } else {
1958
+
1959
+ if (button == 'initial-keep') {
1960
+ currentFeed.temproraryUsersData[i] = currentFeed.usersData[i];
1961
+ }
1962
+ currentFeed.loadMoreDataCount--;
1963
+
1964
+
1965
+ wdi_front.checkForLoadMoreDone(currentFeed, button);
1966
+ continue;
1967
+ }
1968
+ }
1969
 
1970
 
1971
  }
1976
  wdi_front.loadMoreRequest = function (user, next_url, currentFeed, button)
1977
  {
1978
 
1979
+ var usersData = currentFeed['usersData'];
1980
+ var errorMessage = '';
1981
+
1982
+ currentFeed.instagram.requestByUrl(next_url, {
1983
+ success: function (response)
1984
+ {
1985
+ if (response === '' || typeof response == 'undefined' || response == null) {
1986
+ errorMessage = wdi_front_messages.network_error;
1987
+ currentFeed.loadMoreDataCount--;
1988
+ wdi_front.show_alert(errorMessage);
1989
+ return;
1990
+ }
1991
+ if (response['meta']['code'] != 200) {
1992
+ errorMessage = response['meta']['error_message'];
1993
+ currentFeed.loadMoreDataCount--;
1994
+ wdi_front.show_alert(errorMessage);
1995
+ return;
1996
+ }
1997
+
1998
+ response['user_id'] = user.user_id;
1999
+ response['username'] = user.username;
2000
+
2001
+ for (var i = 0; i < currentFeed['usersData'].length; i++) {
2002
+ if (response['user_id'] === currentFeed['usersData'][i]['user_id']) {
2003
+
2004
+ ///mmm!!!
2005
+ if (response['user_id'][0] === '#') {
2006
+ response['data'] = wdi_front.appendRequestHashtag(response['data'], response['user_id']);
2007
+ }
2008
+ ////////////////
2009
+ /*if button is initial-keep then we will lose currentFeed['usersData'][i]
2010
+ for not loosing it we keep it in currentFeed.temproraryUsersData, which value will be
2011
+ used later in wdi_front.checkForLoadMoreDone(), in other cases when button is set to
2012
+ initial we already keep data in that variable, so we don't deed to keep it again, it will give us duplicate value
2013
+ */
2014
+
2015
+ if (button == 'initial-keep') {
2016
+ currentFeed.temproraryUsersData[i] = currentFeed.usersData[i];
2017
+ }
2018
+ currentFeed['usersData'][i] = response;
2019
+
2020
+ currentFeed.loadMoreDataCount--;
2021
+ }
2022
+ }
2023
+
2024
+ //checks if load more done then displays feed
2025
+ wdi_front.checkForLoadMoreDone(currentFeed, button);
2026
+ }
2027
+ })
2028
 
2029
  }
2030
 
2031
  wdi_front.checkForLoadMoreDone = function (currentFeed, button)
2032
  {
2033
+ var load_more_number = currentFeed.feed_row['load_more_number'];
2034
+ var number_of_photos = currentFeed.feed_row['number_of_photos'];
2035
 
2036
+ if (currentFeed.loadMoreDataCount == 0) {
2037
 
2038
+ currentFeed.temproraryUsersData = wdi_front.mergeData(currentFeed.temproraryUsersData, currentFeed.usersData);
2039
+ var gettedDataLength = wdi_front.getArrayContentLength(currentFeed.temproraryUsersData, 'data');
2040
+ /*this will happen when we call loadMore first time
2041
+ initial-keep is the same as initial except that if loadMore is called
2042
+ with initial-keep we store data on currentFeed.temproraryUsersData before checkLoadMoreDone()
2043
+ function call*/
2044
+ if (button == 'initial-keep') {
2045
+ button = 'initial';
2046
+ }
2047
+ //if button is set to inital load number_of_photos photos
2048
+ if (button == 'initial') {
2049
 
2050
+ /*if existing data length is smaller then load_more_number then get more objects until desired number is reached
2051
+ also if it is not possible to reach the desired number (this will happen when all users has no more photos) then
2052
+ displayFeed()*/
2053
+ if (gettedDataLength < number_of_photos && !wdi_front.userHasNoPhoto(currentFeed, currentFeed.temproraryUsersData) && currentFeed.instagramRequestCounter <= currentFeed.maxConditionalFiltersRequestCount) {
2054
+ //console.log('checkForLoadMoreDone recursion');
2055
 
2056
+ wdi_front.loadMore('initial', currentFeed);
2057
+ } else {
2058
 
2059
+ currentFeed.usersData = currentFeed.temproraryUsersData;
2060
 
2061
+ wdi_front.displayFeed(currentFeed);
2062
+ //when all data us properly displayed check for any active filters and then apply them
2063
+ wdi_front.applyFilters(currentFeed);
2064
 
2065
+ //resetting temprorary users data array for the next loadmoer call
2066
+ currentFeed.temproraryUsersData = [];
2067
 
2068
 
2069
+ }
2070
 
2071
+ } else {
2072
+ //else load load_more_number photos
2073
+ //if existing data length is smaller then load_more_number then get more objects until desired number is reached
2074
 
2075
+ if (gettedDataLength < load_more_number && !wdi_front.userHasNoPhoto(currentFeed, currentFeed.temproraryUsersData) && currentFeed.instagramRequestCounter <= currentFeed.maxConditionalFiltersRequestCount) {
2076
+ //console.log('load more recursion');
2077
+ wdi_front.loadMore(undefined, currentFeed);
2078
+ } else {
2079
 
2080
+ currentFeed.usersData = currentFeed.temproraryUsersData;
2081
 
2082
+ if (!wdi_front.activeUsersCount(currentFeed)) {
2083
+ return;
2084
+ }
2085
 
2086
+ wdi_front.displayFeed(currentFeed, load_more_number);
2087
+ //when all data us properly displayed check for any active filters and then apply them
2088
+ wdi_front.applyFilters(currentFeed);
2089
 
2090
+ //resetting temprorary users data array for the next loadmoer call
2091
+ currentFeed.temproraryUsersData = [];
2092
+ }
2093
+ }
2094
 
2095
 
2096
+ }
2097
  }
2098
 
2099
  wdi_front.allDataHasFinished = function (currentFeed)
2100
  {
2101
+ var c = 0;
2102
+ for (var j = 0; j < currentFeed.dataStorageRaw.length; j++) {
2103
+ if (currentFeed.dataStorageRaw[j].length() == 0 && currentFeed.dataStorageRaw[j].locked == true) {
2104
+ c++;
2105
+ }
2106
+ }
2107
 
2108
+ return (c == currentFeed.dataStorageRaw.length);
2109
  }
2110
 
2111
 
2113
  {
2114
 
2115
 
2116
+ for (var i = 0; i < array2.length; i++) {
2117
+ if (typeof array1[i] != 'undefined') {
2118
+ if (array2[i]['finished'] == 'finished') {
2119
+ continue;
2120
+ }
2121
 
2122
+ //if user data is finished then dont add duplicate data
2123
+ if (typeof array1[i]['pagination']['next_max_id'] == 'undefined' &&
2124
+ typeof array1[i]['pagination']['next_max_like_id'] == 'undefined') {
2125
+ continue;
2126
+ }
2127
+ //extend data
2128
+ array1[i]['data'] = array1[i]['data'].concat(array2[i]['data']);
2129
+ array1[i]['pagination'] = array2[i]['pagination'];
2130
+ array1[i]['user_id'] = array2[i]['user_id'];
2131
+ array1[i]['username'] = array2[i]['username'];
2132
+ array1[i]['meta'] = array2[i]['meta'];
2133
+ } else {
2134
+ array1.push(array2[i]);
2135
+ }
2136
+ }
2137
+ return array1;
2138
  }
2139
 
2140
 
2141
  //broken image handling
2142
  wdi_front.brokenImageHandler = function (source)
2143
  {
2144
+ source.src = wdi_url.plugin_url + "../images/missing.png";
2145
+ source.onerror = "";
2146
+ return true;
2147
 
2148
  }
2149
 
2151
  //ajax loading
2152
  wdi_front.ajaxLoader = function (currentFeed)
2153
  {
2154
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
2155
 
2156
+ var feed_container = jQuery('#wdi_feed_' + wdi_feed_counter);
2157
+ if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
2158
+ feed_container.find('.wdi_load_more').addClass('wdi_hidden');
2159
+ feed_container.find('.wdi_spinner').removeClass('wdi_hidden');
2160
+ }
2161
+ /////////////////////////////////////////////////////
2162
+ if (currentFeed.feed_row.feed_display_view == 'infinite_scroll') {
2163
+ var loadingDiv;
2164
+ if (feed_container.find('.wdi_ajax_loading').length == 0) {
2165
+ loadingDiv = jQuery('<div class="wdi_ajax_loading"><div><div><img class="wdi_load_more_spinner" src="' + wdi_url.plugin_url + '../images/ajax_loader.png"></div></div></div>');
2166
+ feed_container.append(loadingDiv);
2167
+ } else {
2168
+ loadingDiv = feed_container.find('.wdi_ajax_loading');
2169
+ }
2170
+ loadingDiv.removeClass('wdi_hidden');
2171
+ }
2172
 
2173
 
2174
+ ////////////////////////////////////////////////////
2175
 
2176
  }
2177
 
2178
  //if all images loaded then clicking load more causes it's removal
2179
  wdi_front.allImagesLoaded = function (currentFeed)
2180
  {
2181
+ ////////////////////////////////////////////////////////////////////
2182
+ //clearInterval(currentFeed.loadingInterval);
2183
+ //jQuery('#wdi_feed_'+currentFeed.feed_row['wdi_feed_counter']+' .wdi_ajax_loading').remove();
 
2184
 
2185
+ ////////////////////////////////////////////////////
2186
 
2187
+ var dataLength = wdi_front.getDataLength(currentFeed);
2188
+ /* display message if feed contains no image at all */
2189
+ if (dataLength == 0 && (currentFeed.feed_row.conditional_filters.length == 0 || currentFeed.feed_row.conditional_filter_enable == 0)) {
2190
+ jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + " .wdi_feed_wrapper").append("<p>There is no media in this feed</p>");
2191
+ }
2192
 
2193
+ //if all images loaded then enable load more button and hide spinner
2194
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
2195
+ var feed_container = jQuery('#wdi_feed_' + wdi_feed_counter);
2196
 
2197
+ if (currentFeed.feed_row.feed_display_view == 'load_more_btn') {
2198
+ feed_container.find('.wdi_load_more').removeClass('wdi_hidden');
2199
+ feed_container.find('.wdi_spinner').addClass('wdi_hidden');
2200
+ }
2201
 
2202
+ if (currentFeed.feed_row.feed_display_view == 'infinite_scroll') {
2203
+ jQuery('#wdi_feed_' + currentFeed.feed_row['wdi_feed_counter'] + ' .wdi_ajax_loading').addClass('wdi_hidden');
2204
+ }
2205
 
2206
 
2207
+ //custom event fired for user based custom js
2208
+ feed_container.trigger('wdi_feed_loaded');
2209
 
2210
 
2211
  }
2214
  //shows different parts of the feed based user choice
2215
  wdi_front.show = function (name, currentFeed)
2216
  {
2217
+ var wdi_feed_counter = currentFeed.feed_row['wdi_feed_counter'];
2218
+ var feed_container = jQuery('#wdi_feed_' + wdi_feed_counter + ' .wdi_feed_container');
2219
+ var _this = this;
2220
+ switch (name) {
2221
+ case 'header':
2222
+ {
2223
+ show_header();
2224
+ break;
2225
+ }
2226
+ case 'users':
2227
+ {
2228
+ show_users(currentFeed);
2229
+ break;
2230
+ }
2231
+
2232
+ }
2233
+
2234
+ function show_header()
2235
+ {
2236
+
2237
+ var templateData = {
2238
+ 'feed_thumb': currentFeed['feed_row']['feed_thumb'],
2239
+ 'feed_name': currentFeed['feed_row']['feed_name'],
2240
+ };
2241
+
2242
+ var headerTemplate = wdi_front.getHeaderTemplate(),
2243
+ html = headerTemplate(templateData),
2244
+ containerHtml = feed_container.find('.wdi_feed_header').html();
2245
+
2246
+ feed_container.find('.wdi_feed_header').html(containerHtml + html);
2247
+
2248
+
2249
+ }
2250
+
2251
+ function show_users(currentFeed)
2252
+ {
2253
+ feed_container.find('.wdi_feed_users').html('');
2254
+ var users = currentFeed['feed_users'];
2255
+ var access_token = currentFeed['feed_row']['access_token'];
2256
+ var i = 0;
2257
+ currentFeed.headerUserinfo = [];
2258
+ getThumb();
2259
+ //recursively calls itself until all user data is ready then displyes it with escapeRequest
2260
+ function getThumb()
2261
+ {
2262
+
2263
+ if (currentFeed.headerUserinfo.length == users.length) {
2264
+ escapeRequest(currentFeed.headerUserinfo, currentFeed);
2265
+ return;
2266
+ }
2267
+ var _user = users[currentFeed.headerUserinfo.length];
2268
+
2269
+
2270
+ if (typeof _user === 'string' && _user === 'self') {
2271
+ currentFeed.instagram.getSelfInfo({
2272
+ success: function (response)
2273
+ {
2274
+ response = _this.checkMediaResponse(response);
2275
+ if (response != false) {
2276
+ var obj = {
2277
+ id: response['data']['id'],
2278
+ name: response['data']['username'],
2279
+ url: response['data']['profile_picture'],
2280
+ bio: response['data']['bio'],
2281
+ counts: response['data']['counts'],
2282
+ website: response['data']['website'],
2283
+ full_name: response['data']['full_name']
2284
+ }
2285
+ currentFeed.headerUserinfo.push(obj);
2286
+ i++;
2287
+ getThumb();
2288
+ }
2289
+ },
2290
+ args: {
2291
+ ignoreFiltering: true,
2292
+ }
2293
+ });
2294
+ }
2295
+ else
2296
+ if (_this.getInputType(_user.username) == 'hashtag') {
2297
+ currentFeed.instagram.searchForTagsByName(_this.stripHashtag(_user.username), {
2298
+ /*currentFeed.instagram.getTagRecentMedia(_this.stripHashtag(_user.username), {*/
2299
+ success: function (response)
2300
+ {
2301
+ response = _this.checkMediaResponse(response);
2302
+ if (response != false) {
2303
+ if (response['data'].length == 0) {
2304
+ var thumb_img = '';
2305
+ var counts = {media: ''};
2306
+ } else {
2307
+ var thumb_img = '';// we will get image src later when will have all the sources
2308
+ //thumb_img = response['data'][0]['images']['thumbnail']['url'];
2309
+ var counts = {media: response['data'][0]['media_count']};
2310
+ }
2311
+
2312
+ var obj = {
2313
+ name: users[i]['username'],
2314
+ url: thumb_img,
2315
+ counts: counts,
2316
+ };
2317
+ i++;
2318
+ currentFeed.headerUserinfo.push(obj);
2319
+ getThumb();
2320
+ }
2321
+ },
2322
+ args: {
2323
+ ignoreFiltering: true,
2324
+ }
2325
+ });
2326
+ }
2327
+ else
2328
+ if (_this.getInputType(_user.username) == 'user') {
2329
+ currentFeed.instagram.getUserInfo(_user.id, {
2330
+ success: function (response)
2331
+ {
2332
+ response = _this.checkMediaResponse(response);
2333
+ if (response != false) {
2334
+ var obj = {
2335
+ id: response['data']['id'],
2336
+ name: response['data']['username'],
2337
+ url: response['data']['profile_picture'],
2338
+ bio: response['data']['bio'],
2339
+ counts: response['data']['counts'],
2340
+ website: response['data']['website'],
2341
+ full_name: response['data']['full_name']
2342
+ }
2343
+ currentFeed.headerUserinfo.push(obj);
2344
+ i++;
2345
+ getThumb();
2346
+ }
2347
+ },
2348
+ args: {
2349
+ ignoreFiltering: true,
2350
+ }
2351
+ });
2352
+ }
2353
+
2354
+ }
2355
+
2356
+ //when all user data is ready break recursion and create user elements
2357
+ function escapeRequest(info, currentFeed)
2358
+ {
2359
+ feed_container.find('.wdi_feed_users').html('');
2360
+ for (var k = 0; k < info.length; k++) {
2361
+ //setting all user filters to false
2362
+
2363
+ var userFilter = {
2364
+ 'flag': false,
2365
+ 'id': info[k]['id'],
2366
+ 'name': info[k]['name']
2367
+ };
2368
+
2369
+
2370
+ //user inforamtion
2371
+ var hashtagClass = (info[k]['name'][0] == '#') ? 'wdi_header_hashtag' : '';
2372
+
2373
+ var templateData = {
2374
+ 'user_index': k,
2375
+ 'user_img_url': info[k]['url'],
2376
+ 'counts': info[k]["counts"],
2377
+ 'feed_counter': currentFeed.feed_row.wdi_feed_counter,
2378
+ 'user_name': info[k]['name'],
2379
+ 'bio': info[k]['bio'],
2380
+ 'usersCount': currentFeed.feed_row.feed_users.length,
2381
+ 'hashtagClass': hashtagClass
2382
+
2383
+ };
2384
+
2385
+ var userTemplate = wdi_front.getUserTemplate(currentFeed, info[k]['name']),
2386
+ html = userTemplate(templateData),
2387
+ containerHtml = feed_container.find('.wdi_feed_users').html();
2388
+
2389
+ feed_container.find('.wdi_feed_users').html(containerHtml + html);
2390
+
2391
+
2392
+ currentFeed.userSortFlags.push(userFilter);
2393
+
2394
+ var clearFloat = jQuery('<div class="wdi_clear"></div>');
2395
+
2396
+ }
2397
+ feed_container.find('.wdi_feed_users').append(clearFloat);
2398
+ wdi_front.updateUsersImages(currentFeed);
2399
+ };
2400
+ }
2401
 
2402
  }
2403
 
2405
  wdi_front.getUserTemplate = function (currentFeed, username)
2406
  {
2407
 
2408
+ var usersCount = currentFeed.dataCount,
2409
+ instagramLink, instagramLinkOnClick, js;
2410
+
2411
+ switch (username[0]) {
2412
+ case '#':
2413
+ {
2414
+ instagramLink = '//instagram.com/explore/tags/' + username.substr(1, username.length);
2415
+ break;
2416
+ }
2417
+ default:
2418
+ {
2419
+ instagramLink = '//instagram.com/' + username;
2420
+ break;
2421
+ }
2422
+ }
2423
+ js = 'window.open("' + instagramLink + '","_blank")';
2424
+ instagramLinkOnClick = "onclick='" + js + "'";
2425
+
2426
+ var source = '<div class="wdi_single_user" user_index="<%=user_index%>">' +
2427
+ '<div class="wdi_header_user_text <%=hashtagClass%>">' +
2428
+
2429
+ '<div class="wdi_user_img_wrap">' +
2430
+ '<img onerror="wdi_front.brokenImageHandler(this);" src="<%= user_img_url%>">';
2431
+ if (usersCount > 1) {
2432
+ source += '<div title="' + wdi_front_messages.filter_title + '" class="wdi_filter_overlay">' +
2433
+ '<div class="wdi_filter_icon">' +
2434
+ '<span onclick="wdi_front.addFilter(<%=user_index%>,<%=feed_counter%>);" class="fa fa-filter"></span>' +
2435
+ '</div>' +
2436
+ '</div>';
2437
+ }
2438
+ source += '</div>';
2439
+ source += '<h3 ' + instagramLinkOnClick + '><%= user_name%></h3>';
2440
+
2441
+ if (username[0] !== '#') {
2442
+ if (currentFeed.feed_row.follow_on_instagram_btn == '1') {
2443
+ source += '<div class="wdi_user_controls">' +
2444
+ '<div class="wdi_follow_btn" onclick="window.open(\'//instagram.com/<%= user_name%>\',\'_blank\')"><span> Follow</span></div>' +
2445
+ '</div>';
2446
+ }
2447
+ source += '<div class="wdi_media_info">' +
2448
+ '<p class="wdi_posts"><span class="fa fa-camera-retro"><%= counts.media%></span></p>' +
2449
+ '<p class="wdi_followers"><span class="fa fa-user"><%= counts.followed_by%></span></p>' +
2450
+ '</div>';
2451
+ } else {
2452
+ source += '<div class="wdi_user_controls">' +
2453
+ '</div>' +
2454
+ '<div class="wdi_media_info">' +
2455
+ '<p class="wdi_posts"><span class="fa fa-camera-retro"><%= counts.media%></span></p>' +
2456
+ '<p class="wdi_followers"><span></span></p>' +
2457
+ '</div>';
2458
+ }
2459
+ source += '<div class="wdi_clear"></div>';
2460
+
2461
+ if (usersCount == 1 && username[0] !== '#' && currentFeed.feed_row.display_user_info == '1') {
2462
+ source += '<div class="wdi_bio"><%= bio%></div>';
2463
+
2464
+ }
2465
+
2466
+
2467
+ source += '</div>' +
2468
+ '</div>';
2469
+
2470
+ var template = _.template(source);
2471
+ return template;
2472
  }
2473
 
2474
 
2475
  wdi_front.getHeaderTemplate = function ()
2476
  {
2477
+ var source = '<div class="wdi_header_wrapper">' +
2478
+ '<div class="wdi_header_img_wrap">' +
2479
+ '<img src="<%=feed_thumb%>">' +
2480
+ '</div>' +
2481
+ '<div class="wdi_header_text"><%=feed_name%></div>' +
2482
+ '<div class="wdi_clear">' +
2483
+ '</div>';
2484
+ var template = _.template(source);
2485
+ return template;
2486
  }
2487
 
2488
 
2489
  //sets user filter to true and applys filter to feed
2490
  wdi_front.addFilter = function (index, feed_counter)
2491
  {
2492
+ var currentFeed = window['wdi_feed_' + feed_counter];
2493
+ var usersCount = currentFeed.dataCount;
2494
+ if (usersCount < 2) {
2495
+ return;
2496
+ }
2497
+
2498
+ if (currentFeed.nowLoadingImages != false) {
2499
+ return;
2500
+ } else {
2501
+
2502
+ var userDiv = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + '_users [user_index="' + index + '"]');
2503
+ userDiv.find('.wdi_filter_overlay').toggleClass('wdi_filter_active_bg');
2504
+ userDiv.find('.wdi_header_user_text h3').toggleClass('wdi_filter_active_col');
2505
+ userDiv.find('.wdi_media_info').toggleClass('wdi_filter_active_col');
2506
+ userDiv.find('.wdi_follow_btn').toggleClass('wdi_filter_active_col');
2507
+
2508
+ currentFeed.customFilterChanged = true;
2509
+ //setting filter flag to true
2510
+ if (currentFeed.userSortFlags[index]['flag'] == false) {
2511
+ currentFeed.userSortFlags[index]['flag'] = true;
2512
+ } else {
2513
+ currentFeed.userSortFlags[index]['flag'] = false;
2514
+ }
2515
+ //getting active filter count
2516
+ var activeFilterCount = 0;
2517
+ for (var j = 0; j < currentFeed.userSortFlags.length; j++) {
2518
+ if (currentFeed.userSortFlags[j]['flag'] == true) {
2519
+ activeFilterCount++;
2520
+ }
2521
+ }
2522
+
2523
+
2524
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
2525
+ //reset responsive indexes because number of feed images may change after using filter
2526
+ currentFeed.resIndex = 0;
2527
+ }
2528
+
2529
+ //applying filters
2530
+ if (activeFilterCount != 0) {
2531
+ wdi_front.filterData(currentFeed);
2532
+ wdi_front.displayFeed(currentFeed);
2533
+ } else {
2534
+ currentFeed.customFilteredData = currentFeed.dataStorageList;
2535
+ wdi_front.displayFeed(currentFeed);
2536
+ }
2537
+
2538
+
2539
+ if (currentFeed.feed_row.feed_display_view == 'pagination') {
2540
+ //reset paginator because while filtering images become more or less so pages also become more or less
2541
+ currentFeed.paginator = Math.ceil((currentFeed.imageIndex) / parseInt(currentFeed.feed_row.pagination_per_page_number));
2542
+ //setting current page as the last loaded page when filter is active
2543
+ currentFeed.currentPage = currentFeed.paginator; //pagination page number
2544
+ //when feed is displayed we are by default in the first page
2545
+ //so we are navigating from page 1 to current page using custom navigation method
2546
+ wdi_front.updatePagination(currentFeed, 'custom', 1);
2547
+
2548
+ jQuery('#wdi_first_page').removeClass('wdi_disabled');
2549
+ jQuery('#wdi_last_page').addClass('wdi_disabled');
2550
+ }
2551
+
2552
+ }
2553
  }
2554
 
2555
  wdi_front.filterData = function (currentFeed)
2556
  {
2557
 
2558
+ var users = currentFeed.userSortFlags;
2559
+ currentFeed.customFilteredData = [];
2560
+ for (var i = 0; i < currentFeed.dataStorageList.length; i++) {
2561
+ for (var j = 0; j < users.length; j++) {
2562
+ if ((currentFeed.dataStorageList[i]['user']['id'] == users[j]['id'] || currentFeed.dataStorageList[i]['wdi_hashtag'] == users[j]['name']) && users[j]['flag'] == true) {
2563
+ currentFeed.customFilteredData.push(currentFeed.dataStorageList[i]);
2564
+ }
2565
 
2566
+ }
2567
+ }
2568
 
2569
  }
2570
 
2571
  wdi_front.applyFilters = function (currentFeed)
2572
  {
2573
+ for (var i = 0; i < currentFeed.userSortFlags.length; i++) {
2574
+ if (currentFeed.userSortFlags[i]['flag'] == true) {
2575
+ var userDiv = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + '[user_index="' + i + '"]');
2576
+ wdi_front.addFilter(i, currentFeed.feed_row.wdi_feed_counter);
2577
+ wdi_front.addFilter(i, currentFeed.feed_row.wdi_feed_counter);
2578
+ }
2579
+ }
2580
 
2581
  }
2582
 
2583
  //gets data Count from global storage
2584
  wdi_front.getImgCount = function (currentFeed)
2585
  {
2586
+ var dataStorage = currentFeed.dataStorage;
2587
+ var count = 0;
2588
+ for (var i = 0; i < dataStorage.length; i++) {
2589
+ count += dataStorage[i].length;
2590
+ }
2591
+ return count;
2592
  }
2593
 
2594
  //parses image data for lightbox popup
2595
  wdi_front.parseLighboxData = function (currentFeed, filterFlag)
2596
  {
2597
 
2598
+ var dataStorage = currentFeed.dataStorage;
2599
+ var sortImagesBy = currentFeed.feed_row['sort_images_by'];
2600
+ var sortOrder = currentFeed.feed_row['display_order'];
2601
+ var sortOperator = wdi_front.sortingOperator(sortImagesBy, sortOrder);
2602
+ var data = [];
2603
+
2604
+ var popupData = [];
2605
+ var obj = {};
2606
+
2607
+ //if filterFlag is true, it means that some filter for frontend content is enabled so give
2608
+ //lightbox only those images which are visible at that moment else give all avialable
2609
+ if (filterFlag == true) {
2610
+ data = currentFeed.customFilteredData;
2611
+ } else {
2612
+ for (var i = 0; i < dataStorage.length; i++) {
2613
+ for (var j = 0; j < dataStorage[i].length; j++) {
2614
+ data.push(dataStorage[i][j]);
2615
+ }
2616
+ }
2617
+ data.sort(sortOperator);
2618
+ }
2619
+
2620
+
2621
+ for (i = 0; i < data.length; i++) {
2622
+ obj = {
2623
+ 'alt': '',
2624
+ 'avg_rating': '',
2625
+ 'comment_count': data[i]['comments']['count'],
2626
+ 'date': wdi_front.convertUnixDate(data[i]['created_time']),
2627
+ 'description': wdi_front.getDescription((data[i]['caption'] !== null) ? data[i]['caption']['text'] : ''),
2628
+ 'filename': wdi_front.getFileName(data[i]),
2629
+ 'filetype': wdi_front.getFileType(data[i]),
2630
+ 'hit_count': '0',
2631
+ 'id': data[i]['id'],
2632
+ 'image_url': data[i]['link'],
2633
+ 'number': 0,
2634
+ 'rate': '',
2635
+ 'rate_count': '0',
2636
+ 'username': data[i]['user']['username'],
2637
+ 'profile_picture': data[i]['user']['profile_picture'],
2638
+ 'thumb_url': data[i]['link'] + 'media/?size=t',
2639
+ 'comments_data': data[i]['comments']['data']
2640
+ }
2641
+ popupData.push(obj);
2642
+ }
2643
+ return popupData;
2644
  }
2645
 
2646
  wdi_front.convertUnixDate = function (date)
2647
  {
2648
+ var utcSeconds = parseInt(date);
2649
+ var newDate = new Date(0);
2650
+ newDate.setUTCSeconds(utcSeconds);
2651
+ var str = newDate.getFullYear() + '-' + newDate.getMonth() + '-' + newDate.getDate();
2652
+ str += ' ' + newDate.getHours() + ':' + newDate.getMinutes();
2653
+ return str;
2654
  }
2655
 
2656
  wdi_front.getDescription = function (desc)
2657
  {
2658
+ desc = desc.replace(/\r?\n|\r/g, ' ');
2659
 
2660
 
2661
+ return desc;
2662
  }
2663
 
2664
+
2665
+ /**
2666
+ * use this data for lightbox
2667
+ * **/
2668
+
2669
  wdi_front.getFileName = function (data)
2670
  {
2671
+ var link = data['link'];
2672
+ var type = data['type'];
2673
+ /*if pure video, not carousel*/
2674
+ if (type === 'video' && data.hasOwnProperty('videos')) {
2675
+ return data['videos']['standard_resolution']['url'];
2676
+ } else {
2677
+ var linkFragments = link.split('/');
2678
+ return linkFragments[linkFragments.length - 2];
2679
+ }
2680
 
2681
  }
2682
 
2683
+ wdi_front.getFileType = function (data)
2684
  {
2685
+ /*if pure video, not carousel*/
2686
+ if (data['type'] == 'video' && data.hasOwnProperty('videos')) {
2687
+ return "EMBED_OEMBED_INSTAGRAM_VIDEO";
2688
+ }
2689
+ else {
2690
+ return "EMBED_OEMBED_INSTAGRAM_IMAGE";
2691
+ }
2692
  }
2693
 
2694
 
2695
  wdi_front.array_max = function (array)
2696
  {
2697
+ var max = array[0];
2698
+ var minIndex = 0;
2699
+ for (var i = 1; i < array.length; i++) {
2700
+ if (max < array[i]) {
2701
+ max = array[i];
2702
+ minIndex = i;
2703
+ }
2704
+ }
2705
+ return {
2706
+ 'value': max,
2707
+ 'index': minIndex
2708
+ };
2709
  }
2710
 
2711
  wdi_front.array_min = function (array)
2712
  {
2713
+ var min = array[0];
2714
+ var minIndex = 0;
2715
+ for (var i = 1; i < array.length; i++) {
2716
+ if (min > array[i]) {
2717
+ min = array[i];
2718
+ minIndex = i;
2719
+ }
2720
+ }
2721
+ return {
2722
+ 'value': min,
2723
+ 'index': minIndex
2724
+ };
2725
  }
2726
 
2727
  /*
2729
  */
2730
  wdi_front.activeUsersCount = function (currentFeed)
2731
  {
2732
+ var counter = 0;
2733
+ for (var i = 0; i < currentFeed.usersData.length; i++) {
2734
+ if (currentFeed.usersData[i].finished != 'finished') {
2735
+ counter++;
2736
+ }
2737
+ }
2738
+ return counter;
2739
  }
2740
 
2741
 
2747
  wdi_front.checkMediaResponse = function (response)
2748
  {
2749
 
2750
+ if (response == '' || typeof response == 'undefined' || response == null) {
2751
+ errorMessage = wdi_front_messages.connection_error;
2752
+ wdi_front.show_alert(errorMessage);
2753
+ return false;
2754
+ }
2755
+ if (response['meta']['code'] != 200) {
2756
+ errorMessage = response['meta']['error_message'];
2757
+ wdi_front.show_alert(errorMessage);
2758
+ return false;
2759
+ }
2760
+ return response;
2761
  }
2762
 
2763
 
2768
  */
2769
  wdi_front.stripHashtag = function (hashtag)
2770
  {
2771
+ switch (hashtag[0]) {
2772
+ case '#':
2773
+ {
2774
+ return hashtag.substr(1, hashtag.length);
2775
+ break;
2776
+ }
2777
+ default:
2778
+ {
2779
+ return hashtag;
2780
+ break;
2781
+ }
2782
+ }
2783
  }
2784
 
2785
  /**
2790
  wdi_front.getInputType = function (input)
2791
  {
2792
 
2793
+ switch (input[0]) {
2794
+ case '#':
2795
+ {
2796
+ return 'hashtag';
2797
+ break;
2798
+ }
2799
+ case '%':
2800
+ {
2801
+ return 'location';
2802
+ break;
2803
+ }
2804
+ default:
2805
+ {
2806
+ return 'user';
2807
+ break;
2808
+ }
2809
 
2810
+ }
2811
  }
2812
 
2813
  /**
2819
  */
2820
  wdi_front.regexpTestCaption = function (captionText, searchkey)
2821
  {
2822
+ var flag1 = false,
2823
+ flag2 = false,
2824
+ matchIndexes = [],
2825
+ escKey = searchkey.replace(/[-[\]{}()*+?.,\\^$|]/g, "\\$&"),
2826
+ regexp1 = new RegExp("(?:^|\\s)" + escKey + "(?:^|\\s)"),
2827
+ regexp2 = new RegExp("(?:^|\\s)" + escKey, 'g');
2828
+ if (regexp1.exec(captionText) != null) {
2829
+ flag1 = true;
2830
+ }
2831
 
2832
+ while (( match = regexp2.exec(captionText) ) != null) {
2833
+ if (match.index == captionText.length - searchkey.length - 1) {
2834
+ flag2 = true;
2835
+ }
2836
+ }
2837
 
2838
+ if (flag1 == true || flag2 == true) {
2839
+ return true;
2840
+ } else {
2841
+ return false;
2842
+ }
2843
 
2844
  }
2845
 
2852
  */
2853
  wdi_front.replaceNewLines = function (string)
2854
  {
2855
+ var delimeter = "vUkCJvN2ps3t",
2856
+ matchIndexes = [],
2857
+ regexp;
2858
+ string = string.replace(/\r?\n|\r/g, delimeter);
2859
 
2860
+ regexp = new RegExp(delimeter, 'g');
2861
+ while (( match = regexp.exec(string) ) != null) {
2862
+ matchIndexes.push(match.index);
2863
+ }
2864
 
2865
+ var pieces = string.split(delimeter);
2866
+ var foundFlag = 0;
2867
 
2868
+ for (var i = 0; i < pieces.length; i++) {
2869
 
2870
+ if (pieces[i] == '') {
2871
+ foundFlag++;
2872
+ } else {
2873
+ foundFlag = 0;
2874
+ }
2875
 
2876
+ if (foundFlag > 0) {
2877
+ pieces.splice(i, 1);
2878
+ foundFlag--;
2879
+ i--;
2880
+ }
2881
 
2882
+ }
2883
+ string = pieces.join(' ');
2884
+ return string;
2885
  }
2886
 
2887
 
2888
  wdi_front.isEmptyObject = function (obj)
2889
  {
2890
+ for (var prop in obj) {
2891
+ if (obj.hasOwnProperty(prop))
2892
+ return false;
2893
+ }
2894
+ return true
2895
  }
2896
 
2897
 
2898
  var WDIFeed = function (obj)
2899
  {
2900
+ this['data'] = obj['data']
2901
+ this['dataCount'] = obj['dataCount']
2902
+ this['feed_row'] = obj['feed_row']
2903
+ this['usersData'] = obj['usersData']
2904
  };
2905
 
2906
  /**
2912
  WDIFeed.prototype.conditionalFilter = function (response, args)
2913
  {
2914
 
2915
+ var currentFeed = this,
2916
+ conditional_filter_type = currentFeed.feed_row.conditional_filter_type,
2917
+ filters = currentFeed.feed_row.conditional_filters;
2918
 
2919
 
2920
+ if (args.ignoreFiltering == true) {
2921
 
2922
+ } else {
2923
 
2924
+ /**
2925
+ * Get rid of duplicate media
2926
+ */
2927
+ response = this.avoidDuplicateMedia(response);
2928
+ }
2929
 
2930
 
2931
+ //if filters json is invalid then return response without filtering
2932
+ if (!wdi_front.isJsonString(filters)) {
2933
+ return response;
2934
+ } else {
2935
+ filters = JSON.parse(filters);
2936
+ if (filters.length == 0) {
2937
+ return response;
2938
+ }
2939
+ }
2940
 
2941
 
2942
+ if (currentFeed.feed_row.conditional_filter_enable == '0') {
2943
+ return response;
2944
+ }
2945
 
2946
 
2947
+ //console.log('filtering');
2948
+ //increase counter for determing request count if this counter is more then
2949
+ //currentFeed.maxConditionalFiltersRequestCount then program will terminate recursion loop
2950
+ currentFeed.instagramRequestCounter++;
2951
 
2952
+ switch (conditional_filter_type) {
2953
+ case 'AND':
2954
+ {
2955
+ response = this.applyANDLogic(response, filters, currentFeed);
2956
+ break;
2957
+ }
2958
+ case 'OR':
2959
+ {
2960
+ response = this.applyORLogic(response, filters, currentFeed)
2961
+ break;
2962
+ }
2963
+ case 'NOR':
2964
+ {
2965
+ response = this.applyNORLogic(response, filters, currentFeed)
2966
+ break;
2967
+ }
2968
+ default:
2969
+ {
2970
+ break;
2971
+ }
2972
+ }
2973
 
2974
 
2975
+ return response;
2976
  }
2977
 
2978
 
2984
  */
2985
  WDIFeed.prototype.applyANDLogic = function (response, filters)
2986
  {
2987
+ var currentFeed = this;
2988
+ for (var i = 0; i < filters.length; i++) {
2989
+ response = this.filterResponse(response, filters[i]);
2990
+ }
2991
 
2992
+ return response;
2993
  }
2994
 
2995
  /**
3000
  */
3001
  WDIFeed.prototype.applyORLogic = function (response, filters)
3002
  {
3003
+ var currentFeed = this;
3004
+ var allData = [],
3005
+ res,
3006
+ mergedData = [],
3007
+ returnObject,
3008
+ media;
3009
 
3010
+ for (var i = 0; i < filters.length; i++) {
3011
+ res = this.filterResponse(response, filters[i]);
3012
+ allData = allData.concat(res['data']);
3013
+ res = {};
3014
+ }
3015
 
3016
+ for (i = 0; i < allData.length; i++) {
3017
+ media = allData[i];
3018
+ if (!this.mediaExists(media, mergedData) && !this.mediaExists(media, currentFeed.dataStorageList)) {
3019
+ mergedData.push(media);
3020
+ }
3021
+ }
3022
 
3023
+ returnObject = {
3024
+ data: mergedData,
3025
+ meta: response['meta'],
3026
+ pagination: response['pagination']
3027
+ }
3028
+ return returnObject;
3029
  }
3030
 
3031
 
3038
  WDIFeed.prototype.applyNORLogic = function (response, filters)
3039
  {
3040
 
3041
+ var res = response,
3042
+ currentFeed = this,
3043
+ matchedData = this.applyORLogic(response, filters, currentFeed),
3044
+ mergedData = [],
3045
+ returnObject;
3046
 
3047
+ for (var i = 0; i < res['data'].length; i++) {
3048
+ if (!this.mediaExists(res['data'][i], matchedData['data'])) {
3049
+ mergedData.push(res['data'][i]);
3050
+ }
3051
+ }
3052
 
3053
+ returnObject = {
3054
+ data: mergedData,
3055
+ meta: res['meta'],
3056
+ pagination: res['pagination']
3057
+ }
3058
+ return returnObject;
3059
  }
3060
 
3061
 
3062
  WDIFeed.prototype.mediaExists = function (media, array)
3063
  {
3064
 
3065
+ for (var i = 0; i < array.length; i++) {
3066
+ if (media['id'] == array[i]['id']) {
3067
+ return true;
3068
+ }
3069
+ }
3070
+ return false;
3071
  }
3072
 
3073
 
3080
  WDIFeed.prototype.filterResponse = function (response, filter)
3081
  {
3082
 
3083
+ switch (filter.filter_type) {
3084
+ case 'hashtag':
3085
+ {
3086
+ return this.filterByHashtag(response, filter);
3087
+ break;
3088
+ }
3089
+ case 'username':
3090
+ {
3091
+ return this.filterByUsername(response, filter);
3092
+ break;
3093
+ }
3094
+ case 'mention':
3095
+ {
3096
+ return this.filterByMention(response, filter);
3097
+ break;
3098
+ }
3099
+ case 'description':
3100
+ {
3101
+ return this.filterByDescription(response, filter);
3102
+ break;
3103
+ }
3104
+ case 'location':
3105
+ {
3106
+ return this.filterByLocation(response, filter);
3107
+ break;
3108
+ }
3109
+ case 'url':
3110
+ {
3111
+ return this.filterByUrl(response, filter);
3112
+ break;
3113
+ }
3114
+ }
3115
  }
3116
 
3117
 
3123
  */
3124
  WDIFeed.prototype.filterByHashtag = function (response, filter)
3125
  {
3126
+ var filteredResponse = [],
3127
+ currentTag,
3128
+ media,
3129
+ returnObject;
3130
 
3131
+ for (var i = 0; i < response['data'].length; i++) {
3132
+ media = response['data'][i];
3133
+ for (var j = 0; j < media['tags'].length; j++) {
3134
+ tag = media['tags'][j];
3135
+ if (tag.toLowerCase() == filter.filter_by.toLowerCase()) {
3136
 
3137
+ filteredResponse.push(media);
3138
+ }
3139
+ }
3140
+ }
3141
 
3142
 
3143
+ returnObject = {
3144
+ data: filteredResponse,
3145
+ meta: response['meta'],
3146
+ pagination: response['pagination']
3147
+ }
3148
+ return returnObject;
3149
  }
3150
 
3151
  /**
3156
  */
3157
  WDIFeed.prototype.filterByUsername = function (response, filter)
3158
  {
3159
+ var filteredResponse = [],
3160
+ media,
3161
+ returnObject;
3162
 
3163
+ for (var i = 0; i < response['data'].length; i++) {
3164
+ media = response['data'][i];
3165
+ if (media.user.username.toLowerCase() == filter.filter_by.toLowerCase()) {
3166
+ filteredResponse.push(media);
3167
+ }
3168
+ }
3169
 
3170
 
3171
+ returnObject = {
3172
+ data: filteredResponse,
3173
+ meta: response['meta'],
3174
+ pagination: response['pagination']
3175
+ }
3176
+ return returnObject;
3177
  }
3178
 
3179
 
3185
  */
3186
  WDIFeed.prototype.filterByMention = function (response, filter)
3187
  {
3188
+ var filteredResponse = [],
3189
+ media, captionText, returnObject;
3190
+ for (var i = 0; i < response['data'].length; i++) {
3191
+ media = response['data'][i];
3192
+ if (media['caption'] !== null) {
3193
+ captionText = media['caption']['text'].toLowerCase();
3194
+ if (captionText.indexOf('@' + filter.filter_by.toLowerCase()) != -1) {
3195
 
3196
+ filteredResponse.push(media);
3197
+ }
3198
+ }
3199
+ }
3200
 
3201
+ returnObject = {
3202
+ data: filteredResponse,
3203
+ meta: response['meta'],
3204
+ pagination: response['pagination']
3205
+ }
3206
+ return returnObject;
3207
  }
3208
 
3209
 
3215
  */
3216
  WDIFeed.prototype.filterByDescription = function (response, filter)
3217
  {
3218
+ var filteredResponse = [],
3219
+ media, captionText, returnObject;
3220
 
3221
+ for (var i = 0; i < response['data'].length; i++) {
3222
+ media = response['data'][i];
3223
+ if (media['caption'] !== null) {
3224
 
3225
+ captionText = media['caption']['text'].toLowerCase();
3226
+ captionText = wdi_front.replaceNewLines(captionText);
3227
+ var searchkey = filter.filter_by.toLowerCase();
3228
 
3229
+ if (wdi_front.regexpTestCaption(captionText, searchkey)) {
3230
+ filteredResponse.push(media);
3231
+ }
3232
+ }
3233
+ }
3234
 
3235
+ returnObject = {
3236
+ data: filteredResponse,
3237
+ meta: response['meta'],
3238
+ pagination: response['pagination']
3239
+ }
3240
 
3241
+ return returnObject;
3242
  }
3243
 
3244
 
3250
  */
3251
  WDIFeed.prototype.filterByLocation = function (response, filter)
3252
  {
3253
+ var filteredResponse = [],
3254
+ media, locationId, returnObject;
3255
+ for (var i = 0; i < response['data'].length; i++) {
3256
+ media = response['data'][i];
3257
 
3258
+ if (media['location'] !== null) {
3259
+ locationId = media['location']['id'];
3260
+ if (locationId == filter.filter_by) {
3261
+ filteredResponse.push(media);
3262
+ }
3263
+ }
3264
+ }
3265
 
3266
+ returnObject = {
3267
+ data: filteredResponse,
3268
+ meta: response['meta'],
3269
+ pagination: response['pagination']
3270
+ }
3271
+ return returnObject;
3272
  }
3273
 
3274
 
3281
 
3282
  WDIFeed.prototype.filterByUrl = function (response, filter)
3283
  {
3284
+ var filteredResponse = [],
3285
+ media, id, returnObject, filter_by;
3286
 
3287
+ filter.filter_by = this.getIdFromUrl(filter.filter_by);
3288
 
3289
+ for (var i = 0; i < response['data'].length; i++) {
3290
+ media = response['data'][i];
3291
 
3292
+ if (media['link'] !== null) {
3293
+ id = this.getIdFromUrl(media['link']);
3294
+ if (id == filter.filter_by) {
3295
+ filteredResponse.push(media);
3296
+ }
3297
+ }
3298
+ }
3299
 
3300
+ returnObject = {
3301
+ data: filteredResponse,
3302
+ meta: response['meta'],
3303
+ pagination: response['pagination']
3304
+ }
3305
+ return returnObject;
3306
  }
3307
 
3308
  /**
3312
  */
3313
  WDIFeed.prototype.getIdFromUrl = function (url)
3314
  {
3315
+ var url_parts = url.split('/'),
3316
+ id = false;
3317
+ for (var i = 0; i < url_parts.length; i++) {
3318
+ if (url_parts[i] == 'p') {
3319
+ if (typeof url_parts[i + 1] != 'undefined') {
3320
+ id = url_parts[i + 1];
3321
+ break;
3322
+ }
3323
+ }
3324
+ }
3325
+ ;
3326
+ return id;
3327
  }
3328
 
3329
 
3334
  */
3335
  WDIFeed.prototype.avoidDuplicateMedia = function (response)
3336
  {
3337
+ var data = response['data'],
3338
+ uniqueData = [],
3339
+ returnObject = {};
3340
+ if (typeof data == "undefined") {
3341
+ data = [];
3342
+ }
3343
 
3344
+ for (var i = 0; i < data.length; i++) {
3345
+ if (!this.mediaExists(data[i], this.dataStorageList) && !this.mediaExists(data[i], uniqueData) && !this.mediaExists(data[i], this.conditionalFilterBuffer)) {
3346
+ uniqueData.push(data[i]);
3347
+ }
3348
+ }
3349
 
3350
+ this.conditionalFilterBuffer = this.conditionalFilterBuffer.concat(uniqueData);
3351
 
3352
+ returnObject = {
3353
+ data: uniqueData,
3354
+ meta: response['meta'],
3355
+ pagination: response['pagination']
3356
+ }
3357
 
3358
+ return returnObject;
3359
 
3360
  }
3361
 
3363
  /* stores data from objects array into global variable */
3364
  WDIFeed.prototype.storeRawData = function (objects, variable)
3365
  {
3366
+ var _this = this;
3367
+ if (typeof this[variable] == "object" && typeof this[variable].length == "number") {
3368
+ //checks if in golbal storage user already exisit then it adds new data to user old data
3369
+ //else it simple puches new user with it's data to global storage
3370
+ for (var i = 0; i < objects.length; i++) {
3371
+
3372
+
3373
+ var hash_id = "";
3374
+ if (wdi_front.isHashtag(objects[i].user_id)) {
3375
+ hash_id = objects[i].pagination.next_max_tag_id;
3376
+ }
3377
+ else
3378
+ if (_this.feed_row.liked_feed == 'liked') {
3379
+ hash_id = objects[i].pagination.next_max_like_id;
3380
+ if (typeof hash_id == "undefined") {
3381
+ hash_id = "";
3382
+ }
3383
+ }
3384
+ else {
3385
+
3386
+ /*strange bug sometimes happening in instagram API when user feed pagination is null*/
3387
+ if (objects[i].pagination == null) {
3388
+ objects[i].pagination = [];
3389
+ }
3390
+
3391
+ hash_id = objects[i].pagination.next_max_id;
3392
+ if (typeof hash_id == "undefined") {
3393
+ hash_id = "";
3394
+ }
3395
+
3396
+
3397
+ }
3398
+
3399
+ if (typeof this[variable][i] == "undefined") {
3400
+ this[variable].push({
3401
+ data: objects[i].data,
3402
+ index: 0,
3403
+ locked: false,
3404
+ hash_id: hash_id,
3405
+ usersDataFinished: false,
3406
+ userId: objects[i].user_id,
3407
+ length: function ()
3408
+ {
3409
+ return this.data.length - this.index;
3410
+ },
3411
+ getData: function (num)
3412
+ {
3413
+ var data = this.data.slice(this.index, this.index + num);
3414
+ this.index += Math.min(num, this.length());
3415
+
3416
+ if (this.index == this.data.length && this.locked == true && this.usersDataFinished == false) {
3417
+
3418
+ for (var j = 0; j < _this.usersData.length; j++) {
3419
+ if (_this.usersData[j]['user_id'] == this.userId) {
3420
+ _this.usersData[j].finished = "finished";
3421
+ this.usersDataFinished = true;
3422
+ break;
3423
+ }
3424
+ }
3425
+ }
3426
+ return data;
3427
+ }
3428
+ });
3429
+ } else {
3430
+ if (this[variable][i].locked == false) {
3431
+
3432
+ if (hash_id != this[variable][i].hash_id) {
3433
+ this[variable][i].data = this[variable][i].data.concat(objects[i].data);
3434
+ this[variable][i].hash_id = hash_id;
3435
+ } else {
3436
+ this[variable][i].locked = true;
3437
+
3438
+ }
3439
+ }
3440
+
3441
+ }
3442
+ }
3443
+ }
3444
 
3445
  }
3446
 
3447
 
3448
  wdi_front.updateUsersIfNecessary = function (currentFeed)
3449
  {
3450
+ var users = currentFeed.feed_users;
3451
+ var ifUpdateNecessary = false;
3452
 
3453
+ for (var i = 0; i < users.length; i++) {
3454
+ if ("#" == users[i].username.substr(0, 1)) {
3455
+ users[i].id = users[i].username;
3456
+ continue;
3457
+ }
3458
+ if ("" == users[i].id || 'username' == users[i].id) {
3459
 
3460
+ ifUpdateNecessary = true;
3461
+ currentFeed.instagram.searchForUsersByName(users[i].username, {
3462
+ success: function (res)
3463
+ {
3464
+ if (res.meta.code == 200 && res.data.length > 0) {
3465
 
3466
+ var found = false;
3467
 
3468
+ for (var k = 0; k < res.data.length; k++) {
3469
+ if (res.data[k].username == res.args.username) {
3470
+ found = true;
3471
+ break;
3472
+ }
3473
+ }
3474
 
3475
+ if (found) {
3476
+ for (var j = 0; j < users.length; j++) {
3477
+ if (res.data[k].username == users[j].username) {
3478
+ users[j].id = res.data[k].id;
3479
+ }
3480
+ }
3481
+ }
3482
 
3483
 
3484
+ }
3485
 
3486
+ var noid_user_left = false;
3487
+ for (var m = 0; m < users.length; m++) {
3488
+ if (users[m].id == "" || users[m].id == "username") {
3489
+ noid_user_left = true;
3490
+ break;
3491
+ }
3492
+ }
3493
+ if (!noid_user_left) {
3494
+ currentFeed.feed_row.feed_users = JSON.stringify(users);
3495
+ wdi_front.init(currentFeed);
3496
+ }
3497
 
3498
+ },
3499
+ username: users[i].username
3500
+ });
3501
+ }
3502
+ }
3503
 
3504
+ return ifUpdateNecessary;
3505
  }
3506
 
3507
 
3508
+ if (typeof wdi_ajax.ajax_response != "undefined") {
3509
+ jQuery(document).one('ajaxStop', function ()
3510
+ {
3511
 
3512
+ if (wdi_front['type'] != 'not_declared') {
3513
 
3514
+ wdi_front.clickOrTouch = wdi_front.detectEvent();
3515
+ //initializing all feeds in the page
3516
+ wdi_front.globalInit();
3517
+ } else {
3518
+ return;
3519
+ }
3520
+ });
 
 
 
 
 
 
 
 
 
3521
 
3522
 
3523
  }
3524
+ else {
3525
+ jQuery(document).ready(function ()
3526
+ {
3527
 
3528
 
3529
+ if (wdi_front['type'] != 'not_declared') {
3530
+ wdi_front.clickOrTouch = wdi_front.detectEvent();
3531
+ //initializing all feeds in the page
3532
+ wdi_front.globalInit();
3533
+ } else {
3534
+ return;
3535
+ }
3536
 
3537
+ });
3538
  }
3539
 
3540
+
js/wdi_responsive.js CHANGED
@@ -3,6 +3,7 @@ jQuery(document).ready(function ()
3
  {
4
 
5
  });
 
6
  function wdi_responsive()
7
  {
8
  };
@@ -113,7 +114,7 @@ wdi_responsive.columnControl = function (currentFeed, load, customWidth)
113
  for (var i = 0; i < colNum; i++) {
114
  newCols += '<div class="wdi_masonry_column" wdi_mas_col="' + i + '"></div>';
115
  }
116
- newCols += '<div class="clear">';
117
  wrapper.html(newCols);
118
 
119
  //resetting index variables
@@ -219,6 +220,8 @@ wdi_responsive.showCaption = function (caption, currentFeedCounter)
219
 
220
  //find maximum height in row
221
  var maxHeight = 0;
 
 
222
  for (var i = 0; i < indexes.length; i++) {
223
  var currentItem = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + ' .wdi_feed_wrapper [' + indexType + '=' + indexes[i] + ']');
224
  currentItem.addClass('wdi_row_affected');
3
  {
4
 
5
  });
6
+
7
  function wdi_responsive()
8
  {
9
  };
114
  for (var i = 0; i < colNum; i++) {
115
  newCols += '<div class="wdi_masonry_column" wdi_mas_col="' + i + '"></div>';
116
  }
117
+ newCols += '<div class="wdi_clear">';
118
  wrapper.html(newCols);
119
 
120
  //resetting index variables
220
 
221
  //find maximum height in row
222
  var maxHeight = 0;
223
+
224
+
225
  for (var i = 0; i < indexes.length; i++) {
226
  var currentItem = jQuery('#wdi_feed_' + currentFeed.feed_row.wdi_feed_counter + ' .wdi_feed_wrapper [' + indexType + '=' + indexes[i] + ']');
227
  currentItem.addClass('wdi_row_affected');
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://web-dorado.com/products/wordpress-instagram-feed-wd.html
4
  Tags: : custom instagram feed, feed, instagram, hashtag, Instagram feed, instagram gallery, instagram posts, Instagram images, Instagram photos, Instagram wall, lightbox, photos
5
  Requires at least: 3.9
6
  Tested up to: 4.7
7
- Stable tag: 1.1.21
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -107,6 +107,13 @@ After downloading the ZIP file of the Instagram Feed WD plugin,
107
 
108
  == Changelog ==
109
 
 
 
 
 
 
 
 
110
  = 1.1.21 =
111
  New: Three new plugins added to featured plugins list: Ad Manager WD, Youtube WD and Staff Team WD
112
  Fixed: Colors and opacities of share buttons in lightbox (PRO)
4
  Tags: : custom instagram feed, feed, instagram, hashtag, Instagram feed, instagram gallery, instagram posts, Instagram images, Instagram photos, Instagram wall, lightbox, photos
5
  Requires at least: 3.9
6
  Tested up to: 4.7
7
+ Stable tag: 1.1.22
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
107
 
108
  == Changelog ==
109
 
110
+ = 1.1.22 =
111
+ New: message displayed on frontend if feed has no media
112
+ Fixed: JS errors for media with Instagram's new "Slideshow" feature. This feature is not supported by Instagram's API yet.
113
+ Changed: Errors by plugin and Instagram API are alerted in frontend only for admins, otherwise output the message to the Web Console
114
+ Changed: Custom attribute "wdi_media_user" added to media containers in frontend. Useful for adding different event listeners, e.g. custom redirects for every user's media.
115
+ Changed: Minor style conflicts fixed
116
+
117
  = 1.1.21 =
118
  New: Three new plugins added to featured plugins list: Ad Manager WD, Youtube WD and Staff Team WD
119
  Fixed: Colors and opacities of share buttons in lightbox (PRO)
wd-instagram-feed.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Instagram Feed WD
4
  Plugin URI: https://web-dorado.com/products/wordpress-instagram-feed-wd.html
5
  Description: WD Instagram Feed is a user-friendly tool for displaying user or hashtag-based feeds on your website. You can create feeds with one of the available layouts. It allows displaying image metadata, open up images in lightbox, download them and even share in social networking websites.
6
- Version: 1.1.21
7
  Author: WebDorado
8
  Author URI: https://web-dorado.com
9
  License: GPLv2 or later
@@ -20,7 +20,7 @@ define("WDI_META", "_".WDI_VAR."_meta");
20
  //define("wdi",'wdi');
21
  define('WDI_FEED_TABLE','wdi_feeds');
22
  define('WDI_THEME_TABLE','wdi_themes');
23
- define('WDI_VERSION','1.1.21');
24
  define('WDI_IS_PRO','false');
25
 
26
 
3
  Plugin Name: Instagram Feed WD
4
  Plugin URI: https://web-dorado.com/products/wordpress-instagram-feed-wd.html
5
  Description: WD Instagram Feed is a user-friendly tool for displaying user or hashtag-based feeds on your website. You can create feeds with one of the available layouts. It allows displaying image metadata, open up images in lightbox, download them and even share in social networking websites.
6
+ Version: 1.1.22
7
  Author: WebDorado
8
  Author URI: https://web-dorado.com
9
  License: GPLv2 or later
20
  //define("wdi",'wdi');
21
  define('WDI_FEED_TABLE','wdi_feeds');
22
  define('WDI_THEME_TABLE','wdi_themes');
23
+ define('WDI_VERSION','1.1.22');
24
  define('WDI_IS_PRO','false');
25
 
26