您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

247 行
5.3 KiB

  1. // common file between desk and website
  2. frappe.avatar = function(user, css_class, title) {
  3. if(user) {
  4. // desk
  5. var user_info = frappe.user_info(user);
  6. } else {
  7. // website
  8. user_info = {
  9. image: frappe.get_cookie("user_image"),
  10. fullname: frappe.get_cookie("full_name"),
  11. abbr: frappe.get_abbr(frappe.get_cookie("full_name")),
  12. color: frappe.get_palette(frappe.get_cookie("full_name"))
  13. }
  14. }
  15. if(!title) {
  16. title = user_info.fullname;
  17. }
  18. if(!css_class) {
  19. css_class = "avatar-small";
  20. }
  21. if(user_info.image) {
  22. var image = (window.cordova && user_info.image.indexOf('http')===-1) ?
  23. frappe.base_url + user_info.image : user_info.image;
  24. return repl('<span class="avatar %(css_class)s" title="%(title)s">\
  25. <span class="avatar-frame" style="background-image: url(%(image)s)"\
  26. title="%(title)s"></span></span>', {
  27. image: image,
  28. title: title,
  29. abbr: user_info.abbr,
  30. css_class: css_class
  31. });
  32. } else {
  33. var abbr = user_info.abbr;
  34. if(css_class==='avatar-small' || css_class=='avatar-xs') {
  35. abbr = abbr.substr(0, 1);
  36. }
  37. return repl('<span class="avatar %(css_class)s" title="%(title)s">\
  38. <div class="standard-image" style="background-color: %(color)s;">%(abbr)s</div></span>', {
  39. title: title,
  40. abbr: abbr,
  41. css_class: css_class,
  42. color: user_info.color
  43. })
  44. }
  45. }
  46. frappe.get_palette = function(txt) {
  47. return '#fafbfc';
  48. // //return '#8D99A6';
  49. // if(txt==='Administrator') return '#36414C';
  50. // // get color palette selection from md5 hash
  51. // var idx = cint((parseInt(md5(txt).substr(4,2), 16) + 1) / 5.33);
  52. // if(idx > 47) idx = 47;
  53. // return frappe.palette[idx][0]
  54. }
  55. frappe.get_abbr = function(txt, max_length) {
  56. if (!txt) return "";
  57. var abbr = "";
  58. $.each(txt.split(" "), function(i, w) {
  59. if (abbr.length >= (max_length || 2)) {
  60. // break
  61. return false;
  62. } else if (!w.trim().length) {
  63. // continue
  64. return true;
  65. }
  66. abbr += w.trim()[0];
  67. });
  68. return abbr || "?";
  69. }
  70. frappe.gravatars = {};
  71. frappe.get_gravatar = function(email_id) {
  72. if(!frappe.gravatars[email_id]) {
  73. frappe.gravatars[email_id] = "https://secure.gravatar.com/avatar/" + md5(email_id) + "?d=retro";
  74. }
  75. return frappe.gravatars[email_id];
  76. }
  77. // string commons
  78. function repl(s, dict) {
  79. if(s==null)return '';
  80. for(var key in dict) {
  81. s = s.split("%("+key+")s").join(dict[key]);
  82. }
  83. return s;
  84. }
  85. function replace_all(s, t1, t2) {
  86. return s.split(t1).join(t2);
  87. }
  88. function strip_html(txt) {
  89. return txt.replace(/<[^>]*>/g, "");
  90. }
  91. var strip = function(s, chars) {
  92. if (s) {
  93. var s= lstrip(s, chars)
  94. s = rstrip(s, chars);
  95. return s;
  96. }
  97. }
  98. var lstrip = function(s, chars) {
  99. if(!chars) chars = ['\n', '\t', ' '];
  100. // strip left
  101. var first_char = s.substr(0,1);
  102. while(in_list(chars, first_char)) {
  103. var s = s.substr(1);
  104. first_char = s.substr(0,1);
  105. }
  106. return s;
  107. }
  108. var rstrip = function(s, chars) {
  109. if(!chars) chars = ['\n', '\t', ' '];
  110. var last_char = s.substr(s.length-1);
  111. while(in_list(chars, last_char)) {
  112. var s = s.substr(0, s.length-1);
  113. last_char = s.substr(s.length-1);
  114. }
  115. return s;
  116. }
  117. function getCookie(name) {
  118. return getCookies()[name];
  119. }
  120. frappe.get_cookie = getCookie;
  121. function getCookies() {
  122. var c = document.cookie, v = 0, cookies = {};
  123. if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) {
  124. c = RegExp.$1;
  125. v = 1;
  126. }
  127. if (v === 0) {
  128. c.split(/[,;]/).map(function(cookie) {
  129. var parts = cookie.split(/=/, 2),
  130. name = decodeURIComponent(parts[0].trimLeft()),
  131. value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;
  132. if(value && value.charAt(0)==='"') {
  133. value = value.substr(1, value.length-2);
  134. }
  135. cookies[name] = value;
  136. });
  137. } else {
  138. c.match(/(?:^|\s+)([!#$%&'*+\-.0-9A-Z^`a-z|~]+)=([!#$%&'*+\-.0-9A-Z^`a-z|~]*|"(?:[\x20-\x7E\x80\xFF]|\\[\x00-\x7F])*")(?=\s*[,;]|$)/g).map(function($0, $1) {
  139. var name = $0,
  140. value = $1.charAt(0) === '"'
  141. ? $1.substr(1, -1).replace(/\\(.)/g, "$1")
  142. : $1;
  143. cookies[name] = value;
  144. });
  145. }
  146. return cookies;
  147. }
  148. if (typeof String.prototype.trimLeft !== "function") {
  149. String.prototype.trimLeft = function() {
  150. return this.replace(/^\s+/, "");
  151. };
  152. }
  153. if (typeof String.prototype.trimRight !== "function") {
  154. String.prototype.trimRight = function() {
  155. return this.replace(/\s+$/, "");
  156. };
  157. }
  158. if (typeof Array.prototype.map !== "function") {
  159. Array.prototype.map = function(callback, thisArg) {
  160. for (var i=0, n=this.length, a=[]; i<n; i++) {
  161. if (i in this) a[i] = callback.call(thisArg, this[i]);
  162. }
  163. return a;
  164. };
  165. }
  166. frappe.palette = [
  167. ['#FFC4C4', 0],
  168. ['#FFE8CD', 0],
  169. ['#FFD2C2', 0],
  170. ['#FF8989', 0],
  171. ['#FFD19C', 0],
  172. ['#FFA685', 0],
  173. ['#FF4D4D', 1],
  174. ['#FFB868', 0],
  175. ['#FF7846', 1],
  176. ['#A83333', 1],
  177. ['#A87945', 1],
  178. ['#A84F2E', 1],
  179. ['#D2D2FF', 0],
  180. ['#F8D4F8', 0],
  181. ['#DAC7FF', 0],
  182. ['#A3A3FF', 0],
  183. ['#F3AAF0', 0],
  184. ['#B592FF', 0],
  185. ['#7575FF', 0],
  186. ['#EC7DEA', 0],
  187. ['#8E58FF', 1],
  188. ['#4D4DA8', 1],
  189. ['#934F92', 1],
  190. ['#5E3AA8', 1],
  191. ['#EBF8CC', 0],
  192. ['#FFD7D7', 0],
  193. ['#D2F8ED', 0],
  194. ['#D9F399', 0],
  195. ['#FFB1B1', 0],
  196. ['#A4F3DD', 0],
  197. ['#C5EC63', 0],
  198. ['#FF8989', 1],
  199. ['#77ECCA', 0],
  200. ['#7B933D', 1],
  201. ['#A85B5B', 1],
  202. ['#49937E', 1],
  203. ['#FFFACD', 0],
  204. ['#D2F1FF', 0],
  205. ['#CEF6D1', 0],
  206. ['#FFF69C', 0],
  207. ['#A6E4FF', 0],
  208. ['#9DECA2', 0],
  209. ['#FFF168', 0],
  210. ['#78D6FF', 0],
  211. ['#6BE273', 0],
  212. ['#A89F45', 1],
  213. ['#4F8EA8', 1],
  214. ['#428B46', 1]
  215. ]
  216. frappe.is_mobile = function() {
  217. return $(document).width() < 768;
  218. }