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

772 行
20 KiB

  1. wn.dom = {
  2. id_count: 0,
  3. // sets a unique id to an element
  4. set_unique_id: function(ele) {
  5. var id = 'unique-' + wn.dom.id_count;
  6. ele.setAttribute('id', id);
  7. wn.dom.id_count++;
  8. return id;
  9. }
  10. }
  11. // short hand functions for setting up
  12. // rich text editor tinymce
  13. wn.tinymce = {
  14. add_simple: function(ele, height) {
  15. if(ele.myid) {
  16. tinyMCE.execCommand( 'mceAddControl', true, ele.myid);
  17. return;
  18. }
  19. // no create
  20. ele.myid = wn.dom.set_unique_id(ele);
  21. $(ele).tinymce({
  22. // Location of TinyMCE script
  23. script_url : 'js/tiny_mce_33/tiny_mce.js',
  24. height: height ? height : '200px',
  25. // General options
  26. theme : "advanced",
  27. theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,link,unlink,forecolor,backcolor,code,",
  28. theme_advanced_buttons2 : "",
  29. theme_advanced_buttons3 : "",
  30. theme_advanced_toolbar_location : "top",
  31. theme_advanced_toolbar_align : "left",
  32. theme_advanced_path : false,
  33. theme_advanced_resizing : false
  34. });
  35. },
  36. remove: function(ele) {
  37. tinyMCE.execCommand( 'mceRemoveControl', true, ele.myid);
  38. },
  39. get_value: function(ele) {
  40. return tinymce.get(ele.myid).getContent();
  41. }
  42. }
  43. wn.ele = {
  44. link: function(args) {
  45. var span = $a(args.parent, 'span', 'link_type', args.style);
  46. span.loading_img = $a(args.parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  47. span.loading_img.src= 'images/ui/button-load.gif';
  48. span.innerHTML = args.label;
  49. span.user_onclick = args.onclick;
  50. span.onclick = function() { if(!this.disabled) this.user_onclick(this); }
  51. // working
  52. span.set_working = function() {
  53. this.disabled = 1;
  54. $di(this.loading_img);
  55. }
  56. span.done_working = function() {
  57. this.disabled = 0;
  58. $dh(this.loading_img);
  59. }
  60. return span;
  61. },
  62. button: function(args) {
  63. var btn = $a(args.parent, 'button');
  64. btn.loading_img = $a(args.parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  65. btn.loading_img.src= 'images/ui/button-load.gif';
  66. $wid_make(btn,color);
  67. if(args.is_ajax) $y(btn,{marginRight:'24px'});
  68. // click
  69. btn.innerHTML = args.label;
  70. btn.user_onclick = args.onclick;
  71. btn.color = args.color;
  72. btn.onclick = function() { if(!this.disabled) this.user_onclick(this); }
  73. // color
  74. $(btn).hover(
  75. function() { $wid_active(this); },
  76. function() { $wid_normal(this); }
  77. )
  78. btn.onmousedown = function() { $wid_pressed(this); }
  79. btn.onmouseup = function() { $wid_active(this); }
  80. // disabled
  81. btn.set_disabled = function() {
  82. $wid_disabled(this);
  83. }
  84. btn.set_enabled = function() {
  85. this.disabled = 0;
  86. $wid_normal(this);
  87. }
  88. // working
  89. btn.set_working = function() {
  90. this.set_disabled();
  91. $di(this.loading_img);
  92. if(args.is_ajax) $y(btn,{marginRight:'0px'});
  93. }
  94. btn.done_working = function() {
  95. this.set_enabled();
  96. $dh(this.loading_img);
  97. if(args.is_ajax) $y(btn,{marginRight:'24px'});
  98. }
  99. if(args.style) $y(btn, args.style);
  100. return btn;
  101. }
  102. }
  103. function $ln(parent, label, onclick, style) {
  104. return wn.ele.link({parent:parent, label:label, onclick:onclick, style:style})
  105. }
  106. function $btn(parent, label, onclick, style, color, is_ajax) {
  107. return wn.ele.button({parent:parent, label:label, onclick:onclick, style:style, is_ajax: is_ajax})
  108. }
  109. function addEvent(ev, fn) {
  110. if(isIE) {
  111. document.attachEvent('on'+ev, function() {
  112. fn(window.event, window.event.srcElement);
  113. });
  114. } else {
  115. document.addEventListener(ev, function(e) { fn(e, e.target); }, true);
  116. }
  117. }
  118. // widget styles
  119. // ====================================
  120. // normal
  121. // --------------------
  122. $wid_normal = function(ele) {
  123. if(ele.disabled) return;
  124. $y(ele, {border:'1px solid #AAC', color:'#446'}); $gr(ele,'#FFF','#D8D8E2');
  125. if(ele.no_left_border) $y(ele, {borderLeft:'0px'})
  126. if(ele.wid_color=='green') {
  127. $y(ele, {color:'#FFF', border:'1px solid #4B4'}); $gr(ele,'#9C9','#4A4');
  128. }
  129. }
  130. $wid_make = function(ele,color) {
  131. if(ele.disabled) return;
  132. fsize = ele.style.fontSize ? ele.style.fontSize : '11px';
  133. $y(ele, {padding:'2px 8px', cursor:'pointer',fontSize:fsize});
  134. $br(ele,'2px');
  135. $bs(ele, '0.5px 0.5px 2px #EEE');
  136. ele.wid_color = color ? color : 'normal';
  137. $wid_normal(ele);
  138. }
  139. // disabled
  140. // --------------------
  141. $wid_disabled = function(ele) {
  142. ele.disabled = 1;
  143. $y(ele, {border:'1px solid #AAA'}); $bg(ele,'#E8E8EA'); $fg(ele,'#AAA');
  144. }
  145. // active (mouseover)
  146. // --------------------
  147. $wid_active = function(ele) {
  148. if(ele.disabled) return;
  149. $y(ele, {border:'1px solid #446', color:'#446'}); $gr(ele,'#FFF','#EEF');
  150. if(ele.no_left_border) $y(ele, {borderLeft:'0px'})
  151. if(ele.wid_color=='green') {
  152. $y(ele, {color:'#FFF', border:'1px solid #292'}); $gr(ele,'#AFA','#7C7');
  153. }
  154. }
  155. // pressed
  156. // --------------------
  157. $wid_pressed = function(ele) {
  158. if(ele.disabled) return;
  159. $y(ele, {border:'1px solid #444'}); $gr(ele,'#EEF','#DDF');
  160. if(ele.wid_color=='green') {
  161. $y(ele, {color:'#FFF', border:'1px solid #292'}); $gr(ele,'#7C7','#2A2');
  162. }
  163. }
  164. // item (for tabs and triggers)
  165. // ====================================
  166. $item_normal = function(ele) {
  167. $y(ele, {padding:'6px 8px',cursor:'pointer',marginRight:'8px', whiteSpace:'nowrap',overflow:'hidden',borderBottom:'1px solid #DDD'});
  168. $bg(ele,'#FFF'); $fg(ele,'#000');
  169. }
  170. $item_active = function(ele) {
  171. $bg(ele,'#FE8'); $fg(ele,'#000');
  172. }
  173. $item_selected = function(ele) {
  174. $bg(ele,'#777'); $fg(ele,'#FFF');
  175. }
  176. $item_pressed = function(ele) {
  177. $bg(ele,'#F90'); $fg(ele,'#FFF');
  178. }
  179. $item_set_working = function(ele) {
  180. if(ele.loading_img) {
  181. $di(ele.loading_img)
  182. } else {
  183. ele.disabled = 1;
  184. ele.loading_img = $a(ele.parentNode,'img','',{marginLeft:'4px',marginBottom:'-2px',display:'inline'});
  185. ele.loading_img.src = 'images/ui/button-load.gif';
  186. }
  187. }
  188. $item_done_working = function(ele) {
  189. ele.disabled = 0;
  190. if(ele.loading_img) { $dh(ele.loading_img) };
  191. }
  192. // set out of 100
  193. function set_opacity(ele, ieop) {
  194. var op = ieop / 100;
  195. if (ele.filters) { // internet explorer
  196. try {
  197. ele.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;
  198. } catch (e) {
  199. ele.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';
  200. }
  201. } else { // other browsers
  202. ele.style.opacity = op;
  203. }
  204. }
  205. // join buttons
  206. // ------------------------------------
  207. function $btn_join(btn1, btn2) {
  208. $br(btn1, '0px', [0,1,1,0]);
  209. $br(btn2, '0px', [1,0,0,1]);
  210. $y(btn1, {marginRight:'0px'});
  211. $y(btn2, {marginLeft:'0px', borderLeft:'0px'});
  212. btn2.no_left_border = 1;
  213. }
  214. // set gradient
  215. // ====================================
  216. function set_gradient(ele, from, to) {
  217. // gradient
  218. var no_gradient=0;
  219. if(isIE)no_gradient=1;
  220. if(isFF && ffversion < 3.6)no_gradient=1;
  221. if(no_gradient) {
  222. var rgb_from = get_rgb(from.substr(1)); var rgb_to = get_rgb(to.substr(1));
  223. $y(ele, {backgroundColor: '#'
  224. + d2h(rgb_to[0] + (rgb_from[0]-rgb_to[0])/2)
  225. + d2h(rgb_to[1] + (rgb_from[1]-rgb_to[1])/2)
  226. + d2h(rgb_to[2] + (rgb_from[2]-rgb_to[2])/2)});
  227. } else {
  228. $y(ele, {background: '-webkit-gradient(linear, left top, left bottom, from('+from+'), to('+to+'))'});
  229. $y(ele, {background: '-moz-linear-gradient(top, '+from+', '+to+')'});
  230. }
  231. }
  232. $gr = set_gradient;
  233. // border radius
  234. // ====================================
  235. $br = function(ele, r, corners) {
  236. if(corners) {
  237. var cl = ['top-left', 'top-right', 'bottom-right' , 'bottom-left'];
  238. for(var i=0; i<4; i++) {
  239. if(corners[i]) {
  240. $(ele).css('-moz-border-radius-'+cl[i].replace('-',''),r).css('-webkit-'+cl[i]+'-border-radius',r);
  241. }
  242. }
  243. } else {
  244. $(ele).css('-moz-border-radius',r).css('-webkit-border-radius',r).css('border-radius',r);
  245. }
  246. }
  247. $bs = function(ele, r) { $(ele).css('-moz-box-shadow',r).css('-webkit-box-shadow',r).css('box-shadow',r); }
  248. // Button
  249. // ====================================
  250. function $btn(parent, label, onclick, style, color, ajax) {
  251. var btn = $a(parent, 'button');
  252. btn.loading_img = $a(parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  253. btn.loading_img.src= 'images/ui/button-load.gif';
  254. $wid_make(btn,color);
  255. if(ajax) $y(btn,{marginRight:'24px'});
  256. // click
  257. btn.innerHTML = label;
  258. btn.user_onclick = onclick; btn.color = color;
  259. btn.onclick = function() { if(!this.disabled) this.user_onclick(this); }
  260. // color
  261. $(btn).hover(
  262. function() { $wid_active(this); },
  263. function() { $wid_normal(this); }
  264. )
  265. btn.onmousedown = function() { $wid_pressed(this); }
  266. btn.onmouseup = function() { $wid_active(this); }
  267. // disabled
  268. btn.set_disabled = function() {
  269. $wid_disabled(this);
  270. }
  271. btn.set_enabled = function() {
  272. this.disabled = 0;
  273. $wid_normal(this);
  274. }
  275. // working
  276. btn.set_working = function() {
  277. this.set_disabled();
  278. $di(this.loading_img);
  279. if(ajax) $y(btn,{marginRight:'0px'});
  280. }
  281. btn.done_working = function() {
  282. this.set_enabled();
  283. $dh(this.loading_img);
  284. if(ajax) $y(btn,{marginRight:'24px'});
  285. }
  286. if(style) $y(btn, style);
  287. return btn;
  288. }
  289. // standard input pattern
  290. // has a standard text that clears on change
  291. // and if onchange the value is empty, shows the text
  292. (function($) {
  293. $.fn.add_default_text = function(txt) {
  294. return this.each(function() {
  295. $(this).attr('default_text', txt).bind('focus', function() {
  296. if(this.value==$(this).attr('default_text')) {
  297. $(this).val('').css('color', '#000');
  298. }
  299. }).bind('blur', function() {
  300. if(!this.value) {
  301. $(this).val($(this).attr('default_text')).css('color', '#888');
  302. }
  303. }).blur();
  304. });
  305. };
  306. })(jQuery);
  307. // Select
  308. // ====================================
  309. function empty_select(s) {
  310. if(s.custom_select) { s.empty(); return; }
  311. if(s.inp)s = s.inp;
  312. if(s) {
  313. var tmplen = s.length; for(var i=0;i<tmplen; i++) s.options[0] = null;
  314. }
  315. }
  316. function sel_val(s) {
  317. if(s.custom_select) {
  318. return s.inp.value ? s.inp.value : '';
  319. }
  320. if(s.inp)s = s.inp;
  321. try {
  322. if(s.selectedIndex<s.options.length) return s.options[s.selectedIndex].value;
  323. else return '';
  324. } catch(err) { return ''; /* IE fix */ }
  325. }
  326. function add_sel_options(s, list, sel_val, o_style) {
  327. if(s.custom_select) {
  328. s.set_options(list)
  329. if(sel_val) s.inp.value = sel_val;
  330. return;
  331. }
  332. if(s.inp)s = s.inp;
  333. for(var i=0, len=list.length; i<len; i++) {
  334. var o = new Option(list[i], list[i], false, (list[i]==sel_val? true : false));
  335. if(o_style) $y(o, o_style);
  336. s.options[s.options.length] = o;
  337. }
  338. }
  339. function cint(v, def) {
  340. v=v+'';
  341. v=lstrip(v, ['0']);
  342. v=parseInt(v);
  343. if(isNaN(v))v=def?def:0; return v;
  344. }
  345. function validate_email(id) { 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; }
  346. function validate_spl_chars(txt) { if(txt.search(/^[a-zA-Z0-9_\- ]*$/)==-1) return 1; else return 0; }
  347. function d2h(d) {return cint(d).toString(16);}
  348. function h2d(h) {return parseInt(h,16);}
  349. function get_darker_shade(col, factor) {
  350. if(!factor) factor = 0.5;
  351. rgb = get_rgb(col)
  352. return "" + d2h(cint(rgb[0]*factor)) + d2h(cint(rgb[1]*factor)) + d2h(cint(rgb[2]*factor));
  353. }
  354. function get_rgb(col) {
  355. if(col.length==3) { return [h2d(col[0]), h2d(col[1]), h2d(col[2])] }
  356. else if(col.length==6) { return [h2d(col.substr(0,2)), h2d(col.substr(2,2)), h2d(col.substr(4,2))] }
  357. else return [];
  358. }
  359. var $n = '\n';
  360. var $f_lab = '<div style="padding: 4px; color: #888;">Fetching...</div>';
  361. var my_title = 'Home'; var title_prefix = '';
  362. function set_title(t) {
  363. document.title = (title_prefix ? (title_prefix + ' - ') : '') + t;
  364. }
  365. function $a(parent, newtag, className, cs, innerHTML, onclick) {
  366. if(parent && parent.substr)parent = $i(parent);
  367. var c = document.createElement(newtag);
  368. if(parent)
  369. parent.appendChild(c);
  370. // if image, 3rd parameter is source
  371. if(className) {
  372. if(newtag.toLowerCase()=='img')
  373. c.src = className
  374. else
  375. c.className = className;
  376. }
  377. if(cs)$y(c,cs);
  378. if(innerHTML) c.innerHTML = innerHTML;
  379. if(onclick) c.onclick = onclick;
  380. return c;
  381. }
  382. function $a_input(p, in_type, attributes, cs) {
  383. if(!attributes) attributes = {};
  384. if(in_type) attributes.type = in_type
  385. if(isIE) {
  386. var s= '<input ';
  387. for(key in attributes)
  388. s+= ' ' + key + '="'+ attributes[key] + '"';
  389. s+= '>'
  390. p.innerHTML = s
  391. var o = p.childNodes[0];
  392. } else {
  393. var o = $a(p, 'input');
  394. for(key in attributes)
  395. o.setAttribute(key, attributes[key]);
  396. }
  397. if(cs)$y(o,cs);
  398. return o;
  399. }
  400. function $dh(d) {
  401. if(d && d.substr)d=$i(d);
  402. if(d && d.style.display.toLowerCase() != 'none') d.style.display = 'none';
  403. }
  404. function $ds(d) {
  405. if(d && d.substr)d=$i(d);
  406. var t = 'block';
  407. if(d && in_list(['span','img','button'], d.tagName.toLowerCase()))
  408. t = 'inline'
  409. if(d && d.style.display.toLowerCase() != t)
  410. d.style.display = t;
  411. }
  412. function $di(d) { if(d && d.substr)d=$i(d); if(d)d.style.display = 'inline'; }
  413. function $i(id) {
  414. if(!id) return null;
  415. if(id && id.appendChild)return id; // already an element
  416. return document.getElementById(id);
  417. }
  418. function $t(parent, txt) { if(parent.substr)parent = $i(parent); return parent.appendChild(document.createTextNode(txt)); }
  419. function $w(e,w) { if(e && e.style && w)e.style.width = w; }
  420. function $h(e,h) { if(e && e.style && h)e.style.height = h; }
  421. function $bg(e,w) { if(e && e.style && w)e.style.backgroundColor = w; }
  422. function $fg(e,w) { if(e && e.style && w)e.style.color = w; }
  423. function $op(e,w) { if(e && e.style && w) { set_opacity(e,w); } }
  424. function $y(ele, s) {
  425. if(ele && s) {
  426. for(var i in s) ele.style[i]=s[i];
  427. };
  428. return ele;
  429. }
  430. function $yt(tab, r, c, s) { /// set style on tables with wildcards
  431. var rmin = r; var rmax = r;
  432. if(r=='*') { rmin = 0; rmax = tab.rows.length-1; }
  433. if(r.search && r.search('-')!= -1) {
  434. r = r.split('-');
  435. rmin = cint(r[0]); rmax = cint(r[1]);
  436. }
  437. var cmin = c; var cmax = c;
  438. if(c=='*') { cmin = 0; cmax = tab.rows[0].cells.length-1; }
  439. if(c.search && c.search('-')!= -1) {
  440. c = c.split('-');
  441. rmin = cint(c[0]); rmax = cint(c[1]);
  442. }
  443. for(var ri = rmin; ri<=rmax; ri++) {
  444. for(var ci = cmin; ci<=cmax; ci++)
  445. $y($td(tab,ri,ci),s);
  446. }
  447. }
  448. // add css classes etc
  449. function set_style(txt) {
  450. var se = document.createElement('style');
  451. se.type = "text/css";
  452. if (se.styleSheet) {
  453. se.styleSheet.cssText = txt;
  454. } else {
  455. se.appendChild(document.createTextNode(txt));
  456. }
  457. document.getElementsByTagName('head')[0].appendChild(se);
  458. }
  459. // Make table
  460. function make_table(parent, nr, nc, table_width, widths, cell_style, table_style) {
  461. var t = $a(parent, 'table');
  462. t.style.borderCollapse = 'collapse';
  463. if(table_width) t.style.width = table_width;
  464. if(cell_style) t.cell_style=cell_style;
  465. for(var ri=0;ri<nr;ri++) {
  466. var r = t.insertRow(ri);
  467. for(var ci=0;ci<nc;ci++) {
  468. var c = r.insertCell(ci);
  469. if(ri==0 && widths && widths[ci]) {
  470. // set widths
  471. c.style.width = widths[ci];
  472. }
  473. if(cell_style) {
  474. for(var s in cell_style) c.style[s] = cell_style[s];
  475. }
  476. }
  477. }
  478. t.append_row = function() { return append_row(this); }
  479. if(table_style) $y(t, table_style);
  480. return t;
  481. }
  482. function append_row(t, at, style) {
  483. var r = t.insertRow(at ? at : t.rows.length);
  484. if(t.rows.length>1) {
  485. for(var i=0;i<t.rows[0].cells.length;i++) {
  486. var c = r.insertCell(i);
  487. if(style) $y(c, style);
  488. }
  489. }
  490. return r
  491. }
  492. function $td(t,r,c) {
  493. if(r<0)r=t.rows.length+r;
  494. if(c<0)c=t.rows[0].cells.length+c;
  495. return t.rows[r].cells[c];
  496. }
  497. // sum of values in a table column
  498. function $sum(t, cidx) {
  499. var s = 0;
  500. if(cidx<1)cidx = t.rows[0].cells.length + cidx;
  501. for(var ri=0; ri<t.rows.length; ri++) {
  502. var c = t.rows[ri].cells[cidx];
  503. if(c.div) s += flt(c.div.innerHTML);
  504. else if(c.value) s+= flt(c.value);
  505. else s += flt(c.innerHTML);
  506. }
  507. return s;
  508. }
  509. function objpos(obj){
  510. if(obj.substr)obj = $i(obj);
  511. var p = $(obj).offset();
  512. return {x : cint(p.left), y : cint(p.top) }
  513. }
  514. function get_screen_dims() {
  515. var d={};
  516. d.w = 0; d.h = 0;
  517. if( typeof( window.innerWidth ) == 'number' ) {
  518. //Non-IE
  519. d.w = window.innerWidth;
  520. d.h = window.innerHeight;
  521. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  522. //IE 6+ in 'standards compliant mode'
  523. d.w = document.documentElement.clientWidth;
  524. d.h = document.documentElement.clientHeight;
  525. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  526. //IE 4 compatible
  527. d.w = document.body.clientWidth;
  528. d.h = document.body.clientHeight;
  529. }
  530. return d
  531. }
  532. // get full page size
  533. function get_page_size(){
  534. if (window.innerHeight && window.scrollMaxY) {// Firefox
  535. yh = window.innerHeight + window.scrollMaxY;
  536. xh = window.innerWidth + window.scrollMaxX;
  537. } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  538. yh = document.body.scrollHeight;
  539. xh = document.body.scrollWidth;
  540. } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
  541. yh = document.body.offsetHeight;
  542. xh = document.body.offsetWidth;
  543. }
  544. r = [xh, yh];
  545. //alert( 'The height is ' + yh + ' and the width is ' + xh );
  546. return r;
  547. }
  548. // get scroll top
  549. function get_scroll_top() {
  550. var st = 0;
  551. if(document.documentElement && document.documentElement.scrollTop)
  552. st = document.documentElement.scrollTop;
  553. else if(document.body && document.body.scrollTop)
  554. st = document.body.scrollTop;
  555. return st;
  556. }
  557. function get_cookie(c) {
  558. var t=""+document.cookie;
  559. var ind=t.indexOf(c);
  560. if (ind==-1 || c=="") return "";
  561. var ind1=t.indexOf(';',ind);
  562. if (ind1==-1) ind1=t.length;
  563. return unescape(t.substring(ind+c.length+1,ind1));
  564. }
  565. // add space holder
  566. add_space_holder = function(parent,cs){
  567. if(!cs) cs = {margin:'170px 0px'}
  568. $y(space_holder_div,cs);
  569. parent.appendChild(space_holder_div);
  570. }
  571. // remove space holder
  572. remove_space_holder = function(){
  573. if(space_holder_div.parentNode)
  574. space_holder_div.parentNode.removeChild(space_holder_div);
  575. };
  576. // URL utilities
  577. wn.urllib = {
  578. // get argument from url
  579. get_arg: function(name) {
  580. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  581. var regexS = "[\\?&]"+name+"=([^&#]*)";
  582. var regex = new RegExp( regexS );
  583. var results = regex.exec( window.location.href );
  584. if( results == null )
  585. return "";
  586. else
  587. return decodeURIComponent(results[1]);
  588. },
  589. // returns url dictionary
  590. get_dict: function() {
  591. var d = {}
  592. var t = window.location.href.split('?')[1];
  593. if(!t) return d;
  594. if(t.indexOf('#')!=-1) t = t.split('#')[0];
  595. if(!t) return d;
  596. t = t.split('&');
  597. for(var i=0; i<t.length; i++) {
  598. var a = t[i].split('=');
  599. d[decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
  600. }
  601. return d;
  602. },
  603. // returns the base url with http + domain + path (-index.cgi or # or ?)
  604. get_base_url: function() {
  605. var url= window.location.href.split('#')[0].split('?')[0].split('index.cgi')[0];
  606. if(url.substr(url.length-1, 1)=='/') url = url.substr(0, url.length-1)
  607. return url
  608. },
  609. // return the relative http url for
  610. // a file upload / attachment
  611. // by file id / name
  612. get_file_url: function(file_id) {
  613. //var url = wn.urllib.get_base_url();
  614. var ac_id = locals['Control Panel']['Control Panel'].account_id;
  615. return repl('cgi-bin/getfile.cgi?name=%(fn)s&acx=%(ac)s', {fn:file_id, ac:ac_id})
  616. }
  617. }
  618. get_url_arg = wn.urllib.get_arg;
  619. get_url_dict = wn.urllib.get_dict;
  620. // set user image
  621. var user_img = {}
  622. var user_img_queue = {};
  623. var user_img_loading = [];
  624. set_user_img = function(img, username, get_latest, img_id) {
  625. function set_it(i) {
  626. if(user_img[username]=='no_img_m')
  627. i.src = 'images/ui/no_img/no_img_m.gif';
  628. else if(user_img[username]=='no_img_f')
  629. i.src = 'images/ui/no_img/no_img_f.gif'; // no image
  630. else {
  631. ac_id = locals['Control Panel']['Control Panel'].account_id;
  632. i.src = repl('cgi-bin/getfile.cgi?ac=%(ac)s&name=%(fn)s', {fn:user_img[username], ac:ac_id});
  633. }
  634. }
  635. // given
  636. if(img_id) {
  637. user_img[username] = img_id;
  638. set_it(img);
  639. return;
  640. }
  641. // from dict or load
  642. if(user_img[username] && !get_latest) {
  643. set_it(img);
  644. } else{
  645. // queue multiple request while loading
  646. if(in_list(user_img_loading,username)) {
  647. if(!user_img_queue[username])
  648. user_img_queue[username] = [];
  649. user_img_queue[username].push(img);
  650. return;
  651. }
  652. $c('webnotes.profile.get_user_img',{username:username},function(r,rt) {
  653. delete user_img_loading[user_img_loading.indexOf(username)];
  654. user_img[username] = r.message;
  655. if(user_img_queue[username]) {
  656. var q=user_img_queue[username];
  657. for(var i in q) { set_it(q[i]); }
  658. }
  659. set_it(img);
  660. }, null, 1);
  661. user_img_loading.push(username);
  662. }
  663. }