Add backbone typeahead component

This commit is contained in:
lilia 2015-01-24 23:16:54 -10:00
parent 79b4c89ce4
commit 79cdadd816
4 changed files with 11 additions and 5 deletions

View file

@ -18,7 +18,8 @@
"backbone.localstorage": "liliakai/Backbone.localStorage#master",
"momentjs": "~2.8.3",
"indexeddb-backbonejs-adapter": "*",
"intl-tel-input": "~4.0.1"
"intl-tel-input": "~4.0.1",
"backbone.typeahead": "mojotech/backbone.typeahead"
},
"devDependencies": {
"mocha": "~2.0.1",
@ -89,6 +90,9 @@
"build/css/intlTelInput.css",
"build/img/flags.png",
"build/js/intlTelInput.js"
],
"backbone.typeahead": [
"backbone.typeahead.min.js"
]
},
"concat": {
@ -104,7 +108,8 @@
"qrcode",
"libphonenumber-api",
"momentjs",
"intl-tel-input"
"intl-tel-input",
"backbone.typeahead"
],
"lib": [
"jquery",

View file

@ -0,0 +1 @@
(function(){var t={}.hasOwnProperty,e=function(e,n){function r(){this.constructor=e}for(var i in n)t.call(n,i)&&(e[i]=n[i]);return r.prototype=n.prototype,e.prototype=new r,e.__super__=n.prototype,e},n=[].slice;Backbone.TypeaheadCollection=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return e(r,t),r.prototype._tokenize=function(t){return t=$.trim(t),0===t.length?null:t.toLowerCase().split(/[\s\-_]+/)},r.prototype._deepObjectMap=function(t,e){return e.length>0&&_.isObject(t)?1===e.length?t[e[0]]:this._deepObjectMap(t[e[0]],e.slice(1,e.length)):t},r.prototype._getAttributeValues=function(t){return _.map(this.typeaheadAttributes,function(e){return function(n){var r;return r=n.split("."),e._deepObjectMap(t.get(r[0]),r.slice(1))}}(this))},r.prototype._extractValues=function(t){return null!=this.typeaheadAttributes?this._getAttributeValues(t):_.values(t.attributes)},r.prototype._tokenizeModel=function(t){return _.uniq(this._tokenize(_.flatten(this._extractValues(t)).join(" ")))},r.prototype._addToIndex=function(t){var e,n,r,i,o,u,s,a,h;for(_.isArray(t)||(t=[t]),h=[],s=0,a=t.length;a>s;s++)i=t[s],u=this._tokenizeModel(i),r=null!=i.id?i.id:i.cid,this._tokens[r]=u,h.push(function(){var t,i,s,a;for(a=[],i=0,s=u.length;s>i;i++)o=u[i],n=o.charAt(0),e=(t=this._adjacency)[n]||(t[n]=[r]),a.push(~_.indexOf(e,r)?void 0:e.push(r));return a}.call(this));return h},r.prototype._removeFromIndex=function(t){var e,r,i,o,u,s,a,h;for(_.isArray(t)||(t=[t]),r=_.map(t,function(t){return null!=t.id?t.id:t.cid}),u=0,s=r.length;s>u;u++)e=r[u],delete this._tokens[e];a=this._adjacency,h=[];for(i in a)o=a[i],h.push(this._adjacency[i]=_.without.apply(_,[o].concat(n.call(r))));return h},r.prototype._rebuildIndex=function(){return this._adjacency={},this._tokens={},this._addToIndex(this.models)},r.prototype.typeaheadIndexer=function(t){return null!=t&&_.keys(t).length>0?_.map(this.where(t),function(t){return null!=t.id?t.id:t.cid}):null},r.prototype.typeahead=function(t,e){var n,r,i,o,u,s,a,h,p,l,c,d,f;if(null==this._adjacency)throw new Error("Index is not built");if(p=this._tokenize(t),h=[],l=null,i=_(p).chain().map(function(t){return t.charAt(0)}).uniq().value(),n=function(t){return function(e){return e.length<((null!=l?l.length:void 0)||t.length)?l=e:void 0}}(this),_.all(i,function(t){return function(e){var r;return r=t._adjacency[e],null==r?!1:(h.push(r),n(r),!0)}}(this)),h.length<i.length)return[];if(r=this.typeaheadIndexer(e),null!=r&&(h.push(r),n(r)),null==l)return this.models;if(0===l.length)return[];for(c=[],d=0,f=l.length;f>d;d++)o=l[d],u=_.every(h,function(t){return~_.indexOf(t,o)}),s=u&&_.every(p,function(t){return function(e){return _.some(t._tokens[o],function(t){return 0===t.indexOf(e)})}}(this)),s&&(a=this.get(o),this.typeaheadPreserveOrder?c[this.indexOf(a)]=a:c.push(a));return this.typeaheadPreserveOrder?_.compact(c):c},r.prototype._reset=function(){return this._tokens={},this._adjacency={},r.__super__._reset.apply(this,arguments)},r.prototype.set=function(){var t;return t=r.__super__.set.apply(this,arguments),_.isArray(t)||(t=[t]),this._rebuildIndex(t),t},r.prototype.remove=function(){var t;return t=r.__super__.remove.apply(this,arguments),_.isArray(t)||(t=[t]),this._removeFromIndex(t),t},r.prototype._onModelEvent=function(t,e){var n;return n=!1,t==="change:"+e.idAttribute?(n=!0,this._removeFromIndex({id:e.previous(e.idAttribute)})):0===t.indexOf("change:")&&(null==this.typeaheadAttributes||_.indexOf(_.map(this.typeaheadAttributes,function(t){return"change:"+t}),t)>=0)&&(n=!0,this._removeFromIndex(e)),n&&this._addToIndex(e),r.__super__._onModelEvent.apply(this,arguments)},r}(Backbone.Collection)}).call(this);

View file

@ -15,8 +15,7 @@
</head>
<body class='signal index'>
<div class='title-bar' id='header'>
<a href id='new-message'>New message</a>
<a href id='new-group'>New group</a>
<input type='text' class='new-message' placeholder="Name or phone number" />
</div>
<div class='notifications'>
<div class='notification info'>

View file

@ -27215,4 +27215,5 @@ JSON.stringify(result);
areaCodes: c[4] || null
};
}
});
});
(function(){var t={}.hasOwnProperty,e=function(e,n){function r(){this.constructor=e}for(var i in n)t.call(n,i)&&(e[i]=n[i]);return r.prototype=n.prototype,e.prototype=new r,e.__super__=n.prototype,e},n=[].slice;Backbone.TypeaheadCollection=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return e(r,t),r.prototype._tokenize=function(t){return t=$.trim(t),0===t.length?null:t.toLowerCase().split(/[\s\-_]+/)},r.prototype._deepObjectMap=function(t,e){return e.length>0&&_.isObject(t)?1===e.length?t[e[0]]:this._deepObjectMap(t[e[0]],e.slice(1,e.length)):t},r.prototype._getAttributeValues=function(t){return _.map(this.typeaheadAttributes,function(e){return function(n){var r;return r=n.split("."),e._deepObjectMap(t.get(r[0]),r.slice(1))}}(this))},r.prototype._extractValues=function(t){return null!=this.typeaheadAttributes?this._getAttributeValues(t):_.values(t.attributes)},r.prototype._tokenizeModel=function(t){return _.uniq(this._tokenize(_.flatten(this._extractValues(t)).join(" ")))},r.prototype._addToIndex=function(t){var e,n,r,i,o,u,s,a,h;for(_.isArray(t)||(t=[t]),h=[],s=0,a=t.length;a>s;s++)i=t[s],u=this._tokenizeModel(i),r=null!=i.id?i.id:i.cid,this._tokens[r]=u,h.push(function(){var t,i,s,a;for(a=[],i=0,s=u.length;s>i;i++)o=u[i],n=o.charAt(0),e=(t=this._adjacency)[n]||(t[n]=[r]),a.push(~_.indexOf(e,r)?void 0:e.push(r));return a}.call(this));return h},r.prototype._removeFromIndex=function(t){var e,r,i,o,u,s,a,h;for(_.isArray(t)||(t=[t]),r=_.map(t,function(t){return null!=t.id?t.id:t.cid}),u=0,s=r.length;s>u;u++)e=r[u],delete this._tokens[e];a=this._adjacency,h=[];for(i in a)o=a[i],h.push(this._adjacency[i]=_.without.apply(_,[o].concat(n.call(r))));return h},r.prototype._rebuildIndex=function(){return this._adjacency={},this._tokens={},this._addToIndex(this.models)},r.prototype.typeaheadIndexer=function(t){return null!=t&&_.keys(t).length>0?_.map(this.where(t),function(t){return null!=t.id?t.id:t.cid}):null},r.prototype.typeahead=function(t,e){var n,r,i,o,u,s,a,h,p,l,c,d,f;if(null==this._adjacency)throw new Error("Index is not built");if(p=this._tokenize(t),h=[],l=null,i=_(p).chain().map(function(t){return t.charAt(0)}).uniq().value(),n=function(t){return function(e){return e.length<((null!=l?l.length:void 0)||t.length)?l=e:void 0}}(this),_.all(i,function(t){return function(e){var r;return r=t._adjacency[e],null==r?!1:(h.push(r),n(r),!0)}}(this)),h.length<i.length)return[];if(r=this.typeaheadIndexer(e),null!=r&&(h.push(r),n(r)),null==l)return this.models;if(0===l.length)return[];for(c=[],d=0,f=l.length;f>d;d++)o=l[d],u=_.every(h,function(t){return~_.indexOf(t,o)}),s=u&&_.every(p,function(t){return function(e){return _.some(t._tokens[o],function(t){return 0===t.indexOf(e)})}}(this)),s&&(a=this.get(o),this.typeaheadPreserveOrder?c[this.indexOf(a)]=a:c.push(a));return this.typeaheadPreserveOrder?_.compact(c):c},r.prototype._reset=function(){return this._tokens={},this._adjacency={},r.__super__._reset.apply(this,arguments)},r.prototype.set=function(){var t;return t=r.__super__.set.apply(this,arguments),_.isArray(t)||(t=[t]),this._rebuildIndex(t),t},r.prototype.remove=function(){var t;return t=r.__super__.remove.apply(this,arguments),_.isArray(t)||(t=[t]),this._removeFromIndex(t),t},r.prototype._onModelEvent=function(t,e){var n;return n=!1,t==="change:"+e.idAttribute?(n=!0,this._removeFromIndex({id:e.previous(e.idAttribute)})):0===t.indexOf("change:")&&(null==this.typeaheadAttributes||_.indexOf(_.map(this.typeaheadAttributes,function(t){return"change:"+t}),t)>=0)&&(n=!0,this._removeFromIndex(e)),n&&this._addToIndex(e),r.__super__._onModelEvent.apply(this,arguments)},r}(Backbone.Collection)}).call(this);