[ Index ]

MailPress 7.2

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

title

Body

[close]

/mp-includes/js/ -> mp_refresh.js (source)

   1  var mp_refresh = {
   2      reg     : new RegExp("(%i%)", "g"),
   3      message : '',
   4  
   5      div : '<div id="mailpress-refresh-counter-wrap"></div>',
   6      button : '<button type="button" id="mailpress-refresh-link" class="button show-settings mp_refresh">%i%</button>',
   7      span : '<span id="mp_refresh_chrono">%i%</span>',
   8  
   9      init  : function() {
  10  
  11      // adding form in Screen Options 
  12          adminMpRefreshL10n.option = adminMpRefreshL10n.option.replace(/\&gt;/g,'>').replace(/\&lt;/g,'<');
  13          jQuery('#screen-options-wrap').append(adminMpRefreshL10n.option);
  14  
  15      // adding button
  16          jQuery('#screen-meta-links').append(mp_refresh.div);
  17          mp_refresh.message = mp_refresh.button.replace(mp_refresh.reg, adminMpRefreshL10n.message.replace(mp_refresh.reg, mp_refresh.span ));
  18          //mp_refresh.message = mp_refresh.button.replace(mp_refresh.reg, adminMpRefreshL10n.message.replace(mp_refresh.reg, "%i%"));
  19  
  20      // checked checkbox
  21          if (jQuery('#MP_Refresh').is(':checked')) mp_refresh.start();
  22      // onchange checkbox
  23          jQuery('#MP_Refresh').change( function() { (jQuery(this).is(':checked')) ? mp_refresh.start() : mp_refresh.stop(); } );
  24      // onclick message
  25          jQuery('div#mailpress-refresh-counter-wrap').click( function() { mp_refresh.stop(); } );
  26      },
  27  
  28      get_time : function() {
  29          var time = jQuery('input#MP_Refresh_every').val();
  30          time     = (isNaN(time)) ? adminMpRefreshL10n.every : time;
  31          time      = (adminMpRefreshL10n.every > time) ? adminMpRefreshL10n.every : time;
  32          jQuery('input#MP_Refresh_every').val(time);
  33          return time;
  34      },
  35  
  36      start : function() {
  37          var message = mp_refresh.message.replace(mp_refresh.reg, mp_refresh.get_time());
  38          mp_refresh.display(message);
  39  
  40          jQuery.schedule({    id    : 'mp_refresh.update',
  41                      time    : 1000, 
  42                      func    : mp_refresh.update,
  43                      repeat  : true, 
  44                      protect : true
  45          });
  46      },
  47  
  48      stop : function() {
  49          jQuery.cancel( 'mp_refresh.update' );
  50          jQuery('#MP_Refresh').attr('checked',false);
  51          mp_refresh.display('');
  52      },
  53  
  54      update : function() {
  55          var time = jQuery('span#mp_refresh_chrono').html();
  56          if (isNaN(time)) return;
  57          time--;
  58          if (time == 0)
  59          {
  60              mp_refresh.refresh();
  61              mp_refresh.stop();
  62          }
  63          if (time < 0) return;
  64          var message = mp_refresh.message.replace(mp_refresh.reg, time);
  65          mp_refresh.display(message);
  66      },
  67  
  68      display : function(message) {
  69          jQuery('div#mailpress-refresh-counter-wrap').html(message);
  70      },
  71  
  72      refresh : function() {
  73          var parms = {};
  74          var query = location.search.substring(1);
  75          var pairs = query.split('&');
  76          for(var i = 0; i < pairs.length; i++)
  77          {
  78              var pos = pairs[i].indexOf('=');
  79              if (pos == -1) continue;
  80              parms[pairs[i].substring(0,pos)] = unescape(pairs[i].substring(pos + 1));
  81          }
  82          parms['autorefresh'] = mp_refresh.get_time();
  83          
  84          var url = 'admin.php';
  85          for(a in parms)
  86          {
  87              var sep = (url == 'admin.php') ? '?' : '&';
  88              url += sep+a+'='+parms[a];
  89          }
  90          window.location = url;
  91      }
  92  };
  93  jQuery(document).ready( function(){ mp_refresh.init(); } );


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