2014-03-24 06:59:45 +01:00
|
|
|
(function() {
|
|
|
|
module("tinymce.ui.Control");
|
|
|
|
|
|
|
|
test("Initial states", function() {
|
|
|
|
var ctrl;
|
|
|
|
|
|
|
|
ctrl = new tinymce.ui.Control({});
|
|
|
|
|
|
|
|
// Check inital states
|
|
|
|
equal(ctrl.disabled(), false);
|
|
|
|
equal(ctrl.active(), false);
|
|
|
|
equal(ctrl.visible(), true);
|
2015-07-01 02:51:22 +02:00
|
|
|
equal(ctrl.text(), undefined);
|
|
|
|
equal(ctrl.name(), undefined);
|
|
|
|
equal(ctrl.title(), undefined);
|
2014-03-24 06:59:45 +01:00
|
|
|
equal(ctrl.parent(), undefined);
|
|
|
|
deepEqual(ctrl.settings, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Settings", function() {
|
|
|
|
var ctrl = new tinymce.ui.Control({
|
|
|
|
disabled: true,
|
|
|
|
active: true,
|
|
|
|
visible: true,
|
|
|
|
text: 'Text',
|
|
|
|
title: 'Title',
|
|
|
|
name: 'Name'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check settings states
|
|
|
|
equal(ctrl.disabled(), true);
|
|
|
|
equal(ctrl.active(), true);
|
|
|
|
equal(ctrl.visible(), true);
|
|
|
|
equal(ctrl.text(), "Text");
|
|
|
|
equal(ctrl.name(), "Name");
|
|
|
|
equal(ctrl.title(), "Title");
|
|
|
|
equal(ctrl.parent(), undefined);
|
|
|
|
deepEqual(ctrl.settings, {
|
|
|
|
disabled: true,
|
|
|
|
active: true,
|
|
|
|
visible: true,
|
|
|
|
text: 'Text',
|
|
|
|
title: 'Title',
|
|
|
|
name: 'Name'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Properties", function() {
|
|
|
|
var ctrl, cont;
|
|
|
|
|
|
|
|
cont = new tinymce.ui.Container({});
|
|
|
|
ctrl = new tinymce.ui.Control({});
|
|
|
|
|
|
|
|
// Set all states
|
|
|
|
ctrl = ctrl.
|
|
|
|
disabled(true).
|
|
|
|
active(true).
|
|
|
|
visible(true).
|
|
|
|
text("Text").
|
|
|
|
title("Title").
|
|
|
|
name("Name").parent(cont);
|
|
|
|
|
|
|
|
// Check states
|
|
|
|
equal(ctrl.disabled(), true);
|
|
|
|
equal(ctrl.active(), true);
|
|
|
|
equal(ctrl.visible(), true);
|
|
|
|
equal(ctrl.text(), "Text");
|
|
|
|
equal(ctrl.name(), "Name");
|
|
|
|
equal(ctrl.title(), "Title");
|
|
|
|
equal(ctrl.parent(), cont);
|
|
|
|
deepEqual(ctrl.settings, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Chained methods", function() {
|
|
|
|
var ctrl = new tinymce.ui.Control({});
|
|
|
|
|
|
|
|
// Set all states
|
|
|
|
ctrl = ctrl.
|
2014-04-16 00:06:11 +02:00
|
|
|
on('click', function() {}).
|
|
|
|
off().
|
|
|
|
renderTo(document.getElementById('view')).
|
2014-03-24 06:59:45 +01:00
|
|
|
remove();
|
|
|
|
|
|
|
|
// Check so that the chain worked
|
|
|
|
ok(ctrl instanceof tinymce.ui.Control);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Events", function() {
|
|
|
|
var ctrl = new tinymce.ui.Control({
|
2014-04-16 00:06:11 +02:00
|
|
|
onMyEvent: function() {
|
|
|
|
count++;
|
|
|
|
},
|
|
|
|
callbacks: {
|
2014-03-24 06:59:45 +01:00
|
|
|
handler1: function() {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}), count;
|
|
|
|
|
2014-04-16 00:06:11 +02:00
|
|
|
ctrl.on('MyEvent', function(args) {
|
|
|
|
equal(ctrl, args.control);
|
|
|
|
equal(ctrl, this);
|
|
|
|
equal(args.myKey, 'myVal');
|
2014-03-24 06:59:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
ctrl.fire('MyEvent', {myKey: 'myVal'});
|
|
|
|
|
2014-04-16 00:06:11 +02:00
|
|
|
function countAndBreak() {
|
2014-03-24 06:59:45 +01:00
|
|
|
count++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bind two events
|
2014-04-16 00:06:11 +02:00
|
|
|
ctrl.on('MyEvent2', countAndBreak);
|
|
|
|
ctrl.on('MyEvent2', countAndBreak);
|
2014-03-24 06:59:45 +01:00
|
|
|
|
|
|
|
// Check if only one of them was called
|
|
|
|
count = 0;
|
|
|
|
ctrl.fire('MyEvent2', {myKey: 'myVal'});
|
|
|
|
equal(count, 1);
|
|
|
|
|
|
|
|
// Fire unbound event
|
|
|
|
ctrl.fire('MyEvent3', {myKey: 'myVal'});
|
|
|
|
|
|
|
|
// Unbind all
|
2014-04-16 00:06:11 +02:00
|
|
|
ctrl.off();
|
2014-03-24 06:59:45 +01:00
|
|
|
count = 0;
|
|
|
|
ctrl.fire('MyEvent2', {myKey: 'myVal'});
|
|
|
|
equal(count, 0, 'Unbind all');
|
|
|
|
|
|
|
|
// Unbind by name
|
2014-04-16 00:06:11 +02:00
|
|
|
ctrl.on('MyEvent1', countAndBreak);
|
|
|
|
ctrl.on('MyEvent2', countAndBreak);
|
|
|
|
ctrl.off('MyEvent2');
|
2014-03-24 06:59:45 +01:00
|
|
|
count = 0;
|
|
|
|
ctrl.fire('MyEvent1', {myKey: 'myVal'});
|
|
|
|
ctrl.fire('MyEvent2', {myKey: 'myVal'});
|
|
|
|
equal(count, 1);
|
|
|
|
|
|
|
|
// Unbind by name callback
|
2014-04-16 00:06:11 +02:00
|
|
|
ctrl.on('MyEvent1', countAndBreak);
|
|
|
|
ctrl.on('MyEvent1', function() {count++;});
|
|
|
|
ctrl.off('MyEvent1', countAndBreak);
|
2014-03-24 06:59:45 +01:00
|
|
|
count = 0;
|
|
|
|
ctrl.fire('MyEvent1', {myKey: 'myVal'});
|
|
|
|
equal(count, 1);
|
|
|
|
|
|
|
|
// Bind by named handler
|
2014-04-16 00:06:11 +02:00
|
|
|
ctrl.off();
|
|
|
|
ctrl.on('MyEvent', 'handler1');
|
2014-03-24 06:59:45 +01:00
|
|
|
count = 0;
|
|
|
|
ctrl.fire('MyEvent', {myKey: 'myVal'});
|
|
|
|
equal(count, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("hasClass,addClass,removeClass", function() {
|
|
|
|
var ctrl = new tinymce.ui.Control({classes: 'class1 class2 class3'});
|
|
|
|
|
2015-07-01 02:51:22 +02:00
|
|
|
equal(ctrl.classes, 'mce-class1 mce-class2 mce-class3');
|
|
|
|
ok(ctrl.classes.contains('class1'));
|
|
|
|
ok(ctrl.classes.contains('class2'));
|
|
|
|
ok(ctrl.classes.contains('class3'));
|
|
|
|
ok(!ctrl.classes.contains('class4'));
|
|
|
|
|
|
|
|
ctrl.classes.add('class4');
|
|
|
|
equal(ctrl.classes, 'mce-class1 mce-class2 mce-class3 mce-class4');
|
|
|
|
ok(ctrl.classes.contains('class1'));
|
|
|
|
ok(ctrl.classes.contains('class2'));
|
|
|
|
ok(ctrl.classes.contains('class3'));
|
|
|
|
ok(ctrl.classes.contains('class4'));
|
|
|
|
|
|
|
|
ctrl.classes.remove('class4');
|
|
|
|
equal(ctrl.classes, 'mce-class1 mce-class2 mce-class3');
|
|
|
|
ok(ctrl.classes.contains('class1'));
|
|
|
|
ok(ctrl.classes.contains('class2'));
|
|
|
|
ok(ctrl.classes.contains('class3'));
|
|
|
|
ok(!ctrl.classes.contains('class4'));
|
|
|
|
|
|
|
|
ctrl.classes.remove('class3').remove('class2');
|
|
|
|
equal(ctrl.classes, 'mce-class1');
|
|
|
|
ok(ctrl.classes.contains('class1'));
|
|
|
|
ok(!ctrl.classes.contains('class2'));
|
|
|
|
ok(!ctrl.classes.contains('class3'));
|
|
|
|
|
|
|
|
ctrl.classes.remove('class3').remove('class1');
|
|
|
|
equal(ctrl.classes, '');
|
|
|
|
ok(!ctrl.classes.contains('class1'));
|
|
|
|
ok(!ctrl.classes.contains('class2'));
|
|
|
|
ok(!ctrl.classes.contains('class3'));
|
2014-03-24 06:59:45 +01:00
|
|
|
});
|
2014-04-16 00:06:11 +02:00
|
|
|
|
|
|
|
test("encode", function() {
|
|
|
|
tinymce.i18n.add('en', {'old': '"new"'});
|
|
|
|
equal(new tinymce.ui.Control({}).encode('<>"&'), '<>"&');
|
|
|
|
equal(new tinymce.ui.Control({}).encode('old'), '"new"');
|
|
|
|
equal(new tinymce.ui.Control({}).encode('old', false), 'old');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("translate", function() {
|
|
|
|
tinymce.i18n.add('en', {'old': 'new'});
|
|
|
|
equal(new tinymce.ui.Control({}).translate('old'), 'new');
|
|
|
|
equal(new tinymce.ui.Control({}).translate('old2'), 'old2');
|
|
|
|
});
|
2014-03-24 06:59:45 +01:00
|
|
|
})();
|