BigW Consortium Gitlab

broadcast_message.js 966 Bytes
Newer Older
Phil Hughes committed
1 2
import _ from 'underscore';

3 4 5 6
export default function initBroadcastMessagesForm() {
  $('input#broadcast_message_color').on('input', function onMessageColorInput() {
    const previewColor = $(this).val();
    $('div.broadcast-message-preview').css('background-color', previewColor);
7
  });
8 9 10 11

  $('input#broadcast_message_font').on('input', function onMessageFontInput() {
    const previewColor = $(this).val();
    $('div.broadcast-message-preview').css('color', previewColor);
12
  });
13 14 15 16 17

  const previewPath = $('textarea#broadcast_message_message').data('preview-path');

  $('textarea#broadcast_message_message').on('input', _.debounce(function onMessageInput() {
    const message = $(this).val();
18
    if (message === '') {
19
      $('.js-broadcast-message-preview').text('Your message here');
20
    } else {
21
      $.ajax({
22
        url: previewPath,
23
        type: 'POST',
24
        data: {
25 26
          broadcast_message: { message },
        },
27 28
      });
    }
29 30
  }, 250));
}