PageSourceSearch

https://geocontacto.com/wp-content/plugins/buddypress-media/app/assets/js/rtMedia.backbone.js?ver=4.7.13

js geocontacto.com collected 2026-10-05 23:42:41 UTC 121,037 bytes, 3,708 lines download raw bytes

1var galleryObj;
2var nextpage = 2;
3var upload_sync = false;
4var activity_id = -1;
5var uploaderObj;
6var objUploadView;
7var rtmedia_load_template_flag = true;
8var rtmedia_add_media_button_post_update = false;
9
10/**
11 * Prevents XSS by escaping special HTML characters in strings (like file names).
12 */
13function rtm_escape_html(text) {
14  if (!text) return text;
15  return String(text)
16    .replace(/&/g, "&")
17    .replace(/</g, "&lt;")
18    .replace(/>/g, "&gt;")
19    .replace(/"/g, "&quot;")
20    .replace(/'/g, "&#039;");
21}
22
23/**
24 * Prevents DOM Selector Injection by ensuring IDs only contain safe characters.
25 */
26function sanitizeCommentMediaId(id) {
27  if (typeof id === "undefined" || id === null) {
28    return "";
29  }
30  return String(id).replace(/[^0-9a-zA-Z_\-]/g, "");
31}
32
33jQuery(document).ready(function () {
34  // Need to pass the object[key] as global variable.
35  if ("object" === typeof rtmedia_backbone) {
36    for (var key in rtmedia_backbone) {
37      window[key] = rtmedia_backbone[key];
38    }
39  }
40  if ("object" === typeof rtMedia_plupload) {
41    for (var key in rtMedia_plupload) {
42      window[key] = rtMedia_plupload[key];
43    }
44  }
45  if ("object" === typeof rtmedia_template) {
46    for (var key in rtmedia_template) {
47      window[key] = rtmedia_template[key];
48    }
49  }
50  if ("object" === typeof rtMedia_activity) {
51    for (var key in rtMedia_activity) {
52      window[key] = rtMedia_activity[key];
53    }
54  }
55  if ("object" === typeof rtmedia_bp) {
56    for (var key in rtmedia_bp) {
57      window[key] = rtmedia_bp[key];
58    }
59  }
60  if ("object" === typeof rtmedia_main) {
61    for (var key in rtmedia_main) {
62      window[key] = rtmedia_main[key];
63    }
64  }
65});
66
67jQuery(function ($) {
68  /**
69   * Issue 1059 fixed: negative comment count
70   */
71  $(document).ready(function () {
72    /**
73     * Bind dynamic event on delete button to remove media ul
74     */
75    $("#activity-stream").on("click", ".acomment-delete", function () {
76      /**
77       * get media ul
78       */
79      let media_children = $(this)
80        .closest("li")
81        .find("div.acomment-content ul.rtmedia-list");
82      if (media_children.length > 0) {
83        /**
84         * remove ul if exists, so buddypress comment js doesn't get confused between media ul and child comment ul
85         */
86        media_children.remove();
87      }
88    });
89
90    /**
91     * Remove imageEdit.save function call and add it only when image is being modified in WP editor.
92     */
93    $("#rtmedia_media_single_edit .rtm-button-save").on("click", function () {
94      var $media_id = $("#rtmedia-editor-media-id").val();
95      var $nonce = $("#rtmedia-editor-nonce").val();
96      if (
97        "undefined" === typeof $nonce ||
98        "" === $nonce.trim() ||
99        "undefined" === typeof $media_id ||
100        "" === $media_id.trim()
101      ) {
102        return;
103      }
104      $media_id = parseInt($media_id);
105      $media_head = $("#media-head-" + $media_id);
106      if (
107        !$media_head.length ||
108        "undefined" === typeof $media_head.css("display") ||
109        "none" !== $media_head.css("display").trim()
110      ) {
111        return;
112      }
113
114      imageEdit.save($media_id, $nonce);
115    });
116
117    /**
118     * Reload page when rtmedia_update type of activity is edited.
119     */
120    function filterBeaSaveSuccess() {
121      location.reload();
122    }
123    /**
124     * Prefilters ajax call which saves edited activity content.
125     * Needed with BuddyPress Edit Activity plugin.
126     * https://wordpress.org/plugins/buddypress-edit-activity/
127     */
128    $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
129      // Modify options, control originalOptions, store jqXHR, etc
130      try {
131        if (
132          null === originalOptions.data ||
133          typeof originalOptions.data === "undefined" ||
134          typeof originalOptions.data.action === "undefined" ||
135          "buddypress-edit-activity-save" !== originalOptions.data.action
136        ) {
137          return true;
138        }
139      } catch (e) {
140        return true;
141      }
142
143      if (
144        !$("#activity-" + originalOptions.data.activity_id).hasClass(
145          "rtmedia_update"
146        )
147      ) {
148        return;
149      }
150
151      // Change the callback function to our own function, which reloads the page.
152      originalOptions.success = filterBeaSaveSuccess;
153      options.success = filterBeaSaveSuccess;
154    });
155  });
156  /**
157   * End of issue 1059 fix
158   */
159
160  var o_is_album, o_is_edit_allowed;
161  if (typeof is_album == "undefined") {
162    o_is_album = new Array("");
163  } else {
164    o_is_album = is_album;
165  }
166  if (typeof is_edit_allowed == "undefined") {
167    o_is_edit_allowed = new Array("");
168  } else {
169    o_is_edit_allowed = is_edit_allowed;
170  }
171
172  rtMedia = window.rtMedia || {};
173
174  rtMedia = window.rtMedia || {};
175
176  rtMedia.Context = Backbone.Model.extend({
177    url: function () {
178      var url = rtmedia_media_slug + "/";
179
180      if (!upload_sync && nextpage > 0) {
181        url += "pg/" + nextpage + "/";
182      }
183
184      return url;
185    },
186    defaults: {
187      context: "post",
188      context_id: false,
189    },
190  });
191
192  rtMedia.Media = Backbone.Model.extend({
193    defaults: {
194      id: 0,
195      blog_id: false,
196      media_id: false,
197      media_author: false,
198      media_title: false,
199      album_id: false,
200      media_type: "photo",
201      activity_id: false,
202      privacy: 0,
203      views: 0,
204      downloads: 0,
205      ratings_average: 0,
206      ratings_total: 0,
207      ratings_count: 0,
208      likes: 0,
209      dislikes: 0,
210      guid: false,
211      width: 0,
212      height: 0,
213      rt_permalink: false,
214      duration: "0:00",
215      //"next": -1,
216      //"prev": -1
217    },
218  });
219
220  rtMedia.Gallery = Backbone.Collection.extend({
221    model: rtMedia.Media,
222    url: function () {
223      var temp = window.location.pathname;
224      var url = "";
225      if (temp.indexOf("/" + rtmedia_media_slug + "/") == -1) {
226        url = rtmedia_media_slug + "/";
227      } else {
228        if (temp.indexOf("pg/") == -1) {
229          url = temp;
230        } else {
231          url = window.location.pathname.substr(
232            0,
233            window.location.pathname.lastIndexOf("pg/")
234          );
235        }
236      }
237      if (!upload_sync && nextpage >= 1) {
238        if (url.substr(url.length - 1) != "/") {
239          url += "/";
240        }
241
242        url += "pg/" + nextpage + "/";
243      }
244
245      return url;
246    },
247    getNext: function (page, el, element) {
248      if (jQuery(".rtmedia-no-media-found").length > 0) {
249        var rtmediaListUl = jQuery("<ul/>", {
250          class: "rtmedia-list rtmedia-list-media rtm-pro-allow-action",
251        });
252        jQuery(".rtmedia-no-media-found").replaceWith(rtmediaListUl);
253      }
254      that = this;
255      if (rtmedia_load_template_flag == true) {
256        if (
257          jQuery(".rtmedia_gallery_wrapper").find("input[name=media_title]")
258            .length > 0
259        ) {
260          template_url +=
261            "&media_title=" +
262            jQuery(".rtmedia_gallery_wrapper")
263              .find("input[name=media_title]")
264              .val();
265        }
266        if (
267          jQuery(".rtmedia_gallery_wrapper").find("input[name=lightbox]")
268            .length > 0
269        ) {
270          template_url +=
271            "&lightbox=" +
272            jQuery(".rtmedia_gallery_wrapper")
273              .find("input[name=lightbox]")
274              .val();
275        }
276        $("#rtmedia-gallery-item-template").load(
277          template_url,
278          {
279            backbone: true,
280            is_album: o_is_album,
281            is_edit_allowed: o_is_edit_allowed,
282            wp_nonce: rtmedia_backbone_strings?.rtmedia_album_gallery_nonce,
283          },
284          function () {
285            rtmedia_load_template_flag = false;
286            that.getNext(page, el, element);
287          }
288        );
289      }
290
291      if (!rtmedia_load_template_flag) {
292        var query = {
293          json: true,
294        };
295
296        //media search
297        if (check_condition("search")) {
298          if ("" !== $("#media_search_input").val()) {
299            var search = check_url("search");
300            if (search) {
301              query.search = search;
302            }
303            if (check_condition("search_by")) {
304              var search_by = check_url("search_by");
305              if (search_by) {
306                query.search_by = search_by;
307              }
308            }
309          }
310        }
311
312        query.rtmedia_page = nextpage;
313
314        if (el == undefined) {
315          el = jQuery(".rtmedia-list").parent().parent();
316        }
317
318        if (el != undefined) {
319          if (element != undefined) {
320            $(element)
321              .parent()
322              .parent()
323              .prevAll("input[type=hidden]")
324              .not(
325                "input[name=_wp_http_referer], input[name=rtmedia_media_delete_nonce], input[name=rtmedia_bulk_delete_nonce], input[name=bulk-action], input[name=rtmedia_create_album_nonce], input[name=rtmedia_media_nonce], input[name=rtmedia_upload_nonce], input[name=rtmedia_allow_upload_attribute]"
326              )
327              .each(function (e) {
328                if ($(this).attr("name")) {
329                  query[$(this).attr("name")] = $(this).val();
330                }
331              });
332          }
333
334          $(el)
335            .find("input[type=hidden]")
336            .not(
337              "input[name=_wp_http_referer], input[name=rtmedia_media_delete_nonce], input[name=rtmedia_bulk_delete_nonce], input[name=bulk-action], input[name=rtmedia_create_album_nonce], input[name=rtmedia_media_nonce], input[name=rtmedia_upload_nonce], input[name=rtmedia_allow_upload_attribute]"
338            )
339            .each(function (e) {
340              if ($(this).attr("name")) {
341                query[$(this).attr("name")] = $(this).val();
342              }
343            });
344        }
345        this.fetch({
346          data: query,
347          success: function (model, response) {
348            jQuery(".rtm-media-loading").hide();
349            var list_el = "";
350
351            if (typeof element === "undefined") {
352              if (jQuery(el).find(".rtmedia-list").length > 0) {
353                list_el = jQuery(el).find(".rtmedia-list");
354              } else {
355                list_el = $(".rtmedia-list")[0];
356              }
357            } else {
358              list_el = element.parent().siblings(".rtmedia-list");
359            }
360            nextpage = response.next;
361
362            if (nextpage < 1) {
363              if (typeof el == "object") {
364                jQuery(el)
365                  .find(".rtmedia_next_prev")
366                  .children("#rtMedia-galary-next")
367                  .hide();
368              }
369            }
370
371            rtMedia.gallery = {};
372            rtMedia.gallery.page = page;
373
374            var galleryViewObj = new rtMedia.GalleryView({
375              collection: new rtMedia.Gallery(response.data),
376              el: list_el,
377            });
378            //Element.show();
379
380            // get current gallery container object
381            var current_gallery =
382              galleryViewObj.$el.parents(".rtmedia-container");
383            var current_gallery_id = current_gallery.attr("id");
384
385            rtMediaHook.call("rtmedia_after_gallery_load");
386
387            jQuery(
388              "#" + current_gallery_id + " .rtmedia_next_prev .rtm-pagination"
389            ).remove();
390            jQuery(
391              "#" + current_gallery_id + " .rtmedia_next_prev .clear"
392            ).remove();
393            jQuery(
394              "#" +
395                current_gallery_id +
396                " .rtmedia_next_prev .rtm-media-loading"
397            ).remove();
398            jQuery(
399              "#" + current_gallery_id + " .rtmedia_next_prev br"
400            ).remove();
401            jQuery("#" + current_gallery_id + " .rtmedia_next_prev").append(
402              response.pagination
403            );
404
405            // Update the media count in user profile & group's media tab.
406            jQuery(
407              "#user-media span, #media-groups-li #media span, #rtmedia-nav-item-all span"
408            ).text(response.media_count.all_media_count);
409
410            // Update the count on sub navigations (Albums)
411            // jQuery( '#rtmedia-nav-item-albums span' ).text( response.media_count.albums_count );
412
413            // Update the count on sub navigations (Photo, Video & Music)
414            jQuery("#rtmedia-nav-item-photo span").text(
415              response.media_count.photos_count
416            );
417            jQuery("#rtmedia-nav-item-music span").text(
418              response.media_count.music_count
419            );
420            jQuery("#rtmedia-nav-item-video span").text(
421              response.media_count.videos_count
422            );
423            jQuery("#rtmedia-nav-item-document span").text(
424              response.media_count.docs_count
425            );
426
427            if (jQuery("li#rtm-url-upload").length === 0) {
428              jQuery("#" + current_gallery_id + " .rtmedia-list").css({
429                opacity: 1,
430                height: "auto",
431                overflow: "auto",
432              });
433              if (
434                rtMediaHook.call(
435                  "rtmedia_js_uploader_slide_after_gallery_reload"
436                )
437              ) {
438                jQuery("#rtm-media-gallery-uploader").slideUp();
439              }
440            }
441          },
442        });
443      }
444    },
445    reloadView: function (parent_el) {
446      upload_sync = true;
447      nextpage = 1;
448      jQuery(".rtmedia-container .rtmedia-list").css("opacity", "0.5");
449      this.getNext(undefined, parent_el, undefined);
450    },
451  });
452
453  rtMedia.MediaView = Backbone.View.extend({
454    tagName: "li",
455    className: "rtmedia-list-item",
456    initialize: function () {
457      this.template = _.template($("#rtmedia-gallery-item-template").html());
458      this.model.on("change", this.render);
459      this.model.on("remove", this.unrender);
460      this.render();
461    },
462    render: function () {
463      $(this.el).html(this.template(this.model.toJSON()));
464      return this.el;
465    },
466    unrender: function () {
467      $(this.el).remove();
468    },
469    remove: function () {
470      this.model.destroy();
471    },
472  });
473
474  rtMedia.GalleryView = Backbone.View.extend({
475    tagName: "ul",
476    className: "rtmedia-list",
477    initialize: function () {
478      this.template = _.template($("#rtmedia-gallery-item-template").html());
479      this.render();
480    },
481    render: function () {
482      that = this;
483      var rtmedia_gallery_container_nodata = $(
484        'div[id^="rtmedia_gallery_container_"] .rtmedia-nodata'
485      );
486      if (upload_sync) {
487        $(that.el).html("");
488      }
489
490      if (
491        (typeof rtmedia_load_more_or_pagination != "undefined" &&
492          rtmedia_load_more_or_pagination == "pagination") ||
493        1 == rtMedia.gallery.page
494      ) {
495        $(that.el).html("");
496      }
497
498      // Remove no data found message if it's there.
499      if (rtmedia_gallery_container_nodata.length > 0) {
500        rtmedia_gallery_container_nodata.remove();
501      }
502      if (0 === this.collection.length) {
503        $('div[id^="rtmedia_gallery_container_"]').append(
504          '<p class="rtmedia-nodata">' + rtmedia_no_media_found + "</p>"
505        );
506      } else {
507        $.each(this.collection.toJSON(), function (key, media) {
508          $(that.el).append(that.template(media));
509        });
510      }
511
512      if (upload_sync) {
513        upload_sync = false;
514      }
515      if (nextpage > 1) {
516        $(that.el)
517          .siblings(".rtmedia_next_prev")
518          .children("#rtMedia-galary-next")
519          .show();
520        //$("#rtMedia-galary-next").show();
521      }
522      if (
523        "undefined" != typeof rtmedia_masonry_layout &&
524        "true" == rtmedia_masonry_layout &&
525        0 == jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length
526      ) {
527        rtm_masonry_reload(rtm_masonry_container);
528      }
529      $("#media_fatch_loader").removeClass("load");
530    },
531    appendTo: function (media) {
532      var mediaView = new rtMedia.MediaView({
533        model: media,
534      });
535      $(this.el).append(mediaView.render().el);
536    },
537  });
538
539  galleryObj = new rtMedia.Gallery();
540
541  $("body").append(
542    '<script id="rtmedia-gallery-item-template" type="text/template"></script>'
543  );
544
545  $(document).on("click", "#rtMedia-galary-next", function (e) {
546    if (jQuery(".rtm-media-loading").length == 0) {
547      $(this).before(
548        "<div class='rtm-media-loading'><img src='" +
549          rMedia_loading_media +
550          "' /></div>"
551      );
552    } else {
553      jQuery(".rtm-media-loading").show();
554    }
555    $(this).hide();
556    e.preventDefault();
557
558    //commented beacuse it was creating a problem when gallery shortcode was used with bulk edit
559    //galleryObj.getNext( nextpage, $( this ).parent().parent().parent(), $( this ) );
560
561    //Added beacuse it was creating a problem when gallery shortcode was used with bulk edit
562    var parent_object = $(this).closest(".rtmedia-container").parent();
563    galleryObj.getNext(nextpage, parent_object, $(this));
564  });
565
566  /**
567   * onClick Show all comment
568   */
569  $(document).on("click", "#rtmedia_show_all_comment", function () {
570    var show_comment = $("#rtmedia_show_all_comment").parent().next();
571    $(show_comment).each(function () {
572      $(this)
573        .find("li")
574        .each(function () {
575          $(this).removeClass("hide");
576        });
577    });
578    $(this).parent().remove();
579
580    /** Scroll function called */
581    rtMediaScrollComments();
582  });
583
584  $(document).on("keypress", "#rtmedia_go_to_num", function (e) {
585    if (e.keyCode == 13) {
586      e.preventDefault();
587
588      var current_gallery = $(this).parents(".rtmedia-container");
589      var current_gallery_id = current_gallery.attr("id");
590
591      if ($("#" + current_gallery_id + " .rtm-media-loading").length == 0) {
592        $("#" + current_gallery_id + " .rtm-pagination").before(
593          "<div class='rtm-media-loading'><img src='" +
594            rMedia_loading_media +
595            "' /></div>"
596        );
597      } else {
598        $("#" + current_gallery_id + " .rtm-media-loading").show();
599      }
600
601      if (
602        parseInt($("#" + current_gallery_id + " #rtmedia_go_to_num").val()) >
603        parseInt($("#" + current_gallery_id + " #rtmedia_last_page").val())
604      ) {
605        nextpage = parseInt(
606          $("#" + current_gallery_id + " #rtmedia_last_page").val()
607        );
608      } else {
609        nextpage = parseInt(
610          $("#" + current_gallery_id + " #rtmedia_go_to_num").val()
611        );
612      }
613
614      var page_base_url = $(
615        "#" + current_gallery_id + " .rtmedia-page-no .rtmedia-page-link"
616      ).data("page-base-url");
617      var href = page_base_url + nextpage;
618
619      change_rtBrowserAddressUrl(href, "");
620
621      galleryObj.getNext(
622        nextpage,
623        $(this).parents(".rtmedia_gallery_wrapper"),
624        $(this).parents(".rtm-pagination")
625      );
626      return false;
627    }
628  });
629
630  $(document).on("click", ".rtmedia-page-link", function (e) {
631    /* Get current clicked href value */
632    href = $(this).attr("href");
633
634    var current_gallery = $(this).parents(".rtmedia-container");
635    var current_gallery_id = current_gallery.attr("id");
636
637    if ($("#" + current_gallery_id + " .rtm-media-loading").length == 0) {
638      $("#" + current_gallery_id + " .rtm-pagination").before(
639        "<div class='rtm-media-loading'><img src='" +
640          rMedia_loading_media +
641          "' /></div>"
642      );
643    } else {
644      $("#" + current_gallery_id + " .rtm-media-loading").show();
645    }
646
647    e.preventDefault();
648    if ($(this).data("page-type") == "page") {
649      nextpage = $(this).data("page");
650    } else if ($(this).data("page-type") == "prev") {
651      if (nextpage == -1) {
652        nextpage =
653          parseInt($("#" + current_gallery_id + " #rtmedia_last_page").val()) -
654          1;
655      } else {
656        nextpage -= 2;
657      }
658    } else if ($(this).data("page-type") == "num") {
659      if (
660        parseInt($("#" + current_gallery_id + " #rtmedia_go_to_num").val()) >
661        parseInt($("#rtmedia_last_page").val())
662      ) {
663        nextpage = parseInt(
664          $("#" + current_gallery_id + " #rtmedia_last_page").val()
665        );
666      } else {
667        nextpage = parseInt(
668          $("#" + current_gallery_id + " #rtmedia_go_to_num").val()
669        );
670      }
671
672      /* Set page url for input type num pagination */
673      page_base_url = $(this).data("page-base-url");
674      href = page_base_url + nextpage;
675    }
676
677    var media_search_input = $("#media_search_input");
678    if (check_condition("search")) {
679      if (media_search_input.length > 0 && "" !== media_search_input.val()) {
680        var search_val = check_url("search");
681        href += "?search=" + search_val;
682
683        if (check_condition("search_by")) {
684          var search_by = check_url("search_by");
685          href += "&search_by=" + search_by;
686        }
687      }
688    }
689
690    change_rtBrowserAddressUrl(href, "");
691    galleryObj.getNext(
692      nextpage,
693      $(this).closest(".rtmedia-container").parent(),
694      $(this).closest(".rtm-pagination")
695    );
696  });
697
698  $(document).on("submit", "form#media_search_form", function (e) {
699    e.preventDefault();
700
701    var $media_search_input = $("#media_search_input").val();
702    var $media_search = $("#media_search");
703    var $media_fatch_loader = $("#media_fatch_loader");
704    var $media_type = $('input[type="hidden"][name="media_type"]');
705
706    if ("" === $media_search_input) {
707      return false;
708    }
709
710    $media_search.css("cursor", "pointer");
711    $media_fatch_loader.addClass("load");
712    nextpage = 1;
713
714    var href = window.location.href;
715    // Remove query string.
716    if (href.indexOf("?") > -1) {
717      href = window.location.pathname;
718    }
719
720    href += "?search=" + $media_search_input;
721    if ($("#search_by").length > 0) {
722      href += "&search_by=" + $("#search_by").val();
723    }
724
725    if ($media_type.length > 0 && "album" === $media_type.val()) {
726      href += "&media_type=" + $media_type.val();
727    }
728
729    href = encodeURI(href);
730
731    change_rtBrowserAddressUrl(href, "");
732    galleryObj.getNext(
733      nextpage,
734      $(this).closest(".rtmedia-container").parent()
735    );
736
737    $("#media_search_remove").show();
738  });
739
740  // media search remove
741  $(document).on("click", "#media_search_remove", function (e) {
742    $("#media_search").css("cursor", "not-allowed");
743    $("#media_fatch_loader").addClass("load");
744    jQuery("#media_search_input").val("");
745    nextpage = 1;
746    var href = window.location.pathname;
747    if (check_condition("/pg")) {
748      remove_index = href.indexOf("pg");
749      remove_href = href.substring(remove_index);
750      href = href.replace(remove_href, "");
751    }
752
753    change_rtBrowserAddressUrl(href, "");
754    galleryObj.getNext(
755      nextpage,
756      $(this).parent().parent().parent().parent().parent()
757    );
758    $("#media_search_remove").hide();
759  });
760
761  if (window.location.pathname.indexOf(rtmedia_media_slug) != -1) {
762    var tempNext = window.location.pathname.substring(
763      window.location.pathname.lastIndexOf("pg/") + 5,
764      window.location.pathname.lastIndexOf("/")
765    );
766    if (isNaN(tempNext) === false) {
767      nextpage = parseInt(tempNext) + 1;
768    }
769  }
770
771  window.UploadView = Backbone.View.extend({
772    events: {
773      "click #rtMedia-start-upload": "uploadFiles",
774    },
775    initialize: function (config) {
776      this.uploader = new plupload.Uploader(config);
777      /*
778       * 'ext_enabled' will get value of enabled media types if nothing is enabled,
779       * then an error message will be displayed.
780       */
781      var ext_enabled = config.filters[0].extensions.length;
782      if (ext_enabled === 0) {
783        this.uploader.bind("Browse", function (up) {
784          rtmedia_gallery_action_alert_message(
785            rtmedia_media_disabled_error_message,
786            "warning"
787          );
788        });
789      }
790    },
791    render: function () {},
792    initUploader: function (a) {
793      if (typeof a !== "undefined") {
794        a = false; // If rtmediapro widget calls the function, dont show max size note.
795      }
796      this.uploader.init();
797      //The plupload HTML5 code gives a negative z-index making add files button unclickable
798      $(".plupload.html5").css({
799        zIndex: 0,
800      });
801      $("#rtMedia-upload-button").css({
802        zIndex: 2,
803      });
804      if (a !== false) {
805        window.file_size_info =
806          rtmedia_max_file_msg + this.uploader.settings.max_file_size_msg;
807        if (rtmedia_version_compare(rtm_wp_version, "3.9")) {
808          // Plupload getting updated in 3.9
809          file_extn = this.uploader.settings.filters.mime_types[0].extensions;
810        } else {
811          file_extn = this.uploader.settings.filters[0].extensions;
812        }
813        window.file_extn_info =
814          rtmedia_allowed_file_formats +
815          " : " +
816          file_extn.split(",").join(", ");
817
818        var info = window.file_size_info + "\n" + window.file_extn_info;
819        $(".rtm-file-size-limit").attr("title", info);
820        //$("#rtMedia-upload-button").after("<span>( <strong>" + rtmedia_max_file_msg + "</strong> "+ this.uploader.settings.max_file_size_msg + ")</span>");
821      }
822
823      return this;
824    },
825    uploadFiles: function (e) {
826      if (e != undefined) {
827        e.preventDefault();
828      }
829      this.uploader.start();
830      return false;
831    },
832  });
833
834  if ($("#rtMedia-upload-button").length > 0) {
835    // Check if media_type is specified in shortcode via data attribute
836    var uploaderForm = jQuery("#rtmedia-uploader-form");
837    var mediaTypeFilter = uploaderForm.data("media-type");
838    
839    if (
840      mediaTypeFilter &&
841      typeof rtmedia_exteansions == "object" &&
842      rtmedia_exteansions[mediaTypeFilter]
843    ) {
844      // Use the specific media type extensions from shortcode attribute
845      rtMedia_plupload_config.filters[0].extensions =
846        rtmedia_exteansions[mediaTypeFilter].join();
847    } else if (
848      typeof rtmedia_upload_type_filter == "object" &&
849      rtmedia_upload_type_filter.length > 0
850    ) {
851      // Fallback to old method for backward compatibility
852      rtMedia_plupload_config.filters[0].extensions =
853        rtmedia_upload_type_filter.join();
854    }
855    uploaderObj = new UploadView(rtMedia_plupload_config);
856    uploaderObj.initUploader();
857
858    var rtnObj = "";
859    var redirect_request = false;
860
861    jQuery(document).ajaxComplete(function () {
862      if (redirect_request) {
863        redirect_request = false;
864        window.location = rtnObj.redirect_url;
865      }
866    });
867
868    uploaderObj.uploader.bind("UploadComplete", function (up, files) {
869      activity_id = -1;
870      var hook_respo = rtMediaHook.call("rtmedia_js_after_files_uploaded");
871      if (
872        typeof rtmedia_gallery_reload_on_upload != "undefined" &&
873        rtmedia_gallery_reload_on_upload == "1"
874      ) {
875        //Reload gallery view when upload completes if enabled( by default enabled)
876        if (hook_respo != false) {
877          galleryObj.reloadView();
878        }
879      }
880      jQuery("#rtmedia_uploader_filelist li.plupload_queue_li").remove();
881      jQuery(".start-media-upload").hide();
882      apply_rtMagnificPopup(
883        jQuery(
884          ".rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content"
885        )
886      );
887
888      var redirection = $("#rt_upload_hf_redirect");
889
890      if (
891        "" !== rtnObj &&
892        "undefined" !== typeof rtnObj.redirect_url &&
893        null !== rtnObj.redirect_url
894      ) {
895        if (
896          uploaderObj.upload_count === up.files.length &&
897          0 < redirection.length &&
898          "true" === redirection.val() &&
899          0 === rtnObj.redirect_url.indexOf("http")
900        ) {
901          redirect_request = true;
902        }
903      }
904
905      window.onbeforeunload = null;
906    });
907
908    uploaderObj.uploader.bind("FilesAdded", function (up, files) {
909      var upload_size_error = false;
910      var upload_error = "";
911      var upload_error_sep = "";
912      var upload_remove_array = [];
913
914      var select_btn = jQuery(".rtmedia-upload-input");
915      var upload_start_btn = jQuery(".start-media-upload");
916
917      $.each(files, function (i, file) {
918        //Set file title along with file
919        rtm_file_name_array = file.name.split(".");
920        file.title = rtm_file_name_array[0];
921
922        var hook_respo = rtMediaHook.call("rtmedia_js_file_added", [
923          up,
924          file,
925          "#rtmedia_uploader_filelist",
926        ]);
927
928        if (hook_respo == false) {
929          file.status = -1;
930          upload_remove_array.push(file.id);
931          return true;
932        }
933
934        select_btn.attr("value", rtmedia_add_more_files_msg);
935        if (
936          typeof rtmedia_direct_upload_enabled != "undefined" &&
937          rtmedia_direct_upload_enabled == "1"
938        ) {
939          upload_start_btn.hide();
940        } else {
941          upload_start_btn.show();
942        }
943        if (uploaderObj.uploader.settings.max_file_size < file.size) {
944          return true;
945        }
946        var tmp_array = file.name.split(".");
947        if (rtmedia_version_compare(rtm_wp_version, "3.9")) {
948          // Plupload getting updated in 3.9
949          var ext_array =
950            uploaderObj.uploader.settings.filters.mime_types[0].extensions.split(
951              ","
952            );
953        } else {
954          var ext_array =
955            uploaderObj.uploader.settings.filters[0].extensions.split(",");
956        }
957        if (tmp_array.length > 1) {
958          var ext = tmp_array[tmp_array.length - 1];
959          ext = ext.toLowerCase();
960          if (jQuery.inArray(ext, ext_array) === -1) {
961            return true;
962          }
963        } else {
964          return true;
965        }
966
967        if (rtmedia_version_compare(rtm_wp_version, "3.9")) {
968          // Plupload getting updated in 3.9
969          uploaderObj.uploader.settings.filters.mime_types[0].title;
970        } else {
971          uploaderObj.uploader.settings.filters[0].title;
972        }
973
974        // Creating list of media to preview selected files
975        rtmedia_selected_file_list(plupload, file, "", "");
976
977        //Delete Function
978        $("#" + file.id + " .plupload_delete .remove-from-queue").click(
979          function (e) {
980            e.preventDefault();
981            uploaderObj.uploader.removeFile(up.getFile(file.id));
982            $("#" + file.id).remove();
983            rtMediaHook.call("rtmedia_js_file_remove", [up, file]);
984            return false;
985          }
986        );
987
988        // To change the name of the uploading file
989        $("#label_" + file.id).click(function (e) {
990          e.preventDefault();
991
992          rtm_file_label = this;
993
994          rtm_file_title_id = "text_" + file.id;
995          rtm_file_title_input = "#" + rtm_file_title_id;
996          rtm_file_title_wrapper_id = "rtm_title_wp_" + file.id;
997          rtm_file_title_wrapper = "#" + rtm_file_title_wrapper_id;
998
999          rtm_file_desc_id = "rtm_desc_" + file.id;
1000          rtm_file_desc_input = "#" + rtm_file_desc_id;
1001          rtm_file_desc_wrapper_id = "rtm_desc_wp_" + file.id;
1002          rtm_file_desc_wrapper = "#" + rtm_file_desc_wrapper_id;
1003
1004          rtm_file_save_id = "save_" + file.id;
1005          rtm_file_save_el = "#" + rtm_file_save_id;
1006
1007          jQuery(rtm_file_label).hide();
1008          jQuery(rtm_file_label).siblings(".plupload_file_name_wrapper").hide();
1009
1010          // Show/create text box to edit media title
1011          if (jQuery(rtm_file_title_input).length === 0) {
1012            jQuery(rtm_file_label)
1013              .parent(".plupload_file_name")
1014              .prepend(
1015                '<div id="' +
1016                  rtm_file_title_wrapper_id +
1017                  '" class="rtm-upload-edit-title-wrapper"><label>' +
1018                  rtmedia_edit_media_info_upload.title +
1019                  '</label><input type="text" class="rtm-upload-edit-title" id="' +
1020                  rtm_file_title_id +
1021                  '" value="' +
1022                  file.title +
1023                  '" style="width: 75%;" /></div><div id="' +
1024                  rtm_file_desc_wrapper_id +
1025                  '" class="rtm-upload-edit-desc-wrapper"><label>' +
1026                  rtmedia_edit_media_info_upload.description +
1027                  '</label><textarea class="rtm-upload-edit-desc" id="' +
1028                  rtm_file_desc_id +
1029                  '"></textarea></div><span id="' +
1030                  rtm_file_save_id +
1031                  '" title="Save Change" class="dashicons dashicons-yes"></span>'
1032              );
1033          } else {
1034            jQuery(rtm_file_title_wrapper).show();
1035            jQuery(rtm_file_desc_wrapper).show();
1036            jQuery(rtm_file_save_el).show();
1037          }
1038
1039          jQuery(rtm_file_title_input).focus();
1040
1041          // Set media title and description in file object
1042          $("#save_" + file.id).click(function (e) {
1043            e.preventDefault();
1044
1045            rtm_file_label = this;
1046
1047            rtm_file_title_id = "text_" + file.id;
1048            rtm_file_title_input = "#" + rtm_file_title_id;
1049            rtm_file_title_wrapper_id = "rtm_title_wp_" + file.id;
1050            rtm_file_title_wrapper = "#" + rtm_file_title_wrapper_id;
1051
1052            rtm_file_desc_id = "rtm_desc_" + file.id;
1053            rtm_file_desc_input = "#" + rtm_file_desc_id;
1054            rtm_file_desc_wrapper_id = "rtm_desc_wp_" + file.id;
1055            rtm_file_desc_wrapper = "#" + rtm_file_desc_wrapper_id;
1056
1057            rtm_file_save_id = "save_" + file.id;
1058            rtm_file_save_el = "#" + rtm_file_save_id;
1059
1060            var file_title_val = jQuery(rtm_file_title_input).val();
1061            var file_desc_val = jQuery(rtm_file_desc_input).val();
1062            var file_name_wrapper_el = jQuery(rtm_file_label).siblings(
1063              ".plupload_file_name_wrapper"
1064            );
1065
1066            if ("" !== file_title_val.trim()) {
1067              var extension = file.name.split(".")[1];
1068              file_name_wrapper_el.text(file_title_val + "." + extension);
1069              file.title = file_title_val;
1070            }
1071
1072            if (file_desc_val != "") {
1073              file.description = file_desc_val;
1074            }
1075
1076            jQuery(rtm_file_title_wrapper).hide();
1077            jQuery(rtm_file_desc_wrapper).hide();
1078
1079            file_name_wrapper_el.show();
1080            jQuery(rtm_file_label)
1081              .siblings("#label_" + file.id)
1082              .show();
1083            jQuery(this).hide();
1084          });
1085        });
1086      });
1087
1088      $.each(upload_remove_array, function (i, rfile) {
1089        if (up.getFile(rfile)) {
1090          up.removeFile(up.getFile(rfile));
1091        }
1092      });
1093
1094      rtMediaHook.call("rtmedia_js_after_files_added", [up, files]);
1095
1096      if (
1097        typeof rtmedia_direct_upload_enabled != "undefined" &&
1098        rtmedia_direct_upload_enabled == "1"
1099      ) {
1100        var allow_upload = rtMediaHook.call("rtmedia_js_upload_file", {
1101          src: "uploader",
1102        });
1103        if (allow_upload == false) {
1104          return false;
1105        }
1106        uploaderObj.uploadFiles();
1107      }
1108
1109      upload_start_btn.focus();
1110    });
1111
1112    uploaderObj.uploader.bind("Error", function (up, err) {
1113      if (err.code == -600) {
1114        //File size error // if file size is greater than server's max allowed size
1115        var tmp_array;
1116        var ext = (tr = "");
1117        tmp_array = err.file.name.split(".");
1118        if (tmp_array.length > 1) {
1119          ext = tmp_array[tmp_array.length - 1];
1120          if (
1121            !(
1122              typeof up.settings.upload_size != "undefined" &&
1123              typeof up.settings.upload_size[ext] != "undefined" &&
1124              typeof up.settings.upload_size[ext]["size"]
1125            )
1126          ) {
1127            rtmedia_selected_file_list(plupload, err.file, up, err);
1128          }
1129        }
1130      } else {
1131        if (err.code == -601) {
1132          // File extension error
1133          err.message = rtmedia_file_extension_error_msg;
1134        }
1135
1136        rtmedia_selected_file_list(plupload, err.file, "", err);
1137      }
1138
1139      jQuery(".plupload_delete").on("click", function (e) {
1140        e.preventDefault();
1141        jQuery(this).parent().parent("li").remove();
1142      });
1143      return false;
1144    });
1145
1146    jQuery(".start-media-upload").on("click", function (e) {
1147      e.preventDefault();
1148      // Make search box blank while uploading a media. So that newly uploaded media can be shown after upload.
1149      var search_box = jQuery("#media_search_input");
1150      if (search_box.length > 0) {
1151        search_box.val("");
1152      }
1153
1154      /**
1155       * To check if any media file is selected or not for uploading
1156       */
1157      if (jQuery("#rtmedia_uploader_filelist").children("li").length > 0) {
1158        var allow_upload = rtMediaHook.call("rtmedia_js_upload_file", {
1159          src: "uploader",
1160        });
1161
1162        if (allow_upload == false) {
1163          return false;
1164        }
1165        uploaderObj.uploadFiles();
1166      }
1167    });
1168
1169    uploaderObj.uploader.bind("UploadProgress", function (up, file) {
1170      //$("#" + file.id + " .plupload_file_status").html(file.percent + "%");
1171      //$( "#" + file.id + " .plupload_file_status" ).html( rtmedia_uploading_msg + '( ' + file.percent + '% )' );
1172      // creates a progress bar to display file upload status
1173      var progressBar = jQuery("<div/>", {
1174        class: "plupload_file_progress ui-widget-header",
1175      });
1176      progressBar.css("width", file.percent + "%");
1177      $("#" + file.id + " .plupload_file_status").html(progressBar);
1178      // filter to customize existing progress bar can be used to display
1179      // '%' of upload completed.
1180      rtMediaHook.call("rtm_custom_progress_bar_content", [file]);
1181      $("#" + file.id).addClass("upload-progress");
1182      if (file.percent == 100) {
1183        $("#" + file.id).toggleClass("upload-success");
1184      }
1185
1186      window.onbeforeunload = function (evt) {
1187        var message = rtmedia_upload_progress_error_message;
1188        return message;
1189      };
1190    });
1191
1192    uploaderObj.uploader.bind("BeforeUpload", function (up, file) {
1193      // We send terms conditions data on backend to validate this on server side.
1194      rtMediaHook.call("rtmedia_js_before_upload", {
1195        uploader: up,
1196        file: file,
1197        src: "uploader",
1198      });
1199
1200      up.settings.multipart_params.title = file.title.split(".")[0];
1201
1202      if (typeof file.description != "undefined") {
1203        up.settings.multipart_params.description = file.description;
1204      } else {
1205        up.settings.multipart_params.description = "";
1206      }
1207
1208      var privacy = $("#rtm-file_upload-ui select.privacy").val();
1209      if (privacy !== undefined) {
1210        up.settings.multipart_params.privacy = $(
1211          "#rtm-file_upload-ui select.privacy"
1212        ).val();
1213      }
1214
1215      var redirection = $("#rt_upload_hf_redirect");
1216
1217      if (0 < redirection.length) {
1218        up.settings.multipart_params.redirect = up.files.length;
1219        up.settings.multipart_params.redirection = redirection.val();
1220      }
1221      jQuery("#rtmedia-uploader-form input[type=hidden]").each(function () {
1222        up.settings.multipart_params[$(this).attr("name")] = $(this).val();
1223      });
1224      up.settings.multipart_params.activity_id = activity_id;
1225      if ($("#rtmedia-uploader-form .rtmedia-user-album-list").length > 0) {
1226        up.settings.multipart_params.album_id = $(
1227          "#rtmedia-uploader-form .rtmedia-user-album-list"
1228        )
1229          .find(":selected")
1230          .val();
1231      } else if (
1232        $("#rtmedia-uploader-form .rtmedia-current-album").length > 0
1233      ) {
1234        up.settings.multipart_params.album_id = $(
1235          "#rtmedia-uploader-form .rtmedia-current-album"
1236        ).val();
1237      }
1238
1239      rtMediaHook.call("rtmedia_js_before_file_upload", [up, file]);
1240    });
1241
1242    uploaderObj.uploader.bind("FileUploaded", function (up, file, res) {
1243      if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
1244        //Test for MSIE x.x;
1245        var ieversion = new Number(RegExp.$1); // Capture x.x portion and store as a number
1246
1247        if (ieversion < 10) {
1248          if (typeof res.response !== "undefined") {
1249            res.status = 200;
1250          }
1251        }
1252      }
1253
1254      try {
1255        rtnObj = JSON.parse(res.response);
1256        uploaderObj.uploader.settings.multipart_params.activity_id =
1257          rtnObj.activity_id;
1258        activity_id = rtnObj.activity_id;
1259        if (rtnObj.permalink != "") {
1260          $("#" + file.id + " .plupload_file_name").html(
1261            "<a href='" +
1262              rtnObj.permalink +
1263              "' target='_blank' title='" +
1264              rtnObj.permalink +
1265              "'>" +
1266              file.title.substring(0, 40).replace(/(<([^>]+)>)/gi, "") +
1267              "</a>"
1268          );
1269          $("#" + file.id + " .plupload_media_edit").html(
1270            "<a href='" +
1271              rtnObj.permalink +
1272              "edit' target='_blank'><span title='" +
1273              rtmedia_edit_media +
1274              "'><i class='dashicons dashicons-edit'></i> " +
1275              rtmedia_edit +
1276              "</span></a>"
1277          );
1278          $("#" + file.id + " .plupload_delete").html(
1279            "<span id='" +
1280              rtnObj.media_id +
1281              "' class='rtmedia-delete-uploaded-media dashicons dashicons-dismiss' title='" +
1282              rtmedia_delete +
1283              "'></span>"
1284          );
1285        }
1286      } catch (e) {
1287        // Console.log('Invalid Activity ID');
1288      }
1289      if (res.status == 200 || res.status == 302) {
1290        if (uploaderObj.upload_count == undefined) {
1291          uploaderObj.upload_count = 1;
1292        } else {
1293          uploaderObj.upload_count++;
1294        }
1295
1296        rtMediaHook.call("rtmedia_js_after_file_upload", [
1297          up,
1298          file,
1299          res.response,
1300        ]);
1301      } else {
1302        $("#" + file.id + " .plupload_file_status").html(
1303          rtmedia_upload_failed_msg
1304        );
1305      }
1306
1307      files = up.files;
1308      lastfile = files[files.length - 1];
1309    });
1310
1311    uploaderObj.uploader.refresh(); //Refresh the uploader for opera/IE fix on media page
1312
1313    $("#rtMedia-start-upload").click(function (e) {
1314      uploaderObj.uploadFiles(e);
1315    });
1316    $("#rtMedia-start-upload").hide();
1317
1318    jQuery(document).on("click", "#rtm_show_upload_ui", function () {
1319      jQuery("#rtm-media-gallery-uploader").slideToggle();
1320      uploaderObj.uploader.refresh(); //Refresh the uploader for opera/IE fix on media page
1321      jQuery("#rtm_show_upload_ui").toggleClass("primary");
1322    });
1323  } else {
1324    jQuery(document).on("click", "#rtm_show_upload_ui", function () {
1325      /*
1326       * 'enabled_ext' will get value of enabled media types if nothing is enabled,
1327       * then an error message will be displayed.
1328       */
1329      if ("object" === typeof rtMedia_plupload_config) {
1330        var enabled_ext = rtMedia_plupload_config.filters[0].extensions.length;
1331        if (0 === enabled_ext) {
1332          // If no media type is enabled error message will be displayed.
1333          rtmedia_gallery_action_alert_message(
1334            rtmedia_media_disabled_error_message,
1335            "warning"
1336          );
1337        }
1338      }
1339
1340      jQuery("#rtm-media-gallery-uploader").slideToggle();
1341      jQuery("#rtm_show_upload_ui").toggleClass("primary");
1342    });
1343  }
1344
1345  jQuery(document).on(
1346    "click",
1347    ".plupload_delete .rtmedia-delete-uploaded-media",
1348    function () {
1349      var that = $(this);
1350      if (confirm(rtmedia_delete_uploaded_media)) {
1351        var nonce = $(
1352          "#rtmedia-upload-container #rtmedia_media_delete_nonce"
1353        ).val();
1354        var media_id = $(this).attr("id");
1355        var data = {
1356          action: "delete_uploaded_media",
1357          nonce: nonce,
1358          media_id: media_id,
1359        };
1360
1361        $.post(ajaxurl, data, function (response) {
1362          if (response == "1") {
1363            that.closest("tr").remove();
1364            $("#" + media_id).remove();
1365          }
1366        });
1367      }
1368    }
1369  );
1370});
1371
1372/** Activity Update Js **/
1373
1374jQuery(document).ready(function ($) {
1375  /**
1376   * Uploader improper enter behavior issue(124) fixed
1377   *
1378   * @param e
1379   */
1380  var submit_function = function (e) {
1381    /**
1382     * Execute code only on enter key
1383     */
1384    if (e.keyCode === 13) {
1385      /**
1386       * Prevent default behavior and fire custom click
1387       */
1388      e.preventDefault();
1389      $(this).trigger("click");
1390      /**
1391       * stop textarea from disabling
1392       * @type {*|jQuery|HTMLElement}
1393       */
1394      var textarea = $("#whats-new");
1395      textarea.removeAttr("disabled");
1396      /**
1397       * set focus to textarea after buddypress timeout code
1398       */
1399      setTimeout(function () {
1400        textarea.focus();
1401      }, 200);
1402    }
1403  };
1404  /**
1405   * End of issue 124 fix
1406   */
1407
1408  /**
1409   * UI changes for buddypress nouveau theme on activity page
1410   */
1411  if (bp_template_pack && "legacy" !== bp_template_pack) {
1412    var whats_new_form = jQuery("#whats-new-form");
1413
1414    jQuery("#whats-new").on("focus", function () {
1415      var rt_uploader_div = whats_new_form.find(".rtmedia-uploader-div");
1416      var rt_uploader_filelist = whats_new_form.find(
1417        "#rtmedia_uploader_filelist"
1418      );
1419      var whats_new_option = whats_new_form.find("#whats-new-options");
1420
1421      rt_uploader_div.show();
1422
1423      if (0 !== whats_new_option.length) {
1424        whats_new_option.show();
1425
1426        whats_new_option.css({
1427          opacity: "1",
1428        });
1429      }
1430
1431      rt_uploader_div.addClass("clearfix");
1432
1433      whats_new_form.find("#rtmedia-action-update").removeClass("clearfix");
1434
1435      rt_uploader_filelist.addClass("clear-both");
1436      rt_uploader_filelist.removeClass("clearfix");
1437    });
1438
1439    whats_new_form.on("reset", function () {
1440      whats_new_form.find(".rtmedia-uploader-div").hide();
1441    });
1442
1443    whats_new_form.on("submit", function () {
1444      window.onbeforeunload = null;
1445      setTimeout(function () {
1446        whats_new_form.find(".rtmedia-uploader-div").hide();
1447      }, 2000);
1448    });
1449  }
1450  /**
1451   * End of UI changes
1452   */
1453
1454  /*
1455   * Fix for file selector does not open in Safari browser in IOS.
1456   * In Safari in IOS, Plupload don't click on it's input(type=file), so file selector dialog won't open.
1457   * In order to fix this, when rtMedia's attach media button is clicked,
1458   * we check if Plupload's input(type=file) is clicked or not, if it's not clicked, then we click it manually
1459   * to open file selector.
1460   */
1461
1462  // Initially, select file dialog is close.
1463  var file_dialog_open = false;
1464
1465  var button = "#rtmedia-upload-container #rtMedia-upload-button";
1466
1467  var input_file_el = "#rtmedia-upload-container input[type=file]:first";
1468
1469  // Bind callback on Plupload's input element.
1470  jQuery(document.body).on("click", input_file_el, function () {
1471    file_dialog_open = true;
1472  });
1473
1474  // Bind callback on rtMedia's attach media button.
1475  jQuery(document.body).on("click", button, function () {
1476    if (false === file_dialog_open) {
1477      jQuery(input_file_el).click();
1478      file_dialog_open = false;
1479    }
1480  });
1481
1482  // Handling the "post update: button on activity page
1483  /**
1484   * Commented by : Naveen giri
1485   * Reason : Commenting this code because its overriding buddypress functionality
1486   * 			and introducing issue Duplicate activity generation  Issue #108.
1487   */
1488  /*JQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
1489	jQuery( document ).on( 'blur', '#whats-new', function() {
1490		setTimeout( function() {
1491			jQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
1492		}, 100 );
1493	} );
1494	jQuery( '#aw-whats-new-submit' ).on( 'click', function( e ) {
1495		setTimeout( function() {
1496			jQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
1497		}, 100 );
1498	} );*/
1499
1500  // When user changes the value in activity "post in" dropdown, hide the privacy dropdown and show when posting in profile.
1501  jQuery("#whats-new-post-in").on("change", function (e) {
1502    if (jQuery(this).val() == "0") {
1503      jQuery("#whats-new-form #rtmedia-action-update .privacy")
1504        .prop("disabled", false)
1505        .show();
1506    } else {
1507      jQuery("#whats-new-form #rtmedia-action-update .privacy")
1508        .prop("disabled", true)
1509        .hide();
1510    }
1511  });
1512
1513  // change color of what's new if content is &nbsp;
1514  let whatsNew = jQuery("#whats-new");
1515  whatsNew.on("keyup", function (e) {
1516    if ("&nbsp;" === whatsNew.val()) {
1517      whatsNew.css("color", "transparent");
1518    } else {
1519      let replaceNbsp = whatsNew.val().replace("&nbsp;", "");
1520      whatsNew.val(replaceNbsp);
1521      whatsNew.css("color", "inherit");
1522    }
1523  });
1524
1525  if (typeof rtMedia_update_plupload_config == "undefined") {
1526    return false;
1527  }
1528  var activity_attachemnt_ids = [];
1529
1530  if (!rtmedia_add_media_button_post_update) {
1531    rtmedia_add_media_button_post_update = $(
1532      "#rtmedia-add-media-button-post-update"
1533    );
1534  }
1535
1536  if (rtmedia_add_media_button_post_update.length > 0) {
1537    objUploadView = new UploadView(rtMedia_update_plupload_config);
1538    objUploadView.initUploader();
1539
1540    setTimeout(function () {
1541      if (rtmedia_add_media_button_post_update.length > 0) {
1542        $("#whats-new-options").prepend(
1543          $("#whats-new-form .rtmedia-plupload-container")
1544        );
1545        if ($("#whats-new-form #rtm-file_upload-ui .privacy").length > 0) {
1546          $("#whats-new-form .rtmedia-plupload-container").append(
1547            $("#whats-new-form #rtm-file_upload-ui .privacy")
1548          );
1549        }
1550        $("#whats-new-form #rtmedia-whts-new-upload-container > div").css(
1551          "top",
1552          "0"
1553        );
1554        $("#whats-new-form #rtmedia-whts-new-upload-container > div").css(
1555          "left",
1556          "0"
1557        );
1558      }
1559    }, 100);
1560
1561    /**
1562     * Appends rtMedia Uploader option below form content section
1563     */
1564    if (bp_template_pack && "legacy" !== bp_template_pack) {
1565      var form_ref = jQuery("#whats-new-form");
1566      var rt_uploader_div = jQuery(".rtmedia-uploader-div");
1567
1568      if (
1569        0 < jQuery(".activity-update-form").length &&
1570        0 < form_ref.length &&
1571        0 < rt_uploader_div.length
1572      ) {
1573        jQuery(form_ref).append(rt_uploader_div);
1574        rt_uploader_div.hide();
1575      }
1576    } else {
1577      var new_options = jQuery("#whats-new-options");
1578      var rt_uploader_div = jQuery("#whats-new-form .rtmedia-uploader-div");
1579
1580      if (0 < new_options.length && 0 < rt_uploader_div.length) {
1581        new_options.append(rt_uploader_div);
1582      }
1583    }
1584
1585    if (!rtmedia_add_media_button_post_update) {
1586      rtmedia_add_media_button_post_update = $(
1587        "#rtmedia-add-media-button-post-update"
1588      );
1589    }
1590    $("#whats-new-form").on(
1591      "click",
1592      rtmedia_add_media_button_post_update,
1593      function (e) {
1594        objUploadView.uploader.refresh();
1595        $("#rtmedia-whts-new-upload-container > div").css("top", "0");
1596        $("#rtmedia-whts-new-upload-container > div").css("left", "0");
1597
1598        /**
1599         * NOTE: Do not change.
1600         * ISSUE: BuddyPress activity upload issue with Microsoft Edge
1601         * GL: 132 [ http://git.rtcamp.com/rtmedia/rtMedia/issues/132 ]
1602         * Reason: Trigger event not working for hidden element in Microsoft Edge browser
1603         * Condition to check current browser.
1604         */
1605        if (/Edge/.test(navigator.userAgent)) {
1606          jQuery(this)
1607            .closest(".rtm-upload-button-wrapper")
1608            .find("input[type=file]")
1609            .click();
1610        }
1611
1612        //Enable 'post update' button when media get select
1613        $("#aw-whats-new-submit").prop("disabled", false);
1614      }
1615    );
1616    //Whats-new-post-in
1617
1618    objUploadView.upload_remove_array = [];
1619
1620    objUploadView.uploader.bind("FilesAdded", function (upl, rfiles) {
1621      //$("#aw-whats-new-submit").attr('disabled', 'disabled');
1622
1623      //Remove focusout when media is added in activity post.
1624      jQuery("#whats-new-form").off("focusout");
1625
1626      $.each(rfiles, function (i, file) {
1627        //Set file title along with file
1628        file.title = file.name.substring(0, file.name.lastIndexOf("."));
1629
1630        rtm_file_name_array = file.name.split(".");
1631
1632        var hook_respo = rtMediaHook.call("rtmedia_js_file_added", [
1633          upl,
1634          file,
1635          "#rtmedia_uploader_filelist",
1636        ]);
1637
1638        if (hook_respo == false) {
1639          file.status = -1;
1640          objUploadView.upload_remove_array.push(file.id);
1641          return true;
1642        }
1643
1644        if (objUploadView.uploader.settings.max_file_size < file.size) {
1645          return true;
1646        }
1647
1648        var tmp_array = file.name.split(".");
1649
1650        if (rtmedia_version_compare(rtm_wp_version, "3.9")) {
1651          // Plupload getting updated in 3.9
1652          var ext_array =
1653            objUploadView.uploader.settings.filters.mime_types[0].extensions.split(
1654              ","
1655            );
1656        } else {
1657          var ext_array =
1658            objUploadView.uploader.settings.filters[0].extensions.split(",");
1659        }
1660        if (tmp_array.length > 1) {
1661          var ext = tmp_array[tmp_array.length - 1];
1662          ext = ext.toLowerCase();
1663          if (jQuery.inArray(ext, ext_array) === -1) {
1664            return true;
1665          }
1666        } else {
1667          return true;
1668        }
1669
1670        rtmedia_selected_file_list(plupload, file, "", "");
1671
1672        jQuery("#whats-new-content").css("padding-bottom", "0px");
1673
1674        $("#" + file.id + " .plupload_delete").click(function (e) {
1675          e.preventDefault();
1676          objUploadView.uploader.removeFile(upl.getFile(file.id));
1677          $("#" + file.id).remove();
1678          return false;
1679        });
1680
1681        // To change the name of the uploading file
1682        $("#label_" + file.id).click(function (e) {
1683          e.preventDefault();
1684
1685          rtm_file_label = this;
1686
1687          rtm_file_title_id = "text_" + file.id;
1688          rtm_file_title_input = "#" + rtm_file_title_id;
1689
1690          rtm_file_title_wrapper_id = "rtm_title_wp_" + file.id;
1691          rtm_file_title_wrapper = "#" + rtm_file_title_wrapper_id;
1692
1693          rtm_file_desc_id = "rtm_desc_" + file.id;
1694          rtm_file_desc_input = "#" + rtm_file_desc_id;
1695
1696          rtm_file_desc_wrapper_id = "rtm_desc_wp_" + file.id;
1697          rtm_file_desc_wrapper = "#" + rtm_file_desc_wrapper_id;
1698
1699          rtm_file_save_id = "save_" + file.id;
1700          rtm_file_save_el = "#" + rtm_file_save_id;
1701
1702          jQuery(rtm_file_label).hide();
1703          jQuery(rtm_file_label).siblings(".plupload_file_name_wrapper").hide();
1704
1705          // Show/create text box to edit media title
1706          if (jQuery(rtm_file_title_input).length === 0) {
1707            jQuery(rtm_file_label)
1708              .parent(".plupload_file_name")
1709              .prepend(
1710                '<div id="' +
1711                  rtm_file_title_wrapper_id +
1712                  '" class="rtm-upload-edit-title-wrapper"><label>' +
1713                  rtmedia_edit_media_info_upload.title +
1714                  '</label><input type="text" class="rtm-upload-edit-title" id="' +
1715                  rtm_file_title_id +
1716                  '" value="' +
1717                  file.title +
1718                  '" style="width: 75%;" /></div><div id="' +
1719                  rtm_file_desc_wrapper_id +
1720                  '" class="rtm-upload-edit-desc-wrapper"><label>' +
1721                  rtmedia_edit_media_info_upload.description +
1722                  '</label><textarea class="rtm-upload-edit-desc" id="' +
1723                  rtm_file_desc_id +
1724                  '"></textarea></div><span id="' +
1725                  rtm_file_save_id +
1726                  '" title="Save Change" class="dashicons dashicons-yes"></span>'
1727              );
1728          } else {
1729            jQuery(rtm_file_title_wrapper).show();
1730            jQuery(rtm_file_desc_wrapper).show();
1731            jQuery(rtm_file_save_el).show();
1732          }
1733
1734          jQuery(rtm_file_title_input).focus();
1735        });
1736
1737        rtm_file_save_id = "save_" + file.id;
1738        rtm_file_save_el = "#" + rtm_file_save_id;
1739        jQuery(document.body).on("click", rtm_file_save_el, function (e) {
1740          e.preventDefault();
1741          rtm_file_title_id = "text_" + file.id;
1742          rtm_file_title_input = "#" + rtm_file_title_id;
1743
1744          rtm_file_desc_id = "rtm_desc_" + file.id;
1745          rtm_file_desc_input = "#" + rtm_file_desc_id;
1746
1747          rtm_file_title_wrapper_id = "rtm_title_wp_" + file.id;
1748          rtm_file_title_wrapper = "#" + rtm_file_title_wrapper_id;
1749
1750          rtm_file_desc_wrapper_id = "rtm_desc_wp_" + file.id;
1751          rtm_file_desc_wrapper = "#" + rtm_file_desc_wrapper_id;
1752
1753          var file_title_val = jQuery(rtm_file_title_input).val();
1754          var file_desc_val = jQuery(rtm_file_desc_input).val();
1755
1756          rtm_file_label = "#label_" + file.id;
1757
1758          var file_name_wrapper_el = jQuery(rtm_file_label).siblings(
1759            ".plupload_file_name_wrapper"
1760          );
1761
1762          if ("" !== file_title_val.trim()) {
1763            var extension = file.name.split(".")[1];
1764            file_name_wrapper_el.text(file_title_val + "." + extension);
1765            file.title = file_title_val;
1766          }
1767
1768          if (file_desc_val != "") {
1769            file.description = file_desc_val;
1770          }
1771
1772          jQuery(rtm_file_title_wrapper).hide();
1773          jQuery(rtm_file_desc_wrapper).hide();
1774          file_name_wrapper_el.show();
1775          jQuery(rtm_file_label).siblings(".plupload_file_name_wrapper");
1776          jQuery(rtm_file_label).show();
1777          jQuery(this).hide();
1778        });
1779      });
1780
1781      $.each(objUploadView.upload_remove_array, function (i, rfile) {
1782        if (upl.getFile(rfile)) {
1783          upl.removeFile(upl.getFile(rfile));
1784        }
1785      });
1786
1787      /*
1788       * add rtmedia_activity_text_with_attachment condition to filter
1789       * if user want media and activity_text both require
1790       * By: Yahil
1791       */
1792      if ("" === jQuery("#whats-new").val().trim()) {
1793        if (rtmedia_activity_text_with_attachment == "disable") {
1794          if ("legacy" === bp_template_pack) {
1795            $("#whats-new").css("color", "transparent");
1796            $("#whats-new").val("&nbsp;");
1797          }
1798        } else {
1799          jQuery("#whats-new-form").prepend(
1800            '<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' +
1801              rtmedia_empty_activity_msg +
1802              " </p></div>"
1803          );
1804          jQuery("#whats-new").removeAttr("disabled");
1805          return false;
1806        }
1807      }
1808
1809      if (
1810        typeof rtmedia_direct_upload_enabled != "undefined" &&
1811        rtmedia_direct_upload_enabled == "1"
1812      ) {
1813        //Call upload event direct when direct upload is enabled (removed UPLOAD button and its triggered event)
1814        var allow_upload = rtMediaHook.call("rtmedia_js_upload_file", {
1815          src: "activity",
1816        });
1817
1818        if (allow_upload == false) {
1819          return false;
1820        }
1821        objUploadView.uploadFiles();
1822      }
1823
1824      /**
1825       * Uploader improper enter behavior issue(124) fixed
1826       */
1827      $("#aw-whats-new-submit").focus();
1828      $(document).off("keydown", "#aw-whats-new-submit", submit_function);
1829      $(document).on("keydown", "#aw-whats-new-submit", submit_function);
1830      /**
1831       * End issue 124
1832       */
1833    });
1834
1835    objUploadView.uploader.bind("FileUploaded", function (up, file, res) {
1836      if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
1837        //Test for MSIE x.x;
1838        var ieversion = new Number(RegExp.$1); // Capture x.x portion and store as a number
1839
1840        if (ieversion < 10) {
1841          try {
1842            if (typeof JSON.parse(res.response) !== "undefined") {
1843              res.status = 200;
1844            }
1845          } catch (e) {}
1846        }
1847      }
1848
1849      if (res.status == 200) {
1850        try {
1851          var objIds = JSON.parse(res.response);
1852          $.each(objIds, function (key, val) {
1853            activity_attachemnt_ids.push(val);
1854            if (
1855              $("#whats-new-form").find("#rtmedia_attached_id_" + val).length <
1856              1
1857            ) {
1858              $("#whats-new-form").append(
1859                "<input type='hidden' name='rtMedia_attached_files[]' data-mode='rtMedia-update' id='rtmedia_attached_id_" +
1860                  val +
1861                  "' value='" +
1862                  val +
1863                  "' />"
1864              );
1865            }
1866          });
1867        } catch (e) {}
1868        rtMediaHook.call("rtmedia_js_after_file_upload", [
1869          up,
1870          file,
1871          res.response,
1872        ]);
1873      }
1874    });
1875
1876    objUploadView.uploader.bind("Error", function (up, err) {
1877      if (err.code == -600) {
1878        //File size error // if file size is greater than server's max allowed size
1879        var tmp_array;
1880        var ext = (tr = "");
1881        tmp_array = err.file.name.split(".");
1882        if (tmp_array.length > 1) {
1883          ext = tmp_array[tmp_array.length - 1];
1884          if (
1885            !(
1886              typeof up.settings.upload_size != "undefined" &&
1887              typeof up.settings.upload_size[ext] != "undefined" &&
1888              (up.settings.upload_size[ext]["size"] < 1 ||
1889                up.settings.upload_size[ext]["size"] * 1024 * 1024 >=
1890                  err.file.size)
1891            )
1892          ) {
1893            rtmedia_selected_file_list(plupload, err.file, up, err);
1894          }
1895        }
1896      } else {
1897        if (err.code == -601) {
1898          // File extension error
1899          err.message = rtmedia_file_extension_error_msg;
1900        }
1901
1902        rtmedia_selected_file_list(plupload, err.file, "", err);
1903      }
1904
1905      jQuery(".plupload_delete").on("click", function (e) {
1906        e.preventDefault();
1907        jQuery(this).parent().parent("li").remove();
1908      });
1909
1910      return false;
1911    });
1912
1913    objUploadView.uploader.bind("BeforeUpload", function (up, files) {
1914      // We send terms conditions data on backend to validate this on server side.
1915      rtMediaHook.call("rtmedia_js_before_upload", {
1916        uploader: up,
1917        file: files,
1918        src: "activity",
1919      });
1920
1921      $.each(objUploadView.upload_remove_array, function (i, rfile) {
1922        if (up.getFile(rfile)) {
1923          up.removeFile(up.getFile(rfile));
1924        }
1925      });
1926
1927      var object = "profile";
1928      var item_id = 0;
1929
1930      if ("legacy" === bp_template_pack) {
1931        if (jQuery("#whats-new-post-in").length > 0) {
1932          item_id = jQuery("#whats-new-post-in").val();
1933        }
1934
1935        /* Set object for non-profile posts */
1936        if (item_id > 0 && jQuery("#whats-new-post-object").length > 0) {
1937          object = jQuery("#whats-new-post-object").val();
1938        }
1939      } else {
1940        if ("undefined" !== typeof BP_Nouveau?.activity?.params?.object) {
1941          object = BP_Nouveau.activity.params.object;
1942        }
1943
1944        if ("undefined" !== typeof BP_Nouveau?.activity?.params?.item_id) {
1945          item_id = BP_Nouveau.activity.params.item_id;
1946        } else if (
1947          ("profile" === object || "user" === object) &&
1948          "undefined" !== typeof BP_Nouveau?.activity?.params?.user_id
1949        ) {
1950          item_id = BP_Nouveau.activity.params.user_id;
1951        }
1952      }
1953
1954      if ("groups" === object) {
1955        object = "group";
1956      } else if ("user" === object) {
1957        object = "profile";
1958      }
1959
1960      up.settings.multipart_params.context = object;
1961      up.settings.multipart_params.context_id = item_id;
1962      up.settings.multipart_params.title = files.title;
1963
1964      if (typeof files.description != "undefined") {
1965        up.settings.multipart_params.description = files.description;
1966      } else {
1967        up.settings.multipart_params.description = "";
1968      }
1969
1970      // If privacy dropdown is not disabled, then get the privacy value of the update
1971      if (jQuery("#whats-new-form select.privacy").prop("disabled") === false) {
1972        up.settings.multipart_params.privacy = jQuery(
1973          "#whats-new-form select.privacy"
1974        ).val();
1975      }
1976    });
1977
1978    objUploadView.uploader.bind("UploadComplete", function (up, files) {
1979      media_uploading = true;
1980
1981      /**
1982       * Blank error display issue resolved
1983       */
1984      if (bp_template_pack && "legacy" !== bp_template_pack) {
1985        if (
1986          "legacy" === bp_template_pack &&
1987          "disable" === rtmedia_activity_text_with_attachment &&
1988          "" === jQuery.trim(jQuery("#whats-new").val())
1989        ) {
1990          let textarea = jQuery("#whats-new");
1991          textarea.css("color", "transparent");
1992          textarea.val(" ");
1993        }
1994
1995        jQuery("#whats-new-form").submit();
1996      } else {
1997        jQuery("#aw-whats-new-submit").click();
1998      }
1999
2000      jQuery(
2001        "#whats-new-form #rtmedia_uploader_filelist li.plupload_queue_li"
2002      ).remove();
2003      window.onbeforeunload = null;
2004    });
2005
2006    objUploadView.uploader.bind("UploadProgress", function (up, file) {
2007      //$( "#" + file.id + " .plupload_file_status" ).html( rtmedia_uploading_msg + '( ' + file.percent + '% )' );
2008      // creates a progress bar to display file upload status
2009      var progressBar = jQuery("<div/>", {
2010        class: "plupload_file_progress ui-widget-header",
2011      });
2012      progressBar.css("width", file.percent + "%");
2013      $("#" + file.id + " .plupload_file_status").html(progressBar);
2014      // filter to customize existing progress bar can be used to display
2015      // '%' of upload completed.
2016      rtMediaHook.call("rtm_custom_progress_bar_content", [file]);
2017      $("#" + file.id).addClass("upload-progress");
2018      if (file.percent == 100) {
2019        $("#" + file.id).toggleClass("upload-success");
2020      }
2021
2022      window.onbeforeunload = function (evt) {
2023        var message = rtmedia_upload_progress_error_message;
2024        return message;
2025      };
2026    });
2027
2028    $("#rtMedia-start-upload").hide();
2029
2030    var change_flag = false;
2031    var media_uploading = false;
2032
2033    $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
2034      // Modify options, control originalOptions, store jqXHR, etc
2035      try {
2036        if (
2037          originalOptions.data == null ||
2038          typeof originalOptions.data == "undefined" ||
2039          typeof originalOptions.data.action == "undefined"
2040        ) {
2041          return true;
2042        }
2043      } catch (e) {
2044        return true;
2045      }
2046
2047      if (
2048        originalOptions.data.action == "post_update" ||
2049        originalOptions.data.action == "activity_widget_filter"
2050      ) {
2051        var temp = activity_attachemnt_ids;
2052        while (activity_attachemnt_ids.length > 0) {
2053          options.data +=
2054            "&rtMedia_attached_files[]=" + activity_attachemnt_ids.pop();
2055        }
2056
2057        var dynamic_privacy = "";
2058
2059        var privacy_select = jQuery("#rtSelectPrivacy");
2060        var whats_new_form = jQuery("#whats-new-form");
2061        if (whats_new_form.length > 0 && privacy_select.length > 0) {
2062          dynamic_privacy = privacy_select.val();
2063        }
2064
2065        options.data += "&rtmedia-privacy=" + dynamic_privacy;
2066        activity_attachemnt_ids = temp;
2067
2068        var orignalSuccess = originalOptions.success;
2069        options.beforeSend = function () {
2070          /**
2071           * This hook is added for rtMedia Upload Terms plugin to check if it is checked or not for activity
2072           */
2073          var allowActivityPost = rtMediaHook.call(
2074            "rtmedia_js_before_activity_added",
2075            { src: "activity" }
2076          );
2077
2078          if (!allowActivityPost) {
2079            $("#whats-new-form #rtmedia-whts-new-upload-container")
2080              .find("input")
2081              .removeAttr("disabled");
2082
2083            /**
2084             * Issue fixed: 1056(rtmedia-upload-terms) - Not allowing to upload
2085             */
2086            var activity_textarea = $("#whats-new");
2087            activity_textarea.removeAttr("disabled");
2088            /**
2089             * End of issue 1056 fix
2090             */
2091
2092            return false;
2093          }
2094
2095          if (originalOptions.data.action == "post_update") {
2096            if (
2097              $.trim($("#whats-new").val()) == "" &&
2098              objUploadView.uploader.files.length > 0
2099            ) {
2100              /*
2101               * Added $nbsp; as activity text to post activity without TEXT
2102               * Disabled TextBox color(transparent)
2103               * ELSE
2104               * Required Activity text with media
2105               * add rtmedia_activity_text_with_attachment condition to filter
2106               * if user want media and activity_text both require
2107               * By: Yahil
2108               */
2109
2110              if (rtmedia_activity_text_with_attachment == "disable") {
2111                if ("legacy" === bp_template_pack) {
2112                  $("#whats-new").css("color", "transparent");
2113                  $("#whats-new").val("&nbsp;");
2114                }
2115              } else {
2116                jQuery("#whats-new-form").prepend(
2117                  '<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' +
2118                    rtmedia_empty_activity_msg +
2119                    " </p></div>"
2120                );
2121                jQuery("#whats-new").removeAttr("disabled");
2122                return false;
2123              }
2124            }
2125          }
2126          if (!media_uploading && objUploadView.uploader.files.length > 0) {
2127            $("#whats-new-post-in").attr("disabled", "disabled");
2128            if (!rtmedia_add_media_button_post_update) {
2129              rtmedia_add_media_button_post_update = $(
2130                "#rtmedia-add-media-button-post-update"
2131              );
2132            }
2133            rtmedia_add_media_button_post_update.attr("disabled", "disabled");
2134
2135            var terms_condition_cb = $("#rtmedia_upload_terms_conditions");
2136            if (terms_condition_cb.prop("checked")) {
2137              terms_condition_cb.prop("disabled", true);
2138            }
2139
2140            objUploadView.uploadFiles();
2141            media_uploading = true;
2142            return false;
2143          } else {
2144            media_uploading = false;
2145            return true;
2146          }
2147        };
2148        options.success = function (response) {
2149          // For BuddyPress Nouveau Template.
2150          if (orignalSuccess && "function" === typeof orignalSuccess) {
2151            orignalSuccess(response);
2152          }
2153
2154          if (response[0] + response[1] == "-1") {
2155            //Error
2156          } else {
2157            if (originalOptions.data.action == "activity_widget_filter") {
2158              $("div.activity").on("fadeIn", function () {
2159                apply_rtMagnificPopup(
2160                  jQuery(
2161                    ".rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content"
2162                  )
2163                );
2164                rtMediaHook.call("rtmedia_js_after_activity_added", []);
2165                if (!rtmedia_add_media_button_post_update) {
2166                  rtmedia_add_media_button_post_update = jQuery(
2167                    "#rtmedia-add-media-button-post-update"
2168                  );
2169                }
2170
2171                rtmedia_add_media_button_post_update.removeAttr("disabled");
2172              });
2173              $("div.activity").fadeIn(100);
2174            }
2175            jQuery("input[data-mode=rtMedia-update]").remove();
2176            while (objUploadView.uploader.files.pop() != undefined) {}
2177            objUploadView.uploader.refresh();
2178            $("#rtmedia-whts-new-upload-container > div").css({
2179              top: "0",
2180              left: "0",
2181            });
2182            $("#whats-new-form #rtMedia-update-queue-list").html("");
2183
2184            apply_rtMagnificPopup(
2185              jQuery(
2186                ".rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content"
2187              )
2188            );
2189
2190            // For BuddyPress New Template hacks
2191            jQuery(".plupload_filelist_content.rtm-plupload-list").html("");
2192
2193            rtMediaHook.call("rtmedia_js_after_activity_added", []);
2194            if (!rtmedia_add_media_button_post_update) {
2195              rtmedia_add_media_button_post_update = jQuery(
2196                "#rtmedia-add-media-button-post-update"
2197              );
2198            }
2199            rtmedia_add_media_button_post_update.removeAttr("disabled");
2200          }
2201
2202          // rtmedia_on_activity_add();
2203
2204          $("#whats-new-post-in").removeAttr("disabled");
2205          if (!rtmedia_add_media_button_post_update) {
2206            rtmedia_add_media_button_post_update = $(
2207              "#rtmedia-add-media-button-post-update"
2208            );
2209          }
2210          rtmedia_add_media_button_post_update.removeAttr("disabled");
2211          // Enabled TextBox color back to normal
2212          $("#whats-new").val("");
2213          $("#whats-new").css("color", "");
2214        };
2215      }
2216    });
2217  } else {
2218    $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
2219      // Modify options, control originalOptions, store jqXHR, etc
2220      try {
2221        if (
2222          originalOptions.data == null ||
2223          typeof originalOptions.data == "undefined" ||
2224          typeof originalOptions.data.action == "undefined"
2225        ) {
2226          return true;
2227        }
2228      } catch (e) {
2229        return true;
2230      }
2231
2232      if (
2233        originalOptions.data.action == "post_update" ||
2234        originalOptions.data.action == "activity_widget_filter"
2235      ) {
2236        var dynamic_privacy = "";
2237
2238        if (
2239          jQuery("select.privacy").not(".rtm-activity-privacy-opt").length > 0
2240        ) {
2241          dynamic_privacy = jQuery("select.privacy")
2242            .not(".rtm-activity-privacy-opt")
2243            .val();
2244        } else if (jQuery('input[name="privacy"]').length > 0) {
2245          dynamic_privacy = jQuery('input[name="privacy"]').val();
2246        }
2247
2248        options.data += "&rtmedia-privacy=" + dynamic_privacy;
2249        var orignalSuccess = originalOptions.done;
2250        options.done = function (response) {
2251          orignalSuccess(response);
2252          if (response[0] + response[1] == "-1") {
2253            //Error
2254          } else {
2255            if (originalOptions.data.action == "activity_widget_filter") {
2256              $("div.activity").fadeIn(100);
2257            }
2258          }
2259
2260          $("#whats-new-post-in").removeAttr("disabled");
2261          // Enabled TextBox color back to normal
2262          $("#whats-new").css("color", "");
2263        };
2264      }
2265    });
2266  }
2267});
2268
2269/**
2270 * RtMedia Comment Js
2271 */
2272jQuery(document).ready(function ($) {
2273  jQuery(document).on(
2274    "click",
2275    "#rt_media_comment_form #rt_media_comment_submit",
2276    function (e) {
2277      var that = this;
2278      var widget_id = jQuery(this).attr("widget_id");
2279      var comment_form_el = jQuery(this).closest("form");
2280      var comment_content_el = comment_form_el.find("#comment_content");
2281
2282      var show_error = false;
2283      var content = jQuery.trim(comment_content_el.val());
2284
2285      comment_attached_id = comment_form_el
2286        .find('input[name="rtMedia_attached_files[]"]')
2287        .val();
2288      if (typeof comment_attached_id == "undefined" && content == "") {
2289        show_error = 1;
2290      } else {
2291        if (comment_attached_id == "" && content == "") {
2292          show_error = 2;
2293        }
2294      }
2295
2296      if (show_error) {
2297        rtmedia_single_media_alert_message(
2298          rtmedia_empty_comment_msg,
2299          "warning",
2300          true
2301        );
2302
2303        if (widget_id) {
2304          rtmedia_comment_media_input_button(widget_id, false);
2305        } else {
2306          rtmedia_comment_submit_button_disable(false);
2307        }
2308
2309        return false;
2310      }
2311
2312      $(this).attr("disabled", "disabled");
2313      //If string has only &nbsp; then set value as empty.
2314      if ("" === comment_content_el.val().replace(/\&nbsp;/g, "")) {
2315        comment_content_el.val("");
2316      }
2317      $.ajax({
2318        url: comment_form_el.attr("action"),
2319        type: "post",
2320        data: comment_form_el.serialize() + "&rtajax=true",
2321        success: function (data) {
2322          $("#rtmedia-no-comments").remove();
2323
2324          $("#rtmedia_comment_ul").append(data);
2325
2326          comment_content_el.val("");
2327
2328          if (widget_id) {
2329            rtmedia_comment_media_remove_hidden_media_id(widget_id);
2330            rtmedia_comment_media_textbox_val(widget_id, false);
2331            rtmedia_comment_media_input_button(widget_id, false);
2332          } else {
2333            rtmedia_comment_submit_button_disable(false);
2334          }
2335
2336          rtmedia_apply_popup_to_media();
2337
2338          rtmedia_reset_video_and_audio_for_popup();
2339
2340          rtMediaHook.call("rtmedia_js_after_comment_added", []);
2341
2342          /** Scroll function called */
2343          rtMediaScrollComments();
2344
2345          /** refreshing fragments */
2346          if (
2347            false == $("body").hasClass("activity") &&
2348            false == $("body").hasClass("groups")
2349          ) {
2350            galleryObj.reloadView();
2351          }
2352        },
2353        error: function (data) {
2354          if (widget_id) {
2355            rtmedia_comment_media_input_button(widget_id, false);
2356            rtmedia_comment_media_remove_hidden_media_id(widget_id);
2357          } else {
2358            rtmedia_comment_submit_button_disable(false);
2359          }
2360        },
2361      });
2362
2363      return false;
2364    }
2365  );
2366
2367  //Delete comment
2368  jQuery(document).on("click", ".rtmedia-delete-comment", function (e) {
2369    e.preventDefault();
2370    var ask_confirmation = true;
2371    ask_confirmation = rtMediaHook.call(
2372      "rtmedia_js_delete_comment_confirmation",
2373      [ask_confirmation]
2374    );
2375    if (
2376      ask_confirmation &&
2377      !confirm(rtmedia_media_comment_delete_confirmation)
2378    ) {
2379      return false;
2380    }
2381    var current_comment = jQuery(this);
2382    var current_comment_parent = current_comment.parent();
2383    var comment_id = current_comment.data("id");
2384    current_comment_parent.css("opacity", "0.4");
2385    if (comment_id == "" || isNaN(comment_id)) {
2386      return false;
2387    }
2388    var comment_ul = current_comment.closest("ul");
2389    var action = comment_ul.data("action");
2390    var delete_nonce = comment_ul.attr("data-delete-nonce");
2391
2392    jQuery.ajax({
2393      url: action,
2394      type: "post",
2395      data: { comment_id: comment_id, rtmedia_delete_comment_nonce: delete_nonce },
2396      success: function (res) {
2397        if (res != "undefined" && res == 1) {
2398          current_comment.closest("li").hide(1000, function () {
2399            current_comment.closest("li").remove();
2400          });
2401        } else {
2402          current_comment_parent.css("opacity", "1");
2403        }
2404        rtMediaHook.call("rtmedia_js_after_comment_deleted", []);
2405      },
2406    });
2407  });
2408
2409  $(document).on("click", ".rtmedia-like", function (e) {
2410    e.preventDefault();
2411    var that = this;
2412    var like_nonce = $("#rtm_media_like_nonce").val();
2413    $(this).attr("disabled", "disabled");
2414    var url = $(this).parent().attr("action");
2415    $(that).prepend(
2416      "<img class='rtm-like-loading' src='" +
2417        rMedia_loading_file +
2418        "' style='width:10px' />"
2419    );
2420    $.ajax({
2421      url: url,
2422      type: "post",
2423      data: { json: true, like_nonce: like_nonce },
2424      success: function (data) {
2425        try {
2426          data = JSON.parse(data);
2427        } catch (e) {}
2428
2429        $(".rtmedia-like span").html(data.next);
2430        $(".rtmedia-like").attr("title", data.next);
2431        $(".rtmedia-like-counter-wrap").html(data.person_text);
2432        $(".rtm-like-loading").remove();
2433        $(that).removeAttr("disabled");
2434        var comments_container = $(".rtmedia-comments-container").length;
2435
2436        //Update the like counter
2437        // $( '.rtmedia-like-counter' ).html( data.count );
2438        if (data.count > 0) {
2439          $(".rtmedia-like-info, .rtm-like-comments-info").removeClass("hide");
2440        } else {
2441          $(".rtmedia-like-info").addClass("hide");
2442
2443          // Add hide class to this element when "comment on media" is not enabled.
2444          if (0 === comments_container) {
2445            $(".rtm-like-comments-info").addClass("hide");
2446          }
2447        }
2448      },
2449    });
2450  });
2451  $(document).on(
2452    "click",
2453    ".rtmedia-featured, .rtmedia-group-featured",
2454    function (e) {
2455      e.preventDefault();
2456      var that = this;
2457      $(this).attr("disabled", "disabled");
2458      var featured_nonce = $(this).siblings("#rtm_media_featured_nonce").val();
2459      var url = $(this).parent().attr("action");
2460      $(that).prepend(
2461        "<img class='rtm-featured-loading' src='" + rMedia_loading_file + "' />"
2462      );
2463      $.ajax({
2464        url: url,
2465        type: "post",
2466        data: { json: true, featured_nonce: featured_nonce },
2467        success: function (data) {
2468          try {
2469            data = JSON.parse(data);
2470          } catch (e) {}
2471
2472          if (data.nonce) {
2473            rtmedia_single_media_alert_message(
2474              rtmedia_something_wrong_msg,
2475              "warning"
2476            );
2477          } else {
2478            if (data.action) {
2479              rtmedia_single_media_alert_message(
2480                rtmedia_set_featured_image_msg,
2481                "success"
2482              );
2483            } else {
2484              rtmedia_single_media_alert_message(
2485                rtmedia_unset_featured_image_msg,
2486                "success"
2487              );
2488            }
2489          }
2490          $(that).find("span").html(data.next);
2491          $(".rtm-featured-loading").remove();
2492          $(that).removeAttr("disabled");
2493        },
2494      });
2495    }
2496  );
2497  jQuery("#div-attache-rtmedia")
2498    .find("input[type=file]")
2499    .each(function () {
2500      //$(this).attr("capture", "camera");
2501      // $(this).attr("accept", $(this).attr("accept") + ';capture=camera');
2502    });
2503
2504  // Manually trigger fadein event so that we can bind some function on this event. It is used in activity when content getting load via ajax
2505  var _old_fadein = $.fn.fadeIn;
2506  jQuery.fn.fadeIn = function () {
2507    return _old_fadein.apply(this, arguments).trigger("fadeIn");
2508  };
2509});
2510
2511function rtmedia_selected_file_list(
2512  plupload,
2513  file,
2514  uploader,
2515  error,
2516  comment_media_id
2517) {
2518  var icon = "",
2519    err_msg = "",
2520    upload_progress = "",
2521    title = "";
2522
2523  /**
2524   * Blank error display issue resolved
2525   */
2526  if (bp_template_pack && "legacy" !== bp_template_pack) {
2527    var new_submit_btn = jQuery("#aw-whats-new-submit");
2528    if (0 < new_submit_btn.length) {
2529      var new_button = jQuery("<input>", {
2530        type: "button",
2531        class: "button",
2532        name: "aw-whats-new-submit",
2533        id: "aw-whats-new-submit",
2534        value: new_submit_btn.val(),
2535      });
2536
2537      new_submit_btn.replaceWith(new_button);
2538
2539      new_button.on("click", function (e) {
2540        if (!rtmedia_add_media_button_post_update) {
2541          rtmedia_add_media_button_post_update = jQuery(
2542            "#rtmedia-add-media-button-post-update"
2543          );
2544        }
2545        rtmedia_add_media_button_post_update.prop("disabled", true);
2546        if (
2547          rtMediaHook.call("rtmedia_js_before_activity_added", {
2548            src: "activity",
2549          })
2550        ) {
2551          objUploadView.uploadFiles(e);
2552        }
2553      });
2554    }
2555  }
2556
2557  var safeCommentMediaId = sanitizeCommentMediaId(comment_media_id);
2558
2559  rtmedia_uploader_filelist =
2560    typeof comment_media_id === "undefined" || safeCommentMediaId === ""
2561      ? "#rtmedia_uploader_filelist"
2562      : "#rtmedia_uploader_filelist-" + safeCommentMediaId;
2563
2564  plupload_delete =
2565    typeof comment_media_id === "undefined" || safeCommentMediaId === ""
2566      ? "plupload_delete"
2567      : "plupload_delete-" + safeCommentMediaId;
2568
2569  var safe_file_name = file.name ? rtm_escape_html(file.name) : "";
2570
2571  if (error == "") {
2572    upload_progress =
2573      '<div class="plupload_file_progress ui-widget-header" style="width: 0%;">';
2574    upload_progress += "</div>";
2575    icon =
2576      '<span id="label_' +
2577      file.id +
2578      '" class="dashicons dashicons-edit" title="' +
2579      rtmedia_backbone_strings.rtm_edit_file_name +
2580      '"></span>';
2581  } else if (error.code == -600) {
2582    alert(rtmedia_max_file_msg + uploader.settings.max_file_size);
2583    err_msg =
2584      uploader != ""
2585        ? rtmedia_max_file_msg + uploader.settings.max_file_size
2586        : window.file_size_info;
2587    title = "title='" + rtm_escape_html(err_msg) + "'";
2588    icon = '<i class="dashicons dashicons-info" ' + title + "></i>";
2589  } else if (error.code == -601) {
2590    alert(error.message + ". " + window.file_extn_info);
2591    err_msg = error.message + ". " + window.file_extn_info;
2592    title = "title='" + rtm_escape_html(err_msg) + "'";
2593    icon = '<i class="dashicons dashicons-info" ' + title + "></i>";
2594  }
2595
2596  var rtmedia_plupload_file =
2597    '<li class="plupload_file ui-state-default plupload_queue_li" id="' +
2598    file.id +
2599    '" ' +
2600    title +
2601    ">";
2602  rtmedia_plupload_file +=
2603    '<div id="file_thumb_' + file.id + '" class="plupload_file_thumb">';
2604  rtmedia_plupload_file += "</div>";
2605  rtmedia_plupload_file += '<div class="plupload_file_status">';
2606  rtmedia_plupload_file += upload_progress;
2607  rtmedia_plupload_file += "</div>";
2608  rtmedia_plupload_file +=
2609    '<div class="plupload_file_name" title="' +
2610    safe_file_name + '">';
2611  rtmedia_plupload_file += '<span class="plupload_file_name_wrapper">';
2612  rtmedia_plupload_file += safe_file_name;
2613  rtmedia_plupload_file += "</span>";
2614  rtmedia_plupload_file += icon;
2615  rtmedia_plupload_file += "</div>";
2616  rtmedia_plupload_file += '<div class="plupload_file_action">';
2617  rtmedia_plupload_file +=
2618    '<div class="plupload_action_icon ui-icon ' + plupload_delete + '">';
2619  rtmedia_plupload_file +=
2620    '<span class="remove-from-queue dashicons dashicons-dismiss"></span>';
2621  rtmedia_plupload_file += "</div>";
2622  rtmedia_plupload_file += "</div>";
2623  rtmedia_plupload_file += '<div class="plupload_file_size">';
2624  rtmedia_plupload_file += plupload.formatSize(file.size).toUpperCase();
2625  rtmedia_plupload_file += "</div>";
2626  rtmedia_plupload_file += '<div class="plupload_file_fields">';
2627  rtmedia_plupload_file += "</div>";
2628  rtmedia_plupload_file += "</li>";
2629
2630  if (error.code !== -601 && error.code !== -600) {
2631    jQuery(rtmedia_plupload_file).appendTo(rtmedia_uploader_filelist);
2632  }
2633
2634  if (comment_media_id) {
2635    jQuery("#rtmedia-comment-media-upload-" + comment_media_id).focus();
2636  } else {
2637    jQuery("#whats-new").focus();
2638  }
2639
2640  var type = file.type;
2641  var media_title = file.name;
2642  var ext = media_title.substring(
2643    media_title.lastIndexOf(".") + 1,
2644    media_title.length
2645  );
2646
2647  if (/image/i.test(type)) {
2648    if (ext === "gif") {
2649      jQuery('<img src="' + rtmedia_media_thumbs["photo"] + '" />').appendTo(
2650        "#file_thumb_" + file.id
2651      );
2652    } else {
2653      var img = new mOxie.Image();
2654      img.onload = function () {
2655        this.embed(jQuery("#file_thumb_" + file.id).get(0), {
2656          width: 100,
2657          height: 60,
2658          crop: true,
2659        });
2660      };
2661      img.onembedded = function () {
2662        this.destroy();
2663      };
2664      img.onerror = function () {
2665        this.destroy();
2666      };
2667      img.load(file.getSource());
2668    }
2669  } else {
2670    jQuery.each(rtmedia_exteansions, function (key, value) {
2671      if (value.indexOf(ext) >= 0) {
2672        var media_thumbnail = "";
2673        if (rtmedia_media_thumbs[ext]) {
2674          media_thumbnail = rtmedia_media_thumbs[ext];
2675        } else {
2676          media_thumbnail = rtmedia_media_thumbs[key];
2677        }
2678        jQuery("<img />", { src: media_thumbnail }).appendTo(
2679          "#file_thumb_" + file.id
2680        );
2681        return false;
2682      }
2683    });
2684  }
2685}
2686
2687/* Change URLin browser without reloading the page */
2688function change_rtBrowserAddressUrl(url, page) {
2689  if (typeof history.pushState != "undefined") {
2690    var obj = { Page: page, Url: url };
2691    history.pushState(obj, obj.Page, obj.Url);
2692  }
2693}
2694
2695// Escape regex special characters in a string so it can be safely used in a RegExp.
2696// This covers: . * + ? ^ $ { } ( ) | [ ] \
2697function escapeForRegex(str) {
2698  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2699}
2700
2701/**
2702 * Get query string value
2703 * ref: http://stackoverflow.com/questions/9870512/how-to-obtaining-the-querystring-from-the-current-url-with-javascript
2704 * return string
2705 */
2706function getQueryStringValue(key) {
2707  const safeKey = escapeForRegex(encodeURIComponent(key));
2708  const regex = new RegExp(
2709    "^(?:.*[&\\?]" + safeKey + "(?:=([^&]*))?)?.*$",
2710    "i"
2711  );
2712  return decodeURIComponent(window.location.search.replace(regex, "$1"));
2713}
2714
2715/**
2716 * Check paramater are available or not in url
2717 * return bool
2718 */
2719function check_condition(key) {
2720  if (window.location.href.indexOf(key) > 0) {
2721    return true;
2722  } else {
2723    return false;
2724  }
2725}
2726
2727/**
2728 * Check paramater are available or not in URL parameters
2729 * Ref: https://www.kevinleary.net/jquery-parse-url
2730 * return bool
2731 */
2732function escapeRegExp(str) {
2733  return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2734}
2735
2736function check_url(query) {
2737  query = escapeRegExp(query);
2738  var expr = "[\\?&]" + query + "=([^&#]*)";
2739  var regex = new RegExp(expr);
2740  var results = regex.exec(window.location.href);
2741  if (null !== results) {
2742    return results[1];
2743  } else {
2744    return false;
2745  }
2746}
2747
2748/*
2749 * To change this template, choose Tools | Templates
2750 * and open the template in the editor.
2751 */
2752var commentObj = {};
2753var plupload_comment_main = {};
2754var comment_media_wrapper = "comment-media-wrapper-";
2755var rtmedia_comment_media_submit = "rtmedia-comment-media-submit-";
2756var comment_media_add_button = "rtmedia-comment-media-upload-";
2757var comment_media_uplaod_media = "rtMedia-start-upload-";
2758
2759jQuery(document).ready(function ($) {
2760  rtMediaHook.register("rtmedia_js_popup_after_content_added", function () {
2761    var popup_upload_comment = jQuery(
2762      ".rtmedia-single-container .rtmedia-single-meta .rtm-media-single-comments form"
2763    );
2764    rtmedia_comment_media_upload(popup_upload_comment);
2765    rtmedia_apply_popup_to_media();
2766    return true;
2767  });
2768
2769  rtmedia_apply_popup_to_media();
2770  rtmedia_comment_media_single_page();
2771  rtmedia_activity_comment_js_add_media_id();
2772  rtmedia_activity_stream_comment_media();
2773  rtmedia_buddypress_load_newest_button_click();
2774});
2775
2776function rtmedia_reset_video_and_audio() {
2777  jQuery(
2778    "ul.activity-list li.activity-item div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, ul.activity-list li.activity-item div.rtmedia-item-thumbnail > video.wp-video-shortcode"
2779  ).mediaelementplayer({
2780    // This is required to work with new MediaElement version.
2781    classPrefix: "mejs-",
2782    // If the <video width> is not specified, this is the default
2783    defaultVideoWidth: 480,
2784    // If the <video height> is not specified, this is the default
2785    defaultVideoHeight: 270,
2786  });
2787}
2788
2789function rtmedia_on_activity_add() {
2790  rtmedia_activity_stream_comment_media();
2791
2792  rtmedia_reset_video_and_audio();
2793
2794  rtmedia_apply_popup_to_media();
2795}
2796
2797function rtmedia_single_page_popup_close() {
2798  /* on close of popup resize the video height */
2799  if (typeof rtmedia_media_size_config != "undefined") {
2800    if (typeof rtmedia_media_size_config.video.activity_media != "undefined") {
2801      jQuery(
2802        ".rtmedia-single-container .rtmedia-comment-media-container .mejs-container.mejs-video"
2803      ).css({
2804        height: rtmedia_media_size_config.video.activity_media.height,
2805        width: rtmedia_media_size_config.video.activity_media.width,
2806      });
2807    }
2808  }
2809}
2810
2811function rtmedia_reset_video_and_audio_for_popup() {
2812  jQuery(
2813    ".rtm-lightbox-container .rtmedia-comments-container ul.rtm-comment-list li.rtmedia-comment div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, .rtm-lightbox-container .rtmedia-comments-container ul.rtm-comment-list li.rtmedia-comment div.rtmedia-item-thumbnail > video.wp-video-shortcode"
2814  ).mediaelementplayer({
2815    // This is required to work with new MediaElement version.
2816    classPrefix: "mejs-",
2817    // If the <video width> is not specified, this is the default
2818    defaultVideoWidth: 200,
2819    // If the <video height> is not specified, this is the default
2820    defaultVideoHeight: 200,
2821  });
2822}
2823
2824function rtmedia_comment_media_uplaod_button_disble(widget_id, $value) {
2825  if (typeof $value != "undefined") {
2826    jQuery("#" + comment_media_add_button + widget_id).prop("disabled", $value);
2827  }
2828}
2829
2830function rtmedia_apply_popup_to_media() {
2831  if (
2832    typeof rtmedia_lightbox_enabled != "undefined" &&
2833    rtmedia_lightbox_enabled == "1"
2834  ) {
2835    apply_rtMagnificPopup(
2836      ".rtmedia-comment-media-container ul.rtmedia-comment-media-list, .rtmedia-list-media.rtm-gallery-list, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content, .rtm-bbp-container, ul.rtm-comment-container"
2837    );
2838  }
2839}
2840
2841function rtmedia_comment_media_enable_diable_media_comment(that) {
2842  var widget_id = jQuery(that).attr("widget_id");
2843  if (typeof widget_id != "undefined") {
2844    rtmedia_comment_media_uplaod_button_disble(widget_id, false);
2845  } else {
2846    jQuery(
2847      ".rt_media_comment_form_with_media .rtmedia-comment-media-upload"
2848    ).prop("disabled", false);
2849  }
2850}
2851
2852function rtmedia_add_comment_media_button_click(widget_id) {
2853  jQuery("." + rtmedia_comment_media_submit + widget_id).on(
2854    "click",
2855    function (e) {
2856      e.preventDefault();
2857      var media = jQuery(this).attr("media");
2858      if (typeof media != "undefined" && media == 1) {
2859        rtmedia_comment_media_input_button(widget_id, true);
2860
2861        rtmedia_comment_media_textbox_val(widget_id, true);
2862
2863        jQuery(this).attr("media", 0);
2864
2865        commentObj[widget_id].uploadFiles();
2866        return false;
2867      }
2868    }
2869  );
2870}
2871
2872/**
2873 * Enable/Disable submit comment button.
2874 *
2875 * @since 4.3.2
2876 * @param {boolean} value Disable or Enable button.
2877 */
2878function rtmedia_comment_submit_button_disable(value) {
2879  if ("boolean" === typeof value) {
2880    jQuery("#rt_media_comment_form #rt_media_comment_submit").prop(
2881      "disabled",
2882      value
2883    );
2884  }
2885}
2886
2887function rtmedia_comment_media_input_button(widget_id, $value) {
2888  rtmedia_comment_media_upload_button_post_disable(widget_id, $value);
2889
2890  rtmedia_comment_media_uplaod_button_disble(widget_id, $value);
2891
2892  rtmedia_uploaded_media_edit_disable(widget_id, $value);
2893}
2894
2895function rtmedia_uploaded_media_edit_disable(widget_id, $value) {
2896  if ($value) {
2897    jQuery("." + comment_media_wrapper + widget_id)
2898      .find(".plupload_filelist_content .dashicons")
2899      .hide();
2900    jQuery("." + comment_media_wrapper + widget_id)
2901      .find(".plupload_file_action")
2902      .hide();
2903  } else {
2904    jQuery("." + comment_media_wrapper + widget_id)
2905      .find(".plupload_file_action")
2906      .show();
2907    jQuery("." + comment_media_wrapper + widget_id)
2908      .find(".plupload_filelist_content .dashicons")
2909      .show();
2910  }
2911}
2912
2913function rtmedia_disable_comment_textbox(widget_id, value) {
2914  var form_class = "." + comment_media_wrapper + widget_id;
2915  if (jQuery(form_class).length > 0) {
2916    comment_string = jQuery(form_class).find("textarea").val();
2917    if (comment_string.includes("&nbsp;")) {
2918      jQuery(form_class).find("textarea.ac-input").val("");
2919    }
2920
2921    jQuery(form_class).find("textarea").prop("disabled", value);
2922    jQuery(form_class).find("textarea").css("color", "");
2923  }
2924}
2925
2926function rtmedia_comment_media_textbox_val(widget_id, $value) {
2927  var form_class = "." + comment_media_wrapper + widget_id;
2928  if (jQuery(form_class).length > 0) {
2929    if (jQuery(form_class).find("textarea.ac-input").length > 0) {
2930      if ($value == true) {
2931        var textarea = jQuery(form_class).find("textarea.ac-input").val();
2932        if (textarea == "") {
2933          jQuery(form_class).find("textarea.ac-input").val("&nbsp;");
2934          jQuery(form_class).find("textarea").css("color", "transparent");
2935        }
2936      } else {
2937        jQuery(form_class).find("textarea.ac-input").val("");
2938        jQuery(form_class).find("textarea").css("color", "");
2939      }
2940    }
2941  }
2942}
2943
2944function rtmedia_comment_media_upload_button_post_disable(widget_id, $value) {
2945  if (typeof $value != "undefined") {
2946    jQuery("." + rtmedia_comment_media_submit + widget_id).prop(
2947      "disabled",
2948      $value
2949    );
2950    if ($value == true) {
2951      jQuery("." + rtmedia_comment_media_submit + widget_id)
2952        .closest("div.ac-reply-content")
2953        .find("a.ac-reply-cancel")
2954        .attr("disabled", "disabled");
2955    } else {
2956      jQuery("." + rtmedia_comment_media_submit + widget_id)
2957        .closest("div.ac-reply-content")
2958        .find("a.ac-reply-cancel")
2959        .removeAttr("disabled");
2960    }
2961  }
2962}
2963
2964function rtmedia_comment_media_remove_hidden_media_id(widget_id) {
2965  jQuery("." + comment_media_wrapper + widget_id)
2966    .find('input[name="rtMedia_attached_files[]"]')
2967    .remove();
2968}
2969
2970function rtmedia_activity_comment_js_add_media_id() {
2971  jQuery.ajaxPrefilter(function (options, originalOptions, jqXHR) {
2972    // Modify options, control originalOptions, store jqXHR, etc
2973    try {
2974      if (
2975        originalOptions.data == null ||
2976        typeof originalOptions.data == "undefined" ||
2977        typeof originalOptions.data.action == "undefined"
2978      ) {
2979        return true;
2980      }
2981    } catch (e) {
2982      return true;
2983    }
2984
2985    if (originalOptions.data.action == "new_activity_comment") {
2986      widget_id = "activity-" + originalOptions.data.form_id;
2987
2988      var rtmedia_disable_media = 1;
2989      if (typeof rtmedia_disable_media_in_commented_media != "undefined") {
2990        rtmedia_disable_media = rtmedia_disable_media_in_commented_media;
2991      }
2992
2993      var temp = jQuery("." + comment_media_wrapper + widget_id)
2994        .find('input[name="rtMedia_attached_files[]"]')
2995        .val();
2996
2997      if (typeof temp == "undefined") {
2998        temp = 0;
2999      }
3000
3001      if (typeof temp == "") {
3002        temp = 0;
3003      }
3004      options.data += "&rtMedia_attached_files[]=" + temp;
3005      options.data +=
3006        "&rtmedia_disable_media_in_commented_media=" + rtmedia_disable_media;
3007
3008      activity_attachemnt_ids = temp;
3009
3010      var orignalSuccess = originalOptions.success;
3011
3012      options.beforeSend = function () {
3013        if (originalOptions.data.action == "new_activity_comment") {
3014          if (rtmedia_disable_media == 1) {
3015            if (
3016              originalOptions.data.form_id != originalOptions.data.comment_id &&
3017              temp > 0
3018            ) {
3019              jQuery("." + comment_media_wrapper + widget_id).append(
3020                '<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' +
3021                  rtmedia_disable_media_in_commented_media_text +
3022                  " </p></div>"
3023              );
3024              jQuery("." + comment_media_wrapper + widget_id).removeAttr(
3025                "disabled"
3026              );
3027
3028              rtmedia_comment_media_input_button(widget_id, false);
3029
3030              rtmedia_disable_comment_textbox(widget_id, false);
3031
3032              return false;
3033            }
3034          }
3035        }
3036      };
3037      options.success = function (response) {
3038        if (orignalSuccess && "function" === typeof orignalSuccess) {
3039          orignalSuccess(response);
3040        }
3041        if (response[0] + response[1] == "-1") {
3042          //Error
3043        } else {
3044          if (originalOptions.data.action == "new_activity_comment") {
3045            rtmedia_comment_media_remove_hidden_media_id(widget_id);
3046
3047            rtmedia_comment_media_textbox_val(widget_id, false);
3048
3049            rtmedia_comment_media_input_button(widget_id, false);
3050
3051            setTimeout(function () {
3052              rtmedia_apply_popup_to_media();
3053
3054              rtmedia_reset_video_and_audio();
3055            }, 500);
3056
3057            rtMediaHook.call("rtmedia_js_after_comment_added", []);
3058          }
3059        }
3060      };
3061      options.error = function () {
3062        if (originalOptions.data.action == "new_activity_comment") {
3063          rtmedia_comment_media_remove_hidden_media_id(widget_id);
3064
3065          rtmedia_comment_media_textbox_val(widget_id, false);
3066
3067          rtmedia_comment_media_input_button(widget_id, false);
3068        }
3069      };
3070    }
3071  });
3072}
3073
3074function rtmedia_buddypress_load_newest_button_click() {
3075  jQuery("body #buddypress").on(
3076    "click",
3077    "ul.activity-list li.load-newest a",
3078    function (e) {
3079      e.preventDefault();
3080      /* add the popup to the images */
3081      rtmedia_apply_popup_to_media();
3082      /* add the uplaod button to the new activity */
3083      rtmedia_activity_stream_comment_media();
3084    }
3085  );
3086}
3087
3088function rtmedia_comment_media_upload_button_class(widget_id) {
3089  jQuery("form." + comment_media_wrapper + widget_id)
3090    .find('input[type="submit"].rt_media_comment_submit')
3091    .addClass(rtmedia_comment_media_submit + widget_id);
3092  jQuery("form." + comment_media_wrapper + widget_id)
3093    .find('input[name="ac_form_submit"]')
3094    .addClass(rtmedia_comment_media_submit + widget_id);
3095  rtmedia_add_widget_id_in_submit_button(widget_id);
3096}
3097
3098function rtmedia_add_widget_id_in_submit_button(widget_id) {
3099  jQuery("." + rtmedia_comment_media_submit + widget_id).attr(
3100    "widget_id",
3101    widget_id
3102  );
3103}
3104
3105function rtmedia_comment_media_upload_button_has_media(widget_id, $value) {
3106  if (typeof $value != "undefined") {
3107    jQuery("." + rtmedia_comment_media_submit + widget_id).attr(
3108      "media",
3109      $value
3110    );
3111  }
3112}
3113
3114function rtmedia_comment_media_media_id(widget_id, media_id) {
3115  if (
3116    jQuery("." + comment_media_wrapper + widget_id).find(
3117      "#rtmedia_attached_id_" + media_id
3118    ).length < 1
3119  ) {
3120    rtmedia_comment_media_remove_hidden_media_id(widget_id);
3121
3122    jQuery("." + comment_media_wrapper + widget_id).append(
3123      "<input type='hidden' name='rtMedia_attached_files[]' data-mode='rtmedia-update' id='rtmedia_attached_id_" +
3124        media_id +
3125        "' value='" +
3126        media_id +
3127        "' />"
3128    );
3129  }
3130}
3131
3132function rtmedia_add_comment_media_button_trigger(widget_id) {
3133  if (jQuery("." + rtmedia_comment_media_submit + widget_id).length > 0) {
3134    jQuery("." + rtmedia_comment_media_submit + widget_id).trigger("click");
3135  }
3136}
3137
3138function renderUploadercomment_media(widget_id, parent_id_type) {
3139  var button = comment_media_add_button + widget_id;
3140
3141  //sidebar widget uploader config script
3142  if (
3143    jQuery("#" + button).length > 0 &&
3144    jQuery("#" + button)
3145      .closest("form")
3146      .find('input[type="file"]').length == 0
3147  ) {
3148    jQuery("#" + button)
3149      .closest("form")
3150      .addClass(comment_media_wrapper + widget_id);
3151
3152    rtmedia_comment_media_upload_button_class(widget_id);
3153
3154    if (typeof rtMedia_update_plupload_comment == "undefined") {
3155      return false;
3156    }
3157
3158    var plupload_comment = rtMedia_update_plupload_comment;
3159    plupload_comment.browse_button = button;
3160    plupload_comment.container =
3161      "rtmedia-comment-media-upload-container-" + widget_id;
3162
3163    plupload_comment_main[widget_id] = plupload_comment;
3164
3165    commentObj[widget_id] = new UploadView(
3166      eval(plupload_comment_main[widget_id])
3167    );
3168
3169    commentObj[widget_id].initUploader(false);
3170
3171    /*
3172     * Fix for file selector does not open in Safari browser in IOS.
3173     * In Safari in IOS, Plupload don't click on it's input(type=file), so file selector dialog won't open.
3174     * In order to fix this, when rtMedia's attach media button is clicked,
3175     * we check if Plupload's input(type=file) is clicked or not, if it's not clicked, then we click it manually
3176     * to open file selector.
3177     */
3178
3179    // Initially, select file dialog is close.
3180    var file_dialog_open = false;
3181
3182    // Plupload will click on this input when user click on rtMedia's attach media button.
3183    var input_file_el =
3184      "#" + plupload_comment.container + " input[type=file]:first";
3185
3186    // Bind callback on Plupload's input element.
3187    jQuery(document.body).on("click", input_file_el, function () {
3188      file_dialog_open = true;
3189    });
3190
3191    // Bind callback on rtMedia's attach media button.
3192    jQuery(document.body).on("click", "#" + button, function () {
3193      if (false === file_dialog_open) {
3194        jQuery(input_file_el).click();
3195        file_dialog_open = false;
3196      }
3197      jQuery(this).blur();
3198    });
3199
3200    var form_html = jQuery("." + comment_media_wrapper + widget_id);
3201    if (jQuery(form_html).find("div.rtmedia-plupload-container").length) {
3202      if (parent_id_type == "activity") {
3203        form_html
3204          .find(".ac-reply-content .ac-textarea")
3205          .after(
3206            form_html.find(
3207              "div.rtmedia-plupload-container .rtmedia-comment-media-upload"
3208            )
3209          );
3210      }
3211
3212      if (parent_id_type == "rtmedia") {
3213        form_html
3214          .find("textarea")
3215          .after(
3216            form_html.find(
3217              "div.rtmedia-plupload-container .rtmedia-comment-media-upload"
3218            )
3219          );
3220      }
3221    }
3222
3223    jQuery("#" + comment_media_uplaod_media + widget_id).hide();
3224
3225    jQuery("#" + comment_media_uplaod_media + widget_id).click(function (e) {
3226      //Enable 'post update' button when media get select
3227      rtmedia_comment_media_upload_button_post_disable(widget_id, true);
3228
3229      commentObj[widget_id].uploadFiles(e);
3230      commentObj[widget_id].uploader.refresh();
3231    });
3232
3233    rtmedia_add_comment_media_button_click(widget_id);
3234
3235    commentObj[widget_id].uploader.bind("FilesAdded", function (upl, rfiles) {
3236      /* doest not allow multipal uplaod in comment media */
3237      while (upl.files.length > 1) {
3238        upl.removeFile(upl.files[0]);
3239      }
3240      /* remove the last file that has being added to the comment media */
3241      commentObj[widget_id].upload_remove_array = [];
3242      jQuery(
3243        "#rtmedia_uploader_filelist-" + widget_id + " li.plupload_queue_li"
3244      ).remove();
3245
3246      rtmedia_comment_media_upload_button_has_media(widget_id, 1);
3247
3248      jQuery.each(rfiles, function (i, file) {
3249        //Set file title along with file
3250        rtm_file_name_array = file.name.split(".");
3251        file.title = rtm_file_name_array[0];
3252
3253        var hook_respo = rtMediaHook.call("rtmedia_js_file_added", [
3254          upl,
3255          file,
3256          "#rtmedia_uploader_filelist-" + widget_id,
3257        ]);
3258
3259        if (hook_respo == false) {
3260          file.status = -1;
3261          commentObj[widget_id].upload_remove_array.push(file.id);
3262          return true;
3263        }
3264
3265        if (commentObj[widget_id].uploader.settings.max_file_size < file.size) {
3266          return true;
3267        }
3268
3269        var tmp_array = file.name.split(".");
3270
3271        if (rtmedia_version_compare(rtm_wp_version, "3.9")) {
3272          // Plupload getting updated in 3.9
3273          var ext_array =
3274            commentObj[
3275              widget_id
3276            ].uploader.settings.filters.mime_types[0].extensions.split(",");
3277        } else {
3278          var ext_array =
3279            commentObj[widget_id].uploader.settings.filters[0].extensions.split(
3280              ","
3281            );
3282        }
3283        if (tmp_array.length > 1) {
3284          var ext = tmp_array[tmp_array.length - 1];
3285          ext = ext.toLowerCase();
3286          if (jQuery.inArray(ext, ext_array) === -1) {
3287            return true;
3288          }
3289        } else {
3290          return true;
3291        }
3292
3293        rtmedia_selected_file_list(plupload, file, "", "", widget_id);
3294
3295        //Delete Function
3296        jQuery(
3297          "#" +
3298            file.id +
3299            " .plupload_delete-" +
3300            widget_id +
3301            " .remove-from-queue"
3302        ).click(function (e) {
3303          e.preventDefault();
3304
3305          /* submit button with no media */
3306          jQuery("." + rtmedia_comment_media_submit + widget_id).attr(
3307            "media",
3308            "0"
3309          );
3310
3311          commentObj[widget_id].uploader.removeFile(upl.getFile(file.id));
3312          jQuery("#" + file.id).remove();
3313          return false;
3314        });
3315
3316        // To change the name of the uploading file
3317        jQuery("#label_" + file.id).click(function (e) {
3318          e.preventDefault();
3319
3320          rtm_file_label = this;
3321
3322          rtm_file_title_id = "text_" + file.id;
3323          rtm_file_title_input = "#" + rtm_file_title_id;
3324
3325          rtm_file_title_wrapper_id = "rtm_title_wp_" + file.id;
3326          rtm_file_title_wrapper = "#" + rtm_file_title_wrapper_id;
3327
3328          rtm_file_desc_id = "rtm_desc_" + file.id;
3329          rtm_file_desc_input = "#" + rtm_file_desc_id;
3330
3331          rtm_file_desc_wrapper_id = "rtm_desc_wp_" + file.id;
3332          rtm_file_desc_wrapper = "#" + rtm_file_desc_wrapper_id;
3333
3334          rtm_file_save_id = "save_" + file.id;
3335          rtm_file_save_el = "#" + rtm_file_save_id;
3336
3337          jQuery(rtm_file_label).hide();
3338          jQuery(rtm_file_label).siblings(".plupload_file_name_wrapper").hide();
3339
3340          // Show/create text box to edit media title
3341          if (jQuery(rtm_file_title_input).length === 0) {
3342            jQuery(rtm_file_label)
3343              .parent(".plupload_file_name")
3344              .prepend(
3345                '<div id="' +
3346                  rtm_file_title_wrapper_id +
3347                  '" class="rtm-upload-edit-title-wrapper"><label>' +
3348                  rtmedia_edit_media_info_upload.title +
3349                  '</label><input type="text" class="rtm-upload-edit-title" id="' +
3350                  rtm_file_title_id +
3351                  '" value="' +
3352                  file.title +
3353                  '" style="width: 75%;" /></div><div id="' +
3354                  rtm_file_desc_wrapper_id +
3355                  '" class="rtm-upload-edit-desc-wrapper"><label>' +
3356                  rtmedia_edit_media_info_upload.description +
3357                  '</label><textarea class="rtm-upload-edit-desc" id="' +
3358                  rtm_file_desc_id +
3359                  '"></textarea></div><span id="' +
3360                  rtm_file_save_id +
3361                  '" title="Save Change" class="dashicons dashicons-yes"></span>'
3362              );
3363          } else {
3364            jQuery(rtm_file_title_wrapper).show();
3365            jQuery(rtm_file_desc_wrapper).show();
3366            jQuery(rtm_file_save_el).show();
3367          }
3368
3369          jQuery(rtm_file_title_input).focus();
3370        });
3371
3372        rtm_file_save_id = "save_" + file.id;
3373        rtm_file_save_el = "#" + rtm_file_save_id;
3374        jQuery(document.body).on("click", rtm_file_save_el, function (e) {
3375          e.preventDefault();
3376          rtm_file_title_id = "text_" + file.id;
3377          rtm_file_title_input = "#" + rtm_file_title_id;
3378
3379          rtm_file_desc_id = "rtm_desc_" + file.id;
3380          rtm_file_desc_input = "#" + rtm_file_desc_id;
3381
3382          rtm_file_title_wrapper_id = "rtm_title_wp_" + file.id;
3383          rtm_file_title_wrapper = "#" + rtm_file_title_wrapper_id;
3384
3385          rtm_file_desc_wrapper_id = "rtm_desc_wp_" + file.id;
3386          rtm_file_desc_wrapper = "#" + rtm_file_desc_wrapper_id;
3387
3388          var file_title_val = jQuery(rtm_file_title_input).val();
3389          var file_desc_val = jQuery(rtm_file_desc_input).val();
3390
3391          rtm_file_label = "#label_" + file.id;
3392
3393          var file_name_wrapper_el = jQuery(rtm_file_label).siblings(
3394            ".plupload_file_name_wrapper"
3395          );
3396
3397          if ("" !== file_title_val.trim()) {
3398            var extension = file.name.split(".")[1];
3399            file_name_wrapper_el.text(file_title_val + "." + extension);
3400            file.title = file_title_val;
3401          }
3402
3403          if (file_desc_val != "") {
3404            file.description = file_desc_val;
3405          }
3406
3407          jQuery(rtm_file_title_wrapper).hide();
3408          jQuery(rtm_file_desc_wrapper).hide();
3409          file_name_wrapper_el.show();
3410          jQuery(rtm_file_label).siblings(".plupload_file_name_wrapper");
3411          jQuery(rtm_file_label).show();
3412          jQuery(this).hide();
3413        });
3414      });
3415
3416      jQuery.each(
3417        commentObj[widget_id].upload_remove_array,
3418        function (i, rfile) {
3419          if (upl.getFile(rfile)) {
3420            upl.removeFile(upl.getFile(rfile));
3421          }
3422        }
3423      );
3424
3425      rtMediaHook.call("rtmedia_js_after_files_added", [upl, rfiles]);
3426
3427      if (
3428        "undefined" != typeof rtmedia_direct_upload_enabled &&
3429        "1" == rtmedia_direct_upload_enabled
3430      ) {
3431        jQuery(".rtmedia-comment-media-submit-" + widget_id).focus();
3432        /* when direct upload is enable */
3433        jQuery("." + rtmedia_comment_media_submit + widget_id).trigger("click");
3434      }
3435
3436      /**
3437       * Uploader improper enter behavior issue(124) fixed
3438       */
3439      jQuery(".rtmedia-comment-media-submit-" + widget_id).focus();
3440      /**
3441       * End of issue 124
3442       */
3443    });
3444
3445    commentObj[widget_id].uploader.bind(
3446      "FileUploaded",
3447      function (up, file, res) {
3448        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
3449          //Test for MSIE x.x;
3450          var ieversion = new Number(RegExp.jQuery1); // Capture x.x portion and store as a number
3451
3452          if (ieversion < 10) {
3453            try {
3454              if (typeof JSON.parse(res.response) !== "undefined") {
3455                res.status = 200;
3456              }
3457            } catch (e) {}
3458          }
3459        }
3460
3461        if (res.status == 200) {
3462          try {
3463            var objIds = JSON.parse(res.response);
3464            jQuery.each(objIds, function (key, val) {
3465              /* after id of the images get */
3466              rtmedia_comment_media_upload_button_post_disable(
3467                widget_id,
3468                false
3469              );
3470              rtmedia_comment_media_media_id(widget_id, val);
3471              rtmedia_add_comment_media_button_trigger(widget_id);
3472            });
3473          } catch (e) {}
3474          rtMediaHook.call("rtmedia_js_after_file_upload", [
3475            up,
3476            file,
3477            res.response,
3478          ]);
3479        }
3480      }
3481    );
3482
3483    commentObj[widget_id].uploader.bind("Error", function (up, err) {
3484      rtmedia_comment_media_upload_button_post_disable(widget_id, false);
3485
3486      if (err.code == -600) {
3487        //File size error // if file size is greater than server's max allowed size
3488        var tmp_array;
3489        var ext = (tr = "");
3490        tmp_array = err.file.name.split(".");
3491        if (tmp_array.length > 1) {
3492          ext = tmp_array[tmp_array.length - 1];
3493          if (
3494            !(
3495              typeof up.settings.upload_size != "undefined" &&
3496              typeof up.settings.upload_size[ext] != "undefined" &&
3497              (up.settings.upload_size[ext]["size"] < 1 ||
3498                up.settings.upload_size[ext]["size"] * 1024 * 1024 >=
3499                  err.file.size)
3500            )
3501          ) {
3502            rtmedia_selected_file_list(plupload, err.file, up, err, widget_id);
3503          }
3504        }
3505      } else {
3506        if (err.code == -601) {
3507          // File extension error
3508          err.message = rtmedia_file_extension_error_msg;
3509        }
3510
3511        rtmedia_selected_file_list(plupload, err.file, "", err, widget_id);
3512      }
3513      jQuery(".plupload_delete-" + widget_id).on("click", function (e) {
3514        e.preventDefault();
3515
3516        /* submit button with no media */
3517        jQuery("." + rtmedia_comment_media_submit + widget_id).attr(
3518          "media",
3519          "0"
3520        );
3521
3522        jQuery(this).parent().parent("li").remove();
3523      });
3524
3525      return false;
3526    });
3527
3528    commentObj[widget_id].uploader.bind("BeforeUpload", function (up, files) {
3529      jQuery.each(
3530        commentObj[widget_id].upload_remove_array,
3531        function (i, rfile) {
3532          if (up.getFile(rfile)) {
3533            up.removeFile(up.getFile(rfile));
3534          }
3535        }
3536      );
3537
3538      item_id = 0;
3539      object = "profile";
3540
3541      up.settings.multipart_params.context = object;
3542      up.settings.multipart_params.comment_media_activity_id = widget_id;
3543      up.settings.multipart_params.context_id = item_id;
3544      up.settings.multipart_params.rtmedia_update = true;
3545      up.settings.multipart_params.activity_id = "null";
3546      up.settings.multipart_params.title = files.title.split(".")[0];
3547      if (typeof files.description != "undefined") {
3548        up.settings.multipart_params.description = files.description;
3549      } else {
3550        up.settings.multipart_params.description = "";
3551      }
3552    });
3553
3554    commentObj[widget_id].uploader.bind("UploadComplete", function (up, files) {
3555      jQuery("#rtmedia_uploader_filelist-" + widget_id + " li").remove();
3556
3557      window.onbeforeunload = null;
3558    });
3559
3560    commentObj[widget_id].uploader.bind("UploadProgress", function (up, file) {
3561      // creates a progress bar to display file upload status
3562      var progressBar = jQuery("<div/>", {
3563        class: "plupload_file_progress ui-widget-header",
3564      });
3565      progressBar.css("width", file.percent + "%");
3566      jQuery("#" + file.id + " .plupload_file_status").html(progressBar);
3567      // filter to customize existing progress bar can be used to display
3568      // '%' of upload completed.
3569      rtMediaHook.call("rtm_custom_progress_bar_content", [file]);
3570      jQuery("#" + file.id).addClass("upload-progress");
3571      if (file.percent == 100) {
3572        jQuery("#" + file.id).toggleClass("upload-success");
3573      }
3574
3575      window.onbeforeunload = function (evt) {
3576        var message = rtmedia_upload_progress_error_message;
3577        return message;
3578      };
3579    });
3580
3581    commentObj[widget_id].uploader.refresh(); //refresh the uploader for opera/IE fix on media page
3582  }
3583}
3584
3585function rtmedia_comment_media_upload(upload_comment) {
3586  if (typeof upload_comment != "undefined") {
3587    if (
3588      jQuery(upload_comment).find(".rt_upload_hf_upload_parent_id").length > 0
3589    ) {
3590      var parent_id = jQuery(upload_comment)
3591        .find(".rt_upload_hf_upload_parent_id")
3592        .val();
3593      var parent_id_type = jQuery(upload_comment)
3594        .find(".rt_upload_hf_upload_parent_id_type")
3595        .val();
3596      if (
3597        typeof parent_id != "undefined" &&
3598        typeof parent_id_type != "undefined"
3599      ) {
3600        // 1. Sanitize parent_id to allow digits only
3601        parent_id = String(parent_id).replace(/[^0-9]/g, "");
3602
3603        // 2. Sanitize parent_id_type to conservative character set (alphanumeric, _, -)
3604        parent_id_type = String(parent_id_type).replace(/[^A-Za-z0-9_\-]/g, "");
3605
3606        // 3. Abort if sanitization resulted in empty strings
3607        if (parent_id === "" || parent_id_type === "") {
3608            return;
3609        }
3610        var widget_id = parent_id_type + "-" + parent_id;
3611
3612        renderUploadercomment_media(widget_id, parent_id_type);
3613      }
3614    }
3615  }
3616}
3617
3618function rtmedia_activity_stream_comment_media() {
3619  // For Buddypress new template nouveau
3620  if (bp_template_pack && "legacy" !== bp_template_pack) {
3621    jQuery(
3622      "#buddypress div#activity-stream ul.activity-list li.activity-item, #buddypress ul#activity-stream ul.activity-list li.activity-item"
3623    ).each(function () {
3624      if (
3625        jQuery(this).find(".rt_upload_hf_upload_parent_id").length &&
3626        jQuery(this).find(".rt_upload_hf_upload_parent_id_type").length
3627      ) {
3628        if (jQuery(this).find("input[type=file]").length == 0) {
3629          // Please remove this in future when buddypress's nouveau tmeplate add some hook into comment form. Currently there is no hook into comment form so this is pretty hook.
3630          var container = jQuery(this).find(".rtmedia-uploader-div");
3631          jQuery(this).find(".ac-form").append(container.html());
3632          container.remove();
3633          rtmedia_comment_media_upload(this);
3634        }
3635      }
3636    });
3637  } else {
3638    jQuery("#buddypress ul#activity-stream li.activity-item").each(function () {
3639      if (
3640        jQuery(this).find(".rt_upload_hf_upload_parent_id").length &&
3641        jQuery(this).find(".rt_upload_hf_upload_parent_id_type").length
3642      ) {
3643        rtmedia_comment_media_upload(this);
3644      }
3645    });
3646  }
3647}
3648
3649function rtmedia_comment_media_single_page() {
3650  var single_upload_comment = jQuery(
3651    ".rtmedia-single-container .rtmedia-single-meta .rtmedia-item-comments form"
3652  );
3653  rtmedia_comment_media_upload(single_upload_comment);
3654}
3655
3656function rtmedia_disable_popup_navigation_comment_media_focus() {
3657  rtmedia_disable_popup_navigation(
3658    ".plupload_filelist_content li input.rtm-upload-edit-title"
3659  );
3660  rtmedia_disable_popup_navigation(
3661    ".plupload_filelist_content li textarea.rtm-upload-edit-desc"
3662  );
3663}
3664
3665function rtmedia_disable_popup_navigation($selector) {
3666  jQuery(document).on("focusin", $selector, function () {
3667    jQuery(document).off("keydown");
3668  });
3669
3670  jQuery(document).on("focusout", $selector, function () {
3671    var rtm_mfp = jQuery.magnificPopup.instance;
3672    jQuery(document).on("keydown", function (e) {
3673      if (e.keyCode === 37) {
3674        rtm_mfp.prev();
3675      } else if (e.keyCode === 39) {
3676        rtm_mfp.next();
3677      }
3678    });
3679  });
3680}
3681
3682/**
3683 * Function that smooth scrolls to the latest comment in rtMedia.
3684 *  Created on 23-Nov-2020 by Vipin Kumar Dinkar <[email protected]>
3685 */
3686const rtMediaScrollComments = () => {
3687  const commentBox = document.getElementById("rtmedia_comment_ul");
3688
3689  if (commentBox !== null) {
3690    const commentsToScroll = commentBox.offsetHeight * 1000;
3691    commentBox.scrollTo({ top: commentsToScroll, behavior: "smooth" });
3692  }
3693};
3694
3695/* Add max size limit message beside upload button */
3696const rtMediaMaxSizeMessage = () => {
3697  const buttonContainer = document.getElementById("rtmedia-action-update");
3698  if (buttonContainer) {
3699    const msg = document.createElement("span");
3700    msg.textContent =
3701      "Max. File Size: " + rtMedia_update_plupload_config.max_file_size;
3702    msg.style.fontSize = "12px";
3703    msg.style.opacity = "0.7";
3704    buttonContainer.appendChild(msg);
3705  }
3706};
3707
3708rtMediaMaxSizeMessage();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.