From 10675e419d8524849f71885d6e6eeeb79b2a4ed8 Mon Sep 17 00:00:00 2001 From: Steven Devooght Date: Sat, 13 Jun 2015 11:04:25 +0200 Subject: [PATCH] #23: Fix checking of previous character. --- .gitignore | 190 +---------------------------------- .travis.yml | 6 ++ mention/editor_plugin.js | 2 +- mention/editor_plugin_src.js | 8 +- 4 files changed, 13 insertions(+), 193 deletions(-) create mode 100644 .travis.yml diff --git a/.gitignore b/.gitignore index f6345d5..4a688ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,188 +1,2 @@ -advhr/css/advhr.css -advhr/editor_plugin.js -advhr/editor_plugin_src.js -advhr/js/rule.js -advhr/langs/en_dlg.js -advhr/rule.htm -advimage/css/advimage.css -advimage/editor_plugin.js -advimage/editor_plugin_src.js -advimage/image.htm -advimage/img/sample.gif -advimage/js/image.js -advimage/langs/en_dlg.js -advlink/css/advlink.css -advlink/editor_plugin.js -advlink/editor_plugin_src.js -advlink/js/advlink.js -advlink/langs/en_dlg.js -advlink/link.htm -advlist/editor_plugin.js -advlist/editor_plugin_src.js -autolink/editor_plugin.js -autolink/editor_plugin_src.js -autoresize/editor_plugin.js -autoresize/editor_plugin_src.js -autosave/editor_plugin.js -autosave/editor_plugin_src.js -bbcode/editor_plugin.js -bbcode/editor_plugin_src.js -contextmenu/editor_plugin.js -contextmenu/editor_plugin_src.js -directionality/editor_plugin.js -directionality/editor_plugin_src.js -emotions/editor_plugin.js -emotions/editor_plugin_src.js -emotions/emotions.htm -emotions/img/smiley-cool.gif -emotions/img/smiley-cry.gif -emotions/img/smiley-embarassed.gif -emotions/img/smiley-foot-in-mouth.gif -emotions/img/smiley-frown.gif -emotions/img/smiley-innocent.gif -emotions/img/smiley-kiss.gif -emotions/img/smiley-laughing.gif -emotions/img/smiley-money-mouth.gif -emotions/img/smiley-sealed.gif -emotions/img/smiley-smile.gif -emotions/img/smiley-surprised.gif -emotions/img/smiley-tongue-out.gif -emotions/img/smiley-undecided.gif -emotions/img/smiley-wink.gif -emotions/img/smiley-yell.gif -emotions/js/emotions.js -emotions/langs/en_dlg.js -example/dialog.htm -example/editor_plugin.js -example/editor_plugin_src.js -example/img/example.gif -example/js/dialog.js -example/langs/en.js -example/langs/en_dlg.js -example_dependency/editor_plugin.js -example_dependency/editor_plugin_src.js -fullpage/css/fullpage.css -fullpage/editor_plugin.js -fullpage/editor_plugin_src.js -fullpage/fullpage.htm -fullpage/js/fullpage.js -fullpage/langs/en_dlg.js -fullscreen/editor_plugin.js -fullscreen/editor_plugin_src.js -fullscreen/fullscreen.htm -iespell/editor_plugin.js -iespell/editor_plugin_src.js -inlinepopups/editor_plugin.js -inlinepopups/editor_plugin_src.js -inlinepopups/skins/clearlooks2/img/alert.gif -inlinepopups/skins/clearlooks2/img/button.gif -inlinepopups/skins/clearlooks2/img/buttons.gif -inlinepopups/skins/clearlooks2/img/confirm.gif -inlinepopups/skins/clearlooks2/img/corners.gif -inlinepopups/skins/clearlooks2/img/horizontal.gif -inlinepopups/skins/clearlooks2/img/vertical.gif -inlinepopups/skins/clearlooks2/window.css -inlinepopups/template.htm -insertdatetime/editor_plugin.js -insertdatetime/editor_plugin_src.js -layer/editor_plugin.js -layer/editor_plugin_src.js -legacyoutput/editor_plugin.js -legacyoutput/editor_plugin_src.js -lists/editor_plugin.js -lists/editor_plugin_src.js -media/css/media.css -media/editor_plugin.js -media/editor_plugin_src.js -media/js/embed.js -media/js/media.js -media/langs/en_dlg.js -media/media.htm -media/moxieplayer.swf -nonbreaking/editor_plugin.js -nonbreaking/editor_plugin_src.js -noneditable/editor_plugin.js -noneditable/editor_plugin_src.js -pagebreak/editor_plugin.js -pagebreak/editor_plugin_src.js -paste/editor_plugin.js -paste/editor_plugin_src.js -paste/js/pastetext.js -paste/js/pasteword.js -paste/langs/en_dlg.js -paste/pastetext.htm -paste/pasteword.htm -preview/editor_plugin.js -preview/editor_plugin_src.js -preview/example.html -preview/jscripts/embed.js -preview/preview.html -print/editor_plugin.js -print/editor_plugin_src.js -save/editor_plugin.js -save/editor_plugin_src.js -searchreplace/css/searchreplace.css -searchreplace/editor_plugin.js -searchreplace/editor_plugin_src.js -searchreplace/js/searchreplace.js -searchreplace/langs/en_dlg.js -searchreplace/searchreplace.htm -spellchecker/css/content.css -spellchecker/editor_plugin.js -spellchecker/editor_plugin_src.js -spellchecker/img/wline.gif -style/css/props.css -style/editor_plugin.js -style/editor_plugin_src.js -style/js/props.js -style/langs/en_dlg.js -style/props.htm -style/readme.txt -tabfocus/editor_plugin.js -tabfocus/editor_plugin_src.js -table/cell.htm -table/css/cell.css -table/css/row.css -table/css/table.css -table/editor_plugin.js -table/editor_plugin_src.js -table/js/cell.js -table/js/merge_cells.js -table/js/row.js -table/js/table.js -table/langs/en_dlg.js -table/merge_cells.htm -table/row.htm -table/table.htm -template/blank.htm -template/css/template.css -template/editor_plugin.js -template/editor_plugin_src.js -template/js/template.js -template/langs/en_dlg.js -template/template.htm -visualblocks/css/visualblocks.css -visualblocks/editor_plugin.js -visualblocks/editor_plugin_src.js -visualchars/editor_plugin.js -visualchars/editor_plugin_src.js -wordcount/editor_plugin.js -wordcount/editor_plugin_src.js -xhtmlxtras/abbr.htm -xhtmlxtras/acronym.htm -xhtmlxtras/attributes.htm -xhtmlxtras/cite.htm -xhtmlxtras/css/attributes.css -xhtmlxtras/css/popup.css -xhtmlxtras/del.htm -xhtmlxtras/editor_plugin.js -xhtmlxtras/editor_plugin_src.js -xhtmlxtras/ins.htm -xhtmlxtras/js/abbr.js -xhtmlxtras/js/acronym.js -xhtmlxtras/js/attributes.js -xhtmlxtras/js/cite.js -xhtmlxtras/js/del.js -xhtmlxtras/js/element_common.js -xhtmlxtras/js/ins.js -xhtmlxtras/langs/en_dlg.js +node_modules/ +bower_components/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2ff177a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "0.10" +branches: + only: + - master \ No newline at end of file diff --git a/mention/editor_plugin.js b/mention/editor_plugin.js index 108b3d7..150b6d9 100644 --- a/mention/editor_plugin.js +++ b/mention/editor_plugin.js @@ -1 +1 @@ -(function(e,t){"use strict";var n=function(e,n){this.editor=e;this.options=t.extend({},{source:[],delay:500,queryBy:"name",items:10},n);this.matcher=this.options.matcher||this.matcher;this.renderDropdown=this.options.renderDropdown||this.renderDropdown;this.render=this.options.render||this.render;this.insert=this.options.insert||this.insert;this.highlighter=this.options.highlighter||this.highlighter;this.query="";this.hasFocus=true;this.renderInput();this.bindEvents()};n.prototype={constructor:n,renderInput:function(){var e=''+''+this.options.delimiter+""+'\ufeff'+"";this.editor.execCommand("mceInsertContent",false,e);this.editor.focus();this.editor.selection.select(this.editor.selection.dom.select("span#autocomplete-searchtext span")[0]);this.editor.selection.collapse(0)},bindEvents:function(){this.editor.onKeyUp.addToTop(this.editorKeyUpProxy=t.proxy(this.rteKeyUp,this));this.editor.onKeyDown.addToTop(this.editorKeyDownProxy=t.proxy(this.rteKeyDown,this));this.editor.onClick.addToTop(this.editorClickProxy=t.proxy(this.rteClicked,this));t(this.editor.getWin()).on("scroll",this.rteScroll=t.proxy(function(){this.cleanUp(true)},this));t("body").on("click",this.bodyClickProxy=t.proxy(this.rteLostFocus,this))},unbindEvents:function(){this.editor.onKeyUp.remove(this.editorKeyUpProxy);this.editor.onKeyDown.remove(this.editorKeyDownProxy);this.editor.onClick.remove(this.editorClickProxy);t(this.editor.getWin()).off("scroll",this.rteScroll);t("body").off("click",this.bodyClickProxy)},rteKeyUp:function(e,t){switch(t.which||t.keyCode){case 40:case 38:case 16:case 17:case 18:break;case 8:if(this.query===""){this.cleanUp(true)}else{this.lookup()}break;case 9:case 13:var n=this.$dropdown!==undefined?this.$dropdown.find("li.active"):[];if(n.length){this.select(n.data());this.cleanUp(false)}else{this.cleanUp(true)}break;case 27:this.cleanUp(true);break;default:this.lookup()}},rteKeyDown:function(e,t){switch(t.which||t.keyCode){case 9:case 13:case 27:t.preventDefault();break;case 8:return false;case 38:t.preventDefault();if(this.$dropdown!==undefined){this.highlightPreviousResult()}break;case 40:t.preventDefault();if(this.$dropdown!==undefined){this.highlightNextResult()}break}t.stopPropagation()},rteClicked:function(e,n){var r=t(n.target);if(this.hasFocus&&r.parent().attr("id")!=="autocomplete-searchtext"){this.cleanUp(true)}},rteLostFocus:function(e,t){if(this.hasFocus){this.cleanUp(true)}},lookup:function(){this.query=t.trim(t(this.editor.getBody()).find("#autocomplete-searchtext").text()).replace("","");clearTimeout(this.searchTimeout);this.searchTimeout=setTimeout(t.proxy(function(){var e=t.isFunction(this.options.source)?this.options.source(this.query,t.proxy(this.process,this)):this.options.source;if(e){this.process(e)}},this),this.options.delay)},matcher:function(e){return~e[this.options.queryBy].toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(e){var t=[],n=[],r=[],i;while((i=e.shift())!==undefined){if(!i[this.options.queryBy].toLowerCase().indexOf(this.query.toLowerCase()))t.push(i);else if(~i[this.options.queryBy].indexOf(this.query))n.push(i);else r.push(i)}return t.concat(n,r)},highlighter:function(e){return e.replace(new RegExp("("+this.query+")","ig"),function(e,t){return""+t+""})},show:function(){var e=t(this.editor.getContainer()).offset(),n=t(this.editor.getContainer()).find(".mceToolbar").first(),r=t(this.editor.dom.select("span#autocomplete")).position(),i=e.top+n.innerHeight()+r.top+t(this.editor.selection.getNode()).innerHeight()-t(this.editor.getDoc()).scrollTop()+5,s=e.left+r.left;this.$dropdown=t(this.renderDropdown()).css({top:i,left:s});t("body").append(this.$dropdown);this.$dropdown.on("click",t.proxy(this.autoCompleteClick,this))},process:function(e){if(!this.hasFocus){return}if(this.$dropdown===undefined){this.show()}var n=this,r=[],i=t.grep(e,function(e){return n.matcher(e)});i=n.sorter(i);i=i.slice(0,this.options.items);t.each(i,function(e,s){var o=t(n.render(s));o.html(o.html().replace(o.text(),n.highlighter(o.text())));t.each(i[e],function(e,t){o.attr("data-"+e,t)});r.push(o[0].outerHTML)});if(r.length){this.$dropdown.html(r.join("")).show()}else{this.$dropdown.hide()}},renderDropdown:function(){return''},render:function(e){return"
  • "+''+e.name+""+"
  • "},autoCompleteClick:function(e){var n=t(e.target).closest("li").data();if(!t.isEmptyObject(n)){this.select(n);this.cleanUp(false)}e.stopPropagation();e.preventDefault()},highlightPreviousResult:function(){var e=this.$dropdown.find("li.active").index(),t=e===0?this.$dropdown.find("li").length-1:e-=1;this.$dropdown.find("li").removeClass("active").eq(t).addClass("active")},highlightNextResult:function(){var e=this.$dropdown.find("li.active").index(),t=e===this.$dropdown.find("li").length-1?0:e+=1;this.$dropdown.find("li").removeClass("active").eq(t).addClass("active")},select:function(e){var t=this.editor.dom.select("span#autocomplete")[0];this.editor.dom.remove(t);this.editor.execCommand("mceInsertContent",false,this.insert(e)+" ")},insert:function(e){return""+e.name+""},cleanUp:function(e){this.unbindEvents();this.hasFocus=false;if(this.$dropdown!==undefined){this.$dropdown.remove();delete this.$dropdown}if(e){var n=this.query,r=t(this.editor.dom.select("span#autocomplete")),i=t("

    "+this.options.delimiter+n+"

    ")[0].firstChild,s=t(this.editor.selection.getNode()).offset().top===r.offset().top+(r.outerHeight()-r.height())/2;this.editor.dom.replace(i,r[0]);if(s){this.editor.selection.select(i);this.editor.selection.collapse()}}}};e.create("tinymce.plugins.Mention",{init:function(e,r){function o(){var n=t(e.selection.getNode().outerHTML),r=n.text(),i=r.substr(r.length-1,1);return!!t.trim(i).length?false:true}var i,s=e.getParam("mentions");s.delimiter=s.delimiter||"@";e.onKeyPress.add(function(e,t){if(String.fromCharCode(t.which||t.keyCode)===s.delimiter&&o()){if(i===undefined||i.hasFocus!==undefined&&!i.hasFocus){t.preventDefault();i=new n(e,s)}}})},getInfo:function(){return{longname:"mention",author:"Steven Devooght",version:e.majorVersion+"."+e.minorVersion}}});e.PluginManager.add("mention",e.plugins.Mention)})(tinymce,jQuery) \ No newline at end of file +!function(a,b){"use strict";var c=function(a,c){this.editor=a,this.options=b.extend({},{source:[],delay:500,queryBy:"name",items:10},c),this.matcher=this.options.matcher||this.matcher,this.renderDropdown=this.options.renderDropdown||this.renderDropdown,this.render=this.options.render||this.render,this.insert=this.options.insert||this.insert,this.highlighter=this.options.highlighter||this.highlighter,this.query="",this.hasFocus=!0,this.renderInput(),this.bindEvents()};c.prototype={constructor:c,renderInput:function(){var a=''+this.options.delimiter+""+'\ufeff'+"";this.editor.execCommand("mceInsertContent",!1,a),this.editor.focus(),this.editor.selection.select(this.editor.selection.dom.select("span#autocomplete-searchtext span")[0]),this.editor.selection.collapse(0)},bindEvents:function(){this.editor.onKeyUp.addToTop(this.editorKeyUpProxy=b.proxy(this.rteKeyUp,this)),this.editor.onKeyDown.addToTop(this.editorKeyDownProxy=b.proxy(this.rteKeyDown,this)),this.editor.onClick.addToTop(this.editorClickProxy=b.proxy(this.rteClicked,this)),b(this.editor.getWin()).on("scroll",this.rteScroll=b.proxy(function(){this.cleanUp(!0)},this)),b("body").on("click",this.bodyClickProxy=b.proxy(this.rteLostFocus,this))},unbindEvents:function(){this.editor.onKeyUp.remove(this.editorKeyUpProxy),this.editor.onKeyDown.remove(this.editorKeyDownProxy),this.editor.onClick.remove(this.editorClickProxy),b(this.editor.getWin()).off("scroll",this.rteScroll),b("body").off("click",this.bodyClickProxy)},rteKeyUp:function(a,b){switch(b.which||b.keyCode){case 40:case 38:case 16:case 17:case 18:break;case 8:""===this.query?this.cleanUp(!0):this.lookup();break;case 9:case 13:var c=void 0!==this.$dropdown?this.$dropdown.find("li.active"):[];c.length?(this.select(c.data()),this.cleanUp(!1)):this.cleanUp(!0);break;case 27:this.cleanUp(!0);break;default:this.lookup()}},rteKeyDown:function(a,b){switch(b.which||b.keyCode){case 9:case 13:case 27:b.preventDefault();break;case 8:return!1;case 38:b.preventDefault(),void 0!==this.$dropdown&&this.highlightPreviousResult();break;case 40:b.preventDefault(),void 0!==this.$dropdown&&this.highlightNextResult()}b.stopPropagation()},rteClicked:function(a,c){var d=b(c.target);this.hasFocus&&"autocomplete-searchtext"!==d.parent().attr("id")&&this.cleanUp(!0)},rteLostFocus:function(){this.hasFocus&&this.cleanUp(!0)},lookup:function(){this.query=b.trim(b(this.editor.getBody()).find("#autocomplete-searchtext").text()).replace("\ufeff",""),clearTimeout(this.searchTimeout),this.searchTimeout=setTimeout(b.proxy(function(){var a=b.isFunction(this.options.source)?this.options.source(this.query,b.proxy(this.process,this)):this.options.source;a&&this.process(a)},this),this.options.delay)},matcher:function(a){return~a[this.options.queryBy].toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(a){for(var e,b=[],c=[],d=[];void 0!==(e=a.shift());)e[this.options.queryBy].toLowerCase().indexOf(this.query.toLowerCase())?~e[this.options.queryBy].indexOf(this.query)?c.push(e):d.push(e):b.push(e);return b.concat(c,d)},highlighter:function(a){return a.replace(new RegExp("("+this.query+")","ig"),function(a,b){return""+b+""})},show:function(){var a=b(this.editor.getContainer()).offset(),c=b(this.editor.getContainer()).find(".mceToolbar").first(),d=b(this.editor.dom.select("span#autocomplete")).position(),e=a.top+c.innerHeight()+d.top+b(this.editor.selection.getNode()).innerHeight()-b(this.editor.getDoc()).scrollTop()+5,f=a.left+d.left;this.$dropdown=b(this.renderDropdown()).css({top:e,left:f}),b("body").append(this.$dropdown),this.$dropdown.on("click",b.proxy(this.autoCompleteClick,this))},process:function(a){if(this.hasFocus){void 0===this.$dropdown&&this.show();var c=this,d=[],e=b.grep(a,function(a){return c.matcher(a)});e=c.sorter(e),e=e.slice(0,this.options.items),b.each(e,function(a,f){var g=b(c.render(f));g.html(g.html().replace(g.text(),c.highlighter(g.text()))),b.each(e[a],function(a,b){g.attr("data-"+a,b)}),d.push(g[0].outerHTML)}),d.length?this.$dropdown.html(d.join("")).show():this.$dropdown.hide()}},renderDropdown:function(){return''},render:function(a){return'
  • '+a.name+""+"
  • "},autoCompleteClick:function(a){var c=b(a.target).closest("li").data();b.isEmptyObject(c)||(this.select(c),this.cleanUp(!1)),a.stopPropagation(),a.preventDefault()},highlightPreviousResult:function(){var a=this.$dropdown.find("li.active").index(),b=0===a?this.$dropdown.find("li").length-1:a-=1;this.$dropdown.find("li").removeClass("active").eq(b).addClass("active")},highlightNextResult:function(){var a=this.$dropdown.find("li.active").index(),b=a===this.$dropdown.find("li").length-1?0:a+=1;this.$dropdown.find("li").removeClass("active").eq(b).addClass("active")},select:function(a){var b=this.editor.dom.select("span#autocomplete")[0];this.editor.dom.remove(b),this.editor.execCommand("mceInsertContent",!1,this.insert(a)+" ")},insert:function(a){return""+a.name+""},cleanUp:function(a){if(this.unbindEvents(),this.hasFocus=!1,void 0!==this.$dropdown&&(this.$dropdown.remove(),delete this.$dropdown),a){var c=this.query,d=b(this.editor.dom.select("span#autocomplete")),e=b("

    "+this.options.delimiter+c+"

    ")[0].firstChild,f=b(this.editor.selection.getNode()).offset().top===d.offset().top+(d.outerHeight()-d.height())/2;this.editor.dom.replace(e,d[0]),f&&(this.editor.selection.select(e),this.editor.selection.collapse())}}},a.create("tinymce.plugins.Mention",{init:function(a){function g(){var c=a.selection.getRng(),d=c.startOffset>0?c.startOffset-1:0,e=void 0===c.startContainer.data?" ":c.startContainer.data[d];return b.trim(e).length?!1:!0}var e,f=a.getParam("mentions");f.delimiter=f.delimiter||"@",a.onKeyPress.add(function(a,b){String.fromCharCode(b.which||b.keyCode)===f.delimiter&&g()&&(void 0===e||void 0!==e.hasFocus&&!e.hasFocus)&&(b.preventDefault(),e=new c(a,f))})},getInfo:function(){return{longname:"mention",author:"Steven Devooght",version:a.majorVersion+"."+a.minorVersion}}}),a.PluginManager.add("mention",a.plugins.Mention)}(tinymce,jQuery); \ No newline at end of file diff --git a/mention/editor_plugin_src.js b/mention/editor_plugin_src.js index 533516b..9e8534a 100644 --- a/mention/editor_plugin_src.js +++ b/mention/editor_plugin_src.js @@ -320,11 +320,11 @@ autoCompleteData.delimiter = autoCompleteData.delimiter || '@'; function prevCharIsSpace() { - var $node = $(ed.selection.getNode().outerHTML), - text = $node.text(), - charachter = text.substr(text.length - 1, 1); + var range = ed.selection.getRng(), + startOffset = range.startOffset > 0 ? range.startOffset - 1 : 0, + character = range.startContainer.data === undefined ? ' ' : range.startContainer.data[startOffset]; - return (!!$.trim(charachter).length) ? false : true; + return (!!$.trim(character).length) ? false : true; } ed.onKeyPress.add(function(ed, e){