Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Commit

Permalink
Update JavaScript components
Browse files Browse the repository at this point in the history
Now that mauriciogentile/angular-livesearch#8 is in, we can overwrite the
hand-honed hack introduced in #271.
  • Loading branch information
Mike Bland committed May 21, 2015
1 parent 792fee3 commit d42860f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 75 deletions.
21 changes: 15 additions & 6 deletions assets/js/vendor/angular-livesearch/liveSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ angular.module("LiveSearch", ["ng"])
scope: {
liveSearchCallback: '=',
liveSearchSelect: '=?',
liveSearchSelectCallback: '=',
liveSearchItemTemplate: '@',
liveSearchWaitTimeout: '=?',
liveSearchMaxResultSize: '=?'
liveSearchMaxResultSize: '=?',
liveSearchMaxlength: '=?'
},
template: "<input type='text' />",
link: function (scope, element, attrs, controller) {
Expand All @@ -32,11 +34,17 @@ angular.module("LiveSearch", ["ng"])
scope.$watch("selectedIndex", function(newValue, oldValue) {
var item = scope.results[newValue];
if(item) {
if(attrs.liveSearchSelect) {
element.val(item[attrs.liveSearchSelect]);
if(attrs.liveSearchSelectCallback) {
var value = scope.liveSearchSelectCallback.call(null, {items: scope.results, item: item});
element.val(value);
}
else {
element.val(item);
if (attrs.liveSearchSelect) {
element.val(item[attrs.liveSearchSelect]);
}
else {
element.val(item);
}
}
}
if ('undefined' !== element.controller('ngModel')) {
Expand Down Expand Up @@ -94,7 +102,8 @@ angular.module("LiveSearch", ["ng"])
var vals = target.val().split(",");
var search_string = vals[vals.length - 1].trim();
// Do Search
if (search_string.length < 3) {
if (search_string.length < 3 ||
(scope.liveSearchMaxlength !== null && search_string.length > scope.liveSearchMaxlength)) {
scope.visible = false;
//unmanaged code needs to force apply
scope.$apply();
Expand Down Expand Up @@ -131,7 +140,7 @@ angular.module("LiveSearch", ["ng"])
};

var itemTemplate = element.attr("live-search-item-template") || "{{result}}";
var template = "<ul ng-show='visible' ng-style=\"{'top':top,'left':left,'width':width}\" class='searchresultspopup'><li ng-class=\"{ 'selected' : isSelected($index) }\" ng-click='select($index)' ng-repeat='result in results' id='search_result_{{$index}}'>" + itemTemplate + "</li></ul>";
var template = "<ul ng-show='visible' ng-style=\"{'top':top,'left':left,'width':width}\" class='searchresultspopup'><li ng-class=\"{ 'selected' : isSelected($index) }\" ng-click='select($index)' ng-repeat='result in results'>" + itemTemplate + "</li></ul>";
var searchPopup = $compile(template)(scope);
document.body.appendChild(searchPopup[0]);
}
Expand Down
138 changes: 72 additions & 66 deletions assets/js/vendor/lunr.js/lunr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.7
* Copyright (C) 2014 Oliver Nightingale
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.9
* Copyright (C) 2015 Oliver Nightingale
* MIT Licensed
* @license
*/
Expand Down Expand Up @@ -56,10 +56,10 @@ var lunr = function (config) {
return idx
}

lunr.version = "0.5.7"
lunr.version = "0.5.9"
/*!
* lunr.utils
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand All @@ -83,7 +83,7 @@ lunr.utils.warn = (function (global) {

/*!
* lunr.EventEmitter
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -165,7 +165,7 @@ lunr.EventEmitter.prototype.hasHandler = function (name) {

/*!
* lunr.tokenizer
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand All @@ -180,27 +180,12 @@ lunr.tokenizer = function (obj) {
if (!arguments.length || obj == null || obj == undefined) return []
if (Array.isArray(obj)) return obj.map(function (t) { return t.toLowerCase() })

var str = obj.toString().replace(/^\s+/, '')

for (var i = str.length - 1; i >= 0; i--) {
if (/\S/.test(str.charAt(i))) {
str = str.substring(0, i + 1)
break
}
}

return str
.split(/(?:\s+|\-)/)
.filter(function (token) {
return !!token
})
.map(function (token) {
return token.toLowerCase()
})
return obj.toString().trim().toLowerCase().split(/[\s\-]+/)
}

/*!
* lunr.Pipeline
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -295,7 +280,7 @@ lunr.Pipeline.load = function (serialised) {
if (fn) {
pipeline.add(fn)
} else {
throw new Error ('Cannot load un-registered function: ' + fnName)
throw new Error('Cannot load un-registered function: ' + fnName)
}
})

Expand Down Expand Up @@ -332,7 +317,12 @@ lunr.Pipeline.prototype.add = function () {
lunr.Pipeline.prototype.after = function (existingFn, newFn) {
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)

var pos = this._stack.indexOf(existingFn) + 1
var pos = this._stack.indexOf(existingFn)
if (pos == -1) {
throw new Error('Cannot find existingFn')
}

pos = pos + 1
this._stack.splice(pos, 0, newFn)
}

Expand All @@ -350,6 +340,10 @@ lunr.Pipeline.prototype.before = function (existingFn, newFn) {
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)

var pos = this._stack.indexOf(existingFn)
if (pos == -1) {
throw new Error('Cannot find existingFn')
}

this._stack.splice(pos, 0, newFn)
}

Expand All @@ -361,6 +355,10 @@ lunr.Pipeline.prototype.before = function (existingFn, newFn) {
*/
lunr.Pipeline.prototype.remove = function (fn) {
var pos = this._stack.indexOf(fn)
if (pos == -1) {
return
}

this._stack.splice(pos, 1)
}

Expand Down Expand Up @@ -417,7 +415,7 @@ lunr.Pipeline.prototype.toJSON = function () {
}
/*!
* lunr.Vector
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -457,13 +455,19 @@ lunr.Vector.Node = function (idx, val, next) {
* @memberOf Vector.
*/
lunr.Vector.prototype.insert = function (idx, val) {
this._magnitude = undefined;
var list = this.list

if (!list) {
this.list = new lunr.Vector.Node (idx, val, list)
return this.length++
}

if (idx < list.idx) {
this.list = new lunr.Vector.Node (idx, val, list)
return this.length++
}

var prev = list,
next = list.next

Expand All @@ -487,7 +491,7 @@ lunr.Vector.prototype.insert = function (idx, val) {
* @memberOf Vector
*/
lunr.Vector.prototype.magnitude = function () {
if (this._magniture) return this._magnitude
if (this._magnitude) return this._magnitude
var node = this.list,
sumOfSquares = 0,
val
Expand Down Expand Up @@ -542,7 +546,7 @@ lunr.Vector.prototype.similarity = function (otherVector) {
}
/*!
* lunr.SortedSet
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -580,10 +584,13 @@ lunr.SortedSet.load = function (serialisedData) {
* @memberOf SortedSet
*/
lunr.SortedSet.prototype.add = function () {
Array.prototype.slice.call(arguments).forEach(function (element) {
if (~this.indexOf(element)) return
var i, element

for (i = 0; i < arguments.length; i++) {
element = arguments[i]
if (~this.indexOf(element)) continue
this.elements.splice(this.locationFor(element), 0, element)
}, this)
}

this.length = this.elements.length
}
Expand Down Expand Up @@ -635,31 +642,30 @@ lunr.SortedSet.prototype.forEach = function (fn, ctx) {
* sorted set, or -1 if it is not present.
*
* @param {Object} elem The object to locate in the sorted set.
* @param {Number} start An optional index at which to start searching from
* within the set.
* @param {Number} end An optional index at which to stop search from within
* the set.
* @returns {Number}
* @memberOf SortedSet
*/
lunr.SortedSet.prototype.indexOf = function (elem, start, end) {
var start = start || 0,
end = end || this.elements.length,
lunr.SortedSet.prototype.indexOf = function (elem) {
var start = 0,
end = this.elements.length,
sectionLength = end - start,
pivot = start + Math.floor(sectionLength / 2),
pivotElem = this.elements[pivot]

if (sectionLength <= 1) {
if (pivotElem === elem) {
return pivot
} else {
return -1
}
while (sectionLength > 1) {
if (pivotElem === elem) return pivot

if (pivotElem < elem) start = pivot
if (pivotElem > elem) end = pivot

sectionLength = end - start
pivot = start + Math.floor(sectionLength / 2)
pivotElem = this.elements[pivot]
}

if (pivotElem < elem) return this.indexOf(elem, pivot, end)
if (pivotElem > elem) return this.indexOf(elem, start, pivot)
if (pivotElem === elem) return pivot

return -1
}

/**
Expand All @@ -670,27 +676,27 @@ lunr.SortedSet.prototype.indexOf = function (elem, start, end) {
* in the sorted set.
*
* @param {Object} elem The elem to find the position for in the set
* @param {Number} start An optional index at which to start searching from
* within the set.
* @param {Number} end An optional index at which to stop search from within
* the set.
* @returns {Number}
* @memberOf SortedSet
*/
lunr.SortedSet.prototype.locationFor = function (elem, start, end) {
var start = start || 0,
end = end || this.elements.length,
lunr.SortedSet.prototype.locationFor = function (elem) {
var start = 0,
end = this.elements.length,
sectionLength = end - start,
pivot = start + Math.floor(sectionLength / 2),
pivotElem = this.elements[pivot]

if (sectionLength <= 1) {
if (pivotElem > elem) return pivot
if (pivotElem < elem) return pivot + 1
while (sectionLength > 1) {
if (pivotElem < elem) start = pivot
if (pivotElem > elem) end = pivot

sectionLength = end - start
pivot = start + Math.floor(sectionLength / 2)
pivotElem = this.elements[pivot]
}

if (pivotElem < elem) return this.locationFor(elem, pivot, end)
if (pivotElem > elem) return this.locationFor(elem, start, pivot)
if (pivotElem > elem) return pivot
if (pivotElem < elem) return pivot + 1
}

/**
Expand Down Expand Up @@ -780,7 +786,7 @@ lunr.SortedSet.prototype.toJSON = function () {
}
/*!
* lunr.Index
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -1201,7 +1207,7 @@ lunr.Index.prototype.use = function (plugin) {
}
/*!
* lunr.Store
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -1297,13 +1303,13 @@ lunr.Store.prototype.toJSON = function () {

/*!
* lunr.stemmer
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
* Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
*/

/**
* lunr.stemmer is an english language stemmer, this is a JavaScript
* implementation of the PorterStemmer taken from http://tartaurs.org/~martin
* implementation of the PorterStemmer taken from http://tartarus.org/~martin
*
* @module
* @param {String} str The string to stem
Expand Down Expand Up @@ -1515,7 +1521,7 @@ lunr.stemmer = (function(){
lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer')
/*!
* lunr.stopWordFilter
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -1662,7 +1668,7 @@ lunr.stopWordFilter.stopWords.elements = [
lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter')
/*!
* lunr.trimmer
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
*/

/**
Expand All @@ -1688,7 +1694,7 @@ lunr.trimmer = function (token) {
lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')
/*!
* lunr.stemmer
* Copyright (C) 2014 Oliver Nightingale
* Copyright (C) 2015 Oliver Nightingale
* Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
*/

Expand Down

0 comments on commit d42860f

Please sign in to comment.