assets/scripts/simple-search.min.js in krad-3.4.6 vs assets/scripts/simple-search.min.js in krad-3.4.7
- old
+ new
@@ -1,6 +1,413 @@
/*!
* Simple-Jekyll-Search v1.4.1 (https://github.com/christian-fei/Simple-Jekyll-Search)
* Copyright 2015-2017, Christian Fei
* Licensed under MIT (https://github.com/christian-fei/Simple-Jekyll-Search/blob/master/LICENSE.md)
*/
-!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]);
\ No newline at end of file
+
+(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){
+'use strict';
+
+function fuzzysearch (needle, haystack) {
+ var tlen = haystack.length;
+ var qlen = needle.length;
+ if (qlen > tlen) {
+ return false;
+ }
+ if (qlen === tlen) {
+ return needle === haystack;
+ }
+ outer: for (var i = 0, j = 0; i < qlen; i++) {
+ var nch = needle.charCodeAt(i);
+ while (j < tlen) {
+ if (haystack.charCodeAt(j++) === nch) {
+ continue outer;
+ }
+ }
+ return false;
+ }
+ return true;
+}
+
+module.exports = fuzzysearch;
+
+},{}],2:[function(require,module,exports){
+'use strict'
+module.exports = {
+ load: load
+}
+
+function load (location, callback) {
+ var xhr = getXHR()
+ xhr.open('GET', location, true)
+ xhr.onreadystatechange = createStateChangeListener(xhr, callback)
+ xhr.send()
+}
+
+function createStateChangeListener (xhr, callback) {
+ return function () {
+ if (xhr.readyState === 4 && xhr.status === 200) {
+ try {
+ callback(null, JSON.parse(xhr.responseText))
+ } catch (err) {
+ callback(err, null)
+ }
+ }
+ }
+}
+
+function getXHR () {
+ return (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
+}
+
+},{}],3:[function(require,module,exports){
+'use strict'
+module.exports = function OptionsValidator (params) {
+ if (!validateParams(params)) {
+ throw new Error('-- OptionsValidator: required options missing')
+ }
+ if (!(this instanceof OptionsValidator)) {
+ return new OptionsValidator(params)
+ }
+
+ var requiredOptions = params.required
+
+ this.getRequiredOptions = function () {
+ return requiredOptions
+ }
+
+ this.validate = function (parameters) {
+ var errors = []
+ requiredOptions.forEach(function (requiredOptionName) {
+ if (typeof parameters[requiredOptionName] === 'undefined') {
+ errors.push(requiredOptionName)
+ }
+ })
+ return errors
+ }
+
+ function validateParams (params) {
+ if (!params) {
+ return false
+ }
+ return typeof params.required !== 'undefined' && params.required instanceof Array
+ }
+}
+
+},{}],4:[function(require,module,exports){
+'use strict'
+module.exports = {
+ put: put,
+ clear: clear,
+ get: get,
+ search: search,
+ setOptions: setOptions
+}
+
+var FuzzySearchStrategy = require('./SearchStrategies/FuzzySearchStrategy')
+var LiteralSearchStrategy = require('./SearchStrategies/LiteralSearchStrategy')
+
+var data = []
+var opt = {}
+opt.fuzzy = false
+opt.limit = 10
+opt.searchStrategy = opt.fuzzy ? FuzzySearchStrategy : LiteralSearchStrategy
+
+function put (data) {
+ if (isObject(data)) {
+ return addObject(data)
+ }
+ if (isArray(data)) {
+ return addArray(data)
+ }
+ return undefined
+}
+function clear () {
+ data.length = 0
+ return data
+}
+
+function get () {
+ return data
+}
+
+function isObject (obj) { return !!obj && Object.prototype.toString.call(obj) === '[object Object]' }
+function isArray (obj) { return !!obj && Object.prototype.toString.call(obj) === '[object Array]' }
+
+function addObject (_data) {
+ data.push(_data)
+ return data
+}
+
+function addArray (_data) {
+ var added = []
+ for (var i = 0; i < _data.length; i++) {
+ if (isObject(_data[i])) {
+ added.push(addObject(_data[i]))
+ }
+ }
+ return added
+}
+
+function search (crit) {
+ if (!crit) {
+ return []
+ }
+ return findMatches(data, crit, opt.searchStrategy, opt)
+}
+
+function setOptions (_opt) {
+ opt = _opt || {}
+
+ opt.fuzzy = _opt.fuzzy || false
+ opt.limit = _opt.limit || 10
+ opt.searchStrategy = _opt.fuzzy ? FuzzySearchStrategy : LiteralSearchStrategy
+}
+
+function findMatches (data, crit, strategy, opt) {
+ var matches = []
+ for (var i = 0; i < data.length && matches.length < opt.limit; i++) {
+ var match = findMatchesInObject(data[i], crit, strategy, opt)
+ if (match) {
+ matches.push(match)
+ }
+ }
+ return matches
+}
+
+function findMatchesInObject (obj, crit, strategy, opt) {
+ for (var key in obj) {
+ if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
+ return obj
+ }
+ }
+}
+
+function isExcluded (term, excludedTerms) {
+ var excluded = false
+ excludedTerms = excludedTerms || []
+ for (var i = 0; i < excludedTerms.length; i++) {
+ var excludedTerm = excludedTerms[i]
+ if (!excluded && new RegExp(term).test(excludedTerm)) {
+ excluded = true
+ }
+ }
+ return excluded
+}
+
+},{"./SearchStrategies/FuzzySearchStrategy":5,"./SearchStrategies/LiteralSearchStrategy":6}],5:[function(require,module,exports){
+'use strict'
+var fuzzysearch = require('fuzzysearch')
+
+module.exports = new FuzzySearchStrategy()
+
+function FuzzySearchStrategy () {
+ this.matches = function (string, crit) {
+ return fuzzysearch(crit, string)
+ }
+}
+
+},{"fuzzysearch":1}],6:[function(require,module,exports){
+'use strict'
+module.exports = new LiteralSearchStrategy()
+
+function LiteralSearchStrategy () {
+ this.matches = function (string, crit) {
+ if (typeof string !== 'string') {
+ return false
+ }
+ string = string.trim()
+ return string.toLowerCase().indexOf(crit.toLowerCase()) >= 0
+ }
+}
+
+},{}],7:[function(require,module,exports){
+'use strict'
+module.exports = {
+ compile: compile,
+ setOptions: setOptions
+}
+
+var options = {}
+options.pattern = /\{(.*?)\}/g
+options.template = ''
+options.middleware = function () {}
+
+function setOptions (_options) {
+ options.pattern = _options.pattern || options.pattern
+ options.template = _options.template || options.template
+ if (typeof _options.middleware === 'function') {
+ options.middleware = _options.middleware
+ }
+}
+
+function compile (data) {
+ return options.template.replace(options.pattern, function (match, prop) {
+ var value = options.middleware(prop, data[prop], options.template)
+ if (typeof value !== 'undefined') {
+ return value
+ }
+ return data[prop] || match
+ })
+}
+
+},{}],8:[function(require,module,exports){
+/*!
+ * Simple-Jekyll-Search v1.4.1 (https://github.com/christian-fei/Simple-Jekyll-Search)
+ * Copyright 2015-2017, Christian Fei
+ * Licensed under MIT (https://github.com/christian-fei/Simple-Jekyll-Search/blob/master/LICENSE.md)
+ */
+
+;(function (window, document) {
+ 'use strict'
+
+ var options = {
+ searchInput: null,
+ resultsContainer: null,
+ json: [],
+ searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
+ templateMiddleware: function () {},
+ noResultsText: 'No results found',
+ limit: 10,
+ fuzzy: false,
+ exclude: []
+ }
+
+ var requiredOptions = ['searchInput', 'resultsContainer', 'json']
+
+ var templater = require('./Templater')
+ var repository = require('./Repository')
+ var jsonLoader = require('./JSONLoader')
+ var optionsValidator = require('./OptionsValidator')({
+ required: requiredOptions
+ })
+ var utils = require('./utils')
+
+ /*
+ Public API
+ */
+ window.SimpleJekyllSearch = function SimpleJekyllSearch (_options) {
+ var errors = optionsValidator.validate(_options)
+ if (errors.length > 0) {
+ throwError('You must specify the following required options: ' + requiredOptions)
+ }
+
+ options = utils.merge(options, _options)
+
+ templater.setOptions({
+ template: options.searchResultTemplate,
+ middleware: options.templateMiddleware
+ })
+
+ repository.setOptions({
+ fuzzy: options.fuzzy,
+ limit: options.limit
+ })
+
+ if (utils.isJSON(options.json)) {
+ initWithJSON(options.json)
+ } else {
+ initWithURL(options.json)
+ }
+
+ return {
+ search: search
+ }
+ }
+
+ // for backwards compatibility
+ window.SimpleJekyllSearch.init = window.SimpleJekyllSearch
+
+ if (typeof window.SimpleJekyllSearchInit === 'function') {
+ window.SimpleJekyllSearchInit.call(this, window.SimpleJekyllSearch)
+ }
+
+ function initWithJSON (json) {
+ repository.put(json)
+ registerInput()
+ }
+
+ function initWithURL (url) {
+ jsonLoader.load(url, function (err, json) {
+ if (err) {
+ throwError('failed to get JSON (' + url + ')')
+ }
+ initWithJSON(json)
+ })
+ }
+
+ function emptyResultsContainer () {
+ options.resultsContainer.innerHTML = ''
+ }
+
+ function appendToResultsContainer (text) {
+ options.resultsContainer.innerHTML += text
+ }
+
+ function registerInput () {
+ options.searchInput.addEventListener('keyup', function (e) {
+ var key = e.which
+ if (isWhitelistedKey(key)) {
+ emptyResultsContainer()
+ var query = e.target.value
+ search(query)
+ }
+ })
+ }
+
+ function search (query) {
+ if (isValidQuery(query)) {
+ render(repository.search(query))
+ }
+ }
+
+ function render (results) {
+ var len = results.length
+ if (len === 0) {
+ return appendToResultsContainer(options.noResultsText)
+ }
+ for (var i = 0; i < len; i++) {
+ appendToResultsContainer(templater.compile(results[i]))
+ }
+ }
+
+ function isValidQuery (query) {
+ return query && query.length > 0
+ }
+
+ function isWhitelistedKey (key) {
+ return [13, 16, 20, 37, 38, 39, 40, 91].indexOf(key) === -1
+ }
+
+ function throwError (message) { throw new Error('SimpleJekyllSearch --- ' + message) }
+})(window, document)
+
+},{"./JSONLoader":2,"./OptionsValidator":3,"./Repository":4,"./Templater":7,"./utils":9}],9:[function(require,module,exports){
+'use strict'
+module.exports = {
+ merge: merge,
+ isJSON: isJSON
+}
+
+function merge (defaultParams, mergeParams) {
+ var mergedOptions = {}
+ for (var option in defaultParams) {
+ mergedOptions[option] = defaultParams[option]
+ if (typeof mergeParams[option] !== 'undefined') {
+ mergedOptions[option] = mergeParams[option]
+ }
+ }
+ return mergedOptions
+}
+
+function isJSON (json) {
+ try {
+ if (json instanceof Object && JSON.parse(JSON.stringify(json))) {
+ return true
+ }
+ return false
+ } catch (e) {
+ return false
+ }
+}
+
+},{}]},{},[8]);