github.com/bosssauce/ponzu@v0.11.1-0.20200102001432-9bc41b703131/system/admin/static/common/js/util.js (about)

     1  // Replaces commonly-used Windows 1252 encoded chars that do not exist in ASCII or ISO-8859-1 with ISO-8859-1 cognates.
     2  // modified from http://www.andornot.com/blog/post/Replace-MS-Word-special-characters-in-javascript-and-C.aspx
     3  function replaceBadChars(text) {
     4      var s = text;
     5      // smart single quotes and apostrophe
     6      s = s.replace(/[\u2018\u2019\u201A]/g, "\'");
     7      // smart double quotes
     8      s = s.replace(/[\u201C\u201D\u201E]/g, "\"");
     9      // ellipsis
    10      s = s.replace(/\u2026/g, "...");
    11      // circumflex
    12      s = s.replace(/\u02C6/g, "^");
    13      // open angle bracket
    14      s = s.replace(/\u2039/g, "<");
    15      // close angle bracket
    16      s = s.replace(/\u203A/g, ">");
    17      // spaces
    18      s = s.replace(/[\u02DC\u00A0]/g, " ");
    19      
    20      return s;
    21  }
    22  
    23  
    24  // Returns a local partial time object based on unix timestamp
    25  function getPartialTime(unix) {
    26      var date = new Date(unix);
    27      var t = {};
    28      var hours = date.getHours();
    29      if (hours < 10) {
    30          hours = "0" + String(hours);
    31      }
    32  
    33      t.hh = hours;
    34      if (hours > 12) {
    35          t.hh = hours - 12;
    36          t.pd = "PM";
    37      } else if (hours === 12) {
    38          t.pd = "PM";
    39      } else if (hours < 12) {
    40          t.pd = "AM";
    41      }
    42  
    43      var minutes = date.getMinutes();
    44      if (minutes < 10) {
    45          minutes = "0" + String(minutes);
    46      }
    47      t.mm = minutes;
    48  
    49      return t;
    50  }
    51  
    52  // Returns a local partial date object based on unix timestamp
    53  function getPartialDate(unix) {
    54      var date = new Date(unix);
    55      var d = {};
    56      
    57      d.yyyy = date.getFullYear();
    58      
    59      d.mm = date.getMonth()+1;
    60  
    61      var day = date.getDate();
    62      if (day < 10) {
    63          day = "0" + String(day);
    64      }
    65      d.dd = day;
    66  
    67      return d;
    68  }
    69  
    70  // Returns a part of the window URL 'search' string
    71  function getParam(param) {
    72      var qs = window.location.search.substring(1);
    73      var qp = qs.split('&');
    74      var t = '';
    75  
    76      for (var i = 0; i < qp.length; i++) {
    77          var p = qp[i].split('=')
    78          if (p[0] === param) {
    79              t = p[1];	
    80          }
    81      }
    82  
    83      return t;
    84  }