(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() { $('#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 = $('