krad 3.4.6 → 3.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba84c630f9fac72bebc6b7fdb9bb6860bc6c6e1c
4
- data.tar.gz: 209fae286dcc054b4116fc83159d5782c0a925a8
3
+ metadata.gz: eb15aaa53a496f41b9387eb86e7cb3199a6bd9d6
4
+ data.tar.gz: 10d4f95b0208ec8307421b6f62a0af0a80a4e36e
5
5
  SHA512:
6
- metadata.gz: ec9d58b9b5cc1175e26df4b7665c6ceaf080d0827423cb75575f157d2dd0213154e9071ee076b840c6c8da3e48c8081493e8034c70f2b66fb4ac13caab94eb7c
7
- data.tar.gz: 033e7eb010da0ef000e284439765c36f406abbeefd3d499c8d66bfa75b9fb9c5c4fd0c46efa885503378cbd520ef111336c22c4de71c1c9651b572cc79f26d09
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
- !function t(e,r,n){function i(o,a){if(!r[o]){if(!e[o]){var c="function"==typeof require&&require;if(!a&&c)return c(o,!0);if(u)return u(o,!0);var s=new Error("Cannot find module '"+o+"'");throw s.code="MODULE_NOT_FOUND",s}var f=r[o]={exports:{}};e[o][0].call(f.exports,function(t){var r=e[o][1][t];return i(r||t)},f,f.exports,t,e,r,n)}return r[o].exports}for(var u="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(t,e,r){"use strict";e.exports=function(t,e){var r=e.length,n=t.length;if(n>r)return!1;if(n===r)return t===e;t:for(var i=0,u=0;i<n;i++){for(var o=t.charCodeAt(i);u<r;)if(e.charCodeAt(u++)===o)continue t;return!1}return!0}},{}],2:[function(t,e,r){"use strict";function n(t,e){return function(){if(4===t.readyState&&200===t.status)try{e(null,JSON.parse(t.responseText))}catch(r){e(r,null)}}}function i(){return window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP")}e.exports={load:function(t,e){var r=i();r.open("GET",t,!0),r.onreadystatechange=n(r,e),r.send()}}},{}],3:[function(t,e,r){"use strict";e.exports=function n(t){if(!function(t){return!!t&&"undefined"!=typeof t.required&&t.required instanceof Array}(t))throw new Error("-- OptionsValidator: required options missing");if(!(this instanceof n))return new n(t);var e=t.required;this.getRequiredOptions=function(){return e},this.validate=function(t){var r=[];return e.forEach(function(e){"undefined"==typeof t[e]&&r.push(e)}),r}}},{}],4:[function(t,e,r){"use strict";function n(t){return!!t&&"[object Object]"===Object.prototype.toString.call(t)}function i(t){return!!t&&"[object Array]"===Object.prototype.toString.call(t)}function u(t){return p.push(t),p}function o(t){for(var e=[],r=0;r<t.length;r++)n(t[r])&&e.push(u(t[r]));return e}function a(t,e,r,n){for(var i=[],u=0;u<t.length&&i.length<n.limit;u++){var o=c(t[u],e,r,n);o&&i.push(o)}return i}function c(t,e,r,n){for(var i in t)if(!s(t[i],n.exclude)&&r.matches(t[i],e))return t}function s(t,e){var r=!1;e=e||[];for(var n=0;n<e.length;n++){var i=e[n];!r&&new RegExp(t).test(i)&&(r=!0)}return r}e.exports={put:function(t){return n(t)?u(t):i(t)?o(t):undefined},clear:function(){return p.length=0,p},get:function(){return p},search:function(t){return t?a(p,t,h.searchStrategy,h):[]},setOptions:function(t){(h=t||{}).fuzzy=t.fuzzy||!1,h.limit=t.limit||10,h.searchStrategy=t.fuzzy?f:l}};var f=t("./SearchStrategies/FuzzySearchStrategy"),l=t("./SearchStrategies/LiteralSearchStrategy"),p=[],h={};h.fuzzy=!1,h.limit=10,h.searchStrategy=h.fuzzy?f:l},{"./SearchStrategies/FuzzySearchStrategy":5,"./SearchStrategies/LiteralSearchStrategy":6}],5:[function(t,e,r){"use strict";var n=t("fuzzysearch");e.exports=new function(){this.matches=function(t,e){return n(e,t)}}},{fuzzysearch:1}],6:[function(t,e,r){"use strict";e.exports=new function(){this.matches=function(t,e){return"string"==typeof t&&(t=t.trim()).toLowerCase().indexOf(e.toLowerCase())>=0}}},{}],7:[function(t,e,r){"use strict";e.exports={compile:function(t){return n.template.replace(n.pattern,function(e,r){var i=n.middleware(r,t[r],n.template);return void 0!==i?i:t[r]||e})},setOptions:function(t){n.pattern=t.pattern||n.pattern,n.template=t.template||n.template,"function"==typeof t.middleware&&(n.middleware=t.middleware)}};var n={};n.pattern=/\{(.*?)\}/g,n.template="",n.middleware=function(){}},{}],8:[function(t,e,r){!function(e,r){"use strict";function n(t){m.put(t),a()}function i(t){S.load(t,function(e,r){e&&p("failed to get JSON ("+t+")"),n(r)})}function u(){h.resultsContainer.innerHTML=""}function o(t){h.resultsContainer.innerHTML+=t}function a(){h.searchInput.addEventListener("keyup",function(t){l(t.which)&&(u(),c(t.target.value))})}function c(t){f(t)&&s(m.search(t))}function s(t){var e=t.length;if(0===e)return o(h.noResultsText);for(var r=0;r<e;r++)o(y.compile(t[r]))}function f(t){return t&&t.length>0}function l(t){return-1===[13,16,20,37,38,39,40,91].indexOf(t)}function p(t){throw new Error("SimpleJekyllSearch --- "+t)}var h={searchInput:null,resultsContainer:null,json:[],searchResultTemplate:'<li><a href="{url}" title="{desc}">{title}</a></li>',templateMiddleware:function(){},noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]},d=["searchInput","resultsContainer","json"],y=t("./Templater"),m=t("./Repository"),S=t("./JSONLoader"),g=t("./OptionsValidator")({required:d}),v=t("./utils");e.SimpleJekyllSearch=function(t){return g.validate(t).length>0&&p("You must specify the following required options: "+d),h=v.merge(h,t),y.setOptions({template:h.searchResultTemplate,middleware:h.templateMiddleware}),m.setOptions({fuzzy:h.fuzzy,limit:h.limit}),v.isJSON(h.json)?n(h.json):i(h.json),{search:c}},e.SimpleJekyllSearch.init=e.SimpleJekyllSearch,"function"==typeof e.SimpleJekyllSearchInit&&e.SimpleJekyllSearchInit.call(this,e.SimpleJekyllSearch)}(window,document)},{"./JSONLoader":2,"./OptionsValidator":3,"./Repository":4,"./Templater":7,"./utils":9}],9:[function(t,e,r){"use strict";e.exports={merge:function(t,e){var r={};for(var n in t)r[n]=t[n],"undefined"!=typeof e[n]&&(r[n]=e[n]);return r},isJSON:function(t){try{return!!(t instanceof Object&&JSON.parse(JSON.stringify(t)))}catch(e){return!1}}}},{}]},{},[8]);
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]);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krad
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.6
4
+ version: 3.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lê Thanh Tùng