diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 00000000..2af5d7a9 --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,26 @@ +name: repo-checks + +on: + push: + branches: + - master + - stable + - beta + pull_request: + +jobs: + main: + name: node_js + runs-on: [self-hosted, zendesk-stable] + steps: + - uses: zendesk/checkout@v2 + - uses: zendesk/setup-node@v2.0.0 + with: + node-version: '4' + - name: test + run: | + npm install -g gulp + npm install -g bower + bower install + npm test + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 42125148..00000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: node_js -node_js: - - "4" -notifications: - email: - on_success: never # default: change - on_failure: change # default: always -branches: - only: - - master - - stable - - beta -before_script: - - npm install -g gulp - - npm install -g bower - - bower install diff --git a/README.md b/README.md index 551820af..f84883e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ **An autocompletion library to autocomplete mentions, smileys etc. just like on Github!** -[![Build Status](https://travis-ci.org/ichord/At.js.png)](https://travis-ci.org/ichord/At.js) +![repo-checks](https://github.com/zendesk/At.js/workflows/repo-checks/badge.svg) #### Notice At.js now **depends on** [Caret.js](https://github.com/ichord/Caret.js). diff --git a/bower.json b/bower.json index 3f569a97..1f07ae36 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "At.js", - "version": "1.5.3", + "version": "1.5.7", "main": [ "dist/js/jquery.atwho.js", "dist/css/jquery.atwho.css" diff --git a/component.json b/component.json index 645144f7..51ea70ed 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "At.js", "repo": "ichord/At.js", "description": "Add Github like mentions autocomplete to your application.", - "version": "1.5.3", + "version": "1.5.7", "demo": "http://ichord.github.com/At.js", "dependencies": { "ichord/Caret.js": "~0.2.2", diff --git a/dist/js/jquery.atwho.js b/dist/js/jquery.atwho.js index 6e4ddc13..64380420 100644 --- a/dist/js/jquery.atwho.js +++ b/dist/js/jquery.atwho.js @@ -1,6 +1,6 @@ /** - * at.js - 1.5.3 - * Copyright (c) 2017 chord.luo ; + * at.js - 1.5.7 + * Copyright (c) 2018 chord.luo ; * Homepage: http://ichord.github.com/At.js * License: MIT */ @@ -19,6 +19,7 @@ factory(jQuery); } }(this, function ($) { + var DEFAULT_CALLBACKS, KEY_CODE; KEY_CODE = { @@ -215,7 +216,7 @@ App = (function() { })(this)).on('compositionend', (function(_this) { return function(e) { _this.isComposing = false; - setTimeout(function(e) { + setTimeout(function() { return _this.dispatch(e); }); return null; @@ -294,7 +295,6 @@ App = (function() { case KEY_CODE.DOWN: case KEY_CODE.UP: case KEY_CODE.CTRL: - case KEY_CODE.ENTER: $.noop(); break; case KEY_CODE.P: @@ -710,6 +710,9 @@ EditableController = (function(superClass) { if (!range.collapsed) { return; } + if (!e) { + return; + } if (e.which === KEY_CODE.ENTER) { ($query = $(range.startContainer).closest('.atwho-query')).contents().unwrap(); if ($query.is(':empty')) { @@ -832,13 +835,13 @@ EditableController = (function(superClass) { } suffix = (suffix = this.getOpt('suffix')) === "" ? suffix : suffix || "\u00A0"; data = $li.data('item-data'); - this.query.el.removeClass('atwho-query').addClass('atwho-inserted').html(content).attr('data-atwho-at-query', "" + data['atwho-at'] + this.query.text).attr('contenteditable', "false"); + this.query.el.removeClass('atwho-query').addClass('atwho-inserted').html(content).attr('data-atwho-at-query', "" + data['atwho-at'] + this.query.text); if (range = this._getRange()) { if (this.query.el.length) { range.setEndAfter(this.query.el[0]); } range.collapse(false); - range.insertNode(suffixNode = this.app.document.createTextNode("" + suffix)); + range.insertNode(suffixNode = this.app.document.createTextNode("\u200B" + suffix)); this._setRange('after', suffixNode, range); } if (!this.$inputor.is(':focus')) { diff --git a/dist/js/jquery.atwho.min.js b/dist/js/jquery.atwho.min.js index d8002b27..c4ab2e57 100644 --- a/dist/js/jquery.atwho.min.js +++ b/dist/js/jquery.atwho.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(["jquery"],function(t){return e(t)}):"object"==typeof exports?module.exports=e(require("jquery")):e(jQuery)}(this,function(t){var e,i;i={ESC:27,TAB:9,ENTER:13,CTRL:17,A:65,P:80,N:78,LEFT:37,UP:38,RIGHT:39,DOWN:40,BACKSPACE:8,SPACE:32},e={beforeSave:function(t){return r.arrayToDefaultHash(t)},matcher:function(t,e,i,n){var r,o,s,a,h;return t=t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),i&&(t="(?:^|\\s)"+t),r=decodeURI("%C3%80"),o=decodeURI("%C3%BF"),h=n?" ":"",a=new RegExp(t+"([A-Za-z"+r+"-"+o+"0-9_"+h+"'.+-]*)$|"+t+"([^\\x00-\\xff]*)$","gi"),s=a.exec(e),s?s[2]||s[1]:null},filter:function(t,e,i){var n,r,o,s;for(n=[],r=0,s=e.length;r-1&&n.push(o);return n.sort(function(t,e){return t.atwho_order-e.atwho_order})},tplEval:function(t,e){var i,n;n=t;try{return"string"!=typeof t&&(n=t(e)),n.replace(/\$\{([^\}]*)\}/g,function(t,i,n){return e[i]})}catch(r){return i=r,""}},highlighter:function(t,e){var i;return e?(i=new RegExp(">\\s*([^<]*?)("+e.replace("+","\\+")+")([^<]*)\\s*<","ig"),t.replace(i,function(t,e,i,n){return"> "+e+""+i+""+n+" <"})):t},beforeInsert:function(t,e,i){return t},beforeReposition:function(t){return t},afterMatchFailed:function(t,e){}};var n;n=function(){function e(e){this.currentFlag=null,this.controllers={},this.aliasMaps={},this.$inputor=t(e),this.setupRootElement(),this.listen()}return e.prototype.createContainer=function(e){var i;return null!=(i=this.$el)&&i.remove(),t(e.body).append(this.$el=t("
"))},e.prototype.setupRootElement=function(e,i){var n;if(null==i&&(i=!1),e)this.window=e.contentWindow,this.document=e.contentDocument||this.window.document,this.iframe=e;else{this.document=this.$inputor[0].ownerDocument,this.window=this.document.defaultView||this.document.parentWindow;try{this.iframe=this.window.frameElement}catch(r){if(n=r,this.iframe=null,t.fn.atwho.debug)throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.\n"+n)}}return this.createContainer((this.iframeAsRoot=i)?this.document:document)},e.prototype.controller=function(t){var e,i,n,r;if(this.aliasMaps[t])i=this.controllers[this.aliasMaps[t]];else{r=this.controllers;for(n in r)if(e=r[n],n===t){i=e;break}}return i?i:this.controllers[this.currentFlag]},e.prototype.setContextFor=function(t){return this.currentFlag=t,this},e.prototype.reg=function(t,e){var i,n;return n=(i=this.controllers)[t]||(i[t]=this.$inputor.is("[contentEditable]")?new l(this,t):new s(this,t)),e.alias&&(this.aliasMaps[e.alias]=t),n.init(e),this},e.prototype.listen=function(){return this.$inputor.on("compositionstart",function(t){return function(e){var i;return null!=(i=t.controller())&&i.view.hide(),t.isComposing=!0,null}}(this)).on("compositionend",function(t){return function(e){return t.isComposing=!1,setTimeout(function(e){return t.dispatch(e)}),null}}(this)).on("keyup.atwhoInner",function(t){return function(e){return t.onKeyup(e)}}(this)).on("keydown.atwhoInner",function(t){return function(e){return t.onKeydown(e)}}(this)).on("blur.atwhoInner",function(t){return function(e){var i;if(i=t.controller())return i.expectedQueryCBId=null,i.view.hide(e,i.getOpt("displayTimeout"))}}(this)).on("click.atwhoInner",function(t){return function(e){return t.dispatch(e)}}(this)).on("scroll.atwhoInner",function(t){return function(){var e;return e=t.$inputor.scrollTop(),function(i){var n,r;return n=i.target.scrollTop,e!==n&&null!=(r=t.controller())&&r.view.hide(i),e=n,!0}}}(this)())},e.prototype.shutdown=function(){var t,e,i;i=this.controllers;for(t in i)e=i[t],e.destroy(),delete this.controllers[t];return this.$inputor.off(".atwhoInner"),this.$el.remove()},e.prototype.dispatch=function(t){var e,i,n,r;n=this.controllers,r=[];for(e in n)i=n[e],r.push(i.lookUp(t));return r},e.prototype.onKeyup=function(e){var n;switch(e.keyCode){case i.ESC:e.preventDefault(),null!=(n=this.controller())&&n.view.hide();break;case i.DOWN:case i.UP:case i.CTRL:case i.ENTER:t.noop();break;case i.P:case i.N:e.ctrlKey||this.dispatch(e);break;default:this.dispatch(e)}},e.prototype.onKeydown=function(e){var n,r;if(r=null!=(n=this.controller())?n.view:void 0,r&&r.visible())switch(e.keyCode){case i.ESC:e.preventDefault(),r.hide(e);break;case i.UP:e.preventDefault(),r.prev();break;case i.DOWN:e.preventDefault(),r.next();break;case i.P:if(!e.ctrlKey)return;e.preventDefault(),r.prev();break;case i.N:if(!e.ctrlKey)return;e.preventDefault(),r.next();break;case i.TAB:case i.ENTER:case i.SPACE:if(!r.visible())return;if(!this.controller().getOpt("spaceSelectsMatch")&&e.keyCode===i.SPACE)return;if(!this.controller().getOpt("tabSelectsMatch")&&e.keyCode===i.TAB)return;r.highlighted()?(e.preventDefault(),r.choose(e)):r.hide(e);break;default:t.noop()}},e}();var r,o=[].slice;r=function(){function i(e,i){this.app=e,this.at=i,this.$inputor=this.app.$inputor,this.id=this.$inputor[0].id||this.uid(),this.expectedQueryCBId=null,this.setting=null,this.query=null,this.pos=0,this.range=null,0===(this.$el=t("#atwho-ground-"+this.id,this.app.$el)).length&&this.app.$el.append(this.$el=t("
")),this.model=new u(this),this.view=new c(this)}return i.prototype.uid=function(){return(Math.random().toString(16)+"000000000").substr(2,8)+(new Date).getTime()},i.prototype.init=function(e){return this.setting=t.extend({},this.setting||t.fn.atwho["default"],e),this.view.init(),this.model.reload(this.setting.data)},i.prototype.destroy=function(){return this.trigger("beforeDestroy"),this.model.destroy(),this.view.destroy(),this.$el.remove()},i.prototype.callDefault=function(){var i,n,r;r=arguments[0],i=2<=arguments.length?o.call(arguments,1):[];try{return e[r].apply(this,i)}catch(s){return n=s,t.error(n+" Or maybe At.js doesn't have function "+r)}},i.prototype.trigger=function(t,e){var i,n;return null==e&&(e=[]),e.push(this),i=this.getOpt("alias"),n=i?t+"-"+i+".atwho":t+".atwho",this.$inputor.trigger(n,e)},i.prototype.callbacks=function(t){return this.getOpt("callbacks")[t]||e[t]},i.prototype.getOpt=function(t,e){var i;try{return this.setting[t]}catch(n){return i=n,null}},i.prototype.insertContentFor=function(e){var i,n;return n=this.getOpt("insertTpl"),i=t.extend({},e.data("item-data"),{"atwho-at":this.at}),this.callbacks("tplEval").call(this,n,i,"onInsert")},i.prototype.renderView=function(t){var e;return e=this.getOpt("searchKey"),t=this.callbacks("sorter").call(this,this.query.text,t.slice(0,1001),e),this.view.render(t.slice(0,this.getOpt("limit")))},i.arrayToDefaultHash=function(e){var i,n,r,o;if(!t.isArray(e))return e;for(o=[],i=0,r=e.length;i0?this.renderView(this.constructor.arrayToDefaultHash(e)):this.view.hide()},this.expectedQueryCBId=this._generateQueryCBId(),this.model.query(e.text,t.proxy(i,this,this.expectedQueryCBId))},i}();var s,a=function(t,e){function i(){this.constructor=t}for(var n in e)h.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},h={}.hasOwnProperty;s=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return a(i,e),i.prototype.catchQuery=function(){var t,e,i,n,r,o,s;if(e=this.$inputor.val(),t=this.$inputor.caret("pos",{iframe:this.app.iframe}),s=e.slice(0,t),r=this.callbacks("matcher").call(this,this.at,s,this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),n="string"==typeof r,!(n&&r.length0)return t.getRangeAt(0)},n.prototype._setRange=function(e,i,n){if(null==n&&(n=this._getRange()),n&&i)return i=t(i)[0],"after"===e?(n.setEndAfter(i),n.setStartAfter(i)):(n.setEndBefore(i),n.setStartBefore(i)),n.collapse(!1),this._clearRange(n)},n.prototype._clearRange=function(t){var e;if(null==t&&(t=this._getRange()),e=this.app.window.getSelection(),null==this.ctrl_a_pressed)return e.removeAllRanges(),e.addRange(t)},n.prototype._movingEvent=function(t){var e;return"click"===t.type||(e=t.which)===i.RIGHT||e===i.LEFT||e===i.UP||e===i.DOWN},n.prototype._unwrap=function(e){var i;return e=t(e).unwrap().get(0),(i=e.nextSibling)&&i.nodeValue&&(e.nodeValue+=i.nodeValue,t(i).remove()),e},n.prototype.catchQuery=function(e){var n,r,o,s,a,h,l,u,c,p,f,d;if((d=this._getRange())&&d.collapsed){if(e.which===i.ENTER)return(r=t(d.startContainer).closest(".atwho-query")).contents().unwrap(),r.is(":empty")&&r.remove(),(r=t(".atwho-query",this.app.document)).text(r.text()).contents().last().unwrap(),void this._clearRange();if(/firefox/i.test(navigator.userAgent)){if(t(d.startContainer).is(this.$inputor))return void this._clearRange();e.which===i.BACKSPACE&&d.startContainer.nodeType===document.ELEMENT_NODE&&(c=d.startOffset-1)>=0?(o=d.cloneRange(),o.setStart(d.startContainer,c),t(o.cloneContents()).contents().last().is(".atwho-inserted")&&(a=t(d.startContainer).contents().get(c),this._setRange("after",t(a).contents().last()))):e.which===i.LEFT&&d.startContainer.nodeType===document.TEXT_NODE&&(n=t(d.startContainer.previousSibling),n.is(".atwho-inserted")&&0===d.startOffset&&this._setRange("after",n.contents().last()))}if(t(d.startContainer).closest(".atwho-inserted").addClass("atwho-query").siblings().removeClass("atwho-query"),(r=t(".atwho-query",this.app.document)).length>0&&r.is(":empty")&&0===r.text().length&&r.remove(),this._movingEvent(e)||r.removeClass("atwho-inserted"),r.length>0)switch(e.which){case i.LEFT:return this._setRange("before",r.get(0),d),void r.removeClass("atwho-query");case i.RIGHT:return this._setRange("after",r.get(0).nextSibling,d),void r.removeClass("atwho-query")}if(r.length>0&&(f=r.attr("data-atwho-at-query"))&&(r.empty().html(f).attr("data-atwho-at-query",null),this._setRange("after",r.get(0),d)),o=d.cloneRange(),o.setStart(d.startContainer,0),u=this.callbacks("matcher").call(this,this.at,o.toString(),this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),h="string"==typeof u,0===r.length&&h&&(s=d.startOffset-this.at.length-u.length)>=0&&(d.setStart(d.startContainer,s),r=t("",this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass("atwho-query"),d.surroundContents(r.get(0)),l=r.contents().last().get(0),l&&(/firefox/i.test(navigator.userAgent)?(d.setStart(l,l.length),d.setEnd(l,l.length),this._clearRange(d)):this._setRange("after",l,d))),!(h&&u.length=0&&(this._movingEvent(e)&&r.hasClass("atwho-inserted")?r.removeClass("atwho-query"):!1!==this.callbacks("afterMatchFailed").call(this,this.at,r)&&this._setRange("after",this._unwrap(r.text(r.text()).contents().first()))),null)}},n.prototype.rect=function(){var e,i,n;if(this.query.el[0]&&this.query.el[0].getClientRects().length&&(n=this.query.el.offset()))return this.app.iframe&&!this.app.iframeAsRoot&&(i=(e=t(this.app.iframe)).offset(),n.left+=i.left-this.$inputor.scrollLeft(),n.top+=i.top-this.$inputor.scrollTop()),n.bottom=n.top+this.query.el.height(),n},n.prototype.insert=function(t,e){var i,n,r,o,s;return this.$inputor.is(":focus")||this.$inputor.focus(),n=this.getOpt("functionOverrides"),n.insert?n.insert.call(this,t,e):(o=""===(o=this.getOpt("suffix"))?o:o||" ",i=e.data("item-data"),this.query.el.removeClass("atwho-query").addClass("atwho-inserted").html(t).attr("data-atwho-at-query",""+i["atwho-at"]+this.query.text).attr("contenteditable","false"),(r=this._getRange())&&(this.query.el.length&&r.setEndAfter(this.query.el[0]),r.collapse(!1),r.insertNode(s=this.app.document.createTextNode(""+o)),this._setRange("after",s,r)),this.$inputor.is(":focus")||this.$inputor.focus(),this.$inputor.change())},n}(r);var u;u=function(){function e(t){this.context=t,this.at=this.context.at,this.storage=this.context.$inputor}return e.prototype.destroy=function(){return this.storage.data(this.at,null)},e.prototype.saved=function(){return this.fetch()>0},e.prototype.query=function(t,e){var i,n,r;return n=this.fetch(),r=this.context.getOpt("searchKey"),n=this.context.callbacks("filter").call(this.context,t,n,r)||[],i=this.context.callbacks("remoteFilter"),n.length>0||!i&&0===n.length?e(n):i.call(this.context,t,e)},e.prototype.fetch=function(){return this.storage.data(this.at)||[]},e.prototype.save=function(t){return this.storage.data(this.at,this.context.callbacks("beforeSave").call(this.context,t||[]))},e.prototype.load=function(t){if(!this.saved()&&t)return this._load(t)},e.prototype.reload=function(t){return this._load(t)},e.prototype._load=function(e){return"string"==typeof e?t.ajax(e,{dataType:"json"}).done(function(t){return function(e){return t.save(e)}}(this)):this.save(e)},e}();var c;c=function(){function e(e){this.context=e,this.$el=t("
    "),this.$elUl=this.$el.children(),this.timeoutID=null,this.context.$el.append(this.$el),this.bindEvent()}return e.prototype.init=function(){var t,e;return e=this.context.getOpt("alias")||this.context.at.charCodeAt(0),t=this.context.getOpt("headerTpl"),t&&1===this.$el.children().length&&this.$el.prepend(t),this.$el.attr({id:"at-view-"+e})},e.prototype.destroy=function(){return this.$el.remove()},e.prototype.bindEvent=function(){var e,i,n;return e=this.$el.find("ul"),i=0,n=0,e.on("mousemove.atwho-view","li",function(r){return function(r){var o;if((i!==r.clientX||n!==r.clientY)&&(i=r.clientX,n=r.clientY,o=t(r.currentTarget),!o.hasClass("cur")))return e.find(".cur").removeClass("cur"),o.addClass("cur")}}(this)).on("click.atwho-view","li",function(i){return function(n){return e.find(".cur").removeClass("cur"),t(n.currentTarget).addClass("cur"),i.choose(n),n.preventDefault()}}(this))},e.prototype.visible=function(){return t.expr.filters.visible(this.$el[0])},e.prototype.highlighted=function(){return this.$el.find(".cur").length>0},e.prototype.choose=function(t){var e,i;if((e=this.$el.find(".cur")).length&&(i=this.context.insertContentFor(e),this.context._stopDelayedCall(),this.context.insert(this.context.callbacks("beforeInsert").call(this.context,i,e,t),e),this.context.trigger("inserted",[e,t]),this.hide(t)),this.context.getOpt("hideWithoutSuffix"))return this.stopShowing=!0},e.prototype.reposition=function(e){var i,n,r,o;return i=this.context.app.iframeAsRoot?this.context.app.window:window,e.bottom+this.$el.height()-t(i).scrollTop()>t(i).height()&&(e.bottom=e.top-this.$el.height()),e.left>(r=t(i).width()-this.$el.width()-5)&&(e.left=r),n={left:e.left,top:e.bottom},null!=(o=this.context.callbacks("beforeReposition"))&&o.call(this.context,n),this.$el.offset(n),this.context.trigger("reposition",[n])},e.prototype.next=function(){var t,e,i,n;return t=this.$el.find(".cur").removeClass("cur"),e=t.next(),e.length||(e=this.$el.find("li:first")),e.addClass("cur"),i=e[0],n=i.offsetTop+i.offsetHeight+(i.nextSibling?i.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,n-this.$el.height()))},e.prototype.prev=function(){var t,e,i,n;return t=this.$el.find(".cur").removeClass("cur"),i=t.prev(),i.length||(i=this.$el.find("li:last")),i.addClass("cur"),n=i[0],e=n.offsetTop+n.offsetHeight+(n.nextSibling?n.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,e-this.$el.height()))},e.prototype.scrollTop=function(t){var e;return e=this.context.getOpt("scrollDuration"),e?this.$elUl.animate({scrollTop:t},e):this.$elUl.scrollTop(t)},e.prototype.show=function(){var t;return this.stopShowing?void(this.stopShowing=!1):(this.visible()||(this.$el.show(),this.$el.scrollTop(0),this.context.trigger("shown")),(t=this.context.rect())?this.reposition(t):void 0)},e.prototype.hide=function(t,e){var i;if(this.visible())return isNaN(e)?(this.$el.hide(),this.context.trigger("hidden",[t])):(i=function(t){return function(){return t.hide()}}(this),clearTimeout(this.timeoutID),this.timeoutID=setTimeout(i,e))},e.prototype.render=function(e){var i,n,r,o,s,a,h;if(!(t.isArray(e)&&e.length>0))return void this.hide();for(this.$el.find("ul").empty(),n=this.$el.find("ul"),h=this.context.getOpt("displayTpl"),r=0,s=e.length;r${name}",insertTpl:"${atwho-at}${name}",headerTpl:null,callbacks:e,functionOverrides:{},searchKey:"name",suffix:void 0,hideWithoutSuffix:!1,startWithSpace:!0,acceptSpaceBar:!1,highlightFirst:!0,limit:5,maxLen:20,minLen:0,displayTimeout:300,delay:null,spaceSelectsMatch:!1,tabSelectsMatch:!0,editableAtwhoQueryAttrs:{},scrollDuration:150,suspendOnComposing:!0,lookUpOnClick:!0},t.fn.atwho.debug=!1}); \ No newline at end of file +var DEFAULT_CALLBACKS,KEY_CODE;KEY_CODE={ESC:27,TAB:9,ENTER:13,CTRL:17,A:65,P:80,N:78,LEFT:37,UP:38,RIGHT:39,DOWN:40,BACKSPACE:8,SPACE:32},DEFAULT_CALLBACKS={beforeSave:function(t){return Controller.arrayToDefaultHash(t)},matcher:function(t,e,i,r){var n,o,s,a,l;return t=t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),i&&(t="(?:^|\\s)"+t),n=decodeURI("%C3%80"),o=decodeURI("%C3%BF"),l=r?" ":"",a=new RegExp(t+"([A-Za-z"+n+"-"+o+"0-9_"+l+"'.+-]*)$|"+t+"([^\\x00-\\xff]*)$","gi"),s=a.exec(e),s?s[2]||s[1]:null},filter:function(t,e,i){var r,n,o,s;for(r=[],n=0,s=e.length;n-1&&r.push(o);return r.sort(function(t,e){return t.atwho_order-e.atwho_order})},tplEval:function(t,e){var i,r;r=t;try{return"string"!=typeof t&&(r=t(e)),r.replace(/\$\{([^\}]*)\}/g,function(t,i,r){return e[i]})}catch(n){return i=n,""}},highlighter:function(t,e){var i;return e?(i=new RegExp(">\\s*([^<]*?)("+e.replace("+","\\+")+")([^<]*)\\s*<","ig"),t.replace(i,function(t,e,i,r){return"> "+e+""+i+""+r+" <"})):t},beforeInsert:function(t,e,i){return t},beforeReposition:function(t){return t},afterMatchFailed:function(t,e){}};var App;App=function(){function t(t){this.currentFlag=null,this.controllers={},this.aliasMaps={},this.$inputor=$(t),this.setupRootElement(),this.listen()}return t.prototype.createContainer=function(t){var e;return null!=(e=this.$el)&&e.remove(),$(t.body).append(this.$el=$("
    "))},t.prototype.setupRootElement=function(t,e){var i;if(null==e&&(e=!1),t)this.window=t.contentWindow,this.document=t.contentDocument||this.window.document,this.iframe=t;else{this.document=this.$inputor[0].ownerDocument,this.window=this.document.defaultView||this.document.parentWindow;try{this.iframe=this.window.frameElement}catch(r){if(i=r,this.iframe=null,$.fn.atwho.debug)throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.\n"+i)}}return this.createContainer((this.iframeAsRoot=e)?this.document:document)},t.prototype.controller=function(t){var e,i,r,n;if(this.aliasMaps[t])i=this.controllers[this.aliasMaps[t]];else{n=this.controllers;for(r in n)if(e=n[r],r===t){i=e;break}}return i?i:this.controllers[this.currentFlag]},t.prototype.setContextFor=function(t){return this.currentFlag=t,this},t.prototype.reg=function(t,e){var i,r;return r=(i=this.controllers)[t]||(i[t]=this.$inputor.is("[contentEditable]")?new EditableController(this,t):new TextareaController(this,t)),e.alias&&(this.aliasMaps[e.alias]=t),r.init(e),this},t.prototype.listen=function(){return this.$inputor.on("compositionstart",function(t){return function(e){var i;return null!=(i=t.controller())&&i.view.hide(),t.isComposing=!0,null}}(this)).on("compositionend",function(t){return function(e){return t.isComposing=!1,setTimeout(function(){return t.dispatch(e)}),null}}(this)).on("keyup.atwhoInner",function(t){return function(e){return t.onKeyup(e)}}(this)).on("keydown.atwhoInner",function(t){return function(e){return t.onKeydown(e)}}(this)).on("blur.atwhoInner",function(t){return function(e){var i;if(i=t.controller())return i.expectedQueryCBId=null,i.view.hide(e,i.getOpt("displayTimeout"))}}(this)).on("click.atwhoInner",function(t){return function(e){return t.dispatch(e)}}(this)).on("scroll.atwhoInner",function(t){return function(){var e;return e=t.$inputor.scrollTop(),function(i){var r,n;return r=i.target.scrollTop,e!==r&&null!=(n=t.controller())&&n.view.hide(i),e=r,!0}}}(this)())},t.prototype.shutdown=function(){var t,e,i;i=this.controllers;for(t in i)e=i[t],e.destroy(),delete this.controllers[t];return this.$inputor.off(".atwhoInner"),this.$el.remove()},t.prototype.dispatch=function(t){var e,i,r,n;r=this.controllers,n=[];for(e in r)i=r[e],n.push(i.lookUp(t));return n},t.prototype.onKeyup=function(t){var e;switch(t.keyCode){case KEY_CODE.ESC:t.preventDefault(),null!=(e=this.controller())&&e.view.hide();break;case KEY_CODE.DOWN:case KEY_CODE.UP:case KEY_CODE.CTRL:$.noop();break;case KEY_CODE.P:case KEY_CODE.N:t.ctrlKey||this.dispatch(t);break;default:this.dispatch(t)}},t.prototype.onKeydown=function(t){var e,i;if(i=null!=(e=this.controller())?e.view:void 0,i&&i.visible())switch(t.keyCode){case KEY_CODE.ESC:t.preventDefault(),i.hide(t);break;case KEY_CODE.UP:t.preventDefault(),i.prev();break;case KEY_CODE.DOWN:t.preventDefault(),i.next();break;case KEY_CODE.P:if(!t.ctrlKey)return;t.preventDefault(),i.prev();break;case KEY_CODE.N:if(!t.ctrlKey)return;t.preventDefault(),i.next();break;case KEY_CODE.TAB:case KEY_CODE.ENTER:case KEY_CODE.SPACE:if(!i.visible())return;if(!this.controller().getOpt("spaceSelectsMatch")&&t.keyCode===KEY_CODE.SPACE)return;if(!this.controller().getOpt("tabSelectsMatch")&&t.keyCode===KEY_CODE.TAB)return;i.highlighted()?(t.preventDefault(),i.choose(t)):i.hide(t);break;default:$.noop()}},t}();var Controller,slice=[].slice;Controller=function(){function t(t,e){this.app=t,this.at=e,this.$inputor=this.app.$inputor,this.id=this.$inputor[0].id||this.uid(),this.expectedQueryCBId=null,this.setting=null,this.query=null,this.pos=0,this.range=null,0===(this.$el=$("#atwho-ground-"+this.id,this.app.$el)).length&&this.app.$el.append(this.$el=$("
    ")),this.model=new Model(this),this.view=new View(this)}return t.prototype.uid=function(){return(Math.random().toString(16)+"000000000").substr(2,8)+(new Date).getTime()},t.prototype.init=function(t){return this.setting=$.extend({},this.setting||$.fn.atwho["default"],t),this.view.init(),this.model.reload(this.setting.data)},t.prototype.destroy=function(){return this.trigger("beforeDestroy"),this.model.destroy(),this.view.destroy(),this.$el.remove()},t.prototype.callDefault=function(){var t,e,i;i=arguments[0],t=2<=arguments.length?slice.call(arguments,1):[];try{return DEFAULT_CALLBACKS[i].apply(this,t)}catch(r){return e=r,$.error(e+" Or maybe At.js doesn't have function "+i)}},t.prototype.trigger=function(t,e){var i,r;return null==e&&(e=[]),e.push(this),i=this.getOpt("alias"),r=i?t+"-"+i+".atwho":t+".atwho",this.$inputor.trigger(r,e)},t.prototype.callbacks=function(t){return this.getOpt("callbacks")[t]||DEFAULT_CALLBACKS[t]},t.prototype.getOpt=function(t,e){var i;try{return this.setting[t]}catch(r){return i=r,null}},t.prototype.insertContentFor=function(t){var e,i;return i=this.getOpt("insertTpl"),e=$.extend({},t.data("item-data"),{"atwho-at":this.at}),this.callbacks("tplEval").call(this,i,e,"onInsert")},t.prototype.renderView=function(t){var e;return e=this.getOpt("searchKey"),t=this.callbacks("sorter").call(this,this.query.text,t.slice(0,1001),e),this.view.render(t.slice(0,this.getOpt("limit")))},t.arrayToDefaultHash=function(t){var e,i,r,n;if(!$.isArray(t))return t;for(n=[],e=0,r=t.length;e0?this.renderView(this.constructor.arrayToDefaultHash(e)):this.view.hide()},this.expectedQueryCBId=this._generateQueryCBId(),this.model.query(t.text,$.proxy(e,this,this.expectedQueryCBId))},t}();var TextareaController,extend=function(t,e){function i(){this.constructor=t}for(var r in e)hasProp.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},hasProp={}.hasOwnProperty;TextareaController=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return extend(e,t),e.prototype.catchQuery=function(){var t,e,i,r,n,o,s;if(e=this.$inputor.val(),t=this.$inputor.caret("pos",{iframe:this.app.iframe}),s=e.slice(0,t),n=this.callbacks("matcher").call(this,this.at,s,this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),r="string"==typeof n,!(r&&n.length0)return t.getRangeAt(0)},e.prototype._setRange=function(t,e,i){if(null==i&&(i=this._getRange()),i&&e)return e=$(e)[0],"after"===t?(i.setEndAfter(e),i.setStartAfter(e)):(i.setEndBefore(e),i.setStartBefore(e)),i.collapse(!1),this._clearRange(i)},e.prototype._clearRange=function(t){var e;if(null==t&&(t=this._getRange()),e=this.app.window.getSelection(),null==this.ctrl_a_pressed)return e.removeAllRanges(),e.addRange(t)},e.prototype._movingEvent=function(t){var e;return"click"===t.type||(e=t.which)===KEY_CODE.RIGHT||e===KEY_CODE.LEFT||e===KEY_CODE.UP||e===KEY_CODE.DOWN},e.prototype._unwrap=function(t){var e;return t=$(t).unwrap().get(0),(e=t.nextSibling)&&e.nodeValue&&(t.nodeValue+=e.nodeValue,$(e).remove()),t},e.prototype.catchQuery=function(t){var e,i,r,n,o,s,a,l,h,u,c,p;if((p=this._getRange())&&p.collapsed&&t){if(t.which===KEY_CODE.ENTER)return(i=$(p.startContainer).closest(".atwho-query")).contents().unwrap(),i.is(":empty")&&i.remove(),(i=$(".atwho-query",this.app.document)).text(i.text()).contents().last().unwrap(),void this._clearRange();if(/firefox/i.test(navigator.userAgent)){if($(p.startContainer).is(this.$inputor))return void this._clearRange();t.which===KEY_CODE.BACKSPACE&&p.startContainer.nodeType===document.ELEMENT_NODE&&(h=p.startOffset-1)>=0?(r=p.cloneRange(),r.setStart(p.startContainer,h),$(r.cloneContents()).contents().last().is(".atwho-inserted")&&(o=$(p.startContainer).contents().get(h),this._setRange("after",$(o).contents().last()))):t.which===KEY_CODE.LEFT&&p.startContainer.nodeType===document.TEXT_NODE&&(e=$(p.startContainer.previousSibling),e.is(".atwho-inserted")&&0===p.startOffset&&this._setRange("after",e.contents().last()))}if($(p.startContainer).closest(".atwho-inserted").addClass("atwho-query").siblings().removeClass("atwho-query"),(i=$(".atwho-query",this.app.document)).length>0&&i.is(":empty")&&0===i.text().length&&i.remove(),this._movingEvent(t)||i.removeClass("atwho-inserted"),i.length>0)switch(t.which){case KEY_CODE.LEFT:return this._setRange("before",i.get(0),p),void i.removeClass("atwho-query");case KEY_CODE.RIGHT:return this._setRange("after",i.get(0).nextSibling,p),void i.removeClass("atwho-query")}if(i.length>0&&(c=i.attr("data-atwho-at-query"))&&(i.empty().html(c).attr("data-atwho-at-query",null),this._setRange("after",i.get(0),p)),r=p.cloneRange(),r.setStart(p.startContainer,0),l=this.callbacks("matcher").call(this,this.at,r.toString(),this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),s="string"==typeof l,0===i.length&&s&&(n=p.startOffset-this.at.length-l.length)>=0&&(p.setStart(p.startContainer,n),i=$("",this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass("atwho-query"),p.surroundContents(i.get(0)),a=i.contents().last().get(0),a&&(/firefox/i.test(navigator.userAgent)?(p.setStart(a,a.length),p.setEnd(a,a.length),this._clearRange(p)):this._setRange("after",a,p))),!(s&&l.length=0&&(this._movingEvent(t)&&i.hasClass("atwho-inserted")?i.removeClass("atwho-query"):!1!==this.callbacks("afterMatchFailed").call(this,this.at,i)&&this._setRange("after",this._unwrap(i.text(i.text()).contents().first()))),null)}},e.prototype.rect=function(){var t,e,i;if(i=this.query.el.offset(),i&&this.query.el[0].getClientRects().length)return this.app.iframe&&!this.app.iframeAsRoot&&(e=(t=$(this.app.iframe)).offset(),i.left+=e.left-this.$inputor.scrollLeft(),i.top+=e.top-this.$inputor.scrollTop()),i.bottom=i.top+this.query.el.height(),i},e.prototype.insert=function(t,e){var i,r,n,o,s;return this.$inputor.is(":focus")||this.$inputor.focus(),r=this.getOpt("functionOverrides"),r.insert?r.insert.call(this,t,e):(o=""===(o=this.getOpt("suffix"))?o:o||" ",i=e.data("item-data"),this.query.el.removeClass("atwho-query").addClass("atwho-inserted").html(t).attr("data-atwho-at-query",""+i["atwho-at"]+this.query.text),(n=this._getRange())&&(this.query.el.length&&n.setEndAfter(this.query.el[0]),n.collapse(!1),n.insertNode(s=this.app.document.createTextNode("​"+o)),this._setRange("after",s,n)),this.$inputor.is(":focus")||this.$inputor.focus(),this.$inputor.change())},e}(Controller);var Model;Model=function(){function t(t){this.context=t,this.at=this.context.at,this.storage=this.context.$inputor}return t.prototype.destroy=function(){return this.storage.data(this.at,null)},t.prototype.saved=function(){return this.fetch()>0},t.prototype.query=function(t,e){var i,r,n;return r=this.fetch(),n=this.context.getOpt("searchKey"),r=this.context.callbacks("filter").call(this.context,t,r,n)||[],i=this.context.callbacks("remoteFilter"),r.length>0||!i&&0===r.length?e(r):i.call(this.context,t,e)},t.prototype.fetch=function(){return this.storage.data(this.at)||[]},t.prototype.save=function(t){return this.storage.data(this.at,this.context.callbacks("beforeSave").call(this.context,t||[]))},t.prototype.load=function(t){if(!this.saved()&&t)return this._load(t)},t.prototype.reload=function(t){return this._load(t)},t.prototype._load=function(t){return"string"==typeof t?$.ajax(t,{dataType:"json"}).done(function(t){return function(e){return t.save(e)}}(this)):this.save(t)},t}();var View;View=function(){function t(t){this.context=t,this.$el=$("
      "),this.$elUl=this.$el.children(),this.timeoutID=null,this.context.$el.append(this.$el),this.bindEvent()}return t.prototype.init=function(){var t,e;return e=this.context.getOpt("alias")||this.context.at.charCodeAt(0),t=this.context.getOpt("headerTpl"),t&&1===this.$el.children().length&&this.$el.prepend(t),this.$el.attr({id:"at-view-"+e})},t.prototype.destroy=function(){return this.$el.remove()},t.prototype.bindEvent=function(){var t,e,i;return t=this.$el.find("ul"),e=0,i=0,t.on("mousemove.atwho-view","li",function(r){return function(r){var n;if((e!==r.clientX||i!==r.clientY)&&(e=r.clientX,i=r.clientY,n=$(r.currentTarget),!n.hasClass("cur")))return t.find(".cur").removeClass("cur"),n.addClass("cur")}}(this)).on("click.atwho-view","li",function(e){return function(i){return t.find(".cur").removeClass("cur"),$(i.currentTarget).addClass("cur"),e.choose(i),i.preventDefault()}}(this))},t.prototype.visible=function(){return $.expr.filters.visible(this.$el[0])},t.prototype.highlighted=function(){return this.$el.find(".cur").length>0},t.prototype.choose=function(t){var e,i;if((e=this.$el.find(".cur")).length&&(i=this.context.insertContentFor(e),this.context._stopDelayedCall(),this.context.insert(this.context.callbacks("beforeInsert").call(this.context,i,e,t),e),this.context.trigger("inserted",[e,t]),this.hide(t)),this.context.getOpt("hideWithoutSuffix"))return this.stopShowing=!0},t.prototype.reposition=function(t){var e,i,r,n;return e=this.context.app.iframeAsRoot?this.context.app.window:window,t.bottom+this.$el.height()-$(e).scrollTop()>$(e).height()&&(t.bottom=t.top-this.$el.height()),t.left>(r=$(e).width()-this.$el.width()-5)&&(t.left=r),i={left:t.left,top:t.bottom},null!=(n=this.context.callbacks("beforeReposition"))&&n.call(this.context,i),this.$el.offset(i),this.context.trigger("reposition",[i])},t.prototype.next=function(){var t,e,i,r;return t=this.$el.find(".cur").removeClass("cur"),e=t.next(),e.length||(e=this.$el.find("li:first")),e.addClass("cur"),i=e[0],r=i.offsetTop+i.offsetHeight+(i.nextSibling?i.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,r-this.$el.height()))},t.prototype.prev=function(){var t,e,i,r;return t=this.$el.find(".cur").removeClass("cur"),i=t.prev(),i.length||(i=this.$el.find("li:last")),i.addClass("cur"),r=i[0],e=r.offsetTop+r.offsetHeight+(r.nextSibling?r.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,e-this.$el.height()))},t.prototype.scrollTop=function(t){var e;return e=this.context.getOpt("scrollDuration"),e?this.$elUl.animate({scrollTop:t},e):this.$elUl.scrollTop(t)},t.prototype.show=function(){var t;return this.stopShowing?void(this.stopShowing=!1):(this.visible()||(this.$el.show(),this.$el.scrollTop(0),this.context.trigger("shown")),(t=this.context.rect())?this.reposition(t):void 0)},t.prototype.hide=function(t,e){var i;if(this.visible())return isNaN(e)?(this.$el.hide(),this.context.trigger("hidden",[t])):(i=function(t){return function(){return t.hide()}}(this),clearTimeout(this.timeoutID),this.timeoutID=setTimeout(i,e))},t.prototype.render=function(t){var e,i,r,n,o,s,a;if(!($.isArray(t)&&t.length>0))return void this.hide();for(this.$el.find("ul").empty(),i=this.$el.find("ul"),a=this.context.getOpt("displayTpl"),r=0,o=t.length;r${name}",insertTpl:"${atwho-at}${name}",headerTpl:null,callbacks:DEFAULT_CALLBACKS,functionOverrides:{},searchKey:"name",suffix:void 0,hideWithoutSuffix:!1,startWithSpace:!0,acceptSpaceBar:!1,highlightFirst:!0,limit:5,maxLen:20,minLen:0,displayTimeout:300,delay:null,spaceSelectsMatch:!1,tabSelectsMatch:!0,editableAtwhoQueryAttrs:{},scrollDuration:150,suspendOnComposing:!0,lookUpOnClick:!0},$.fn.atwho.debug=!1; \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index a7576786..76626023 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,7 +43,7 @@ gulp.task('umd', function() { gulp.task('bump', function() { gulp.src(['bower.json', 'component.json', 'package.json']) - .pipe(bump({version: "1.5.3"})) + .pipe(bump({version: "1.5.7"})) .pipe(gulp.dest('./')); }); diff --git a/package.json b/package.json index 129f0854..54bf8716 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ }, "homepage": "http://ichord.github.com/At.js", "license": "MIT", - "version": "1.5.3", + "version": "1.5.7", "repository": { "type": "git", "url": "https://github.com/ichord/At.js" @@ -18,9 +18,6 @@ "scripts": { "test": "gulp test" }, - "peerDependencies": { - "jquery": "^1.7.0" - }, "devDependencies": { "gulp": "^3.9.0", "gulp-bump": "^1.0.0", @@ -37,6 +34,7 @@ "gulp-util": "^3.0.7", "jasmine-ajax": "^3.2.0", "jasmine-jquery": "^2.1.1", + "jquery": ">=1.7.0", "phantomjs": "^1.9.19" }, "spm": { diff --git a/src/app.coffee b/src/app.coffee index fd601b51..92298432 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -76,7 +76,7 @@ class App null .on 'compositionend', (e) => @isComposing = false - setTimeout((e) => @dispatch(e)) + setTimeout(() => @dispatch(e)) null .on 'keyup.atwhoInner', (e) => this.onKeyup(e) @@ -113,7 +113,7 @@ class App when KEY_CODE.ESC e.preventDefault() this.controller()?.view.hide() - when KEY_CODE.DOWN, KEY_CODE.UP, KEY_CODE.CTRL, KEY_CODE.ENTER + when KEY_CODE.DOWN, KEY_CODE.UP, KEY_CODE.CTRL $.noop() when KEY_CODE.P, KEY_CODE.N this.dispatch e if not e.ctrlKey diff --git a/src/editableController.coffee b/src/editableController.coffee index d6fcaeb7..ffa22a47 100644 --- a/src/editableController.coffee +++ b/src/editableController.coffee @@ -36,6 +36,7 @@ class EditableController extends Controller catchQuery: (e) -> return unless range = @_getRange() return unless range.collapsed + return unless e if e.which == KEY_CODE.ENTER ($query = $(range.startContainer).closest '.atwho-query') @@ -163,12 +164,11 @@ class EditableController extends Controller .addClass 'atwho-inserted' .html content .attr 'data-atwho-at-query', "" + data['atwho-at'] + @query.text - .attr 'contenteditable', "false" if range = @_getRange() if @query.el.length range.setEndAfter @query.el[0] range.collapse false - range.insertNode suffixNode = @app.document.createTextNode "" + suffix + range.insertNode suffixNode = @app.document.createTextNode "\u200B" + suffix @_setRange 'after', suffixNode, range @$inputor.focus() unless @$inputor.is ':focus' @$inputor.change()