drowl_media-8.x-2.0-rc0/modules/drowl_media_video/dist/js/drowl_media.admin.video.js

modules/drowl_media_video/dist/js/drowl_media.admin.video.js
(function($, Drupal2) {
  Drupal2.behaviors.drowl_media_video = {
    elemFileUploadFieldSelector: "#edit-field-video-file-0-upload",
    elemFileUploadFieldFileWrapperSelector: "#edit-field-video-file-wrapper",
    elemVideoEmbedUrlFieldSelector: "#edit-field-video-0-value",
    attach: function(context, settings) {
      copyUploadedVideoUrlToVideoEmbed(context, settings);
    },
    /**
     * Copies the video URL in a media upload form into the video embed input field
     * after upload has finished.
     *
     * @param {object} context
     * @param {object} settings
     */
    copyUploadedVideoUrlToVideoEmbed: function(context, settings) {
      if ($(
        Drupal2.behaviors.drowl_media_video.elemFileUploadFieldFileWrapperSelector,
        context
      ).length == 1) {
        var videoUrl = Drupal2.behaviors.drowl_media_video.getUploadedVideoUrl(context);
        if (videoUrl) {
          videoUrl = Drupal2.behaviors.drowl_media_video.sanitizeVideoUrl(videoUrl);
          Drupal2.behaviors.drowl_media_video.setVideoEmbedUrl(videoUrl);
        }
      }
    },
    /**
     * Retrieves the video URL
     */
    getUploadedVideoUrl: function(context, settings) {
      var videoUrl = null;
      var $elemtLinkField = $(
        Drupal2.behaviors.drowl_media_video.elemFileUploadFieldFileWrapperSelector,
        context
      ).find(".file.file--video > a:first");
      if ($elemtLinkField.length === 1) {
        var href = $elemtLinkField.attr("href");
        if (href) {
          videoUrl = href;
        }
      }
      return videoUrl;
    },
    /**
     * Sanitizes the full video URL to make it relative.
     * @param {string} videoUrl
     */
    sanitizeVideoUrl: function(videoUrl) {
      videoUrl = videoUrl.replace(/^.*\/\/[^\/]+/, "");
      return videoUrl;
    },
    /**
     * Sets the given video URL in the video embed input field.
     * @param {string} videoUrl
     */
    setVideoEmbedUrl: function(videoUrl) {
      $(Drupal2.behaviors.drowl_media_video.elemVideoEmbedUrlFieldSelector).val(
        videoUrl
      );
    }
  };
})(jQuery, Drupal);

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc