web/assets/libs/edusoho/autocomplete/1.0.0/autocomplete.js
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/**
* Created by liumengte on 15-6-15.
*/
define(function (require, exports, module) {
var BaseAutoComplete = require('autocomplete');
var AutoComplete = BaseAutoComplete.extend({
_initFilter: function() {
var filter = this.get("filter");
if(filter.name in CustomFunc){
filter = {
name: filter.name,
func: CustomFunc[filter.name],
options : filter.options
}
this.set("filter", filter);
}else{
AutoComplete.superclass._initFilter.call(this);
}
}
});
module.exports = AutoComplete;
var CustomFunc = {
"stringIgnoreCaseMatch": function (data, query,options) {
options = this.attrs.filter.value.options;
query = query || '';
var result = [], l = query.length;
if (!l) return []
$.each(data, function (index, item) {
var matchKeys = getMatchKey(item,options);
// 匹配和显示相同才有必要高亮 忽略大小写
if (matchKeys.toUpperCase().indexOf(query.toUpperCase()) > -1) {
item.highlightIndex = stringMatch(matchKeys.toUpperCase(), query.toUpperCase());
item.matchKey = matchKeys;
result.push(item);
}
});
return result;
}
}
function stringMatch(matchKey, query) {
var r = [],
a = matchKey.split('');
var queryIndex = 0,
q = query.split('');
for (var i = 0, l = a.length; i < l; i++) {
var v = a[i];
if (v === q[queryIndex]) {
if (queryIndex === q.length - 1) {
r.push([i - q.length + 1, i + 1]);
queryIndex = 0;
continue;
}
queryIndex++;
} else {
queryIndex = 0;
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。