amelie.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*!
  2. * jQuery Cookie Plugin v1.1
  3. * https://github.com/carhartl/jquery-cookie
  4. *
  5. * Copyright 2011, Klaus Hartl
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.opensource.org/licenses/GPL-2.0
  9. */
  10. (function($, document) {
  11. var pluses = /\+/g;
  12. function raw(s) {
  13. return s;
  14. }
  15. function decoded(s) {
  16. return decodeURIComponent(s.replace(pluses, ' '));
  17. }
  18. $.cookie = function(key, value, options) {
  19. // key and at least value given, set cookie...
  20. if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value == null)) {
  21. options = $.extend({}, $.cookie.defaults, options);
  22. if (value == null) {
  23. options.expires = -1;
  24. }
  25. if (typeof options.expires === 'number') {
  26. var days = options.expires, t = options.expires = new Date();
  27. t.setDate(t.getDate() + days);
  28. }
  29. value = String(value);
  30. return (document.cookie = [
  31. encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
  32. options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  33. options.path ? '; path=' + options.path : '',
  34. options.domain ? '; domain=' + options.domain : '',
  35. options.secure ? '; secure' : ''
  36. ].join(''));
  37. }
  38. // key and possibly options given, get cookie...
  39. options = value || $.cookie.defaults || {};
  40. var decode = options.raw ? raw : decoded;
  41. var cookies = document.cookie.split('; ');
  42. for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
  43. if (decode(parts.shift()) === key) {
  44. return decode(parts.join('='));
  45. }
  46. }
  47. return null;
  48. };
  49. $.cookie.defaults = {};
  50. })(jQuery, document);
  51. /*******************************************************************************
  52. * Date utilities
  53. */
  54. Date.prototype.relative = function(t2,fix){
  55. var t1 = this;
  56. var diff = t1 - t2;
  57. var minute = 60, hour = minute * 60, day = hour * 24,
  58. week = day * 7, month = day * 30, year = month * 12;
  59. return inRange(
  60. [0,'just now'],
  61. [5,'% seconds',1],
  62. [minute,'a minute'],
  63. [minute*2,'% minutes',minute],
  64. [minute*30,'half an hour'],
  65. [minute*31,'% minutes',minute],
  66. [hour,'an hour'],
  67. [hour*2,'% hours',hour],
  68. [hour*3,'a few hours'],
  69. [hour*4,'% hours',hour],
  70. [day,'a day'],
  71. [day*2,'% days',day],
  72. [week,'a week'],
  73. [week*2,'% weeks',week],
  74. [month,'a month'],
  75. [month*2,'% months',month],
  76. [year,'a year'],
  77. [year*2,'% years',year]
  78. );
  79. function inRange() {
  80. var span = Math.abs(diff/1000);
  81. for (var i = arguments.length-1; i >= 0; i--) {
  82. var range = arguments[i];
  83. if (span >= range[0]) {
  84. return (
  85. (fix&& diff>0?'in ':'') +
  86. (range[1].match(/%/)?
  87. range[1].replace(/%/g,Math.round(span/(range[2]? range[2] : 1)))
  88. : range[1]) +
  89. (fix&& diff<0?' ago':'')
  90. );
  91. }
  92. }
  93. }
  94. };
  95. function refreshDates(){
  96. $('.relative-time').each(function(){
  97. var t = (new Date($(this).attr('data-epoch') * 1000));
  98. var now = new Date();
  99. $(this).text(t.relative(now,true));
  100. });
  101. }
  102. /*******************************************************************************
  103. * Main code.
  104. */
  105. $(function(){
  106. $('form').each(function(){
  107. $(this).find('input[name=author]')
  108. .val($.cookie('author'))
  109. .change(function(){
  110. $.cookie('author', $(this).val(), { expires: 365, path: '/' });
  111. });
  112. });
  113. $('.hint').each(function (){
  114. var var_2 = $(this);
  115. var_2.css('height','1em');
  116. var_2.css('overflow','hidden');
  117. var_2.parent().css('cursor','pointer');
  118. var_2.parent().toggle(function (){
  119. var_2.css('height','auto');
  120. return false;
  121. },function (){
  122. var_2.css('height','1em');
  123. var_2.css('overflow','hidden');
  124. return false;
  125. });
  126. return true;
  127. });
  128. $('.paste-nav').each(function (){
  129. var var_6 = $('<a href="">Expand</a>');
  130. var var_7 = $(this);
  131. var_7.prepend(' - ');
  132. var_7.prepend(var_6);
  133. var var_8 = var_7.siblings('.paste-specs');
  134. var_8.css('display','none');
  135. var_6.text('Expand');
  136. var_6.toggle(function (){
  137. var_8.css('display','block');
  138. var_6.text('Collapse');
  139. return false;
  140. },function (){
  141. var_8.css('display','none');
  142. var_6.text('Expand');
  143. return false;
  144. });
  145. return true;
  146. });
  147. refreshDates();
  148. setInterval(refreshDates,1000);
  149. });