tinymce autocomplete

This commit is contained in:
Friendika 2011-11-04 01:52:03 -07:00
parent e19b597180
commit 51b0f583b0

View file

@ -20,11 +20,11 @@ function ACPopup(elm,backend_url){
h = $(elm).height(); h = $(elm).height();
} }
else { else {
style = $('.profile-jot-text').offset(); style = $(elm.container).offset();
w = 300; w = elm.container.offsetWidth;
h = 150; h = elm.container.offsetHeight;
}
}
style.top=style.top+h; style.top=style.top+h;
style.width = w; style.width = w;
style.position = 'absolute'; style.position = 'absolute';
@ -73,7 +73,7 @@ ACPopup.prototype._search = function(){
that.cont.show(); that.cont.show();
$(data.items).each(function(){ $(data.items).each(function(){
html = "<img src='{0}' height='16px' width='16px'>{1} ({2})".format(this.photo, this.name, this.nick) html = "<img src='{0}' height='16px' width='16px'>{1} ({2})".format(this.photo, this.name, this.nick)
that.add(html, this.nick + '+' + this.id + ' - ' + this.link); that.add(html, this.nick + '+' + this.id + ' - ' + this.link);
}); });
} else { } else {
that.cont.hide(); that.cont.hide();
@ -82,16 +82,25 @@ ACPopup.prototype._search = function(){
}); });
} }
ACPopup.prototype.add = function(label, value){ ACPopup.prototype.add = function(label, value){
var that=this; var that=this;
var elm = $("<div class='acpopupitem' title='"+value+"'>"+label+"</div>"); var elm = $("<div class='acpopupitem' title='"+value+"'>"+label+"</div>");
elm.click(function(e){ elm.click(function(e){
t = $(this).attr('title').replace(new RegExp(' \- .*'),''); t = $(this).attr('title').replace(new RegExp(' \- .*'),'');
el=$(that.element); if(typeof(that.element.container) === "undefined") {
sel = el.getSelection(); el=$(that.element);
sel.start = sel.start- that.searchText.length; sel = el.getSelection();
el.setSelection(sel.start,sel.end).replaceSelectedText(t).collapseSelection(false); sel.start = sel.start- that.searchText.length;
that.close(); el.setSelection(sel.start,sel.end).replaceSelectedText(t+' ').collapseSelection(false);
that.close();
}
else {
txt = tinyMCE.activeEditor.getContent();
newtxt = txt.replace(that.searchText,t+' ');
tinyMCE.activeEditor.setContent(newtxt);
tinyMCE.activeEditor.focus();
that.close();
}
}); });
$(this.cont).append(elm); $(this.cont).append(elm);
} }