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.

button.js 1.2 KiB

13 vuotta sitten
14 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. wn.ui.Button = function(args) {
  2. var me = this;
  3. $.extend(this, {
  4. make: function() {
  5. me.btn = wn.dom.add(args.parent, 'button', 'btn btn-small ' + (args.css_class || ''));
  6. me.btn.args = args;
  7. // ajax loading
  8. me.loading_img = wn.dom.add(me.btn.args.parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  9. me.loading_img.src= 'lib/images/ui/button-load.gif';
  10. if(args.is_ajax) wn.dom.css(me.btn,{marginRight:'24px'});
  11. // label
  12. me.btn.innerHTML = args.label;
  13. // onclick
  14. me.btn.user_onclick = args.onclick;
  15. $(me.btn).bind('click', function() {
  16. if(!this.disabled && this.user_onclick)
  17. this.user_onclick(this);
  18. })
  19. // bc
  20. me.btn.set_working = me.set_working;
  21. me.btn.done_working = me.done_working;
  22. // style
  23. if(me.btn.args.style)
  24. wn.dom.css(me.btn, args.style);
  25. },
  26. set_working: function() {
  27. me.btn.disabled = 'disabled';
  28. if(me.btn.args.is_ajax) {
  29. $(me.btn).css('margin-right', '0px');
  30. }
  31. wn.dom.show(me.loading_img, 'inline');
  32. },
  33. done_working: function() {
  34. me.btn.disabled = false;
  35. if(me.btn.args.is_ajax) {
  36. $(me.btn).css('margin-right', '24px');
  37. }
  38. wn.dom.hide(me.loading_img);
  39. }
  40. });
  41. this.make();
  42. }