Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

571 linhas
15 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= '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='cupid-green';
  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. function addEvent(ev, fn) {
  70. if(isIE) {
  71. document.attachEvent('on'+ev, function() {
  72. fn(window.event, window.event.srcElement);
  73. });
  74. } else {
  75. document.addEventListener(ev, function(e) { fn(e, e.target); }, true);
  76. }
  77. }
  78. // item (for tabs and triggers)
  79. // ====================================
  80. $item_normal = function(ele) {
  81. $y(ele, {padding:'6px 8px',cursor:'pointer',marginRight:'8px', whiteSpace:'nowrap',overflow:'hidden',borderBottom:'1px solid #DDD'});
  82. $bg(ele,'#FFF'); $fg(ele,'#000');
  83. }
  84. $item_active = function(ele) {
  85. $bg(ele,'#FE8'); $fg(ele,'#000');
  86. }
  87. $item_selected = function(ele) {
  88. $bg(ele,'#777'); $fg(ele,'#FFF');
  89. }
  90. $item_pressed = function(ele) {
  91. $bg(ele,'#F90'); $fg(ele,'#FFF');
  92. }
  93. $item_set_working = function(ele) {
  94. if(ele.loading_img) {
  95. $di(ele.loading_img)
  96. } else {
  97. ele.disabled = 1;
  98. ele.loading_img = $a(ele.parentNode,'img','',{marginLeft:'4px',marginBottom:'-2px',display:'inline'});
  99. ele.loading_img.src = 'images/ui/button-load.gif';
  100. }
  101. }
  102. $item_done_working = function(ele) {
  103. ele.disabled = 0;
  104. if(ele.loading_img) { $dh(ele.loading_img) };
  105. }
  106. // set out of 100
  107. function set_opacity(ele, ieop) {
  108. var op = ieop / 100;
  109. if (ele.filters) { // internet explorer
  110. try {
  111. ele.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;
  112. } catch (e) {
  113. ele.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';
  114. }
  115. } else { // other browsers
  116. ele.style.opacity = op;
  117. }
  118. }
  119. // set gradient
  120. // ====================================
  121. function set_gradient(ele, from, to) {
  122. // gradient
  123. var no_gradient=0;
  124. if(isIE)no_gradient=1;
  125. if(isFF && ffversion < 3.6)no_gradient=1;
  126. if(no_gradient) {
  127. var rgb_from = get_rgb(from.substr(1)); var rgb_to = get_rgb(to.substr(1));
  128. $y(ele, {backgroundColor: '#'
  129. + d2h(rgb_to[0] + (rgb_from[0]-rgb_to[0])/2)
  130. + d2h(rgb_to[1] + (rgb_from[1]-rgb_to[1])/2)
  131. + d2h(rgb_to[2] + (rgb_from[2]-rgb_to[2])/2)});
  132. } else {
  133. $y(ele, {background: '-webkit-gradient(linear, left top, left bottom, from('+from+'), to('+to+'))'});
  134. $y(ele, {background: '-moz-linear-gradient(top, '+from+', '+to+')'});
  135. }
  136. }
  137. $gr = set_gradient;
  138. // border radius
  139. // ====================================
  140. $br = function(ele, r, corners) {
  141. if(corners) {
  142. var cl = ['top-left', 'top-right', 'bottom-right' , 'bottom-left'];
  143. for(var i=0; i<4; i++) {
  144. if(corners[i]) {
  145. $(ele).css('-moz-border-radius-'+cl[i].replace('-',''),r).css('-webkit-'+cl[i]+'-border-radius',r);
  146. }
  147. }
  148. } else {
  149. $(ele).css('-moz-border-radius',r).css('-webkit-border-radius',r).css('border-radius',r);
  150. }
  151. }
  152. $bs = function(ele, r) { $(ele).css('-moz-box-shadow',r).css('-webkit-box-shadow',r).css('box-shadow',r); }
  153. // Select
  154. // ====================================
  155. function empty_select(s) {
  156. if(s.custom_select) { s.empty(); return; }
  157. if(s.inp)s = s.inp;
  158. if(s) {
  159. var tmplen = s.length; for(var i=0;i<tmplen; i++) s.options[0] = null;
  160. }
  161. }
  162. function sel_val(s) {
  163. if(s.custom_select) {
  164. return s.inp.value ? s.inp.value : '';
  165. }
  166. if(s.inp)s = s.inp;
  167. try {
  168. if(s.selectedIndex<s.options.length) return s.options[s.selectedIndex].value;
  169. else return '';
  170. } catch(err) { return ''; /* IE fix */ }
  171. }
  172. function add_sel_options(s, list, sel_val, o_style) {
  173. if(s.custom_select) {
  174. s.set_options(list)
  175. if(sel_val) s.inp.value = sel_val;
  176. return;
  177. }
  178. if(s.inp)s = s.inp;
  179. for(var i=0, len=list.length; i<len; i++) {
  180. var o = new Option(list[i], list[i], false, (list[i]==sel_val? true : false));
  181. if(o_style) $y(o, o_style);
  182. s.options[s.options.length] = o;
  183. }
  184. }
  185. function cint(v, def) {
  186. v=v+'';
  187. v=lstrip(v, ['0']);
  188. v=parseInt(v);
  189. if(isNaN(v))v=def?def:0; return v;
  190. }
  191. 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; }
  192. function validate_spl_chars(txt) { if(txt.search(/^[a-zA-Z0-9_\- ]*$/)==-1) return 1; else return 0; }
  193. function d2h(d) {return cint(d).toString(16);}
  194. function h2d(h) {return parseInt(h,16);}
  195. function get_darker_shade(col, factor) {
  196. if(!factor) factor = 0.5;
  197. rgb = get_rgb(col)
  198. return "" + d2h(cint(rgb[0]*factor)) + d2h(cint(rgb[1]*factor)) + d2h(cint(rgb[2]*factor));
  199. }
  200. function get_rgb(col) {
  201. if(col.length==3) { return [h2d(col[0]), h2d(col[1]), h2d(col[2])] }
  202. else if(col.length==6) { return [h2d(col.substr(0,2)), h2d(col.substr(2,2)), h2d(col.substr(4,2))] }
  203. else return [];
  204. }
  205. var $n = '\n';
  206. var $f_lab = '<div style="padding: 4px; color: #888;">Fetching...</div>';
  207. var my_title = 'Home'; var title_prefix = '';
  208. function set_title(t) {
  209. document.title = (title_prefix ? (title_prefix + ' - ') : '') + t;
  210. }
  211. function $a(parent, newtag, className, cs, innerHTML, onclick) {
  212. if(parent && parent.substr)parent = $i(parent);
  213. var c = document.createElement(newtag);
  214. if(parent)
  215. parent.appendChild(c);
  216. // if image, 3rd parameter is source
  217. if(className) {
  218. if(newtag.toLowerCase()=='img')
  219. c.src = className
  220. else
  221. c.className = className;
  222. }
  223. if(cs)$y(c,cs);
  224. if(innerHTML) c.innerHTML = innerHTML;
  225. if(onclick) c.onclick = onclick;
  226. return c;
  227. }
  228. function $a_input(p, in_type, attributes, cs) {
  229. if(!attributes) attributes = {};
  230. if(in_type) attributes.type = in_type
  231. if(isIE) {
  232. var s= '<input ';
  233. for(key in attributes)
  234. s+= ' ' + key + '="'+ attributes[key] + '"';
  235. s+= '>'
  236. p.innerHTML = s
  237. var o = p.childNodes[0];
  238. } else {
  239. var o = $a(p, 'input');
  240. for(key in attributes)
  241. o.setAttribute(key, attributes[key]);
  242. }
  243. if(cs)$y(o,cs);
  244. return o;
  245. }
  246. function $dh(d) {
  247. if(d && d.substr)d=$i(d);
  248. if(d && d.style.display.toLowerCase() != 'none') d.style.display = 'none';
  249. }
  250. function $ds(d) {
  251. if(d && d.substr)d=$i(d);
  252. var t = 'block';
  253. if(d && in_list(['span','img','button'], d.tagName.toLowerCase()))
  254. t = 'inline'
  255. if(d && d.style.display.toLowerCase() != t)
  256. d.style.display = t;
  257. }
  258. function $di(d) { if(d && d.substr)d=$i(d); if(d)d.style.display = 'inline'; }
  259. function $i(id) {
  260. if(!id) return null;
  261. if(id && id.appendChild)return id; // already an element
  262. return document.getElementById(id);
  263. }
  264. function $t(parent, txt) { if(parent.substr)parent = $i(parent); return parent.appendChild(document.createTextNode(txt)); }
  265. function $w(e,w) { if(e && e.style && w)e.style.width = w; }
  266. function $h(e,h) { if(e && e.style && h)e.style.height = h; }
  267. function $bg(e,w) { if(e && e.style && w)e.style.backgroundColor = w; }
  268. function $fg(e,w) { if(e && e.style && w)e.style.color = w; }
  269. function $op(e,w) { if(e && e.style && w) { set_opacity(e,w); } }
  270. function $y(ele, s) {
  271. if(ele && s) {
  272. for(var i in s) ele.style[i]=s[i];
  273. };
  274. return ele;
  275. }
  276. function $yt(tab, r, c, s) { /// set style on tables with wildcards
  277. var rmin = r; var rmax = r;
  278. if(r=='*') { rmin = 0; rmax = tab.rows.length-1; }
  279. if(r.search && r.search('-')!= -1) {
  280. r = r.split('-');
  281. rmin = cint(r[0]); rmax = cint(r[1]);
  282. }
  283. var cmin = c; var cmax = c;
  284. if(c=='*') { cmin = 0; cmax = tab.rows[0].cells.length-1; }
  285. if(c.search && c.search('-')!= -1) {
  286. c = c.split('-');
  287. rmin = cint(c[0]); rmax = cint(c[1]);
  288. }
  289. for(var ri = rmin; ri<=rmax; ri++) {
  290. for(var ci = cmin; ci<=cmax; ci++)
  291. $y($td(tab,ri,ci),s);
  292. }
  293. }
  294. // add css classes etc
  295. function set_style(txt) {
  296. var se = document.createElement('style');
  297. se.type = "text/css";
  298. if (se.styleSheet) {
  299. se.styleSheet.cssText = txt;
  300. } else {
  301. se.appendChild(document.createTextNode(txt));
  302. }
  303. document.getElementsByTagName('head')[0].appendChild(se);
  304. }
  305. // Make table
  306. function make_table(parent, nr, nc, table_width, widths, cell_style, table_style) {
  307. var t = $a(parent, 'table');
  308. t.style.borderCollapse = 'collapse';
  309. if(table_width) t.style.width = table_width;
  310. if(cell_style) t.cell_style=cell_style;
  311. for(var ri=0;ri<nr;ri++) {
  312. var r = t.insertRow(ri);
  313. for(var ci=0;ci<nc;ci++) {
  314. var c = r.insertCell(ci);
  315. if(ri==0 && widths && widths[ci]) {
  316. // set widths
  317. c.style.width = widths[ci];
  318. }
  319. if(cell_style) {
  320. for(var s in cell_style) c.style[s] = cell_style[s];
  321. }
  322. }
  323. }
  324. t.append_row = function() { return append_row(this); }
  325. if(table_style) $y(t, table_style);
  326. return t;
  327. }
  328. function append_row(t, at, style) {
  329. var r = t.insertRow(at ? at : t.rows.length);
  330. if(t.rows.length>1) {
  331. for(var i=0;i<t.rows[0].cells.length;i++) {
  332. var c = r.insertCell(i);
  333. if(style) $y(c, style);
  334. }
  335. }
  336. return r
  337. }
  338. function $td(t,r,c) {
  339. if(r<0)r=t.rows.length+r;
  340. if(c<0)c=t.rows[0].cells.length+c;
  341. return t.rows[r].cells[c];
  342. }
  343. // sum of values in a table column
  344. function $sum(t, cidx) {
  345. var s = 0;
  346. if(cidx<1)cidx = t.rows[0].cells.length + cidx;
  347. for(var ri=0; ri<t.rows.length; ri++) {
  348. var c = t.rows[ri].cells[cidx];
  349. if(c.div) s += flt(c.div.innerHTML);
  350. else if(c.value) s+= flt(c.value);
  351. else s += flt(c.innerHTML);
  352. }
  353. return s;
  354. }
  355. function objpos(obj){
  356. if(obj.substr)obj = $i(obj);
  357. var p = $(obj).offset();
  358. return {x : cint(p.left), y : cint(p.top) }
  359. }
  360. function get_screen_dims() {
  361. var d={};
  362. d.w = 0; d.h = 0;
  363. if( typeof( window.innerWidth ) == 'number' ) {
  364. //Non-IE
  365. d.w = window.innerWidth;
  366. d.h = window.innerHeight;
  367. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  368. //IE 6+ in 'standards compliant mode'
  369. d.w = document.documentElement.clientWidth;
  370. d.h = document.documentElement.clientHeight;
  371. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  372. //IE 4 compatible
  373. d.w = document.body.clientWidth;
  374. d.h = document.body.clientHeight;
  375. }
  376. return d
  377. }
  378. // get full page size
  379. function get_page_size(){
  380. return [$(document).height(), $(document).width()];
  381. }
  382. // get scroll top
  383. function get_scroll_top() {
  384. var st = 0;
  385. if(document.documentElement && document.documentElement.scrollTop)
  386. st = document.documentElement.scrollTop;
  387. else if(document.body && document.body.scrollTop)
  388. st = document.body.scrollTop;
  389. return st;
  390. }
  391. function get_cookie(c) {
  392. var t=""+document.cookie;
  393. var ind=t.indexOf(c);
  394. if (ind==-1 || c=="") return "";
  395. var ind1=t.indexOf(';',ind);
  396. if (ind1==-1) ind1=t.length;
  397. return unescape(t.substring(ind+c.length+1,ind1));
  398. }
  399. // add space holder
  400. add_space_holder = function(parent,cs){
  401. if(!cs) cs = {margin:'170px 0px'}
  402. $y(space_holder_div,cs);
  403. parent.appendChild(space_holder_div);
  404. }
  405. // remove space holder
  406. remove_space_holder = function(){
  407. if(space_holder_div.parentNode)
  408. space_holder_div.parentNode.removeChild(space_holder_div);
  409. };
  410. // URL utilities
  411. wn.urllib = {
  412. // get argument from url
  413. get_arg: function(name) {
  414. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  415. var regexS = "[\\?&]"+name+"=([^&#]*)";
  416. var regex = new RegExp( regexS );
  417. var results = regex.exec( window.location.href );
  418. if( results == null )
  419. return "";
  420. else
  421. return decodeURIComponent(results[1]);
  422. },
  423. // returns url dictionary
  424. get_dict: function() {
  425. var d = {}
  426. var t = window.location.href.split('?')[1];
  427. if(!t) return d;
  428. if(t.indexOf('#')!=-1) t = t.split('#')[0];
  429. if(!t) return d;
  430. t = t.split('&');
  431. for(var i=0; i<t.length; i++) {
  432. var a = t[i].split('=');
  433. d[decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
  434. }
  435. return d;
  436. },
  437. // returns the base url with http + domain + path (-index.cgi or # or ?)
  438. get_base_url: function() {
  439. var url= window.location.href.split('#')[0].split('?')[0].split('index.cgi')[0];
  440. if(url.substr(url.length-1, 1)=='/') url = url.substr(0, url.length-1)
  441. return url
  442. },
  443. // return the relative http url for
  444. // a file upload / attachment
  445. // by file id / name
  446. get_file_url: function(file_id) {
  447. //var url = wn.urllib.get_base_url();
  448. var ac_id = locals['Control Panel']['Control Panel'].account_id;
  449. return repl('cgi-bin/getfile.cgi?name=%(fn)s&acx=%(ac)s', {fn:file_id, ac:ac_id})
  450. }
  451. }
  452. get_url_arg = wn.urllib.get_arg;
  453. get_url_dict = wn.urllib.get_dict;
  454. // set user image
  455. var user_img = {}
  456. var user_img_queue = {};
  457. var user_img_loading = [];
  458. set_user_img = function(img, username, get_latest, img_id) {
  459. function set_it(i) {
  460. if(user_img[username]=='no_img_m')
  461. i.src = 'images/ui/no_img/no_img_m.gif';
  462. else if(user_img[username]=='no_img_f')
  463. i.src = 'images/ui/no_img/no_img_f.gif'; // no image
  464. else {
  465. ac_id = locals['Control Panel']['Control Panel'].account_id;
  466. i.src = repl('cgi-bin/getfile.cgi?ac=%(ac)s&name=%(fn)s', {fn:user_img[username], ac:ac_id});
  467. }
  468. }
  469. // given
  470. if(img_id) {
  471. user_img[username] = img_id;
  472. set_it(img);
  473. return;
  474. }
  475. // from dict or load
  476. if(user_img[username] && !get_latest) {
  477. set_it(img);
  478. } else{
  479. // queue multiple request while loading
  480. if(in_list(user_img_loading,username)) {
  481. if(!user_img_queue[username])
  482. user_img_queue[username] = [];
  483. user_img_queue[username].push(img);
  484. return;
  485. }
  486. $c('webnotes.profile.get_user_img',{username:username},function(r,rt) {
  487. delete user_img_loading[user_img_loading.indexOf(username)];
  488. user_img[username] = r.message;
  489. if(user_img_queue[username]) {
  490. var q=user_img_queue[username];
  491. for(var i in q) { set_it(q[i]); }
  492. }
  493. set_it(img);
  494. }, null, 1);
  495. user_img_loading.push(username);
  496. }
  497. }