}, opt.after );
QUnit.test( opt.description, function ( assert ) {
- /*jshint onevar: false */
- var tests = 1;
+ var $textarea, start, end, options, text, selected,
+ tests = 1;
if ( opt.after.selected !== null ) {
tests++;
}
QUnit.expect( tests );
- var $textarea = $( '<textarea>' );
+ $textarea = $( '<textarea>' );
$( '#qunit-fixture' ).append( $textarea );
- //$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm...
- $textarea.val( opt.before.text ); // won't work with the WikiEditor iframe?
-
- var start = opt.before.start,
- end = opt.before.end;
- if ( window.opera ) {
- // Compensate for Opera's craziness converting \n to \r\n and counting that as two chars
- var newLinesBefore = opt.before.text.substring( 0, start ).split( '\n' ).length - 1,
- newLinesInside = opt.before.text.substring( start, end ).split( '\n' ).length - 1;
- start += newLinesBefore;
- end += newLinesBefore + newLinesInside;
- }
+ // This method is actually missing atm...
+ //$textarea.textSelection( 'setContents', opt.before.text);
+
+ // Won't work with the WikiEditor iframe?
+ $textarea.val( opt.before.text );
- var options = $.extend( {}, opt.replace ); // Clone opt.replace
+ start = opt.before.start;
+ end = opt.before.end;
+
+ // Clone opt.replace
+ options = $.extend( {}, opt.replace );
options.selectionStart = start;
options.selectionEnd = end;
$textarea.textSelection( 'encapsulateSelection', options );
- var text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, '\n' );
+ text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, '\n' );
assert.equal( text, opt.after.text, 'Checking full text after encapsulation' );
if ( opt.after.selected !== null ) {
- var selected = $textarea.textSelection( 'getSelection' );
+ selected = $textarea.textSelection( 'getSelection' );
assert.equal( selected, opt.after.selected, 'Checking selected text after encapsulation.' );
}
replace: h2
} );
-
encapsulateTest( {
description: 'ownline option: turn a partial line into new h2',
before: {
replace: h2
} );
-
encapsulateTest( {
description: 'splitlines option: no selection, insert new list item',
before: {
replace: ulist
} );
-
function caretTest( options ) {
QUnit.test( options.description, 2, function ( assert ) {
- var pos, $textarea = $( '<textarea>' ).text( options.text );
+ var pos,
+ $textarea = $( '<textarea>' ).text( options.text );
$( '#qunit-fixture' ).append( $textarea );
caretSample = 'Some big text that we like to work with. Nothing fancy... you know what I mean?';
- /*
- // @broken: Disabled per bug 34820
- caretTest({
- description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8',
- text: caretSample,
- start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length)
- end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both.
- mode: 'get'
- });
- */
+/*
+ // @broken: Disabled per bug 34820
+ caretTest({
+ description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8',
+ text: caretSample,
+ start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length)
+ end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both.
+ mode: 'get'
+ });
+*/
caretTest( {
description: 'set/getCaretPosition with forced empty selection',