]> git.mxchange.org Git - friendica.git/commitdiff
tinymce autocomplete
authorFriendika <info@friendika.com>
Fri, 4 Nov 2011 08:52:03 +0000 (01:52 -0700)
committerFriendika <info@friendika.com>
Fri, 4 Nov 2011 08:52:03 +0000 (01:52 -0700)
js/fk.autocomplete.js

index 45de0cb2dd306bd53bd7bab1c8a7d878085de592..3f73c6fbbd5fbf2c95de9d62f529b409585854ca 100644 (file)
@@ -20,11 +20,11 @@ function ACPopup(elm,backend_url){
                h = $(elm).height();
        }
        else {
-               style = $('.profile-jot-text').offset();
-               w = 300;
-               h = 150;
+               style = $(elm.container).offset();
+               w = elm.container.offsetWidth;
+               h = elm.container.offsetHeight;
+       }
 
-       } 
        style.top=style.top+h;
        style.width = w;
        style.position = 'absolute';
@@ -73,7 +73,7 @@ ACPopup.prototype._search = function(){
                                that.cont.show();
                                $(data.items).each(function(){
                                        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 {
                                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 elm = $("<div class='acpopupitem' title='"+value+"'>"+label+"</div>");
        elm.click(function(e){
-                       t = $(this).attr('title').replace(new RegExp(' \- .*'),'');
-               el=$(that.element);
-               sel = el.getSelection();
-               sel.start = sel.start- that.searchText.length;
-               el.setSelection(sel.start,sel.end).replaceSelectedText(t).collapseSelection(false);
-               that.close();
+               t = $(this).attr('title').replace(new RegExp(' \- .*'),'');
+               if(typeof(that.element.container) === "undefined") {
+                       el=$(that.element);
+                       sel = el.getSelection();
+                       sel.start = sel.start- that.searchText.length;
+                       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);
 }