PageSourceSearch

https://www.munturkey.com/wp-content/plugins/buddypress-media/app/assets/js/rtMedia.js

js munturkey.com collected 2026-10-02 00:19:10 UTC 55,466 bytes, 1,762 lines download raw bytes

1var rtMagnificPopup;
2var rtm_masonry_container;
3var comment_media = false;
4
5jQuery(document).ready(function () {
6  // Need to pass the object[key] as global variable.
7  if ("object" === typeof rtmedia_bp) {
8    for (var key in rtmedia_bp) {
9      window[key] = rtmedia_bp[key];
10    }
11  }
12
13  if ("object" === typeof rtmedia_main) {
14    for (var key in rtmedia_main) {
15      window[key] = rtmedia_main[key];
16    }
17  }
18
19  if ("object" === typeof rtmedia_upload_terms) {
20    for (var key in rtmedia_upload_terms) {
21      window[key] = rtmedia_upload_terms[key];
22    }
23  }
24
25  if ("object" === typeof rtmedia_magnific) {
26    for (var key in rtmedia_magnific) {
27      window[key] = rtmedia_magnific[key];
28    }
29  }
30});
31
32function apply_rtMagnificPopup(selector) {
33  jQuery("document").ready(function ($) {
34    var rt_load_more = "";
35    if (typeof rtmedia_load_more === "undefined") {
36      rt_load_more = "Loading media";
37    } else {
38      rt_load_more = rtmedia_load_more;
39    }
40    if (
41      typeof rtmedia_lightbox_enabled != "undefined" &&
42      rtmedia_lightbox_enabled == "1"
43    ) {
44      // If lightbox is enabled.
45
46      var old_gallery_media;
47      var current_page;
48      var more_media_loaded = false;
49
50      if (
51        $(".activity-item .rtmedia-activity-container .rtmedia-list-item > a")
52          .siblings("p")
53          .children("a").length > 0
54      ) {
55        $(".activity-item .rtmedia-activity-container .rtmedia-list-item > a")
56          .siblings("p")
57          .children("a")
58          .addClass("no-popup");
59      }
60
61      rtMagnificPopup = jQuery(selector).magnificPopup({
62        delegate:
63          "a:not(.no-popup, .mejs-time-slider, .mejs-volume-slider, .mejs-horizontal-volume-slider)",
64        type: "ajax",
65        fixedContentPos: true,
66        fixedBgPos: true,
67        tLoading: rt_load_more + " #%curr%...",
68        mainClass: "mfp-img-mobile",
69        preload: [1, 3],
70        closeOnBgClick: true,
71        gallery: {
72          enabled: true,
73          navigateByImgClick: true,
74          arrowMarkup: "", // Disabled default arrows
75          preload: [0, 1], // Will preload 0 - before current, and 1 after the current image
76        },
77        image: {
78          tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
79          titleSrc: function (item) {
80            return (
81              item.el.attr("title") + "<small>by Marsel Van Oosten</small>"
82            );
83          },
84        },
85        callbacks: {
86          ajaxContentAdded: function () {
87            mfp = jQuery.magnificPopup.instance;
88            if (jQuery(mfp.items).length === 1) {
89              jQuery(".mfp-arrow").remove();
90            }
91            // When last second media is encountered in lightbox, load more medias if available
92            var mfp = jQuery.magnificPopup.instance;
93            var current_media = mfp.currItem.el;
94            var li = current_media.parent();
95            if (!li.is("li")) {
96              li = li.parent();
97            }
98            if (
99              (li.is(":nth-last-child(2)") || li.is(":last-child")) &&
100              li.find("a").hasClass("rtmedia-list-item-a")
101            ) {
102              // If its last second media
103              var last_li = li.next();
104              if (jQuery("#rtMedia-galary-next").css("display") == "block") {
105                // If more medias are available
106
107                if (!more_media_loaded) {
108                  old_gallery_media = mfp.ev.children();
109                  more_media_loaded = true;
110                  current_page = nextpage;
111                }
112
113                jQuery("#rtMedia-galary-next").click(); // Load more
114              }
115            }
116
117            var items = mfp.items.length;
118            if (mfp.index == items - 1 && !li.is(":last-child")) {
119              current_media.click();
120              return;
121            }
122
123            var settings = {};
124
125            if (typeof _wpmejsSettings !== "undefined") {
126              settings.pluginPath = _wpmejsSettings.pluginPath;
127            }
128            var $single_meta_h = jQuery(
129              ".rtmedia-container .rtmedia-single-meta"
130            ).height();
131
132            var probablymobile = false;
133            // check if it's is an mobile or not
134            if (
135              typeof mfp != "undefined" &&
136              typeof mfp.probablyMobile != "undefined" &&
137              mfp.probablyMobile == true
138            ) {
139              probablymobile = true;
140            }
141            /* adding auto play button in the popup */
142            $(
143              ".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video"
144            ).attr("autoplay", true);
145
146            // if it's mobile then add mute button to it
147            if (probablymobile) {
148              $(
149                ".mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video"
150              ).attr("muted", false);
151            }
152
153            $(
154              ".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video"
155            ).mediaelementplayer({
156              // This is required to work with new MediaElement version.
157              classPrefix: "mejs-",
158              // If the <video width> is not specified, this is the default
159              defaultVideoWidth: 480,
160              // always show the volume button
161              hideVolumeOnTouchDevices: false,
162              features: [
163                "playpause",
164                "progress",
165                "current",
166                "volume",
167                "fullscreen",
168              ],
169              // If the <video height> is not specified, this is the default
170              defaultVideoHeight: 270,
171              // always show control for mobile
172              alwaysShowControls: probablymobile,
173              enableAutosize: true,
174              clickToPlayPause: true,
175              // if set, overrides <video height>
176              videoHeight: -1,
177              success: function (mediaElement, domObject) {
178                mediaElement.addEventListener(
179                  "loadeddata",
180                  function (e) {
181                    var $video_h = $(mediaElement).height();
182                    var $window_h = $(window).height();
183                    var $rtm_ltb = jQuery(
184                      "div.rtm-ltb-action-container"
185                    ).height();
186                    var $rtm_ltb = $rtm_ltb + 50;
187                    var $new_video_h = $single_meta_h - $rtm_ltb;
188                    if ($video_h > $window_h) {
189                      jQuery(
190                        ".rtmedia-container #rtmedia-single-media-container .mejs-container"
191                      ).attr(
192                        "style",
193                        "height:" +
194                          $new_video_h +
195                          "px !important; transition:0.2s"
196                      );
197                    }
198                  },
199                  false
200                );
201                // Call the play method
202
203                // check if it's mobile
204                if (
205                  probablymobile &&
206                  $(mediaElement).hasClass("wp-video-shortcode")
207                ) {
208                  jQuery("body").on(
209                    "touchstart",
210                    ".mejs-overlay-button",
211                    function (e) {
212                      mediaElement.paused
213                        ? mediaElement.play()
214                        : mediaElement.pause();
215                    }
216                  );
217                } else {
218                  // Changed to .pause() in PR 1082 to stop autoplay.
219                  mediaElement.pause();
220                }
221              },
222            });
223            $(".mfp-content .mejs-audio .mejs-controls").css(
224              "position",
225              "relative"
226            );
227            rtMediaHook.call("rtmedia_js_popup_after_content_added", []);
228
229            if (typeof bp != "undefined") {
230              if (
231                typeof bp.mentions != "undefined" &&
232                typeof bp.mentions.users != "undefined"
233              ) {
234                $("#atwho-container #atwho-ground-comment_content").remove();
235                $("#comment_content").bp_mentions(bp.mentions.users);
236              }
237            }
238
239            rtmedia_reset_video_and_audio_for_popup();
240
241            apply_rtMagnificPopup(
242              ".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"
243            );
244          },
245          open: function () {
246            var lightBoxBackgrundHeight = jQuery(".mfp-bg");
247            var lightBox = jQuery(".mfp-wrap");
248            lightBoxBackgrundHeight.height(
249              lightBoxBackgrundHeight.height() + lightBox.height()
250            );
251          },
252          close: function (e) {
253            //Console.log(e);
254
255            //If more media is loaded in lighbox then remove them set nextpage to default one.
256            if (more_media_loaded) {
257              mfp.ev.empty();
258              mfp.ev.append(old_gallery_media);
259
260              nextpage = current_page;
261              more_media_loaded = false;
262
263              if (nextpage > 1) {
264                jQuery("#rtMedia-galary-next").show();
265              }
266            }
267
268            rtmedia_single_page_popup_close();
269          },
270          BeforeChange: function (e) {
271            //Console.log(e);
272          },
273        },
274      });
275    }
276    /**
277     * string replace Save From ok
278     * By: Yahil
279     */
280    jQuery(document).ajaxComplete(function () {
281      jQuery("[id^=imgedit-leaving]").filter(function () {
282        var text = jQuery(this).text();
283        jQuery(this).text(text.replace("OK", "Save"));
284      });
285    });
286  });
287}
288var rtMediaHook = {
289  hooks: [],
290  is_break: false,
291  register: function (name, callback) {
292    if ("undefined" == typeof rtMediaHook.hooks[name]) {
293      rtMediaHook.hooks[name] = [];
294    }
295    rtMediaHook.hooks[name].push(callback);
296  },
297  call: function (name, arguments) {
298    if ("undefined" != typeof rtMediaHook.hooks[name]) {
299      for (i = 0; i < rtMediaHook.hooks[name].length; ++i) {
300        var result = rtMediaHook.hooks[name][i](arguments);
301        if (false === result || 0 === result) {
302          rtMediaHook.is_break = true;
303          return false;
304          break;
305        }
306      }
307    }
308    return true;
309  },
310};
311
312//Drop-down js
313function rtmedia_init_action_dropdown(parent) {
314  var all_ul;
315  var curr_ul;
316  jQuery(
317    parent + " .click-nav > span," + parent + " .click-nav > div"
318  ).toggleClass("no-js js");
319  jQuery(parent + " .click-nav .js ul").hide();
320  jQuery(parent + " .click-nav .clicker").click(function (e) {
321    all_ul = jQuery("#rtm-media-options .click-nav .clicker").next("ul");
322    curr_ul = jQuery(this).next("ul");
323    jQuery.each(all_ul, function (index, value) {
324      if (jQuery(value).html() != curr_ul.html()) {
325        // Check clicked option with other options
326        jQuery(value).hide();
327      }
328    });
329    jQuery(curr_ul).toggle();
330    e.stopPropagation();
331  });
332}
333
334jQuery("document").ready(function ($) {
335  // When Ajax completed attach media uploader to new activity, applay popup and attach media to comment uploader.
336  jQuery(document).ajaxComplete(function (event, xhr, settings) {
337    if ("legacy" !== bp_template_pack && bp_template_pack) {
338      var get_action = get_parameter("action", settings.data);
339      if (
340        ("activity_filter" === get_action ||
341          "post_update" === get_action ||
342          "get_single_activity_content" === get_action ||
343          "activity_get_older_updates" === get_action) &&
344        "undefined" !== typeof rtmedia_masonry_layout &&
345        rtm_is_true(rtmedia_masonry_layout) &&
346        "undefined" !== typeof rtmedia_masonry_layout_activity &&
347        rtm_is_true(rtmedia_masonry_layout_activity)
348      ) {
349        setTimeout(function () {
350          apply_rtMagnificPopup(
351            ".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"
352          );
353          rtmedia_activity_masonry();
354          rtmedia_activity_stream_comment_media();
355        }, 1000);
356      } else if (
357        "activity_filter" === get_action ||
358        "post_update" === get_action ||
359        "get_single_activity_content" === get_action ||
360        "activity_get_older_updates" === get_action
361      ) {
362        setTimeout(function () {
363          apply_rtMagnificPopup(
364            ".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"
365          );
366          rtmedia_activity_stream_comment_media();
367        }, 1000);
368      }
369    }
370  });
371
372  jQuery(".rtmedia-uploader-div").css({
373    opacity: "1",
374    display: "block",
375    visibility: "visible",
376  });
377
378  jQuery(" #whats-new-options ").css({
379    opacity: "1",
380  });
381
382  // Tabs
383  if (typeof $.fn.rtTab !== "undefined") {
384    $(".rtm-tabs").rtTab();
385  }
386
387  // Open magnific popup as modal for create album/playlist
388  if (jQuery(".rtmedia-modal-link").length > 0) {
389    $(".rtmedia-modal-link").magnificPopup({
390      type: "inline",
391      midClick: true, // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href
392      closeBtnInside: true,
393    });
394  }
395
396  $("#rt_media_comment_form").submit(function (e) {
397    if ($.trim($("#comment_content").val()) == "") {
398      if (jQuery("#rtmedia-single-media-container").length == 0) {
399        rtmedia_gallery_action_alert_message(
400          rtmedia_empty_comment_msg,
401          "warning"
402        );
403      } else {
404        rtmedia_single_media_alert_message(
405          rtmedia_empty_comment_msg,
406          "warning"
407        );
408      }
409      return false;
410    } else {
411      return true;
412    }
413  });
414
415  //Remove title from popup duplication
416  $("li.rtmedia-list-item p a").each(function (e) {
417    $(this).addClass("no-popup");
418  });
419
420  //Remove title from popup duplication
421  $("li.rtmedia-list-item p a").each(function (e) {
422    $(this).addClass("no-popup");
423  });
424  //Rtmedia_lightbox_enabled from setting
425  if (
426    typeof rtmedia_lightbox_enabled != "undefined" &&
427    rtmedia_lightbox_enabled == "1"
428  ) {
429    apply_rtMagnificPopup(
430      ".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"
431    );
432  }
433
434  jQuery.ajaxPrefilter(function (options, originalOptions, jqXHR) {
435    try {
436      if (
437        originalOptions.data == null ||
438        typeof originalOptions.data == "undefined" ||
439        typeof originalOptions.data.action == "undefined"
440      ) {
441        return true;
442      }
443    } catch (e) {
444      return true;
445    }
446
447    // Handle lightbox in BuddyPress activity loadmore
448    if (originalOptions.data.action == "activity_get_older_updates") {
449      var orignalSuccess = originalOptions.success;
450      options.success = function (response) {
451        if ("function" === typeof orignalSuccess) {
452          orignalSuccess(response);
453        }
454        apply_rtMagnificPopup(
455          ".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"
456        );
457        rtMediaHook.call("rtmedia_js_after_activity_added", []);
458      };
459    } else if (originalOptions.data.action == "get_single_activity_content") {
460      // Handle lightbox in BuddyPress single activity loadmore
461      var orignalSuccess = originalOptions.success;
462      options.success = function (response) {
463        if ("function" === typeof orignalSuccess) {
464          orignalSuccess(response);
465        }
466        setTimeout(function () {
467          apply_rtMagnificPopup(
468            ".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"
469          );
470          jQuery(
471            "ul.activity-list li.rtmedia_update:first-child .wp-audio-shortcode, ul.activity-list li.rtmedia_update:first-child .wp-video-shortcode"
472          ).mediaelementplayer({
473            // This is required to work with new MediaElement version.
474            classPrefix: "mejs-",
475            // If the <video width> is not specified, this is the default
476            defaultVideoWidth: 480,
477            // If the <video height> is not specified, this is the default
478            defaultVideoHeight: 270,
479          });
480        }, 900);
481      };
482    }
483  });
484
485  jQuery.ajaxPrefilter(function (options, originalOptions, jqXHR) {
486    try {
487      if (
488        originalOptions.data == null ||
489        typeof originalOptions.data == "undefined" ||
490        typeof originalOptions.data.action == "undefined"
491      ) {
492        return true;
493      }
494    } catch (e) {
495      return true;
496    }
497    if (originalOptions.data.action == "activity_get_older_updates") {
498      var orignalSuccess = originalOptions.success;
499      options.success = function (response) {
500        if ("function" === typeof orignalSuccess) {
501          orignalSuccess(response);
502        }
503        apply_rtMagnificPopup(
504          ".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"
505        );
506
507        jQuery(
508          "ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > video.wp-video-shortcode"
509        ).mediaelementplayer({
510          // This is required to work with new MediaElement version.
511          classPrefix: "mejs-",
512          // If the <video width> is not specified, this is the default
513          defaultVideoWidth: 480,
514          // If the <video height> is not specified, this is the default
515          defaultVideoHeight: 270,
516        });
517
518        setTimeout(function () {
519          rtmedia_activity_stream_comment_media();
520        }, 900);
521
522        rtMediaHook.call("rtmedia_js_after_activity_added", []);
523      };
524    }
525  });
526
527  jQuery(".rtmedia-container").on("click", ".select-all", function (e) {
528    jQuery(this).toggleClass("unselect-all").toggleClass("select-all");
529    jQuery(this).attr("title", rtmedia_unselect_all_visible);
530    jQuery(".rtmedia-list input").each(function () {
531      jQuery(this).prop("checked", true);
532    });
533    jQuery(".rtmedia-list-item").addClass("bulk-selected");
534  });
535
536  jQuery(".rtmedia-container").on("click", ".unselect-all", function (e) {
537    jQuery(this).toggleClass("select-all").toggleClass("unselect-all");
538    jQuery(this).attr("title", rtmedia_select_all_visible);
539    jQuery(".rtmedia-list input").each(function () {
540      jQuery(this).prop("checked", false);
541    });
542    jQuery(".rtmedia-list-item").removeClass("bulk-selected");
543  });
544
545  jQuery(".rtmedia-container").on("click", ".rtmedia-move", function (e) {
546    jQuery(".rtmedia-delete-container").slideUp();
547    jQuery(".rtmedia-move-container").slideToggle();
548  });
549
550  jQuery("#rtmedia-create-album-modal").on(
551    "click",
552    "#rtmedia_create_new_album",
553    function (e) {
554      $albumname = jQuery("<span/>")
555        .text(jQuery.trim(jQuery("#rtmedia_album_name").val()))
556        .html();
557      $album_description = jQuery("#rtmedia_album_description");
558      $context = jQuery.trim(jQuery("#rtmedia_album_context").val());
559      $context_id = jQuery.trim(jQuery("#rtmedia_album_context_id").val());
560      $privacy = jQuery.trim(jQuery("#rtmedia_select_album_privacy").val());
561      $create_album_nonce = jQuery.trim(
562        jQuery("#rtmedia_create_album_nonce").val()
563      );
564
565      if ($albumname != "") {
566        var data = {
567          action: "rtmedia_create_album",
568          name: $albumname,
569          description: $album_description.val(),
570          context: $context,
571          context_id: $context_id,
572          create_album_nonce: $create_album_nonce,
573        };
574
575        if ($privacy !== "") {
576          data["privacy"] = $privacy;
577        }
578
579        // Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
580        $("#rtmedia_create_new_album").attr("disabled", "disabled");
581        var old_val = $("#rtmedia_create_new_album").html();
582        $("#rtmedia_create_new_album").prepend(
583          "<img src='" + rMedia_loading_file + "' />"
584        );
585        jQuery.post(rtmedia_ajax_url, data, function (response) {
586          if (typeof response.album != "undefined") {
587            response = jQuery.trim(response.album);
588            var flag = true;
589            $album_description.val("");
590            $("#rtmedia_album_name").focus();
591
592            jQuery(".rtmedia-user-album-list").each(function () {
593              jQuery(this)
594                .children("optgroup")
595                .each(function () {
596                  if (jQuery(this).attr("value") === $context) {
597                    flag = false;
598
599                    jQuery(this).append(
600                      '<option value="' +
601                        response +
602                        '">' +
603                        $albumname +
604                        "</option>"
605                    );
606
607                    return;
608                  }
609                });
610
611              if (flag) {
612                var label =
613                  $context.charAt(0).toUpperCase() +
614                  $context.slice(1) +
615                  " " +
616                  rtmedia_main_js_strings.rtmedia_albums;
617
618                var opt_html =
619                  '<optgroup value="' +
620                  $context +
621                  '" label="' +
622                  label +
623                  '"><option value="' +
624                  response +
625                  '">' +
626                  $albumname +
627                  "</option></optgroup>";
628
629                jQuery(this).append(opt_html);
630              }
631            });
632
633            jQuery(
634              'select.rtmedia-user-album-list option[value="' + response + '"]'
635            ).prop("selected", true);
636            jQuery(".rtmedia-create-new-album-container").slideToggle();
637            jQuery("#rtmedia_album_name").val("");
638            jQuery("#rtmedia-create-album-modal").append(
639              "<div class='rtmedia-success rtmedia-create-album-alert'><b>" +
640                $albumname +
641                "</b>" +
642                rtmedia_album_created_msg +
643                "</div>"
644            );
645
646            setTimeout(function () {
647              jQuery(".rtmedia-create-album-alert").remove();
648            }, 4000);
649
650            setTimeout(function () {
651              galleryObj.reloadView();
652              window.location.reload();
653              jQuery(".close-reveal-modal").click();
654            }, 2000);
655          } else if (typeof response.error != "undefined") {
656            rtmedia_gallery_action_alert_message(response.error, "warning");
657          } else {
658            rtmedia_gallery_action_alert_message(
659              rtmedia_something_wrong_msg,
660              "warning"
661            );
662          }
663
664          $("#rtmedia_create_new_album").removeAttr("disabled");
665          $("#rtmedia_create_new_album").html(old_val);
666        });
667      } else {
668        rtmedia_gallery_action_alert_message(
669          rtmedia_empty_album_name_msg,
670          "warning"
671        );
672      }
673    }
674  );
675
676  jQuery(".rtmedia-container").on(
677    "click",
678    ".rtmedia-delete-selected",
679    function (e) {
680      if (jQuery(".rtmedia-list :checkbox:checked").length > 0) {
681        if (confirm(rtmedia_selected_media_delete_confirmation)) {
682          jQuery(this)
683            .closest("form")
684            .attr("action", "../../../" + rtmedia_media_slug + "/delete")
685            .submit();
686        }
687      } else {
688        rtmedia_gallery_action_alert_message(
689          rtmedia_no_media_selected,
690          "warning"
691        );
692      }
693    }
694  );
695
696  jQuery(".rtmedia-container").on(
697    "click",
698    ".rtmedia-move-selected",
699    function (e) {
700      if (jQuery(".rtmedia-list :checkbox:checked").length > 0) {
701        if (confirm(rtmedia_selected_media_move_confirmation)) {
702          jQuery(this).closest("form").attr("action", "").submit();
703        }
704      } else {
705        rtmedia_gallery_action_alert_message(
706          rtmedia_no_media_selected,
707          "warning"
708        );
709      }
710    }
711  );
712
713  jQuery("#buddypress").on("change", ".rtm-activity-privacy-opt", function () {
714    var activity_id = jQuery(this).attr("id");
715    activity_id = activity_id.split("-");
716    activity_id = activity_id[activity_id.length - 1];
717
718    var that = this;
719
720    data = {
721      activity_id: activity_id,
722      privacy: jQuery(this).val(),
723      nonce: jQuery("#rtmedia_activity_privacy_nonce").val(),
724      action: "rtm_change_activity_privacy",
725    };
726
727    jQuery.post(ajaxurl, data, function (res) {
728      var message = "";
729      var css_class = "";
730      if (res == "true") {
731        message = rtmedia_main_js_strings.privacy_update_success;
732        css_class = "rtmedia-success";
733      } else {
734        message = rtmedia_main_js_strings.privacy_update_error;
735        css_class = "fail";
736      }
737
738      jQuery(that).after(
739        '<p class="rtm-ac-privacy-updated ' +
740          css_class +
741          '">' +
742          message +
743          "</p>"
744      );
745      setTimeout(function () {
746        jQuery(that).siblings(".rtm-ac-privacy-updated").remove();
747      }, 2000);
748    });
749  });
750
751  jQuery(".media_search_input").on("keyup", function () {
752    rtm_search_media_text_validation();
753  });
754
755  function rtmedia_media_view_counts() {
756    //Var view_count_action = jQuery('#rtmedia-media-view-form').attr("action");
757    if (jQuery("#rtmedia-media-view-form").length > 0) {
758      var url = jQuery("#rtmedia-media-view-form").attr("action");
759      jQuery.post(url, {}, function (data) {});
760    }
761  }
762
763  rtmedia_media_view_counts();
764  rtMediaHook.register("rtmedia_js_popup_after_content_added", function () {
765    rtmedia_media_view_counts();
766    rtmedia_init_media_deleting();
767    mfp = jQuery.magnificPopup.instance;
768
769    if (jQuery(mfp.items).length > 1 && comment_media == false) {
770      rtmedia_init_popup_navigation();
771    } else {
772      rtmedia_disable_popup_navigation_all();
773    }
774
775    rtmedia_disable_popup_navigation_comment_focus();
776
777    rtmedia_disable_popup_navigation_comment_media_focus();
778
779    var height = $(window).height();
780    jQuery(".rtm-lightbox-container .mejs-video").css({
781      height: height * 0.8,
782      "over-flow": "hidden",
783    });
784    jQuery(".mfp-content .rtmedia-media").css({
785      "max-height": height * 0.87,
786      "over-flow": "hidden",
787    });
788    //Mejs-video
789    //init the options dropdown menu
790    rtmedia_init_action_dropdown(".rtm-lightbox-container .rtmedia-actions");
791    //Get focus on comment textarea when comment-link is clicked
792    jQuery(".rtmedia-comment-link").on("click", function (e) {
793      e.preventDefault();
794      jQuery("#comment_content").focus();
795    });
796
797    jQuery(".rtm-more").shorten({
798      // Shorten the media description to 100 characters
799      showChars: 130,
800    });
801
802    //Show gallery title in lightbox at bottom
803    var gal_title = $(".rtm-gallery-title"),
804      title = "";
805    if (!$.isEmptyObject(gal_title)) {
806      title = gal_title.html();
807    } else {
808      title = $("#subnav.item-list-tabs li.selected ").html();
809    }
810    if (title != "") {
811      $(".rtm-ltb-gallery-title .ltb-title").html(title);
812    }
813
814    //Show image counts
815    var counts = $("#subnav.item-list-tabs li.selected span").html();
816    $("li.total").html(counts);
817
818    return true;
819  });
820
821  function rtmedia_init_popup_navigation() {
822    var rtm_mfp = jQuery.magnificPopup.instance;
823
824    var probablyMobile = rtm_mfp.probablyMobile;
825    var tooltipShown = getCookie("rtmedia-touch-swipe-tooltip");
826
827    // Check if its mobile and tooltip is first time dispaly.
828    if (probablyMobile && "" === tooltipShown) {
829      // Show tooltip.
830      jQuery("#mobile-swipe-overlay").show();
831
832      // On touch hide tooltip.
833      jQuery("#mobile-swipe-overlay").on("click", function (e) {
834        setCookie("rtmedia-touch-swipe-tooltip", true, 365);
835        jQuery(this).hide();
836        jQuery(
837          "#rtmedia-single-media-container .mejs-playpause-button"
838        ).trigger("click");
839      });
840
841      // On swipe hide tooltip.
842      jQuery("#mobile-swipe-overlay").swipe({
843        //Generic swipe handler for all directions
844        swipe: function (
845          event,
846          direction,
847          distance,
848          duration,
849          fingerCount,
850          fingerData
851        ) {
852          setCookie("rtmedia-touch-swipe-tooltip", true, 365);
853          jQuery("#mobile-swipe-overlay").hide();
854          jQuery(
855            "#rtmedia-single-media-container .mejs-playpause-button"
856          ).trigger("click");
857        },
858        threshold: 0,
859      });
860    } else {
861      // play video or audio if user visited previously.
862      jQuery("#rtmedia-single-media-container .mejs-playpause-button").trigger(
863        "click"
864      );
865    }
866
867    jQuery(".mfp-arrow-right").on("click", function (e) {
868      rtm_mfp.next();
869    });
870    jQuery(".mfp-arrow-left").on("click", function (e) {
871      rtm_mfp.prev();
872    });
873
874    jQuery(".mfp-content .rtmedia-media").swipe({
875      //Generic swipe handler for all directions
876      swipeLeft: function (
877        event,
878        direction,
879        distance,
880        duration,
881        fingerCount // Bind leftswipe
882      ) {
883        rtm_mfp.next();
884      },
885      swipeRight: function (
886        event,
887        direction,
888        distance,
889        duration,
890        fingerCount // Bind rightswipe
891      ) {
892        rtm_mfp.prev();
893      },
894      threshold: 0,
895    });
896  }
897
898  /**
899   * Sets Cookie.
900   *
901   * @param {string} cname
902   * @param {string} cvalue
903   * @param {int} exdays
904   * @return void
905   */
906  function setCookie(cname, cvalue, exdays) {
907    var d = new Date();
908    d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
909    var expires = "expires=" + d.toUTCString();
910    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
911  }
912
913  /**
914   * Get Cookie.
915   *
916   * @param {string} cname
917   * @return {string}
918   */
919  function getCookie(cname) {
920    var name = cname + "=";
921    var ca = document.cookie.split(";");
922    for (var i = 0; i < ca.length; i++) {
923      var c = ca[i];
924      while (" " == c.charAt(0)) {
925        c = c.substring(1);
926      }
927      if (0 == c.indexOf(name)) {
928        return c.substring(name.length, c.length);
929      }
930    }
931
932    return "";
933  }
934
935  function rtmedia_disable_popup_navigation_all() {
936    // hide the left and right key
937    jQuery(".mfp-arrow-right").hide();
938    jQuery(".mfp-arrow-left").hide();
939
940    // disable the left and right keyboard button
941    jQuery(document).off("keydown");
942  }
943
944  function rtmedia_disable_popup_navigation_comment_focus() {
945    rtmedia_disable_popup_navigation("#comment_content");
946  }
947
948  var dragArea = jQuery("#drag-drop-area");
949  var activityArea = jQuery("#whats-new");
950  var content = dragArea.html();
951  jQuery("#rtmedia-upload-container").after(
952    "<div id='rtm-drop-files-title'>" + rtmedia_drop_media_msg + "</div>"
953  );
954  if (
955    typeof rtmedia_bp_enable_activity != "undefined" &&
956    rtmedia_bp_enable_activity == "1"
957  ) {
958    jQuery("#whats-new-textarea").append(
959      "<div id='rtm-drop-files-title'>" + rtmedia_drop_media_msg + "</div>"
960    );
961  }
962  jQuery(document)
963    .on("dragover", function (e) {
964      e.preventDefault();
965      /* check if media is dragging on same page */
966      if (e.target == this) {
967        return;
968      }
969      jQuery("#rtm-media-gallery-uploader").show();
970      if (
971        typeof rtmedia_bp_enable_activity != "undefined" &&
972        rtmedia_bp_enable_activity == "1"
973      ) {
974        activityArea.addClass("rtm-drag-drop-active");
975      }
976
977      dragArea.addClass("rtm-drag-drop-active");
978      jQuery("#rtm-drop-files-title").show();
979    })
980    .on("dragleave", function (e) {
981      e.preventDefault();
982      if (e.originalEvent.pageX != 0 && e.originalEvent.pageY != 0) {
983        return false;
984      }
985      if (
986        typeof rtmedia_bp_enable_activity != "undefined" &&
987        rtmedia_bp_enable_activity == "1"
988      ) {
989        activityArea.removeClass("rtm-drag-drop-active");
990        activityArea.removeAttr("style");
991      }
992      dragArea.removeClass("rtm-drag-drop-active");
993      jQuery("#rtm-drop-files-title").hide();
994    })
995    .on("drop", function (e) {
996      e.preventDefault();
997      /* Put cursor into activity box after dropping any media */
998      jQuery(".bp-suggestions").focus();
999      if (
1000        typeof rtmedia_bp_enable_activity != "undefined" &&
1001        rtmedia_bp_enable_activity == "1"
1002      ) {
1003        activityArea.removeClass("rtm-drag-drop-active");
1004        activityArea.removeAttr("style");
1005      }
1006      dragArea.removeClass("rtm-drag-drop-active");
1007      jQuery("#rtm-drop-files-title").hide();
1008    });
1009
1010  function rtmedia_init_media_deleting() {
1011    jQuery(".rtmedia-container").on(
1012      "click",
1013      ".rtmedia-delete-media",
1014      function (e) {
1015        e.preventDefault();
1016        if (confirm(rtmedia_media_delete_confirmation)) {
1017          jQuery(this).closest("form").submit();
1018        }
1019      }
1020    );
1021  }
1022
1023  jQuery(".rtmedia-container").on(
1024    "click",
1025    ".rtmedia-delete-album",
1026    function (e) {
1027      e.preventDefault();
1028      if (confirm(rtmedia_album_delete_confirmation)) {
1029        jQuery(this).closest("form").submit();
1030      }
1031    }
1032  );
1033
1034  jQuery(".rtmedia-container").on(
1035    "click",
1036    ".rtmedia-delete-media",
1037    function (e) {
1038      e.preventDefault();
1039      if (confirm(rtmedia_media_delete_confirmation)) {
1040        jQuery(this).closest("form").submit();
1041      }
1042    }
1043  );
1044
1045  rtmedia_init_action_dropdown("");
1046
1047  $(document).click(function () {
1048    if ($(".click-nav ul").is(":visible")) {
1049      $(".click-nav ul", this).hide();
1050    }
1051  });
1052
1053  //Get focus on comment textarea when comment-link is clicked
1054  jQuery(".rtmedia-comment-link").on("click", function (e) {
1055    e.preventDefault();
1056    jQuery("#comment_content").focus();
1057  });
1058
1059  if (jQuery(".rtm-more").length > 0) {
1060    $(".rtm-more").shorten({
1061      // Shorten the media description to 100 characters
1062      showChars: 200,
1063    });
1064  }
1065
1066  // Masonry code for activity
1067  if (
1068    typeof rtmedia_masonry_layout != "undefined" &&
1069    rtm_is_true(rtmedia_masonry_layout) &&
1070    typeof rtmedia_masonry_layout_activity != "undefined" &&
1071    rtm_is_true(rtmedia_masonry_layout_activity)
1072  ) {
1073    // Arrange media into masonry view
1074    rtmedia_activity_masonry();
1075  }
1076
1077  // Arrange media into masonry view right after upload or clicking on readmore link to activity without page load.
1078  jQuery(document).ajaxComplete(function (event, xhr, settings) {
1079    var get_action = get_parameter("action", settings.data);
1080
1081    if (
1082      ("post_update" === get_action ||
1083        "get_single_activity_content" === get_action ||
1084        "activity_get_older_updates" === get_action) &&
1085      typeof rtmedia_masonry_layout != "undefined" &&
1086      rtm_is_true(rtmedia_masonry_layout) &&
1087      typeof rtmedia_masonry_layout_activity != "undefined" &&
1088      rtm_is_true(rtmedia_masonry_layout_activity)
1089    ) {
1090      rtmedia_activity_masonry();
1091    }
1092  });
1093
1094  // Masonry code
1095  if (
1096    typeof rtmedia_masonry_layout != "undefined" &&
1097    rtm_is_true(rtmedia_masonry_layout) &&
1098    jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length == 0
1099  ) {
1100    rtm_masonry_container = jQuery(".rtmedia-container .rtmedia-list");
1101    rtm_masonry_container.masonry({
1102      itemSelector: ".rtmedia-list-item",
1103    });
1104    setInterval(function () {
1105      jQuery.each(
1106        jQuery(".rtmedia-list.masonry .rtmedia-item-title"),
1107        function (i, item) {
1108          jQuery(item).width(
1109            jQuery(item)
1110              .siblings(".rtmedia-item-thumbnail")
1111              .children("img")
1112              .width()
1113          );
1114        }
1115      );
1116      rtm_masonry_reload(rtm_masonry_container);
1117    }, 1000);
1118    jQuery.each(
1119      jQuery(".rtmedia-list.masonry .rtmedia-item-title"),
1120      function (i, item) {
1121        jQuery(item).width(
1122          jQuery(item)
1123            .siblings(".rtmedia-item-thumbnail")
1124            .children("img")
1125            .width()
1126        );
1127      }
1128    );
1129  }
1130
1131  if (jQuery(".rtm-uploader-tabs").length > 0) {
1132    jQuery(".rtm-uploader-tabs li").click(function (e) {
1133      if (!jQuery(this).hasClass("active")) {
1134        jQuery(this).siblings().removeClass("active");
1135        jQuery(this).parents(".rtm-uploader-tabs").siblings().hide();
1136        class_name = jQuery(this).attr("class");
1137        jQuery(this)
1138          .parents(".rtm-uploader-tabs")
1139          .siblings('[data-id="' + class_name + '"]')
1140          .show();
1141        jQuery(this).addClass("active");
1142
1143        if (class_name != "rtm-upload-tab") {
1144          jQuery("div.moxie-shim").hide();
1145        } else {
1146          jQuery("div.moxie-shim").show();
1147        }
1148      }
1149    });
1150  }
1151
1152  /**
1153   * Delete media from gallery page under the user's profile when user clicks the delete button on the gallery item.
1154   * Modified 11-Feb-2020 Adarsh Verma <[email protected]>
1155   */
1156  jQuery(".rtmedia-container").on("click", ".rtm-delete-media", function (e) {
1157    e.preventDefault();
1158    var confirmation = RTMedia_Main_JS.media_delete_confirmation;
1159
1160    if (confirm(confirmation)) {
1161      // If user confirms, send ajax request to delete the selected media
1162      var curr_li = jQuery(this).closest("li");
1163      var nonce = jQuery("#rtmedia_media_delete_nonce").val();
1164      var media_type = jQuery(this)
1165        .parents(".rtmedia-list-item")
1166        .data("media_type");
1167
1168      var data = {
1169        action: "delete_uploaded_media",
1170        nonce: nonce,
1171        media_id: curr_li.attr("id"),
1172        media_type: media_type,
1173      };
1174
1175      jQuery.ajax({
1176        url: RTMedia_Main_JS.rtmedia_ajaxurl,
1177        type: "POST",
1178        data: data,
1179        dataType: "JSON",
1180        success: function (response) {
1181          // Reload the current page
1182          window.location.reload();
1183
1184          if ("rtmedia-media-deleted" === response.data.code) {
1185            //Media delete
1186            rtmedia_gallery_action_alert_message(
1187              RTMedia_Main_JS.media_delete_success,
1188              "success"
1189            );
1190            curr_li.remove();
1191
1192            if (
1193              "undefined" !== typeof rtmedia_masonry_layout &&
1194              rtm_is_true(rtmedia_masonry_layout)
1195            ) {
1196              rtm_masonry_reload(rtm_masonry_container);
1197            }
1198
1199            // Update the media count in user profile & group's media tab.
1200            jQuery(
1201              "#user-media span, #media-groups-li #media span, #rtmedia-nav-item-all span"
1202            ).text(response.data.all_media_count);
1203
1204            // Update the count on sub navigations (Albums)
1205            // jQuery( '#rtmedia-nav-item-albums span' ).text( response.data.albums_count );
1206
1207            // Update the count on sub navigations (Photo, Video & Music)
1208            jQuery("#rtmedia-nav-item-photo span").text(
1209              response.data.photos_count
1210            );
1211            jQuery("#rtmedia-nav-item-music span").text(
1212              response.data.music_count
1213            );
1214            jQuery("#rtmedia-nav-item-video span").text(
1215              response.data.videos_count
1216            );
1217          } else {
1218            // Show alert message
1219            rtmedia_gallery_action_alert_message(
1220              response.data.message,
1221              "warning"
1222            );
1223          }
1224        },
1225      });
1226    }
1227  });
1228});
1229
1230//Legacy media element for old activities
1231function bp_media_create_element(id) {
1232  return false;
1233}
1234
1235/**
1236 * Check if a value is true (handles both string "true" and boolean true).
1237 *
1238 * @param {*} value The value to check.
1239 * @return {boolean} True if the value is "true" (string) or true (boolean).
1240 */
1241function rtm_is_true(value) {
1242  return "true" === value || true === value;
1243}
1244
1245function rtmedia_version_compare(left, right) {
1246  if (typeof left + typeof right != "stringstring") {
1247    return false;
1248  }
1249
1250  var a = left.split("."),
1251    b = right.split("."),
1252    i = 0,
1253    len = Math.max(a.length, b.length);
1254
1255  for (; i < len; i++) {
1256    if (
1257      (a[i] && !b[i] && parseInt(a[i]) > 0) ||
1258      parseInt(a[i]) > parseInt(b[i])
1259    ) {
1260      return true;
1261    } else if (
1262      (b[i] && !a[i] && parseInt(b[i]) > 0) ||
1263      parseInt(a[i]) < parseInt(b[i])
1264    ) {
1265      return false;
1266    }
1267  }
1268
1269  return true;
1270}
1271
1272function rtm_is_element_exist(el) {
1273  if (jQuery(el).length > 0) {
1274    return true;
1275  } else {
1276    return false;
1277  }
1278}
1279
1280function rtm_masonry_reload(el) {
1281  setTimeout(function () {
1282    // We make masonry recalculate the element based on their current state.
1283    // Check if masonry instance exists and use the appropriate method.
1284    var masonryInstance = el.data('masonry');
1285    if (masonryInstance) {
1286      // Masonry v4.x uses reloadItems() + layout() instead of reload()
1287      if (typeof masonryInstance.reload === 'function') {
1288        el.masonry("reload");
1289      } else if (typeof masonryInstance.reloadItems === 'function') {
1290        masonryInstance.reloadItems();
1291        masonryInstance.layout();
1292      }
1293    }
1294  }, 250);
1295}
1296
1297/*
1298 * To change this license header, choose License Headers in Project Properties.
1299 * To change this template file, choose Tools | Templates
1300 * and open the template in the editor.
1301 */
1302(function ($) {
1303  $.fn.shorten = function (settings) {
1304    "use strict";
1305
1306    var config = {
1307      showChars: 100,
1308      minHideChars: 10,
1309      ellipsesText: "...",
1310      moreText: rtmedia_read_more,
1311      lessText: rtmedia__show_less,
1312      onLess: function () {},
1313      onMore: function () {},
1314      errMsg: null,
1315      force: false,
1316    };
1317
1318    if (settings) {
1319      $.extend(config, settings);
1320    }
1321
1322    if ($(this).data("jquery.shorten") && !config.force) {
1323      return false;
1324    }
1325    $(this).data("jquery.shorten", true);
1326
1327    $(document).off("click", ".morelink");
1328
1329    $(document).on(
1330      {
1331        click: function () {
1332          var $this = $(this);
1333          if ($this.hasClass("less")) {
1334            $this.removeClass("less");
1335            $this.html(config.moreText);
1336            $this
1337              .parent()
1338              .prev()
1339              .hide(0, function () {
1340                $this.parent().prev().prev().show();
1341              })
1342              .hide(0, function () {
1343                config.onLess();
1344              });
1345          } else {
1346            $this.addClass("less");
1347            $this.html(config.lessText);
1348            $this
1349              .parent()
1350              .prev()
1351              .show(0, function () {
1352                $this.parent().prev().prev().hide();
1353              })
1354              .show(0, function () {
1355                config.onMore();
1356              });
1357          }
1358          return false;
1359        },
1360      },
1361      ".morelink"
1362    );
1363
1364    return this.each(function () {
1365      var $this = $(this);
1366
1367      var content = $this.html();
1368      var contentlen = $this.text().length;
1369      if (contentlen > config.showChars + config.minHideChars) {
1370        var c = content.substr(0, config.showChars);
1371        if (c.indexOf("<") >= 0) {
1372          // If there's HTML don't want to cut it
1373          var inTag = false; // I'm in a tag?
1374          var bag = ""; // Put the characters to be shown here
1375          var countChars = 0; // Current bag size
1376          var openTags = []; // Stack for opened tags, so I can close them later
1377          var tagName = null;
1378
1379          for (var i = 0, r = 0; r <= config.showChars; i++) {
1380            if (content[i] == "<" && !inTag) {
1381              inTag = true;
1382
1383              // This could be "tag" or "/tag"
1384              tagName = content.substring(i + 1, content.indexOf(">", i));
1385
1386              // If its a closing tag
1387              if (tagName[0] == "/") {
1388                if (tagName != "/" + openTags[0]) {
1389                  config.errMsg =
1390                    "ERROR en HTML: the top of the stack should be the tag that closes";
1391                } else {
1392                  openTags.shift(); // Pops the last tag from the open tag stack (the tag is closed in the retult HTML!)
1393                }
1394              } else {
1395                // There are some nasty tags that don't have a close tag like <br/>
1396                if (tagName.toLowerCase() != "br") {
1397                  openTags.unshift(tagName); // Add to start the name of the tag that opens
1398                }
1399              }
1400            }
1401            if (inTag && content[i] == ">") {
1402              inTag = false;
1403            }
1404
1405            if (inTag) {
1406              bag += content.charAt(i);
1407            } // Add tag name chars to the result
1408            else {
1409              r++;
1410              if (countChars <= config.showChars) {
1411                bag += content.charAt(i); // Fix to ie 7 not allowing you to reference string characters using the []
1412                countChars++;
1413              } // Now I have the characters needed
1414              else {
1415                if (openTags.length > 0) {
1416                  // I have unclosed tags
1417                  //Console.log('They were open tags');
1418                  //console.log(openTags);
1419                  for (j = 0; j < openTags.length; j++) {
1420                    //Console.log('Cierro tag ' + openTags[j]);
1421                    bag += "</" + openTags[j] + ">"; // Close all tags that were opened
1422
1423                    // You could shift the tag from the stack to check if you end with an empty stack, that means you have closed all open tags
1424                  }
1425                  break;
1426                }
1427              }
1428            }
1429          }
1430          c = $("<div/>")
1431            .html(
1432              bag + '<span class="ellip">' + config.ellipsesText + "</span>"
1433            )
1434            .html();
1435        } else {
1436          c += config.ellipsesText;
1437        }
1438
1439        var html =
1440          '<div class="shortcontent">' +
1441          c +
1442          '</div><div class="allcontent">' +
1443          content +
1444          '</div><span><a href="javascript://nop/" class="morelink">' +
1445          config.moreText +
1446          "</a></span>";
1447
1448        $this.html(html);
1449        $this.find(".allcontent").hide(); // Hide all text
1450        $(".shortcontent p:last", $this).css("margin-bottom", 0); //Remove bottom margin on last paragraph as it's likely shortened
1451      }
1452    });
1453  };
1454})(jQuery);
1455
1456window.onload = function () {
1457  if (
1458    "undefined" != typeof rtmedia_masonry_layout &&
1459    "true" == rtmedia_masonry_layout &&
1460    0 == jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length
1461  ) {
1462    rtm_masonry_reload(rtm_masonry_container);
1463  }
1464
1465  rtm_search_media_text_validation();
1466
1467  if (check_condition("search")) {
1468    jQuery("#media_search_remove").show();
1469  }
1470};
1471
1472/**
1473 * Update style as per search testbox value
1474 * issue: https://github.com/rtMediaWP/rtMedia/issues/834
1475 */
1476function rtm_search_media_text_validation() {
1477  if ("" === jQuery("#media_search_input").val()) {
1478    jQuery("#media_search").css("cursor", "not-allowed");
1479  } else {
1480    jQuery("#media_search").css("cursor", "pointer");
1481  }
1482}
1483
1484// Get query string parameters from url
1485function rtmediaGetParameterByName(name) {
1486  name = name.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]");
1487  var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
1488    results = regex.exec(location.search);
1489  return results == null
1490    ? ""
1491    : decodeURIComponent(results[1].replace(/\+/g, " "));
1492}
1493
1494function rtmedia_single_media_alert_message(msg, action, is_comment) {
1495  var action_class = "rtmedia-success";
1496
1497  if ("warning" == action) {
1498    action_class = "rtmedia-warning";
1499  }
1500
1501  /**
1502   * Remove existing task specific message containers
1503   */
1504  var exists = false;
1505  var msg_containers = jQuery(".rtmedia-message-container");
1506  msg_containers.each(function (i, container) {
1507    /**
1508     * Convert DOM to jQuery element.
1509     */
1510    container = jQuery(container);
1511    /**
1512     * If is comment error and has dedicated error class, then only remove
1513     */
1514    if (is_comment && container.hasClass("rtmedia-empty-comment-error-class")) {
1515      container.remove();
1516      exists = true;
1517      return false;
1518    }
1519    /**
1520     * If is not comment error and container doesn't have dedicated error class, then only remove
1521     */
1522    if (
1523      is_comment === undefined &&
1524      !container.hasClass("rtmedia-empty-comment-error-class")
1525    ) {
1526      container.remove();
1527      exists = true;
1528      return false;
1529    }
1530  });
1531  /**
1532   * Construct message container
1533   */
1534  var $div = jQuery("<div>", {
1535    title: "Click to dismiss",
1536    class:
1537      "rtmedia-message-container" +
1538      (is_comment ? " rtmedia-empty-comment-error-class" : ""),
1539    style: "margin:1em 0;",
1540  });
1541  var $span = jQuery("<span>", {
1542    class: action_class,
1543  });
1544  /**
1545   * Append constructed html
1546   */
1547  $span.html(msg);
1548  $span.appendTo($div);
1549
1550  var container;
1551  if (is_comment) {
1552    /**
1553     * container should be comment form
1554     */
1555    container = jQuery("#rt_media_comment_form");
1556    jQuery("#comment_content").focus();
1557  } else if (is_comment === undefined) {
1558    /**
1559     * container should be main rtmedia container
1560     */
1561    container = jQuery(".rtmedia-single-media .rtmedia-media");
1562    container.css("opacity", "0.2");
1563  }
1564  /**
1565   * Append final element
1566   */
1567  container.after($div);
1568  if (exists) {
1569    /**
1570     * Add border if message already exists
1571     */
1572    $span.css({ border: "2px solid #884646" });
1573    setTimeout(function () {
1574      $span.css({ border: "none" });
1575    }, 500);
1576  }
1577  /**
1578   * Remove element after 3 seconds
1579   */
1580  setTimeout(function () {
1581    $div.remove();
1582    if (is_comment === undefined) {
1583      container.css("opacity", "1");
1584    }
1585  }, 3000);
1586  /**
1587   * Remove element on click
1588   */
1589  $div.click(function () {
1590    $div.remove();
1591    if (is_comment === undefined) {
1592      container.css("opacity", "1");
1593    }
1594  });
1595}
1596
1597function rtmedia_gallery_action_alert_message(msg, action) {
1598  var action_class = "rtmedia-success";
1599
1600  if ("warning" == action) {
1601    action_class = "rtmedia-warning";
1602  }
1603  var container = '<div class="rtmedia-gallery-alert-container"> </div>';
1604  jQuery("body").append(container);
1605  jQuery(".rtmedia-gallery-alert-container").append(
1606    "<div class='rtmedia-gallery-message-box'><span class='" +
1607      action_class +
1608      "'>" +
1609      msg +
1610      " </span></div>"
1611  );
1612
1613  setTimeout(function () {
1614    jQuery(".rtmedia-gallery-alert-container").remove();
1615  }, 3000);
1616
1617  jQuery(".rtmedia-gallery-message-box").click(function () {
1618    jQuery(".rtmedia-gallery-alert-container").remove();
1619  });
1620}
1621
1622// Set masonry view for activity
1623function rtmedia_activity_masonry() {
1624  jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list").masonry({
1625    itemSelector: ".rtmedia-list-item",
1626    gutter: 7,
1627  });
1628  var timesRun = 0;
1629  var interval = setInterval(function () {
1630    timesRun += 1;
1631    // Run this for 5 times only.
1632    if (timesRun === 5) {
1633      clearInterval(interval);
1634    }
1635    jQuery.each(
1636      jQuery(
1637        ".rtmedia-activity-container .rtmedia-list.masonry .rtmedia-item-title"
1638      ),
1639      function (i, item) {
1640        jQuery(item).width(
1641          jQuery(item)
1642            .siblings(".rtmedia-item-thumbnail")
1643            .children("img")
1644            .width()
1645        );
1646      }
1647    );
1648    // Reload masonry view.
1649    rtm_masonry_reload(
1650      jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list")
1651    );
1652  }, 1000);
1653}
1654
1655/**
1656 * Get specific parameter value from Query string.
1657 * @param string parameter Parameter of query string.
1658 * @param object data Set of data.
1659 * @return bool
1660 */
1661function get_parameter(parameter, data) {
1662  if (!parameter) {
1663    return false;
1664  }
1665
1666  if (!data) {
1667    data = window.location.href;
1668  }
1669
1670  var parameter = parameter.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]");
1671  var expr = parameter + "=([^&#]*)";
1672  var regex = new RegExp(expr);
1673  var results = regex.exec(data);
1674
1675  if (null !== results) {
1676    return results[1];
1677  } else {
1678    return false;
1679  }
1680}
1681
1682/**
1683 * Prevent user to upload media without checking upload terms checkbox.
1684 */
1685function rtm_upload_terms_activity() {
1686  // Check if upload term checkbox is there.
1687  if (jQuery("#rtmedia_upload_terms_conditions").length > 0) {
1688    // Handle error on click event.
1689    jQuery("#bp-nouveau-activity-form").on(
1690      "click",
1691      "#aw-whats-new-submit",
1692      function (event) {
1693        var form = jQuery("#whats-new-form");
1694        var condition_checkbox = form.find("#rtmedia_upload_terms_conditions");
1695        if (
1696          0 !== condition_checkbox.length &&
1697          false === condition_checkbox.prop("checked") &&
1698          form.find("#message").length === 0
1699        ) {
1700          event.preventDefault();
1701          var selector = form.find(".rtmedia-upload-terms");
1702          rtp_display_terms_warning(
1703            selector,
1704            rtmedia_upload_terms_check_terms_message
1705          );
1706        }
1707      }
1708    );
1709
1710    var bp_legacy_form = jQuery("#whats-new-form");
1711
1712    // Re-enable hidden inputs disabled in the activity post form.
1713    if (bp_legacy_form.length > 0) {
1714      // Add upload terms element selector to work when direct upload is enabled.
1715      jQuery("#whats-new-form, #rtmedia_upload_terms_conditions").on(
1716        "click",
1717        function (event) {
1718          var hidden_fields = bp_legacy_form.find("input:hidden");
1719          hidden_fields.each(function () {
1720            jQuery(this).prop("disabled", false);
1721          });
1722        }
1723      );
1724    }
1725  }
1726}
1727
1728jQuery(document).ready(function () {
1729  // Call function when document loaded.
1730  rtm_upload_terms_activity();
1731
1732  // Avoid Lightbox conflict due to class has-sidebar in theme 2017 v2.1.
1733  if (
1734    jQuery("body").hasClass("has-sidebar") &&
1735    0 === jQuery("#secondary").length
1736  ) {
1737    if (
1738      jQuery(".rtmedia-single-container").length ||
1739      jQuery(".rtmedia-container").length
1740    ) {
1741      jQuery("body").removeClass("has-sidebar");
1742    }
1743  }
1744
1745  // remove download option from video.
1746  if (rtmedia_main) {
1747    if (
1748      "undefined" === rtmedia_main.rtmedia_direct_download_link ||
1749      !parseInt(rtmedia_main.rtmedia_direct_download_link)
1750    ) {
1751      jQuery(document).on("bp_ajax_request", function (event) {
1752        setTimeout(function () {
1753          jQuery("video").each(function () {
1754            jQuery(this).attr("controlsList", "nodownload");
1755            jQuery(this).attr("playsinline", "playsinline");
1756            jQuery(this).load();
1757          });
1758        }, 200);
1759      });
1760    }
1761  }
1762});

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.