From e19b5971804f0e07d7f3e4ad6d7b71e05ff49ed5 Mon Sep 17 00:00:00 2001 From: Friendika Date: Thu, 3 Nov 2011 20:40:56 -0700 Subject: [PATCH 1/2] tinymce tag complete stuff --- js/fk.autocomplete.js | 28 ++++++++++++++++++---------- view/jot-header.tpl | 25 ++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/js/fk.autocomplete.js b/js/fk.autocomplete.js index c17d61fc57..45de0cb2dd 100644 --- a/js/fk.autocomplete.js +++ b/js/fk.autocomplete.js @@ -13,20 +13,28 @@ function ACPopup(elm,backend_url){ this.ready=true; this.kp_timer = false; this.url = backend_url; - - style = $(elm).offset(); - w = $(elm).width(); - h = $(elm).height(); + + if(typeof elm.editorId == "undefined") { + style = $(elm).offset(); + w = $(elm).width(); + h = $(elm).height(); + } + else { + style = $('.profile-jot-text').offset(); + w = 300; + h = 150; + + } style.top=style.top+h; style.width = w; style.position = 'absolute'; -/* style['max-height'] = '150px'; - style.border = '1px solid red'; - style.background = '#cccccc'; + /* style['max-height'] = '150px'; + style.border = '1px solid red'; + style.background = '#cccccc'; - style.overflow = 'auto'; - style['z-index'] = '100000'; -*/ + style.overflow = 'auto'; + style['z-index'] = '100000'; + */ style.display = 'none'; this.cont = $("
"); diff --git a/view/jot-header.tpl b/view/jot-header.tpl index ecf27e1b17..9ded3e9b43 100644 --- a/view/jot-header.tpl +++ b/view/jot-header.tpl @@ -30,9 +30,26 @@ function initEditor(cb){ content_css: "$baseurl/view/custom_tinymce.css", theme_advanced_path : false, setup : function(ed) { - //Character count + cPopup = null; + ed.onKeyDown.add(function(ed,e) { + if(cPopup !== null) + cPopup.onkey(e); + }); + ed.onKeyUp.add(function(ed, e) { var txt = tinyMCE.activeEditor.getContent(); + match = txt.match(/@([^ \n]+)$/); + if(match!==null) { + if(cPopup === null) { + cPopup = new ACPopup(this,baseurl+"/acl"); + } + if(cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]); + if(! cPopup.ready) cPopup = null; + } + else { + if(cPopup !== null) { cPopup.close(); cPopup = null; } + } + textlen = txt.length; if(textlen != 0 && $('#jot-perms-icon').is('.unlock')) { $('#profile-jot-desc').html(ispublic); @@ -41,6 +58,8 @@ function initEditor(cb){ $('#profile-jot-desc').html(' '); } + //Character count + if(textlen <= 140) { $('#character-counter').removeClass('red'); $('#character-counter').removeClass('orange'); @@ -71,8 +90,8 @@ function initEditor(cb){ editor = true; // setup acl popup $("a#jot-perms-icon").fancybox({ - 'transitionIn' : 'none', - 'transitionOut' : 'none' + 'transitionIn' : 'elastic', + 'transitionOut' : 'elastic' }); } else { if (typeof cb!="undefined") cb(); From 51b0f583b0b4f9e9f7a2fcfdf27332c905cc1011 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 4 Nov 2011 01:52:03 -0700 Subject: [PATCH 2/2] tinymce autocomplete --- js/fk.autocomplete.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/js/fk.autocomplete.js b/js/fk.autocomplete.js index 45de0cb2dd..3f73c6fbbd 100644 --- a/js/fk.autocomplete.js +++ b/js/fk.autocomplete.js @@ -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 = "{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 = $("
"+label+"
"); 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); }