module( "plugins.directionality" ); //1 notblockelement&&collapsed=false test( '非块元素,不闭合', function() { var editor = te.obj[0], d = editor.document, range = te.obj[1], db = editor.body; editor.setContent('xxxxgggsiekes'); setTimeout(function () { range.selectNode(d.getElementsByTagName("strong")[0]).collapse(true).select(); equal(editor.queryCommandValue('directionality'), "ltr", "ltr queryCommandValue"); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

xxxxgggsiekes

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "directionrtl queryCommandValue"); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

xxxxgggsiekes

", "directionltr"); equal(editor.queryCommandValue('directionality'), "ltr", "directionltr queryCommandValue"); start(); }, 20); stop(); } ); //2 blockelement&&collapsed=false test( '块元素,不闭合', function() { var editor = te.obj[0],d = editor.document,range = te.obj[1],db = editor.body; editor.setContent('

gggsiekes

'); setTimeout(function () { range.selectNode(d.getElementsByTagName("h1")[0]).select(); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

gggsiekes

", "directionltr"); equal(editor.queryCommandValue('directionality'), "ltr", "directionltr queryCommandValue"); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

gggsiekes

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "directionrtl queryCommandValue"); start(); }, 20); stop(); } ); test( '非块元素,闭合', function() { var editor = te.obj[0], d = editor.document, range = te.obj[1], db = editor.body; editor.setContent('gggsiekes'); setTimeout(function () { range.selectNode(d.getElementsByTagName("strong")[0].firstChild).collapse(true).select(); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

gggsiekes

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "directionrtl queryCommandValue"); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

gggsiekes

", "directionltr"); equal(editor.queryCommandValue('directionality'), "ltr", "directionltr queryCommandValue"); editor.setContent('gggsiekes'); range.selectNode(d.getElementsByTagName("strong")[0]).collapse(true).select(); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

gggsiekes

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "查询文字输入方向为从右向左"); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

gggsiekes

", "从左向右"); equal(editor.queryCommandValue('directionality'), "ltr", "查询文字输入方向为从左向右"); start(); }, 20); stop(); } ); //4 range between blockelement and notblockelement test( '选区包含块和非块元素', function() { var editor = te.obj[0],d = editor.document,range = te.obj[1],db = editor.body; editor.setContent('gggsiekes

xx

'); setTimeout(function () { range.setStart(d.getElementsByTagName("strong")[0].firstChild, 0).setEnd(d.getElementsByTagName("p")[1].firstChild, 2).select(); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

gggsiekes

xx

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "directionrtl queryCommandValue"); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

gggsiekes

xx

", "directionltr"); equal(editor.queryCommandValue('directionality'), "ltr", "directionltr queryCommandValue"); start(); }, 20); stop(); } ); //5 betweenblockelement test( '选区在两个块元素之间', function() { var editor = te.obj[0], d = editor.document, range = te.obj[1], db = editor.body; editor.setContent('

sss

xx

'); setTimeout(function () { range.setStart(d.getElementsByTagName("p")[0].firstChild, 0).setEnd(d.getElementsByTagName("p")[1].firstChild, 2).select(); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

sss

xx

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "directionrtl queryCommandValue"); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

sss

xx

", "directionltr"); equal(editor.queryCommandValue('directionality'), "ltr", "directionltr queryCommandValue"); start(); }, 20); stop(); } ); //6 br test( 'betweenblockelement', function() { var editor = te.obj[0],d = editor.document,range = te.obj[1],db = editor.body; editor.setContent( '

xx

br' ); setTimeout(function () { range.setStart(d.getElementsByTagName("p")[0].firstChild, 0).setEnd(db.lastChild, 1).select(); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

xx

br

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "directionrtl queryCommandValue"); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

xx

br

", "directionltr"); equal(editor.queryCommandValue('directionality'), "ltr", "directionltr queryCommandValue"); start(); }, 20); stop(); } ); //7   test( '空格 ', function() { var editor = te.obj[0], d = editor.document, range = te.obj[1], db = editor.body; editor.setContent('

xx

 '); setTimeout(function () { range.setStart(d.getElementsByTagName("p")[0].firstChild, 0).setEnd(db.lastChild, 1).select(); editor.execCommand('directionality', "rtl"); equal(ua.getChildHTML(db), "

xx

 

", "directionrtl"); equal(editor.queryCommandValue('directionality'), "rtl", "directionrtl queryCommandValue"); editor.execCommand('directionality', "ltr"); equal(ua.getChildHTML(db), "

xx

 

", "directionltr"); equal(editor.queryCommandValue('directionality'), "ltr", "directionltr queryCommandValue"); start(); }, 20); stop(); } ); test('body',function(){ var editor=te.obj[0]; var range=te.obj[1]; editor.setContent('

xx

'); range.setStart(editor.body,0).collapse(1).select(); editor.execCommand('directionality', 'rtl'); if(ua.browser.ie){ equal( ua.getChildHTML( editor.body ), "

xx

", "directionrtl" ); } else{ equal( ua.getChildHTML( editor.body ), "

xx

", "directionrtl" ); } })