modx.button.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Overrides native Ext.Button behavior to use FontAwesome icons
  3. *
  4. * @class MODx.Button
  5. * @extends Ext.Button
  6. * @constructor
  7. * @param {Object} config An object of options.
  8. * @xtype modx-button
  9. */
  10. MODx.Button = function(config) {
  11. config = config || {};
  12. if(config.iconCls){
  13. config.ctCls = config.cls + ' ' + config.ctCls
  14. config.cls = config.iconCls
  15. config.iconCls = ''
  16. }
  17. Ext.applyIf(config,{
  18. template: new Ext.XTemplate('<span id="{4}" class="x-btn icon {1} {3}" unselectable="on">'+
  19. ' <i class="{2}">'+
  20. // ' <button type="{0}"></button>'+
  21. ' </i>'+
  22. '</span>').compile()
  23. });
  24. MODx.Button.superclass.constructor.call(this,config);
  25. };
  26. Ext.extend(MODx.Button,Ext.Button,{
  27. // private
  28. onRender : function(ct, position){
  29. if(!this.template){
  30. if(!Ext.Button.buttonTemplate){
  31. // hideous table template
  32. Ext.Button.buttonTemplate = new Ext.Template(
  33. '<span id="{4}" class="x-btn icon {1} {3}" unselectable="on">'+
  34. ' <i class="{iconCls}"></i>'+
  35. '</span>');
  36. Ext.Button.buttonTemplate.compile();
  37. }
  38. this.template = Ext.Button.buttonTemplate;
  39. }
  40. var btn, targs = this.getTemplateArgs();
  41. targs.iconCls = this.iconCls;
  42. if(position){
  43. btn = this.template.insertBefore(position, targs, true);
  44. }else{
  45. btn = this.template.append(ct, targs, true);
  46. }
  47. /**
  48. * An {@link Ext.Element Element} encapsulating the Button's clickable element. By default,
  49. * this references a <tt>&lt;button&gt;</tt> element. Read only.
  50. * @type Ext.Element
  51. * @property btnEl
  52. */
  53. this.btnEl = btn.child('i');
  54. this.mon(this.btnEl, {
  55. scope: this,
  56. focus: this.onFocus,
  57. blur: this.onBlur
  58. });
  59. this.initButtonEl(btn, this.btnEl);
  60. Ext.ButtonToggleMgr.register(this);
  61. },
  62. });
  63. Ext.reg('modx-button',MODx.Button);