[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/js/meta_boxes/post/ -> test.js (source)

   1  var mp_meta_box_post_test = {
   2  
   3      fields  : {'toemail' : 0, 'newsletter' : 0, 'theme' : 0},
   4      select  : {'toemail' : 0, 'newsletter' : 1, 'theme' : 1},
   5      css_err : {'border-color' : '#CC0000', 'background-color' :'#FFEBE8'},
   6      css     : {},
   7  
   8  // init
   9      init : function() {
  10          
  11          for (field in mp_meta_box_post_test.fields)
  12          {
  13              // edit
  14              jQuery('.mp-edit-'     + field).click(function(){ var a = jQuery(this); var fld = a.attr('href').substr(4); mp_meta_box_post_test.edit(fld); return false; });
  15              // cancel
  16              jQuery('.mp-cancel-'     + field).click(function(){ var a = jQuery(this); var fld = a.attr('href').substr(4); mp_meta_box_post_test.cancel(fld); return false; });
  17              // ok
  18              jQuery('.mp-save-'     + field).click(function(){ var a = jQuery(this); var fld = a.attr('href').substr(4); mp_meta_box_post_test.ok(fld, 'init'); return false; });
  19              // css
  20              mp_meta_box_post_test.css[field] = {};
  21              for (prop in mp_meta_box_post_test.css_err) mp_meta_box_post_test.css[field][prop] = jQuery('#mp_' + field).css(prop);
  22          }
  23  
  24          jQuery('.mp_meta_box_post_test').click( function(){
  25              //# check data
  26              for (field in mp_meta_box_post_test.fields) { mp_meta_box_post_test.ok(field, 'ajax'); if (mp_meta_box_post_test.ajax_enabled()) return; }
  27  
  28              //# collect data
  29              var data = {'action' : 'mp_ajax', 'mp_action' : 'mp_meta_box_post_test', 'post_id' : parseInt(jQuery('#post_ID').val())};
  30              for (field in mp_meta_box_post_test.fields) data[field] = jQuery('#mp_' + field).val();
  31  
  32              //# loading
  33              jQuery('div#MailPress_post_test_ajax').fadeTo(500,0);
  34               jQuery('div#MailPress_post_test_loading').fadeTo(500,1);
  35  
  36              //# ajax
  37              jQuery.ajax({
  38                  data: data,
  39                  beforeSend: null,
  40                  type: "POST",
  41                  url: ajaxurl,
  42                  success: mp_meta_box_post_test.callback_ajax
  43              });
  44          });
  45      },
  46  
  47  // for each item
  48      open  : function(field) { jQuery('#mp_div_' + field).slideDown("normal"); jQuery('.mp-edit-' + field).hide(); },
  49      close : function(field) { jQuery('#mp_div_' + field).slideUp("normal");   jQuery('.mp-edit-' + field).show(); },
  50  
  51  // for test button
  52      disable_ajax : function() { jQuery('.mp_meta_box_post_test').attr('disabled', 'disabled'); },
  53      enable_ajax  : function() { jQuery('.mp_meta_box_post_test').removeAttr('disabled'); },
  54      ajax_enabled : function() { return ('disabled' == jQuery('.mp_meta_box_post_test').attr('disabled')); },
  55  
  56  // for field check
  57      check_data : function(field, value) {
  58          switch(field)
  59          {
  60              case 'toemail' :
  61                  if (mp_meta_box_post_test.is_email(value)) break;
  62                  mp_meta_box_post_test.is_error('toemail');
  63                  return false;
  64              break;
  65          }
  66          mp_meta_box_post_test.is_ok(field);
  67          return true;
  68      },
  69  
  70      is_error : function(field) {
  71          // some css
  72          jQuery('#mp_' + field).css(mp_meta_box_post_test.css_err);
  73          mp_meta_box_post_test.fields[field]++;
  74          // disable Test button
  75          jQuery('.mp_meta_box_post_test').attr('disabled', 'disabled');
  76      },
  77  
  78      is_ok : function(field) {
  79          // restore css
  80          jQuery('#mp_' + field).css(mp_meta_box_post_test.css[field]);
  81          mp_meta_box_post_test.fields[field] = 0;
  82          // restore Test button
  83          for (fld in mp_meta_box_post_test.fields) if (mp_meta_box_post_test.fields[fld]) return;
  84          jQuery('.mp_meta_box_post_test').removeAttr('disabled');
  85      },
  86  
  87  //    is_email : function(m) { 
  88  //        var pattern = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/; 
  89  //        return pattern.test(m);
  90  //    },
  91      is_email : function(m) {
  92          var _r;
  93          var data = { action: "mp_ajax", mp_action: "email", email: m }; 
  94          jQuery.ajax({ 
  95              data: data, type: "POST", 
  96              async: false, 
  97              url: ajaxurl, 
  98              success: function(r) { _r = r;} 
  99          }); 
 100          return (_r==1); 
 101      },
 102  
 103  
 104  // for each field
 105      edit : function(field) { mp_meta_box_post_test.open(field); },
 106  
 107      cancel : function(field) {
 108          mp_meta_box_post_test.is_ok(field);
 109          jQuery('#mp_' + field).val(jQuery('#mp_hidden_' + field).val());
 110          if (mp_meta_box_post_test.select[field])
 111              jQuery('#span_' + field).html(jQuery('#mp_hidden_lib_' + field).val());
 112          else
 113              jQuery('#span_' + field).html(jQuery('#mp_hidden_' + field).val());
 114          mp_meta_box_post_test.close(field);
 115      },
 116  
 117      ok : function(field, status) {
 118          var val = jQuery('#mp_' + field).val();
 119  
 120          if (mp_meta_box_post_test.check_data(field, val))
 121          {
 122              if (('newsletter' == field) || ('theme' == field))
 123                  val = jQuery('#mp_'+field+' >option').filter(':selected').text();
 124  
 125              jQuery('#span_' + field).html(val);
 126              mp_meta_box_post_test.close(field);
 127              return true;
 128          }
 129  
 130          if ('ajax' == status) mp_meta_box_post_test.open(field);
 131  
 132          return false;
 133      },
 134  
 135  // back from ajax
 136      callback_ajax : function(response) {
 137          var message = '';
 138          var id = 0;
 139  
 140          var res = wpAjax.parseAjaxResponse(response, 'mp_meta_box_post_test');                     // parse the ajax response
 141          if ( res && res.responses && res.responses.length ) 
 142          {
 143              message = res.responses[0].data;
 144              id      = res.responses[0].id;
 145              if ( message ) { jQuery('#MailPress_post_test_ajax').html(message); }                 // display message
 146          }
 147  
 148           jQuery('div#MailPress_post_test_loading').fadeTo(500,0);
 149          jQuery('div#MailPress_post_test_ajax').fadeTo(500,1);
 150      }
 151  }
 152  jQuery(document).ready( function() { mp_meta_box_post_test.init() });


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1