editor.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. module( 'ui.editor' );
  2. //test('图片浮层',function(){
  3. // var ue1 = new baidu.editor.ui.Editor({theme:'default'});
  4. // var div = document.createElement("div");
  5. // document.body.appendChild(div);
  6. // ue1.render(div);
  7. // stop();
  8. // ue1.ready(function(){
  9. // editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0001.gif', width:50, height:51} );
  10. // });
  11. //});
  12. test('拖拽', function(){
  13. var sc = document.createElement("script");
  14. sc.id="sc";
  15. sc.type = "text/plain";
  16. document.body.appendChild(sc);
  17. var ue = new UE.ui.Editor({'autoHeightEnabled':false,'autoFloatEnabled':false,'scaleEnabled':true});
  18. ue.render('sc');
  19. stop();
  20. ue.ready(function(){
  21. var me =this;
  22. var offset = 100;
  23. setTimeout(function(){
  24. //保存现有的编辑器宽,高
  25. var editorWidth = $(this.document.getElementById(me.ui.id)).css('width');
  26. var editorHeight = $(this.document.getElementById(me.ui.id)).css('height');
  27. //取得拖拽的元素
  28. var scaleDiv = this.document.getElementById(me.ui.id+'_scale');
  29. //从拖拽元素的右下角开始,拖拽到向下,向右20px
  30. var mouseX = $(scaleDiv).offset().left + parseInt($(scaleDiv).css('width'));//+editorBorderHeight;
  31. var mouseY = $(scaleDiv).offset().top + parseInt($(scaleDiv).css('height'));//+editorBorderWidth;
  32. ua.dragto(scaleDiv,{startX:mouseX,startY:mouseY,endX:mouseX+offset,endY:mouseY+offset});
  33. setTimeout(function(){
  34. //取编辑器的边框
  35. var editorBorderWidth = parseInt($(this.document.getElementById(me.ui.id)).css('border-left-width'))+parseInt($(this.document.getElementById(me.ui.id)).css('border-right-width'));
  36. var editorBorderHeight = parseInt($(this.document.getElementById(me.ui.id)).css('border-top-width'))+parseInt($(this.document.getElementById(me.ui.id)).css('border-bottom-width'));
  37. var border = me.options.theme=='default'?1:0;
  38. var bd = parseInt(editorHeight) + offset - 2 -editorBorderWidth + border;
  39. var height = parseInt($(this.document.getElementById(me.ui.id)).css('height'));
  40. equal(parseInt($(this.document.getElementById(me.ui.id)).css('width')),parseInt(editorWidth) + offset - 2 -editorBorderHeight + border,'宽');
  41. ok(height==bd||height==bd-1,'高'+height);
  42. setTimeout(function () {
  43. UE.delEditor('sc');
  44. sc = document.getElementById('sc');
  45. sc && sc.parentNode.removeChild(sc);
  46. start();
  47. }, 100);
  48. },1800);
  49. },100);
  50. });
  51. });
  52. test('编辑器皮肤',function(){
  53. if(ua.browser.ie<8 && ua.browser.ie>0) return 0;
  54. var ue1 = new baidu.editor.ui.Editor({theme:'default'});
  55. var sc1 = document.createElement("script");
  56. sc1.id="sc1";
  57. document.body.appendChild(sc1);
  58. ue1.render(sc1);
  59. stop();
  60. ue1.ready(function(){
  61. var id = document.getElementById('sc1').firstChild.id;
  62. equal(document.getElementById('sc1').firstChild.className,'edui-editor edui-default','第一个editor的classname');
  63. equal(document.getElementById(id+'_toolbarbox').className,'edui-editor-toolbarbox edui-default','第一个editor toolbar的classname');
  64. equal(document.getElementById(id+'_iframeholder').className,'edui-editor-iframeholder edui-default','第一个editor iframeholder的classname');
  65. equal(document.getElementById(id+'_bottombar').className,'edui-editor-bottomContainer edui-default','第一个editor bottombar的classname');
  66. equal(document.getElementById(id+'_scalelayer').className,'edui-default','第一个editor scalelayer的classname');
  67. sc1 = document.getElementById('sc1');
  68. sc1.parentNode.removeChild(sc1);
  69. var ue2 = new baidu.editor.ui.Editor({theme:'modern'});
  70. var sc2 = document.createElement("script");
  71. sc2.id="sc2";
  72. document.body.appendChild(sc2);
  73. ue2.render('sc2');
  74. ue2.ready(function(){
  75. id = document.getElementById('sc2').firstChild.id;
  76. equal(document.getElementById('sc2').firstChild.className,'edui-editor edui-modern','第二个editor的classname');
  77. equal(document.getElementById(id+'_toolbarbox').className,'edui-editor-toolbarbox edui-modern','第二个editor toolbar的classname');
  78. equal(document.getElementById(id+'_iframeholder').className,'edui-editor-iframeholder edui-modern','第二个editor iframeholder的classname');
  79. equal(document.getElementById(id+'_bottombar').className,'edui-editor-bottomContainer edui-modern','第二个editor bottombar的classname');
  80. equal(document.getElementById(id+'_scalelayer').className,'edui-modern','第二个editor scalelayer的classname');
  81. sc2 = document.getElementById('sc2');
  82. sc2.parentNode.removeChild(sc2);
  83. start();
  84. });
  85. });
  86. });
  87. test( '判断render有内容时,显示render内容(script)', function() {
  88. var ue3 = new baidu.editor.ui.Editor();
  89. var sc3 = document.createElement("script");
  90. sc3.id="sc3";
  91. sc3.type="text/plain";
  92. // if(sc3.text)
  93. sc3.text= 'renderinnerhtml';
  94. // else
  95. // sc3.textContent='renderinnerhtml';
  96. document.body.appendChild(sc3);
  97. ue3.render('sc3');
  98. stop();
  99. ue3.ready(function(){
  100. equal(ue3.body.firstChild.innerHTML.toLowerCase(),"renderinnerhtml",'标签有内容,显示标签内容');
  101. sc3 = document.getElementById('sc3');
  102. sc3.parentNode.removeChild(sc3);
  103. start();
  104. });
  105. } );
  106. test( 'render没有内容时,显示initialContent', function() {
  107. var ue4 = new baidu.editor.ui.Editor({initialContent:'<br>'});
  108. var sc4 = document.createElement("script");
  109. sc4.id="sc4";
  110. document.body.appendChild(sc4);
  111. ue4.render(sc4);
  112. stop();
  113. ue4.ready(function(){
  114. equal(ue4.body.firstChild.innerHTML.toLowerCase(),ue4.options.initialContent.toLowerCase(),'标签没有内容,显示initialContent');
  115. sc4 = document.getElementById('sc4');
  116. sc4.parentNode.removeChild(sc4);
  117. start();
  118. });
  119. } );
  120. test('判断dialogs对象名包含"Dialog"字符', function(){
  121. var ue5 = new baidu.editor.ui.Editor();
  122. var sc5 = document.createElement("script");
  123. sc5.id="sc5";
  124. document.body.appendChild(sc5);
  125. ue5.render(sc5);
  126. stop();
  127. ue5.ready(function(){
  128. var array=ue5.ui._dialogs;
  129. for(var p in array){
  130. ok(p.indexOf('Dialog')!=-1, p);
  131. }
  132. sc5 = document.getElementById('sc5');
  133. sc5.parentNode.removeChild(sc5);
  134. start();
  135. });
  136. });
  137. test('getEditor--delEditor',function(){
  138. var ue7 = UE.ui.Editor();
  139. var div = document.createElement('div');
  140. div.id='editor2';
  141. document.body.appendChild(div);
  142. ue7.render('editor2');
  143. ue7.ready(function(){
  144. var ue8=UE.getEditor('editor2');
  145. equal(ue8.uid,ue7.uid);
  146. // UE.delEditor('editor2');
  147. // equal(document.getElementById('editor1').tagName.toLowerCase(),'textarea');
  148. });
  149. })
  150. //test('多层div 全屏',function(){
  151. // var div1 = document.createElement('div');
  152. // document.body.appendChild(div1);
  153. // div1.id = 'div1';
  154. // div1.innerHTML = '<div style="position: relative;top:50px""></div>';
  155. // div1.firstChild.innerHTML='<div style="position:absolute;left:100px;width:500px;height:100px">';
  156. // var div2 = div1.firstChild.firstChild;
  157. // var ue6 = new baidu.editor.ui.Editor({autoFloatEnabled:false});
  158. // ue6.render(div2);
  159. // stop();
  160. // ue6.ready(function(){
  161. // var me = document.getElementById(ue6.ui.id);
  162. // var left = $(me).offset().left;
  163. // var top = $(me).offset().top;
  164. // ue6.ui.setFullScreen( true );
  165. // setTimeout(function(){
  166. // ue6.ui.setFullScreen( false );
  167. // setTimeout(function(){
  168. // me = document.getElementById(ue6.ui.id);
  169. // ok(left==$(me).offset().left,'left不变'+$(me).offset().left);
  170. // ok(top==$(me).offset().top,'top不变'+$(me).offset().top);
  171. // ue6.focus();
  172. // ua.checkResult(ue6.selection.getRange(), ue6.body.firstChild.firstChild, ue6.body.firstChild.firstChild, 0, 0, 1);
  173. // me = document.getElementById(ue6.ui.id);
  174. // me.parentNode.removeChild(me);
  175. // start();
  176. // },50);
  177. // },50);
  178. // });
  179. //})