').appendTo(oParent).append(oLiClone);
},
start: function (event, ui) {
ui.helper.__widget = widget;
},
containment: ".popup_panel",
tolerance: "pointer",
stop: function (event, ui) {
var oLiDraggable = $(this);
oLiDraggable.css('visibility', 'visible');
}
});
}
}
}
return li;
},
_renderTags : function() {
var self = this;
this.elements.ul.find('li:not(.inputosaurus-required)').remove();
$.each(this._chosenValues, function (k, v) {
var el = self._createTag(v.key, v.value);
self.elements.ul.find('li.inputosaurus-input').before(el);
});
},
_removeTag : function(ev) {
var widget = (ev && ev.data.widget) || this;
widget._removeLiTag($(ev.currentTarget).closest('li'), widget);
widget.options.openedByClick = false;
},
_removeLiTag : function ($li, widget) {
var key = $li.data('inputosaurus'),
indexFound = false;
$.each(widget._chosenValues, function(k,v) {
if(key === v.key){
indexFound = k;
}
});
if (indexFound !== false)
{
widget._chosenValues.splice(indexFound, 1);
}
widget._setValue(widget._buildValue());
$li.remove();
setTimeout(function () {
widget.elements.input.focus();
}, 100);
widget._resizeInput();
},
focus : function () {
this.elements.input.focus();
},
_focus : function(ev) {
var
widget = (ev && ev.data.widget) || this,
li = (ev && ev.target) ? $(ev.target).closest('li') : null
;
if (li && li.is('li'))
{
li.find('a').focus();
}
if (!ev || !$(ev.target).closest('li').data('inputosaurus'))
{
widget.elements.input.focus();
}
},
_click : function(ev) {
var widget = (ev && ev.data.widget) || this ;
if (widget.elements.input.val() === '' && !ev || !$(ev.target).closest('li').data('inputosaurus'))
{
if (!widget.options.openedByClick)
{
widget.elements.input.autocomplete("option", "minLength", 0); //for triggering search on empty field
widget.elements.input.autocomplete("search");
setTimeout(function () {
widget.elements.input.autocomplete("option", "minLength", 1);
}.bind(this), 0);
widget.options.openedByClick = true;
}
else
{
widget.options.openedByClick = false;
}
}
},
_tagFocus : function(ev) {
$(ev.currentTarget).parent()[ev.type === 'focusout' ? 'removeClass' : 'addClass']('inputosaurus-selected');
},
refresh : function() {
var val = this.element.val(),
values = [],
aRecipients = AddressUtils.getArrayRecipients(val, true);
values = _.map(aRecipients, function (oRecipient) {
return oRecipient.fullEmail;
});
this._chosenValues = [];
_.isFunction(this.options.parseHook) && (values = this.options.parseHook(values));
this._setChosen(values);
this._renderTags();
this.elements.input.val('');
this._resizeInput();
},
_attachEvents : function() {
var widget = this;
this.elements.input.on('keyup.inputosaurus', {widget : widget}, this._inputKeypress);
this.elements.input.on('keydown.inputosaurus', {widget : widget}, this._inputKeypress);
this.elements.input.on('change.inputosaurus', {widget : widget}, this._inputKeypress);
this.elements.input.on('focus.inputosaurus', {widget : widget}, this._inputFocus);
this.options.parseOnBlur && this.elements.input.on('blur.inputosaurus', {widget : widget}, this.parseInput);
this.elements.input.on('focus.inputosaurus', function () {
widget.elements.input.show();
});
this.elements.ul.on('click.inputosaurus', {widget : widget}, this._click);
this.elements.ul.on('click.inputosaurus', {widget : widget}, this._focus);
this.elements.ul.on('click.inputosaurus', 'a', {widget : widget}, this._removeTag);
this.elements.ul.on('dblclick.inputosaurus', 'li', {widget : widget}, this._editTag);
this.elements.ul.on('focus.inputosaurus', 'a', {widget : widget}, this._tagFocus);
this.elements.ul.on('blur.inputosaurus', 'a', {widget : widget}, this._tagFocus);
this.elements.ul.on('keydown.inputosaurus', 'a', {widget : widget}, this._tagKeypress);
if (widget.options.mobileDevice)
{
this.elements.ul.on('tap.inputosaurus', {widget : widget}, this._focus);
this.elements.ul.on('doubletap.inputosaurus', 'li', {widget : widget}, this._editTag);
}
},
_destroy: function() {
this.elements.input.unbind('.inputosaurus');
this.elements.ul.replaceWith(this.element);
}
};
$.widget("ui.inputosaurus", inputosaurustext);
module.exports = {};