]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Autocomplete/Autocomplete.js
Use Notice_bookmark::saveNew() from NewbookmarkAction
[quix0rs-gnu-social.git] / plugins / Autocomplete / Autocomplete.js
index e799c11e50ae14ced17c0bf9ddb3e58f2bee4cd5..c3f022702ac0fb107e11a29d67ec859df3be6306 100644 (file)
@@ -1,38 +1,38 @@
 $(document).ready(function(){
-    $.getJSON($('address .url')[0].href+'/api/statuses/friends.json?user_id=' + current_user['id'] + '&lite=true&callback=?',
-        function(friends){
-            $('#notice_data-text').autocomplete(friends, {
-                multiple: true,
-                multipleSeparator: " ",
-                minChars: 1,
-                formatItem: function(row, i, max){
-                    return '@' + row.screen_name + ' (' + row.name + ')';
-                },
-                formatMatch: function(row, i, max){
-                    return '@' + row.screen_name;
-                },
-                formatResult: function(row){
-                    return '@' + row.screen_name;
-                }
-            });
+    function fullName(row) {
+        if (typeof row.fullname == "string" && row.fullname != '') {
+            return row.nickname + ' (' + row.fullname + ')';
+        } else {
+            return row.nickname;
         }
-    );
-    $.getJSON($('address .url')[0].href+'/api/laconica/groups/list.json?user_id=' + current_user['id'] + '&callback=?',
-        function(groups){
-            $('#notice_data-text').autocomplete(groups, {
-                multiple: true,
-                multipleSeparator: " ",
-                minChars: 1,
-                formatItem: function(row, i, max){
-                    return '!' + row.nickname + ' (' + row.fullname + ')';
-                },
-                formatMatch: function(row, i, max){
+    }
+    $('#notice_data-text').autocomplete($('address .url')[0].href+'main/autocomplete/suggest', {
+        multiple: true,
+        multipleSeparator: " ",
+        minChars: 1,
+        formatItem: function(row, i, max){
+            row = eval("(" + row + ")");
+            // the display:inline is because our INSANE stylesheets
+            // override the standard display of all img tags for no
+            // good reason.
+            var div = $('<div><img style="display:inline; vertical-align: middle"> <span></span></div>')
+                .find('img').attr('src', row.avatar).end()
+                .find('span').text(fullName(row)).end()
+            return div.html();
+        },
+        formatMatch: function(row, i, max){
+            row = eval("(" + row + ")");
+            return row.nickname;
+        },
+        formatResult: function(row){
+            row = eval("(" + row + ")");
+            switch(row.type)
+            {
+                case 'user':
+                    return '@' + row.nickname;
+                case 'group':
                     return '!' + row.nickname;
-                },
-                formatResult: function(row){
-                    return '!' + row.nickname;
-                }
-            });
+            }
         }
-    );
+    });
 });