[ Index ]

MailPress 7.2

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

title

Body

[close]

/mp-admin/js/ -> write.js (source)

   1  // write
   2  
   3  var mp_write = {
   4  
   5      submit : {    stamp : null,
   6              button : null
   7      },
   8  
   9      init : function() {
  10          // close postboxes that should be closed
  11          jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
  12  
  13          // postboxes
  14          postboxes.add_postbox_toggles(MP_AdminPageL10n.screen);
  15  
  16          //uploader
  17          mp_fileupload.init();
  18  
  19          //autosave
  20          autosave.init();
  21  
  22          //mail formats
  23          var mf = jQuery('.mail-format-options a');
  24          mf.hover( function() { jQuery('.mail-format-tip').html( jQuery(this).prop('title') );}, function() {jQuery('.mail-format-tip').html( jQuery('.mail-format-options a.active').prop('title') );} );
  25          mf.click( function(e) {
  26              e.preventDefault();
  27              var of = jQuery('.mail-format-options a.active')
  28   
  29              var old_format = of.attr('data-mp-format');
  30              var new_format = jQuery(this).attr('data-mp-format');
  31              if (old_format == new_format) return false;
  32  
  33              of.removeClass('active');
  34              jQuery(this).addClass('active');
  35  
  36              jQuery('#mail_format').val(new_format);
  37  
  38              jQuery('.mail-formats-fields #mp-format-' + old_format).slideUp();
  39              jQuery('.mail-formats-fields #mp-format-' + new_format).slideDown();
  40          });
  41  
  42  
  43          if ( jQuery('#title').val() == '' )
  44              jQuery('#title').siblings('#title-prompt-text').css('visibility', '');
  45          jQuery('#title-prompt-text').click(function(){
  46              jQuery(this).css('visibility', 'hidden').siblings('#title').focus();
  47          });
  48          jQuery('#title').blur( function() {
  49              if (this.value == '') jQuery(this).siblings('#title-prompt-text').css('visibility', '');
  50              if ( (jQuery("#mail_id").val() > 0) || (jQuery("#title").val().length == 0) ) return; 
  51              autosave.main(); 
  52          }).focus(function(){
  53              jQuery(this).siblings('#title-prompt-text').css('visibility', 'hidden');
  54          }).keydown(function(e){
  55              jQuery(this).siblings('#title-prompt-text').css('visibility', 'hidden');
  56              jQuery(this).unbind(e);
  57          });
  58  
  59  
  60          //toemail
  61          if ( jQuery('#toemail').val() == '' )
  62              jQuery('#toemail').siblings('#toemail-prompt-text').css('visibility', '');
  63          jQuery('#toemail-prompt-text').click(function(){
  64              jQuery(this).css('visibility', 'hidden').siblings('#toemail').focus();
  65          });
  66          jQuery('#toemail').blur( function() {
  67              if (this.value == '') jQuery(this).siblings('#toemail-prompt-text').css('visibility', '');
  68          }).focus(function(){
  69              jQuery(this).siblings('#toemail-prompt-text').css('visibility', 'hidden');
  70          }).keydown(function(e){
  71              jQuery(this).siblings('#toemail-prompt-text').css('visibility', 'hidden');
  72              jQuery(this).unbind(e);
  73          });
  74  
  75          //toname
  76          if ( jQuery('#toname').val() == '' )
  77              jQuery('#toname').siblings('#toname-prompt-text').css('visibility', '');
  78          jQuery('#toname-prompt-text').click(function(){
  79              jQuery(this).css('visibility', 'hidden').siblings('#toname').focus();
  80          });
  81          jQuery('#toname').blur( function() {
  82              if (this.value == '') jQuery(this).siblings('#toname-prompt-text').css('visibility', '');
  83          }).focus(function(){
  84              jQuery(this).siblings('#toname-prompt-text').css('visibility', 'hidden');
  85          }).keydown(function(e){
  86              jQuery(this).siblings('#toname-prompt-text').css('visibility', 'hidden');
  87              jQuery(this).unbind(e);
  88          });
  89  
  90          jQuery('#to_list').change(function(){
  91  //            var v = (this.value == '') ? '' : 'none';
  92  //            jQuery('#toemail-toname').css('display', v);
  93              if (this.value == '') jQuery('#toemail-toname').slideDown("normal");
  94              else                  jQuery('#toemail-toname').slideUp("normal");
  95          });
  96  
  97  
  98          // submitdiv : save context
  99          mp_write.submit.stamp  = jQuery('#timestamp').html();
 100          mp_write.submit.button = jQuery('#publish').val();
 101          mp_write.submit.name   = jQuery('#publish').attr('name');
 102          mp_write.submit.save_post = jQuery('#save-post').hasClass('hidden');
 103  
 104          // from
 105          jQuery('#fromdiv').siblings('a.edit-from').click(function() {
 106              if (jQuery('#fromdiv').is(":hidden")) {
 107                  jQuery('#fromdiv').slideDown("normal");
 108                  jQuery(this).hide();
 109              }
 110              return false;
 111          });
 112          jQuery('.cancel-from', '#fromdiv').click(function() {
 113              document.writeform.fromemail.style.border='1px solid #C6D9E9';
 114              jQuery('#fromdiv').slideUp("normal");
 115              jQuery('#fromname').val(jQuery('#hidden_fromname').val());
 116              jQuery('#fromemail').val(jQuery('#hidden_fromemail').val());
 117              var val = "<b>" + jQuery('#hidden_fromname').val() + "</b> &lt;" + jQuery('#hidden_fromemail').val() + "&gt;";
 118              jQuery('#span_from').html(val);
 119              jQuery('#fromdiv').siblings('a.edit-from').show();
 120              return false;
 121          });
 122          jQuery('.save-from', '#fromdiv').click(function () {
 123              var fromname = jQuery('#fromname' ).val();
 124              var fromemail= jQuery('#fromemail').val();
 125  
 126              if (!mp_write.is_email(fromemail))
 127              {
 128                  document.writeform.fromemail.style.border='1px solid #f00';
 129                  alert(MP_AdminPageL10n.errmess);
 130                  return false;
 131              }
 132              document.writeform.fromemail.style.border='1px solid #C6D9E9';
 133  
 134              jQuery('#fromdiv').slideUp("normal");
 135              var val = "<b>" + fromname + "</b> &lt;" + fromemail + "&gt;";
 136              jQuery('#span_from').html(val);
 137              jQuery('#fromdiv').siblings('a.edit-from').show();
 138              return false;
 139          }); 
 140  
 141          // theme
 142          jQuery('#themediv').siblings('a.edit-theme').click(function() {
 143              if (jQuery('#themediv').is(":hidden")) {
 144                  jQuery('#themediv').slideDown("normal");
 145                  jQuery(this).hide();
 146              }
 147              return false;
 148          });
 149          jQuery('.cancel-theme', '#themediv').click(function() {
 150              jQuery('#themediv').slideUp("normal");
 151              jQuery('#theme').val(jQuery('#hidden_theme').val());
 152              var val = jQuery('#theme >option').filter(':selected').text();
 153              jQuery('#span_theme').html(val);
 154              jQuery('#themediv').siblings('a.edit-theme').show();
 155              return false;
 156          });
 157          jQuery('.save-theme', '#themediv').click(function () {
 158              jQuery('#themediv').slideUp("normal");
 159              var val = jQuery('#theme >option').filter(':selected').text();
 160              jQuery('#span_theme').html(val);
 161              jQuery('#themediv').siblings('a.edit-theme').show();
 162              return false;
 163          }); 
 164  
 165          // timestamp
 166          jQuery('#timestampdiv').siblings('a.edit-timestamp').click(function() {
 167              if (jQuery('#timestampdiv').is(":hidden")) {
 168                  jQuery('#timestampdiv').slideDown("normal");
 169                  jQuery(this).hide();
 170              }
 171              return false;
 172          });
 173          jQuery('.cancel-timestamp', '#timestampdiv').click(function() {
 174              jQuery('#timestampdiv').slideUp("normal");
 175              jQuery('#mm').val(jQuery('#hidden_mm').val());
 176              jQuery('#jj').val(jQuery('#hidden_jj').val());
 177              jQuery('#aa').val(jQuery('#hidden_aa').val());
 178              jQuery('#hh').val(jQuery('#hidden_hh').val());
 179              jQuery('#mn').val(jQuery('#hidden_mn').val());
 180              jQuery('#timestampdiv').siblings('a.edit-timestamp').show();
 181              mp_write.updateText();
 182              return false;
 183          });
 184          jQuery('.save-timestamp', '#timestampdiv').click(function () {
 185              if ( mp_write.updateText() ) {
 186                  jQuery('#timestampdiv').slideUp("normal");
 187                  jQuery('#timestampdiv').siblings('a.edit-timestamp').show();
 188              }
 189              return false;
 190          }); 
 191  
 192          // custom fields
 193          new mp_customfields();
 194  
 195          // control form
 196          jQuery('form#writeform').submit( function() {
 197              return mp_write.control();
 198          });
 199      },
 200  
 201      convertDateToString : function(iDate) {
 202          var oDate   = iDate.getFullYear() +'-';
 203          oDate  += ((1 + iDate.getMonth()) < 10) ? '0'+ (1 + iDate.getMonth()) +'-' : (1 + iDate.getMonth()) +'-';
 204          oDate  += (iDate.getDate() < 10)         ? '0'+ iDate.getDate()  +' '       : iDate.getDate() +' ';
 205          oDate  += (iDate.getHours()< 10)         ? '0'+ iDate.getHours() +':'       : iDate.getHours() +':';
 206          oDate  += (iDate.getMinutes()<10)        ? '0'+ iDate.getMinutes()          : iDate.getMinutes();
 207          return oDate;
 208      },
 209  
 210      updateText : function() {
 211  
 212          var aa = jQuery('#aa').val(),
 213              mm = jQuery('#mm').val(), 
 214              jj = jQuery('#jj').val(), 
 215              hh = jQuery('#hh').val(), 
 216              mn = jQuery('#mn').val();
 217          var attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
 218          var originalDate  = new Date( jQuery('#hidden_aa').val(), jQuery('#hidden_mm').val() -1, jQuery('#hidden_jj').val(), jQuery('#hidden_hh').val(), jQuery('#hidden_mn').val() );
 219          var currentDate   = new Date( jQuery('#cur_aa').val(), jQuery('#cur_mm').val() -1, jQuery('#cur_jj').val(), jQuery('#cur_hh').val(), jQuery('#cur_mn').val() );
 220  
 221  
 222      // attemptedDate is a date ?
 223          if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn )
 224          {
 225              jQuery('.timestamp-wrap', '#timestampdiv').addClass('form-invalid');
 226              return false;
 227          }
 228          else
 229          {
 230              jQuery('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid');
 231          }
 232  
 233          if ( attemptedDate == originalDate )
 234          {
 235              jQuery('#timestamp').html(mp_write.submit.stamp);
 236              jQuery('#publish').val(mp_write.submit.button);
 237              jQuery('#publish').attr('name', mp_write.submit.name);
 238              if (mp_write.submit.save_post) jQuery('#save-post').addClass('hidden');
 239              else                      jQuery('#save-post').removeClass('hidden');
 240  
 241              return true;
 242          } 
 243  
 244          if ( attemptedDate <= currentDate )
 245          {
 246              attemptedDate = currentDate;
 247  
 248              jQuery('#aa').val(jQuery('#cur_aa').val());
 249              jQuery('#mm').val(jQuery('#cur_mm').val()); 
 250              jQuery('#jj').val(jQuery('#cur_jj').val()); 
 251              jQuery('#hh').val(jQuery('#cur_hh').val()); 
 252              jQuery('#mn').val(jQuery('#cur_mn').val());
 253  
 254              jQuery('#timestamp').html(MP_AdminPageL10n.sendImmediately);
 255              jQuery('#publish').val(MP_AdminPageL10n.send);
 256              jQuery('#publish').attr('name', MP_AdminPageL10n.name_send);
 257              jQuery('#save-post').removeClass('hidden');
 258  
 259              return true;
 260          }
 261  
 262          jQuery('#timestamp').html(
 263              MP_AdminPageL10n.sendOnFuture + ' <b>' +
 264              jQuery('option[value=' + jQuery('#mm').val() + ']', '#mm').text() + ' ' +
 265              jj + ', ' +
 266              aa + ' @ ' +
 267              hh + ':' +
 268              mn + '</b> '
 269          );
 270          jQuery('#publish').val( MP_AdminPageL10n.schedule );
 271          jQuery('#publish').attr('name', MP_AdminPageL10n.name_send);
 272          jQuery('#save-post').addClass('hidden');
 273  
 274          return true;
 275      },
 276  
 277      control : function() {
 278          var err = 0;
 279  
 280          // fromemail
 281          var fromemail = jQuery('#fromdiv');
 282          if (fromemail)
 283          {
 284              document.writeform.fromemail.style.border='1px solid #C6D9E9';
 285  
 286              if (mp_write.is_empty(document.writeform.fromemail.value))
 287              {
 288                  document.writeform.fromemail.style.border='1px solid #f00';
 289                  err++;
 290              }
 291              else if (!mp_write.is_empty(document.writeform.fromemail.value))
 292              {
 293                  if (!mp_write.is_email(document.writeform.fromemail.value))
 294                  {
 295                      document.writeform.fromemail.style.border='1px solid #f00';
 296                      err++;
 297                  }
 298              }
 299  
 300              if (err == 0)
 301              {
 302                  jQuery('#fromdiv').slideUp("normal");
 303                  var val = "<b>" + document.writeform.fromname.value + "</b> &lt;" + document.writeform.fromemail.value + "&gt;";
 304                  jQuery('#span_from').html(val);
 305                  jQuery('#fromdiv').siblings('a.edit-from').show();
 306              }
 307              else if (fromemail.is(":hidden")) 
 308              {
 309                  fromemail.slideDown("normal");
 310                  fromemail.siblings('a.edit-from').hide();
 311              }
 312          }
 313  
 314          // email or list
 315          document.writeform.toemail.style.border='1px solid #C6D9E9';
 316          document.writeform.to_list.style.border='1px solid #C6D9E9';
 317  
 318          if (mp_write.is_empty(document.writeform.toemail.value) && (mp_write.is_empty(document.writeform.to_list.value)))
 319          {
 320              document.writeform.toemail.style.border='1px solid #f00';
 321              document.writeform.to_list.style.border='1px solid #f00';
 322              err++;
 323          }
 324          else if (!mp_write.is_empty(document.writeform.toemail.value))
 325          {
 326              if (!mp_write.is_email(document.writeform.toemail.value))
 327              {
 328                  document.writeform.toemail.style.border='1px solid #f00';
 329                  err++;
 330              }
 331          }
 332  
 333          if ( err == 0 )    return true;
 334  
 335          alert(MP_AdminPageL10n.errmess);
 336          return false;
 337      },
 338  
 339      is_empty : function(t) { return (t.length == 0); },
 340      is_email : function(m) { var _r; var data = { action: "mp_ajax", mp_action: "email", email: m }; jQuery.ajax({ data: data, type: "POST", async: false, url: ajaxurl, success: function(r) { _r = r;} }); return (_r==1); },
 341      is_numeric : function(n) { var pattern = /^[0-9]$/; return pattern.test(n); }
 342  }
 343  jQuery(document).ready( function() { mp_write.init(); });


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