github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/pubnot/trumbowyg/plugins/insertaudio/trumbowyg.insertaudio.js (about)

     1  /*/* ===========================================================
     2   * trumbowyg.insertaudio.js v1.0
     3   * InsertAudio plugin for Trumbowyg
     4   * http://alex-d.github.com/Trumbowyg
     5   * ===========================================================
     6   * Author : Adam Hess (AdamHess)
     7   */
     8  
     9  (function ($) {
    10      'use strict';
    11  
    12      var insertAudioOptions = {
    13          src: {
    14              label: 'URL',
    15              required: true
    16          },
    17          autoplay: {
    18              label: 'AutoPlay',
    19              required: false,
    20              type: 'checkbox'
    21          },
    22          muted: {
    23              label: 'Muted',
    24              required: false,
    25              type: 'checkbox'
    26          },
    27          preload: {
    28              label: 'preload options',
    29              required: false
    30          }
    31      };
    32  
    33  
    34      $.extend(true, $.trumbowyg, {
    35          langs: {
    36              en: {
    37                  insertAudio: 'Insert Audio'
    38              },
    39              ru: {
    40                  insertAudio: 'Вставить аудио'
    41              },
    42              ja: {
    43                  insertAudio: '音声の挿入'
    44              }
    45          },
    46          plugins: {
    47              insertAudio: {
    48                  init: function (trumbowyg) {
    49                      var btnDef = {
    50                          fn: function () {
    51                              var insertAudioCallback = function (v) {
    52                                  // controls should always be show otherwise the audio will
    53                                  // be invisible defeating the point of a wysiwyg
    54                                  var html = '<audio controls';
    55                                  if (v.src) {
    56                                      html += ' src=\'' + v.src + '\'';
    57                                  }
    58                                  if (v.autoplay) {
    59                                      html += ' autoplay';
    60                                  }
    61                                  if (v.muted) {
    62                                      html += ' muted';
    63                                  }
    64                                  if (v.preload) {
    65                                      html += ' preload=\'' + v + '\'';
    66                                  }
    67                                  html += '></audio>';
    68                                  var node = $(html)[0];
    69                                  trumbowyg.range.deleteContents();
    70                                  trumbowyg.range.insertNode(node);
    71                                  return true;
    72                              };
    73  
    74                              trumbowyg.openModalInsert(trumbowyg.lang.insertAudio, insertAudioOptions, insertAudioCallback);
    75                          }
    76                      };
    77  
    78                      trumbowyg.addBtnDef('insertAudio', btnDef);
    79                  }
    80              }
    81          }
    82      });
    83  })(jQuery);