tablepicker.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ///import core
  2. ///import uicore
  3. (function (){
  4. var utils = baidu.editor.utils,
  5. uiUtils = baidu.editor.ui.uiUtils,
  6. UIBase = baidu.editor.ui.UIBase;
  7. var TablePicker = baidu.editor.ui.TablePicker = function (options){
  8. this.initOptions(options);
  9. this.initTablePicker();
  10. };
  11. TablePicker.prototype = {
  12. defaultNumRows: 10,
  13. defaultNumCols: 10,
  14. maxNumRows: 20,
  15. maxNumCols: 20,
  16. numRows: 10,
  17. numCols: 10,
  18. lengthOfCellSide: 22,
  19. initTablePicker: function (){
  20. this.initUIBase();
  21. },
  22. getHtmlTpl: function (){
  23. var me = this;
  24. return '<div id="##" class="edui-tablepicker %%">' +
  25. '<div class="edui-tablepicker-body">' +
  26. '<div class="edui-infoarea">' +
  27. '<span id="##_label" class="edui-label"></span>' +
  28. '</div>' +
  29. '<div class="edui-pickarea"' +
  30. ' onmousemove="$$._onMouseMove(event, this);"' +
  31. ' onmouseover="$$._onMouseOver(event, this);"' +
  32. ' onmouseout="$$._onMouseOut(event, this);"' +
  33. ' onclick="$$._onClick(event, this);"' +
  34. '>' +
  35. '<div id="##_overlay" class="edui-overlay"></div>' +
  36. '</div>' +
  37. '</div>' +
  38. '</div>';
  39. },
  40. _UIBase_render: UIBase.prototype.render,
  41. render: function (holder){
  42. this._UIBase_render(holder);
  43. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_row")+' x 0'+this.editor.getLang("t_col");
  44. },
  45. _track: function (numCols, numRows){
  46. var style = this.getDom('overlay').style;
  47. var sideLen = this.lengthOfCellSide;
  48. style.width = numCols * sideLen + 'px';
  49. style.height = numRows * sideLen + 'px';
  50. var label = this.getDom('label');
  51. label.innerHTML = numCols +this.editor.getLang("t_col")+' x ' + numRows + this.editor.getLang("t_row");
  52. this.numCols = numCols;
  53. this.numRows = numRows;
  54. },
  55. _onMouseOver: function (evt, el){
  56. var rel = evt.relatedTarget || evt.fromElement;
  57. if (!uiUtils.contains(el, rel) && el !== rel) {
  58. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  59. this.getDom('overlay').style.visibility = '';
  60. }
  61. },
  62. _onMouseOut: function (evt, el){
  63. var rel = evt.relatedTarget || evt.toElement;
  64. if (!uiUtils.contains(el, rel) && el !== rel) {
  65. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  66. this.getDom('overlay').style.visibility = 'hidden';
  67. }
  68. },
  69. _onMouseMove: function (evt, el){
  70. var style = this.getDom('overlay').style;
  71. var offset = uiUtils.getEventOffset(evt);
  72. var sideLen = this.lengthOfCellSide;
  73. var numCols = Math.ceil(offset.left / sideLen);
  74. var numRows = Math.ceil(offset.top / sideLen);
  75. this._track(numCols, numRows);
  76. },
  77. _onClick: function (){
  78. this.fireEvent('picktable', this.numCols, this.numRows);
  79. }
  80. };
  81. utils.inherits(TablePicker, UIBase);
  82. })();