add typeahead.js, fix

This commit is contained in:
vitalets
2013-09-28 14:48:39 +04:00
parent 88514be8ec
commit 06934b9656
9 changed files with 1438 additions and 4 deletions

@ -220,6 +220,16 @@ define(function () {
init: function(require) {
loadCss(require.toUrl("./address.css"));
}
},
'inputs-ext/typeaheadjs/typeaheadjs': {
deps: [
'require',
'inputs/text',
'inputs-ext/typeaheadjs/lib/typeahead'
],
init: function(require) {
loadCss(require.toUrl("./lib/typeahead.js-bootstrap.css"));
}
}
};
@ -231,7 +241,8 @@ define(function () {
shim['editable-form/editable-form'].deps = shim['editable-form/editable-form'].deps.concat(
[
'inputs/date/datefield',
'inputs/datetime/datetimefield'
'inputs/datetime/datetimefield',
'inputs-ext/typeaheadjs/typeaheadjs'
//'inputs-ext/wysihtml5/wysihtml5',
//'inputs/typeahead'
]);

@ -56,9 +56,9 @@ require(["loader", jqurl], function(loader) {
'test/unit/datefield',
'test/unit/date',
'test/unit/datetimefield',
'test/unit/datetime'
'test/unit/datetime',
//'test/unit/wysihtml5'
//'test/unit/typeahead'
'test/unit/typeaheadjs'
];
break;

66
test/unit/typeaheadjs.js Normal file

@ -0,0 +1,66 @@
$(function () {
module("typeaheadjs", {
setup: function(){
sfx = $('#qunit-fixture'),
fx = $('#async-fixture');
$.support.transition = false;
}
});
asyncTest("should load correct value and save new entered text ", function () {
var v = 'ru',
e = $('<a href="#" data-pk="1" data-name="text1" data-type="typeaheadjs" data-url="post.php"></a>').appendTo(fx).editable({
value: v,
typeahead: {
name: 'country',
local: [
{value: 'ru', tokens: ['Russia']},
{value: 'gb', tokens: ['Great Britain']},
{value: 'us', tokens: ['United States']}
],
template: function(item) {
return item.tokens[0] + ' (' + item.value + ')';
}
}
}),
nv = 'gb',
newText = 'G';
equal(e.data().editable.value, v, 'initial value ok');
e.click();
var p = tip(e),
$input = p.find('input.tt-query');
ok(p.is(':visible'), 'popup visible');
ok($input.length, 'input exists');
equal($input.val(), v, 'input contains correct text');
ok($input.typeahead, 'typeahead applied to input');
// can`t find way to trigger dropdown menu of typeahead
var ev = jQuery.Event( "keydown.tt", { keyCode: 64 } );
$input.val(nv).trigger('queryChanged');
/*
ok(p.find('.tt-dropdown-menu').is(':visible'), 'dropdown visible');
equal(p.find('tt-suggestion').length, 1, 'suggestion exists');
p.find('tt-suggestion:eq(0)').mouseover().click();
equal($input.val(), nv, 'input contain correct text');
*/
p.find('form').submit();
setTimeout(function() {
ok(!p.is(':visible'), 'popup closed');
equal(e.data('editable').value, nv, 'new text saved to value');
equal(e.text(), nv, 'new text shown');
e.remove();
start();
}, timeout);
});
});