summaryrefslogtreecommitdiff
path: root/plugins/message_highlight/message_highlight.js
blob: f6b0c58ec122ff940cff1ef8be4a5722c8466ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var mh_cur_row;

$(document).ready(function() {
  if(window.rcmail) {
	
    rcmail.addEventListener('plugin.mh_receive_row', mh_receive_row);
	
    rcmail.addEventListener('insertrow', function(evt) {
      var message = rcmail.env.messages[evt.row.uid];
  
      // check if our color info is present
      if(message.flags && message.flags.plugin_mh_color) {
        $(evt.row.obj).addClass('rcmfd_mh_row');
        evt.row.obj.style.color = message.flags.plugin_mh_color;
      }
    });  

  
    $('.mh_delete').live('click', function() {
      mh_delete(this);
    });

    $('.mh_add').live('click', function() {
      mh_add(this);
    });
  }
});


function mh_delete(button) {
  if(confirm(rcmail.get_label('message_highlight.deleteconfirm'))) {
    $(button).closest('tr', '#prefs-details').remove();
  }
}

// do an ajax call to get a new row
function mh_add(button) {
  mh_cur_row = $(button).closest('tr', '#prefs-details');
  lock = rcmail.set_busy(true, 'loading');
  rcmail.http_request('plugin.mh_add_row', '', lock);
}

// ajax return call
function mh_receive_row(data) {
  var row = data.row;
  $(mh_cur_row).after('<tr><td>'+row+'</td></tr>');
  //$('.mh_color_input:last').mColorPicker();
  
  $('input[data-mcolorpicker!="true"]').filter(function() {
    return ($.fn.mColorPicker.init.replace == '[type=color]')? this.getAttribute("type") == 'color': $(this).is($.fn.mColorPicker.init.replace);
  }).mColorPicker({
    imageFolder: 'plugins/message_highlight/colorpicker/images/',
    allowTransparency: false,
    showLogo: false,
    liveEvents: false,
    checkRedraw: 'ajaxSuccess'
  });
}