Skip to content
Snippets Groups Projects
scp.js 34.1 KiB
Newer Older
  • Learn to ignore specific revisions
  •         T.addClass('no-bar small');
        note.replaceWith(T);
        $('<p>').addClass('submit').css('text-align', 'center')
            .append(button).appendTo(T.parent());
        $.redact(T);
        $(T).redactor('focus');
        return false;
    });
    
    
    function __(s) {
    
      if ($.oststrings && $.oststrings[s])
        return $.oststrings[s];
    
    
    // Thanks, http://stackoverflow.com/a/487049
    function addSearchParam(key, value) {
        key = encodeURI(key); value = encodeURI(value);
    
        var kvp = document.location.search.substr(1).split('&');
        var i=kvp.length; var x;
        while (i--) {
            x = kvp[i].split('=');
            if (x[0]==key) {
                x[1] = value;
                kvp[i] = x.join('=');
                break;
            }
        }
        if(i<0) {kvp[kvp.length] = [key,value].join('=');}
    
        //this will reload the page, it's likely better to store this until finished
    
        return kvp.join('&');
    
    
    // Periodically adjust relative times
    window.relativeAdjust = setInterval(function() {
    
      // Thanks, http://stackoverflow.com/a/7641822/1025836
    
      var prettyDate = function(time) {
        var date = new Date((time || "").replace(/-/g, "/").replace(/[TZ]/g, " ")),
            diff = (((new Date()).getTime() - date.getTime()) / 1000),
            day_diff = Math.floor(diff / 86400);
    
        if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) return;
    
        return day_diff == 0 && (
             diff < 60 && __("just now")
          || diff < 120 && __("about a minute ago")
          || diff < 3600 && __("%d minutes ago").replace('%d', Math.floor(diff/60))
          || diff < 7200 && __("about an hour ago")
    
          || diff < 86400 &&  __("%d hours ago").replace('%d', Math.floor(diff/3600))
    
        )
        || day_diff == 1 && __("yesterday")
        || day_diff < 7 && __("%d days ago").replace('%d', day_diff);
        // Longer dates don't need to change dynamically
      };
      $('time.relative[datetime]').each(function() {
        var rel = prettyDate($(this).attr('datetime'));
        if (rel) $(this).text(rel);
      });
    }, 20000);