You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 11 година
пре 13 година
пре 12 година
пре 14 година
пре 13 година
пре 14 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. // short hand functions for setting up
  4. // rich text editor tinymce
  5. wn.tinymce = {
  6. add_simple: function(ele, height) {
  7. if(ele.myid) {
  8. tinyMCE.execCommand( 'mceAddControl', true, ele.myid);
  9. return;
  10. }
  11. // no create
  12. ele.myid = wn.dom.set_unique_id(ele);
  13. $(ele).tinymce({
  14. // Location of TinyMCE script
  15. script_url : 'js/lib/tiny_mce_3.5.7/tiny_mce.js',
  16. height: height ? height : '200px',
  17. // General options
  18. theme : "advanced",
  19. theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,link,unlink,forecolor,backcolor,code,",
  20. theme_advanced_buttons2 : "",
  21. theme_advanced_buttons3 : "",
  22. theme_advanced_toolbar_location : "top",
  23. theme_advanced_toolbar_align : "left",
  24. theme_advanced_path : false,
  25. theme_advanced_resizing : false
  26. });
  27. },
  28. remove: function(ele) {
  29. tinyMCE.execCommand( 'mceRemoveControl', true, ele.myid);
  30. },
  31. get_value: function(ele) {
  32. return tinymce.get(ele.myid).getContent();
  33. }
  34. }
  35. wn.ele = {
  36. link: function(args) {
  37. var span = $a(args.parent, 'span', 'link_type', args.style);
  38. span.loading_img = $a(args.parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  39. span.loading_img.src= 'assets/webnotes/images/ui/button-load.gif';
  40. span.innerHTML = args.label;
  41. span.user_onclick = args.onclick;
  42. span.onclick = function() { if(!this.disabled) this.user_onclick(this); }
  43. // working
  44. span.set_working = function() {
  45. this.disabled = 1;
  46. $di(this.loading_img);
  47. }
  48. span.done_working = function() {
  49. this.disabled = 0;
  50. $dh(this.loading_img);
  51. }
  52. return span;
  53. }
  54. }
  55. function $ln(parent, label, onclick, style) {
  56. return wn.ele.link({parent:parent, label:label, onclick:onclick, style:style})
  57. }
  58. function $btn(parent, label, onclick, style, css_class, is_ajax) {
  59. if(css_class==='green') css_class='btn-info';
  60. return new wn.ui.Button(
  61. {parent:parent, label:label, onclick:onclick, style:style, is_ajax: is_ajax, css_class: css_class}
  62. ).btn;
  63. }
  64. // item (for tabs and triggers)
  65. // ====================================
  66. $item_normal = function(ele) {
  67. $y(ele, {padding:'6px 8px',cursor:'pointer',marginRight:'8px', whiteSpace:'nowrap',overflow:'hidden',borderBottom:'1px solid #DDD'});
  68. $bg(ele,'#FFF'); $fg(ele,'#000');
  69. }
  70. $item_active = function(ele) {
  71. $bg(ele,'#FE8'); $fg(ele,'#000');
  72. }
  73. $item_selected = function(ele) {
  74. $bg(ele,'#777'); $fg(ele,'#FFF');
  75. }
  76. $item_pressed = function(ele) {
  77. $bg(ele,'#F90'); $fg(ele,'#FFF');
  78. };
  79. // set out of 100
  80. function set_opacity(ele, ieop) {
  81. var op = ieop / 100;
  82. if (ele.filters) { // internet explorer
  83. try {
  84. ele.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;
  85. } catch (e) {
  86. ele.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';
  87. }
  88. } else { // other browsers
  89. ele.style.opacity = op;
  90. }
  91. }
  92. // border radius
  93. // ====================================
  94. $br = function(ele, r, corners) {
  95. if(corners) {
  96. var cl = ['top-left', 'top-right', 'bottom-right' , 'bottom-left'];
  97. for(var i=0; i<4; i++) {
  98. if(corners[i]) {
  99. $(ele).css('-moz-border-radius-'+cl[i].replace('-',''),r).css('-webkit-'+cl[i]+'-border-radius',r);
  100. }
  101. }
  102. } else {
  103. $(ele).css('-moz-border-radius',r).css('-webkit-border-radius',r).css('border-radius',r);
  104. }
  105. }
  106. $bs = function(ele, r) { $(ele).css('-moz-box-shadow',r).css('-webkit-box-shadow',r).css('box-shadow',r); }
  107. function empty_select(s) {
  108. if(s.custom_select) { s.empty(); return; }
  109. if(s.inp)s = s.inp;
  110. if(s) {
  111. var tmplen = s.length; for(var i=0;i<tmplen; i++) s.options[0] = null;
  112. }
  113. }
  114. function sel_val(s) {
  115. if(s.custom_select) {
  116. return s.inp.value ? s.inp.value : '';
  117. }
  118. if(s.inp)s = s.inp;
  119. try {
  120. if(s.selectedIndex<s.options.length) return s.options[s.selectedIndex].value;
  121. else return '';
  122. } catch(err) { return ''; /* IE fix */ }
  123. }
  124. function add_sel_options(s, list, sel_val, o_style) {
  125. if(s.custom_select) {
  126. s.set_options(list)
  127. if(sel_val) s.inp.value = sel_val;
  128. return;
  129. }
  130. if(s.inp)s = s.inp;
  131. for(var i=0, len=list.length; i<len; i++) {
  132. var o = new Option(list[i], list[i], false, (list[i]==sel_val? true : false));
  133. if(o_style) $y(o, o_style);
  134. s.options[s.options.length] = o;
  135. }
  136. }
  137. var $n = '\n';
  138. function set_title(t) {
  139. document.title = (wn.title_prefix ? (wn.title_prefix + ' - ') : '') + t;
  140. }
  141. function $a(parent, newtag, className, cs, innerHTML, onclick) {
  142. if(parent && parent.substr)parent = $i(parent);
  143. var c = document.createElement(newtag);
  144. if(parent)
  145. parent.appendChild(c);
  146. // if image, 3rd parameter is source
  147. if(className) {
  148. if(newtag.toLowerCase()=='img')
  149. c.src = className
  150. else
  151. c.className = className;
  152. }
  153. if(cs)$y(c,cs);
  154. if(innerHTML) c.innerHTML = innerHTML;
  155. if(onclick) c.onclick = onclick;
  156. return c;
  157. }
  158. function $a_input(p, in_type, attributes, cs) {
  159. if(!attributes) attributes = {};
  160. var $input = $(p).append('<input type="'+ in_type +'">').find('input:last');
  161. for(key in attributes)
  162. $input.attr(key, attributes[key]);
  163. var input = $input.get(0);
  164. if(cs)
  165. $y(input,cs);
  166. return input;
  167. }
  168. function $dh(d) {
  169. if(d && d.substr)d=$i(d);
  170. if(d && d.style.display.toLowerCase() != 'none') d.style.display = 'none';
  171. }
  172. function $ds(d) {
  173. if(d && d.substr)d=$i(d);
  174. var t = 'block';
  175. if(d && in_list(['span','img','button'], d.tagName.toLowerCase()))
  176. t = 'inline'
  177. if(d && d.style.display.toLowerCase() != t)
  178. d.style.display = t;
  179. }
  180. function $di(d) { if(d && d.substr)d=$i(d); if(d)d.style.display = 'inline'; }
  181. function $i(id) {
  182. if(!id) return null;
  183. if(id && id.appendChild)return id; // already an element
  184. return document.getElementById(id);
  185. }
  186. function $w(e,w) { if(e && e.style && w)e.style.width = w; }
  187. function $h(e,h) { if(e && e.style && h)e.style.height = h; }
  188. function $bg(e,w) { if(e && e.style && w)e.style.backgroundColor = w; }
  189. function $y(ele, s) {
  190. if(ele && s) {
  191. for(var i in s) ele.style[i]=s[i];
  192. };
  193. return ele;
  194. }
  195. function $yt(tab, r, c, s) { /// set style on tables with wildcards
  196. var rmin = r; var rmax = r;
  197. if(r=='*') { rmin = 0; rmax = tab.rows.length-1; }
  198. if(r.search && r.search('-')!= -1) {
  199. r = r.split('-');
  200. rmin = cint(r[0]); rmax = cint(r[1]);
  201. }
  202. var cmin = c; var cmax = c;
  203. if(c=='*') { cmin = 0; cmax = tab.rows[0].cells.length-1; }
  204. if(c.search && c.search('-')!= -1) {
  205. c = c.split('-');
  206. rmin = cint(c[0]); rmax = cint(c[1]);
  207. }
  208. for(var ri = rmin; ri<=rmax; ri++) {
  209. for(var ci = cmin; ci<=cmax; ci++)
  210. $y($td(tab,ri,ci),s);
  211. }
  212. }
  213. // Make table
  214. function make_table(parent, nr, nc, table_width, widths, cell_style, table_style) {
  215. var t = $a(parent, 'table');
  216. t.style.borderCollapse = 'collapse';
  217. if(table_width) t.style.width = table_width;
  218. if(cell_style) t.cell_style=cell_style;
  219. for(var ri=0;ri<nr;ri++) {
  220. var r = t.insertRow(ri);
  221. for(var ci=0;ci<nc;ci++) {
  222. var c = r.insertCell(ci);
  223. if(ri==0 && widths && widths[ci]) {
  224. // set widths
  225. c.style.width = widths[ci];
  226. }
  227. if(cell_style) {
  228. for(var s in cell_style) c.style[s] = cell_style[s];
  229. }
  230. }
  231. }
  232. t.append_row = function() { return append_row(this); }
  233. if(table_style) $y(t, table_style);
  234. return t;
  235. }
  236. function append_row(t, at, style) {
  237. var r = t.insertRow(at ? at : t.rows.length);
  238. if(t.rows.length>1) {
  239. for(var i=0;i<t.rows[0].cells.length;i++) {
  240. var c = r.insertCell(i);
  241. if(style) $y(c, style);
  242. }
  243. }
  244. return r
  245. }
  246. function $td(t,r,c) {
  247. if(r<0)r=t.rows.length+r;
  248. if(c<0)c=t.rows[0].cells.length+c;
  249. return t.rows[r].cells[c];
  250. }
  251. // URL utilities
  252. wn.urllib = {
  253. // get argument from url
  254. get_arg: function(name) {
  255. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  256. var regexS = "[\\?&]"+name+"=([^&#]*)";
  257. var regex = new RegExp( regexS );
  258. var results = regex.exec( window.location.href );
  259. if( results == null )
  260. return "";
  261. else
  262. return decodeURIComponent(results[1]);
  263. },
  264. // returns url dictionary
  265. get_dict: function() {
  266. var d = {}
  267. var t = window.location.href.split('?')[1];
  268. if(!t) return d;
  269. if(t.indexOf('#')!=-1) t = t.split('#')[0];
  270. if(!t) return d;
  271. t = t.split('&');
  272. for(var i=0; i<t.length; i++) {
  273. var a = t[i].split('=');
  274. d[decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
  275. }
  276. return d;
  277. },
  278. // returns the base url with http + domain + path (-index.cgi or # or ?)
  279. get_base_url: function() {
  280. var url= window.location.href.split('#')[0].split('?')[0].split('app.html')[0];
  281. if(url.substr(url.length-1, 1)=='/') url = url.substr(0, url.length-1)
  282. return url
  283. }
  284. }
  285. get_url_arg = wn.urllib.get_arg;
  286. get_url_dict = wn.urllib.get_dict;