(function() {
var $elm;
module("tinymce.dom.DomQuery", {
teardown: function() {
if ($elm) {
$elm.off();
$elm = null;
}
document.getElementById('view').innerHTML = '';
}
});
function normalizeParentNode(parentNode) {
// IE 8 will return a document fragment as it's parent when nodes are removed
if (parentNode && parentNode.nodeType == 11) {
return null;
}
return parentNode;
}
function normalizeStyleValue(value) {
if (typeof value == 'string') {
return value.toLowerCase().replace(/\s+/g, ' ').replace(/;\s*$/, '');
}
return value;
}
function splitAtView(nodes) {
nodes.each(function(i) {
if (this.id == 'view') {
nodes = nodes.slice(0, i);
return false;
}
});
return nodes;
}
function addTests(prefix, $) {
test(prefix + 'Constructor HTML', function() {
var $html;
$html = $('ab');
equal($html.length, 2);
equal($html[0].tagName, 'B');
equal($html[1].tagName, 'I');
});
test(prefix + 'Constructor HTML with attributes', function() {
var $html;
$html = $('', {id: 'id', title: 'title'});
equal($html.length, 1);
equal($html[0].tagName, 'B');
equal($html[0].getAttribute('id'), 'id');
equal($html[0].getAttribute('title'), 'title');
});
test(prefix + 'Constructor selector', function() {
var $selector;
$selector = $('#view');
equal($selector.length, 1);
equal($selector.selector, '#view');
strictEqual($selector.context, document);
});
test(prefix + 'Constructor selector and context', function() {
var $selector;
$selector = $('#view', document);
equal($selector.length, 1);
equal($selector.selector, '#view');
strictEqual($selector.context, document);
});
test(prefix + 'Constructor selector and context', function() {
var $selector;
$('#view').html('
a
b
');
$('b', $('#view div')[0]).html('x');
equal($('#view').html().toLowerCase().replace(/[\r\n]/g, ''), 'x
b
');
});
test(prefix + 'Constructor array', function() {
var $html;
$html = $([document.getElementById('view'), document.body]);
equal($html.length, 2);
equal($html[0].tagName, 'DIV');
equal($html[1].tagName, 'BODY');
});
test(prefix + 'Constructor query instance', function() {
var $clone;
$clone = $($('#view'));
equal($clone.length, 1);
equal($clone[0].tagName, 'DIV');
});
test(prefix + 'Constructor window', function() {
var $win;
$win = $(window);
equal($win.length, 1);
strictEqual($win[0], window);
});
test(prefix + 'Constructor window', function() {
var $elm;
$elm = $(document.body);
equal($elm.length, 1);
strictEqual($elm[0], document.body);
});
test(prefix + 'static extend()', function() {
var data;
deepEqual($.extend({a: 1, b: 1}, {b: 2, c: 2}), {a: 1, b: 2, c: 2});
deepEqual($.extend({a: 1, b: 1}, {b: 2, c: 2}, {c: 3, d: 3}), {a: 1, b: 2, c: 3, d: 3});
data = {a: 1, b: 1};
ok(data === $.extend(data, {b: 2, c: 2}, {c: 3, d: 3}), {a: 1, b: 2, c: 3, d: 3});
});
test(prefix + 'static makeArray()', function() {
strictEqual($.makeArray(window)[0], window);
deepEqual($.makeArray({'0': 'a', '1': 'b', length: 2}), ['a', 'b']);
});
test(prefix + 'static inArray()', function() {
deepEqual($.inArray(1, [1, 2]), 0);
deepEqual($.inArray(2, [1, 2]), 1);
deepEqual($.inArray(3, [1, 2]), -1);
});
test(prefix + 'static grep()', function() {
deepEqual($.grep([1, 2, 3], function(v) {return v > 1;}), [2, 3]);
});
test(prefix + 'static isArray()', function() {
ok($.isArray([]));
ok(!$.isArray({}));
});
test(prefix + 'static each()', function() {
var data;
data = '';
$.each([1, 2, 3], function(key, value) {
data += '' + value + key;
});
equal(data, '102132');
data = '';
$.each({a: 1, b: 2, c: 3}, function(key, value) {
data += '' + value + key;
});
equal(data, '1a2b3c');
data = '';
$.each([1, 2, 3], function(key, value) {
data += '' + value + key;
if (value == 2) {
return false;
}
});
equal(data, '1021');
});
test(prefix + 'static trim()', function() {
equal($.trim(' a '), 'a');
equal($.trim('a '), 'a');
equal($.trim(' a'), 'a');
});
test(prefix + 'static unique()', function() {
var nodes;
nodes = $.unique([document.getElementById('view'), document.getElementById('view'), document.body]);
equal(nodes.length, 2);
equal(nodes[0].tagName, 'BODY');
equal(nodes[1].tagName, 'DIV');
});
test(prefix + 'toArray()', function() {
ok($.isArray($('#view').toArray()));
equal($('#view').toArray().length, 1);
});
test(prefix + 'add() single element', function() {
var $nodes = $('#view').add(document.body);
equal($nodes.length, 2);
equal($nodes[0].tagName, 'BODY');
equal($nodes[1].tagName, 'DIV');
});
test(prefix + 'add() multiple elements (duplicates)', function() {
var $nodes = $('#view,#view').add([document.body, document.body]);
equal($nodes.length, 2);
equal($nodes[0].tagName, 'BODY');
equal($nodes[1].tagName, 'DIV');
});
test(prefix + 'add() multiple elements (non duplicates)', function() {
var $nodes = $('#view').add([$('')[0], $('')[0]]);
equal($nodes.length, 3);
equal($nodes[0].tagName, 'DIV');
equal($nodes[1].tagName, 'B');
equal($nodes[2].tagName, 'I');
});
test(prefix + 'add() selector', function() {
var $nodes = $().add('#view');
equal($nodes.length, 1);
equal($nodes[0].tagName, 'DIV');
});
test(prefix + 'attr() set/get attr on element', function() {
var $elm;
$elm = $('').attr('id', 'x');
equal($elm.attr('id'), 'x');
equal(typeof $elm.attr('noattr'), 'undefined', 'Undefined attribute shouldn\'t have a value');
$elm = $('').attr('attr', null);
equal(typeof $elm.attr('attr'), 'undefined', 'Deleted attribute shouldn\'t have a value (1)');
$elm = $('').attr('id', 1);
strictEqual($elm.attr('id'), '1');
});
test(prefix + 'attr() set/get style attr on element (IE 7)', function() {
$elm = $('').attr('style', 'font-size: 43px');
equal(normalizeStyleValue($elm.attr('style')), 'font-size: 43px');
});
test(prefix + 'attr() set/get checked attr on element (IE 7)', function() {
$elm = $('').attr('checked', 'checked');
equal($elm.attr('checked').toLowerCase(), 'checked');
});
test(prefix + 'attr() get special attrs on element (IE 7)', function() {
$elm = $('');
equal(typeof $elm.attr('maxlength'), 'undefined', 'Undefined maxlength');
equal(typeof $elm.attr('size'), 'undefined', 'Undefined size');
equal(typeof $elm.attr('checked'), 'undefined', 'Undefined checked');
equal(typeof $elm.attr('readonly'), 'undefined', 'Undefined readonly');
equal(typeof $elm.attr('disabled'), 'undefined', 'Undefined disabled');
$elm = $('');
equal(typeof $elm.attr('maxlength'), 'undefined', 'Undefined maxlength');
equal(typeof $elm.attr('size'), 'undefined', 'Undefined size');
equal(typeof $elm.attr('checked'), 'undefined', 'Undefined checked');
equal(typeof $elm.attr('readonly'), 'undefined', 'Undefined readonly');
equal(typeof $elm.attr('disabled'), 'undefined', 'Undefined disabled');
$elm = $('');
equal($elm.attr('maxlength'), '21', 'maxlength');
equal($elm.attr('size'), '11', 'size');
equal($elm.attr('disabled'), 'disabled', 'disabled');
$elm = $('');
equal(typeof $elm.attr('maxlength'), 'undefined', 'Undefined maxlength');
equal(typeof $elm.attr('size'), 'undefined', 'Undefined size');
equal(typeof $elm.attr('checked'), 'undefined', 'Undefined checked');
equal(typeof $elm.attr('readonly'), 'undefined', 'Undefined readonly');
equal(typeof $elm.attr('disabled'), 'undefined', 'Undefined disabled');
$elm = $('');
equal($elm.attr('readonly'), 'readonly', 'readonly');
});
test(prefix + 'attr() set/get attrs on element', function() {
var $elm;
$elm = $('').attr({id: 'x', title: 'y'});
equal($elm.attr('id'), 'x');
equal($elm.attr('title'), 'y');
});
test(prefix + 'attr() set/get on non element', function() {
var $elm;
$elm = $([document.createTextNode('x')]).attr('id', 'x');
equal(typeof $elm.attr('id'), 'undefined');
});
test(prefix + 'removeAttr() on element', function() {
var $elm;
$elm = $('').removeAttr('AttR');
equal(typeof $elm.attr('attr'), 'undefined');
$elm = $([document.createTextNode('x')]).removeAttr('id');
equal(typeof $elm.attr('id'), 'undefined');
});
test(prefix + 'prop() set/get attr on element', function() {
var $elm;
$elm = $('').prop('id', 'x');
equal($elm.prop('id'), 'x');
equal(typeof $elm.prop('noprop'), 'undefined');
$elm = $('');
equal($elm.prop('class'), 'x');
equal($elm.prop('className'), 'x');
$elm = $('');
equal($elm.prop('for'), 'x');
equal($elm.prop('htmlFor'), 'x');
});
test(prefix + 'prop() set/get attrs on element', function() {
var $elm;
$elm = $('').prop({id: 'x', title: 'y'});
equal($elm.prop('id'), 'x');
equal($elm.prop('title'), 'y');
});
test(prefix + 'css() get/set single item on element', function() {
var $elm;
$elm = $('').appendTo('#view').css('font-size', 42);
equal($elm.css('font-size'), '42px');
$elm = $('').appendTo('#view').css('fontSize', 42);
equal($elm.css('fontSize'), '42px');
});
test(prefix + 'css() get/set items on element', function() {
var $elm;
$elm = $('x').appendTo('#view').css({'font-size': 42, 'text-indent': 42});
equal($elm.css('font-size'), '42px');
equal($elm.css('text-indent'), '42px');
});
test(prefix + 'css() set opacity', function() {
var styles = new tinymce.html.Styles();
if (tinymce.Env.ie && tinymce.Env.ie < 9) {
// jQuery has a slightly different output but basically the same
deepEqual(styles.parse($('').css('opacity', 0.5).attr('style')), {filter: 'alpha(opacity=50)', 'zoom': '1'});
strictEqual(typeof $('').css('opacity', null).attr('style'), 'undefined');
} else {
strictEqual(normalizeStyleValue($('').css('opacity', 0.5).attr('style')), 'opacity: 0.5');
ok(!$('').css('opacity', null).attr('style'));
ok(!$('').css('opacity', '').attr('style'));
}
});
test(prefix + 'css() set float', function() {
strictEqual(normalizeStyleValue($('').css('float', 'right').attr('style')), 'float: right');
ok(!$('').css('float', '').attr('style'));
ok(!$('').css('float', null).attr('style'));
});
test(prefix + 'remove() single element', function() {
var $elm;
$elm = $('x').appendTo('#view').remove();
strictEqual(normalizeParentNode($elm[0].parentNode), null);
});
test(prefix + 'remove() multiple elements', function() {
var $elm;
$elm = $('xx').appendTo('#view').remove();
strictEqual(normalizeParentNode($elm[0].parentNode), null);
strictEqual(normalizeParentNode($elm[1].parentNode), null);
});
test(prefix + 'remove() unappended element', function() {
var $elm;
$elm = $('x').remove();
strictEqual(normalizeParentNode($elm[0].parentNode), null);
});
test(prefix + 'empty() single element', function() {
var $elm;
$elm = $('xy').empty();
strictEqual($elm[0].firstChild, null);
});
test(prefix + 'html() set on single element', function() {
var $elm;
$elm = $('').html('x');
strictEqual($elm[0].firstChild.tagName, 'I');
});
test(prefix + 'html() get on element/elements', function() {
strictEqual($('x').html().toLowerCase(), 'x');
strictEqual($('xa').html().toLowerCase(), 'x');
});
/*
test(prefix + 'html() set comment as first child (IE)', function() {
$('#view').html('y');
strictEqual($('#view').html(), 'y');
});
*/
test(prefix + 'html() set DIV as child of P (IE 8)', function() {
$('').appendTo('#view');
$('#view p').html('x
');
strictEqual($('#view').html().toLowerCase().replace(/[\r\n]/g, ''), 'x
');
});
test(prefix + 'text() set on single element', function() {
var $elm;
$elm = $('').text('x');
strictEqual($elm[0].firstChild.data, 'x');
});
test(prefix + 'text() get on element', function() {
strictEqual($('xy').text().toLowerCase(), 'xy');
});
test(prefix + 'append() to element', function() {
var $elm;
$elm = $('a');
$elm.append($('b'));
strictEqual($elm.html().toLowerCase(), 'ab');
$elm = $('a');
$elm.append('b');
strictEqual($elm.html().toLowerCase(), 'ab');
$elm = $('a');
$elm.append('b');
strictEqual($elm.html().toLowerCase(), 'ab');
$elm = $('a');
$elm.append($('bc'));
strictEqual($elm.html().toLowerCase(), 'abc');
$elm = $('');
$elm.append($('b'));
strictEqual($elm.html().toLowerCase(), 'b');
});
test(prefix + 'prepend() to element', function() {
var $elm;
$elm = $('a');
$elm.prepend($('b'));
strictEqual($elm.html().toLowerCase(), 'ba');
$elm = $('a');
$elm.prepend($('bc'));
strictEqual($elm.html().toLowerCase(), 'bca');
$elm = $('');
$elm.prepend($('b'));
strictEqual($elm.html().toLowerCase(), 'b');
});
test(prefix + 'before() element', function() {
var $elm;
$elm = $('a');
$elm.children().before($('b'));
strictEqual($elm.html().toLowerCase(), 'ba');
$elm = $('a');
$elm.children().before($('bc'));
strictEqual($elm.html().toLowerCase(), 'bca');
});
test(prefix + 'after() element', function() {
var $elm;
$elm = $('a');
$elm.children().after($('b'));
strictEqual($elm.html().toLowerCase(), 'ab');
$elm = $('a');
$elm.children().after($('bc'));
strictEqual($elm.html().toLowerCase(), 'abc');
});
test(prefix + 'appendTo() to element', function() {
var $elm;
$elm = $('a');
$('b').appendTo($elm);
strictEqual($elm.html().toLowerCase(), 'ab');
$elm = $('a');
$('bc').appendTo($elm);
strictEqual($elm.html().toLowerCase(), 'abc');
$elm = $('');
$('b').appendTo($elm);
strictEqual($elm.html().toLowerCase(), 'b');
});
test(prefix + 'prependTo() to element', function() {
var $elm;
$elm = $('a');
$('b').prependTo($elm);
strictEqual($elm.html().toLowerCase(), 'ba');
$elm = $('a');
$('bc').prependTo($elm);
strictEqual($elm.html().toLowerCase(), 'bca');
$elm = $('');
$('b').prependTo($elm);
strictEqual($elm.html().toLowerCase(), 'b');
});
test(prefix + 'addClass() to element', function() {
var $elm;
$elm = $('').addClass('a');
strictEqual($elm.attr('class'), 'a');
$elm = $('').addClass('b');
strictEqual($elm.attr('class'), 'a b');
});
test(prefix + 'removeClass() from element', function() {
var $elm;
$elm = $('').removeClass('a');
strictEqual($elm.attr('class'), 'x');
$elm = $('').removeClass('b');
strictEqual($elm.attr('class'), 'a');
$elm = $('').removeClass('a');
strictEqual($elm.attr('class'), '');
});
test(prefix + 'toggleClass() on element', function() {
var $elm;
$elm = $('').toggleClass('a');
strictEqual($elm.attr('class'), 'x a');
$elm = $('').toggleClass('b');
strictEqual($elm.attr('class'), 'a');
$elm = $('').toggleClass('a', true);
strictEqual($elm.attr('class'), 'a');
$elm = $('').toggleClass('a', false);
strictEqual($elm.attr('class'), 'b');
});
test(prefix + 'toggleClass() on element', function() {
strictEqual($('').hasClass('a'), true);
strictEqual($('').hasClass('b'), false);
strictEqual($('').hasClass('b'), true);
strictEqual($('').hasClass('a'), true);
});
test(prefix + 'filter()', function() {
strictEqual($('').filter('b,i').length, 2);
strictEqual($('').filter(function(i, elm) {
return elm.tagName != 'U';
}).length, 2);
strictEqual($('').filter(function(i, elm) {
return i != 2;
}).length, 2);
strictEqual($([document, window, document.createTextNode('x')]).filter('*').length, 0);
strictEqual($.filter('*', [document, window, document.createTextNode('x')]).length, 0);
});
test(prefix + 'each() collection', function() {
var $html = $('ab'), data;
data = '';
$html.each(function(index, elm) {
data += index + elm.innerHTML + this.innerHTML;
});
strictEqual(data, '0aa1bb');
data = '';
$html.each(function(index, elm) {
data += index + elm.innerHTML + this.innerHTML;
if (index === 0) {
return false;
}
});
strictEqual(data, '0aa');
});
test(prefix + 'on()/off()/trigger()', function() {
var lastArgs1, lastArgs2;
$elm = $('')
// Single listener
$elm.on('click', function(e) {
lastArgs1 = e;
});
$elm.trigger('click');
strictEqual(lastArgs1.type, 'click');
// Single listener trigger object
$elm.off().on('click', function(e) {
lastArgs1 = e;
});
$elm.trigger({type: 'click', custom: 'x'});
strictEqual(lastArgs1.type, 'click');
strictEqual(lastArgs1.custom, 'x');
// Unbind listeners
lastArgs1 = null;
$elm.off('click');
$elm.trigger('click');
strictEqual(lastArgs1, null);
// Bind two listeners
$elm.on('click', function(e) {
lastArgs1 = e;
});
$elm.on('click', function(e) {
lastArgs2 = e;
});
$elm.trigger('click');
strictEqual(lastArgs1.type, 'click');
strictEqual(lastArgs2.type, 'click');
// Bind two listeners and stop propagation
lastArgs1 = lastArgs2 = null;
$elm.off('click');
$elm.on('click', function(e) {
lastArgs1 = e;
e.stopImmediatePropagation();
});
$elm.on('click', function(e) {
lastArgs2 = e;
});
$elm.trigger('click');
strictEqual(lastArgs1.type, 'click');
strictEqual(lastArgs2, null);
});
test(prefix + 'show()/hide() element', function() {
equal(normalizeStyleValue($('').hide().attr('style')), 'display: none');
ok(!$('').show().attr('style'));
});
test(prefix + 'slice/eq/first/last() on collection', function() {
var $html = $('123');
strictEqual($html.slice(1).length, 2);
strictEqual($html.slice(1)[0].tagName, 'I');
strictEqual($html.slice(1)[1].tagName, 'EM');
strictEqual($html.slice(1, 2).length, 1);
strictEqual($html.slice(1, 2)[0].tagName, 'I');
strictEqual($html.slice(-2, -1).length, 1);
strictEqual($html.slice(-2, -1)[0].tagName, 'I');
strictEqual($html.eq(1).length, 1);
strictEqual($html.eq(1)[0].tagName, 'I');
strictEqual($html.eq(-1).length, 1);
strictEqual($html.eq(-1)[0].tagName, 'EM');
strictEqual($html.eq(1).length, 1);
strictEqual($html.eq(1)[0].tagName, 'I');
strictEqual($html.first().length, 1);
strictEqual($html.first()[0].tagName, 'B');
strictEqual($html.last().length, 1);
strictEqual($html.last()[0].tagName, 'EM');
});
test(prefix + 'replaceWith() on single element with single element', function() {
var $result;
$('1').appendTo('#view');
$result = $('#view b').replaceWith('2');
strictEqual($('#view').html().toLowerCase(), '2');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'B');
});
test(prefix + 'replaceWith() on single element with multiple elements', function() {
var $result;
$('1').appendTo('#view');
$result = $('#view b').replaceWith('23');
strictEqual($('#view').html().toLowerCase(), '23');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'B');
});
/*
test(prefix + 'replaceWith() on multiple elements with multiple elements', function() {
var $result;
$('12').appendTo('#view');
$result = $('#view b, #view i').replaceWith('34');
strictEqual($('#view').html().toLowerCase(), '34');
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'B');
strictEqual($result[1].tagName, 'I');
});
*/
test(prefix + 'wrap() single element', function() {
$('1').appendTo('#view').wrap('');
strictEqual($('#view').html().toLowerCase(), '1');
});
test(prefix + 'wrap() multiple element', function() {
$('12').appendTo('#view').wrap('');
strictEqual($('#view').html().toLowerCase(), '12');
});
test(prefix + 'wrapAll() multiple element', function() {
$('12').appendTo('#view').wrapAll('');
strictEqual($('#view').html().toLowerCase(), '12');
});
test(prefix + 'wrapInner() multiple element', function() {
$('1a2b').appendTo('#view').wrapInner('');
strictEqual($('#view').html().toLowerCase(), '1a2b');
});
test(prefix + 'unwrap() single element with no siblings', function() {
$('#view').html('1');
$('#view i').unwrap();
strictEqual($('#view').html().toLowerCase(), '1');
});
test(prefix + 'unwrap() single element with siblings', function() {
$('#view').html('12');
$('#view i').unwrap();
strictEqual($('#view').html().toLowerCase(), '12');
});
test(prefix + 'clone() single element', function() {
$('1').appendTo('#view').clone().appendTo('#view');
strictEqual($('#view').html().toLowerCase(), '11');
});
test(prefix + 'find()', function() {
var $result;
$('#view').append('12');
$result = $('#view').find('*');
strictEqual($result.length, 4);
$result = $('#view em').find('*');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
$result = $('#view em, #view strong').find('*');
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'I');
strictEqual($result[1].tagName, 'B');
});
test(prefix + 'parent()', function() {
var $result;
$('#view').append('12');
$result = $('#view i, #view b').parent();
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'EM');
strictEqual($result[1].tagName, 'STRONG');
$result = $('#view i, #view b').parent('em');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'EM');
$result = $('#view i, #view b').parent('div');
strictEqual($result.length, 0);
});
test(prefix + 'parents()', function() {
var $result, html;
html = $('12
').appendTo('#view');
$result = splitAtView($('#view i, #view b').parents());
strictEqual($result.length, 3);
strictEqual($result[0].tagName, 'STRONG');
strictEqual($result[1].tagName, 'EM');
strictEqual($result[2].tagName, 'DIV');
$result = splitAtView($('#view i, #view b').parents('em'));
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'EM');
$result = splitAtView($('#view i, #view b').parents('p'));
strictEqual($result.length, 0);
});
test(prefix + 'parentsUntil(selector)', function() {
var $result, html;
html = $('12
').appendTo('#view');
$result = $('#view i, #view b').parentsUntil('#view');
strictEqual($result.length, 3);
strictEqual($result[0].tagName, 'STRONG');
strictEqual($result[1].tagName, 'EM');
strictEqual($result[2].tagName, 'DIV');
$result = $('#view i, #view b').parentsUntil('#view', 'div');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'DIV');
});
test(prefix + 'parentsUntil(element)', function() {
var $result, html;
html = $('12
').appendTo('#view');
$result = $('#view i, #view b').parentsUntil(document.getElementById('view'));
strictEqual($result.length, 3);
strictEqual($result[0].tagName, 'STRONG');
strictEqual($result[1].tagName, 'EM');
strictEqual($result[2].tagName, 'DIV');
$result = $('#view i, #view b').parentsUntil(document.getElementById('view'), 'div');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'DIV');
});
test(prefix + 'parentsUntil(query)', function() {
var $result, html;
html = $('12
').appendTo('#view');
$result = $('#view i, #view b').parentsUntil($('#view'));
strictEqual($result.length, 3);
strictEqual($result[0].tagName, 'STRONG');
strictEqual($result[1].tagName, 'EM');
strictEqual($result[2].tagName, 'DIV');
$result = $('#view i, #view b').parentsUntil($('#view'), 'div');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'DIV');
});
test(prefix + 'next()', function() {
var $result, html;
html = $('123');
$result = html.next();
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
});
test(prefix + 'prev()', function() {
var $result, html;
html = $('123');
$result = $(html).prev();
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'B');
});
test(prefix + 'nextUntil(selector)', function() {
var $result, html;
html = $('1233');
$result = html.first().nextUntil('span');
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'I');
strictEqual($result[1].tagName, 'EM');
$result = html.first().nextUntil('span', 'i');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
});
test(prefix + 'nextUntil(element)', function() {
var $result, html;
html = $('1233');
$result = html.first().nextUntil(html.last()[0]);
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'I');
strictEqual($result[1].tagName, 'EM');
$result = html.first().nextUntil(html.last()[0], 'i');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
});
test(prefix + 'nextUntil(query)', function() {
var $result, html;
html = $('1233');
$result = html.first().nextUntil(html.last());
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'I');
strictEqual($result[1].tagName, 'EM');
$result = html.first().nextUntil(html.last(), 'i');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
});
test(prefix + 'prevUntil(selector)', function() {
var $result, html;
html = $('1233');
$result = html.last().prevUntil('b');
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'EM');
strictEqual($result[1].tagName, 'I');
$result = html.last().prevUntil('b', 'i');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
});
test(prefix + 'prevUntil(element)', function() {
var $result, html;
html = $('1233');
$result = html.last().prevUntil(html.first()[0]);
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'EM');
strictEqual($result[1].tagName, 'I');
$result = html.last().prevUntil(html.first()[0], 'i');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
});
test(prefix + 'prevUntil(query)', function() {
var $result, html;
html = $('1233');
$result = html.last().prevUntil(html.first());
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'EM');
strictEqual($result[1].tagName, 'I');
$result = html.last().prevUntil(html.first(), 'i');
strictEqual($result.length, 1);
strictEqual($result[0].tagName, 'I');
});
test(prefix + 'children()', function() {
var $result, html;
html = $('123');
$result = html.children();
strictEqual($result.length, 2);
strictEqual($result[0].tagName, 'I');
strictEqual($result[1].tagName, 'B');
});
test(prefix + 'contents()', function() {
var $result, html;
html = $('123');
$result = html.contents();
strictEqual($result.length, 3);
strictEqual($result[0].nodeName, '#text');
strictEqual($result[1].tagName, 'I');
strictEqual($result[2].tagName, 'B');
});
test(prefix + 'closest(selector/element/query)', function() {
var innerMost, html;
html = $('x');
innerMost = $(html[0].firstChild.firstChild.firstChild);
strictEqual(innerMost.closest(null).length, 0);
strictEqual(innerMost.closest('b').html(), 'x');
strictEqual(innerMost.closest(innerMost[0]).html(), 'x');
strictEqual(innerMost.closest('b i').html().toLowerCase(), 'x');
strictEqual(innerMost.closest($(html[0].firstChild.firstChild)).html().toLowerCase(), 'x');
strictEqual(innerMost.closest($(html[0].firstChild.firstChild)[0]).html().toLowerCase(), 'x');
});
test(prefix + 'offset()', function() {
var testElm = $('').offset({top: 10, left: 20});
strictEqual(testElm[0].style.top, '10px');
strictEqual(testElm[0].style.left, '20px');
var viewOffset = $('#view').offset();
var testElmOffset = $('').css({position: 'absolute', top: 10, left: 20}).prependTo('#view').offset();
testElmOffset.left -= viewOffset.left;
testElmOffset.top -= viewOffset.top;
deepEqual(testElmOffset, {top: 10, left: 20});
});
}
// Run tests against jQuery/DomQuery so we know that we are compatible
addTests('DomQuery: ', tinymce.dom.DomQuery);
addTests('jQuery: ', jQuery);
})();