krad 3.4.6 → 3.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/scripts/simple-search.min.js +408 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb15aaa53a496f41b9387eb86e7cb3199a6bd9d6
|
4
|
+
data.tar.gz: 10d4f95b0208ec8307421b6f62a0af0a80a4e36e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 015ff0227d5e2225a9aef93a0a3d6f7c925a7c2a49a5a57b83532902e764d88774b9a7611af0d6d1ba4bad0835f2673c14836469fb05293aa5833c4865764720
|
7
|
+
data.tar.gz: 75b2454544007754cb1955019cde0aecb1284b39d35465c51258543c7c287e4392ae6b5c81bb721024a7fea53e9ccc0c75156de67c7a0a8e178b6c9816760a5c
|
@@ -3,4 +3,411 @@
|
|
3
3
|
* Copyright 2015-2017, Christian Fei
|
4
4
|
* Licensed under MIT (https://github.com/christian-fei/Simple-Jekyll-Search/blob/master/LICENSE.md)
|
5
5
|
*/
|
6
|
-
|
6
|
+
|
7
|
+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
8
|
+
'use strict';
|
9
|
+
|
10
|
+
function fuzzysearch (needle, haystack) {
|
11
|
+
var tlen = haystack.length;
|
12
|
+
var qlen = needle.length;
|
13
|
+
if (qlen > tlen) {
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
if (qlen === tlen) {
|
17
|
+
return needle === haystack;
|
18
|
+
}
|
19
|
+
outer: for (var i = 0, j = 0; i < qlen; i++) {
|
20
|
+
var nch = needle.charCodeAt(i);
|
21
|
+
while (j < tlen) {
|
22
|
+
if (haystack.charCodeAt(j++) === nch) {
|
23
|
+
continue outer;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
return true;
|
29
|
+
}
|
30
|
+
|
31
|
+
module.exports = fuzzysearch;
|
32
|
+
|
33
|
+
},{}],2:[function(require,module,exports){
|
34
|
+
'use strict'
|
35
|
+
module.exports = {
|
36
|
+
load: load
|
37
|
+
}
|
38
|
+
|
39
|
+
function load (location, callback) {
|
40
|
+
var xhr = getXHR()
|
41
|
+
xhr.open('GET', location, true)
|
42
|
+
xhr.onreadystatechange = createStateChangeListener(xhr, callback)
|
43
|
+
xhr.send()
|
44
|
+
}
|
45
|
+
|
46
|
+
function createStateChangeListener (xhr, callback) {
|
47
|
+
return function () {
|
48
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
49
|
+
try {
|
50
|
+
callback(null, JSON.parse(xhr.responseText))
|
51
|
+
} catch (err) {
|
52
|
+
callback(err, null)
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
function getXHR () {
|
59
|
+
return (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
|
60
|
+
}
|
61
|
+
|
62
|
+
},{}],3:[function(require,module,exports){
|
63
|
+
'use strict'
|
64
|
+
module.exports = function OptionsValidator (params) {
|
65
|
+
if (!validateParams(params)) {
|
66
|
+
throw new Error('-- OptionsValidator: required options missing')
|
67
|
+
}
|
68
|
+
if (!(this instanceof OptionsValidator)) {
|
69
|
+
return new OptionsValidator(params)
|
70
|
+
}
|
71
|
+
|
72
|
+
var requiredOptions = params.required
|
73
|
+
|
74
|
+
this.getRequiredOptions = function () {
|
75
|
+
return requiredOptions
|
76
|
+
}
|
77
|
+
|
78
|
+
this.validate = function (parameters) {
|
79
|
+
var errors = []
|
80
|
+
requiredOptions.forEach(function (requiredOptionName) {
|
81
|
+
if (typeof parameters[requiredOptionName] === 'undefined') {
|
82
|
+
errors.push(requiredOptionName)
|
83
|
+
}
|
84
|
+
})
|
85
|
+
return errors
|
86
|
+
}
|
87
|
+
|
88
|
+
function validateParams (params) {
|
89
|
+
if (!params) {
|
90
|
+
return false
|
91
|
+
}
|
92
|
+
return typeof params.required !== 'undefined' && params.required instanceof Array
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
},{}],4:[function(require,module,exports){
|
97
|
+
'use strict'
|
98
|
+
module.exports = {
|
99
|
+
put: put,
|
100
|
+
clear: clear,
|
101
|
+
get: get,
|
102
|
+
search: search,
|
103
|
+
setOptions: setOptions
|
104
|
+
}
|
105
|
+
|
106
|
+
var FuzzySearchStrategy = require('./SearchStrategies/FuzzySearchStrategy')
|
107
|
+
var LiteralSearchStrategy = require('./SearchStrategies/LiteralSearchStrategy')
|
108
|
+
|
109
|
+
var data = []
|
110
|
+
var opt = {}
|
111
|
+
opt.fuzzy = false
|
112
|
+
opt.limit = 10
|
113
|
+
opt.searchStrategy = opt.fuzzy ? FuzzySearchStrategy : LiteralSearchStrategy
|
114
|
+
|
115
|
+
function put (data) {
|
116
|
+
if (isObject(data)) {
|
117
|
+
return addObject(data)
|
118
|
+
}
|
119
|
+
if (isArray(data)) {
|
120
|
+
return addArray(data)
|
121
|
+
}
|
122
|
+
return undefined
|
123
|
+
}
|
124
|
+
function clear () {
|
125
|
+
data.length = 0
|
126
|
+
return data
|
127
|
+
}
|
128
|
+
|
129
|
+
function get () {
|
130
|
+
return data
|
131
|
+
}
|
132
|
+
|
133
|
+
function isObject (obj) { return !!obj && Object.prototype.toString.call(obj) === '[object Object]' }
|
134
|
+
function isArray (obj) { return !!obj && Object.prototype.toString.call(obj) === '[object Array]' }
|
135
|
+
|
136
|
+
function addObject (_data) {
|
137
|
+
data.push(_data)
|
138
|
+
return data
|
139
|
+
}
|
140
|
+
|
141
|
+
function addArray (_data) {
|
142
|
+
var added = []
|
143
|
+
for (var i = 0; i < _data.length; i++) {
|
144
|
+
if (isObject(_data[i])) {
|
145
|
+
added.push(addObject(_data[i]))
|
146
|
+
}
|
147
|
+
}
|
148
|
+
return added
|
149
|
+
}
|
150
|
+
|
151
|
+
function search (crit) {
|
152
|
+
if (!crit) {
|
153
|
+
return []
|
154
|
+
}
|
155
|
+
return findMatches(data, crit, opt.searchStrategy, opt)
|
156
|
+
}
|
157
|
+
|
158
|
+
function setOptions (_opt) {
|
159
|
+
opt = _opt || {}
|
160
|
+
|
161
|
+
opt.fuzzy = _opt.fuzzy || false
|
162
|
+
opt.limit = _opt.limit || 10
|
163
|
+
opt.searchStrategy = _opt.fuzzy ? FuzzySearchStrategy : LiteralSearchStrategy
|
164
|
+
}
|
165
|
+
|
166
|
+
function findMatches (data, crit, strategy, opt) {
|
167
|
+
var matches = []
|
168
|
+
for (var i = 0; i < data.length && matches.length < opt.limit; i++) {
|
169
|
+
var match = findMatchesInObject(data[i], crit, strategy, opt)
|
170
|
+
if (match) {
|
171
|
+
matches.push(match)
|
172
|
+
}
|
173
|
+
}
|
174
|
+
return matches
|
175
|
+
}
|
176
|
+
|
177
|
+
function findMatchesInObject (obj, crit, strategy, opt) {
|
178
|
+
for (var key in obj) {
|
179
|
+
if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
|
180
|
+
return obj
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
function isExcluded (term, excludedTerms) {
|
186
|
+
var excluded = false
|
187
|
+
excludedTerms = excludedTerms || []
|
188
|
+
for (var i = 0; i < excludedTerms.length; i++) {
|
189
|
+
var excludedTerm = excludedTerms[i]
|
190
|
+
if (!excluded && new RegExp(term).test(excludedTerm)) {
|
191
|
+
excluded = true
|
192
|
+
}
|
193
|
+
}
|
194
|
+
return excluded
|
195
|
+
}
|
196
|
+
|
197
|
+
},{"./SearchStrategies/FuzzySearchStrategy":5,"./SearchStrategies/LiteralSearchStrategy":6}],5:[function(require,module,exports){
|
198
|
+
'use strict'
|
199
|
+
var fuzzysearch = require('fuzzysearch')
|
200
|
+
|
201
|
+
module.exports = new FuzzySearchStrategy()
|
202
|
+
|
203
|
+
function FuzzySearchStrategy () {
|
204
|
+
this.matches = function (string, crit) {
|
205
|
+
return fuzzysearch(crit, string)
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
},{"fuzzysearch":1}],6:[function(require,module,exports){
|
210
|
+
'use strict'
|
211
|
+
module.exports = new LiteralSearchStrategy()
|
212
|
+
|
213
|
+
function LiteralSearchStrategy () {
|
214
|
+
this.matches = function (string, crit) {
|
215
|
+
if (typeof string !== 'string') {
|
216
|
+
return false
|
217
|
+
}
|
218
|
+
string = string.trim()
|
219
|
+
return string.toLowerCase().indexOf(crit.toLowerCase()) >= 0
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
},{}],7:[function(require,module,exports){
|
224
|
+
'use strict'
|
225
|
+
module.exports = {
|
226
|
+
compile: compile,
|
227
|
+
setOptions: setOptions
|
228
|
+
}
|
229
|
+
|
230
|
+
var options = {}
|
231
|
+
options.pattern = /\{(.*?)\}/g
|
232
|
+
options.template = ''
|
233
|
+
options.middleware = function () {}
|
234
|
+
|
235
|
+
function setOptions (_options) {
|
236
|
+
options.pattern = _options.pattern || options.pattern
|
237
|
+
options.template = _options.template || options.template
|
238
|
+
if (typeof _options.middleware === 'function') {
|
239
|
+
options.middleware = _options.middleware
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
function compile (data) {
|
244
|
+
return options.template.replace(options.pattern, function (match, prop) {
|
245
|
+
var value = options.middleware(prop, data[prop], options.template)
|
246
|
+
if (typeof value !== 'undefined') {
|
247
|
+
return value
|
248
|
+
}
|
249
|
+
return data[prop] || match
|
250
|
+
})
|
251
|
+
}
|
252
|
+
|
253
|
+
},{}],8:[function(require,module,exports){
|
254
|
+
/*!
|
255
|
+
* Simple-Jekyll-Search v1.4.1 (https://github.com/christian-fei/Simple-Jekyll-Search)
|
256
|
+
* Copyright 2015-2017, Christian Fei
|
257
|
+
* Licensed under MIT (https://github.com/christian-fei/Simple-Jekyll-Search/blob/master/LICENSE.md)
|
258
|
+
*/
|
259
|
+
|
260
|
+
;(function (window, document) {
|
261
|
+
'use strict'
|
262
|
+
|
263
|
+
var options = {
|
264
|
+
searchInput: null,
|
265
|
+
resultsContainer: null,
|
266
|
+
json: [],
|
267
|
+
searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
|
268
|
+
templateMiddleware: function () {},
|
269
|
+
noResultsText: 'No results found',
|
270
|
+
limit: 10,
|
271
|
+
fuzzy: false,
|
272
|
+
exclude: []
|
273
|
+
}
|
274
|
+
|
275
|
+
var requiredOptions = ['searchInput', 'resultsContainer', 'json']
|
276
|
+
|
277
|
+
var templater = require('./Templater')
|
278
|
+
var repository = require('./Repository')
|
279
|
+
var jsonLoader = require('./JSONLoader')
|
280
|
+
var optionsValidator = require('./OptionsValidator')({
|
281
|
+
required: requiredOptions
|
282
|
+
})
|
283
|
+
var utils = require('./utils')
|
284
|
+
|
285
|
+
/*
|
286
|
+
Public API
|
287
|
+
*/
|
288
|
+
window.SimpleJekyllSearch = function SimpleJekyllSearch (_options) {
|
289
|
+
var errors = optionsValidator.validate(_options)
|
290
|
+
if (errors.length > 0) {
|
291
|
+
throwError('You must specify the following required options: ' + requiredOptions)
|
292
|
+
}
|
293
|
+
|
294
|
+
options = utils.merge(options, _options)
|
295
|
+
|
296
|
+
templater.setOptions({
|
297
|
+
template: options.searchResultTemplate,
|
298
|
+
middleware: options.templateMiddleware
|
299
|
+
})
|
300
|
+
|
301
|
+
repository.setOptions({
|
302
|
+
fuzzy: options.fuzzy,
|
303
|
+
limit: options.limit
|
304
|
+
})
|
305
|
+
|
306
|
+
if (utils.isJSON(options.json)) {
|
307
|
+
initWithJSON(options.json)
|
308
|
+
} else {
|
309
|
+
initWithURL(options.json)
|
310
|
+
}
|
311
|
+
|
312
|
+
return {
|
313
|
+
search: search
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
// for backwards compatibility
|
318
|
+
window.SimpleJekyllSearch.init = window.SimpleJekyllSearch
|
319
|
+
|
320
|
+
if (typeof window.SimpleJekyllSearchInit === 'function') {
|
321
|
+
window.SimpleJekyllSearchInit.call(this, window.SimpleJekyllSearch)
|
322
|
+
}
|
323
|
+
|
324
|
+
function initWithJSON (json) {
|
325
|
+
repository.put(json)
|
326
|
+
registerInput()
|
327
|
+
}
|
328
|
+
|
329
|
+
function initWithURL (url) {
|
330
|
+
jsonLoader.load(url, function (err, json) {
|
331
|
+
if (err) {
|
332
|
+
throwError('failed to get JSON (' + url + ')')
|
333
|
+
}
|
334
|
+
initWithJSON(json)
|
335
|
+
})
|
336
|
+
}
|
337
|
+
|
338
|
+
function emptyResultsContainer () {
|
339
|
+
options.resultsContainer.innerHTML = ''
|
340
|
+
}
|
341
|
+
|
342
|
+
function appendToResultsContainer (text) {
|
343
|
+
options.resultsContainer.innerHTML += text
|
344
|
+
}
|
345
|
+
|
346
|
+
function registerInput () {
|
347
|
+
options.searchInput.addEventListener('keyup', function (e) {
|
348
|
+
var key = e.which
|
349
|
+
if (isWhitelistedKey(key)) {
|
350
|
+
emptyResultsContainer()
|
351
|
+
var query = e.target.value
|
352
|
+
search(query)
|
353
|
+
}
|
354
|
+
})
|
355
|
+
}
|
356
|
+
|
357
|
+
function search (query) {
|
358
|
+
if (isValidQuery(query)) {
|
359
|
+
render(repository.search(query))
|
360
|
+
}
|
361
|
+
}
|
362
|
+
|
363
|
+
function render (results) {
|
364
|
+
var len = results.length
|
365
|
+
if (len === 0) {
|
366
|
+
return appendToResultsContainer(options.noResultsText)
|
367
|
+
}
|
368
|
+
for (var i = 0; i < len; i++) {
|
369
|
+
appendToResultsContainer(templater.compile(results[i]))
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
function isValidQuery (query) {
|
374
|
+
return query && query.length > 0
|
375
|
+
}
|
376
|
+
|
377
|
+
function isWhitelistedKey (key) {
|
378
|
+
return [13, 16, 20, 37, 38, 39, 40, 91].indexOf(key) === -1
|
379
|
+
}
|
380
|
+
|
381
|
+
function throwError (message) { throw new Error('SimpleJekyllSearch --- ' + message) }
|
382
|
+
})(window, document)
|
383
|
+
|
384
|
+
},{"./JSONLoader":2,"./OptionsValidator":3,"./Repository":4,"./Templater":7,"./utils":9}],9:[function(require,module,exports){
|
385
|
+
'use strict'
|
386
|
+
module.exports = {
|
387
|
+
merge: merge,
|
388
|
+
isJSON: isJSON
|
389
|
+
}
|
390
|
+
|
391
|
+
function merge (defaultParams, mergeParams) {
|
392
|
+
var mergedOptions = {}
|
393
|
+
for (var option in defaultParams) {
|
394
|
+
mergedOptions[option] = defaultParams[option]
|
395
|
+
if (typeof mergeParams[option] !== 'undefined') {
|
396
|
+
mergedOptions[option] = mergeParams[option]
|
397
|
+
}
|
398
|
+
}
|
399
|
+
return mergedOptions
|
400
|
+
}
|
401
|
+
|
402
|
+
function isJSON (json) {
|
403
|
+
try {
|
404
|
+
if (json instanceof Object && JSON.parse(JSON.stringify(json))) {
|
405
|
+
return true
|
406
|
+
}
|
407
|
+
return false
|
408
|
+
} catch (e) {
|
409
|
+
return false
|
410
|
+
}
|
411
|
+
}
|
412
|
+
|
413
|
+
},{}]},{},[8]);
|