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

507 行
13 KiB

  1. wn.dom.set_unique_id = function(ele) {
  2. var id = 'unique-' + wn.dom.id_count;
  3. ele.setAttribute('id', id);
  4. wn.dom.id_count++;
  5. return id;
  6. }
  7. // short hand functions for setting up
  8. // rich text editor tinymce
  9. wn.tinymce = {
  10. add_simple: function(ele, height) {
  11. if(ele.myid) {
  12. tinyMCE.execCommand( 'mceAddControl', true, ele.myid);
  13. return;
  14. }
  15. // no create
  16. ele.myid = wn.dom.set_unique_id(ele);
  17. $(ele).tinymce({
  18. // Location of TinyMCE script
  19. script_url : 'lib/js/legacy/tiny_mce_33/tiny_mce.js',
  20. height: height ? height : '200px',
  21. // General options
  22. theme : "advanced",
  23. theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,link,unlink,forecolor,backcolor,code,",
  24. theme_advanced_buttons2 : "",
  25. theme_advanced_buttons3 : "",
  26. theme_advanced_toolbar_location : "top",
  27. theme_advanced_toolbar_align : "left",
  28. theme_advanced_path : false,
  29. theme_advanced_resizing : false
  30. });
  31. },
  32. remove: function(ele) {
  33. tinyMCE.execCommand( 'mceRemoveControl', true, ele.myid);
  34. },
  35. get_value: function(ele) {
  36. return tinymce.get(ele.myid).getContent();
  37. }
  38. }
  39. wn.ele = {
  40. link: function(args) {
  41. var span = $a(args.parent, 'span', 'link_type', args.style);
  42. span.loading_img = $a(args.parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  43. span.loading_img.src= 'lib/images/ui/button-load.gif';
  44. span.innerHTML = args.label;
  45. span.user_onclick = args.onclick;
  46. span.onclick = function() { if(!this.disabled) this.user_onclick(this); }
  47. // working
  48. span.set_working = function() {
  49. this.disabled = 1;
  50. $di(this.loading_img);
  51. }
  52. span.done_working = function() {
  53. this.disabled = 0;
  54. $dh(this.loading_img);
  55. }
  56. return span;
  57. }
  58. }
  59. function $ln(parent, label, onclick, style) {
  60. return wn.ele.link({parent:parent, label:label, onclick:onclick, style:style})
  61. }
  62. function $btn(parent, label, onclick, style, css_class, is_ajax) {
  63. wn.require('lib/js/wn/ui/button.js');
  64. if(css_class==='green') css_class='btn-primary';
  65. return new wn.ui.Button(
  66. {parent:parent, label:label, onclick:onclick, style:style, is_ajax: is_ajax, css_class: css_class}
  67. ).btn;
  68. }
  69. // item (for tabs and triggers)
  70. // ====================================
  71. $item_normal = function(ele) {
  72. $y(ele, {padding:'6px 8px',cursor:'pointer',marginRight:'8px', whiteSpace:'nowrap',overflow:'hidden',borderBottom:'1px solid #DDD'});
  73. $bg(ele,'#FFF'); $fg(ele,'#000');
  74. }
  75. $item_active = function(ele) {
  76. $bg(ele,'#FE8'); $fg(ele,'#000');
  77. }
  78. $item_selected = function(ele) {
  79. $bg(ele,'#777'); $fg(ele,'#FFF');
  80. }
  81. $item_pressed = function(ele) {
  82. $bg(ele,'#F90'); $fg(ele,'#FFF');
  83. };
  84. (function($) {
  85. $.fn.set_working = function() {
  86. var ele = this.get(0);
  87. if(ele.loading_img) {
  88. $di(ele.loading_img)
  89. } else {
  90. ele.disabled = 1;
  91. ele.loading_img = $a(ele.parentNode,'img','',
  92. {marginLeft:'4px',marginBottom:'-2px',display:'inline'});
  93. ele.loading_img.src = 'lib/images/ui/button-load.gif';
  94. }
  95. }
  96. $.fn.done_working = function() {
  97. var ele = this.get(0);
  98. ele.disabled = 0;
  99. if(ele.loading_img) { $dh(ele.loading_img) };
  100. }
  101. })(jQuery);
  102. // set out of 100
  103. function set_opacity(ele, ieop) {
  104. var op = ieop / 100;
  105. if (ele.filters) { // internet explorer
  106. try {
  107. ele.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;
  108. } catch (e) {
  109. ele.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';
  110. }
  111. } else { // other browsers
  112. ele.style.opacity = op;
  113. }
  114. }
  115. // border radius
  116. // ====================================
  117. $br = function(ele, r, corners) {
  118. if(corners) {
  119. var cl = ['top-left', 'top-right', 'bottom-right' , 'bottom-left'];
  120. for(var i=0; i<4; i++) {
  121. if(corners[i]) {
  122. $(ele).css('-moz-border-radius-'+cl[i].replace('-',''),r).css('-webkit-'+cl[i]+'-border-radius',r);
  123. }
  124. }
  125. } else {
  126. $(ele).css('-moz-border-radius',r).css('-webkit-border-radius',r).css('border-radius',r);
  127. }
  128. }
  129. $bs = function(ele, r) { $(ele).css('-moz-box-shadow',r).css('-webkit-box-shadow',r).css('box-shadow',r); }
  130. // Select
  131. // ====================================
  132. function empty_select(s) {
  133. if(s.custom_select) { s.empty(); return; }
  134. if(s.inp)s = s.inp;
  135. if(s) {
  136. var tmplen = s.length; for(var i=0;i<tmplen; i++) s.options[0] = null;
  137. }
  138. }
  139. function sel_val(s) {
  140. if(s.custom_select) {
  141. return s.inp.value ? s.inp.value : '';
  142. }
  143. if(s.inp)s = s.inp;
  144. try {
  145. if(s.selectedIndex<s.options.length) return s.options[s.selectedIndex].value;
  146. else return '';
  147. } catch(err) { return ''; /* IE fix */ }
  148. }
  149. function add_sel_options(s, list, sel_val, o_style) {
  150. if(s.custom_select) {
  151. s.set_options(list)
  152. if(sel_val) s.inp.value = sel_val;
  153. return;
  154. }
  155. if(s.inp)s = s.inp;
  156. for(var i=0, len=list.length; i<len; i++) {
  157. var o = new Option(list[i], list[i], false, (list[i]==sel_val? true : false));
  158. if(o_style) $y(o, o_style);
  159. s.options[s.options.length] = o;
  160. }
  161. }
  162. function cint(v, def) {
  163. v=v+'';
  164. v=lstrip(v, ['0']);
  165. v=parseInt(v);
  166. if(isNaN(v))v=def?def:0; return v;
  167. }
  168. function validate_email(id) {
  169. if(strip(id).search("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")==-1) return 0; else return 1; }
  170. function validate_spl_chars(txt) {
  171. if(txt.search(/^[a-zA-Z0-9_\- ]*$/)==-1) return 1; else return 0; }
  172. function d2h(d) {return cint(d).toString(16);}
  173. function h2d(h) {return parseInt(h,16);}
  174. var $n = '\n';
  175. function set_title(t) {
  176. document.title = (wn.title_prefix ? (wn.title_prefix + ' - ') : '') + t;
  177. }
  178. function $a(parent, newtag, className, cs, innerHTML, onclick) {
  179. if(parent && parent.substr)parent = $i(parent);
  180. var c = document.createElement(newtag);
  181. if(parent)
  182. parent.appendChild(c);
  183. // if image, 3rd parameter is source
  184. if(className) {
  185. if(newtag.toLowerCase()=='img')
  186. c.src = className
  187. else
  188. c.className = className;
  189. }
  190. if(cs)$y(c,cs);
  191. if(innerHTML) c.innerHTML = innerHTML;
  192. if(onclick) c.onclick = onclick;
  193. return c;
  194. }
  195. function $a_input(p, in_type, attributes, cs) {
  196. if(!attributes) attributes = {};
  197. var $input = $(p).append('<input type="'+ in_type +'">').find('input:last');
  198. for(key in attributes)
  199. $input.attr(key, attributes[key]);
  200. var input = $input.get(0);
  201. if(cs)
  202. $y(input,cs);
  203. return input;
  204. }
  205. function $dh(d) {
  206. if(d && d.substr)d=$i(d);
  207. if(d && d.style.display.toLowerCase() != 'none') d.style.display = 'none';
  208. }
  209. function $ds(d) {
  210. if(d && d.substr)d=$i(d);
  211. var t = 'block';
  212. if(d && in_list(['span','img','button'], d.tagName.toLowerCase()))
  213. t = 'inline'
  214. if(d && d.style.display.toLowerCase() != t)
  215. d.style.display = t;
  216. }
  217. function $di(d) { if(d && d.substr)d=$i(d); if(d)d.style.display = 'inline'; }
  218. function $i(id) {
  219. if(!id) return null;
  220. if(id && id.appendChild)return id; // already an element
  221. return document.getElementById(id);
  222. }
  223. function $t(parent, txt) { if(parent.substr)parent = $i(parent); return parent.appendChild(document.createTextNode(txt)); }
  224. function $w(e,w) { if(e && e.style && w)e.style.width = w; }
  225. function $h(e,h) { if(e && e.style && h)e.style.height = h; }
  226. function $bg(e,w) { if(e && e.style && w)e.style.backgroundColor = w; }
  227. function $fg(e,w) { if(e && e.style && w)e.style.color = w; }
  228. function $op(e,w) { if(e && e.style && w) { set_opacity(e,w); } }
  229. function $y(ele, s) {
  230. if(ele && s) {
  231. for(var i in s) ele.style[i]=s[i];
  232. };
  233. return ele;
  234. }
  235. function $yt(tab, r, c, s) { /// set style on tables with wildcards
  236. var rmin = r; var rmax = r;
  237. if(r=='*') { rmin = 0; rmax = tab.rows.length-1; }
  238. if(r.search && r.search('-')!= -1) {
  239. r = r.split('-');
  240. rmin = cint(r[0]); rmax = cint(r[1]);
  241. }
  242. var cmin = c; var cmax = c;
  243. if(c=='*') { cmin = 0; cmax = tab.rows[0].cells.length-1; }
  244. if(c.search && c.search('-')!= -1) {
  245. c = c.split('-');
  246. rmin = cint(c[0]); rmax = cint(c[1]);
  247. }
  248. for(var ri = rmin; ri<=rmax; ri++) {
  249. for(var ci = cmin; ci<=cmax; ci++)
  250. $y($td(tab,ri,ci),s);
  251. }
  252. }
  253. // add css classes etc
  254. function set_style(txt) {
  255. var se = document.createElement('style');
  256. se.type = "text/css";
  257. if (se.styleSheet) {
  258. se.styleSheet.cssText = txt;
  259. } else {
  260. se.appendChild(document.createTextNode(txt));
  261. }
  262. document.getElementsByTagName('head')[0].appendChild(se);
  263. }
  264. // Make table
  265. function make_table(parent, nr, nc, table_width, widths, cell_style, table_style) {
  266. var t = $a(parent, 'table');
  267. t.style.borderCollapse = 'collapse';
  268. if(table_width) t.style.width = table_width;
  269. if(cell_style) t.cell_style=cell_style;
  270. for(var ri=0;ri<nr;ri++) {
  271. var r = t.insertRow(ri);
  272. for(var ci=0;ci<nc;ci++) {
  273. var c = r.insertCell(ci);
  274. if(ri==0 && widths && widths[ci]) {
  275. // set widths
  276. c.style.width = widths[ci];
  277. }
  278. if(cell_style) {
  279. for(var s in cell_style) c.style[s] = cell_style[s];
  280. }
  281. }
  282. }
  283. t.append_row = function() { return append_row(this); }
  284. if(table_style) $y(t, table_style);
  285. return t;
  286. }
  287. function append_row(t, at, style) {
  288. var r = t.insertRow(at ? at : t.rows.length);
  289. if(t.rows.length>1) {
  290. for(var i=0;i<t.rows[0].cells.length;i++) {
  291. var c = r.insertCell(i);
  292. if(style) $y(c, style);
  293. }
  294. }
  295. return r
  296. }
  297. function $td(t,r,c) {
  298. if(r<0)r=t.rows.length+r;
  299. if(c<0)c=t.rows[0].cells.length+c;
  300. return t.rows[r].cells[c];
  301. }
  302. // sum of values in a table column
  303. function $sum(t, cidx) {
  304. var s = 0;
  305. if(cidx<1)cidx = t.rows[0].cells.length + cidx;
  306. for(var ri=0; ri<t.rows.length; ri++) {
  307. var c = t.rows[ri].cells[cidx];
  308. if(c.div) s += flt(c.div.innerHTML);
  309. else if(c.value) s+= flt(c.value);
  310. else s += flt(c.innerHTML);
  311. }
  312. return s;
  313. }
  314. function objpos(obj){
  315. if(obj.substr)obj = $i(obj);
  316. var p = $(obj).offset();
  317. return {x : cint(p.left), y : cint(p.top) }
  318. }
  319. function get_screen_dims() {
  320. var d={};
  321. d.w = 0; d.h = 0;
  322. if( typeof( window.innerWidth ) == 'number' ) {
  323. //Non-IE
  324. d.w = window.innerWidth;
  325. d.h = window.innerHeight;
  326. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  327. //IE 6+ in 'standards compliant mode'
  328. d.w = document.documentElement.clientWidth;
  329. d.h = document.documentElement.clientHeight;
  330. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  331. //IE 4 compatible
  332. d.w = document.body.clientWidth;
  333. d.h = document.body.clientHeight;
  334. }
  335. return d
  336. }
  337. // get full page size
  338. function get_page_size(){
  339. return [$(document).height(), $(document).width()];
  340. }
  341. // get scroll top
  342. function get_scroll_top() {
  343. var st = 0;
  344. if(document.documentElement && document.documentElement.scrollTop)
  345. st = document.documentElement.scrollTop;
  346. else if(document.body && document.body.scrollTop)
  347. st = document.body.scrollTop;
  348. return st;
  349. }
  350. function get_cookie(c) {
  351. var t=""+document.cookie;
  352. var ind=t.indexOf(c);
  353. if (ind==-1 || c=="") return "";
  354. var ind1=t.indexOf(';',ind);
  355. if (ind1==-1) ind1=t.length;
  356. return unescape(t.substring(ind+c.length+1,ind1));
  357. }
  358. // URL utilities
  359. wn.urllib = {
  360. // get argument from url
  361. get_arg: function(name) {
  362. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  363. var regexS = "[\\?&]"+name+"=([^&#]*)";
  364. var regex = new RegExp( regexS );
  365. var results = regex.exec( window.location.href );
  366. if( results == null )
  367. return "";
  368. else
  369. return decodeURIComponent(results[1]);
  370. },
  371. // returns url dictionary
  372. get_dict: function() {
  373. var d = {}
  374. var t = window.location.href.split('?')[1];
  375. if(!t) return d;
  376. if(t.indexOf('#')!=-1) t = t.split('#')[0];
  377. if(!t) return d;
  378. t = t.split('&');
  379. for(var i=0; i<t.length; i++) {
  380. var a = t[i].split('=');
  381. d[decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
  382. }
  383. return d;
  384. },
  385. // returns the base url with http + domain + path (-index.cgi or # or ?)
  386. get_base_url: function() {
  387. var url= window.location.href.split('#')[0].split('?')[0].split('index.html')[0];
  388. if(url.substr(url.length-1, 1)=='/') url = url.substr(0, url.length-1)
  389. return url
  390. },
  391. // return the relative http url for
  392. // a file upload / attachment
  393. // by file id / name
  394. get_file_url: function(file_id) {
  395. return repl('files/%(fn)s', {fn:file_id})
  396. }
  397. }
  398. get_url_arg = wn.urllib.get_arg;
  399. get_url_dict = wn.urllib.get_dict;
  400. // set user image
  401. var user_img = {}
  402. var user_img_queue = {};
  403. var user_img_loading = [];
  404. set_user_img = function(img, username, get_latest, img_id) {
  405. function set_it(i) {
  406. if(user_img[username]=='no_img_m')
  407. i.src = 'lib/images/ui/no_img_m.gif';
  408. else if(user_img[username]=='no_img_f')
  409. i.src = 'lib/images/ui/no_img_f.gif'; // no image
  410. else {
  411. ac_id = wn.control_panel.account_id;
  412. i.src = repl('cgi-bin/getfile.cgi?ac=%(ac)s&name=%(fn)s', {fn:user_img[username], ac:ac_id});
  413. }
  414. }
  415. // given
  416. if(img_id) {
  417. user_img[username] = img_id;
  418. set_it(img);
  419. return;
  420. }
  421. // from dict or load
  422. if(user_img[username] && !get_latest) {
  423. set_it(img);
  424. } else{
  425. // queue multiple request while loading
  426. if(in_list(user_img_loading,username)) {
  427. if(!user_img_queue[username])
  428. user_img_queue[username] = [];
  429. user_img_queue[username].push(img);
  430. return;
  431. }
  432. $c('webnotes.profile.get_user_img',{username:username},function(r,rt) {
  433. delete user_img_loading[user_img_loading.indexOf(username)];
  434. user_img[username] = r.message;
  435. if(user_img_queue[username]) {
  436. var q=user_img_queue[username];
  437. for(var i in q) { set_it(q[i]); }
  438. }
  439. set_it(img);
  440. }, null, 1);
  441. user_img_loading.push(username);
  442. }
  443. }