| 1 |
/*! docsearch 2.6.1 | © Algolia | github.com/algolia/docsearch */ |
| 2 |
(function webpackUniversalModuleDefinition(root, factory) { |
| 3 |
if(typeof exports === 'object' && typeof module === 'object') |
| 4 |
module.exports = factory(); |
| 5 |
else if(typeof define === 'function' && define.amd) |
| 6 |
define([], factory); |
| 7 |
else if(typeof exports === 'object') |
| 8 |
exports["docsearch"] = factory(); |
| 9 |
else |
| 10 |
root["docsearch"] = factory(); |
| 11 |
})(typeof self !== 'undefined' ? self : this, function() { |
| 12 |
return /******/ (function(modules) { // webpackBootstrap |
| 13 |
/******/ // The module cache |
| 14 |
/******/ var installedModules = {}; |
| 15 |
/******/ |
| 16 |
/******/ // The require function |
| 17 |
/******/ function __webpack_require__(moduleId) { |
| 18 |
/******/ |
| 19 |
/******/ // Check if module is in cache |
| 20 |
/******/ if(installedModules[moduleId]) { |
| 21 |
/******/ return installedModules[moduleId].exports; |
| 22 |
/******/ } |
| 23 |
/******/ // Create a new module (and put it into the cache) |
| 24 |
/******/ var module = installedModules[moduleId] = { |
| 25 |
/******/ i: moduleId, |
| 26 |
/******/ l: false, |
| 27 |
/******/ exports: {} |
| 28 |
/******/ }; |
| 29 |
/******/ |
| 30 |
/******/ // Execute the module function |
| 31 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 32 |
/******/ |
| 33 |
/******/ // Flag the module as loaded |
| 34 |
/******/ module.l = true; |
| 35 |
/******/ |
| 36 |
/******/ // Return the exports of the module |
| 37 |
/******/ return module.exports; |
| 38 |
/******/ } |
| 39 |
/******/ |
| 40 |
/******/ |
| 41 |
/******/ // expose the modules object (__webpack_modules__) |
| 42 |
/******/ __webpack_require__.m = modules; |
| 43 |
/******/ |
| 44 |
/******/ // expose the module cache |
| 45 |
/******/ __webpack_require__.c = installedModules; |
| 46 |
/******/ |
| 47 |
/******/ // define getter function for harmony exports |
| 48 |
/******/ __webpack_require__.d = function(exports, name, getter) { |
| 49 |
/******/ if(!__webpack_require__.o(exports, name)) { |
| 50 |
/******/ Object.defineProperty(exports, name, { |
| 51 |
/******/ configurable: false, |
| 52 |
/******/ enumerable: true, |
| 53 |
/******/ get: getter |
| 54 |
/******/ }); |
| 55 |
/******/ } |
| 56 |
/******/ }; |
| 57 |
/******/ |
| 58 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 59 |
/******/ __webpack_require__.n = function(module) { |
| 60 |
/******/ var getter = module && module.__esModule ? |
| 61 |
/******/ function getDefault() { return module['default']; } : |
| 62 |
/******/ function getModuleExports() { return module; }; |
| 63 |
/******/ __webpack_require__.d(getter, 'a', getter); |
| 64 |
/******/ return getter; |
| 65 |
/******/ }; |
| 66 |
/******/ |
| 67 |
/******/ // Object.prototype.hasOwnProperty.call |
| 68 |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
| 69 |
/******/ |
| 70 |
/******/ // __webpack_public_path__ |
| 71 |
/******/ __webpack_require__.p = ""; |
| 72 |
/******/ |
| 73 |
/******/ // Load entry module and return exports |
| 74 |
/******/ return __webpack_require__(__webpack_require__.s = 22); |
| 75 |
/******/ }) |
| 76 |
/************************************************************************/ |
| 77 |
/******/ ([ |
| 78 |
/* 0 */ |
| 79 |
/***/ (function(module, exports, __webpack_require__) { |
| 80 |
|
| 81 |
"use strict"; |
| 82 |
|
| 83 |
|
| 84 |
var DOM = __webpack_require__(1); |
| 85 |
|
| 86 |
function escapeRegExp(str) { |
| 87 |
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); |
| 88 |
} |
| 89 |
|
| 90 |
module.exports = { |
| 91 |
// those methods are implemented differently |
| 92 |
// depending on which build it is, using |
| 93 |
// $... or angular... or Zepto... or require(...) |
| 94 |
isArray: null, |
| 95 |
isFunction: null, |
| 96 |
isObject: null, |
| 97 |
bind: null, |
| 98 |
each: null, |
| 99 |
map: null, |
| 100 |
mixin: null, |
| 101 |
|
| 102 |
isMsie: function(agentString) { |
| 103 |
if (agentString === undefined) { agentString = navigator.userAgent; } |
| 104 |
// from https://github.com/ded/bowser/blob/master/bowser.js |
| 105 |
if ((/(msie|trident)/i).test(agentString)) { |
| 106 |
var match = agentString.match(/(msie |rv:)(\d+(.\d+)?)/i); |
| 107 |
if (match) { return match[2]; } |
| 108 |
} |
| 109 |
return false; |
| 110 |
}, |
| 111 |
|
| 112 |
// http://stackoverflow.com/a/6969486 |
| 113 |
escapeRegExChars: function(str) { |
| 114 |
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); |
| 115 |
}, |
| 116 |
|
| 117 |
isNumber: function(obj) { return typeof obj === 'number'; }, |
| 118 |
|
| 119 |
toStr: function toStr(s) { |
| 120 |
return s === undefined || s === null ? '' : s + ''; |
| 121 |
}, |
| 122 |
|
| 123 |
cloneDeep: function cloneDeep(obj) { |
| 124 |
var clone = this.mixin({}, obj); |
| 125 |
var self = this; |
| 126 |
this.each(clone, function(value, key) { |
| 127 |
if (value) { |
| 128 |
if (self.isArray(value)) { |
| 129 |
clone[key] = [].concat(value); |
| 130 |
} else if (self.isObject(value)) { |
| 131 |
clone[key] = self.cloneDeep(value); |
| 132 |
} |
| 133 |
} |
| 134 |
}); |
| 135 |
return clone; |
| 136 |
}, |
| 137 |
|
| 138 |
error: function(msg) { |
| 139 |
throw new Error(msg); |
| 140 |
}, |
| 141 |
|
| 142 |
every: function(obj, test) { |
| 143 |
var result = true; |
| 144 |
if (!obj) { |
| 145 |
return result; |
| 146 |
} |
| 147 |
this.each(obj, function(val, key) { |
| 148 |
result = test.call(null, val, key, obj); |
| 149 |
if (!result) { |
| 150 |
return false; |
| 151 |
} |
| 152 |
}); |
| 153 |
return !!result; |
| 154 |
}, |
| 155 |
|
| 156 |
any: function(obj, test) { |
| 157 |
var found = false; |
| 158 |
if (!obj) { |
| 159 |
return found; |
| 160 |
} |
| 161 |
this.each(obj, function(val, key) { |
| 162 |
if (test.call(null, val, key, obj)) { |
| 163 |
found = true; |
| 164 |
return false; |
| 165 |
} |
| 166 |
}); |
| 167 |
return found; |
| 168 |
}, |
| 169 |
|
| 170 |
getUniqueId: (function() { |
| 171 |
var counter = 0; |
| 172 |
return function() { return counter++; }; |
| 173 |
})(), |
| 174 |
|
| 175 |
templatify: function templatify(obj) { |
| 176 |
if (this.isFunction(obj)) { |
| 177 |
return obj; |
| 178 |
} |
| 179 |
var $template = DOM.element(obj); |
| 180 |
if ($template.prop('tagName') === 'SCRIPT') { |
| 181 |
return function template() { return $template.text(); }; |
| 182 |
} |
| 183 |
return function template() { return String(obj); }; |
| 184 |
}, |
| 185 |
|
| 186 |
defer: function(fn) { setTimeout(fn, 0); }, |
| 187 |
|
| 188 |
noop: function() {}, |
| 189 |
|
| 190 |
formatPrefix: function(prefix, noPrefix) { |
| 191 |
return noPrefix ? '' : prefix + '-'; |
| 192 |
}, |
| 193 |
|
| 194 |
className: function(prefix, clazz, skipDot) { |
| 195 |
return (skipDot ? '' : '.') + prefix + clazz; |
| 196 |
}, |
| 197 |
|
| 198 |
escapeHighlightedString: function(str, highlightPreTag, highlightPostTag) { |
| 199 |
highlightPreTag = highlightPreTag || '<em>'; |
| 200 |
var pre = document.createElement('div'); |
| 201 |
pre.appendChild(document.createTextNode(highlightPreTag)); |
| 202 |
|
| 203 |
highlightPostTag = highlightPostTag || '</em>'; |
| 204 |
var post = document.createElement('div'); |
| 205 |
post.appendChild(document.createTextNode(highlightPostTag)); |
| 206 |
|
| 207 |
var div = document.createElement('div'); |
| 208 |
div.appendChild(document.createTextNode(str)); |
| 209 |
return div.innerHTML |
| 210 |
.replace(RegExp(escapeRegExp(pre.innerHTML), 'g'), highlightPreTag) |
| 211 |
.replace(RegExp(escapeRegExp(post.innerHTML), 'g'), highlightPostTag); |
| 212 |
} |
| 213 |
}; |
| 214 |
|
| 215 |
|
| 216 |
/***/ }), |
| 217 |
/* 1 */ |
| 218 |
/***/ (function(module, exports, __webpack_require__) { |
| 219 |
|
| 220 |
"use strict"; |
| 221 |
|
| 222 |
|
| 223 |
module.exports = { |
| 224 |
element: null |
| 225 |
}; |
| 226 |
|
| 227 |
|
| 228 |
/***/ }), |
| 229 |
/* 2 */ |
| 230 |
/***/ (function(module, exports) { |
| 231 |
|
| 232 |
|
| 233 |
var hasOwn = Object.prototype.hasOwnProperty; |
| 234 |
var toString = Object.prototype.toString; |
| 235 |
|
| 236 |
module.exports = function forEach (obj, fn, ctx) { |
| 237 |
if (toString.call(fn) !== '[object Function]') { |
| 238 |
throw new TypeError('iterator must be a function'); |
| 239 |
} |
| 240 |
var l = obj.length; |
| 241 |
if (l === +l) { |
| 242 |
for (var i = 0; i < l; i++) { |
| 243 |
fn.call(ctx, obj[i], i, obj); |
| 244 |
} |
| 245 |
} else { |
| 246 |
for (var k in obj) { |
| 247 |
if (hasOwn.call(obj, k)) { |
| 248 |
fn.call(ctx, obj[k], k, obj); |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
}; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
/***/ }), |
| 257 |
/* 3 */ |
| 258 |
/***/ (function(module, exports) { |
| 259 |
|
| 260 |
module.exports = function clone(obj) { |
| 261 |
return JSON.parse(JSON.stringify(obj)); |
| 262 |
}; |
| 263 |
|
| 264 |
|
| 265 |
/***/ }), |
| 266 |
/* 4 */ |
| 267 |
/***/ (function(module, exports) { |
| 268 |
|
| 269 |
var g; |
| 270 |
|
| 271 |
// This works in non-strict mode |
| 272 |
g = (function() { |
| 273 |
return this; |
| 274 |
})(); |
| 275 |
|
| 276 |
try { |
| 277 |
// This works if eval is allowed (see CSP) |
| 278 |
g = g || Function("return this")() || (1,eval)("this"); |
| 279 |
} catch(e) { |
| 280 |
// This works if the window reference is available |
| 281 |
if(typeof window === "object") |
| 282 |
g = window; |
| 283 |
} |
| 284 |
|
| 285 |
// g can still be undefined, but nothing to do about it... |
| 286 |
// We return undefined, instead of nothing here, so it's |
| 287 |
// easier to handle this case. if(!global) { ...} |
| 288 |
|
| 289 |
module.exports = g; |
| 290 |
|
| 291 |
|
| 292 |
/***/ }), |
| 293 |
/* 5 */ |
| 294 |
/***/ (function(module, exports, __webpack_require__) { |
| 295 |
|
| 296 |
"use strict"; |
| 297 |
|
| 298 |
|
| 299 |
// This file hosts our error definitions |
| 300 |
// We use custom error "types" so that we can act on them when we need it |
| 301 |
// e.g.: if error instanceof errors.UnparsableJSON then.. |
| 302 |
|
| 303 |
var inherits = __webpack_require__(12); |
| 304 |
|
| 305 |
function AlgoliaSearchError(message, extraProperties) { |
| 306 |
var forEach = __webpack_require__(2); |
| 307 |
|
| 308 |
var error = this; |
| 309 |
|
| 310 |
// try to get a stacktrace |
| 311 |
if (typeof Error.captureStackTrace === 'function') { |
| 312 |
Error.captureStackTrace(this, this.constructor); |
| 313 |
} else { |
| 314 |
error.stack = (new Error()).stack || 'Cannot get a stacktrace, browser is too old'; |
| 315 |
} |
| 316 |
|
| 317 |
this.name = 'AlgoliaSearchError'; |
| 318 |
this.message = message || 'Unknown error'; |
| 319 |
|
| 320 |
if (extraProperties) { |
| 321 |
forEach(extraProperties, function addToErrorObject(value, key) { |
| 322 |
error[key] = value; |
| 323 |
}); |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
inherits(AlgoliaSearchError, Error); |
| 328 |
|
| 329 |
function createCustomError(name, message) { |
| 330 |
function AlgoliaSearchCustomError() { |
| 331 |
var args = Array.prototype.slice.call(arguments, 0); |
| 332 |
|
| 333 |
// custom message not set, use default |
| 334 |
if (typeof args[0] !== 'string') { |
| 335 |
args.unshift(message); |
| 336 |
} |
| 337 |
|
| 338 |
AlgoliaSearchError.apply(this, args); |
| 339 |
this.name = 'AlgoliaSearch' + name + 'Error'; |
| 340 |
} |
| 341 |
|
| 342 |
inherits(AlgoliaSearchCustomError, AlgoliaSearchError); |
| 343 |
|
| 344 |
return AlgoliaSearchCustomError; |
| 345 |
} |
| 346 |
|
| 347 |
// late exports to let various fn defs and inherits take place |
| 348 |
module.exports = { |
| 349 |
AlgoliaSearchError: AlgoliaSearchError, |
| 350 |
UnparsableJSON: createCustomError( |
| 351 |
'UnparsableJSON', |
| 352 |
'Could not parse the incoming response as JSON, see err.more for details' |
| 353 |
), |
| 354 |
RequestTimeout: createCustomError( |
| 355 |
'RequestTimeout', |
| 356 |
'Request timedout before getting a response' |
| 357 |
), |
| 358 |
Network: createCustomError( |
| 359 |
'Network', |
| 360 |
'Network issue, see err.more for details' |
| 361 |
), |
| 362 |
JSONPScriptFail: createCustomError( |
| 363 |
'JSONPScriptFail', |
| 364 |
'<script> was loaded but did not call our provided callback' |
| 365 |
), |
| 366 |
JSONPScriptError: createCustomError( |
| 367 |
'JSONPScriptError', |
| 368 |
'<script> unable to load due to an `error` event on it' |
| 369 |
), |
| 370 |
Unknown: createCustomError( |
| 371 |
'Unknown', |
| 372 |
'Unknown error occured' |
| 373 |
) |
| 374 |
}; |
| 375 |
|
| 376 |
|
| 377 |
/***/ }), |
| 378 |
/* 6 */ |
| 379 |
/***/ (function(module, exports) { |
| 380 |
|
| 381 |
var toString = {}.toString; |
| 382 |
|
| 383 |
module.exports = Array.isArray || function (arr) { |
| 384 |
return toString.call(arr) == '[object Array]'; |
| 385 |
}; |
| 386 |
|
| 387 |
|
| 388 |
/***/ }), |
| 389 |
/* 7 */ |
| 390 |
/***/ (function(module, exports, __webpack_require__) { |
| 391 |
|
| 392 |
var foreach = __webpack_require__(2); |
| 393 |
|
| 394 |
module.exports = function map(arr, fn) { |
| 395 |
var newArr = []; |
| 396 |
foreach(arr, function(item, itemIndex) { |
| 397 |
newArr.push(fn(item, itemIndex, arr)); |
| 398 |
}); |
| 399 |
return newArr; |
| 400 |
}; |
| 401 |
|
| 402 |
|
| 403 |
/***/ }), |
| 404 |
/* 8 */ |
| 405 |
/***/ (function(module, exports, __webpack_require__) { |
| 406 |
|
| 407 |
/* WEBPACK VAR INJECTION */(function(process) {/** |
| 408 |
* This is the web browser implementation of `debug()`. |
| 409 |
* |
| 410 |
* Expose `debug()` as the module. |
| 411 |
*/ |
| 412 |
|
| 413 |
exports = module.exports = __webpack_require__(39); |
| 414 |
exports.log = log; |
| 415 |
exports.formatArgs = formatArgs; |
| 416 |
exports.save = save; |
| 417 |
exports.load = load; |
| 418 |
exports.useColors = useColors; |
| 419 |
exports.storage = 'undefined' != typeof chrome |
| 420 |
&& 'undefined' != typeof chrome.storage |
| 421 |
? chrome.storage.local |
| 422 |
: localstorage(); |
| 423 |
|
| 424 |
/** |
| 425 |
* Colors. |
| 426 |
*/ |
| 427 |
|
| 428 |
exports.colors = [ |
| 429 |
'lightseagreen', |
| 430 |
'forestgreen', |
| 431 |
'goldenrod', |
| 432 |
'dodgerblue', |
| 433 |
'darkorchid', |
| 434 |
'crimson' |
| 435 |
]; |
| 436 |
|
| 437 |
/** |
| 438 |
* Currently only WebKit-based Web Inspectors, Firefox >= v31, |
| 439 |
* and the Firebug extension (any Firefox version) are known |
| 440 |
* to support "%c" CSS customizations. |
| 441 |
* |
| 442 |
* TODO: add a `localStorage` variable to explicitly enable/disable colors |
| 443 |
*/ |
| 444 |
|
| 445 |
function useColors() { |
| 446 |
// NB: In an Electron preload script, document will be defined but not fully |
| 447 |
// initialized. Since we know we're in Chrome, we'll just detect this case |
| 448 |
// explicitly |
| 449 |
if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') { |
| 450 |
return true; |
| 451 |
} |
| 452 |
|
| 453 |
// is webkit? http://stackoverflow.com/a/16459606/376773 |
| 454 |
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 |
| 455 |
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || |
| 456 |
// is firebug? http://stackoverflow.com/a/398120/376773 |
| 457 |
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || |
| 458 |
// is firefox >= v31? |
| 459 |
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages |
| 460 |
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || |
| 461 |
// double check webkit in userAgent just in case we are in a worker |
| 462 |
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. |
| 467 |
*/ |
| 468 |
|
| 469 |
exports.formatters.j = function(v) { |
| 470 |
try { |
| 471 |
return JSON.stringify(v); |
| 472 |
} catch (err) { |
| 473 |
return '[UnexpectedJSONParseError]: ' + err.message; |
| 474 |
} |
| 475 |
}; |
| 476 |
|
| 477 |
|
| 478 |
/** |
| 479 |
* Colorize log arguments if enabled. |
| 480 |
* |
| 481 |
* @api public |
| 482 |
*/ |
| 483 |
|
| 484 |
function formatArgs(args) { |
| 485 |
var useColors = this.useColors; |
| 486 |
|
| 487 |
args[0] = (useColors ? '%c' : '') |
| 488 |
+ this.namespace |
| 489 |
+ (useColors ? ' %c' : ' ') |
| 490 |
+ args[0] |
| 491 |
+ (useColors ? '%c ' : ' ') |
| 492 |
+ '+' + exports.humanize(this.diff); |
| 493 |
|
| 494 |
if (!useColors) return; |
| 495 |
|
| 496 |
var c = 'color: ' + this.color; |
| 497 |
args.splice(1, 0, c, 'color: inherit') |
| 498 |
|
| 499 |
// the final "%c" is somewhat tricky, because there could be other |
| 500 |
// arguments passed either before or after the %c, so we need to |
| 501 |
// figure out the correct index to insert the CSS into |
| 502 |
var index = 0; |
| 503 |
var lastC = 0; |
| 504 |
args[0].replace(/%[a-zA-Z%]/g, function(match) { |
| 505 |
if ('%%' === match) return; |
| 506 |
index++; |
| 507 |
if ('%c' === match) { |
| 508 |
// we only are interested in the *last* %c |
| 509 |
// (the user may have provided their own) |
| 510 |
lastC = index; |
| 511 |
} |
| 512 |
}); |
| 513 |
|
| 514 |
args.splice(lastC, 0, c); |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Invokes `console.log()` when available. |
| 519 |
* No-op when `console.log` is not a "function". |
| 520 |
* |
| 521 |
* @api public |
| 522 |
*/ |
| 523 |
|
| 524 |
function log() { |
| 525 |
// this hackery is required for IE8/9, where |
| 526 |
// the `console.log` function doesn't have 'apply' |
| 527 |
return 'object' === typeof console |
| 528 |
&& console.log |
| 529 |
&& Function.prototype.apply.call(console.log, console, arguments); |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* Save `namespaces`. |
| 534 |
* |
| 535 |
* @param {String} namespaces |
| 536 |
* @api private |
| 537 |
*/ |
| 538 |
|
| 539 |
function save(namespaces) { |
| 540 |
try { |
| 541 |
if (null == namespaces) { |
| 542 |
exports.storage.removeItem('debug'); |
| 543 |
} else { |
| 544 |
exports.storage.debug = namespaces; |
| 545 |
} |
| 546 |
} catch(e) {} |
| 547 |
} |
| 548 |
|
| 549 |
/** |
| 550 |
* Load `namespaces`. |
| 551 |
* |
| 552 |
* @return {String} returns the previously persisted debug modes |
| 553 |
* @api private |
| 554 |
*/ |
| 555 |
|
| 556 |
function load() { |
| 557 |
var r; |
| 558 |
try { |
| 559 |
r = exports.storage.debug; |
| 560 |
} catch(e) {} |
| 561 |
|
| 562 |
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG |
| 563 |
if (!r && typeof process !== 'undefined' && 'env' in process) { |
| 564 |
r = Object({"NODE_ENV":"production"}).DEBUG; |
| 565 |
} |
| 566 |
|
| 567 |
return r; |
| 568 |
} |
| 569 |
|
| 570 |
/** |
| 571 |
* Enable namespaces listed in `localStorage.debug` initially. |
| 572 |
*/ |
| 573 |
|
| 574 |
exports.enable(load()); |
| 575 |
|
| 576 |
/** |
| 577 |
* Localstorage attempts to return the localstorage. |
| 578 |
* |
| 579 |
* This is necessary because safari throws |
| 580 |
* when a user disables cookies/localstorage |
| 581 |
* and you attempt to access it. |
| 582 |
* |
| 583 |
* @return {LocalStorage} |
| 584 |
* @api private |
| 585 |
*/ |
| 586 |
|
| 587 |
function localstorage() { |
| 588 |
try { |
| 589 |
return window.localStorage; |
| 590 |
} catch (e) {} |
| 591 |
} |
| 592 |
|
| 593 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9))) |
| 594 |
|
| 595 |
/***/ }), |
| 596 |
/* 9 */ |
| 597 |
/***/ (function(module, exports) { |
| 598 |
|
| 599 |
// shim for using process in browser |
| 600 |
var process = module.exports = {}; |
| 601 |
|
| 602 |
// cached from whatever global is present so that test runners that stub it |
| 603 |
// don't break things. But we need to wrap it in a try catch in case it is |
| 604 |
// wrapped in strict mode code which doesn't define any globals. It's inside a |
| 605 |
// function because try/catches deoptimize in certain engines. |
| 606 |
|
| 607 |
var cachedSetTimeout; |
| 608 |
var cachedClearTimeout; |
| 609 |
|
| 610 |
function defaultSetTimout() { |
| 611 |
throw new Error('setTimeout has not been defined'); |
| 612 |
} |
| 613 |
function defaultClearTimeout () { |
| 614 |
throw new Error('clearTimeout has not been defined'); |
| 615 |
} |
| 616 |
(function () { |
| 617 |
try { |
| 618 |
if (typeof setTimeout === 'function') { |
| 619 |
cachedSetTimeout = setTimeout; |
| 620 |
} else { |
| 621 |
cachedSetTimeout = defaultSetTimout; |
| 622 |
} |
| 623 |
} catch (e) { |
| 624 |
cachedSetTimeout = defaultSetTimout; |
| 625 |
} |
| 626 |
try { |
| 627 |
if (typeof clearTimeout === 'function') { |
| 628 |
cachedClearTimeout = clearTimeout; |
| 629 |
} else { |
| 630 |
cachedClearTimeout = defaultClearTimeout; |
| 631 |
} |
| 632 |
} catch (e) { |
| 633 |
cachedClearTimeout = defaultClearTimeout; |
| 634 |
} |
| 635 |
} ()) |
| 636 |
function runTimeout(fun) { |
| 637 |
if (cachedSetTimeout === setTimeout) { |
| 638 |
//normal enviroments in sane situations |
| 639 |
return setTimeout(fun, 0); |
| 640 |
} |
| 641 |
// if setTimeout wasn't available but was latter defined |
| 642 |
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { |
| 643 |
cachedSetTimeout = setTimeout; |
| 644 |
return setTimeout(fun, 0); |
| 645 |
} |
| 646 |
try { |
| 647 |
// when when somebody has screwed with setTimeout but no I.E. maddness |
| 648 |
return cachedSetTimeout(fun, 0); |
| 649 |
} catch(e){ |
| 650 |
try { |
| 651 |
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally |
| 652 |
return cachedSetTimeout.call(null, fun, 0); |
| 653 |
} catch(e){ |
| 654 |
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error |
| 655 |
return cachedSetTimeout.call(this, fun, 0); |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
} |
| 661 |
function runClearTimeout(marker) { |
| 662 |
if (cachedClearTimeout === clearTimeout) { |
| 663 |
//normal enviroments in sane situations |
| 664 |
return clearTimeout(marker); |
| 665 |
} |
| 666 |
// if clearTimeout wasn't available but was latter defined |
| 667 |
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { |
| 668 |
cachedClearTimeout = clearTimeout; |
| 669 |
return clearTimeout(marker); |
| 670 |
} |
| 671 |
try { |
| 672 |
// when when somebody has screwed with setTimeout but no I.E. maddness |
| 673 |
return cachedClearTimeout(marker); |
| 674 |
} catch (e){ |
| 675 |
try { |
| 676 |
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally |
| 677 |
return cachedClearTimeout.call(null, marker); |
| 678 |
} catch (e){ |
| 679 |
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. |
| 680 |
// Some versions of I.E. have different rules for clearTimeout vs setTimeout |
| 681 |
return cachedClearTimeout.call(this, marker); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
} |
| 688 |
var queue = []; |
| 689 |
var draining = false; |
| 690 |
var currentQueue; |
| 691 |
var queueIndex = -1; |
| 692 |
|
| 693 |
function cleanUpNextTick() { |
| 694 |
if (!draining || !currentQueue) { |
| 695 |
return; |
| 696 |
} |
| 697 |
draining = false; |
| 698 |
if (currentQueue.length) { |
| 699 |
queue = currentQueue.concat(queue); |
| 700 |
} else { |
| 701 |
queueIndex = -1; |
| 702 |
} |
| 703 |
if (queue.length) { |
| 704 |
drainQueue(); |
| 705 |
} |
| 706 |
} |
| 707 |
|
| 708 |
function drainQueue() { |
| 709 |
if (draining) { |
| 710 |
return; |
| 711 |
} |
| 712 |
var timeout = runTimeout(cleanUpNextTick); |
| 713 |
draining = true; |
| 714 |
|
| 715 |
var len = queue.length; |
| 716 |
while(len) { |
| 717 |
currentQueue = queue; |
| 718 |
queue = []; |
| 719 |
while (++queueIndex < len) { |
| 720 |
if (currentQueue) { |
| 721 |
currentQueue[queueIndex].run(); |
| 722 |
} |
| 723 |
} |
| 724 |
queueIndex = -1; |
| 725 |
len = queue.length; |
| 726 |
} |
| 727 |
currentQueue = null; |
| 728 |
draining = false; |
| 729 |
runClearTimeout(timeout); |
| 730 |
} |
| 731 |
|
| 732 |
process.nextTick = function (fun) { |
| 733 |
var args = new Array(arguments.length - 1); |
| 734 |
if (arguments.length > 1) { |
| 735 |
for (var i = 1; i < arguments.length; i++) { |
| 736 |
args[i - 1] = arguments[i]; |
| 737 |
} |
| 738 |
} |
| 739 |
queue.push(new Item(fun, args)); |
| 740 |
if (queue.length === 1 && !draining) { |
| 741 |
runTimeout(drainQueue); |
| 742 |
} |
| 743 |
}; |
| 744 |
|
| 745 |
// v8 likes predictible objects |
| 746 |
function Item(fun, array) { |
| 747 |
this.fun = fun; |
| 748 |
this.array = array; |
| 749 |
} |
| 750 |
Item.prototype.run = function () { |
| 751 |
this.fun.apply(null, this.array); |
| 752 |
}; |
| 753 |
process.title = 'browser'; |
| 754 |
process.browser = true; |
| 755 |
process.env = {}; |
| 756 |
process.argv = []; |
| 757 |
process.version = ''; // empty string to avoid regexp issues |
| 758 |
process.versions = {}; |
| 759 |
|
| 760 |
function noop() {} |
| 761 |
|
| 762 |
process.on = noop; |
| 763 |
process.addListener = noop; |
| 764 |
process.once = noop; |
| 765 |
process.off = noop; |
| 766 |
process.removeListener = noop; |
| 767 |
process.removeAllListeners = noop; |
| 768 |
process.emit = noop; |
| 769 |
process.prependListener = noop; |
| 770 |
process.prependOnceListener = noop; |
| 771 |
|
| 772 |
process.listeners = function (name) { return [] } |
| 773 |
|
| 774 |
process.binding = function (name) { |
| 775 |
throw new Error('process.binding is not supported'); |
| 776 |
}; |
| 777 |
|
| 778 |
process.cwd = function () { return '/' }; |
| 779 |
process.chdir = function (dir) { |
| 780 |
throw new Error('process.chdir is not supported'); |
| 781 |
}; |
| 782 |
process.umask = function() { return 0; }; |
| 783 |
|
| 784 |
|
| 785 |
/***/ }), |
| 786 |
/* 10 */ |
| 787 |
/***/ (function(module, exports, __webpack_require__) { |
| 788 |
|
| 789 |
"use strict"; |
| 790 |
|
| 791 |
|
| 792 |
var immediate = __webpack_require__(53); |
| 793 |
var splitter = /\s+/; |
| 794 |
|
| 795 |
module.exports = { |
| 796 |
onSync: onSync, |
| 797 |
onAsync: onAsync, |
| 798 |
off: off, |
| 799 |
trigger: trigger |
| 800 |
}; |
| 801 |
|
| 802 |
function on(method, types, cb, context) { |
| 803 |
var type; |
| 804 |
|
| 805 |
if (!cb) { |
| 806 |
return this; |
| 807 |
} |
| 808 |
|
| 809 |
types = types.split(splitter); |
| 810 |
cb = context ? bindContext(cb, context) : cb; |
| 811 |
|
| 812 |
this._callbacks = this._callbacks || {}; |
| 813 |
|
| 814 |
while (type = types.shift()) { |
| 815 |
this._callbacks[type] = this._callbacks[type] || {sync: [], async: []}; |
| 816 |
this._callbacks[type][method].push(cb); |
| 817 |
} |
| 818 |
|
| 819 |
return this; |
| 820 |
} |
| 821 |
|
| 822 |
function onAsync(types, cb, context) { |
| 823 |
return on.call(this, 'async', types, cb, context); |
| 824 |
} |
| 825 |
|
| 826 |
function onSync(types, cb, context) { |
| 827 |
return on.call(this, 'sync', types, cb, context); |
| 828 |
} |
| 829 |
|
| 830 |
function off(types) { |
| 831 |
var type; |
| 832 |
|
| 833 |
if (!this._callbacks) { |
| 834 |
return this; |
| 835 |
} |
| 836 |
|
| 837 |
types = types.split(splitter); |
| 838 |
|
| 839 |
while (type = types.shift()) { |
| 840 |
delete this._callbacks[type]; |
| 841 |
} |
| 842 |
|
| 843 |
return this; |
| 844 |
} |
| 845 |
|
| 846 |
function trigger(types) { |
| 847 |
var type; |
| 848 |
var callbacks; |
| 849 |
var args; |
| 850 |
var syncFlush; |
| 851 |
var asyncFlush; |
| 852 |
|
| 853 |
if (!this._callbacks) { |
| 854 |
return this; |
| 855 |
} |
| 856 |
|
| 857 |
types = types.split(splitter); |
| 858 |
args = [].slice.call(arguments, 1); |
| 859 |
|
| 860 |
while ((type = types.shift()) && (callbacks = this._callbacks[type])) { // eslint-disable-line |
| 861 |
syncFlush = getFlush(callbacks.sync, this, [type].concat(args)); |
| 862 |
asyncFlush = getFlush(callbacks.async, this, [type].concat(args)); |
| 863 |
|
| 864 |
if (syncFlush()) { |
| 865 |
immediate(asyncFlush); |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
return this; |
| 870 |
} |
| 871 |
|
| 872 |
function getFlush(callbacks, context, args) { |
| 873 |
return flush; |
| 874 |
|
| 875 |
function flush() { |
| 876 |
var cancelled; |
| 877 |
|
| 878 |
for (var i = 0, len = callbacks.length; !cancelled && i < len; i += 1) { |
| 879 |
// only cancel if the callback explicitly returns false |
| 880 |
cancelled = callbacks[i].apply(context, args) === false; |
| 881 |
} |
| 882 |
|
| 883 |
return !cancelled; |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
function bindContext(fn, context) { |
| 888 |
return fn.bind ? |
| 889 |
fn.bind(context) : |
| 890 |
function() { fn.apply(context, [].slice.call(arguments, 0)); }; |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
/***/ }), |
| 895 |
/* 11 */ |
| 896 |
/***/ (function(module, exports, __webpack_require__) { |
| 897 |
|
| 898 |
"use strict"; |
| 899 |
|
| 900 |
|
| 901 |
var _ = __webpack_require__(0); |
| 902 |
|
| 903 |
var css = { |
| 904 |
wrapper: { |
| 905 |
position: 'relative', |
| 906 |
display: 'inline-block' |
| 907 |
}, |
| 908 |
hint: { |
| 909 |
position: 'absolute', |
| 910 |
top: '0', |
| 911 |
left: '0', |
| 912 |
borderColor: 'transparent', |
| 913 |
boxShadow: 'none', |
| 914 |
// #741: fix hint opacity issue on iOS |
| 915 |
opacity: '1' |
| 916 |
}, |
| 917 |
input: { |
| 918 |
position: 'relative', |
| 919 |
verticalAlign: 'top', |
| 920 |
backgroundColor: 'transparent' |
| 921 |
}, |
| 922 |
inputWithNoHint: { |
| 923 |
position: 'relative', |
| 924 |
verticalAlign: 'top' |
| 925 |
}, |
| 926 |
dropdown: { |
| 927 |
position: 'absolute', |
| 928 |
top: '100%', |
| 929 |
left: '0', |
| 930 |
zIndex: '100', |
| 931 |
display: 'none' |
| 932 |
}, |
| 933 |
suggestions: { |
| 934 |
display: 'block' |
| 935 |
}, |
| 936 |
suggestion: { |
| 937 |
whiteSpace: 'nowrap', |
| 938 |
cursor: 'pointer' |
| 939 |
}, |
| 940 |
suggestionChild: { |
| 941 |
whiteSpace: 'normal' |
| 942 |
}, |
| 943 |
ltr: { |
| 944 |
left: '0', |
| 945 |
right: 'auto' |
| 946 |
}, |
| 947 |
rtl: { |
| 948 |
left: 'auto', |
| 949 |
right: '0' |
| 950 |
}, |
| 951 |
defaultClasses: { |
| 952 |
root: 'algolia-autocomplete', |
| 953 |
prefix: 'aa', |
| 954 |
noPrefix: false, |
| 955 |
dropdownMenu: 'dropdown-menu', |
| 956 |
input: 'input', |
| 957 |
hint: 'hint', |
| 958 |
suggestions: 'suggestions', |
| 959 |
suggestion: 'suggestion', |
| 960 |
cursor: 'cursor', |
| 961 |
dataset: 'dataset', |
| 962 |
empty: 'empty' |
| 963 |
}, |
| 964 |
// will be merged with the default ones if appendTo is used |
| 965 |
appendTo: { |
| 966 |
wrapper: { |
| 967 |
position: 'absolute', |
| 968 |
zIndex: '100', |
| 969 |
display: 'none' |
| 970 |
}, |
| 971 |
input: {}, |
| 972 |
inputWithNoHint: {}, |
| 973 |
dropdown: { |
| 974 |
display: 'block' |
| 975 |
} |
| 976 |
} |
| 977 |
}; |
| 978 |
|
| 979 |
// ie specific styling |
| 980 |
if (_.isMsie()) { |
| 981 |
// ie6-8 (and 9?) doesn't fire hover and click events for elements with |
| 982 |
// transparent backgrounds, for a workaround, use 1x1 transparent gif |
| 983 |
_.mixin(css.input, { |
| 984 |
backgroundImage: 'url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)' |
| 985 |
}); |
| 986 |
} |
| 987 |
|
| 988 |
// ie7 and under specific styling |
| 989 |
if (_.isMsie() && _.isMsie() <= 7) { |
| 990 |
// if someone can tell me why this is necessary to align |
| 991 |
// the hint with the query in ie7, i'll send you $5 - @JakeHarding |
| 992 |
_.mixin(css.input, {marginTop: '-1px'}); |
| 993 |
} |
| 994 |
|
| 995 |
module.exports = css; |
| 996 |
|
| 997 |
|
| 998 |
/***/ }), |
| 999 |
/* 12 */ |
| 1000 |
/***/ (function(module, exports) { |
| 1001 |
|
| 1002 |
if (typeof Object.create === 'function') { |
| 1003 |
// implementation from standard node.js 'util' module |
| 1004 |
module.exports = function inherits(ctor, superCtor) { |
| 1005 |
ctor.super_ = superCtor |
| 1006 |
ctor.prototype = Object.create(superCtor.prototype, { |
| 1007 |
constructor: { |
| 1008 |
value: ctor, |
| 1009 |
enumerable: false, |
| 1010 |
writable: true, |
| 1011 |
configurable: true |
| 1012 |
} |
| 1013 |
}); |
| 1014 |
}; |
| 1015 |
} else { |
| 1016 |
// old school shim for old browsers |
| 1017 |
module.exports = function inherits(ctor, superCtor) { |
| 1018 |
ctor.super_ = superCtor |
| 1019 |
var TempCtor = function () {} |
| 1020 |
TempCtor.prototype = superCtor.prototype |
| 1021 |
ctor.prototype = new TempCtor() |
| 1022 |
ctor.prototype.constructor = ctor |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
/***/ }), |
| 1028 |
/* 13 */ |
| 1029 |
/***/ (function(module, exports, __webpack_require__) { |
| 1030 |
|
| 1031 |
module.exports = buildSearchMethod; |
| 1032 |
|
| 1033 |
var errors = __webpack_require__(5); |
| 1034 |
|
| 1035 |
/** |
| 1036 |
* Creates a search method to be used in clients |
| 1037 |
* @param {string} queryParam the name of the attribute used for the query |
| 1038 |
* @param {string} url the url |
| 1039 |
* @return {function} the search method |
| 1040 |
*/ |
| 1041 |
function buildSearchMethod(queryParam, url) { |
| 1042 |
/** |
| 1043 |
* The search method. Prepares the data and send the query to Algolia. |
| 1044 |
* @param {string} query the string used for query search |
| 1045 |
* @param {object} args additional parameters to send with the search |
| 1046 |
* @param {function} [callback] the callback to be called with the client gets the answer |
| 1047 |
* @return {undefined|Promise} If the callback is not provided then this methods returns a Promise |
| 1048 |
*/ |
| 1049 |
return function search(query, args, callback) { |
| 1050 |
// warn V2 users on how to search |
| 1051 |
if (typeof query === 'function' && typeof args === 'object' || |
| 1052 |
typeof callback === 'object') { |
| 1053 |
// .search(query, params, cb) |
| 1054 |
// .search(cb, params) |
| 1055 |
throw new errors.AlgoliaSearchError('index.search usage is index.search(query, params, cb)'); |
| 1056 |
} |
| 1057 |
|
| 1058 |
// Normalizing the function signature |
| 1059 |
if (arguments.length === 0 || typeof query === 'function') { |
| 1060 |
// Usage : .search(), .search(cb) |
| 1061 |
callback = query; |
| 1062 |
query = ''; |
| 1063 |
} else if (arguments.length === 1 || typeof args === 'function') { |
| 1064 |
// Usage : .search(query/args), .search(query, cb) |
| 1065 |
callback = args; |
| 1066 |
args = undefined; |
| 1067 |
} |
| 1068 |
// At this point we have 3 arguments with values |
| 1069 |
|
| 1070 |
// Usage : .search(args) // careful: typeof null === 'object' |
| 1071 |
if (typeof query === 'object' && query !== null) { |
| 1072 |
args = query; |
| 1073 |
query = undefined; |
| 1074 |
} else if (query === undefined || query === null) { // .search(undefined/null) |
| 1075 |
query = ''; |
| 1076 |
} |
| 1077 |
|
| 1078 |
var params = ''; |
| 1079 |
|
| 1080 |
if (query !== undefined) { |
| 1081 |
params += queryParam + '=' + encodeURIComponent(query); |
| 1082 |
} |
| 1083 |
|
| 1084 |
var additionalUA; |
| 1085 |
if (args !== undefined) { |
| 1086 |
if (args.additionalUA) { |
| 1087 |
additionalUA = args.additionalUA; |
| 1088 |
delete args.additionalUA; |
| 1089 |
} |
| 1090 |
// `_getSearchParams` will augment params, do not be fooled by the = versus += from previous if |
| 1091 |
params = this.as._getSearchParams(args, params); |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
return this._search(params, url, callback, additionalUA); |
| 1096 |
}; |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
/***/ }), |
| 1101 |
/* 14 */ |
| 1102 |
/***/ (function(module, exports, __webpack_require__) { |
| 1103 |
|
| 1104 |
module.exports = function omit(obj, test) { |
| 1105 |
var keys = __webpack_require__(36); |
| 1106 |
var foreach = __webpack_require__(2); |
| 1107 |
|
| 1108 |
var filtered = {}; |
| 1109 |
|
| 1110 |
foreach(keys(obj), function doFilter(keyName) { |
| 1111 |
if (test(keyName) !== true) { |
| 1112 |
filtered[keyName] = obj[keyName]; |
| 1113 |
} |
| 1114 |
}); |
| 1115 |
|
| 1116 |
return filtered; |
| 1117 |
}; |
| 1118 |
|
| 1119 |
|
| 1120 |
/***/ }), |
| 1121 |
/* 15 */ |
| 1122 |
/***/ (function(module, exports) { |
| 1123 |
|
| 1124 |
/* istanbul ignore next */ |
| 1125 |
/* Zepto v1.2.0 - zepto event assets data - zeptojs.com/license */ |
| 1126 |
(function(global, factory) { |
| 1127 |
module.exports = factory(global); |
| 1128 |
}(/* this ##### UPDATED: here we want to use window/global instead of this which is the current file context ##### */ window, function(window) { |
| 1129 |
var Zepto = (function() { |
| 1130 |
var undefined, key, $, classList, emptyArray = [], concat = emptyArray.concat, filter = emptyArray.filter, slice = emptyArray.slice, |
| 1131 |
document = window.document, |
| 1132 |
elementDisplay = {}, classCache = {}, |
| 1133 |
cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 }, |
| 1134 |
fragmentRE = /^\s*<(\w+|!)[^>]*>/, |
| 1135 |
singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, |
| 1136 |
tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, |
| 1137 |
rootNodeRE = /^(?:body|html)$/i, |
| 1138 |
capitalRE = /([A-Z])/g, |
| 1139 |
|
| 1140 |
// special attributes that should be get/set via method calls |
| 1141 |
methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], |
| 1142 |
|
| 1143 |
adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ], |
| 1144 |
table = document.createElement('table'), |
| 1145 |
tableRow = document.createElement('tr'), |
| 1146 |
containers = { |
| 1147 |
'tr': document.createElement('tbody'), |
| 1148 |
'tbody': table, 'thead': table, 'tfoot': table, |
| 1149 |
'td': tableRow, 'th': tableRow, |
| 1150 |
'*': document.createElement('div') |
| 1151 |
}, |
| 1152 |
readyRE = /complete|loaded|interactive/, |
| 1153 |
simpleSelectorRE = /^[\w-]*$/, |
| 1154 |
class2type = {}, |
| 1155 |
toString = class2type.toString, |
| 1156 |
zepto = {}, |
| 1157 |
camelize, uniq, |
| 1158 |
tempParent = document.createElement('div'), |
| 1159 |
propMap = { |
| 1160 |
'tabindex': 'tabIndex', |
| 1161 |
'readonly': 'readOnly', |
| 1162 |
'for': 'htmlFor', |
| 1163 |
'class': 'className', |
| 1164 |
'maxlength': 'maxLength', |
| 1165 |
'cellspacing': 'cellSpacing', |
| 1166 |
'cellpadding': 'cellPadding', |
| 1167 |
'rowspan': 'rowSpan', |
| 1168 |
'colspan': 'colSpan', |
| 1169 |
'usemap': 'useMap', |
| 1170 |
'frameborder': 'frameBorder', |
| 1171 |
'contenteditable': 'contentEditable' |
| 1172 |
}, |
| 1173 |
isArray = Array.isArray || |
| 1174 |
function(object){ return object instanceof Array } |
| 1175 |
|
| 1176 |
zepto.matches = function(element, selector) { |
| 1177 |
if (!selector || !element || element.nodeType !== 1) return false |
| 1178 |
var matchesSelector = element.matches || element.webkitMatchesSelector || |
| 1179 |
element.mozMatchesSelector || element.oMatchesSelector || |
| 1180 |
element.matchesSelector |
| 1181 |
if (matchesSelector) return matchesSelector.call(element, selector) |
| 1182 |
// fall back to performing a selector: |
| 1183 |
var match, parent = element.parentNode, temp = !parent |
| 1184 |
if (temp) (parent = tempParent).appendChild(element) |
| 1185 |
match = ~zepto.qsa(parent, selector).indexOf(element) |
| 1186 |
temp && tempParent.removeChild(element) |
| 1187 |
return match |
| 1188 |
} |
| 1189 |
|
| 1190 |
function type(obj) { |
| 1191 |
return obj == null ? String(obj) : |
| 1192 |
class2type[toString.call(obj)] || "object" |
| 1193 |
} |
| 1194 |
|
| 1195 |
function isFunction(value) { return type(value) == "function" } |
| 1196 |
function isWindow(obj) { return obj != null && obj == obj.window } |
| 1197 |
function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE } |
| 1198 |
function isObject(obj) { return type(obj) == "object" } |
| 1199 |
function isPlainObject(obj) { |
| 1200 |
return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype |
| 1201 |
} |
| 1202 |
|
| 1203 |
function likeArray(obj) { |
| 1204 |
var length = !!obj && 'length' in obj && obj.length, |
| 1205 |
type = $.type(obj) |
| 1206 |
|
| 1207 |
return 'function' != type && !isWindow(obj) && ( |
| 1208 |
'array' == type || length === 0 || |
| 1209 |
(typeof length == 'number' && length > 0 && (length - 1) in obj) |
| 1210 |
) |
| 1211 |
} |
| 1212 |
|
| 1213 |
function compact(array) { return filter.call(array, function(item){ return item != null }) } |
| 1214 |
function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } |
| 1215 |
camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) } |
| 1216 |
function dasherize(str) { |
| 1217 |
return str.replace(/::/g, '/') |
| 1218 |
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') |
| 1219 |
.replace(/([a-z\d])([A-Z])/g, '$1_$2') |
| 1220 |
.replace(/_/g, '-') |
| 1221 |
.toLowerCase() |
| 1222 |
} |
| 1223 |
uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) } |
| 1224 |
|
| 1225 |
function classRE(name) { |
| 1226 |
return name in classCache ? |
| 1227 |
classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)')) |
| 1228 |
} |
| 1229 |
|
| 1230 |
function maybeAddPx(name, value) { |
| 1231 |
return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value |
| 1232 |
} |
| 1233 |
|
| 1234 |
function defaultDisplay(nodeName) { |
| 1235 |
var element, display |
| 1236 |
if (!elementDisplay[nodeName]) { |
| 1237 |
element = document.createElement(nodeName) |
| 1238 |
document.body.appendChild(element) |
| 1239 |
display = getComputedStyle(element, '').getPropertyValue("display") |
| 1240 |
element.parentNode.removeChild(element) |
| 1241 |
display == "none" && (display = "block") |
| 1242 |
elementDisplay[nodeName] = display |
| 1243 |
} |
| 1244 |
return elementDisplay[nodeName] |
| 1245 |
} |
| 1246 |
|
| 1247 |
function children(element) { |
| 1248 |
return 'children' in element ? |
| 1249 |
slice.call(element.children) : |
| 1250 |
$.map(element.childNodes, function(node){ if (node.nodeType == 1) return node }) |
| 1251 |
} |
| 1252 |
|
| 1253 |
function Z(dom, selector) { |
| 1254 |
var i, len = dom ? dom.length : 0 |
| 1255 |
for (i = 0; i < len; i++) this[i] = dom[i] |
| 1256 |
this.length = len |
| 1257 |
this.selector = selector || '' |
| 1258 |
} |
| 1259 |
|
| 1260 |
// `$.zepto.fragment` takes a html string and an optional tag name |
| 1261 |
// to generate DOM nodes from the given html string. |
| 1262 |
// The generated DOM nodes are returned as an array. |
| 1263 |
// This function can be overridden in plugins for example to make |
| 1264 |
// it compatible with browsers that don't support the DOM fully. |
| 1265 |
zepto.fragment = function(html, name, properties) { |
| 1266 |
var dom, nodes, container |
| 1267 |
|
| 1268 |
// A special case optimization for a single tag |
| 1269 |
if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1)) |
| 1270 |
|
| 1271 |
if (!dom) { |
| 1272 |
if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>") |
| 1273 |
if (name === undefined) name = fragmentRE.test(html) && RegExp.$1 |
| 1274 |
if (!(name in containers)) name = '*' |
| 1275 |
|
| 1276 |
container = containers[name] |
| 1277 |
container.innerHTML = '' + html |
| 1278 |
dom = $.each(slice.call(container.childNodes), function(){ |
| 1279 |
container.removeChild(this) |
| 1280 |
}) |
| 1281 |
} |
| 1282 |
|
| 1283 |
if (isPlainObject(properties)) { |
| 1284 |
nodes = $(dom) |
| 1285 |
$.each(properties, function(key, value) { |
| 1286 |
if (methodAttributes.indexOf(key) > -1) nodes[key](value) |
| 1287 |
else nodes.attr(key, value) |
| 1288 |
}) |
| 1289 |
} |
| 1290 |
|
| 1291 |
return dom |
| 1292 |
} |
| 1293 |
|
| 1294 |
// `$.zepto.Z` swaps out the prototype of the given `dom` array |
| 1295 |
// of nodes with `$.fn` and thus supplying all the Zepto functions |
| 1296 |
// to the array. This method can be overridden in plugins. |
| 1297 |
zepto.Z = function(dom, selector) { |
| 1298 |
return new Z(dom, selector) |
| 1299 |
} |
| 1300 |
|
| 1301 |
// `$.zepto.isZ` should return `true` if the given object is a Zepto |
| 1302 |
// collection. This method can be overridden in plugins. |
| 1303 |
zepto.isZ = function(object) { |
| 1304 |
return object instanceof zepto.Z |
| 1305 |
} |
| 1306 |
|
| 1307 |
// `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and |
| 1308 |
// takes a CSS selector and an optional context (and handles various |
| 1309 |
// special cases). |
| 1310 |
// This method can be overridden in plugins. |
| 1311 |
zepto.init = function(selector, context) { |
| 1312 |
var dom |
| 1313 |
// If nothing given, return an empty Zepto collection |
| 1314 |
if (!selector) return zepto.Z() |
| 1315 |
// Optimize for string selectors |
| 1316 |
else if (typeof selector == 'string') { |
| 1317 |
selector = selector.trim() |
| 1318 |
// If it's a html fragment, create nodes from it |
| 1319 |
// Note: In both Chrome 21 and Firefox 15, DOM error 12 |
| 1320 |
// is thrown if the fragment doesn't begin with < |
| 1321 |
if (selector[0] == '<' && fragmentRE.test(selector)) |
| 1322 |
dom = zepto.fragment(selector, RegExp.$1, context), selector = null |
| 1323 |
// If there's a context, create a collection on that context first, and select |
| 1324 |
// nodes from there |
| 1325 |
else if (context !== undefined) return $(context).find(selector) |
| 1326 |
// If it's a CSS selector, use it to select nodes. |
| 1327 |
else dom = zepto.qsa(document, selector) |
| 1328 |
} |
| 1329 |
// If a function is given, call it when the DOM is ready |
| 1330 |
else if (isFunction(selector)) return $(document).ready(selector) |
| 1331 |
// If a Zepto collection is given, just return it |
| 1332 |
else if (zepto.isZ(selector)) return selector |
| 1333 |
else { |
| 1334 |
// normalize array if an array of nodes is given |
| 1335 |
if (isArray(selector)) dom = compact(selector) |
| 1336 |
// Wrap DOM nodes. |
| 1337 |
else if (isObject(selector)) |
| 1338 |
dom = [selector], selector = null |
| 1339 |
// If it's a html fragment, create nodes from it |
| 1340 |
else if (fragmentRE.test(selector)) |
| 1341 |
dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null |
| 1342 |
// If there's a context, create a collection on that context first, and select |
| 1343 |
// nodes from there |
| 1344 |
else if (context !== undefined) return $(context).find(selector) |
| 1345 |
// And last but no least, if it's a CSS selector, use it to select nodes. |
| 1346 |
else dom = zepto.qsa(document, selector) |
| 1347 |
} |
| 1348 |
// create a new Zepto collection from the nodes found |
| 1349 |
return zepto.Z(dom, selector) |
| 1350 |
} |
| 1351 |
|
| 1352 |
// `$` will be the base `Zepto` object. When calling this |
| 1353 |
// function just call `$.zepto.init, which makes the implementation |
| 1354 |
// details of selecting nodes and creating Zepto collections |
| 1355 |
// patchable in plugins. |
| 1356 |
$ = function(selector, context){ |
| 1357 |
return zepto.init(selector, context) |
| 1358 |
} |
| 1359 |
|
| 1360 |
function extend(target, source, deep) { |
| 1361 |
for (key in source) |
| 1362 |
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { |
| 1363 |
if (isPlainObject(source[key]) && !isPlainObject(target[key])) |
| 1364 |
target[key] = {} |
| 1365 |
if (isArray(source[key]) && !isArray(target[key])) |
| 1366 |
target[key] = [] |
| 1367 |
extend(target[key], source[key], deep) |
| 1368 |
} |
| 1369 |
else if (source[key] !== undefined) target[key] = source[key] |
| 1370 |
} |
| 1371 |
|
| 1372 |
// Copy all but undefined properties from one or more |
| 1373 |
// objects to the `target` object. |
| 1374 |
$.extend = function(target){ |
| 1375 |
var deep, args = slice.call(arguments, 1) |
| 1376 |
if (typeof target == 'boolean') { |
| 1377 |
deep = target |
| 1378 |
target = args.shift() |
| 1379 |
} |
| 1380 |
args.forEach(function(arg){ extend(target, arg, deep) }) |
| 1381 |
return target |
| 1382 |
} |
| 1383 |
|
| 1384 |
// `$.zepto.qsa` is Zepto's CSS selector implementation which |
| 1385 |
// uses `document.querySelectorAll` and optimizes for some special cases, like `#id`. |
| 1386 |
// This method can be overridden in plugins. |
| 1387 |
zepto.qsa = function(element, selector){ |
| 1388 |
var found, |
| 1389 |
maybeID = selector[0] == '#', |
| 1390 |
maybeClass = !maybeID && selector[0] == '.', |
| 1391 |
nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked |
| 1392 |
isSimple = simpleSelectorRE.test(nameOnly) |
| 1393 |
return (element.getElementById && isSimple && maybeID) ? // Safari DocumentFragment doesn't have getElementById |
| 1394 |
( (found = element.getElementById(nameOnly)) ? [found] : [] ) : |
| 1395 |
(element.nodeType !== 1 && element.nodeType !== 9 && element.nodeType !== 11) ? [] : |
| 1396 |
slice.call( |
| 1397 |
isSimple && !maybeID && element.getElementsByClassName ? // DocumentFragment doesn't have getElementsByClassName/TagName |
| 1398 |
maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class |
| 1399 |
element.getElementsByTagName(selector) : // Or a tag |
| 1400 |
element.querySelectorAll(selector) // Or it's not simple, and we need to query all |
| 1401 |
) |
| 1402 |
} |
| 1403 |
|
| 1404 |
function filtered(nodes, selector) { |
| 1405 |
return selector == null ? $(nodes) : $(nodes).filter(selector) |
| 1406 |
} |
| 1407 |
|
| 1408 |
$.contains = document.documentElement.contains ? |
| 1409 |
function(parent, node) { |
| 1410 |
return parent !== node && parent.contains(node) |
| 1411 |
} : |
| 1412 |
function(parent, node) { |
| 1413 |
while (node && (node = node.parentNode)) |
| 1414 |
if (node === parent) return true |
| 1415 |
return false |
| 1416 |
} |
| 1417 |
|
| 1418 |
function funcArg(context, arg, idx, payload) { |
| 1419 |
return isFunction(arg) ? arg.call(context, idx, payload) : arg |
| 1420 |
} |
| 1421 |
|
| 1422 |
function setAttribute(node, name, value) { |
| 1423 |
value == null ? node.removeAttribute(name) : node.setAttribute(name, value) |
| 1424 |
} |
| 1425 |
|
| 1426 |
// access className property while respecting SVGAnimatedString |
| 1427 |
function className(node, value){ |
| 1428 |
var klass = node.className || '', |
| 1429 |
svg = klass && klass.baseVal !== undefined |
| 1430 |
|
| 1431 |
if (value === undefined) return svg ? klass.baseVal : klass |
| 1432 |
svg ? (klass.baseVal = value) : (node.className = value) |
| 1433 |
} |
| 1434 |
|
| 1435 |
// "true" => true |
| 1436 |
// "false" => false |
| 1437 |
// "null" => null |
| 1438 |
// "42" => 42 |
| 1439 |
// "42.5" => 42.5 |
| 1440 |
// "08" => "08" |
| 1441 |
// JSON => parse if valid |
| 1442 |
// String => self |
| 1443 |
function deserializeValue(value) { |
| 1444 |
try { |
| 1445 |
return value ? |
| 1446 |
value == "true" || |
| 1447 |
( value == "false" ? false : |
| 1448 |
value == "null" ? null : |
| 1449 |
+value + "" == value ? +value : |
| 1450 |
/^[\[\{]/.test(value) ? $.parseJSON(value) : |
| 1451 |
value ) |
| 1452 |
: value |
| 1453 |
} catch(e) { |
| 1454 |
return value |
| 1455 |
} |
| 1456 |
} |
| 1457 |
|
| 1458 |
$.type = type |
| 1459 |
$.isFunction = isFunction |
| 1460 |
$.isWindow = isWindow |
| 1461 |
$.isArray = isArray |
| 1462 |
$.isPlainObject = isPlainObject |
| 1463 |
|
| 1464 |
$.isEmptyObject = function(obj) { |
| 1465 |
var name |
| 1466 |
for (name in obj) return false |
| 1467 |
return true |
| 1468 |
} |
| 1469 |
|
| 1470 |
$.isNumeric = function(val) { |
| 1471 |
var num = Number(val), type = typeof val |
| 1472 |
return val != null && type != 'boolean' && |
| 1473 |
(type != 'string' || val.length) && |
| 1474 |
!isNaN(num) && isFinite(num) || false |
| 1475 |
} |
| 1476 |
|
| 1477 |
$.inArray = function(elem, array, i){ |
| 1478 |
return emptyArray.indexOf.call(array, elem, i) |
| 1479 |
} |
| 1480 |
|
| 1481 |
$.camelCase = camelize |
| 1482 |
$.trim = function(str) { |
| 1483 |
return str == null ? "" : String.prototype.trim.call(str) |
| 1484 |
} |
| 1485 |
|
| 1486 |
// plugin compatibility |
| 1487 |
$.uuid = 0 |
| 1488 |
$.support = { } |
| 1489 |
$.expr = { } |
| 1490 |
$.noop = function() {} |
| 1491 |
|
| 1492 |
$.map = function(elements, callback){ |
| 1493 |
var value, values = [], i, key |
| 1494 |
if (likeArray(elements)) |
| 1495 |
for (i = 0; i < elements.length; i++) { |
| 1496 |
value = callback(elements[i], i) |
| 1497 |
if (value != null) values.push(value) |
| 1498 |
} |
| 1499 |
else |
| 1500 |
for (key in elements) { |
| 1501 |
value = callback(elements[key], key) |
| 1502 |
if (value != null) values.push(value) |
| 1503 |
} |
| 1504 |
return flatten(values) |
| 1505 |
} |
| 1506 |
|
| 1507 |
$.each = function(elements, callback){ |
| 1508 |
var i, key |
| 1509 |
if (likeArray(elements)) { |
| 1510 |
for (i = 0; i < elements.length; i++) |
| 1511 |
if (callback.call(elements[i], i, elements[i]) === false) return elements |
| 1512 |
} else { |
| 1513 |
for (key in elements) |
| 1514 |
if (callback.call(elements[key], key, elements[key]) === false) return elements |
| 1515 |
} |
| 1516 |
|
| 1517 |
return elements |
| 1518 |
} |
| 1519 |
|
| 1520 |
$.grep = function(elements, callback){ |
| 1521 |
return filter.call(elements, callback) |
| 1522 |
} |
| 1523 |
|
| 1524 |
if (window.JSON) $.parseJSON = JSON.parse |
| 1525 |
|
| 1526 |
// Populate the class2type map |
| 1527 |
$.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { |
| 1528 |
class2type[ "[object " + name + "]" ] = name.toLowerCase() |
| 1529 |
}) |
| 1530 |
|
| 1531 |
// Define methods that will be available on all |
| 1532 |
// Zepto collections |
| 1533 |
$.fn = { |
| 1534 |
constructor: zepto.Z, |
| 1535 |
length: 0, |
| 1536 |
|
| 1537 |
// Because a collection acts like an array |
| 1538 |
// copy over these useful array functions. |
| 1539 |
forEach: emptyArray.forEach, |
| 1540 |
reduce: emptyArray.reduce, |
| 1541 |
push: emptyArray.push, |
| 1542 |
sort: emptyArray.sort, |
| 1543 |
splice: emptyArray.splice, |
| 1544 |
indexOf: emptyArray.indexOf, |
| 1545 |
concat: function(){ |
| 1546 |
var i, value, args = [] |
| 1547 |
for (i = 0; i < arguments.length; i++) { |
| 1548 |
value = arguments[i] |
| 1549 |
args[i] = zepto.isZ(value) ? value.toArray() : value |
| 1550 |
} |
| 1551 |
return concat.apply(zepto.isZ(this) ? this.toArray() : this, args) |
| 1552 |
}, |
| 1553 |
|
| 1554 |
// `map` and `slice` in the jQuery API work differently |
| 1555 |
// from their array counterparts |
| 1556 |
map: function(fn){ |
| 1557 |
return $($.map(this, function(el, i){ return fn.call(el, i, el) })) |
| 1558 |
}, |
| 1559 |
slice: function(){ |
| 1560 |
return $(slice.apply(this, arguments)) |
| 1561 |
}, |
| 1562 |
|
| 1563 |
ready: function(callback){ |
| 1564 |
// need to check if document.body exists for IE as that browser reports |
| 1565 |
// document ready when it hasn't yet created the body element |
| 1566 |
if (readyRE.test(document.readyState) && document.body) callback($) |
| 1567 |
else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false) |
| 1568 |
return this |
| 1569 |
}, |
| 1570 |
get: function(idx){ |
| 1571 |
return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length] |
| 1572 |
}, |
| 1573 |
toArray: function(){ return this.get() }, |
| 1574 |
size: function(){ |
| 1575 |
return this.length |
| 1576 |
}, |
| 1577 |
remove: function(){ |
| 1578 |
return this.each(function(){ |
| 1579 |
if (this.parentNode != null) |
| 1580 |
this.parentNode.removeChild(this) |
| 1581 |
}) |
| 1582 |
}, |
| 1583 |
each: function(callback){ |
| 1584 |
emptyArray.every.call(this, function(el, idx){ |
| 1585 |
return callback.call(el, idx, el) !== false |
| 1586 |
}) |
| 1587 |
return this |
| 1588 |
}, |
| 1589 |
filter: function(selector){ |
| 1590 |
if (isFunction(selector)) return this.not(this.not(selector)) |
| 1591 |
return $(filter.call(this, function(element){ |
| 1592 |
return zepto.matches(element, selector) |
| 1593 |
})) |
| 1594 |
}, |
| 1595 |
add: function(selector,context){ |
| 1596 |
return $(uniq(this.concat($(selector,context)))) |
| 1597 |
}, |
| 1598 |
is: function(selector){ |
| 1599 |
return this.length > 0 && zepto.matches(this[0], selector) |
| 1600 |
}, |
| 1601 |
not: function(selector){ |
| 1602 |
var nodes=[] |
| 1603 |
if (isFunction(selector) && selector.call !== undefined) |
| 1604 |
this.each(function(idx){ |
| 1605 |
if (!selector.call(this,idx)) nodes.push(this) |
| 1606 |
}) |
| 1607 |
else { |
| 1608 |
var excludes = typeof selector == 'string' ? this.filter(selector) : |
| 1609 |
(likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector) |
| 1610 |
this.forEach(function(el){ |
| 1611 |
if (excludes.indexOf(el) < 0) nodes.push(el) |
| 1612 |
}) |
| 1613 |
} |
| 1614 |
return $(nodes) |
| 1615 |
}, |
| 1616 |
has: function(selector){ |
| 1617 |
return this.filter(function(){ |
| 1618 |
return isObject(selector) ? |
| 1619 |
$.contains(this, selector) : |
| 1620 |
$(this).find(selector).size() |
| 1621 |
}) |
| 1622 |
}, |
| 1623 |
eq: function(idx){ |
| 1624 |
return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1) |
| 1625 |
}, |
| 1626 |
first: function(){ |
| 1627 |
var el = this[0] |
| 1628 |
return el && !isObject(el) ? el : $(el) |
| 1629 |
}, |
| 1630 |
last: function(){ |
| 1631 |
var el = this[this.length - 1] |
| 1632 |
return el && !isObject(el) ? el : $(el) |
| 1633 |
}, |
| 1634 |
find: function(selector){ |
| 1635 |
var result, $this = this |
| 1636 |
if (!selector) result = $() |
| 1637 |
else if (typeof selector == 'object') |
| 1638 |
result = $(selector).filter(function(){ |
| 1639 |
var node = this |
| 1640 |
return emptyArray.some.call($this, function(parent){ |
| 1641 |
return $.contains(parent, node) |
| 1642 |
}) |
| 1643 |
}) |
| 1644 |
else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) |
| 1645 |
else result = this.map(function(){ return zepto.qsa(this, selector) }) |
| 1646 |
return result |
| 1647 |
}, |
| 1648 |
closest: function(selector, context){ |
| 1649 |
var nodes = [], collection = typeof selector == 'object' && $(selector) |
| 1650 |
this.each(function(_, node){ |
| 1651 |
while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector))) |
| 1652 |
node = node !== context && !isDocument(node) && node.parentNode |
| 1653 |
if (node && nodes.indexOf(node) < 0) nodes.push(node) |
| 1654 |
}) |
| 1655 |
return $(nodes) |
| 1656 |
}, |
| 1657 |
parents: function(selector){ |
| 1658 |
var ancestors = [], nodes = this |
| 1659 |
while (nodes.length > 0) |
| 1660 |
nodes = $.map(nodes, function(node){ |
| 1661 |
if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) { |
| 1662 |
ancestors.push(node) |
| 1663 |
return node |
| 1664 |
} |
| 1665 |
}) |
| 1666 |
return filtered(ancestors, selector) |
| 1667 |
}, |
| 1668 |
parent: function(selector){ |
| 1669 |
return filtered(uniq(this.pluck('parentNode')), selector) |
| 1670 |
}, |
| 1671 |
children: function(selector){ |
| 1672 |
return filtered(this.map(function(){ return children(this) }), selector) |
| 1673 |
}, |
| 1674 |
contents: function() { |
| 1675 |
return this.map(function() { return this.contentDocument || slice.call(this.childNodes) }) |
| 1676 |
}, |
| 1677 |
siblings: function(selector){ |
| 1678 |
return filtered(this.map(function(i, el){ |
| 1679 |
return filter.call(children(el.parentNode), function(child){ return child!==el }) |
| 1680 |
}), selector) |
| 1681 |
}, |
| 1682 |
empty: function(){ |
| 1683 |
return this.each(function(){ this.innerHTML = '' }) |
| 1684 |
}, |
| 1685 |
// `pluck` is borrowed from Prototype.js |
| 1686 |
pluck: function(property){ |
| 1687 |
return $.map(this, function(el){ return el[property] }) |
| 1688 |
}, |
| 1689 |
show: function(){ |
| 1690 |
return this.each(function(){ |
| 1691 |
this.style.display == "none" && (this.style.display = '') |
| 1692 |
if (getComputedStyle(this, '').getPropertyValue("display") == "none") |
| 1693 |
this.style.display = defaultDisplay(this.nodeName) |
| 1694 |
}) |
| 1695 |
}, |
| 1696 |
replaceWith: function(newContent){ |
| 1697 |
return this.before(newContent).remove() |
| 1698 |
}, |
| 1699 |
wrap: function(structure){ |
| 1700 |
var func = isFunction(structure) |
| 1701 |
if (this[0] && !func) |
| 1702 |
var dom = $(structure).get(0), |
| 1703 |
clone = dom.parentNode || this.length > 1 |
| 1704 |
|
| 1705 |
return this.each(function(index){ |
| 1706 |
$(this).wrapAll( |
| 1707 |
func ? structure.call(this, index) : |
| 1708 |
clone ? dom.cloneNode(true) : dom |
| 1709 |
) |
| 1710 |
}) |
| 1711 |
}, |
| 1712 |
wrapAll: function(structure){ |
| 1713 |
if (this[0]) { |
| 1714 |
$(this[0]).before(structure = $(structure)) |
| 1715 |
var children |
| 1716 |
// drill down to the inmost element |
| 1717 |
while ((children = structure.children()).length) structure = children.first() |
| 1718 |
$(structure).append(this) |
| 1719 |
} |
| 1720 |
return this |
| 1721 |
}, |
| 1722 |
wrapInner: function(structure){ |
| 1723 |
var func = isFunction(structure) |
| 1724 |
return this.each(function(index){ |
| 1725 |
var self = $(this), contents = self.contents(), |
| 1726 |
dom = func ? structure.call(this, index) : structure |
| 1727 |
contents.length ? contents.wrapAll(dom) : self.append(dom) |
| 1728 |
}) |
| 1729 |
}, |
| 1730 |
unwrap: function(){ |
| 1731 |
this.parent().each(function(){ |
| 1732 |
$(this).replaceWith($(this).children()) |
| 1733 |
}) |
| 1734 |
return this |
| 1735 |
}, |
| 1736 |
clone: function(){ |
| 1737 |
return this.map(function(){ return this.cloneNode(true) }) |
| 1738 |
}, |
| 1739 |
hide: function(){ |
| 1740 |
return this.css("display", "none") |
| 1741 |
}, |
| 1742 |
toggle: function(setting){ |
| 1743 |
return this.each(function(){ |
| 1744 |
var el = $(this) |
| 1745 |
;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide() |
| 1746 |
}) |
| 1747 |
}, |
| 1748 |
prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') }, |
| 1749 |
next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') }, |
| 1750 |
html: function(html){ |
| 1751 |
return 0 in arguments ? |
| 1752 |
this.each(function(idx){ |
| 1753 |
var originHtml = this.innerHTML |
| 1754 |
$(this).empty().append( funcArg(this, html, idx, originHtml) ) |
| 1755 |
}) : |
| 1756 |
(0 in this ? this[0].innerHTML : null) |
| 1757 |
}, |
| 1758 |
text: function(text){ |
| 1759 |
return 0 in arguments ? |
| 1760 |
this.each(function(idx){ |
| 1761 |
var newText = funcArg(this, text, idx, this.textContent) |
| 1762 |
this.textContent = newText == null ? '' : ''+newText |
| 1763 |
}) : |
| 1764 |
(0 in this ? this.pluck('textContent').join("") : null) |
| 1765 |
}, |
| 1766 |
attr: function(name, value){ |
| 1767 |
var result |
| 1768 |
return (typeof name == 'string' && !(1 in arguments)) ? |
| 1769 |
(0 in this && this[0].nodeType == 1 && (result = this[0].getAttribute(name)) != null ? result : undefined) : |
| 1770 |
this.each(function(idx){ |
| 1771 |
if (this.nodeType !== 1) return |
| 1772 |
if (isObject(name)) for (key in name) setAttribute(this, key, name[key]) |
| 1773 |
else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name))) |
| 1774 |
}) |
| 1775 |
}, |
| 1776 |
removeAttr: function(name){ |
| 1777 |
return this.each(function(){ this.nodeType === 1 && name.split(' ').forEach(function(attribute){ |
| 1778 |
setAttribute(this, attribute) |
| 1779 |
}, this)}) |
| 1780 |
}, |
| 1781 |
prop: function(name, value){ |
| 1782 |
name = propMap[name] || name |
| 1783 |
return (1 in arguments) ? |
| 1784 |
this.each(function(idx){ |
| 1785 |
this[name] = funcArg(this, value, idx, this[name]) |
| 1786 |
}) : |
| 1787 |
(this[0] && this[0][name]) |
| 1788 |
}, |
| 1789 |
removeProp: function(name){ |
| 1790 |
name = propMap[name] || name |
| 1791 |
return this.each(function(){ delete this[name] }) |
| 1792 |
}, |
| 1793 |
data: function(name, value){ |
| 1794 |
var attrName = 'data-' + name.replace(capitalRE, '-$1').toLowerCase() |
| 1795 |
|
| 1796 |
var data = (1 in arguments) ? |
| 1797 |
this.attr(attrName, value) : |
| 1798 |
this.attr(attrName) |
| 1799 |
|
| 1800 |
return data !== null ? deserializeValue(data) : undefined |
| 1801 |
}, |
| 1802 |
val: function(value){ |
| 1803 |
if (0 in arguments) { |
| 1804 |
if (value == null) value = "" |
| 1805 |
return this.each(function(idx){ |
| 1806 |
this.value = funcArg(this, value, idx, this.value) |
| 1807 |
}) |
| 1808 |
} else { |
| 1809 |
return this[0] && (this[0].multiple ? |
| 1810 |
$(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') : |
| 1811 |
this[0].value) |
| 1812 |
} |
| 1813 |
}, |
| 1814 |
offset: function(coordinates){ |
| 1815 |
if (coordinates) return this.each(function(index){ |
| 1816 |
var $this = $(this), |
| 1817 |
coords = funcArg(this, coordinates, index, $this.offset()), |
| 1818 |
parentOffset = $this.offsetParent().offset(), |
| 1819 |
props = { |
| 1820 |
top: coords.top - parentOffset.top, |
| 1821 |
left: coords.left - parentOffset.left |
| 1822 |
} |
| 1823 |
|
| 1824 |
if ($this.css('position') == 'static') props['position'] = 'relative' |
| 1825 |
$this.css(props) |
| 1826 |
}) |
| 1827 |
if (!this.length) return null |
| 1828 |
if (document.documentElement !== this[0] && !$.contains(document.documentElement, this[0])) |
| 1829 |
return {top: 0, left: 0} |
| 1830 |
var obj = this[0].getBoundingClientRect() |
| 1831 |
return { |
| 1832 |
left: obj.left + window.pageXOffset, |
| 1833 |
top: obj.top + window.pageYOffset, |
| 1834 |
width: Math.round(obj.width), |
| 1835 |
height: Math.round(obj.height) |
| 1836 |
} |
| 1837 |
}, |
| 1838 |
css: function(property, value){ |
| 1839 |
if (arguments.length < 2) { |
| 1840 |
var element = this[0] |
| 1841 |
if (typeof property == 'string') { |
| 1842 |
if (!element) return |
| 1843 |
return element.style[camelize(property)] || getComputedStyle(element, '').getPropertyValue(property) |
| 1844 |
} else if (isArray(property)) { |
| 1845 |
if (!element) return |
| 1846 |
var props = {} |
| 1847 |
var computedStyle = getComputedStyle(element, '') |
| 1848 |
$.each(property, function(_, prop){ |
| 1849 |
props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop)) |
| 1850 |
}) |
| 1851 |
return props |
| 1852 |
} |
| 1853 |
} |
| 1854 |
|
| 1855 |
var css = '' |
| 1856 |
if (type(property) == 'string') { |
| 1857 |
if (!value && value !== 0) |
| 1858 |
this.each(function(){ this.style.removeProperty(dasherize(property)) }) |
| 1859 |
else |
| 1860 |
css = dasherize(property) + ":" + maybeAddPx(property, value) |
| 1861 |
} else { |
| 1862 |
for (key in property) |
| 1863 |
if (!property[key] && property[key] !== 0) |
| 1864 |
this.each(function(){ this.style.removeProperty(dasherize(key)) }) |
| 1865 |
else |
| 1866 |
css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' |
| 1867 |
} |
| 1868 |
|
| 1869 |
return this.each(function(){ this.style.cssText += ';' + css }) |
| 1870 |
}, |
| 1871 |
index: function(element){ |
| 1872 |
return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) |
| 1873 |
}, |
| 1874 |
hasClass: function(name){ |
| 1875 |
if (!name) return false |
| 1876 |
return emptyArray.some.call(this, function(el){ |
| 1877 |
return this.test(className(el)) |
| 1878 |
}, classRE(name)) |
| 1879 |
}, |
| 1880 |
addClass: function(name){ |
| 1881 |
if (!name) return this |
| 1882 |
return this.each(function(idx){ |
| 1883 |
if (!('className' in this)) return |
| 1884 |
classList = [] |
| 1885 |
var cls = className(this), newName = funcArg(this, name, idx, cls) |
| 1886 |
newName.split(/\s+/g).forEach(function(klass){ |
| 1887 |
if (!$(this).hasClass(klass)) classList.push(klass) |
| 1888 |
}, this) |
| 1889 |
classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) |
| 1890 |
}) |
| 1891 |
}, |
| 1892 |
removeClass: function(name){ |
| 1893 |
return this.each(function(idx){ |
| 1894 |
if (!('className' in this)) return |
| 1895 |
if (name === undefined) return className(this, '') |
| 1896 |
classList = className(this) |
| 1897 |
funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ |
| 1898 |
classList = classList.replace(classRE(klass), " ") |
| 1899 |
}) |
| 1900 |
className(this, classList.trim()) |
| 1901 |
}) |
| 1902 |
}, |
| 1903 |
toggleClass: function(name, when){ |
| 1904 |
if (!name) return this |
| 1905 |
return this.each(function(idx){ |
| 1906 |
var $this = $(this), names = funcArg(this, name, idx, className(this)) |
| 1907 |
names.split(/\s+/g).forEach(function(klass){ |
| 1908 |
(when === undefined ? !$this.hasClass(klass) : when) ? |
| 1909 |
$this.addClass(klass) : $this.removeClass(klass) |
| 1910 |
}) |
| 1911 |
}) |
| 1912 |
}, |
| 1913 |
scrollTop: function(value){ |
| 1914 |
if (!this.length) return |
| 1915 |
var hasScrollTop = 'scrollTop' in this[0] |
| 1916 |
if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset |
| 1917 |
return this.each(hasScrollTop ? |
| 1918 |
function(){ this.scrollTop = value } : |
| 1919 |
function(){ this.scrollTo(this.scrollX, value) }) |
| 1920 |
}, |
| 1921 |
scrollLeft: function(value){ |
| 1922 |
if (!this.length) return |
| 1923 |
var hasScrollLeft = 'scrollLeft' in this[0] |
| 1924 |
if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset |
| 1925 |
return this.each(hasScrollLeft ? |
| 1926 |
function(){ this.scrollLeft = value } : |
| 1927 |
function(){ this.scrollTo(value, this.scrollY) }) |
| 1928 |
}, |
| 1929 |
position: function() { |
| 1930 |
if (!this.length) return |
| 1931 |
|
| 1932 |
var elem = this[0], |
| 1933 |
// Get *real* offsetParent |
| 1934 |
offsetParent = this.offsetParent(), |
| 1935 |
// Get correct offsets |
| 1936 |
offset = this.offset(), |
| 1937 |
parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() |
| 1938 |
|
| 1939 |
// Subtract element margins |
| 1940 |
// note: when an element has margin: auto the offsetLeft and marginLeft |
| 1941 |
// are the same in Safari causing offset.left to incorrectly be 0 |
| 1942 |
offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 |
| 1943 |
offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 |
| 1944 |
|
| 1945 |
// Add offsetParent borders |
| 1946 |
parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 |
| 1947 |
parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 |
| 1948 |
|
| 1949 |
// Subtract the two offsets |
| 1950 |
return { |
| 1951 |
top: offset.top - parentOffset.top, |
| 1952 |
left: offset.left - parentOffset.left |
| 1953 |
} |
| 1954 |
}, |
| 1955 |
offsetParent: function() { |
| 1956 |
return this.map(function(){ |
| 1957 |
var parent = this.offsetParent || document.body |
| 1958 |
while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") |
| 1959 |
parent = parent.offsetParent |
| 1960 |
return parent |
| 1961 |
}) |
| 1962 |
} |
| 1963 |
} |
| 1964 |
|
| 1965 |
// for now |
| 1966 |
$.fn.detach = $.fn.remove |
| 1967 |
|
| 1968 |
// Generate the `width` and `height` functions |
| 1969 |
;['width', 'height'].forEach(function(dimension){ |
| 1970 |
var dimensionProperty = |
| 1971 |
dimension.replace(/./, function(m){ return m[0].toUpperCase() }) |
| 1972 |
|
| 1973 |
$.fn[dimension] = function(value){ |
| 1974 |
var offset, el = this[0] |
| 1975 |
if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] : |
| 1976 |
isDocument(el) ? el.documentElement['scroll' + dimensionProperty] : |
| 1977 |
(offset = this.offset()) && offset[dimension] |
| 1978 |
else return this.each(function(idx){ |
| 1979 |
el = $(this) |
| 1980 |
el.css(dimension, funcArg(this, value, idx, el[dimension]())) |
| 1981 |
}) |
| 1982 |
} |
| 1983 |
}) |
| 1984 |
|
| 1985 |
function traverseNode(node, fun) { |
| 1986 |
fun(node) |
| 1987 |
for (var i = 0, len = node.childNodes.length; i < len; i++) |
| 1988 |
traverseNode(node.childNodes[i], fun) |
| 1989 |
} |
| 1990 |
|
| 1991 |
// Generate the `after`, `prepend`, `before`, `append`, |
| 1992 |
// `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. |
| 1993 |
adjacencyOperators.forEach(function(operator, operatorIndex) { |
| 1994 |
var inside = operatorIndex % 2 //=> prepend, append |
| 1995 |
|
| 1996 |
$.fn[operator] = function(){ |
| 1997 |
// arguments can be nodes, arrays of nodes, Zepto objects and HTML strings |
| 1998 |
var argType, nodes = $.map(arguments, function(arg) { |
| 1999 |
var arr = [] |
| 2000 |
argType = type(arg) |
| 2001 |
if (argType == "array") { |
| 2002 |
arg.forEach(function(el) { |
| 2003 |
if (el.nodeType !== undefined) return arr.push(el) |
| 2004 |
else if ($.zepto.isZ(el)) return arr = arr.concat(el.get()) |
| 2005 |
arr = arr.concat(zepto.fragment(el)) |
| 2006 |
}) |
| 2007 |
return arr |
| 2008 |
} |
| 2009 |
return argType == "object" || arg == null ? |
| 2010 |
arg : zepto.fragment(arg) |
| 2011 |
}), |
| 2012 |
parent, copyByClone = this.length > 1 |
| 2013 |
if (nodes.length < 1) return this |
| 2014 |
|
| 2015 |
return this.each(function(_, target){ |
| 2016 |
parent = inside ? target : target.parentNode |
| 2017 |
|
| 2018 |
// convert all methods to a "before" operation |
| 2019 |
target = operatorIndex == 0 ? target.nextSibling : |
| 2020 |
operatorIndex == 1 ? target.firstChild : |
| 2021 |
operatorIndex == 2 ? target : |
| 2022 |
null |
| 2023 |
|
| 2024 |
var parentInDocument = $.contains(document.documentElement, parent) |
| 2025 |
|
| 2026 |
nodes.forEach(function(node){ |
| 2027 |
if (copyByClone) node = node.cloneNode(true) |
| 2028 |
else if (!parent) return $(node).remove() |
| 2029 |
|
| 2030 |
parent.insertBefore(node, target) |
| 2031 |
if (parentInDocument) traverseNode(node, function(el){ |
| 2032 |
if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && |
| 2033 |
(!el.type || el.type === 'text/javascript') && !el.src){ |
| 2034 |
var target = el.ownerDocument ? el.ownerDocument.defaultView : window |
| 2035 |
target['eval'].call(target, el.innerHTML) |
| 2036 |
} |
| 2037 |
}) |
| 2038 |
}) |
| 2039 |
}) |
| 2040 |
} |
| 2041 |
|
| 2042 |
// after => insertAfter |
| 2043 |
// prepend => prependTo |
| 2044 |
// before => insertBefore |
| 2045 |
// append => appendTo |
| 2046 |
$.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ |
| 2047 |
$(html)[operator](this) |
| 2048 |
return this |
| 2049 |
} |
| 2050 |
}) |
| 2051 |
|
| 2052 |
zepto.Z.prototype = Z.prototype = $.fn |
| 2053 |
|
| 2054 |
// Export internal API functions in the `$.zepto` namespace |
| 2055 |
zepto.uniq = uniq |
| 2056 |
zepto.deserializeValue = deserializeValue |
| 2057 |
$.zepto = zepto |
| 2058 |
|
| 2059 |
return $ |
| 2060 |
})() |
| 2061 |
|
| 2062 |
;(function($){ |
| 2063 |
var _zid = 1, undefined, |
| 2064 |
slice = Array.prototype.slice, |
| 2065 |
isFunction = $.isFunction, |
| 2066 |
isString = function(obj){ return typeof obj == 'string' }, |
| 2067 |
handlers = {}, |
| 2068 |
specialEvents={}, |
| 2069 |
focusinSupported = 'onfocusin' in window, |
| 2070 |
focus = { focus: 'focusin', blur: 'focusout' }, |
| 2071 |
hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } |
| 2072 |
|
| 2073 |
specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' |
| 2074 |
|
| 2075 |
function zid(element) { |
| 2076 |
return element._zid || (element._zid = _zid++) |
| 2077 |
} |
| 2078 |
function findHandlers(element, event, fn, selector) { |
| 2079 |
event = parse(event) |
| 2080 |
if (event.ns) var matcher = matcherFor(event.ns) |
| 2081 |
return (handlers[zid(element)] || []).filter(function(handler) { |
| 2082 |
return handler |
| 2083 |
&& (!event.e || handler.e == event.e) |
| 2084 |
&& (!event.ns || matcher.test(handler.ns)) |
| 2085 |
&& (!fn || zid(handler.fn) === zid(fn)) |
| 2086 |
&& (!selector || handler.sel == selector) |
| 2087 |
}) |
| 2088 |
} |
| 2089 |
function parse(event) { |
| 2090 |
var parts = ('' + event).split('.') |
| 2091 |
return {e: parts[0], ns: parts.slice(1).sort().join(' ')} |
| 2092 |
} |
| 2093 |
function matcherFor(ns) { |
| 2094 |
return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') |
| 2095 |
} |
| 2096 |
|
| 2097 |
function eventCapture(handler, captureSetting) { |
| 2098 |
return handler.del && |
| 2099 |
(!focusinSupported && (handler.e in focus)) || |
| 2100 |
!!captureSetting |
| 2101 |
} |
| 2102 |
|
| 2103 |
function realEvent(type) { |
| 2104 |
return hover[type] || (focusinSupported && focus[type]) || type |
| 2105 |
} |
| 2106 |
|
| 2107 |
function add(element, events, fn, data, selector, delegator, capture){ |
| 2108 |
var id = zid(element), set = (handlers[id] || (handlers[id] = [])) |
| 2109 |
events.split(/\s/).forEach(function(event){ |
| 2110 |
if (event == 'ready') return $(document).ready(fn) |
| 2111 |
var handler = parse(event) |
| 2112 |
handler.fn = fn |
| 2113 |
handler.sel = selector |
| 2114 |
// emulate mouseenter, mouseleave |
| 2115 |
if (handler.e in hover) fn = function(e){ |
| 2116 |
var related = e.relatedTarget |
| 2117 |
if (!related || (related !== this && !$.contains(this, related))) |
| 2118 |
return handler.fn.apply(this, arguments) |
| 2119 |
} |
| 2120 |
handler.del = delegator |
| 2121 |
var callback = delegator || fn |
| 2122 |
handler.proxy = function(e){ |
| 2123 |
e = compatible(e) |
| 2124 |
if (e.isImmediatePropagationStopped()) return |
| 2125 |
try { |
| 2126 |
var dataPropDescriptor = Object.getOwnPropertyDescriptor(e, 'data') |
| 2127 |
if (!dataPropDescriptor || dataPropDescriptor.writable) |
| 2128 |
e.data = data |
| 2129 |
} catch (e) {} // when using strict mode dataPropDescriptor will be undefined when e is InputEvent (even though data property exists). So we surround with try/catch |
| 2130 |
var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args)) |
| 2131 |
if (result === false) e.preventDefault(), e.stopPropagation() |
| 2132 |
return result |
| 2133 |
} |
| 2134 |
handler.i = set.length |
| 2135 |
set.push(handler) |
| 2136 |
if ('addEventListener' in element) |
| 2137 |
element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) |
| 2138 |
}) |
| 2139 |
} |
| 2140 |
function remove(element, events, fn, selector, capture){ |
| 2141 |
var id = zid(element) |
| 2142 |
;(events || '').split(/\s/).forEach(function(event){ |
| 2143 |
findHandlers(element, event, fn, selector).forEach(function(handler){ |
| 2144 |
delete handlers[id][handler.i] |
| 2145 |
if ('removeEventListener' in element) |
| 2146 |
element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) |
| 2147 |
}) |
| 2148 |
}) |
| 2149 |
} |
| 2150 |
|
| 2151 |
$.event = { add: add, remove: remove } |
| 2152 |
|
| 2153 |
$.proxy = function(fn, context) { |
| 2154 |
var args = (2 in arguments) && slice.call(arguments, 2) |
| 2155 |
if (isFunction(fn)) { |
| 2156 |
var proxyFn = function(){ return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments) } |
| 2157 |
proxyFn._zid = zid(fn) |
| 2158 |
return proxyFn |
| 2159 |
} else if (isString(context)) { |
| 2160 |
if (args) { |
| 2161 |
args.unshift(fn[context], fn) |
| 2162 |
return $.proxy.apply(null, args) |
| 2163 |
} else { |
| 2164 |
return $.proxy(fn[context], fn) |
| 2165 |
} |
| 2166 |
} else { |
| 2167 |
throw new TypeError("expected function") |
| 2168 |
} |
| 2169 |
} |
| 2170 |
|
| 2171 |
$.fn.bind = function(event, data, callback){ |
| 2172 |
return this.on(event, data, callback) |
| 2173 |
} |
| 2174 |
$.fn.unbind = function(event, callback){ |
| 2175 |
return this.off(event, callback) |
| 2176 |
} |
| 2177 |
$.fn.one = function(event, selector, data, callback){ |
| 2178 |
return this.on(event, selector, data, callback, 1) |
| 2179 |
} |
| 2180 |
|
| 2181 |
var returnTrue = function(){return true}, |
| 2182 |
returnFalse = function(){return false}, |
| 2183 |
ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$|webkitMovement[XY]$)/, |
| 2184 |
eventMethods = { |
| 2185 |
preventDefault: 'isDefaultPrevented', |
| 2186 |
stopImmediatePropagation: 'isImmediatePropagationStopped', |
| 2187 |
stopPropagation: 'isPropagationStopped' |
| 2188 |
} |
| 2189 |
|
| 2190 |
function compatible(event, source) { |
| 2191 |
if (source || !event.isDefaultPrevented) { |
| 2192 |
source || (source = event) |
| 2193 |
|
| 2194 |
$.each(eventMethods, function(name, predicate) { |
| 2195 |
var sourceMethod = source[name] |
| 2196 |
event[name] = function(){ |
| 2197 |
this[predicate] = returnTrue |
| 2198 |
return sourceMethod && sourceMethod.apply(source, arguments) |
| 2199 |
} |
| 2200 |
event[predicate] = returnFalse |
| 2201 |
}) |
| 2202 |
|
| 2203 |
event.timeStamp || (event.timeStamp = Date.now()) |
| 2204 |
|
| 2205 |
if (source.defaultPrevented !== undefined ? source.defaultPrevented : |
| 2206 |
'returnValue' in source ? source.returnValue === false : |
| 2207 |
source.getPreventDefault && source.getPreventDefault()) |
| 2208 |
event.isDefaultPrevented = returnTrue |
| 2209 |
} |
| 2210 |
return event |
| 2211 |
} |
| 2212 |
|
| 2213 |
function createProxy(event) { |
| 2214 |
var key, proxy = { originalEvent: event } |
| 2215 |
for (key in event) |
| 2216 |
if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key] |
| 2217 |
|
| 2218 |
return compatible(proxy, event) |
| 2219 |
} |
| 2220 |
|
| 2221 |
$.fn.delegate = function(selector, event, callback){ |
| 2222 |
return this.on(event, selector, callback) |
| 2223 |
} |
| 2224 |
$.fn.undelegate = function(selector, event, callback){ |
| 2225 |
return this.off(event, selector, callback) |
| 2226 |
} |
| 2227 |
|
| 2228 |
$.fn.live = function(event, callback){ |
| 2229 |
$(document.body).delegate(this.selector, event, callback) |
| 2230 |
return this |
| 2231 |
} |
| 2232 |
$.fn.die = function(event, callback){ |
| 2233 |
$(document.body).undelegate(this.selector, event, callback) |
| 2234 |
return this |
| 2235 |
} |
| 2236 |
|
| 2237 |
$.fn.on = function(event, selector, data, callback, one){ |
| 2238 |
var autoRemove, delegator, $this = this |
| 2239 |
if (event && !isString(event)) { |
| 2240 |
$.each(event, function(type, fn){ |
| 2241 |
$this.on(type, selector, data, fn, one) |
| 2242 |
}) |
| 2243 |
return $this |
| 2244 |
} |
| 2245 |
|
| 2246 |
if (!isString(selector) && !isFunction(callback) && callback !== false) |
| 2247 |
callback = data, data = selector, selector = undefined |
| 2248 |
if (callback === undefined || data === false) |
| 2249 |
callback = data, data = undefined |
| 2250 |
|
| 2251 |
if (callback === false) callback = returnFalse |
| 2252 |
|
| 2253 |
return $this.each(function(_, element){ |
| 2254 |
if (one) autoRemove = function(e){ |
| 2255 |
remove(element, e.type, callback) |
| 2256 |
return callback.apply(this, arguments) |
| 2257 |
} |
| 2258 |
|
| 2259 |
if (selector) delegator = function(e){ |
| 2260 |
var evt, match = $(e.target).closest(selector, element).get(0) |
| 2261 |
if (match && match !== element) { |
| 2262 |
evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) |
| 2263 |
return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1))) |
| 2264 |
} |
| 2265 |
} |
| 2266 |
|
| 2267 |
add(element, event, callback, data, selector, delegator || autoRemove) |
| 2268 |
}) |
| 2269 |
} |
| 2270 |
$.fn.off = function(event, selector, callback){ |
| 2271 |
var $this = this |
| 2272 |
if (event && !isString(event)) { |
| 2273 |
$.each(event, function(type, fn){ |
| 2274 |
$this.off(type, selector, fn) |
| 2275 |
}) |
| 2276 |
return $this |
| 2277 |
} |
| 2278 |
|
| 2279 |
if (!isString(selector) && !isFunction(callback) && callback !== false) |
| 2280 |
callback = selector, selector = undefined |
| 2281 |
|
| 2282 |
if (callback === false) callback = returnFalse |
| 2283 |
|
| 2284 |
return $this.each(function(){ |
| 2285 |
remove(this, event, callback, selector) |
| 2286 |
}) |
| 2287 |
} |
| 2288 |
|
| 2289 |
$.fn.trigger = function(event, args){ |
| 2290 |
event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event) |
| 2291 |
event._args = args |
| 2292 |
return this.each(function(){ |
| 2293 |
// handle focus(), blur() by calling them directly |
| 2294 |
if (event.type in focus && typeof this[event.type] == "function") this[event.type]() |
| 2295 |
// items in the collection might not be DOM elements |
| 2296 |
else if ('dispatchEvent' in this) this.dispatchEvent(event) |
| 2297 |
else $(this).triggerHandler(event, args) |
| 2298 |
}) |
| 2299 |
} |
| 2300 |
|
| 2301 |
// triggers event handlers on current element just as if an event occurred, |
| 2302 |
// doesn't trigger an actual event, doesn't bubble |
| 2303 |
$.fn.triggerHandler = function(event, args){ |
| 2304 |
var e, result |
| 2305 |
this.each(function(i, element){ |
| 2306 |
e = createProxy(isString(event) ? $.Event(event) : event) |
| 2307 |
e._args = args |
| 2308 |
e.target = element |
| 2309 |
$.each(findHandlers(element, event.type || event), function(i, handler){ |
| 2310 |
result = handler.proxy(e) |
| 2311 |
if (e.isImmediatePropagationStopped()) return false |
| 2312 |
}) |
| 2313 |
}) |
| 2314 |
return result |
| 2315 |
} |
| 2316 |
|
| 2317 |
// shortcut methods for `.bind(event, fn)` for each event type |
| 2318 |
;('focusin focusout focus blur load resize scroll unload click dblclick '+ |
| 2319 |
'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ |
| 2320 |
'change select keydown keypress keyup error').split(' ').forEach(function(event) { |
| 2321 |
$.fn[event] = function(callback) { |
| 2322 |
return (0 in arguments) ? |
| 2323 |
this.bind(event, callback) : |
| 2324 |
this.trigger(event) |
| 2325 |
} |
| 2326 |
}) |
| 2327 |
|
| 2328 |
$.Event = function(type, props) { |
| 2329 |
if (!isString(type)) props = type, type = props.type |
| 2330 |
var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true |
| 2331 |
if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) |
| 2332 |
event.initEvent(type, bubbles, true) |
| 2333 |
return compatible(event) |
| 2334 |
} |
| 2335 |
|
| 2336 |
})(Zepto) |
| 2337 |
|
| 2338 |
;(function($){ |
| 2339 |
var cache = [], timeout |
| 2340 |
|
| 2341 |
$.fn.remove = function(){ |
| 2342 |
return this.each(function(){ |
| 2343 |
if(this.parentNode){ |
| 2344 |
if(this.tagName === 'IMG'){ |
| 2345 |
cache.push(this) |
| 2346 |
this.src = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' |
| 2347 |
if (timeout) clearTimeout(timeout) |
| 2348 |
timeout = setTimeout(function(){ cache = [] }, 60000) |
| 2349 |
} |
| 2350 |
this.parentNode.removeChild(this) |
| 2351 |
} |
| 2352 |
}) |
| 2353 |
} |
| 2354 |
})(Zepto) |
| 2355 |
|
| 2356 |
;(function($){ |
| 2357 |
var data = {}, dataAttr = $.fn.data, camelize = $.camelCase, |
| 2358 |
exp = $.expando = 'Zepto' + (+new Date()), emptyArray = [] |
| 2359 |
|
| 2360 |
// Get value from node: |
| 2361 |
// 1. first try key as given, |
| 2362 |
// 2. then try camelized key, |
| 2363 |
// 3. fall back to reading "data-*" attribute. |
| 2364 |
function getData(node, name) { |
| 2365 |
var id = node[exp], store = id && data[id] |
| 2366 |
if (name === undefined) return store || setData(node) |
| 2367 |
else { |
| 2368 |
if (store) { |
| 2369 |
if (name in store) return store[name] |
| 2370 |
var camelName = camelize(name) |
| 2371 |
if (camelName in store) return store[camelName] |
| 2372 |
} |
| 2373 |
return dataAttr.call($(node), name) |
| 2374 |
} |
| 2375 |
} |
| 2376 |
|
| 2377 |
// Store value under camelized key on node |
| 2378 |
function setData(node, name, value) { |
| 2379 |
var id = node[exp] || (node[exp] = ++$.uuid), |
| 2380 |
store = data[id] || (data[id] = attributeData(node)) |
| 2381 |
if (name !== undefined) store[camelize(name)] = value |
| 2382 |
return store |
| 2383 |
} |
| 2384 |
|
| 2385 |
// Read all "data-*" attributes from a node |
| 2386 |
function attributeData(node) { |
| 2387 |
var store = {} |
| 2388 |
$.each(node.attributes || emptyArray, function(i, attr){ |
| 2389 |
if (attr.name.indexOf('data-') == 0) |
| 2390 |
store[camelize(attr.name.replace('data-', ''))] = |
| 2391 |
$.zepto.deserializeValue(attr.value) |
| 2392 |
}) |
| 2393 |
return store |
| 2394 |
} |
| 2395 |
|
| 2396 |
$.fn.data = function(name, value) { |
| 2397 |
return value === undefined ? |
| 2398 |
// set multiple values via object |
| 2399 |
$.isPlainObject(name) ? |
| 2400 |
this.each(function(i, node){ |
| 2401 |
$.each(name, function(key, value){ setData(node, key, value) }) |
| 2402 |
}) : |
| 2403 |
// get value from first element |
| 2404 |
(0 in this ? getData(this[0], name) : undefined) : |
| 2405 |
// set value on all elements |
| 2406 |
this.each(function(){ setData(this, name, value) }) |
| 2407 |
} |
| 2408 |
|
| 2409 |
$.data = function(elem, name, value) { |
| 2410 |
return $(elem).data(name, value) |
| 2411 |
} |
| 2412 |
|
| 2413 |
$.hasData = function(elem) { |
| 2414 |
var id = elem[exp], store = id && data[id] |
| 2415 |
return store ? !$.isEmptyObject(store) : false |
| 2416 |
} |
| 2417 |
|
| 2418 |
$.fn.removeData = function(names) { |
| 2419 |
if (typeof names == 'string') names = names.split(/\s+/) |
| 2420 |
return this.each(function(){ |
| 2421 |
var id = this[exp], store = id && data[id] |
| 2422 |
if (store) $.each(names || store, function(key){ |
| 2423 |
delete store[names ? camelize(this) : key] |
| 2424 |
}) |
| 2425 |
}) |
| 2426 |
} |
| 2427 |
|
| 2428 |
// Generate extended `remove` and `empty` functions |
| 2429 |
;['remove', 'empty'].forEach(function(methodName){ |
| 2430 |
var origFn = $.fn[methodName] |
| 2431 |
$.fn[methodName] = function() { |
| 2432 |
var elements = this.find('*') |
| 2433 |
if (methodName === 'remove') elements = elements.add(this) |
| 2434 |
elements.removeData() |
| 2435 |
return origFn.call(this) |
| 2436 |
} |
| 2437 |
}) |
| 2438 |
})(Zepto) |
| 2439 |
return Zepto |
| 2440 |
})) |
| 2441 |
|
| 2442 |
|
| 2443 |
/***/ }), |
| 2444 |
/* 16 */ |
| 2445 |
/***/ (function(module, exports, __webpack_require__) { |
| 2446 |
|
| 2447 |
"use strict"; |
| 2448 |
|
| 2449 |
|
| 2450 |
var namespace = 'autocomplete:'; |
| 2451 |
|
| 2452 |
var _ = __webpack_require__(0); |
| 2453 |
var DOM = __webpack_require__(1); |
| 2454 |
|
| 2455 |
// constructor |
| 2456 |
// ----------- |
| 2457 |
|
| 2458 |
function EventBus(o) { |
| 2459 |
if (!o || !o.el) { |
| 2460 |
_.error('EventBus initialized without el'); |
| 2461 |
} |
| 2462 |
|
| 2463 |
this.$el = DOM.element(o.el); |
| 2464 |
} |
| 2465 |
|
| 2466 |
// instance methods |
| 2467 |
// ---------------- |
| 2468 |
|
| 2469 |
_.mixin(EventBus.prototype, { |
| 2470 |
|
| 2471 |
// ### public |
| 2472 |
|
| 2473 |
trigger: function(type) { |
| 2474 |
var args = [].slice.call(arguments, 1); |
| 2475 |
|
| 2476 |
var event = _.Event(namespace + type); |
| 2477 |
this.$el.trigger(event, args); |
| 2478 |
return event; |
| 2479 |
} |
| 2480 |
}); |
| 2481 |
|
| 2482 |
module.exports = EventBus; |
| 2483 |
|
| 2484 |
|
| 2485 |
/***/ }), |
| 2486 |
/* 17 */ |
| 2487 |
/***/ (function(module, exports, __webpack_require__) { |
| 2488 |
|
| 2489 |
"use strict"; |
| 2490 |
|
| 2491 |
|
| 2492 |
module.exports = { |
| 2493 |
wrapper: '<span class="%ROOT%"></span>', |
| 2494 |
dropdown: '<span class="%PREFIX%%DROPDOWN_MENU%"></span>', |
| 2495 |
dataset: '<div class="%PREFIX%%DATASET%-%CLASS%"></div>', |
| 2496 |
suggestions: '<span class="%PREFIX%%SUGGESTIONS%"></span>', |
| 2497 |
suggestion: '<div class="%PREFIX%%SUGGESTION%"></div>' |
| 2498 |
}; |
| 2499 |
|
| 2500 |
|
| 2501 |
/***/ }), |
| 2502 |
/* 18 */ |
| 2503 |
/***/ (function(module, exports) { |
| 2504 |
|
| 2505 |
module.exports = "0.32.0"; |
| 2506 |
|
| 2507 |
|
| 2508 |
/***/ }), |
| 2509 |
/* 19 */ |
| 2510 |
/***/ (function(module, exports, __webpack_require__) { |
| 2511 |
|
| 2512 |
"use strict"; |
| 2513 |
|
| 2514 |
module.exports = function parseAlgoliaClientVersion(agent) { |
| 2515 |
var parsed = agent.match(/Algolia for vanilla JavaScript (\d+\.)(\d+\.)(\d+)/); |
| 2516 |
if (parsed) return [parsed[1], parsed[2], parsed[3]]; |
| 2517 |
return undefined; |
| 2518 |
}; |
| 2519 |
|
| 2520 |
|
| 2521 |
/***/ }), |
| 2522 |
/* 20 */ |
| 2523 |
/***/ (function(module, exports, __webpack_require__) { |
| 2524 |
|
| 2525 |
"use strict"; |
| 2526 |
|
| 2527 |
|
| 2528 |
Object.defineProperty(exports, "__esModule", { |
| 2529 |
value: true |
| 2530 |
}); |
| 2531 |
|
| 2532 |
var _zepto = __webpack_require__(15); |
| 2533 |
|
| 2534 |
var _zepto2 = _interopRequireDefault(_zepto); |
| 2535 |
|
| 2536 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 2537 |
|
| 2538 |
exports.default = _zepto2.default; |
| 2539 |
|
| 2540 |
/***/ }), |
| 2541 |
/* 21 */ |
| 2542 |
/***/ (function(module, exports, __webpack_require__) { |
| 2543 |
|
| 2544 |
"use strict"; |
| 2545 |
|
| 2546 |
|
| 2547 |
Object.defineProperty(exports, "__esModule", { |
| 2548 |
value: true |
| 2549 |
}); |
| 2550 |
exports.default = '2.6.1'; |
| 2551 |
|
| 2552 |
/***/ }), |
| 2553 |
/* 22 */ |
| 2554 |
/***/ (function(module, exports, __webpack_require__) { |
| 2555 |
|
| 2556 |
"use strict"; |
| 2557 |
|
| 2558 |
|
| 2559 |
var _main = __webpack_require__(23); |
| 2560 |
|
| 2561 |
var _main2 = _interopRequireDefault(_main); |
| 2562 |
|
| 2563 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 2564 |
|
| 2565 |
module.exports = _main2.default; /* eslint-disable import/no-commonjs */ |
| 2566 |
|
| 2567 |
/***/ }), |
| 2568 |
/* 23 */ |
| 2569 |
/***/ (function(module, exports, __webpack_require__) { |
| 2570 |
|
| 2571 |
"use strict"; |
| 2572 |
|
| 2573 |
|
| 2574 |
Object.defineProperty(exports, "__esModule", { |
| 2575 |
value: true |
| 2576 |
}); |
| 2577 |
|
| 2578 |
var _toFactory = __webpack_require__(24); |
| 2579 |
|
| 2580 |
var _toFactory2 = _interopRequireDefault(_toFactory); |
| 2581 |
|
| 2582 |
var _DocSearch = __webpack_require__(25); |
| 2583 |
|
| 2584 |
var _DocSearch2 = _interopRequireDefault(_DocSearch); |
| 2585 |
|
| 2586 |
var _version = __webpack_require__(21); |
| 2587 |
|
| 2588 |
var _version2 = _interopRequireDefault(_version); |
| 2589 |
|
| 2590 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 2591 |
|
| 2592 |
var docsearch = (0, _toFactory2.default)(_DocSearch2.default); |
| 2593 |
docsearch.version = _version2.default; |
| 2594 |
|
| 2595 |
exports.default = docsearch; |
| 2596 |
|
| 2597 |
/***/ }), |
| 2598 |
/* 24 */ |
| 2599 |
/***/ (function(module, exports, __webpack_require__) { |
| 2600 |
|
| 2601 |
"use strict"; |
| 2602 |
|
| 2603 |
|
| 2604 |
var _bind = Function.prototype.bind; |
| 2605 |
function toFactory(Class) { |
| 2606 |
var Factory = function Factory() { |
| 2607 |
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
| 2608 |
args[_key] = arguments[_key]; |
| 2609 |
} |
| 2610 |
|
| 2611 |
return new (_bind.apply(Class, [null].concat(args)))(); |
| 2612 |
}; |
| 2613 |
Factory.__proto__ = Class; |
| 2614 |
Factory.prototype = Class.prototype; |
| 2615 |
return Factory; |
| 2616 |
} |
| 2617 |
|
| 2618 |
module.exports = toFactory; |
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
/***/ }), |
| 2623 |
/* 25 */ |
| 2624 |
/***/ (function(module, exports, __webpack_require__) { |
| 2625 |
|
| 2626 |
"use strict"; |
| 2627 |
|
| 2628 |
|
| 2629 |
Object.defineProperty(exports, "__esModule", { |
| 2630 |
value: true |
| 2631 |
}); |
| 2632 |
|
| 2633 |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; |
| 2634 |
|
| 2635 |
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
| 2636 |
|
| 2637 |
var _hogan = __webpack_require__(26); |
| 2638 |
|
| 2639 |
var _hogan2 = _interopRequireDefault(_hogan); |
| 2640 |
|
| 2641 |
var _lite = __webpack_require__(29); |
| 2642 |
|
| 2643 |
var _lite2 = _interopRequireDefault(_lite); |
| 2644 |
|
| 2645 |
var _autocomplete = __webpack_require__(49); |
| 2646 |
|
| 2647 |
var _autocomplete2 = _interopRequireDefault(_autocomplete); |
| 2648 |
|
| 2649 |
var _templates = __webpack_require__(64); |
| 2650 |
|
| 2651 |
var _templates2 = _interopRequireDefault(_templates); |
| 2652 |
|
| 2653 |
var _utils = __webpack_require__(65); |
| 2654 |
|
| 2655 |
var _utils2 = _interopRequireDefault(_utils); |
| 2656 |
|
| 2657 |
var _version = __webpack_require__(21); |
| 2658 |
|
| 2659 |
var _version2 = _interopRequireDefault(_version); |
| 2660 |
|
| 2661 |
var _zepto = __webpack_require__(20); |
| 2662 |
|
| 2663 |
var _zepto2 = _interopRequireDefault(_zepto); |
| 2664 |
|
| 2665 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 2666 |
|
| 2667 |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 2668 |
|
| 2669 |
/** |
| 2670 |
* Adds an autocomplete dropdown to an input field |
| 2671 |
* @function DocSearch |
| 2672 |
* @param {string} options.apiKey Read-only API key |
| 2673 |
* @param {string} options.indexName Name of the index to target |
| 2674 |
* @param {string} options.inputSelector CSS selector that targets the input |
| 2675 |
* @param {string} [options.appId] Lets you override the applicationId used. |
| 2676 |
* If using the default Algolia Crawler, you should not have to change this |
| 2677 |
* value. |
| 2678 |
* @param {Object} [options.algoliaOptions] Options to pass the underlying Algolia client |
| 2679 |
* @param {Object} [options.autocompleteOptions] Options to pass to the underlying autocomplete instance |
| 2680 |
* @return {Object} |
| 2681 |
*/ |
| 2682 |
var usage = 'Usage:\n documentationSearch({\n apiKey,\n indexName,\n inputSelector,\n [ appId ],\n [ algoliaOptions.{hitsPerPage} ]\n [ autocompleteOptions.{hint,debug} ]\n})'; |
| 2683 |
|
| 2684 |
var DocSearch = function () { |
| 2685 |
function DocSearch(_ref) { |
| 2686 |
var apiKey = _ref.apiKey, |
| 2687 |
indexName = _ref.indexName, |
| 2688 |
inputSelector = _ref.inputSelector, |
| 2689 |
_ref$appId = _ref.appId, |
| 2690 |
appId = _ref$appId === undefined ? 'BH4D9OD16A' : _ref$appId, |
| 2691 |
_ref$debug = _ref.debug, |
| 2692 |
debug = _ref$debug === undefined ? false : _ref$debug, |
| 2693 |
_ref$algoliaOptions = _ref.algoliaOptions, |
| 2694 |
algoliaOptions = _ref$algoliaOptions === undefined ? {} : _ref$algoliaOptions, |
| 2695 |
_ref$autocompleteOpti = _ref.autocompleteOptions, |
| 2696 |
autocompleteOptions = _ref$autocompleteOpti === undefined ? { |
| 2697 |
debug: false, |
| 2698 |
hint: false, |
| 2699 |
autoselect: true |
| 2700 |
} : _ref$autocompleteOpti, |
| 2701 |
_ref$transformData = _ref.transformData, |
| 2702 |
transformData = _ref$transformData === undefined ? false : _ref$transformData, |
| 2703 |
_ref$queryHook = _ref.queryHook, |
| 2704 |
queryHook = _ref$queryHook === undefined ? false : _ref$queryHook, |
| 2705 |
_ref$handleSelected = _ref.handleSelected, |
| 2706 |
handleSelected = _ref$handleSelected === undefined ? false : _ref$handleSelected, |
| 2707 |
_ref$enhancedSearchIn = _ref.enhancedSearchInput, |
| 2708 |
enhancedSearchInput = _ref$enhancedSearchIn === undefined ? false : _ref$enhancedSearchIn, |
| 2709 |
_ref$layout = _ref.layout, |
| 2710 |
layout = _ref$layout === undefined ? 'collumns' : _ref$layout; |
| 2711 |
|
| 2712 |
_classCallCheck(this, DocSearch); |
| 2713 |
|
| 2714 |
DocSearch.checkArguments({ |
| 2715 |
apiKey: apiKey, |
| 2716 |
indexName: indexName, |
| 2717 |
inputSelector: inputSelector, |
| 2718 |
debug: debug, |
| 2719 |
algoliaOptions: algoliaOptions, |
| 2720 |
autocompleteOptions: autocompleteOptions, |
| 2721 |
transformData: transformData, |
| 2722 |
queryHook: queryHook, |
| 2723 |
handleSelected: handleSelected, |
| 2724 |
enhancedSearchInput: enhancedSearchInput, |
| 2725 |
layout: layout |
| 2726 |
}); |
| 2727 |
|
| 2728 |
this.apiKey = apiKey; |
| 2729 |
this.appId = appId; |
| 2730 |
this.indexName = indexName; |
| 2731 |
this.input = DocSearch.getInputFromSelector(inputSelector); |
| 2732 |
this.algoliaOptions = _extends({ hitsPerPage: 5 }, algoliaOptions); |
| 2733 |
var autocompleteOptionsDebug = autocompleteOptions && autocompleteOptions.debug ? autocompleteOptions.debug : false; |
| 2734 |
// eslint-disable-next-line no-param-reassign |
| 2735 |
autocompleteOptions.debug = debug || autocompleteOptionsDebug; |
| 2736 |
this.autocompleteOptions = autocompleteOptions; |
| 2737 |
this.autocompleteOptions.cssClasses = this.autocompleteOptions.cssClasses || {}; |
| 2738 |
this.autocompleteOptions.cssClasses.prefix = this.autocompleteOptions.cssClasses.prefix || 'ds'; |
| 2739 |
|
| 2740 |
// eslint-disable-next-line no-param-reassign |
| 2741 |
handleSelected = handleSelected || this.handleSelected; |
| 2742 |
|
| 2743 |
this.isSimpleLayout = layout === 'simple'; |
| 2744 |
|
| 2745 |
this.client = (0, _lite2.default)(this.appId, this.apiKey); |
| 2746 |
this.client.addAlgoliaAgent('docsearch.js ' + _version2.default); |
| 2747 |
|
| 2748 |
if (enhancedSearchInput) { |
| 2749 |
this.input = DocSearch.injectSearchBox(this.input); |
| 2750 |
} |
| 2751 |
|
| 2752 |
this.autocomplete = (0, _autocomplete2.default)(this.input, autocompleteOptions, [{ |
| 2753 |
source: this.getAutocompleteSource(transformData, queryHook), |
| 2754 |
templates: { |
| 2755 |
suggestion: DocSearch.getSuggestionTemplate(this.isSimpleLayout), |
| 2756 |
footer: _templates2.default.footer, |
| 2757 |
empty: DocSearch.getEmptyTemplate() |
| 2758 |
} |
| 2759 |
}]); |
| 2760 |
|
| 2761 |
// If user defined its own handleSelected, we prevent clicks on suggestions |
| 2762 |
// link to do anything |
| 2763 |
if (handleSelected) { |
| 2764 |
(0, _zepto2.default)('.algolia-autocomplete').on('click', '.ds-suggestions a', function (event) { |
| 2765 |
event.preventDefault(); |
| 2766 |
}); |
| 2767 |
} |
| 2768 |
|
| 2769 |
// Click on suggestions will follow the link, but keyboard navigation still |
| 2770 |
// need the handleSelected |
| 2771 |
this.autocomplete.on('autocomplete:selected', handleSelected.bind(null, this.autocomplete.autocomplete)); |
| 2772 |
|
| 2773 |
this.autocomplete.on('autocomplete:shown', this.handleShown.bind(null, this.input)); |
| 2774 |
|
| 2775 |
if (enhancedSearchInput) { |
| 2776 |
DocSearch.bindSearchBoxEvent(); |
| 2777 |
} |
| 2778 |
} |
| 2779 |
|
| 2780 |
/** |
| 2781 |
* Checks that the passed arguments are valid. Will throw errors otherwise |
| 2782 |
* @function checkArguments |
| 2783 |
* @param {object} args Arguments as an option object |
| 2784 |
* @returns {void} |
| 2785 |
*/ |
| 2786 |
|
| 2787 |
|
| 2788 |
_createClass(DocSearch, [{ |
| 2789 |
key: 'getAutocompleteSource', |
| 2790 |
|
| 2791 |
|
| 2792 |
/** |
| 2793 |
* Returns the `source` method to be passed to autocomplete.js. It will query |
| 2794 |
* the Algolia index and call the callbacks with the formatted hits. |
| 2795 |
* @function getAutocompleteSource |
| 2796 |
* @param {function} transformData An optional function to transform the hits |
| 2797 |
* @param {function} queryHook An optional function to transform the query |
| 2798 |
* @returns {function} Method to be passed as the `source` option of |
| 2799 |
* autocomplete |
| 2800 |
*/ |
| 2801 |
value: function getAutocompleteSource(transformData, queryHook) { |
| 2802 |
var _this = this; |
| 2803 |
|
| 2804 |
return function (query, callback) { |
| 2805 |
if (queryHook) { |
| 2806 |
// eslint-disable-next-line no-param-reassign |
| 2807 |
query = queryHook(query) || query; |
| 2808 |
} |
| 2809 |
|
| 2810 |
_this.client.search([{ |
| 2811 |
indexName: _this.indexName, |
| 2812 |
query: query, |
| 2813 |
params: _this.algoliaOptions |
| 2814 |
}]).then(function (data) { |
| 2815 |
var hits = data.results[0].hits; |
| 2816 |
if (transformData) { |
| 2817 |
hits = transformData(hits) || hits; |
| 2818 |
} |
| 2819 |
callback(DocSearch.formatHits(hits)); |
| 2820 |
}); |
| 2821 |
}; |
| 2822 |
} |
| 2823 |
|
| 2824 |
// Given a list of hits returned by the API, will reformat them to be used in |
| 2825 |
// a Hogan template |
| 2826 |
|
| 2827 |
}, { |
| 2828 |
key: 'handleSelected', |
| 2829 |
value: function handleSelected(input, event, suggestion) { |
| 2830 |
input.setVal(''); |
| 2831 |
window.location.assign(suggestion.url); |
| 2832 |
} |
| 2833 |
}, { |
| 2834 |
key: 'handleShown', |
| 2835 |
value: function handleShown(input) { |
| 2836 |
var middleOfInput = input.offset().left + input.width() / 2; |
| 2837 |
var middleOfWindow = (0, _zepto2.default)(document).width() / 2; |
| 2838 |
|
| 2839 |
if (isNaN(middleOfWindow)) { |
| 2840 |
middleOfWindow = 900; |
| 2841 |
} |
| 2842 |
|
| 2843 |
var alignClass = middleOfInput - middleOfWindow >= 0 ? 'algolia-autocomplete-right' : 'algolia-autocomplete-left'; |
| 2844 |
var otherAlignClass = middleOfInput - middleOfWindow < 0 ? 'algolia-autocomplete-right' : 'algolia-autocomplete-left'; |
| 2845 |
var autocompleteWrapper = (0, _zepto2.default)('.algolia-autocomplete'); |
| 2846 |
if (!autocompleteWrapper.hasClass(alignClass)) { |
| 2847 |
autocompleteWrapper.addClass(alignClass); |
| 2848 |
} |
| 2849 |
|
| 2850 |
if (autocompleteWrapper.hasClass(otherAlignClass)) { |
| 2851 |
autocompleteWrapper.removeClass(otherAlignClass); |
| 2852 |
} |
| 2853 |
} |
| 2854 |
}], [{ |
| 2855 |
key: 'checkArguments', |
| 2856 |
value: function checkArguments(args) { |
| 2857 |
if (!args.apiKey || !args.indexName) { |
| 2858 |
throw new Error(usage); |
| 2859 |
} |
| 2860 |
|
| 2861 |
if (typeof args.inputSelector !== 'string') { |
| 2862 |
throw new Error('Error: inputSelector:' + args.inputSelector + ' must be a string. Each selector must match only one element and separated by \',\''); |
| 2863 |
} |
| 2864 |
|
| 2865 |
if (!DocSearch.getInputFromSelector(args.inputSelector)) { |
| 2866 |
throw new Error('Error: No input element in the page matches ' + args.inputSelector); |
| 2867 |
} |
| 2868 |
} |
| 2869 |
}, { |
| 2870 |
key: 'injectSearchBox', |
| 2871 |
value: function injectSearchBox(input) { |
| 2872 |
input.before(_templates2.default.searchBox); |
| 2873 |
var newInput = input.prev().prev().find('input'); |
| 2874 |
input.remove(); |
| 2875 |
return newInput; |
| 2876 |
} |
| 2877 |
}, { |
| 2878 |
key: 'bindSearchBoxEvent', |
| 2879 |
value: function bindSearchBoxEvent() { |
| 2880 |
(0, _zepto2.default)('.searchbox [type="reset"]').on('click', function () { |
| 2881 |
(0, _zepto2.default)('input#docsearch').focus(); |
| 2882 |
(0, _zepto2.default)(this).addClass('hide'); |
| 2883 |
_autocomplete2.default.autocomplete.setVal(''); |
| 2884 |
}); |
| 2885 |
|
| 2886 |
(0, _zepto2.default)('input#docsearch').on('keyup', function () { |
| 2887 |
var searchbox = document.querySelector('input#docsearch'); |
| 2888 |
var reset = document.querySelector('.searchbox [type="reset"]'); |
| 2889 |
reset.className = 'searchbox__reset'; |
| 2890 |
if (searchbox.value.length === 0) { |
| 2891 |
reset.className += ' hide'; |
| 2892 |
} |
| 2893 |
}); |
| 2894 |
} |
| 2895 |
|
| 2896 |
/** |
| 2897 |
* Returns the matching input from a CSS selector, null if none matches |
| 2898 |
* @function getInputFromSelector |
| 2899 |
* @param {string} selector CSS selector that matches the search |
| 2900 |
* input of the page |
| 2901 |
* @returns {void} |
| 2902 |
*/ |
| 2903 |
|
| 2904 |
}, { |
| 2905 |
key: 'getInputFromSelector', |
| 2906 |
value: function getInputFromSelector(selector) { |
| 2907 |
var input = (0, _zepto2.default)(selector).filter('input'); |
| 2908 |
return input.length ? (0, _zepto2.default)(input[0]) : null; |
| 2909 |
} |
| 2910 |
}, { |
| 2911 |
key: 'formatHits', |
| 2912 |
value: function formatHits(receivedHits) { |
| 2913 |
var clonedHits = _utils2.default.deepClone(receivedHits); |
| 2914 |
var hits = clonedHits.map(function (hit) { |
| 2915 |
if (hit._highlightResult) { |
| 2916 |
// eslint-disable-next-line no-param-reassign |
| 2917 |
hit._highlightResult = _utils2.default.mergeKeyWithParent(hit._highlightResult, 'hierarchy'); |
| 2918 |
} |
| 2919 |
return _utils2.default.mergeKeyWithParent(hit, 'hierarchy'); |
| 2920 |
}); |
| 2921 |
|
| 2922 |
// Group hits by category / subcategory |
| 2923 |
var groupedHits = _utils2.default.groupBy(hits, 'lvl0'); |
| 2924 |
_zepto2.default.each(groupedHits, function (level, collection) { |
| 2925 |
var groupedHitsByLvl1 = _utils2.default.groupBy(collection, 'lvl1'); |
| 2926 |
var flattenedHits = _utils2.default.flattenAndFlagFirst(groupedHitsByLvl1, 'isSubCategoryHeader'); |
| 2927 |
groupedHits[level] = flattenedHits; |
| 2928 |
}); |
| 2929 |
groupedHits = _utils2.default.flattenAndFlagFirst(groupedHits, 'isCategoryHeader'); |
| 2930 |
|
| 2931 |
// Translate hits into smaller objects to be send to the template |
| 2932 |
return groupedHits.map(function (hit) { |
| 2933 |
var url = DocSearch.formatURL(hit); |
| 2934 |
var category = _utils2.default.getHighlightedValue(hit, 'lvl0'); |
| 2935 |
var subcategory = _utils2.default.getHighlightedValue(hit, 'lvl1') || category; |
| 2936 |
var displayTitle = _utils2.default.compact([_utils2.default.getHighlightedValue(hit, 'lvl2') || subcategory, _utils2.default.getHighlightedValue(hit, 'lvl3'), _utils2.default.getHighlightedValue(hit, 'lvl4'), _utils2.default.getHighlightedValue(hit, 'lvl5'), _utils2.default.getHighlightedValue(hit, 'lvl6')]).join('<span class="aa-suggestion-title-separator" aria-hidden="true"> › </span>'); |
| 2937 |
var text = _utils2.default.getSnippetedValue(hit, 'content'); |
| 2938 |
var isTextOrSubcategoryNonEmpty = subcategory && subcategory !== '' || displayTitle && displayTitle !== ''; |
| 2939 |
var isLvl1EmptyOrDuplicate = !subcategory || subcategory === '' || subcategory === category; |
| 2940 |
var isLvl2 = displayTitle && displayTitle !== '' && displayTitle !== subcategory; |
| 2941 |
var isLvl1 = !isLvl2 && subcategory && subcategory !== '' && subcategory !== category; |
| 2942 |
var isLvl0 = !isLvl1 && !isLvl2; |
| 2943 |
|
| 2944 |
return { |
| 2945 |
isLvl0: isLvl0, |
| 2946 |
isLvl1: isLvl1, |
| 2947 |
isLvl2: isLvl2, |
| 2948 |
isLvl1EmptyOrDuplicate: isLvl1EmptyOrDuplicate, |
| 2949 |
isCategoryHeader: hit.isCategoryHeader, |
| 2950 |
isSubCategoryHeader: hit.isSubCategoryHeader, |
| 2951 |
isTextOrSubcategoryNonEmpty: isTextOrSubcategoryNonEmpty, |
| 2952 |
category: category, |
| 2953 |
subcategory: subcategory, |
| 2954 |
title: displayTitle, |
| 2955 |
text: text, |
| 2956 |
url: url |
| 2957 |
}; |
| 2958 |
}); |
| 2959 |
} |
| 2960 |
}, { |
| 2961 |
key: 'formatURL', |
| 2962 |
value: function formatURL(hit) { |
| 2963 |
var url = hit.url, |
| 2964 |
anchor = hit.anchor; |
| 2965 |
|
| 2966 |
if (url) { |
| 2967 |
var containsAnchor = url.indexOf('#') !== -1; |
| 2968 |
if (containsAnchor) return url;else if (anchor) return hit.url + '#' + hit.anchor; |
| 2969 |
return url; |
| 2970 |
} else if (anchor) return '#' + hit.anchor; |
| 2971 |
/* eslint-disable */ |
| 2972 |
console.warn('no anchor nor url for : ', JSON.stringify(hit)); |
| 2973 |
/* eslint-enable */ |
| 2974 |
return null; |
| 2975 |
} |
| 2976 |
}, { |
| 2977 |
key: 'getEmptyTemplate', |
| 2978 |
value: function getEmptyTemplate() { |
| 2979 |
return function (args) { |
| 2980 |
return _hogan2.default.compile(_templates2.default.empty).render(args); |
| 2981 |
}; |
| 2982 |
} |
| 2983 |
}, { |
| 2984 |
key: 'getSuggestionTemplate', |
| 2985 |
value: function getSuggestionTemplate(isSimpleLayout) { |
| 2986 |
var stringTemplate = isSimpleLayout ? _templates2.default.suggestionSimple : _templates2.default.suggestion; |
| 2987 |
var template = _hogan2.default.compile(stringTemplate); |
| 2988 |
return function (suggestion) { |
| 2989 |
return template.render(suggestion); |
| 2990 |
}; |
| 2991 |
} |
| 2992 |
}]); |
| 2993 |
|
| 2994 |
return DocSearch; |
| 2995 |
}(); |
| 2996 |
|
| 2997 |
exports.default = DocSearch; |
| 2998 |
|
| 2999 |
/***/ }), |
| 3000 |
/* 26 */ |
| 3001 |
/***/ (function(module, exports, __webpack_require__) { |
| 3002 |
|
| 3003 |
/* |
| 3004 |
* Copyright 2011 Twitter, Inc. |
| 3005 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3006 |
* you may not use this file except in compliance with the License. |
| 3007 |
* You may obtain a copy of the License at |
| 3008 |
* |
| 3009 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3010 |
* |
| 3011 |
* Unless required by applicable law or agreed to in writing, software |
| 3012 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 3013 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 3014 |
* See the License for the specific language governing permissions and |
| 3015 |
* limitations under the License. |
| 3016 |
*/ |
| 3017 |
|
| 3018 |
// This file is for use with Node.js. See dist/ for browser files. |
| 3019 |
|
| 3020 |
var Hogan = __webpack_require__(27); |
| 3021 |
Hogan.Template = __webpack_require__(28).Template; |
| 3022 |
Hogan.template = Hogan.Template; |
| 3023 |
module.exports = Hogan; |
| 3024 |
|
| 3025 |
|
| 3026 |
/***/ }), |
| 3027 |
/* 27 */ |
| 3028 |
/***/ (function(module, exports, __webpack_require__) { |
| 3029 |
|
| 3030 |
/* |
| 3031 |
* Copyright 2011 Twitter, Inc. |
| 3032 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3033 |
* you may not use this file except in compliance with the License. |
| 3034 |
* You may obtain a copy of the License at |
| 3035 |
* |
| 3036 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3037 |
* |
| 3038 |
* Unless required by applicable law or agreed to in writing, software |
| 3039 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 3040 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 3041 |
* See the License for the specific language governing permissions and |
| 3042 |
* limitations under the License. |
| 3043 |
*/ |
| 3044 |
|
| 3045 |
(function (Hogan) { |
| 3046 |
// Setup regex assignments |
| 3047 |
// remove whitespace according to Mustache spec |
| 3048 |
var rIsWhitespace = /\S/, |
| 3049 |
rQuot = /\"/g, |
| 3050 |
rNewline = /\n/g, |
| 3051 |
rCr = /\r/g, |
| 3052 |
rSlash = /\\/g, |
| 3053 |
rLineSep = /\u2028/, |
| 3054 |
rParagraphSep = /\u2029/; |
| 3055 |
|
| 3056 |
Hogan.tags = { |
| 3057 |
'#': 1, '^': 2, '<': 3, '$': 4, |
| 3058 |
'/': 5, '!': 6, '>': 7, '=': 8, '_v': 9, |
| 3059 |
'{': 10, '&': 11, '_t': 12 |
| 3060 |
}; |
| 3061 |
|
| 3062 |
Hogan.scan = function scan(text, delimiters) { |
| 3063 |
var len = text.length, |
| 3064 |
IN_TEXT = 0, |
| 3065 |
IN_TAG_TYPE = 1, |
| 3066 |
IN_TAG = 2, |
| 3067 |
state = IN_TEXT, |
| 3068 |
tagType = null, |
| 3069 |
tag = null, |
| 3070 |
buf = '', |
| 3071 |
tokens = [], |
| 3072 |
seenTag = false, |
| 3073 |
i = 0, |
| 3074 |
lineStart = 0, |
| 3075 |
otag = '{{', |
| 3076 |
ctag = '}}'; |
| 3077 |
|
| 3078 |
function addBuf() { |
| 3079 |
if (buf.length > 0) { |
| 3080 |
tokens.push({tag: '_t', text: new String(buf)}); |
| 3081 |
buf = ''; |
| 3082 |
} |
| 3083 |
} |
| 3084 |
|
| 3085 |
function lineIsWhitespace() { |
| 3086 |
var isAllWhitespace = true; |
| 3087 |
for (var j = lineStart; j < tokens.length; j++) { |
| 3088 |
isAllWhitespace = |
| 3089 |
(Hogan.tags[tokens[j].tag] < Hogan.tags['_v']) || |
| 3090 |
(tokens[j].tag == '_t' && tokens[j].text.match(rIsWhitespace) === null); |
| 3091 |
if (!isAllWhitespace) { |
| 3092 |
return false; |
| 3093 |
} |
| 3094 |
} |
| 3095 |
|
| 3096 |
return isAllWhitespace; |
| 3097 |
} |
| 3098 |
|
| 3099 |
function filterLine(haveSeenTag, noNewLine) { |
| 3100 |
addBuf(); |
| 3101 |
|
| 3102 |
if (haveSeenTag && lineIsWhitespace()) { |
| 3103 |
for (var j = lineStart, next; j < tokens.length; j++) { |
| 3104 |
if (tokens[j].text) { |
| 3105 |
if ((next = tokens[j+1]) && next.tag == '>') { |
| 3106 |
// set indent to token value |
| 3107 |
next.indent = tokens[j].text.toString() |
| 3108 |
} |
| 3109 |
tokens.splice(j, 1); |
| 3110 |
} |
| 3111 |
} |
| 3112 |
} else if (!noNewLine) { |
| 3113 |
tokens.push({tag:'\n'}); |
| 3114 |
} |
| 3115 |
|
| 3116 |
seenTag = false; |
| 3117 |
lineStart = tokens.length; |
| 3118 |
} |
| 3119 |
|
| 3120 |
function changeDelimiters(text, index) { |
| 3121 |
var close = '=' + ctag, |
| 3122 |
closeIndex = text.indexOf(close, index), |
| 3123 |
delimiters = trim( |
| 3124 |
text.substring(text.indexOf('=', index) + 1, closeIndex) |
| 3125 |
).split(' '); |
| 3126 |
|
| 3127 |
otag = delimiters[0]; |
| 3128 |
ctag = delimiters[delimiters.length - 1]; |
| 3129 |
|
| 3130 |
return closeIndex + close.length - 1; |
| 3131 |
} |
| 3132 |
|
| 3133 |
if (delimiters) { |
| 3134 |
delimiters = delimiters.split(' '); |
| 3135 |
otag = delimiters[0]; |
| 3136 |
ctag = delimiters[1]; |
| 3137 |
} |
| 3138 |
|
| 3139 |
for (i = 0; i < len; i++) { |
| 3140 |
if (state == IN_TEXT) { |
| 3141 |
if (tagChange(otag, text, i)) { |
| 3142 |
--i; |
| 3143 |
addBuf(); |
| 3144 |
state = IN_TAG_TYPE; |
| 3145 |
} else { |
| 3146 |
if (text.charAt(i) == '\n') { |
| 3147 |
filterLine(seenTag); |
| 3148 |
} else { |
| 3149 |
buf += text.charAt(i); |
| 3150 |
} |
| 3151 |
} |
| 3152 |
} else if (state == IN_TAG_TYPE) { |
| 3153 |
i += otag.length - 1; |
| 3154 |
tag = Hogan.tags[text.charAt(i + 1)]; |
| 3155 |
tagType = tag ? text.charAt(i + 1) : '_v'; |
| 3156 |
if (tagType == '=') { |
| 3157 |
i = changeDelimiters(text, i); |
| 3158 |
state = IN_TEXT; |
| 3159 |
} else { |
| 3160 |
if (tag) { |
| 3161 |
i++; |
| 3162 |
} |
| 3163 |
state = IN_TAG; |
| 3164 |
} |
| 3165 |
seenTag = i; |
| 3166 |
} else { |
| 3167 |
if (tagChange(ctag, text, i)) { |
| 3168 |
tokens.push({tag: tagType, n: trim(buf), otag: otag, ctag: ctag, |
| 3169 |
i: (tagType == '/') ? seenTag - otag.length : i + ctag.length}); |
| 3170 |
buf = ''; |
| 3171 |
i += ctag.length - 1; |
| 3172 |
state = IN_TEXT; |
| 3173 |
if (tagType == '{') { |
| 3174 |
if (ctag == '}}') { |
| 3175 |
i++; |
| 3176 |
} else { |
| 3177 |
cleanTripleStache(tokens[tokens.length - 1]); |
| 3178 |
} |
| 3179 |
} |
| 3180 |
} else { |
| 3181 |
buf += text.charAt(i); |
| 3182 |
} |
| 3183 |
} |
| 3184 |
} |
| 3185 |
|
| 3186 |
filterLine(seenTag, true); |
| 3187 |
|
| 3188 |
return tokens; |
| 3189 |
} |
| 3190 |
|
| 3191 |
function cleanTripleStache(token) { |
| 3192 |
if (token.n.substr(token.n.length - 1) === '}') { |
| 3193 |
token.n = token.n.substring(0, token.n.length - 1); |
| 3194 |
} |
| 3195 |
} |
| 3196 |
|
| 3197 |
function trim(s) { |
| 3198 |
if (s.trim) { |
| 3199 |
return s.trim(); |
| 3200 |
} |
| 3201 |
|
| 3202 |
return s.replace(/^\s*|\s*$/g, ''); |
| 3203 |
} |
| 3204 |
|
| 3205 |
function tagChange(tag, text, index) { |
| 3206 |
if (text.charAt(index) != tag.charAt(0)) { |
| 3207 |
return false; |
| 3208 |
} |
| 3209 |
|
| 3210 |
for (var i = 1, l = tag.length; i < l; i++) { |
| 3211 |
if (text.charAt(index + i) != tag.charAt(i)) { |
| 3212 |
return false; |
| 3213 |
} |
| 3214 |
} |
| 3215 |
|
| 3216 |
return true; |
| 3217 |
} |
| 3218 |
|
| 3219 |
// the tags allowed inside super templates |
| 3220 |
var allowedInSuper = {'_t': true, '\n': true, '$': true, '/': true}; |
| 3221 |
|
| 3222 |
function buildTree(tokens, kind, stack, customTags) { |
| 3223 |
var instructions = [], |
| 3224 |
opener = null, |
| 3225 |
tail = null, |
| 3226 |
token = null; |
| 3227 |
|
| 3228 |
tail = stack[stack.length - 1]; |
| 3229 |
|
| 3230 |
while (tokens.length > 0) { |
| 3231 |
token = tokens.shift(); |
| 3232 |
|
| 3233 |
if (tail && tail.tag == '<' && !(token.tag in allowedInSuper)) { |
| 3234 |
throw new Error('Illegal content in < super tag.'); |
| 3235 |
} |
| 3236 |
|
| 3237 |
if (Hogan.tags[token.tag] <= Hogan.tags['$'] || isOpener(token, customTags)) { |
| 3238 |
stack.push(token); |
| 3239 |
token.nodes = buildTree(tokens, token.tag, stack, customTags); |
| 3240 |
} else if (token.tag == '/') { |
| 3241 |
if (stack.length === 0) { |
| 3242 |
throw new Error('Closing tag without opener: /' + token.n); |
| 3243 |
} |
| 3244 |
opener = stack.pop(); |
| 3245 |
if (token.n != opener.n && !isCloser(token.n, opener.n, customTags)) { |
| 3246 |
throw new Error('Nesting error: ' + opener.n + ' vs. ' + token.n); |
| 3247 |
} |
| 3248 |
opener.end = token.i; |
| 3249 |
return instructions; |
| 3250 |
} else if (token.tag == '\n') { |
| 3251 |
token.last = (tokens.length == 0) || (tokens[0].tag == '\n'); |
| 3252 |
} |
| 3253 |
|
| 3254 |
instructions.push(token); |
| 3255 |
} |
| 3256 |
|
| 3257 |
if (stack.length > 0) { |
| 3258 |
throw new Error('missing closing tag: ' + stack.pop().n); |
| 3259 |
} |
| 3260 |
|
| 3261 |
return instructions; |
| 3262 |
} |
| 3263 |
|
| 3264 |
function isOpener(token, tags) { |
| 3265 |
for (var i = 0, l = tags.length; i < l; i++) { |
| 3266 |
if (tags[i].o == token.n) { |
| 3267 |
token.tag = '#'; |
| 3268 |
return true; |
| 3269 |
} |
| 3270 |
} |
| 3271 |
} |
| 3272 |
|
| 3273 |
function isCloser(close, open, tags) { |
| 3274 |
for (var i = 0, l = tags.length; i < l; i++) { |
| 3275 |
if (tags[i].c == close && tags[i].o == open) { |
| 3276 |
return true; |
| 3277 |
} |
| 3278 |
} |
| 3279 |
} |
| 3280 |
|
| 3281 |
function stringifySubstitutions(obj) { |
| 3282 |
var items = []; |
| 3283 |
for (var key in obj) { |
| 3284 |
items.push('"' + esc(key) + '": function(c,p,t,i) {' + obj[key] + '}'); |
| 3285 |
} |
| 3286 |
return "{ " + items.join(",") + " }"; |
| 3287 |
} |
| 3288 |
|
| 3289 |
function stringifyPartials(codeObj) { |
| 3290 |
var partials = []; |
| 3291 |
for (var key in codeObj.partials) { |
| 3292 |
partials.push('"' + esc(key) + '":{name:"' + esc(codeObj.partials[key].name) + '", ' + stringifyPartials(codeObj.partials[key]) + "}"); |
| 3293 |
} |
| 3294 |
return "partials: {" + partials.join(",") + "}, subs: " + stringifySubstitutions(codeObj.subs); |
| 3295 |
} |
| 3296 |
|
| 3297 |
Hogan.stringify = function(codeObj, text, options) { |
| 3298 |
return "{code: function (c,p,i) { " + Hogan.wrapMain(codeObj.code) + " }," + stringifyPartials(codeObj) + "}"; |
| 3299 |
} |
| 3300 |
|
| 3301 |
var serialNo = 0; |
| 3302 |
Hogan.generate = function(tree, text, options) { |
| 3303 |
serialNo = 0; |
| 3304 |
var context = { code: '', subs: {}, partials: {} }; |
| 3305 |
Hogan.walk(tree, context); |
| 3306 |
|
| 3307 |
if (options.asString) { |
| 3308 |
return this.stringify(context, text, options); |
| 3309 |
} |
| 3310 |
|
| 3311 |
return this.makeTemplate(context, text, options); |
| 3312 |
} |
| 3313 |
|
| 3314 |
Hogan.wrapMain = function(code) { |
| 3315 |
return 'var t=this;t.b(i=i||"");' + code + 'return t.fl();'; |
| 3316 |
} |
| 3317 |
|
| 3318 |
Hogan.template = Hogan.Template; |
| 3319 |
|
| 3320 |
Hogan.makeTemplate = function(codeObj, text, options) { |
| 3321 |
var template = this.makePartials(codeObj); |
| 3322 |
template.code = new Function('c', 'p', 'i', this.wrapMain(codeObj.code)); |
| 3323 |
return new this.template(template, text, this, options); |
| 3324 |
} |
| 3325 |
|
| 3326 |
Hogan.makePartials = function(codeObj) { |
| 3327 |
var key, template = {subs: {}, partials: codeObj.partials, name: codeObj.name}; |
| 3328 |
for (key in template.partials) { |
| 3329 |
template.partials[key] = this.makePartials(template.partials[key]); |
| 3330 |
} |
| 3331 |
for (key in codeObj.subs) { |
| 3332 |
template.subs[key] = new Function('c', 'p', 't', 'i', codeObj.subs[key]); |
| 3333 |
} |
| 3334 |
return template; |
| 3335 |
} |
| 3336 |
|
| 3337 |
function esc(s) { |
| 3338 |
return s.replace(rSlash, '\\\\') |
| 3339 |
.replace(rQuot, '\\\"') |
| 3340 |
.replace(rNewline, '\\n') |
| 3341 |
.replace(rCr, '\\r') |
| 3342 |
.replace(rLineSep, '\\u2028') |
| 3343 |
.replace(rParagraphSep, '\\u2029'); |
| 3344 |
} |
| 3345 |
|
| 3346 |
function chooseMethod(s) { |
| 3347 |
return (~s.indexOf('.')) ? 'd' : 'f'; |
| 3348 |
} |
| 3349 |
|
| 3350 |
function createPartial(node, context) { |
| 3351 |
var prefix = "<" + (context.prefix || ""); |
| 3352 |
var sym = prefix + node.n + serialNo++; |
| 3353 |
context.partials[sym] = {name: node.n, partials: {}}; |
| 3354 |
context.code += 't.b(t.rp("' + esc(sym) + '",c,p,"' + (node.indent || '') + '"));'; |
| 3355 |
return sym; |
| 3356 |
} |
| 3357 |
|
| 3358 |
Hogan.codegen = { |
| 3359 |
'#': function(node, context) { |
| 3360 |
context.code += 'if(t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),' + |
| 3361 |
'c,p,0,' + node.i + ',' + node.end + ',"' + node.otag + " " + node.ctag + '")){' + |
| 3362 |
't.rs(c,p,' + 'function(c,p,t){'; |
| 3363 |
Hogan.walk(node.nodes, context); |
| 3364 |
context.code += '});c.pop();}'; |
| 3365 |
}, |
| 3366 |
|
| 3367 |
'^': function(node, context) { |
| 3368 |
context.code += 'if(!t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),c,p,1,0,0,"")){'; |
| 3369 |
Hogan.walk(node.nodes, context); |
| 3370 |
context.code += '};'; |
| 3371 |
}, |
| 3372 |
|
| 3373 |
'>': createPartial, |
| 3374 |
'<': function(node, context) { |
| 3375 |
var ctx = {partials: {}, code: '', subs: {}, inPartial: true}; |
| 3376 |
Hogan.walk(node.nodes, ctx); |
| 3377 |
var template = context.partials[createPartial(node, context)]; |
| 3378 |
template.subs = ctx.subs; |
| 3379 |
template.partials = ctx.partials; |
| 3380 |
}, |
| 3381 |
|
| 3382 |
'$': function(node, context) { |
| 3383 |
var ctx = {subs: {}, code: '', partials: context.partials, prefix: node.n}; |
| 3384 |
Hogan.walk(node.nodes, ctx); |
| 3385 |
context.subs[node.n] = ctx.code; |
| 3386 |
if (!context.inPartial) { |
| 3387 |
context.code += 't.sub("' + esc(node.n) + '",c,p,i);'; |
| 3388 |
} |
| 3389 |
}, |
| 3390 |
|
| 3391 |
'\n': function(node, context) { |
| 3392 |
context.code += write('"\\n"' + (node.last ? '' : ' + i')); |
| 3393 |
}, |
| 3394 |
|
| 3395 |
'_v': function(node, context) { |
| 3396 |
context.code += 't.b(t.v(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));'; |
| 3397 |
}, |
| 3398 |
|
| 3399 |
'_t': function(node, context) { |
| 3400 |
context.code += write('"' + esc(node.text) + '"'); |
| 3401 |
}, |
| 3402 |
|
| 3403 |
'{': tripleStache, |
| 3404 |
|
| 3405 |
'&': tripleStache |
| 3406 |
} |
| 3407 |
|
| 3408 |
function tripleStache(node, context) { |
| 3409 |
context.code += 't.b(t.t(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));'; |
| 3410 |
} |
| 3411 |
|
| 3412 |
function write(s) { |
| 3413 |
return 't.b(' + s + ');'; |
| 3414 |
} |
| 3415 |
|
| 3416 |
Hogan.walk = function(nodelist, context) { |
| 3417 |
var func; |
| 3418 |
for (var i = 0, l = nodelist.length; i < l; i++) { |
| 3419 |
func = Hogan.codegen[nodelist[i].tag]; |
| 3420 |
func && func(nodelist[i], context); |
| 3421 |
} |
| 3422 |
return context; |
| 3423 |
} |
| 3424 |
|
| 3425 |
Hogan.parse = function(tokens, text, options) { |
| 3426 |
options = options || {}; |
| 3427 |
return buildTree(tokens, '', [], options.sectionTags || []); |
| 3428 |
} |
| 3429 |
|
| 3430 |
Hogan.cache = {}; |
| 3431 |
|
| 3432 |
Hogan.cacheKey = function(text, options) { |
| 3433 |
return [text, !!options.asString, !!options.disableLambda, options.delimiters, !!options.modelGet].join('||'); |
| 3434 |
} |
| 3435 |
|
| 3436 |
Hogan.compile = function(text, options) { |
| 3437 |
options = options || {}; |
| 3438 |
var key = Hogan.cacheKey(text, options); |
| 3439 |
var template = this.cache[key]; |
| 3440 |
|
| 3441 |
if (template) { |
| 3442 |
var partials = template.partials; |
| 3443 |
for (var name in partials) { |
| 3444 |
delete partials[name].instance; |
| 3445 |
} |
| 3446 |
return template; |
| 3447 |
} |
| 3448 |
|
| 3449 |
template = this.generate(this.parse(this.scan(text, options.delimiters), text, options), text, options); |
| 3450 |
return this.cache[key] = template; |
| 3451 |
} |
| 3452 |
})( true ? exports : Hogan); |
| 3453 |
|
| 3454 |
|
| 3455 |
/***/ }), |
| 3456 |
/* 28 */ |
| 3457 |
/***/ (function(module, exports, __webpack_require__) { |
| 3458 |
|
| 3459 |
/* |
| 3460 |
* Copyright 2011 Twitter, Inc. |
| 3461 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3462 |
* you may not use this file except in compliance with the License. |
| 3463 |
* You may obtain a copy of the License at |
| 3464 |
* |
| 3465 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3466 |
* |
| 3467 |
* Unless required by applicable law or agreed to in writing, software |
| 3468 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 3469 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 3470 |
* See the License for the specific language governing permissions and |
| 3471 |
* limitations under the License. |
| 3472 |
*/ |
| 3473 |
|
| 3474 |
var Hogan = {}; |
| 3475 |
|
| 3476 |
(function (Hogan) { |
| 3477 |
Hogan.Template = function (codeObj, text, compiler, options) { |
| 3478 |
codeObj = codeObj || {}; |
| 3479 |
this.r = codeObj.code || this.r; |
| 3480 |
this.c = compiler; |
| 3481 |
this.options = options || {}; |
| 3482 |
this.text = text || ''; |
| 3483 |
this.partials = codeObj.partials || {}; |
| 3484 |
this.subs = codeObj.subs || {}; |
| 3485 |
this.buf = ''; |
| 3486 |
} |
| 3487 |
|
| 3488 |
Hogan.Template.prototype = { |
| 3489 |
// render: replaced by generated code. |
| 3490 |
r: function (context, partials, indent) { return ''; }, |
| 3491 |
|
| 3492 |
// variable escaping |
| 3493 |
v: hoganEscape, |
| 3494 |
|
| 3495 |
// triple stache |
| 3496 |
t: coerceToString, |
| 3497 |
|
| 3498 |
render: function render(context, partials, indent) { |
| 3499 |
return this.ri([context], partials || {}, indent); |
| 3500 |
}, |
| 3501 |
|
| 3502 |
// render internal -- a hook for overrides that catches partials too |
| 3503 |
ri: function (context, partials, indent) { |
| 3504 |
return this.r(context, partials, indent); |
| 3505 |
}, |
| 3506 |
|
| 3507 |
// ensurePartial |
| 3508 |
ep: function(symbol, partials) { |
| 3509 |
var partial = this.partials[symbol]; |
| 3510 |
|
| 3511 |
// check to see that if we've instantiated this partial before |
| 3512 |
var template = partials[partial.name]; |
| 3513 |
if (partial.instance && partial.base == template) { |
| 3514 |
return partial.instance; |
| 3515 |
} |
| 3516 |
|
| 3517 |
if (typeof template == 'string') { |
| 3518 |
if (!this.c) { |
| 3519 |
throw new Error("No compiler available."); |
| 3520 |
} |
| 3521 |
template = this.c.compile(template, this.options); |
| 3522 |
} |
| 3523 |
|
| 3524 |
if (!template) { |
| 3525 |
return null; |
| 3526 |
} |
| 3527 |
|
| 3528 |
// We use this to check whether the partials dictionary has changed |
| 3529 |
this.partials[symbol].base = template; |
| 3530 |
|
| 3531 |
if (partial.subs) { |
| 3532 |
// Make sure we consider parent template now |
| 3533 |
if (!partials.stackText) partials.stackText = {}; |
| 3534 |
for (key in partial.subs) { |
| 3535 |
if (!partials.stackText[key]) { |
| 3536 |
partials.stackText[key] = (this.activeSub !== undefined && partials.stackText[this.activeSub]) ? partials.stackText[this.activeSub] : this.text; |
| 3537 |
} |
| 3538 |
} |
| 3539 |
template = createSpecializedPartial(template, partial.subs, partial.partials, |
| 3540 |
this.stackSubs, this.stackPartials, partials.stackText); |
| 3541 |
} |
| 3542 |
this.partials[symbol].instance = template; |
| 3543 |
|
| 3544 |
return template; |
| 3545 |
}, |
| 3546 |
|
| 3547 |
// tries to find a partial in the current scope and render it |
| 3548 |
rp: function(symbol, context, partials, indent) { |
| 3549 |
var partial = this.ep(symbol, partials); |
| 3550 |
if (!partial) { |
| 3551 |
return ''; |
| 3552 |
} |
| 3553 |
|
| 3554 |
return partial.ri(context, partials, indent); |
| 3555 |
}, |
| 3556 |
|
| 3557 |
// render a section |
| 3558 |
rs: function(context, partials, section) { |
| 3559 |
var tail = context[context.length - 1]; |
| 3560 |
|
| 3561 |
if (!isArray(tail)) { |
| 3562 |
section(context, partials, this); |
| 3563 |
return; |
| 3564 |
} |
| 3565 |
|
| 3566 |
for (var i = 0; i < tail.length; i++) { |
| 3567 |
context.push(tail[i]); |
| 3568 |
section(context, partials, this); |
| 3569 |
context.pop(); |
| 3570 |
} |
| 3571 |
}, |
| 3572 |
|
| 3573 |
// maybe start a section |
| 3574 |
s: function(val, ctx, partials, inverted, start, end, tags) { |
| 3575 |
var pass; |
| 3576 |
|
| 3577 |
if (isArray(val) && val.length === 0) { |
| 3578 |
return false; |
| 3579 |
} |
| 3580 |
|
| 3581 |
if (typeof val == 'function') { |
| 3582 |
val = this.ms(val, ctx, partials, inverted, start, end, tags); |
| 3583 |
} |
| 3584 |
|
| 3585 |
pass = !!val; |
| 3586 |
|
| 3587 |
if (!inverted && pass && ctx) { |
| 3588 |
ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]); |
| 3589 |
} |
| 3590 |
|
| 3591 |
return pass; |
| 3592 |
}, |
| 3593 |
|
| 3594 |
// find values with dotted names |
| 3595 |
d: function(key, ctx, partials, returnFound) { |
| 3596 |
var found, |
| 3597 |
names = key.split('.'), |
| 3598 |
val = this.f(names[0], ctx, partials, returnFound), |
| 3599 |
doModelGet = this.options.modelGet, |
| 3600 |
cx = null; |
| 3601 |
|
| 3602 |
if (key === '.' && isArray(ctx[ctx.length - 2])) { |
| 3603 |
val = ctx[ctx.length - 1]; |
| 3604 |
} else { |
| 3605 |
for (var i = 1; i < names.length; i++) { |
| 3606 |
found = findInScope(names[i], val, doModelGet); |
| 3607 |
if (found !== undefined) { |
| 3608 |
cx = val; |
| 3609 |
val = found; |
| 3610 |
} else { |
| 3611 |
val = ''; |
| 3612 |
} |
| 3613 |
} |
| 3614 |
} |
| 3615 |
|
| 3616 |
if (returnFound && !val) { |
| 3617 |
return false; |
| 3618 |
} |
| 3619 |
|
| 3620 |
if (!returnFound && typeof val == 'function') { |
| 3621 |
ctx.push(cx); |
| 3622 |
val = this.mv(val, ctx, partials); |
| 3623 |
ctx.pop(); |
| 3624 |
} |
| 3625 |
|
| 3626 |
return val; |
| 3627 |
}, |
| 3628 |
|
| 3629 |
// find values with normal names |
| 3630 |
f: function(key, ctx, partials, returnFound) { |
| 3631 |
var val = false, |
| 3632 |
v = null, |
| 3633 |
found = false, |
| 3634 |
doModelGet = this.options.modelGet; |
| 3635 |
|
| 3636 |
for (var i = ctx.length - 1; i >= 0; i--) { |
| 3637 |
v = ctx[i]; |
| 3638 |
val = findInScope(key, v, doModelGet); |
| 3639 |
if (val !== undefined) { |
| 3640 |
found = true; |
| 3641 |
break; |
| 3642 |
} |
| 3643 |
} |
| 3644 |
|
| 3645 |
if (!found) { |
| 3646 |
return (returnFound) ? false : ""; |
| 3647 |
} |
| 3648 |
|
| 3649 |
if (!returnFound && typeof val == 'function') { |
| 3650 |
val = this.mv(val, ctx, partials); |
| 3651 |
} |
| 3652 |
|
| 3653 |
return val; |
| 3654 |
}, |
| 3655 |
|
| 3656 |
// higher order templates |
| 3657 |
ls: function(func, cx, partials, text, tags) { |
| 3658 |
var oldTags = this.options.delimiters; |
| 3659 |
|
| 3660 |
this.options.delimiters = tags; |
| 3661 |
this.b(this.ct(coerceToString(func.call(cx, text)), cx, partials)); |
| 3662 |
this.options.delimiters = oldTags; |
| 3663 |
|
| 3664 |
return false; |
| 3665 |
}, |
| 3666 |
|
| 3667 |
// compile text |
| 3668 |
ct: function(text, cx, partials) { |
| 3669 |
if (this.options.disableLambda) { |
| 3670 |
throw new Error('Lambda features disabled.'); |
| 3671 |
} |
| 3672 |
return this.c.compile(text, this.options).render(cx, partials); |
| 3673 |
}, |
| 3674 |
|
| 3675 |
// template result buffering |
| 3676 |
b: function(s) { this.buf += s; }, |
| 3677 |
|
| 3678 |
fl: function() { var r = this.buf; this.buf = ''; return r; }, |
| 3679 |
|
| 3680 |
// method replace section |
| 3681 |
ms: function(func, ctx, partials, inverted, start, end, tags) { |
| 3682 |
var textSource, |
| 3683 |
cx = ctx[ctx.length - 1], |
| 3684 |
result = func.call(cx); |
| 3685 |
|
| 3686 |
if (typeof result == 'function') { |
| 3687 |
if (inverted) { |
| 3688 |
return true; |
| 3689 |
} else { |
| 3690 |
textSource = (this.activeSub && this.subsText && this.subsText[this.activeSub]) ? this.subsText[this.activeSub] : this.text; |
| 3691 |
return this.ls(result, cx, partials, textSource.substring(start, end), tags); |
| 3692 |
} |
| 3693 |
} |
| 3694 |
|
| 3695 |
return result; |
| 3696 |
}, |
| 3697 |
|
| 3698 |
// method replace variable |
| 3699 |
mv: function(func, ctx, partials) { |
| 3700 |
var cx = ctx[ctx.length - 1]; |
| 3701 |
var result = func.call(cx); |
| 3702 |
|
| 3703 |
if (typeof result == 'function') { |
| 3704 |
return this.ct(coerceToString(result.call(cx)), cx, partials); |
| 3705 |
} |
| 3706 |
|
| 3707 |
return result; |
| 3708 |
}, |
| 3709 |
|
| 3710 |
sub: function(name, context, partials, indent) { |
| 3711 |
var f = this.subs[name]; |
| 3712 |
if (f) { |
| 3713 |
this.activeSub = name; |
| 3714 |
f(context, partials, this, indent); |
| 3715 |
this.activeSub = false; |
| 3716 |
} |
| 3717 |
} |
| 3718 |
|
| 3719 |
}; |
| 3720 |
|
| 3721 |
//Find a key in an object |
| 3722 |
function findInScope(key, scope, doModelGet) { |
| 3723 |
var val; |
| 3724 |
|
| 3725 |
if (scope && typeof scope == 'object') { |
| 3726 |
|
| 3727 |
if (scope[key] !== undefined) { |
| 3728 |
val = scope[key]; |
| 3729 |
|
| 3730 |
// try lookup with get for backbone or similar model data |
| 3731 |
} else if (doModelGet && scope.get && typeof scope.get == 'function') { |
| 3732 |
val = scope.get(key); |
| 3733 |
} |
| 3734 |
} |
| 3735 |
|
| 3736 |
return val; |
| 3737 |
} |
| 3738 |
|
| 3739 |
function createSpecializedPartial(instance, subs, partials, stackSubs, stackPartials, stackText) { |
| 3740 |
function PartialTemplate() {}; |
| 3741 |
PartialTemplate.prototype = instance; |
| 3742 |
function Substitutions() {}; |
| 3743 |
Substitutions.prototype = instance.subs; |
| 3744 |
var key; |
| 3745 |
var partial = new PartialTemplate(); |
| 3746 |
partial.subs = new Substitutions(); |
| 3747 |
partial.subsText = {}; //hehe. substext. |
| 3748 |
partial.buf = ''; |
| 3749 |
|
| 3750 |
stackSubs = stackSubs || {}; |
| 3751 |
partial.stackSubs = stackSubs; |
| 3752 |
partial.subsText = stackText; |
| 3753 |
for (key in subs) { |
| 3754 |
if (!stackSubs[key]) stackSubs[key] = subs[key]; |
| 3755 |
} |
| 3756 |
for (key in stackSubs) { |
| 3757 |
partial.subs[key] = stackSubs[key]; |
| 3758 |
} |
| 3759 |
|
| 3760 |
stackPartials = stackPartials || {}; |
| 3761 |
partial.stackPartials = stackPartials; |
| 3762 |
for (key in partials) { |
| 3763 |
if (!stackPartials[key]) stackPartials[key] = partials[key]; |
| 3764 |
} |
| 3765 |
for (key in stackPartials) { |
| 3766 |
partial.partials[key] = stackPartials[key]; |
| 3767 |
} |
| 3768 |
|
| 3769 |
return partial; |
| 3770 |
} |
| 3771 |
|
| 3772 |
var rAmp = /&/g, |
| 3773 |
rLt = /</g, |
| 3774 |
rGt = />/g, |
| 3775 |
rApos = /\'/g, |
| 3776 |
rQuot = /\"/g, |
| 3777 |
hChars = /[&<>\"\']/; |
| 3778 |
|
| 3779 |
function coerceToString(val) { |
| 3780 |
return String((val === null || val === undefined) ? '' : val); |
| 3781 |
} |
| 3782 |
|
| 3783 |
function hoganEscape(str) { |
| 3784 |
str = coerceToString(str); |
| 3785 |
return hChars.test(str) ? |
| 3786 |
str |
| 3787 |
.replace(rAmp, '&') |
| 3788 |
.replace(rLt, '<') |
| 3789 |
.replace(rGt, '>') |
| 3790 |
.replace(rApos, ''') |
| 3791 |
.replace(rQuot, '"') : |
| 3792 |
str; |
| 3793 |
} |
| 3794 |
|
| 3795 |
var isArray = Array.isArray || function(a) { |
| 3796 |
return Object.prototype.toString.call(a) === '[object Array]'; |
| 3797 |
}; |
| 3798 |
|
| 3799 |
})( true ? exports : Hogan); |
| 3800 |
|
| 3801 |
|
| 3802 |
/***/ }), |
| 3803 |
/* 29 */ |
| 3804 |
/***/ (function(module, exports, __webpack_require__) { |
| 3805 |
|
| 3806 |
"use strict"; |
| 3807 |
|
| 3808 |
|
| 3809 |
var AlgoliaSearchCore = __webpack_require__(30); |
| 3810 |
var createAlgoliasearch = __webpack_require__(41); |
| 3811 |
|
| 3812 |
module.exports = createAlgoliasearch(AlgoliaSearchCore, '(lite) '); |
| 3813 |
|
| 3814 |
|
| 3815 |
/***/ }), |
| 3816 |
/* 30 */ |
| 3817 |
/***/ (function(module, exports, __webpack_require__) { |
| 3818 |
|
| 3819 |
module.exports = AlgoliaSearchCore; |
| 3820 |
|
| 3821 |
var errors = __webpack_require__(5); |
| 3822 |
var exitPromise = __webpack_require__(31); |
| 3823 |
var IndexCore = __webpack_require__(32); |
| 3824 |
var store = __webpack_require__(38); |
| 3825 |
|
| 3826 |
// We will always put the API KEY in the JSON body in case of too long API KEY, |
| 3827 |
// to avoid query string being too long and failing in various conditions (our server limit, browser limit, |
| 3828 |
// proxies limit) |
| 3829 |
var MAX_API_KEY_LENGTH = 500; |
| 3830 |
var RESET_APP_DATA_TIMER = |
| 3831 |
Object({"NODE_ENV":"production"}).RESET_APP_DATA_TIMER && parseInt(Object({"NODE_ENV":"production"}).RESET_APP_DATA_TIMER, 10) || |
| 3832 |
60 * 2 * 1000; // after 2 minutes reset to first host |
| 3833 |
|
| 3834 |
/* |
| 3835 |
* Algolia Search library initialization |
| 3836 |
* https://www.algolia.com/ |
| 3837 |
* |
| 3838 |
* @param {string} applicationID - Your applicationID, found in your dashboard |
| 3839 |
* @param {string} apiKey - Your API key, found in your dashboard |
| 3840 |
* @param {Object} [opts] |
| 3841 |
* @param {number} [opts.timeout=2000] - The request timeout set in milliseconds, |
| 3842 |
* another request will be issued after this timeout |
| 3843 |
* @param {string} [opts.protocol='https:'] - The protocol used to query Algolia Search API. |
| 3844 |
* Set to 'http:' to force using http. |
| 3845 |
* @param {Object|Array} [opts.hosts={ |
| 3846 |
* read: [this.applicationID + '-dsn.algolia.net'].concat([ |
| 3847 |
* this.applicationID + '-1.algolianet.com', |
| 3848 |
* this.applicationID + '-2.algolianet.com', |
| 3849 |
* this.applicationID + '-3.algolianet.com'] |
| 3850 |
* ]), |
| 3851 |
* write: [this.applicationID + '.algolia.net'].concat([ |
| 3852 |
* this.applicationID + '-1.algolianet.com', |
| 3853 |
* this.applicationID + '-2.algolianet.com', |
| 3854 |
* this.applicationID + '-3.algolianet.com'] |
| 3855 |
* ]) - The hosts to use for Algolia Search API. |
| 3856 |
* If you provide them, you will less benefit from our HA implementation |
| 3857 |
*/ |
| 3858 |
function AlgoliaSearchCore(applicationID, apiKey, opts) { |
| 3859 |
var debug = __webpack_require__(8)('algoliasearch'); |
| 3860 |
|
| 3861 |
var clone = __webpack_require__(3); |
| 3862 |
var isArray = __webpack_require__(6); |
| 3863 |
var map = __webpack_require__(7); |
| 3864 |
|
| 3865 |
var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)'; |
| 3866 |
|
| 3867 |
if (opts._allowEmptyCredentials !== true && !applicationID) { |
| 3868 |
throw new errors.AlgoliaSearchError('Please provide an application ID. ' + usage); |
| 3869 |
} |
| 3870 |
|
| 3871 |
if (opts._allowEmptyCredentials !== true && !apiKey) { |
| 3872 |
throw new errors.AlgoliaSearchError('Please provide an API key. ' + usage); |
| 3873 |
} |
| 3874 |
|
| 3875 |
this.applicationID = applicationID; |
| 3876 |
this.apiKey = apiKey; |
| 3877 |
|
| 3878 |
this.hosts = { |
| 3879 |
read: [], |
| 3880 |
write: [] |
| 3881 |
}; |
| 3882 |
|
| 3883 |
opts = opts || {}; |
| 3884 |
|
| 3885 |
this._timeouts = opts.timeouts || { |
| 3886 |
connect: 1 * 1000, // 500ms connect is GPRS latency |
| 3887 |
read: 2 * 1000, |
| 3888 |
write: 30 * 1000 |
| 3889 |
}; |
| 3890 |
|
| 3891 |
// backward compat, if opts.timeout is passed, we use it to configure all timeouts like before |
| 3892 |
if (opts.timeout) { |
| 3893 |
this._timeouts.connect = this._timeouts.read = this._timeouts.write = opts.timeout; |
| 3894 |
} |
| 3895 |
|
| 3896 |
var protocol = opts.protocol || 'https:'; |
| 3897 |
// while we advocate for colon-at-the-end values: 'http:' for `opts.protocol` |
| 3898 |
// we also accept `http` and `https`. It's a common error. |
| 3899 |
if (!/:$/.test(protocol)) { |
| 3900 |
protocol = protocol + ':'; |
| 3901 |
} |
| 3902 |
|
| 3903 |
if (protocol !== 'http:' && protocol !== 'https:') { |
| 3904 |
throw new errors.AlgoliaSearchError('protocol must be `http:` or `https:` (was `' + opts.protocol + '`)'); |
| 3905 |
} |
| 3906 |
|
| 3907 |
this._checkAppIdData(); |
| 3908 |
|
| 3909 |
if (!opts.hosts) { |
| 3910 |
var defaultHosts = map(this._shuffleResult, function(hostNumber) { |
| 3911 |
return applicationID + '-' + hostNumber + '.algolianet.com'; |
| 3912 |
}); |
| 3913 |
|
| 3914 |
// no hosts given, compute defaults |
| 3915 |
var mainSuffix = (opts.dsn === false ? '' : '-dsn') + '.algolia.net'; |
| 3916 |
this.hosts.read = [this.applicationID + mainSuffix].concat(defaultHosts); |
| 3917 |
this.hosts.write = [this.applicationID + '.algolia.net'].concat(defaultHosts); |
| 3918 |
} else if (isArray(opts.hosts)) { |
| 3919 |
// when passing custom hosts, we need to have a different host index if the number |
| 3920 |
// of write/read hosts are different. |
| 3921 |
this.hosts.read = clone(opts.hosts); |
| 3922 |
this.hosts.write = clone(opts.hosts); |
| 3923 |
} else { |
| 3924 |
this.hosts.read = clone(opts.hosts.read); |
| 3925 |
this.hosts.write = clone(opts.hosts.write); |
| 3926 |
} |
| 3927 |
|
| 3928 |
// add protocol and lowercase hosts |
| 3929 |
this.hosts.read = map(this.hosts.read, prepareHost(protocol)); |
| 3930 |
this.hosts.write = map(this.hosts.write, prepareHost(protocol)); |
| 3931 |
|
| 3932 |
this.extraHeaders = {}; |
| 3933 |
|
| 3934 |
// In some situations you might want to warm the cache |
| 3935 |
this.cache = opts._cache || {}; |
| 3936 |
|
| 3937 |
this._ua = opts._ua; |
| 3938 |
this._useCache = opts._useCache === undefined || opts._cache ? true : opts._useCache; |
| 3939 |
this._useRequestCache = this._useCache && opts._useRequestCache; |
| 3940 |
this._useFallback = opts.useFallback === undefined ? true : opts.useFallback; |
| 3941 |
|
| 3942 |
this._setTimeout = opts._setTimeout; |
| 3943 |
|
| 3944 |
debug('init done, %j', this); |
| 3945 |
} |
| 3946 |
|
| 3947 |
/* |
| 3948 |
* Get the index object initialized |
| 3949 |
* |
| 3950 |
* @param indexName the name of index |
| 3951 |
* @param callback the result callback with one argument (the Index instance) |
| 3952 |
*/ |
| 3953 |
AlgoliaSearchCore.prototype.initIndex = function(indexName) { |
| 3954 |
return new IndexCore(this, indexName); |
| 3955 |
}; |
| 3956 |
|
| 3957 |
/** |
| 3958 |
* Add an extra field to the HTTP request |
| 3959 |
* |
| 3960 |
* @param name the header field name |
| 3961 |
* @param value the header field value |
| 3962 |
*/ |
| 3963 |
AlgoliaSearchCore.prototype.setExtraHeader = function(name, value) { |
| 3964 |
this.extraHeaders[name.toLowerCase()] = value; |
| 3965 |
}; |
| 3966 |
|
| 3967 |
/** |
| 3968 |
* Get the value of an extra HTTP header |
| 3969 |
* |
| 3970 |
* @param name the header field name |
| 3971 |
*/ |
| 3972 |
AlgoliaSearchCore.prototype.getExtraHeader = function(name) { |
| 3973 |
return this.extraHeaders[name.toLowerCase()]; |
| 3974 |
}; |
| 3975 |
|
| 3976 |
/** |
| 3977 |
* Remove an extra field from the HTTP request |
| 3978 |
* |
| 3979 |
* @param name the header field name |
| 3980 |
*/ |
| 3981 |
AlgoliaSearchCore.prototype.unsetExtraHeader = function(name) { |
| 3982 |
delete this.extraHeaders[name.toLowerCase()]; |
| 3983 |
}; |
| 3984 |
|
| 3985 |
/** |
| 3986 |
* Augment sent x-algolia-agent with more data, each agent part |
| 3987 |
* is automatically separated from the others by a semicolon; |
| 3988 |
* |
| 3989 |
* @param algoliaAgent the agent to add |
| 3990 |
*/ |
| 3991 |
AlgoliaSearchCore.prototype.addAlgoliaAgent = function(algoliaAgent) { |
| 3992 |
if (this._ua.indexOf(';' + algoliaAgent) === -1) { |
| 3993 |
this._ua += ';' + algoliaAgent; |
| 3994 |
} |
| 3995 |
}; |
| 3996 |
|
| 3997 |
/* |
| 3998 |
* Wrapper that try all hosts to maximize the quality of service |
| 3999 |
*/ |
| 4000 |
AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) { |
| 4001 |
this._checkAppIdData(); |
| 4002 |
|
| 4003 |
var requestDebug = __webpack_require__(8)('algoliasearch:' + initialOpts.url); |
| 4004 |
|
| 4005 |
|
| 4006 |
var body; |
| 4007 |
var cacheID; |
| 4008 |
var additionalUA = initialOpts.additionalUA || ''; |
| 4009 |
var cache = initialOpts.cache; |
| 4010 |
var client = this; |
| 4011 |
var tries = 0; |
| 4012 |
var usingFallback = false; |
| 4013 |
var hasFallback = client._useFallback && client._request.fallback && initialOpts.fallback; |
| 4014 |
var headers; |
| 4015 |
|
| 4016 |
if ( |
| 4017 |
this.apiKey.length > MAX_API_KEY_LENGTH && |
| 4018 |
initialOpts.body !== undefined && |
| 4019 |
(initialOpts.body.params !== undefined || // index.search() |
| 4020 |
initialOpts.body.requests !== undefined) // client.search() |
| 4021 |
) { |
| 4022 |
initialOpts.body.apiKey = this.apiKey; |
| 4023 |
headers = this._computeRequestHeaders({ |
| 4024 |
additionalUA: additionalUA, |
| 4025 |
withApiKey: false, |
| 4026 |
headers: initialOpts.headers |
| 4027 |
}); |
| 4028 |
} else { |
| 4029 |
headers = this._computeRequestHeaders({ |
| 4030 |
additionalUA: additionalUA, |
| 4031 |
headers: initialOpts.headers |
| 4032 |
}); |
| 4033 |
} |
| 4034 |
|
| 4035 |
if (initialOpts.body !== undefined) { |
| 4036 |
body = safeJSONStringify(initialOpts.body); |
| 4037 |
} |
| 4038 |
|
| 4039 |
requestDebug('request start'); |
| 4040 |
var debugData = []; |
| 4041 |
|
| 4042 |
|
| 4043 |
function doRequest(requester, reqOpts) { |
| 4044 |
client._checkAppIdData(); |
| 4045 |
|
| 4046 |
var startTime = new Date(); |
| 4047 |
|
| 4048 |
if (client._useCache && !client._useRequestCache) { |
| 4049 |
cacheID = initialOpts.url; |
| 4050 |
} |
| 4051 |
|
| 4052 |
// as we sometime use POST requests to pass parameters (like query='aa'), |
| 4053 |
// the cacheID must also include the body to be different between calls |
| 4054 |
if (client._useCache && !client._useRequestCache && body) { |
| 4055 |
cacheID += '_body_' + reqOpts.body; |
| 4056 |
} |
| 4057 |
|
| 4058 |
// handle cache existence |
| 4059 |
if (isCacheValidWithCurrentID(!client._useRequestCache, cache, cacheID)) { |
| 4060 |
requestDebug('serving response from cache'); |
| 4061 |
|
| 4062 |
var responseText = cache[cacheID]; |
| 4063 |
|
| 4064 |
// Cache response must match the type of the original one |
| 4065 |
return client._promise.resolve({ |
| 4066 |
body: JSON.parse(responseText), |
| 4067 |
responseText: responseText |
| 4068 |
}); |
| 4069 |
} |
| 4070 |
|
| 4071 |
// if we reached max tries |
| 4072 |
if (tries >= client.hosts[initialOpts.hostType].length) { |
| 4073 |
if (!hasFallback || usingFallback) { |
| 4074 |
requestDebug('could not get any response'); |
| 4075 |
// then stop |
| 4076 |
return client._promise.reject(new errors.AlgoliaSearchError( |
| 4077 |
'Cannot connect to the AlgoliaSearch API.' + |
| 4078 |
' Send an email to [email protected] to report and resolve the issue.' + |
| 4079 |
' Application id was: ' + client.applicationID, {debugData: debugData} |
| 4080 |
)); |
| 4081 |
} |
| 4082 |
|
| 4083 |
requestDebug('switching to fallback'); |
| 4084 |
|
| 4085 |
// let's try the fallback starting from here |
| 4086 |
tries = 0; |
| 4087 |
|
| 4088 |
// method, url and body are fallback dependent |
| 4089 |
reqOpts.method = initialOpts.fallback.method; |
| 4090 |
reqOpts.url = initialOpts.fallback.url; |
| 4091 |
reqOpts.jsonBody = initialOpts.fallback.body; |
| 4092 |
if (reqOpts.jsonBody) { |
| 4093 |
reqOpts.body = safeJSONStringify(reqOpts.jsonBody); |
| 4094 |
} |
| 4095 |
// re-compute headers, they could be omitting the API KEY |
| 4096 |
headers = client._computeRequestHeaders({ |
| 4097 |
additionalUA: additionalUA, |
| 4098 |
headers: initialOpts.headers |
| 4099 |
}); |
| 4100 |
|
| 4101 |
reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType); |
| 4102 |
client._setHostIndexByType(0, initialOpts.hostType); |
| 4103 |
usingFallback = true; // the current request is now using fallback |
| 4104 |
return doRequest(client._request.fallback, reqOpts); |
| 4105 |
} |
| 4106 |
|
| 4107 |
var currentHost = client._getHostByType(initialOpts.hostType); |
| 4108 |
|
| 4109 |
var url = currentHost + reqOpts.url; |
| 4110 |
var options = { |
| 4111 |
body: reqOpts.body, |
| 4112 |
jsonBody: reqOpts.jsonBody, |
| 4113 |
method: reqOpts.method, |
| 4114 |
headers: headers, |
| 4115 |
timeouts: reqOpts.timeouts, |
| 4116 |
debug: requestDebug, |
| 4117 |
forceAuthHeaders: reqOpts.forceAuthHeaders |
| 4118 |
}; |
| 4119 |
|
| 4120 |
requestDebug('method: %s, url: %s, headers: %j, timeouts: %d', |
| 4121 |
options.method, url, options.headers, options.timeouts); |
| 4122 |
|
| 4123 |
if (requester === client._request.fallback) { |
| 4124 |
requestDebug('using fallback'); |
| 4125 |
} |
| 4126 |
|
| 4127 |
// `requester` is any of this._request or this._request.fallback |
| 4128 |
// thus it needs to be called using the client as context |
| 4129 |
return requester.call(client, url, options).then(success, tryFallback); |
| 4130 |
|
| 4131 |
function success(httpResponse) { |
| 4132 |
// compute the status of the response, |
| 4133 |
// |
| 4134 |
// When in browser mode, using XDR or JSONP, we have no statusCode available |
| 4135 |
// So we rely on our API response `status` property. |
| 4136 |
// But `waitTask` can set a `status` property which is not the statusCode (it's the task status) |
| 4137 |
// So we check if there's a `message` along `status` and it means it's an error |
| 4138 |
// |
| 4139 |
// That's the only case where we have a response.status that's not the http statusCode |
| 4140 |
var status = httpResponse && httpResponse.body && httpResponse.body.message && httpResponse.body.status || |
| 4141 |
|
| 4142 |
// this is important to check the request statusCode AFTER the body eventual |
| 4143 |
// statusCode because some implementations (jQuery XDomainRequest transport) may |
| 4144 |
// send statusCode 200 while we had an error |
| 4145 |
httpResponse.statusCode || |
| 4146 |
|
| 4147 |
// When in browser mode, using XDR or JSONP |
| 4148 |
// we default to success when no error (no response.status && response.message) |
| 4149 |
// If there was a JSON.parse() error then body is null and it fails |
| 4150 |
httpResponse && httpResponse.body && 200; |
| 4151 |
|
| 4152 |
requestDebug('received response: statusCode: %s, computed statusCode: %d, headers: %j', |
| 4153 |
httpResponse.statusCode, status, httpResponse.headers); |
| 4154 |
|
| 4155 |
var httpResponseOk = Math.floor(status / 100) === 2; |
| 4156 |
|
| 4157 |
var endTime = new Date(); |
| 4158 |
debugData.push({ |
| 4159 |
currentHost: currentHost, |
| 4160 |
headers: removeCredentials(headers), |
| 4161 |
content: body || null, |
| 4162 |
contentLength: body !== undefined ? body.length : null, |
| 4163 |
method: reqOpts.method, |
| 4164 |
timeouts: reqOpts.timeouts, |
| 4165 |
url: reqOpts.url, |
| 4166 |
startTime: startTime, |
| 4167 |
endTime: endTime, |
| 4168 |
duration: endTime - startTime, |
| 4169 |
statusCode: status |
| 4170 |
}); |
| 4171 |
|
| 4172 |
if (httpResponseOk) { |
| 4173 |
if (client._useCache && !client._useRequestCache && cache) { |
| 4174 |
cache[cacheID] = httpResponse.responseText; |
| 4175 |
} |
| 4176 |
|
| 4177 |
return { |
| 4178 |
responseText: httpResponse.responseText, |
| 4179 |
body: httpResponse.body |
| 4180 |
}; |
| 4181 |
} |
| 4182 |
|
| 4183 |
var shouldRetry = Math.floor(status / 100) !== 4; |
| 4184 |
|
| 4185 |
if (shouldRetry) { |
| 4186 |
tries += 1; |
| 4187 |
return retryRequest(); |
| 4188 |
} |
| 4189 |
|
| 4190 |
requestDebug('unrecoverable error'); |
| 4191 |
|
| 4192 |
// no success and no retry => fail |
| 4193 |
var unrecoverableError = new errors.AlgoliaSearchError( |
| 4194 |
httpResponse.body && httpResponse.body.message, {debugData: debugData, statusCode: status} |
| 4195 |
); |
| 4196 |
|
| 4197 |
return client._promise.reject(unrecoverableError); |
| 4198 |
} |
| 4199 |
|
| 4200 |
function tryFallback(err) { |
| 4201 |
// error cases: |
| 4202 |
// While not in fallback mode: |
| 4203 |
// - CORS not supported |
| 4204 |
// - network error |
| 4205 |
// While in fallback mode: |
| 4206 |
// - timeout |
| 4207 |
// - network error |
| 4208 |
// - badly formatted JSONP (script loaded, did not call our callback) |
| 4209 |
// In both cases: |
| 4210 |
// - uncaught exception occurs (TypeError) |
| 4211 |
requestDebug('error: %s, stack: %s', err.message, err.stack); |
| 4212 |
|
| 4213 |
var endTime = new Date(); |
| 4214 |
debugData.push({ |
| 4215 |
currentHost: currentHost, |
| 4216 |
headers: removeCredentials(headers), |
| 4217 |
content: body || null, |
| 4218 |
contentLength: body !== undefined ? body.length : null, |
| 4219 |
method: reqOpts.method, |
| 4220 |
timeouts: reqOpts.timeouts, |
| 4221 |
url: reqOpts.url, |
| 4222 |
startTime: startTime, |
| 4223 |
endTime: endTime, |
| 4224 |
duration: endTime - startTime |
| 4225 |
}); |
| 4226 |
|
| 4227 |
if (!(err instanceof errors.AlgoliaSearchError)) { |
| 4228 |
err = new errors.Unknown(err && err.message, err); |
| 4229 |
} |
| 4230 |
|
| 4231 |
tries += 1; |
| 4232 |
|
| 4233 |
// stop the request implementation when: |
| 4234 |
if ( |
| 4235 |
// we did not generate this error, |
| 4236 |
// it comes from a throw in some other piece of code |
| 4237 |
err instanceof errors.Unknown || |
| 4238 |
|
| 4239 |
// server sent unparsable JSON |
| 4240 |
err instanceof errors.UnparsableJSON || |
| 4241 |
|
| 4242 |
// max tries and already using fallback or no fallback |
| 4243 |
tries >= client.hosts[initialOpts.hostType].length && |
| 4244 |
(usingFallback || !hasFallback)) { |
| 4245 |
// stop request implementation for this command |
| 4246 |
err.debugData = debugData; |
| 4247 |
return client._promise.reject(err); |
| 4248 |
} |
| 4249 |
|
| 4250 |
// When a timeout occured, retry by raising timeout |
| 4251 |
if (err instanceof errors.RequestTimeout) { |
| 4252 |
return retryRequestWithHigherTimeout(); |
| 4253 |
} |
| 4254 |
|
| 4255 |
return retryRequest(); |
| 4256 |
} |
| 4257 |
|
| 4258 |
function retryRequest() { |
| 4259 |
requestDebug('retrying request'); |
| 4260 |
client._incrementHostIndex(initialOpts.hostType); |
| 4261 |
return doRequest(requester, reqOpts); |
| 4262 |
} |
| 4263 |
|
| 4264 |
function retryRequestWithHigherTimeout() { |
| 4265 |
requestDebug('retrying request with higher timeout'); |
| 4266 |
client._incrementHostIndex(initialOpts.hostType); |
| 4267 |
client._incrementTimeoutMultipler(); |
| 4268 |
reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType); |
| 4269 |
return doRequest(requester, reqOpts); |
| 4270 |
} |
| 4271 |
} |
| 4272 |
|
| 4273 |
function isCacheValidWithCurrentID( |
| 4274 |
useRequestCache, |
| 4275 |
currentCache, |
| 4276 |
currentCacheID |
| 4277 |
) { |
| 4278 |
return ( |
| 4279 |
client._useCache && |
| 4280 |
useRequestCache && |
| 4281 |
currentCache && |
| 4282 |
currentCache[currentCacheID] !== undefined |
| 4283 |
); |
| 4284 |
} |
| 4285 |
|
| 4286 |
|
| 4287 |
function interopCallbackReturn(request, callback) { |
| 4288 |
if (isCacheValidWithCurrentID(client._useRequestCache, cache, cacheID)) { |
| 4289 |
request.catch(function() { |
| 4290 |
// Release the cache on error |
| 4291 |
delete cache[cacheID]; |
| 4292 |
}); |
| 4293 |
} |
| 4294 |
|
| 4295 |
if (typeof initialOpts.callback === 'function') { |
| 4296 |
// either we have a callback |
| 4297 |
request.then(function okCb(content) { |
| 4298 |
exitPromise(function() { |
| 4299 |
initialOpts.callback(null, callback(content)); |
| 4300 |
}, client._setTimeout || setTimeout); |
| 4301 |
}, function nookCb(err) { |
| 4302 |
exitPromise(function() { |
| 4303 |
initialOpts.callback(err); |
| 4304 |
}, client._setTimeout || setTimeout); |
| 4305 |
}); |
| 4306 |
} else { |
| 4307 |
// either we are using promises |
| 4308 |
return request.then(callback); |
| 4309 |
} |
| 4310 |
} |
| 4311 |
|
| 4312 |
if (client._useCache && client._useRequestCache) { |
| 4313 |
cacheID = initialOpts.url; |
| 4314 |
} |
| 4315 |
|
| 4316 |
// as we sometime use POST requests to pass parameters (like query='aa'), |
| 4317 |
// the cacheID must also include the body to be different between calls |
| 4318 |
if (client._useCache && client._useRequestCache && body) { |
| 4319 |
cacheID += '_body_' + body; |
| 4320 |
} |
| 4321 |
|
| 4322 |
if (isCacheValidWithCurrentID(client._useRequestCache, cache, cacheID)) { |
| 4323 |
requestDebug('serving request from cache'); |
| 4324 |
|
| 4325 |
var maybePromiseForCache = cache[cacheID]; |
| 4326 |
|
| 4327 |
// In case the cache is warmup with value that is not a promise |
| 4328 |
var promiseForCache = typeof maybePromiseForCache.then !== 'function' |
| 4329 |
? client._promise.resolve({responseText: maybePromiseForCache}) |
| 4330 |
: maybePromiseForCache; |
| 4331 |
|
| 4332 |
return interopCallbackReturn(promiseForCache, function(content) { |
| 4333 |
// In case of the cache request, return the original value |
| 4334 |
return JSON.parse(content.responseText); |
| 4335 |
}); |
| 4336 |
} |
| 4337 |
|
| 4338 |
var request = doRequest( |
| 4339 |
client._request, { |
| 4340 |
url: initialOpts.url, |
| 4341 |
method: initialOpts.method, |
| 4342 |
body: body, |
| 4343 |
jsonBody: initialOpts.body, |
| 4344 |
timeouts: client._getTimeoutsForRequest(initialOpts.hostType), |
| 4345 |
forceAuthHeaders: initialOpts.forceAuthHeaders |
| 4346 |
} |
| 4347 |
); |
| 4348 |
|
| 4349 |
if (client._useCache && client._useRequestCache && cache) { |
| 4350 |
cache[cacheID] = request; |
| 4351 |
} |
| 4352 |
|
| 4353 |
return interopCallbackReturn(request, function(content) { |
| 4354 |
// In case of the first request, return the JSON value |
| 4355 |
return content.body; |
| 4356 |
}); |
| 4357 |
}; |
| 4358 |
|
| 4359 |
/* |
| 4360 |
* Transform search param object in query string |
| 4361 |
* @param {object} args arguments to add to the current query string |
| 4362 |
* @param {string} params current query string |
| 4363 |
* @return {string} the final query string |
| 4364 |
*/ |
| 4365 |
AlgoliaSearchCore.prototype._getSearchParams = function(args, params) { |
| 4366 |
if (args === undefined || args === null) { |
| 4367 |
return params; |
| 4368 |
} |
| 4369 |
for (var key in args) { |
| 4370 |
if (key !== null && args[key] !== undefined && args.hasOwnProperty(key)) { |
| 4371 |
params += params === '' ? '' : '&'; |
| 4372 |
params += key + '=' + encodeURIComponent(Object.prototype.toString.call(args[key]) === '[object Array]' ? safeJSONStringify(args[key]) : args[key]); |
| 4373 |
} |
| 4374 |
} |
| 4375 |
return params; |
| 4376 |
}; |
| 4377 |
|
| 4378 |
/** |
| 4379 |
* Compute the headers for a request |
| 4380 |
* |
| 4381 |
* @param [string] options.additionalUA semi-colon separated string with other user agents to add |
| 4382 |
* @param [boolean=true] options.withApiKey Send the api key as a header |
| 4383 |
* @param [Object] options.headers Extra headers to send |
| 4384 |
*/ |
| 4385 |
AlgoliaSearchCore.prototype._computeRequestHeaders = function(options) { |
| 4386 |
var forEach = __webpack_require__(2); |
| 4387 |
|
| 4388 |
var ua = options.additionalUA ? |
| 4389 |
this._ua + ';' + options.additionalUA : |
| 4390 |
this._ua; |
| 4391 |
|
| 4392 |
var requestHeaders = { |
| 4393 |
'x-algolia-agent': ua, |
| 4394 |
'x-algolia-application-id': this.applicationID |
| 4395 |
}; |
| 4396 |
|
| 4397 |
// browser will inline headers in the url, node.js will use http headers |
| 4398 |
// but in some situations, the API KEY will be too long (big secured API keys) |
| 4399 |
// so if the request is a POST and the KEY is very long, we will be asked to not put |
| 4400 |
// it into headers but in the JSON body |
| 4401 |
if (options.withApiKey !== false) { |
| 4402 |
requestHeaders['x-algolia-api-key'] = this.apiKey; |
| 4403 |
} |
| 4404 |
|
| 4405 |
if (this.userToken) { |
| 4406 |
requestHeaders['x-algolia-usertoken'] = this.userToken; |
| 4407 |
} |
| 4408 |
|
| 4409 |
if (this.securityTags) { |
| 4410 |
requestHeaders['x-algolia-tagfilters'] = this.securityTags; |
| 4411 |
} |
| 4412 |
|
| 4413 |
forEach(this.extraHeaders, function addToRequestHeaders(value, key) { |
| 4414 |
requestHeaders[key] = value; |
| 4415 |
}); |
| 4416 |
|
| 4417 |
if (options.headers) { |
| 4418 |
forEach(options.headers, function addToRequestHeaders(value, key) { |
| 4419 |
requestHeaders[key] = value; |
| 4420 |
}); |
| 4421 |
} |
| 4422 |
|
| 4423 |
return requestHeaders; |
| 4424 |
}; |
| 4425 |
|
| 4426 |
/** |
| 4427 |
* Search through multiple indices at the same time |
| 4428 |
* @param {Object[]} queries An array of queries you want to run. |
| 4429 |
* @param {string} queries[].indexName The index name you want to target |
| 4430 |
* @param {string} [queries[].query] The query to issue on this index. Can also be passed into `params` |
| 4431 |
* @param {Object} queries[].params Any search param like hitsPerPage, .. |
| 4432 |
* @param {Function} callback Callback to be called |
| 4433 |
* @return {Promise|undefined} Returns a promise if no callback given |
| 4434 |
*/ |
| 4435 |
AlgoliaSearchCore.prototype.search = function(queries, opts, callback) { |
| 4436 |
var isArray = __webpack_require__(6); |
| 4437 |
var map = __webpack_require__(7); |
| 4438 |
|
| 4439 |
var usage = 'Usage: client.search(arrayOfQueries[, callback])'; |
| 4440 |
|
| 4441 |
if (!isArray(queries)) { |
| 4442 |
throw new Error(usage); |
| 4443 |
} |
| 4444 |
|
| 4445 |
if (typeof opts === 'function') { |
| 4446 |
callback = opts; |
| 4447 |
opts = {}; |
| 4448 |
} else if (opts === undefined) { |
| 4449 |
opts = {}; |
| 4450 |
} |
| 4451 |
|
| 4452 |
var client = this; |
| 4453 |
|
| 4454 |
var postObj = { |
| 4455 |
requests: map(queries, function prepareRequest(query) { |
| 4456 |
var params = ''; |
| 4457 |
|
| 4458 |
// allow query.query |
| 4459 |
// so we are mimicing the index.search(query, params) method |
| 4460 |
// {indexName:, query:, params:} |
| 4461 |
if (query.query !== undefined) { |
| 4462 |
params += 'query=' + encodeURIComponent(query.query); |
| 4463 |
} |
| 4464 |
|
| 4465 |
return { |
| 4466 |
indexName: query.indexName, |
| 4467 |
params: client._getSearchParams(query.params, params) |
| 4468 |
}; |
| 4469 |
}) |
| 4470 |
}; |
| 4471 |
|
| 4472 |
var JSONPParams = map(postObj.requests, function prepareJSONPParams(request, requestId) { |
| 4473 |
return requestId + '=' + |
| 4474 |
encodeURIComponent( |
| 4475 |
'/1/indexes/' + encodeURIComponent(request.indexName) + '?' + |
| 4476 |
request.params |
| 4477 |
); |
| 4478 |
}).join('&'); |
| 4479 |
|
| 4480 |
var url = '/1/indexes/*/queries'; |
| 4481 |
|
| 4482 |
if (opts.strategy !== undefined) { |
| 4483 |
postObj.strategy = opts.strategy; |
| 4484 |
} |
| 4485 |
|
| 4486 |
return this._jsonRequest({ |
| 4487 |
cache: this.cache, |
| 4488 |
method: 'POST', |
| 4489 |
url: url, |
| 4490 |
body: postObj, |
| 4491 |
hostType: 'read', |
| 4492 |
fallback: { |
| 4493 |
method: 'GET', |
| 4494 |
url: '/1/indexes/*', |
| 4495 |
body: { |
| 4496 |
params: JSONPParams |
| 4497 |
} |
| 4498 |
}, |
| 4499 |
callback: callback |
| 4500 |
}); |
| 4501 |
}; |
| 4502 |
|
| 4503 |
/** |
| 4504 |
* Search for facet values |
| 4505 |
* https://www.algolia.com/doc/rest-api/search#search-for-facet-values |
| 4506 |
* This is the top-level API for SFFV. |
| 4507 |
* |
| 4508 |
* @param {object[]} queries An array of queries to run. |
| 4509 |
* @param {string} queries[].indexName Index name, name of the index to search. |
| 4510 |
* @param {object} queries[].params Query parameters. |
| 4511 |
* @param {string} queries[].params.facetName Facet name, name of the attribute to search for values in. |
| 4512 |
* Must be declared as a facet |
| 4513 |
* @param {string} queries[].params.facetQuery Query for the facet search |
| 4514 |
* @param {string} [queries[].params.*] Any search parameter of Algolia, |
| 4515 |
* see https://www.algolia.com/doc/api-client/javascript/search#search-parameters |
| 4516 |
* Pagination is not supported. The page and hitsPerPage parameters will be ignored. |
| 4517 |
*/ |
| 4518 |
AlgoliaSearchCore.prototype.searchForFacetValues = function(queries) { |
| 4519 |
var isArray = __webpack_require__(6); |
| 4520 |
var map = __webpack_require__(7); |
| 4521 |
|
| 4522 |
var usage = 'Usage: client.searchForFacetValues([{indexName, params: {facetName, facetQuery, ...params}}, ...queries])'; // eslint-disable-line max-len |
| 4523 |
|
| 4524 |
if (!isArray(queries)) { |
| 4525 |
throw new Error(usage); |
| 4526 |
} |
| 4527 |
|
| 4528 |
var client = this; |
| 4529 |
|
| 4530 |
return client._promise.all(map(queries, function performQuery(query) { |
| 4531 |
if ( |
| 4532 |
!query || |
| 4533 |
query.indexName === undefined || |
| 4534 |
query.params.facetName === undefined || |
| 4535 |
query.params.facetQuery === undefined |
| 4536 |
) { |
| 4537 |
throw new Error(usage); |
| 4538 |
} |
| 4539 |
|
| 4540 |
var clone = __webpack_require__(3); |
| 4541 |
var omit = __webpack_require__(14); |
| 4542 |
|
| 4543 |
var indexName = query.indexName; |
| 4544 |
var params = query.params; |
| 4545 |
|
| 4546 |
var facetName = params.facetName; |
| 4547 |
var filteredParams = omit(clone(params), function(keyName) { |
| 4548 |
return keyName === 'facetName'; |
| 4549 |
}); |
| 4550 |
var searchParameters = client._getSearchParams(filteredParams, ''); |
| 4551 |
|
| 4552 |
return client._jsonRequest({ |
| 4553 |
cache: client.cache, |
| 4554 |
method: 'POST', |
| 4555 |
url: |
| 4556 |
'/1/indexes/' + |
| 4557 |
encodeURIComponent(indexName) + |
| 4558 |
'/facets/' + |
| 4559 |
encodeURIComponent(facetName) + |
| 4560 |
'/query', |
| 4561 |
hostType: 'read', |
| 4562 |
body: {params: searchParameters} |
| 4563 |
}); |
| 4564 |
})); |
| 4565 |
}; |
| 4566 |
|
| 4567 |
/** |
| 4568 |
* Set the extra security tagFilters header |
| 4569 |
* @param {string|array} tags The list of tags defining the current security filters |
| 4570 |
*/ |
| 4571 |
AlgoliaSearchCore.prototype.setSecurityTags = function(tags) { |
| 4572 |
if (Object.prototype.toString.call(tags) === '[object Array]') { |
| 4573 |
var strTags = []; |
| 4574 |
for (var i = 0; i < tags.length; ++i) { |
| 4575 |
if (Object.prototype.toString.call(tags[i]) === '[object Array]') { |
| 4576 |
var oredTags = []; |
| 4577 |
for (var j = 0; j < tags[i].length; ++j) { |
| 4578 |
oredTags.push(tags[i][j]); |
| 4579 |
} |
| 4580 |
strTags.push('(' + oredTags.join(',') + ')'); |
| 4581 |
} else { |
| 4582 |
strTags.push(tags[i]); |
| 4583 |
} |
| 4584 |
} |
| 4585 |
tags = strTags.join(','); |
| 4586 |
} |
| 4587 |
|
| 4588 |
this.securityTags = tags; |
| 4589 |
}; |
| 4590 |
|
| 4591 |
/** |
| 4592 |
* Set the extra user token header |
| 4593 |
* @param {string} userToken The token identifying a uniq user (used to apply rate limits) |
| 4594 |
*/ |
| 4595 |
AlgoliaSearchCore.prototype.setUserToken = function(userToken) { |
| 4596 |
this.userToken = userToken; |
| 4597 |
}; |
| 4598 |
|
| 4599 |
/** |
| 4600 |
* Clear all queries in client's cache |
| 4601 |
* @return undefined |
| 4602 |
*/ |
| 4603 |
AlgoliaSearchCore.prototype.clearCache = function() { |
| 4604 |
this.cache = {}; |
| 4605 |
}; |
| 4606 |
|
| 4607 |
/** |
| 4608 |
* Set the number of milliseconds a request can take before automatically being terminated. |
| 4609 |
* @deprecated |
| 4610 |
* @param {Number} milliseconds |
| 4611 |
*/ |
| 4612 |
AlgoliaSearchCore.prototype.setRequestTimeout = function(milliseconds) { |
| 4613 |
if (milliseconds) { |
| 4614 |
this._timeouts.connect = this._timeouts.read = this._timeouts.write = milliseconds; |
| 4615 |
} |
| 4616 |
}; |
| 4617 |
|
| 4618 |
/** |
| 4619 |
* Set the three different (connect, read, write) timeouts to be used when requesting |
| 4620 |
* @param {Object} timeouts |
| 4621 |
*/ |
| 4622 |
AlgoliaSearchCore.prototype.setTimeouts = function(timeouts) { |
| 4623 |
this._timeouts = timeouts; |
| 4624 |
}; |
| 4625 |
|
| 4626 |
/** |
| 4627 |
* Get the three different (connect, read, write) timeouts to be used when requesting |
| 4628 |
* @param {Object} timeouts |
| 4629 |
*/ |
| 4630 |
AlgoliaSearchCore.prototype.getTimeouts = function() { |
| 4631 |
return this._timeouts; |
| 4632 |
}; |
| 4633 |
|
| 4634 |
AlgoliaSearchCore.prototype._getAppIdData = function() { |
| 4635 |
var data = store.get(this.applicationID); |
| 4636 |
if (data !== null) this._cacheAppIdData(data); |
| 4637 |
return data; |
| 4638 |
}; |
| 4639 |
|
| 4640 |
AlgoliaSearchCore.prototype._setAppIdData = function(data) { |
| 4641 |
data.lastChange = (new Date()).getTime(); |
| 4642 |
this._cacheAppIdData(data); |
| 4643 |
return store.set(this.applicationID, data); |
| 4644 |
}; |
| 4645 |
|
| 4646 |
AlgoliaSearchCore.prototype._checkAppIdData = function() { |
| 4647 |
var data = this._getAppIdData(); |
| 4648 |
var now = (new Date()).getTime(); |
| 4649 |
if (data === null || now - data.lastChange > RESET_APP_DATA_TIMER) { |
| 4650 |
return this._resetInitialAppIdData(data); |
| 4651 |
} |
| 4652 |
|
| 4653 |
return data; |
| 4654 |
}; |
| 4655 |
|
| 4656 |
AlgoliaSearchCore.prototype._resetInitialAppIdData = function(data) { |
| 4657 |
var newData = data || {}; |
| 4658 |
newData.hostIndexes = {read: 0, write: 0}; |
| 4659 |
newData.timeoutMultiplier = 1; |
| 4660 |
newData.shuffleResult = newData.shuffleResult || shuffle([1, 2, 3]); |
| 4661 |
return this._setAppIdData(newData); |
| 4662 |
}; |
| 4663 |
|
| 4664 |
AlgoliaSearchCore.prototype._cacheAppIdData = function(data) { |
| 4665 |
this._hostIndexes = data.hostIndexes; |
| 4666 |
this._timeoutMultiplier = data.timeoutMultiplier; |
| 4667 |
this._shuffleResult = data.shuffleResult; |
| 4668 |
}; |
| 4669 |
|
| 4670 |
AlgoliaSearchCore.prototype._partialAppIdDataUpdate = function(newData) { |
| 4671 |
var foreach = __webpack_require__(2); |
| 4672 |
var currentData = this._getAppIdData(); |
| 4673 |
foreach(newData, function(value, key) { |
| 4674 |
currentData[key] = value; |
| 4675 |
}); |
| 4676 |
|
| 4677 |
return this._setAppIdData(currentData); |
| 4678 |
}; |
| 4679 |
|
| 4680 |
AlgoliaSearchCore.prototype._getHostByType = function(hostType) { |
| 4681 |
return this.hosts[hostType][this._getHostIndexByType(hostType)]; |
| 4682 |
}; |
| 4683 |
|
| 4684 |
AlgoliaSearchCore.prototype._getTimeoutMultiplier = function() { |
| 4685 |
return this._timeoutMultiplier; |
| 4686 |
}; |
| 4687 |
|
| 4688 |
AlgoliaSearchCore.prototype._getHostIndexByType = function(hostType) { |
| 4689 |
return this._hostIndexes[hostType]; |
| 4690 |
}; |
| 4691 |
|
| 4692 |
AlgoliaSearchCore.prototype._setHostIndexByType = function(hostIndex, hostType) { |
| 4693 |
var clone = __webpack_require__(3); |
| 4694 |
var newHostIndexes = clone(this._hostIndexes); |
| 4695 |
newHostIndexes[hostType] = hostIndex; |
| 4696 |
this._partialAppIdDataUpdate({hostIndexes: newHostIndexes}); |
| 4697 |
return hostIndex; |
| 4698 |
}; |
| 4699 |
|
| 4700 |
AlgoliaSearchCore.prototype._incrementHostIndex = function(hostType) { |
| 4701 |
return this._setHostIndexByType( |
| 4702 |
(this._getHostIndexByType(hostType) + 1) % this.hosts[hostType].length, hostType |
| 4703 |
); |
| 4704 |
}; |
| 4705 |
|
| 4706 |
AlgoliaSearchCore.prototype._incrementTimeoutMultipler = function() { |
| 4707 |
var timeoutMultiplier = Math.max(this._timeoutMultiplier + 1, 4); |
| 4708 |
return this._partialAppIdDataUpdate({timeoutMultiplier: timeoutMultiplier}); |
| 4709 |
}; |
| 4710 |
|
| 4711 |
AlgoliaSearchCore.prototype._getTimeoutsForRequest = function(hostType) { |
| 4712 |
return { |
| 4713 |
connect: this._timeouts.connect * this._timeoutMultiplier, |
| 4714 |
complete: this._timeouts[hostType] * this._timeoutMultiplier |
| 4715 |
}; |
| 4716 |
}; |
| 4717 |
|
| 4718 |
function prepareHost(protocol) { |
| 4719 |
return function prepare(host) { |
| 4720 |
return protocol + '//' + host.toLowerCase(); |
| 4721 |
}; |
| 4722 |
} |
| 4723 |
|
| 4724 |
// Prototype.js < 1.7, a widely used library, defines a weird |
| 4725 |
// Array.prototype.toJSON function that will fail to stringify our content |
| 4726 |
// appropriately |
| 4727 |
// refs: |
| 4728 |
// - https://groups.google.com/forum/#!topic/prototype-core/E-SAVvV_V9Q |
| 4729 |
// - https://github.com/sstephenson/prototype/commit/038a2985a70593c1a86c230fadbdfe2e4898a48c |
| 4730 |
// - http://stackoverflow.com/a/3148441/147079 |
| 4731 |
function safeJSONStringify(obj) { |
| 4732 |
/* eslint no-extend-native:0 */ |
| 4733 |
|
| 4734 |
if (Array.prototype.toJSON === undefined) { |
| 4735 |
return JSON.stringify(obj); |
| 4736 |
} |
| 4737 |
|
| 4738 |
var toJSON = Array.prototype.toJSON; |
| 4739 |
delete Array.prototype.toJSON; |
| 4740 |
var out = JSON.stringify(obj); |
| 4741 |
Array.prototype.toJSON = toJSON; |
| 4742 |
|
| 4743 |
return out; |
| 4744 |
} |
| 4745 |
|
| 4746 |
function shuffle(array) { |
| 4747 |
var currentIndex = array.length; |
| 4748 |
var temporaryValue; |
| 4749 |
var randomIndex; |
| 4750 |
|
| 4751 |
// While there remain elements to shuffle... |
| 4752 |
while (currentIndex !== 0) { |
| 4753 |
// Pick a remaining element... |
| 4754 |
randomIndex = Math.floor(Math.random() * currentIndex); |
| 4755 |
currentIndex -= 1; |
| 4756 |
|
| 4757 |
// And swap it with the current element. |
| 4758 |
temporaryValue = array[currentIndex]; |
| 4759 |
array[currentIndex] = array[randomIndex]; |
| 4760 |
array[randomIndex] = temporaryValue; |
| 4761 |
} |
| 4762 |
|
| 4763 |
return array; |
| 4764 |
} |
| 4765 |
|
| 4766 |
function removeCredentials(headers) { |
| 4767 |
var newHeaders = {}; |
| 4768 |
|
| 4769 |
for (var headerName in headers) { |
| 4770 |
if (Object.prototype.hasOwnProperty.call(headers, headerName)) { |
| 4771 |
var value; |
| 4772 |
|
| 4773 |
if (headerName === 'x-algolia-api-key' || headerName === 'x-algolia-application-id') { |
| 4774 |
value = '**hidden for security purposes**'; |
| 4775 |
} else { |
| 4776 |
value = headers[headerName]; |
| 4777 |
} |
| 4778 |
|
| 4779 |
newHeaders[headerName] = value; |
| 4780 |
} |
| 4781 |
} |
| 4782 |
|
| 4783 |
return newHeaders; |
| 4784 |
} |
| 4785 |
|
| 4786 |
|
| 4787 |
/***/ }), |
| 4788 |
/* 31 */ |
| 4789 |
/***/ (function(module, exports) { |
| 4790 |
|
| 4791 |
// Parse cloud does not supports setTimeout |
| 4792 |
// We do not store a setTimeout reference in the client everytime |
| 4793 |
// We only fallback to a fake setTimeout when not available |
| 4794 |
// setTimeout cannot be override globally sadly |
| 4795 |
module.exports = function exitPromise(fn, _setTimeout) { |
| 4796 |
_setTimeout(fn, 0); |
| 4797 |
}; |
| 4798 |
|
| 4799 |
|
| 4800 |
/***/ }), |
| 4801 |
/* 32 */ |
| 4802 |
/***/ (function(module, exports, __webpack_require__) { |
| 4803 |
|
| 4804 |
var buildSearchMethod = __webpack_require__(13); |
| 4805 |
var deprecate = __webpack_require__(33); |
| 4806 |
var deprecatedMessage = __webpack_require__(34); |
| 4807 |
|
| 4808 |
module.exports = IndexCore; |
| 4809 |
|
| 4810 |
/* |
| 4811 |
* Index class constructor. |
| 4812 |
* You should not use this method directly but use initIndex() function |
| 4813 |
*/ |
| 4814 |
function IndexCore(algoliasearch, indexName) { |
| 4815 |
this.indexName = indexName; |
| 4816 |
this.as = algoliasearch; |
| 4817 |
this.typeAheadArgs = null; |
| 4818 |
this.typeAheadValueOption = null; |
| 4819 |
|
| 4820 |
// make sure every index instance has it's own cache |
| 4821 |
this.cache = {}; |
| 4822 |
} |
| 4823 |
|
| 4824 |
/* |
| 4825 |
* Clear all queries in cache |
| 4826 |
*/ |
| 4827 |
IndexCore.prototype.clearCache = function() { |
| 4828 |
this.cache = {}; |
| 4829 |
}; |
| 4830 |
|
| 4831 |
/* |
| 4832 |
* Search inside the index using XMLHttpRequest request (Using a POST query to |
| 4833 |
* minimize number of OPTIONS queries: Cross-Origin Resource Sharing). |
| 4834 |
* |
| 4835 |
* @param {string} [query] the full text query |
| 4836 |
* @param {object} [args] (optional) if set, contains an object with query parameters: |
| 4837 |
* - page: (integer) Pagination parameter used to select the page to retrieve. |
| 4838 |
* Page is zero-based and defaults to 0. Thus, |
| 4839 |
* to retrieve the 10th page you need to set page=9 |
| 4840 |
* - hitsPerPage: (integer) Pagination parameter used to select the number of hits per page. Defaults to 20. |
| 4841 |
* - attributesToRetrieve: a string that contains the list of object attributes |
| 4842 |
* you want to retrieve (let you minimize the answer size). |
| 4843 |
* Attributes are separated with a comma (for example "name,address"). |
| 4844 |
* You can also use an array (for example ["name","address"]). |
| 4845 |
* By default, all attributes are retrieved. You can also use '*' to retrieve all |
| 4846 |
* values when an attributesToRetrieve setting is specified for your index. |
| 4847 |
* - attributesToHighlight: a string that contains the list of attributes you |
| 4848 |
* want to highlight according to the query. |
| 4849 |
* Attributes are separated by a comma. You can also use an array (for example ["name","address"]). |
| 4850 |
* If an attribute has no match for the query, the raw value is returned. |
| 4851 |
* By default all indexed text attributes are highlighted. |
| 4852 |
* You can use `*` if you want to highlight all textual attributes. |
| 4853 |
* Numerical attributes are not highlighted. |
| 4854 |
* A matchLevel is returned for each highlighted attribute and can contain: |
| 4855 |
* - full: if all the query terms were found in the attribute, |
| 4856 |
* - partial: if only some of the query terms were found, |
| 4857 |
* - none: if none of the query terms were found. |
| 4858 |
* - attributesToSnippet: a string that contains the list of attributes to snippet alongside |
| 4859 |
* the number of words to return (syntax is `attributeName:nbWords`). |
| 4860 |
* Attributes are separated by a comma (Example: attributesToSnippet=name:10,content:10). |
| 4861 |
* You can also use an array (Example: attributesToSnippet: ['name:10','content:10']). |
| 4862 |
* By default no snippet is computed. |
| 4863 |
* - minWordSizefor1Typo: the minimum number of characters in a query word to accept one typo in this word. |
| 4864 |
* Defaults to 3. |
| 4865 |
* - minWordSizefor2Typos: the minimum number of characters in a query word |
| 4866 |
* to accept two typos in this word. Defaults to 7. |
| 4867 |
* - getRankingInfo: if set to 1, the result hits will contain ranking |
| 4868 |
* information in _rankingInfo attribute. |
| 4869 |
* - aroundLatLng: search for entries around a given |
| 4870 |
* latitude/longitude (specified as two floats separated by a comma). |
| 4871 |
* For example aroundLatLng=47.316669,5.016670). |
| 4872 |
* You can specify the maximum distance in meters with the aroundRadius parameter (in meters) |
| 4873 |
* and the precision for ranking with aroundPrecision |
| 4874 |
* (for example if you set aroundPrecision=100, two objects that are distant of |
| 4875 |
* less than 100m will be considered as identical for "geo" ranking parameter). |
| 4876 |
* At indexing, you should specify geoloc of an object with the _geoloc attribute |
| 4877 |
* (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}}) |
| 4878 |
* - insideBoundingBox: search entries inside a given area defined by the two extreme points |
| 4879 |
* of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat,p2Lng). |
| 4880 |
* For example insideBoundingBox=47.3165,4.9665,47.3424,5.0201). |
| 4881 |
* At indexing, you should specify geoloc of an object with the _geoloc attribute |
| 4882 |
* (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}}) |
| 4883 |
* - numericFilters: a string that contains the list of numeric filters you want to |
| 4884 |
* apply separated by a comma. |
| 4885 |
* The syntax of one filter is `attributeName` followed by `operand` followed by `value`. |
| 4886 |
* Supported operands are `<`, `<=`, `=`, `>` and `>=`. |
| 4887 |
* You can have multiple conditions on one attribute like for example numericFilters=price>100,price<1000. |
| 4888 |
* You can also use an array (for example numericFilters: ["price>100","price<1000"]). |
| 4889 |
* - tagFilters: filter the query by a set of tags. You can AND tags by separating them by commas. |
| 4890 |
* To OR tags, you must add parentheses. For example, tags=tag1,(tag2,tag3) means tag1 AND (tag2 OR tag3). |
| 4891 |
* You can also use an array, for example tagFilters: ["tag1",["tag2","tag3"]] |
| 4892 |
* means tag1 AND (tag2 OR tag3). |
| 4893 |
* At indexing, tags should be added in the _tags** attribute |
| 4894 |
* of objects (for example {"_tags":["tag1","tag2"]}). |
| 4895 |
* - facetFilters: filter the query by a list of facets. |
| 4896 |
* Facets are separated by commas and each facet is encoded as `attributeName:value`. |
| 4897 |
* For example: `facetFilters=category:Book,author:John%20Doe`. |
| 4898 |
* You can also use an array (for example `["category:Book","author:John%20Doe"]`). |
| 4899 |
* - facets: List of object attributes that you want to use for faceting. |
| 4900 |
* Comma separated list: `"category,author"` or array `['category','author']` |
| 4901 |
* Only attributes that have been added in **attributesForFaceting** index setting |
| 4902 |
* can be used in this parameter. |
| 4903 |
* You can also use `*` to perform faceting on all attributes specified in **attributesForFaceting**. |
| 4904 |
* - queryType: select how the query words are interpreted, it can be one of the following value: |
| 4905 |
* - prefixAll: all query words are interpreted as prefixes, |
| 4906 |
* - prefixLast: only the last word is interpreted as a prefix (default behavior), |
| 4907 |
* - prefixNone: no query word is interpreted as a prefix. This option is not recommended. |
| 4908 |
* - optionalWords: a string that contains the list of words that should |
| 4909 |
* be considered as optional when found in the query. |
| 4910 |
* Comma separated and array are accepted. |
| 4911 |
* - distinct: If set to 1, enable the distinct feature (disabled by default) |
| 4912 |
* if the attributeForDistinct index setting is set. |
| 4913 |
* This feature is similar to the SQL "distinct" keyword: when enabled |
| 4914 |
* in a query with the distinct=1 parameter, |
| 4915 |
* all hits containing a duplicate value for the attributeForDistinct attribute are removed from results. |
| 4916 |
* For example, if the chosen attribute is show_name and several hits have |
| 4917 |
* the same value for show_name, then only the best |
| 4918 |
* one is kept and others are removed. |
| 4919 |
* - restrictSearchableAttributes: List of attributes you want to use for |
| 4920 |
* textual search (must be a subset of the attributesToIndex index setting) |
| 4921 |
* either comma separated or as an array |
| 4922 |
* @param {function} [callback] the result callback called with two arguments: |
| 4923 |
* error: null or Error('message'). If false, the content contains the error. |
| 4924 |
* content: the server answer that contains the list of results. |
| 4925 |
*/ |
| 4926 |
IndexCore.prototype.search = buildSearchMethod('query'); |
| 4927 |
|
| 4928 |
/* |
| 4929 |
* -- BETA -- |
| 4930 |
* Search a record similar to the query inside the index using XMLHttpRequest request (Using a POST query to |
| 4931 |
* minimize number of OPTIONS queries: Cross-Origin Resource Sharing). |
| 4932 |
* |
| 4933 |
* @param {string} [query] the similar query |
| 4934 |
* @param {object} [args] (optional) if set, contains an object with query parameters. |
| 4935 |
* All search parameters are supported (see search function), restrictSearchableAttributes and facetFilters |
| 4936 |
* are the two most useful to restrict the similar results and get more relevant content |
| 4937 |
*/ |
| 4938 |
IndexCore.prototype.similarSearch = buildSearchMethod('similarQuery'); |
| 4939 |
|
| 4940 |
/* |
| 4941 |
* Browse index content. The response content will have a `cursor` property that you can use |
| 4942 |
* to browse subsequent pages for this query. Use `index.browseFrom(cursor)` when you want. |
| 4943 |
* |
| 4944 |
* @param {string} query - The full text query |
| 4945 |
* @param {Object} [queryParameters] - Any search query parameter |
| 4946 |
* @param {Function} [callback] - The result callback called with two arguments |
| 4947 |
* error: null or Error('message') |
| 4948 |
* content: the server answer with the browse result |
| 4949 |
* @return {Promise|undefined} Returns a promise if no callback given |
| 4950 |
* @example |
| 4951 |
* index.browse('cool songs', { |
| 4952 |
* tagFilters: 'public,comments', |
| 4953 |
* hitsPerPage: 500 |
| 4954 |
* }, callback); |
| 4955 |
* @see {@link https://www.algolia.com/doc/rest_api#Browse|Algolia REST API Documentation} |
| 4956 |
*/ |
| 4957 |
IndexCore.prototype.browse = function(query, queryParameters, callback) { |
| 4958 |
var merge = __webpack_require__(35); |
| 4959 |
|
| 4960 |
var indexObj = this; |
| 4961 |
|
| 4962 |
var page; |
| 4963 |
var hitsPerPage; |
| 4964 |
|
| 4965 |
// we check variadic calls that are not the one defined |
| 4966 |
// .browse()/.browse(fn) |
| 4967 |
// => page = 0 |
| 4968 |
if (arguments.length === 0 || arguments.length === 1 && typeof arguments[0] === 'function') { |
| 4969 |
page = 0; |
| 4970 |
callback = arguments[0]; |
| 4971 |
query = undefined; |
| 4972 |
} else if (typeof arguments[0] === 'number') { |
| 4973 |
// .browse(2)/.browse(2, 10)/.browse(2, fn)/.browse(2, 10, fn) |
| 4974 |
page = arguments[0]; |
| 4975 |
if (typeof arguments[1] === 'number') { |
| 4976 |
hitsPerPage = arguments[1]; |
| 4977 |
} else if (typeof arguments[1] === 'function') { |
| 4978 |
callback = arguments[1]; |
| 4979 |
hitsPerPage = undefined; |
| 4980 |
} |
| 4981 |
query = undefined; |
| 4982 |
queryParameters = undefined; |
| 4983 |
} else if (typeof arguments[0] === 'object') { |
| 4984 |
// .browse(queryParameters)/.browse(queryParameters, cb) |
| 4985 |
if (typeof arguments[1] === 'function') { |
| 4986 |
callback = arguments[1]; |
| 4987 |
} |
| 4988 |
queryParameters = arguments[0]; |
| 4989 |
query = undefined; |
| 4990 |
} else if (typeof arguments[0] === 'string' && typeof arguments[1] === 'function') { |
| 4991 |
// .browse(query, cb) |
| 4992 |
callback = arguments[1]; |
| 4993 |
queryParameters = undefined; |
| 4994 |
} |
| 4995 |
|
| 4996 |
// otherwise it's a .browse(query)/.browse(query, queryParameters)/.browse(query, queryParameters, cb) |
| 4997 |
|
| 4998 |
// get search query parameters combining various possible calls |
| 4999 |
// to .browse(); |
| 5000 |
queryParameters = merge({}, queryParameters || {}, { |
| 5001 |
page: page, |
| 5002 |
hitsPerPage: hitsPerPage, |
| 5003 |
query: query |
| 5004 |
}); |
| 5005 |
|
| 5006 |
var params = this.as._getSearchParams(queryParameters, ''); |
| 5007 |
|
| 5008 |
return this.as._jsonRequest({ |
| 5009 |
method: 'POST', |
| 5010 |
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/browse', |
| 5011 |
body: {params: params}, |
| 5012 |
hostType: 'read', |
| 5013 |
callback: callback |
| 5014 |
}); |
| 5015 |
}; |
| 5016 |
|
| 5017 |
/* |
| 5018 |
* Continue browsing from a previous position (cursor), obtained via a call to `.browse()`. |
| 5019 |
* |
| 5020 |
* @param {string} query - The full text query |
| 5021 |
* @param {Object} [queryParameters] - Any search query parameter |
| 5022 |
* @param {Function} [callback] - The result callback called with two arguments |
| 5023 |
* error: null or Error('message') |
| 5024 |
* content: the server answer with the browse result |
| 5025 |
* @return {Promise|undefined} Returns a promise if no callback given |
| 5026 |
* @example |
| 5027 |
* index.browseFrom('14lkfsakl32', callback); |
| 5028 |
* @see {@link https://www.algolia.com/doc/rest_api#Browse|Algolia REST API Documentation} |
| 5029 |
*/ |
| 5030 |
IndexCore.prototype.browseFrom = function(cursor, callback) { |
| 5031 |
return this.as._jsonRequest({ |
| 5032 |
method: 'POST', |
| 5033 |
url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/browse', |
| 5034 |
body: {cursor: cursor}, |
| 5035 |
hostType: 'read', |
| 5036 |
callback: callback |
| 5037 |
}); |
| 5038 |
}; |
| 5039 |
|
| 5040 |
/* |
| 5041 |
* Search for facet values |
| 5042 |
* https://www.algolia.com/doc/rest-api/search#search-for-facet-values |
| 5043 |
* |
| 5044 |
* @param {string} params.facetName Facet name, name of the attribute to search for values in. |
| 5045 |
* Must be declared as a facet |
| 5046 |
* @param {string} params.facetQuery Query for the facet search |
| 5047 |
* @param {string} [params.*] Any search parameter of Algolia, |
| 5048 |
* see https://www.algolia.com/doc/api-client/javascript/search#search-parameters |
| 5049 |
* Pagination is not supported. The page and hitsPerPage parameters will be ignored. |
| 5050 |
* @param callback (optional) |
| 5051 |
*/ |
| 5052 |
IndexCore.prototype.searchForFacetValues = function(params, callback) { |
| 5053 |
var clone = __webpack_require__(3); |
| 5054 |
var omit = __webpack_require__(14); |
| 5055 |
var usage = 'Usage: index.searchForFacetValues({facetName, facetQuery, ...params}[, callback])'; |
| 5056 |
|
| 5057 |
if (params.facetName === undefined || params.facetQuery === undefined) { |
| 5058 |
throw new Error(usage); |
| 5059 |
} |
| 5060 |
|
| 5061 |
var facetName = params.facetName; |
| 5062 |
var filteredParams = omit(clone(params), function(keyName) { |
| 5063 |
return keyName === 'facetName'; |
| 5064 |
}); |
| 5065 |
var searchParameters = this.as._getSearchParams(filteredParams, ''); |
| 5066 |
|
| 5067 |
return this.as._jsonRequest({ |
| 5068 |
method: 'POST', |
| 5069 |
url: '/1/indexes/' + |
| 5070 |
encodeURIComponent(this.indexName) + '/facets/' + encodeURIComponent(facetName) + '/query', |
| 5071 |
hostType: 'read', |
| 5072 |
body: {params: searchParameters}, |
| 5073 |
callback: callback |
| 5074 |
}); |
| 5075 |
}; |
| 5076 |
|
| 5077 |
IndexCore.prototype.searchFacet = deprecate(function(params, callback) { |
| 5078 |
return this.searchForFacetValues(params, callback); |
| 5079 |
}, deprecatedMessage( |
| 5080 |
'index.searchFacet(params[, callback])', |
| 5081 |
'index.searchForFacetValues(params[, callback])' |
| 5082 |
)); |
| 5083 |
|
| 5084 |
IndexCore.prototype._search = function(params, url, callback, additionalUA) { |
| 5085 |
return this.as._jsonRequest({ |
| 5086 |
cache: this.cache, |
| 5087 |
method: 'POST', |
| 5088 |
url: url || '/1/indexes/' + encodeURIComponent(this.indexName) + '/query', |
| 5089 |
body: {params: params}, |
| 5090 |
hostType: 'read', |
| 5091 |
fallback: { |
| 5092 |
method: 'GET', |
| 5093 |
url: '/1/indexes/' + encodeURIComponent(this.indexName), |
| 5094 |
body: {params: params} |
| 5095 |
}, |
| 5096 |
callback: callback, |
| 5097 |
additionalUA: additionalUA |
| 5098 |
}); |
| 5099 |
}; |
| 5100 |
|
| 5101 |
/* |
| 5102 |
* Get an object from this index |
| 5103 |
* |
| 5104 |
* @param objectID the unique identifier of the object to retrieve |
| 5105 |
* @param attrs (optional) if set, contains the array of attribute names to retrieve |
| 5106 |
* @param callback (optional) the result callback called with two arguments |
| 5107 |
* error: null or Error('message') |
| 5108 |
* content: the object to retrieve or the error message if a failure occured |
| 5109 |
*/ |
| 5110 |
IndexCore.prototype.getObject = function(objectID, attrs, callback) { |
| 5111 |
var indexObj = this; |
| 5112 |
|
| 5113 |
if (arguments.length === 1 || typeof attrs === 'function') { |
| 5114 |
callback = attrs; |
| 5115 |
attrs = undefined; |
| 5116 |
} |
| 5117 |
|
| 5118 |
var params = ''; |
| 5119 |
if (attrs !== undefined) { |
| 5120 |
params = '?attributes='; |
| 5121 |
for (var i = 0; i < attrs.length; ++i) { |
| 5122 |
if (i !== 0) { |
| 5123 |
params += ','; |
| 5124 |
} |
| 5125 |
params += attrs[i]; |
| 5126 |
} |
| 5127 |
} |
| 5128 |
|
| 5129 |
return this.as._jsonRequest({ |
| 5130 |
method: 'GET', |
| 5131 |
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID) + params, |
| 5132 |
hostType: 'read', |
| 5133 |
callback: callback |
| 5134 |
}); |
| 5135 |
}; |
| 5136 |
|
| 5137 |
/* |
| 5138 |
* Get several objects from this index |
| 5139 |
* |
| 5140 |
* @param objectIDs the array of unique identifier of objects to retrieve |
| 5141 |
*/ |
| 5142 |
IndexCore.prototype.getObjects = function(objectIDs, attributesToRetrieve, callback) { |
| 5143 |
var isArray = __webpack_require__(6); |
| 5144 |
var map = __webpack_require__(7); |
| 5145 |
|
| 5146 |
var usage = 'Usage: index.getObjects(arrayOfObjectIDs[, callback])'; |
| 5147 |
|
| 5148 |
if (!isArray(objectIDs)) { |
| 5149 |
throw new Error(usage); |
| 5150 |
} |
| 5151 |
|
| 5152 |
var indexObj = this; |
| 5153 |
|
| 5154 |
if (arguments.length === 1 || typeof attributesToRetrieve === 'function') { |
| 5155 |
callback = attributesToRetrieve; |
| 5156 |
attributesToRetrieve = undefined; |
| 5157 |
} |
| 5158 |
|
| 5159 |
var body = { |
| 5160 |
requests: map(objectIDs, function prepareRequest(objectID) { |
| 5161 |
var request = { |
| 5162 |
indexName: indexObj.indexName, |
| 5163 |
objectID: objectID |
| 5164 |
}; |
| 5165 |
|
| 5166 |
if (attributesToRetrieve) { |
| 5167 |
request.attributesToRetrieve = attributesToRetrieve.join(','); |
| 5168 |
} |
| 5169 |
|
| 5170 |
return request; |
| 5171 |
}) |
| 5172 |
}; |
| 5173 |
|
| 5174 |
return this.as._jsonRequest({ |
| 5175 |
method: 'POST', |
| 5176 |
url: '/1/indexes/*/objects', |
| 5177 |
hostType: 'read', |
| 5178 |
body: body, |
| 5179 |
callback: callback |
| 5180 |
}); |
| 5181 |
}; |
| 5182 |
|
| 5183 |
IndexCore.prototype.as = null; |
| 5184 |
IndexCore.prototype.indexName = null; |
| 5185 |
IndexCore.prototype.typeAheadArgs = null; |
| 5186 |
IndexCore.prototype.typeAheadValueOption = null; |
| 5187 |
|
| 5188 |
|
| 5189 |
/***/ }), |
| 5190 |
/* 33 */ |
| 5191 |
/***/ (function(module, exports) { |
| 5192 |
|
| 5193 |
module.exports = function deprecate(fn, message) { |
| 5194 |
var warned = false; |
| 5195 |
|
| 5196 |
function deprecated() { |
| 5197 |
if (!warned) { |
| 5198 |
/* eslint no-console:0 */ |
| 5199 |
console.warn(message); |
| 5200 |
warned = true; |
| 5201 |
} |
| 5202 |
|
| 5203 |
return fn.apply(this, arguments); |
| 5204 |
} |
| 5205 |
|
| 5206 |
return deprecated; |
| 5207 |
}; |
| 5208 |
|
| 5209 |
|
| 5210 |
/***/ }), |
| 5211 |
/* 34 */ |
| 5212 |
/***/ (function(module, exports) { |
| 5213 |
|
| 5214 |
module.exports = function deprecatedMessage(previousUsage, newUsage) { |
| 5215 |
var githubAnchorLink = previousUsage.toLowerCase() |
| 5216 |
.replace(/[\.\(\)]/g, ''); |
| 5217 |
|
| 5218 |
return 'algoliasearch: `' + previousUsage + '` was replaced by `' + newUsage + |
| 5219 |
'`. Please see https://github.com/algolia/algoliasearch-client-javascript/wiki/Deprecated#' + githubAnchorLink; |
| 5220 |
}; |
| 5221 |
|
| 5222 |
|
| 5223 |
/***/ }), |
| 5224 |
/* 35 */ |
| 5225 |
/***/ (function(module, exports, __webpack_require__) { |
| 5226 |
|
| 5227 |
var foreach = __webpack_require__(2); |
| 5228 |
|
| 5229 |
module.exports = function merge(destination/* , sources */) { |
| 5230 |
var sources = Array.prototype.slice.call(arguments); |
| 5231 |
|
| 5232 |
foreach(sources, function(source) { |
| 5233 |
for (var keyName in source) { |
| 5234 |
if (source.hasOwnProperty(keyName)) { |
| 5235 |
if (typeof destination[keyName] === 'object' && typeof source[keyName] === 'object') { |
| 5236 |
destination[keyName] = merge({}, destination[keyName], source[keyName]); |
| 5237 |
} else if (source[keyName] !== undefined) { |
| 5238 |
destination[keyName] = source[keyName]; |
| 5239 |
} |
| 5240 |
} |
| 5241 |
} |
| 5242 |
}); |
| 5243 |
|
| 5244 |
return destination; |
| 5245 |
}; |
| 5246 |
|
| 5247 |
|
| 5248 |
/***/ }), |
| 5249 |
/* 36 */ |
| 5250 |
/***/ (function(module, exports, __webpack_require__) { |
| 5251 |
|
| 5252 |
"use strict"; |
| 5253 |
|
| 5254 |
|
| 5255 |
// modified from https://github.com/es-shims/es5-shim |
| 5256 |
var has = Object.prototype.hasOwnProperty; |
| 5257 |
var toStr = Object.prototype.toString; |
| 5258 |
var slice = Array.prototype.slice; |
| 5259 |
var isArgs = __webpack_require__(37); |
| 5260 |
var isEnumerable = Object.prototype.propertyIsEnumerable; |
| 5261 |
var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString'); |
| 5262 |
var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype'); |
| 5263 |
var dontEnums = [ |
| 5264 |
'toString', |
| 5265 |
'toLocaleString', |
| 5266 |
'valueOf', |
| 5267 |
'hasOwnProperty', |
| 5268 |
'isPrototypeOf', |
| 5269 |
'propertyIsEnumerable', |
| 5270 |
'constructor' |
| 5271 |
]; |
| 5272 |
var equalsConstructorPrototype = function (o) { |
| 5273 |
var ctor = o.constructor; |
| 5274 |
return ctor && ctor.prototype === o; |
| 5275 |
}; |
| 5276 |
var excludedKeys = { |
| 5277 |
$applicationCache: true, |
| 5278 |
$console: true, |
| 5279 |
$external: true, |
| 5280 |
$frame: true, |
| 5281 |
$frameElement: true, |
| 5282 |
$frames: true, |
| 5283 |
$innerHeight: true, |
| 5284 |
$innerWidth: true, |
| 5285 |
$outerHeight: true, |
| 5286 |
$outerWidth: true, |
| 5287 |
$pageXOffset: true, |
| 5288 |
$pageYOffset: true, |
| 5289 |
$parent: true, |
| 5290 |
$scrollLeft: true, |
| 5291 |
$scrollTop: true, |
| 5292 |
$scrollX: true, |
| 5293 |
$scrollY: true, |
| 5294 |
$self: true, |
| 5295 |
$webkitIndexedDB: true, |
| 5296 |
$webkitStorageInfo: true, |
| 5297 |
$window: true |
| 5298 |
}; |
| 5299 |
var hasAutomationEqualityBug = (function () { |
| 5300 |
/* global window */ |
| 5301 |
if (typeof window === 'undefined') { return false; } |
| 5302 |
for (var k in window) { |
| 5303 |
try { |
| 5304 |
if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') { |
| 5305 |
try { |
| 5306 |
equalsConstructorPrototype(window[k]); |
| 5307 |
} catch (e) { |
| 5308 |
return true; |
| 5309 |
} |
| 5310 |
} |
| 5311 |
} catch (e) { |
| 5312 |
return true; |
| 5313 |
} |
| 5314 |
} |
| 5315 |
return false; |
| 5316 |
}()); |
| 5317 |
var equalsConstructorPrototypeIfNotBuggy = function (o) { |
| 5318 |
/* global window */ |
| 5319 |
if (typeof window === 'undefined' || !hasAutomationEqualityBug) { |
| 5320 |
return equalsConstructorPrototype(o); |
| 5321 |
} |
| 5322 |
try { |
| 5323 |
return equalsConstructorPrototype(o); |
| 5324 |
} catch (e) { |
| 5325 |
return false; |
| 5326 |
} |
| 5327 |
}; |
| 5328 |
|
| 5329 |
var keysShim = function keys(object) { |
| 5330 |
var isObject = object !== null && typeof object === 'object'; |
| 5331 |
var isFunction = toStr.call(object) === '[object Function]'; |
| 5332 |
var isArguments = isArgs(object); |
| 5333 |
var isString = isObject && toStr.call(object) === '[object String]'; |
| 5334 |
var theKeys = []; |
| 5335 |
|
| 5336 |
if (!isObject && !isFunction && !isArguments) { |
| 5337 |
throw new TypeError('Object.keys called on a non-object'); |
| 5338 |
} |
| 5339 |
|
| 5340 |
var skipProto = hasProtoEnumBug && isFunction; |
| 5341 |
if (isString && object.length > 0 && !has.call(object, 0)) { |
| 5342 |
for (var i = 0; i < object.length; ++i) { |
| 5343 |
theKeys.push(String(i)); |
| 5344 |
} |
| 5345 |
} |
| 5346 |
|
| 5347 |
if (isArguments && object.length > 0) { |
| 5348 |
for (var j = 0; j < object.length; ++j) { |
| 5349 |
theKeys.push(String(j)); |
| 5350 |
} |
| 5351 |
} else { |
| 5352 |
for (var name in object) { |
| 5353 |
if (!(skipProto && name === 'prototype') && has.call(object, name)) { |
| 5354 |
theKeys.push(String(name)); |
| 5355 |
} |
| 5356 |
} |
| 5357 |
} |
| 5358 |
|
| 5359 |
if (hasDontEnumBug) { |
| 5360 |
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); |
| 5361 |
|
| 5362 |
for (var k = 0; k < dontEnums.length; ++k) { |
| 5363 |
if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) { |
| 5364 |
theKeys.push(dontEnums[k]); |
| 5365 |
} |
| 5366 |
} |
| 5367 |
} |
| 5368 |
return theKeys; |
| 5369 |
}; |
| 5370 |
|
| 5371 |
keysShim.shim = function shimObjectKeys() { |
| 5372 |
if (Object.keys) { |
| 5373 |
var keysWorksWithArguments = (function () { |
| 5374 |
// Safari 5.0 bug |
| 5375 |
return (Object.keys(arguments) || '').length === 2; |
| 5376 |
}(1, 2)); |
| 5377 |
if (!keysWorksWithArguments) { |
| 5378 |
var originalKeys = Object.keys; |
| 5379 |
Object.keys = function keys(object) { // eslint-disable-line func-name-matching |
| 5380 |
if (isArgs(object)) { |
| 5381 |
return originalKeys(slice.call(object)); |
| 5382 |
} else { |
| 5383 |
return originalKeys(object); |
| 5384 |
} |
| 5385 |
}; |
| 5386 |
} |
| 5387 |
} else { |
| 5388 |
Object.keys = keysShim; |
| 5389 |
} |
| 5390 |
return Object.keys || keysShim; |
| 5391 |
}; |
| 5392 |
|
| 5393 |
module.exports = keysShim; |
| 5394 |
|
| 5395 |
|
| 5396 |
/***/ }), |
| 5397 |
/* 37 */ |
| 5398 |
/***/ (function(module, exports, __webpack_require__) { |
| 5399 |
|
| 5400 |
"use strict"; |
| 5401 |
|
| 5402 |
|
| 5403 |
var toStr = Object.prototype.toString; |
| 5404 |
|
| 5405 |
module.exports = function isArguments(value) { |
| 5406 |
var str = toStr.call(value); |
| 5407 |
var isArgs = str === '[object Arguments]'; |
| 5408 |
if (!isArgs) { |
| 5409 |
isArgs = str !== '[object Array]' && |
| 5410 |
value !== null && |
| 5411 |
typeof value === 'object' && |
| 5412 |
typeof value.length === 'number' && |
| 5413 |
value.length >= 0 && |
| 5414 |
toStr.call(value.callee) === '[object Function]'; |
| 5415 |
} |
| 5416 |
return isArgs; |
| 5417 |
}; |
| 5418 |
|
| 5419 |
|
| 5420 |
/***/ }), |
| 5421 |
/* 38 */ |
| 5422 |
/***/ (function(module, exports, __webpack_require__) { |
| 5423 |
|
| 5424 |
/* WEBPACK VAR INJECTION */(function(global) {var debug = __webpack_require__(8)('algoliasearch:src/hostIndexState.js'); |
| 5425 |
var localStorageNamespace = 'algoliasearch-client-js'; |
| 5426 |
|
| 5427 |
var store; |
| 5428 |
var moduleStore = { |
| 5429 |
state: {}, |
| 5430 |
set: function(key, data) { |
| 5431 |
this.state[key] = data; |
| 5432 |
return this.state[key]; |
| 5433 |
}, |
| 5434 |
get: function(key) { |
| 5435 |
return this.state[key] || null; |
| 5436 |
} |
| 5437 |
}; |
| 5438 |
|
| 5439 |
var localStorageStore = { |
| 5440 |
set: function(key, data) { |
| 5441 |
moduleStore.set(key, data); // always replicate localStorageStore to moduleStore in case of failure |
| 5442 |
|
| 5443 |
try { |
| 5444 |
var namespace = JSON.parse(global.localStorage[localStorageNamespace]); |
| 5445 |
namespace[key] = data; |
| 5446 |
global.localStorage[localStorageNamespace] = JSON.stringify(namespace); |
| 5447 |
return namespace[key]; |
| 5448 |
} catch (e) { |
| 5449 |
return localStorageFailure(key, e); |
| 5450 |
} |
| 5451 |
}, |
| 5452 |
get: function(key) { |
| 5453 |
try { |
| 5454 |
return JSON.parse(global.localStorage[localStorageNamespace])[key] || null; |
| 5455 |
} catch (e) { |
| 5456 |
return localStorageFailure(key, e); |
| 5457 |
} |
| 5458 |
} |
| 5459 |
}; |
| 5460 |
|
| 5461 |
function localStorageFailure(key, e) { |
| 5462 |
debug('localStorage failed with', e); |
| 5463 |
cleanup(); |
| 5464 |
store = moduleStore; |
| 5465 |
return store.get(key); |
| 5466 |
} |
| 5467 |
|
| 5468 |
store = supportsLocalStorage() ? localStorageStore : moduleStore; |
| 5469 |
|
| 5470 |
module.exports = { |
| 5471 |
get: getOrSet, |
| 5472 |
set: getOrSet, |
| 5473 |
supportsLocalStorage: supportsLocalStorage |
| 5474 |
}; |
| 5475 |
|
| 5476 |
function getOrSet(key, data) { |
| 5477 |
if (arguments.length === 1) { |
| 5478 |
return store.get(key); |
| 5479 |
} |
| 5480 |
|
| 5481 |
return store.set(key, data); |
| 5482 |
} |
| 5483 |
|
| 5484 |
function supportsLocalStorage() { |
| 5485 |
try { |
| 5486 |
if ('localStorage' in global && |
| 5487 |
global.localStorage !== null) { |
| 5488 |
if (!global.localStorage[localStorageNamespace]) { |
| 5489 |
// actual creation of the namespace |
| 5490 |
global.localStorage.setItem(localStorageNamespace, JSON.stringify({})); |
| 5491 |
} |
| 5492 |
return true; |
| 5493 |
} |
| 5494 |
|
| 5495 |
return false; |
| 5496 |
} catch (_) { |
| 5497 |
return false; |
| 5498 |
} |
| 5499 |
} |
| 5500 |
|
| 5501 |
// In case of any error on localStorage, we clean our own namespace, this should handle |
| 5502 |
// quota errors when a lot of keys + data are used |
| 5503 |
function cleanup() { |
| 5504 |
try { |
| 5505 |
global.localStorage.removeItem(localStorageNamespace); |
| 5506 |
} catch (_) { |
| 5507 |
// nothing to do |
| 5508 |
} |
| 5509 |
} |
| 5510 |
|
| 5511 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) |
| 5512 |
|
| 5513 |
/***/ }), |
| 5514 |
/* 39 */ |
| 5515 |
/***/ (function(module, exports, __webpack_require__) { |
| 5516 |
|
| 5517 |
|
| 5518 |
/** |
| 5519 |
* This is the common logic for both the Node.js and web browser |
| 5520 |
* implementations of `debug()`. |
| 5521 |
* |
| 5522 |
* Expose `debug()` as the module. |
| 5523 |
*/ |
| 5524 |
|
| 5525 |
exports = module.exports = createDebug.debug = createDebug['default'] = createDebug; |
| 5526 |
exports.coerce = coerce; |
| 5527 |
exports.disable = disable; |
| 5528 |
exports.enable = enable; |
| 5529 |
exports.enabled = enabled; |
| 5530 |
exports.humanize = __webpack_require__(40); |
| 5531 |
|
| 5532 |
/** |
| 5533 |
* The currently active debug mode names, and names to skip. |
| 5534 |
*/ |
| 5535 |
|
| 5536 |
exports.names = []; |
| 5537 |
exports.skips = []; |
| 5538 |
|
| 5539 |
/** |
| 5540 |
* Map of special "%n" handling functions, for the debug "format" argument. |
| 5541 |
* |
| 5542 |
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". |
| 5543 |
*/ |
| 5544 |
|
| 5545 |
exports.formatters = {}; |
| 5546 |
|
| 5547 |
/** |
| 5548 |
* Previous log timestamp. |
| 5549 |
*/ |
| 5550 |
|
| 5551 |
var prevTime; |
| 5552 |
|
| 5553 |
/** |
| 5554 |
* Select a color. |
| 5555 |
* @param {String} namespace |
| 5556 |
* @return {Number} |
| 5557 |
* @api private |
| 5558 |
*/ |
| 5559 |
|
| 5560 |
function selectColor(namespace) { |
| 5561 |
var hash = 0, i; |
| 5562 |
|
| 5563 |
for (i in namespace) { |
| 5564 |
hash = ((hash << 5) - hash) + namespace.charCodeAt(i); |
| 5565 |
hash |= 0; // Convert to 32bit integer |
| 5566 |
} |
| 5567 |
|
| 5568 |
return exports.colors[Math.abs(hash) % exports.colors.length]; |
| 5569 |
} |
| 5570 |
|
| 5571 |
/** |
| 5572 |
* Create a debugger with the given `namespace`. |
| 5573 |
* |
| 5574 |
* @param {String} namespace |
| 5575 |
* @return {Function} |
| 5576 |
* @api public |
| 5577 |
*/ |
| 5578 |
|
| 5579 |
function createDebug(namespace) { |
| 5580 |
|
| 5581 |
function debug() { |
| 5582 |
// disabled? |
| 5583 |
if (!debug.enabled) return; |
| 5584 |
|
| 5585 |
var self = debug; |
| 5586 |
|
| 5587 |
// set `diff` timestamp |
| 5588 |
var curr = +new Date(); |
| 5589 |
var ms = curr - (prevTime || curr); |
| 5590 |
self.diff = ms; |
| 5591 |
self.prev = prevTime; |
| 5592 |
self.curr = curr; |
| 5593 |
prevTime = curr; |
| 5594 |
|
| 5595 |
// turn the `arguments` into a proper Array |
| 5596 |
var args = new Array(arguments.length); |
| 5597 |
for (var i = 0; i < args.length; i++) { |
| 5598 |
args[i] = arguments[i]; |
| 5599 |
} |
| 5600 |
|
| 5601 |
args[0] = exports.coerce(args[0]); |
| 5602 |
|
| 5603 |
if ('string' !== typeof args[0]) { |
| 5604 |
// anything else let's inspect with %O |
| 5605 |
args.unshift('%O'); |
| 5606 |
} |
| 5607 |
|
| 5608 |
// apply any `formatters` transformations |
| 5609 |
var index = 0; |
| 5610 |
args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) { |
| 5611 |
// if we encounter an escaped % then don't increase the array index |
| 5612 |
if (match === '%%') return match; |
| 5613 |
index++; |
| 5614 |
var formatter = exports.formatters[format]; |
| 5615 |
if ('function' === typeof formatter) { |
| 5616 |
var val = args[index]; |
| 5617 |
match = formatter.call(self, val); |
| 5618 |
|
| 5619 |
// now we need to remove `args[index]` since it's inlined in the `format` |
| 5620 |
args.splice(index, 1); |
| 5621 |
index--; |
| 5622 |
} |
| 5623 |
return match; |
| 5624 |
}); |
| 5625 |
|
| 5626 |
// apply env-specific formatting (colors, etc.) |
| 5627 |
exports.formatArgs.call(self, args); |
| 5628 |
|
| 5629 |
var logFn = debug.log || exports.log || console.log.bind(console); |
| 5630 |
logFn.apply(self, args); |
| 5631 |
} |
| 5632 |
|
| 5633 |
debug.namespace = namespace; |
| 5634 |
debug.enabled = exports.enabled(namespace); |
| 5635 |
debug.useColors = exports.useColors(); |
| 5636 |
debug.color = selectColor(namespace); |
| 5637 |
|
| 5638 |
// env-specific initialization logic for debug instances |
| 5639 |
if ('function' === typeof exports.init) { |
| 5640 |
exports.init(debug); |
| 5641 |
} |
| 5642 |
|
| 5643 |
return debug; |
| 5644 |
} |
| 5645 |
|
| 5646 |
/** |
| 5647 |
* Enables a debug mode by namespaces. This can include modes |
| 5648 |
* separated by a colon and wildcards. |
| 5649 |
* |
| 5650 |
* @param {String} namespaces |
| 5651 |
* @api public |
| 5652 |
*/ |
| 5653 |
|
| 5654 |
function enable(namespaces) { |
| 5655 |
exports.save(namespaces); |
| 5656 |
|
| 5657 |
exports.names = []; |
| 5658 |
exports.skips = []; |
| 5659 |
|
| 5660 |
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); |
| 5661 |
var len = split.length; |
| 5662 |
|
| 5663 |
for (var i = 0; i < len; i++) { |
| 5664 |
if (!split[i]) continue; // ignore empty strings |
| 5665 |
namespaces = split[i].replace(/\*/g, '.*?'); |
| 5666 |
if (namespaces[0] === '-') { |
| 5667 |
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); |
| 5668 |
} else { |
| 5669 |
exports.names.push(new RegExp('^' + namespaces + '$')); |
| 5670 |
} |
| 5671 |
} |
| 5672 |
} |
| 5673 |
|
| 5674 |
/** |
| 5675 |
* Disable debug output. |
| 5676 |
* |
| 5677 |
* @api public |
| 5678 |
*/ |
| 5679 |
|
| 5680 |
function disable() { |
| 5681 |
exports.enable(''); |
| 5682 |
} |
| 5683 |
|
| 5684 |
/** |
| 5685 |
* Returns true if the given mode name is enabled, false otherwise. |
| 5686 |
* |
| 5687 |
* @param {String} name |
| 5688 |
* @return {Boolean} |
| 5689 |
* @api public |
| 5690 |
*/ |
| 5691 |
|
| 5692 |
function enabled(name) { |
| 5693 |
var i, len; |
| 5694 |
for (i = 0, len = exports.skips.length; i < len; i++) { |
| 5695 |
if (exports.skips[i].test(name)) { |
| 5696 |
return false; |
| 5697 |
} |
| 5698 |
} |
| 5699 |
for (i = 0, len = exports.names.length; i < len; i++) { |
| 5700 |
if (exports.names[i].test(name)) { |
| 5701 |
return true; |
| 5702 |
} |
| 5703 |
} |
| 5704 |
return false; |
| 5705 |
} |
| 5706 |
|
| 5707 |
/** |
| 5708 |
* Coerce `val`. |
| 5709 |
* |
| 5710 |
* @param {Mixed} val |
| 5711 |
* @return {Mixed} |
| 5712 |
* @api private |
| 5713 |
*/ |
| 5714 |
|
| 5715 |
function coerce(val) { |
| 5716 |
if (val instanceof Error) return val.stack || val.message; |
| 5717 |
return val; |
| 5718 |
} |
| 5719 |
|
| 5720 |
|
| 5721 |
/***/ }), |
| 5722 |
/* 40 */ |
| 5723 |
/***/ (function(module, exports) { |
| 5724 |
|
| 5725 |
/** |
| 5726 |
* Helpers. |
| 5727 |
*/ |
| 5728 |
|
| 5729 |
var s = 1000; |
| 5730 |
var m = s * 60; |
| 5731 |
var h = m * 60; |
| 5732 |
var d = h * 24; |
| 5733 |
var y = d * 365.25; |
| 5734 |
|
| 5735 |
/** |
| 5736 |
* Parse or format the given `val`. |
| 5737 |
* |
| 5738 |
* Options: |
| 5739 |
* |
| 5740 |
* - `long` verbose formatting [false] |
| 5741 |
* |
| 5742 |
* @param {String|Number} val |
| 5743 |
* @param {Object} [options] |
| 5744 |
* @throws {Error} throw an error if val is not a non-empty string or a number |
| 5745 |
* @return {String|Number} |
| 5746 |
* @api public |
| 5747 |
*/ |
| 5748 |
|
| 5749 |
module.exports = function(val, options) { |
| 5750 |
options = options || {}; |
| 5751 |
var type = typeof val; |
| 5752 |
if (type === 'string' && val.length > 0) { |
| 5753 |
return parse(val); |
| 5754 |
} else if (type === 'number' && isNaN(val) === false) { |
| 5755 |
return options.long ? fmtLong(val) : fmtShort(val); |
| 5756 |
} |
| 5757 |
throw new Error( |
| 5758 |
'val is not a non-empty string or a valid number. val=' + |
| 5759 |
JSON.stringify(val) |
| 5760 |
); |
| 5761 |
}; |
| 5762 |
|
| 5763 |
/** |
| 5764 |
* Parse the given `str` and return milliseconds. |
| 5765 |
* |
| 5766 |
* @param {String} str |
| 5767 |
* @return {Number} |
| 5768 |
* @api private |
| 5769 |
*/ |
| 5770 |
|
| 5771 |
function parse(str) { |
| 5772 |
str = String(str); |
| 5773 |
if (str.length > 100) { |
| 5774 |
return; |
| 5775 |
} |
| 5776 |
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec( |
| 5777 |
str |
| 5778 |
); |
| 5779 |
if (!match) { |
| 5780 |
return; |
| 5781 |
} |
| 5782 |
var n = parseFloat(match[1]); |
| 5783 |
var type = (match[2] || 'ms').toLowerCase(); |
| 5784 |
switch (type) { |
| 5785 |
case 'years': |
| 5786 |
case 'year': |
| 5787 |
case 'yrs': |
| 5788 |
case 'yr': |
| 5789 |
case 'y': |
| 5790 |
return n * y; |
| 5791 |
case 'days': |
| 5792 |
case 'day': |
| 5793 |
case 'd': |
| 5794 |
return n * d; |
| 5795 |
case 'hours': |
| 5796 |
case 'hour': |
| 5797 |
case 'hrs': |
| 5798 |
case 'hr': |
| 5799 |
case 'h': |
| 5800 |
return n * h; |
| 5801 |
case 'minutes': |
| 5802 |
case 'minute': |
| 5803 |
case 'mins': |
| 5804 |
case 'min': |
| 5805 |
case 'm': |
| 5806 |
return n * m; |
| 5807 |
case 'seconds': |
| 5808 |
case 'second': |
| 5809 |
case 'secs': |
| 5810 |
case 'sec': |
| 5811 |
case 's': |
| 5812 |
return n * s; |
| 5813 |
case 'milliseconds': |
| 5814 |
case 'millisecond': |
| 5815 |
case 'msecs': |
| 5816 |
case 'msec': |
| 5817 |
case 'ms': |
| 5818 |
return n; |
| 5819 |
default: |
| 5820 |
return undefined; |
| 5821 |
} |
| 5822 |
} |
| 5823 |
|
| 5824 |
/** |
| 5825 |
* Short format for `ms`. |
| 5826 |
* |
| 5827 |
* @param {Number} ms |
| 5828 |
* @return {String} |
| 5829 |
* @api private |
| 5830 |
*/ |
| 5831 |
|
| 5832 |
function fmtShort(ms) { |
| 5833 |
if (ms >= d) { |
| 5834 |
return Math.round(ms / d) + 'd'; |
| 5835 |
} |
| 5836 |
if (ms >= h) { |
| 5837 |
return Math.round(ms / h) + 'h'; |
| 5838 |
} |
| 5839 |
if (ms >= m) { |
| 5840 |
return Math.round(ms / m) + 'm'; |
| 5841 |
} |
| 5842 |
if (ms >= s) { |
| 5843 |
return Math.round(ms / s) + 's'; |
| 5844 |
} |
| 5845 |
return ms + 'ms'; |
| 5846 |
} |
| 5847 |
|
| 5848 |
/** |
| 5849 |
* Long format for `ms`. |
| 5850 |
* |
| 5851 |
* @param {Number} ms |
| 5852 |
* @return {String} |
| 5853 |
* @api private |
| 5854 |
*/ |
| 5855 |
|
| 5856 |
function fmtLong(ms) { |
| 5857 |
return plural(ms, d, 'day') || |
| 5858 |
plural(ms, h, 'hour') || |
| 5859 |
plural(ms, m, 'minute') || |
| 5860 |
plural(ms, s, 'second') || |
| 5861 |
ms + ' ms'; |
| 5862 |
} |
| 5863 |
|
| 5864 |
/** |
| 5865 |
* Pluralization helper. |
| 5866 |
*/ |
| 5867 |
|
| 5868 |
function plural(ms, n, name) { |
| 5869 |
if (ms < n) { |
| 5870 |
return; |
| 5871 |
} |
| 5872 |
if (ms < n * 1.5) { |
| 5873 |
return Math.floor(ms / n) + ' ' + name; |
| 5874 |
} |
| 5875 |
return Math.ceil(ms / n) + ' ' + name + 's'; |
| 5876 |
} |
| 5877 |
|
| 5878 |
|
| 5879 |
/***/ }), |
| 5880 |
/* 41 */ |
| 5881 |
/***/ (function(module, exports, __webpack_require__) { |
| 5882 |
|
| 5883 |
"use strict"; |
| 5884 |
|
| 5885 |
|
| 5886 |
var global = __webpack_require__(42); |
| 5887 |
var Promise = global.Promise || __webpack_require__(43).Promise; |
| 5888 |
|
| 5889 |
// This is the standalone browser build entry point |
| 5890 |
// Browser implementation of the Algolia Search JavaScript client, |
| 5891 |
// using XMLHttpRequest, XDomainRequest and JSONP as fallback |
| 5892 |
module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) { |
| 5893 |
var inherits = __webpack_require__(12); |
| 5894 |
var errors = __webpack_require__(5); |
| 5895 |
var inlineHeaders = __webpack_require__(44); |
| 5896 |
var jsonpRequest = __webpack_require__(46); |
| 5897 |
var places = __webpack_require__(47); |
| 5898 |
uaSuffix = uaSuffix || ''; |
| 5899 |
|
| 5900 |
if (false) { |
| 5901 |
require('debug').enable('algoliasearch*'); |
| 5902 |
} |
| 5903 |
|
| 5904 |
function algoliasearch(applicationID, apiKey, opts) { |
| 5905 |
var cloneDeep = __webpack_require__(3); |
| 5906 |
|
| 5907 |
opts = cloneDeep(opts || {}); |
| 5908 |
|
| 5909 |
opts._ua = opts._ua || algoliasearch.ua; |
| 5910 |
|
| 5911 |
return new AlgoliaSearchBrowser(applicationID, apiKey, opts); |
| 5912 |
} |
| 5913 |
|
| 5914 |
algoliasearch.version = __webpack_require__(48); |
| 5915 |
algoliasearch.ua = 'Algolia for vanilla JavaScript ' + uaSuffix + algoliasearch.version; |
| 5916 |
algoliasearch.initPlaces = places(algoliasearch); |
| 5917 |
|
| 5918 |
// we expose into window no matter how we are used, this will allow |
| 5919 |
// us to easily debug any website running algolia |
| 5920 |
global.__algolia = { |
| 5921 |
debug: __webpack_require__(8), |
| 5922 |
algoliasearch: algoliasearch |
| 5923 |
}; |
| 5924 |
|
| 5925 |
var support = { |
| 5926 |
hasXMLHttpRequest: 'XMLHttpRequest' in global, |
| 5927 |
hasXDomainRequest: 'XDomainRequest' in global |
| 5928 |
}; |
| 5929 |
|
| 5930 |
if (support.hasXMLHttpRequest) { |
| 5931 |
support.cors = 'withCredentials' in new XMLHttpRequest(); |
| 5932 |
} |
| 5933 |
|
| 5934 |
function AlgoliaSearchBrowser() { |
| 5935 |
// call AlgoliaSearch constructor |
| 5936 |
AlgoliaSearch.apply(this, arguments); |
| 5937 |
} |
| 5938 |
|
| 5939 |
inherits(AlgoliaSearchBrowser, AlgoliaSearch); |
| 5940 |
|
| 5941 |
AlgoliaSearchBrowser.prototype._request = function request(url, opts) { |
| 5942 |
return new Promise(function wrapRequest(resolve, reject) { |
| 5943 |
// no cors or XDomainRequest, no request |
| 5944 |
if (!support.cors && !support.hasXDomainRequest) { |
| 5945 |
// very old browser, not supported |
| 5946 |
reject(new errors.Network('CORS not supported')); |
| 5947 |
return; |
| 5948 |
} |
| 5949 |
|
| 5950 |
url = inlineHeaders(url, opts.headers); |
| 5951 |
|
| 5952 |
var body = opts.body; |
| 5953 |
var req = support.cors ? new XMLHttpRequest() : new XDomainRequest(); |
| 5954 |
var reqTimeout; |
| 5955 |
var timedOut; |
| 5956 |
var connected = false; |
| 5957 |
|
| 5958 |
reqTimeout = setTimeout(onTimeout, opts.timeouts.connect); |
| 5959 |
// we set an empty onprogress listener |
| 5960 |
// so that XDomainRequest on IE9 is not aborted |
| 5961 |
// refs: |
| 5962 |
// - https://github.com/algolia/algoliasearch-client-js/issues/76 |
| 5963 |
// - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment |
| 5964 |
req.onprogress = onProgress; |
| 5965 |
if ('onreadystatechange' in req) req.onreadystatechange = onReadyStateChange; |
| 5966 |
req.onload = onLoad; |
| 5967 |
req.onerror = onError; |
| 5968 |
|
| 5969 |
// do not rely on default XHR async flag, as some analytics code like hotjar |
| 5970 |
// breaks it and set it to false by default |
| 5971 |
if (req instanceof XMLHttpRequest) { |
| 5972 |
req.open(opts.method, url, true); |
| 5973 |
|
| 5974 |
// The Analytics API never accepts Auth headers as query string |
| 5975 |
// this option exists specifically for them. |
| 5976 |
if (opts.forceAuthHeaders) { |
| 5977 |
req.setRequestHeader( |
| 5978 |
'x-algolia-application-id', |
| 5979 |
opts.headers['x-algolia-application-id'] |
| 5980 |
); |
| 5981 |
req.setRequestHeader( |
| 5982 |
'x-algolia-api-key', |
| 5983 |
opts.headers['x-algolia-api-key'] |
| 5984 |
); |
| 5985 |
} |
| 5986 |
} else { |
| 5987 |
req.open(opts.method, url); |
| 5988 |
} |
| 5989 |
|
| 5990 |
// headers are meant to be sent after open |
| 5991 |
if (support.cors) { |
| 5992 |
if (body) { |
| 5993 |
if (opts.method === 'POST') { |
| 5994 |
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests |
| 5995 |
req.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); |
| 5996 |
} else { |
| 5997 |
req.setRequestHeader('content-type', 'application/json'); |
| 5998 |
} |
| 5999 |
} |
| 6000 |
req.setRequestHeader('accept', 'application/json'); |
| 6001 |
} |
| 6002 |
|
| 6003 |
if (body) { |
| 6004 |
req.send(body); |
| 6005 |
} else { |
| 6006 |
req.send(); |
| 6007 |
} |
| 6008 |
|
| 6009 |
// event object not received in IE8, at least |
| 6010 |
// but we do not use it, still important to note |
| 6011 |
function onLoad(/* event */) { |
| 6012 |
// When browser does not supports req.timeout, we can |
| 6013 |
// have both a load and timeout event, since handled by a dumb setTimeout |
| 6014 |
if (timedOut) { |
| 6015 |
return; |
| 6016 |
} |
| 6017 |
|
| 6018 |
clearTimeout(reqTimeout); |
| 6019 |
|
| 6020 |
var out; |
| 6021 |
|
| 6022 |
try { |
| 6023 |
out = { |
| 6024 |
body: JSON.parse(req.responseText), |
| 6025 |
responseText: req.responseText, |
| 6026 |
statusCode: req.status, |
| 6027 |
// XDomainRequest does not have any response headers |
| 6028 |
headers: req.getAllResponseHeaders && req.getAllResponseHeaders() || {} |
| 6029 |
}; |
| 6030 |
} catch (e) { |
| 6031 |
out = new errors.UnparsableJSON({ |
| 6032 |
more: req.responseText |
| 6033 |
}); |
| 6034 |
} |
| 6035 |
|
| 6036 |
if (out instanceof errors.UnparsableJSON) { |
| 6037 |
reject(out); |
| 6038 |
} else { |
| 6039 |
resolve(out); |
| 6040 |
} |
| 6041 |
} |
| 6042 |
|
| 6043 |
function onError(event) { |
| 6044 |
if (timedOut) { |
| 6045 |
return; |
| 6046 |
} |
| 6047 |
|
| 6048 |
clearTimeout(reqTimeout); |
| 6049 |
|
| 6050 |
// error event is trigerred both with XDR/XHR on: |
| 6051 |
// - DNS error |
| 6052 |
// - unallowed cross domain request |
| 6053 |
reject( |
| 6054 |
new errors.Network({ |
| 6055 |
more: event |
| 6056 |
}) |
| 6057 |
); |
| 6058 |
} |
| 6059 |
|
| 6060 |
function onTimeout() { |
| 6061 |
timedOut = true; |
| 6062 |
req.abort(); |
| 6063 |
|
| 6064 |
reject(new errors.RequestTimeout()); |
| 6065 |
} |
| 6066 |
|
| 6067 |
function onConnect() { |
| 6068 |
connected = true; |
| 6069 |
clearTimeout(reqTimeout); |
| 6070 |
reqTimeout = setTimeout(onTimeout, opts.timeouts.complete); |
| 6071 |
} |
| 6072 |
|
| 6073 |
function onProgress() { |
| 6074 |
if (!connected) onConnect(); |
| 6075 |
} |
| 6076 |
|
| 6077 |
function onReadyStateChange() { |
| 6078 |
if (!connected && req.readyState > 1) onConnect(); |
| 6079 |
} |
| 6080 |
}); |
| 6081 |
}; |
| 6082 |
|
| 6083 |
AlgoliaSearchBrowser.prototype._request.fallback = function requestFallback(url, opts) { |
| 6084 |
url = inlineHeaders(url, opts.headers); |
| 6085 |
|
| 6086 |
return new Promise(function wrapJsonpRequest(resolve, reject) { |
| 6087 |
jsonpRequest(url, opts, function jsonpRequestDone(err, content) { |
| 6088 |
if (err) { |
| 6089 |
reject(err); |
| 6090 |
return; |
| 6091 |
} |
| 6092 |
|
| 6093 |
resolve(content); |
| 6094 |
}); |
| 6095 |
}); |
| 6096 |
}; |
| 6097 |
|
| 6098 |
AlgoliaSearchBrowser.prototype._promise = { |
| 6099 |
reject: function rejectPromise(val) { |
| 6100 |
return Promise.reject(val); |
| 6101 |
}, |
| 6102 |
resolve: function resolvePromise(val) { |
| 6103 |
return Promise.resolve(val); |
| 6104 |
}, |
| 6105 |
delay: function delayPromise(ms) { |
| 6106 |
return new Promise(function resolveOnTimeout(resolve/* , reject*/) { |
| 6107 |
setTimeout(resolve, ms); |
| 6108 |
}); |
| 6109 |
}, |
| 6110 |
all: function all(promises) { |
| 6111 |
return Promise.all(promises); |
| 6112 |
} |
| 6113 |
}; |
| 6114 |
|
| 6115 |
return algoliasearch; |
| 6116 |
}; |
| 6117 |
|
| 6118 |
|
| 6119 |
/***/ }), |
| 6120 |
/* 42 */ |
| 6121 |
/***/ (function(module, exports, __webpack_require__) { |
| 6122 |
|
| 6123 |
/* WEBPACK VAR INJECTION */(function(global) {var win; |
| 6124 |
|
| 6125 |
if (typeof window !== "undefined") { |
| 6126 |
win = window; |
| 6127 |
} else if (typeof global !== "undefined") { |
| 6128 |
win = global; |
| 6129 |
} else if (typeof self !== "undefined"){ |
| 6130 |
win = self; |
| 6131 |
} else { |
| 6132 |
win = {}; |
| 6133 |
} |
| 6134 |
|
| 6135 |
module.exports = win; |
| 6136 |
|
| 6137 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) |
| 6138 |
|
| 6139 |
/***/ }), |
| 6140 |
/* 43 */ |
| 6141 |
/***/ (function(module, exports, __webpack_require__) { |
| 6142 |
|
| 6143 |
/* WEBPACK VAR INJECTION */(function(process, global) {/*! |
| 6144 |
* @overview es6-promise - a tiny implementation of Promises/A+. |
| 6145 |
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) |
| 6146 |
* @license Licensed under MIT license |
| 6147 |
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE |
| 6148 |
* @version v4.2.4+314e4831 |
| 6149 |
*/ |
| 6150 |
|
| 6151 |
(function (global, factory) { |
| 6152 |
true ? module.exports = factory() : |
| 6153 |
typeof define === 'function' && define.amd ? define(factory) : |
| 6154 |
(global.ES6Promise = factory()); |
| 6155 |
}(this, (function () { 'use strict'; |
| 6156 |
|
| 6157 |
function objectOrFunction(x) { |
| 6158 |
var type = typeof x; |
| 6159 |
return x !== null && (type === 'object' || type === 'function'); |
| 6160 |
} |
| 6161 |
|
| 6162 |
function isFunction(x) { |
| 6163 |
return typeof x === 'function'; |
| 6164 |
} |
| 6165 |
|
| 6166 |
|
| 6167 |
|
| 6168 |
var _isArray = void 0; |
| 6169 |
if (Array.isArray) { |
| 6170 |
_isArray = Array.isArray; |
| 6171 |
} else { |
| 6172 |
_isArray = function (x) { |
| 6173 |
return Object.prototype.toString.call(x) === '[object Array]'; |
| 6174 |
}; |
| 6175 |
} |
| 6176 |
|
| 6177 |
var isArray = _isArray; |
| 6178 |
|
| 6179 |
var len = 0; |
| 6180 |
var vertxNext = void 0; |
| 6181 |
var customSchedulerFn = void 0; |
| 6182 |
|
| 6183 |
var asap = function asap(callback, arg) { |
| 6184 |
queue[len] = callback; |
| 6185 |
queue[len + 1] = arg; |
| 6186 |
len += 2; |
| 6187 |
if (len === 2) { |
| 6188 |
// If len is 2, that means that we need to schedule an async flush. |
| 6189 |
// If additional callbacks are queued before the queue is flushed, they |
| 6190 |
// will be processed by this flush that we are scheduling. |
| 6191 |
if (customSchedulerFn) { |
| 6192 |
customSchedulerFn(flush); |
| 6193 |
} else { |
| 6194 |
scheduleFlush(); |
| 6195 |
} |
| 6196 |
} |
| 6197 |
}; |
| 6198 |
|
| 6199 |
function setScheduler(scheduleFn) { |
| 6200 |
customSchedulerFn = scheduleFn; |
| 6201 |
} |
| 6202 |
|
| 6203 |
function setAsap(asapFn) { |
| 6204 |
asap = asapFn; |
| 6205 |
} |
| 6206 |
|
| 6207 |
var browserWindow = typeof window !== 'undefined' ? window : undefined; |
| 6208 |
var browserGlobal = browserWindow || {}; |
| 6209 |
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; |
| 6210 |
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; |
| 6211 |
|
| 6212 |
// test for web worker but not in IE10 |
| 6213 |
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; |
| 6214 |
|
| 6215 |
// node |
| 6216 |
function useNextTick() { |
| 6217 |
// node version 0.10.x displays a deprecation warning when nextTick is used recursively |
| 6218 |
// see https://github.com/cujojs/when/issues/410 for details |
| 6219 |
return function () { |
| 6220 |
return process.nextTick(flush); |
| 6221 |
}; |
| 6222 |
} |
| 6223 |
|
| 6224 |
// vertx |
| 6225 |
function useVertxTimer() { |
| 6226 |
if (typeof vertxNext !== 'undefined') { |
| 6227 |
return function () { |
| 6228 |
vertxNext(flush); |
| 6229 |
}; |
| 6230 |
} |
| 6231 |
|
| 6232 |
return useSetTimeout(); |
| 6233 |
} |
| 6234 |
|
| 6235 |
function useMutationObserver() { |
| 6236 |
var iterations = 0; |
| 6237 |
var observer = new BrowserMutationObserver(flush); |
| 6238 |
var node = document.createTextNode(''); |
| 6239 |
observer.observe(node, { characterData: true }); |
| 6240 |
|
| 6241 |
return function () { |
| 6242 |
node.data = iterations = ++iterations % 2; |
| 6243 |
}; |
| 6244 |
} |
| 6245 |
|
| 6246 |
// web worker |
| 6247 |
function useMessageChannel() { |
| 6248 |
var channel = new MessageChannel(); |
| 6249 |
channel.port1.onmessage = flush; |
| 6250 |
return function () { |
| 6251 |
return channel.port2.postMessage(0); |
| 6252 |
}; |
| 6253 |
} |
| 6254 |
|
| 6255 |
function useSetTimeout() { |
| 6256 |
// Store setTimeout reference so es6-promise will be unaffected by |
| 6257 |
// other code modifying setTimeout (like sinon.useFakeTimers()) |
| 6258 |
var globalSetTimeout = setTimeout; |
| 6259 |
return function () { |
| 6260 |
return globalSetTimeout(flush, 1); |
| 6261 |
}; |
| 6262 |
} |
| 6263 |
|
| 6264 |
var queue = new Array(1000); |
| 6265 |
function flush() { |
| 6266 |
for (var i = 0; i < len; i += 2) { |
| 6267 |
var callback = queue[i]; |
| 6268 |
var arg = queue[i + 1]; |
| 6269 |
|
| 6270 |
callback(arg); |
| 6271 |
|
| 6272 |
queue[i] = undefined; |
| 6273 |
queue[i + 1] = undefined; |
| 6274 |
} |
| 6275 |
|
| 6276 |
len = 0; |
| 6277 |
} |
| 6278 |
|
| 6279 |
function attemptVertx() { |
| 6280 |
try { |
| 6281 |
var vertx = Function('return this')().require('vertx'); |
| 6282 |
vertxNext = vertx.runOnLoop || vertx.runOnContext; |
| 6283 |
return useVertxTimer(); |
| 6284 |
} catch (e) { |
| 6285 |
return useSetTimeout(); |
| 6286 |
} |
| 6287 |
} |
| 6288 |
|
| 6289 |
var scheduleFlush = void 0; |
| 6290 |
// Decide what async method to use to triggering processing of queued callbacks: |
| 6291 |
if (isNode) { |
| 6292 |
scheduleFlush = useNextTick(); |
| 6293 |
} else if (BrowserMutationObserver) { |
| 6294 |
scheduleFlush = useMutationObserver(); |
| 6295 |
} else if (isWorker) { |
| 6296 |
scheduleFlush = useMessageChannel(); |
| 6297 |
} else if (browserWindow === undefined && "function" === 'function') { |
| 6298 |
scheduleFlush = attemptVertx(); |
| 6299 |
} else { |
| 6300 |
scheduleFlush = useSetTimeout(); |
| 6301 |
} |
| 6302 |
|
| 6303 |
function then(onFulfillment, onRejection) { |
| 6304 |
var parent = this; |
| 6305 |
|
| 6306 |
var child = new this.constructor(noop); |
| 6307 |
|
| 6308 |
if (child[PROMISE_ID] === undefined) { |
| 6309 |
makePromise(child); |
| 6310 |
} |
| 6311 |
|
| 6312 |
var _state = parent._state; |
| 6313 |
|
| 6314 |
|
| 6315 |
if (_state) { |
| 6316 |
var callback = arguments[_state - 1]; |
| 6317 |
asap(function () { |
| 6318 |
return invokeCallback(_state, child, callback, parent._result); |
| 6319 |
}); |
| 6320 |
} else { |
| 6321 |
subscribe(parent, child, onFulfillment, onRejection); |
| 6322 |
} |
| 6323 |
|
| 6324 |
return child; |
| 6325 |
} |
| 6326 |
|
| 6327 |
/** |
| 6328 |
`Promise.resolve` returns a promise that will become resolved with the |
| 6329 |
passed `value`. It is shorthand for the following: |
| 6330 |
|
| 6331 |
```javascript |
| 6332 |
let promise = new Promise(function(resolve, reject){ |
| 6333 |
resolve(1); |
| 6334 |
}); |
| 6335 |
|
| 6336 |
promise.then(function(value){ |
| 6337 |
// value === 1 |
| 6338 |
}); |
| 6339 |
``` |
| 6340 |
|
| 6341 |
Instead of writing the above, your code now simply becomes the following: |
| 6342 |
|
| 6343 |
```javascript |
| 6344 |
let promise = Promise.resolve(1); |
| 6345 |
|
| 6346 |
promise.then(function(value){ |
| 6347 |
// value === 1 |
| 6348 |
}); |
| 6349 |
``` |
| 6350 |
|
| 6351 |
@method resolve |
| 6352 |
@static |
| 6353 |
@param {Any} value value that the returned promise will be resolved with |
| 6354 |
Useful for tooling. |
| 6355 |
@return {Promise} a promise that will become fulfilled with the given |
| 6356 |
`value` |
| 6357 |
*/ |
| 6358 |
function resolve$1(object) { |
| 6359 |
/*jshint validthis:true */ |
| 6360 |
var Constructor = this; |
| 6361 |
|
| 6362 |
if (object && typeof object === 'object' && object.constructor === Constructor) { |
| 6363 |
return object; |
| 6364 |
} |
| 6365 |
|
| 6366 |
var promise = new Constructor(noop); |
| 6367 |
resolve(promise, object); |
| 6368 |
return promise; |
| 6369 |
} |
| 6370 |
|
| 6371 |
var PROMISE_ID = Math.random().toString(36).substring(2); |
| 6372 |
|
| 6373 |
function noop() {} |
| 6374 |
|
| 6375 |
var PENDING = void 0; |
| 6376 |
var FULFILLED = 1; |
| 6377 |
var REJECTED = 2; |
| 6378 |
|
| 6379 |
var TRY_CATCH_ERROR = { error: null }; |
| 6380 |
|
| 6381 |
function selfFulfillment() { |
| 6382 |
return new TypeError("You cannot resolve a promise with itself"); |
| 6383 |
} |
| 6384 |
|
| 6385 |
function cannotReturnOwn() { |
| 6386 |
return new TypeError('A promises callback cannot return that same promise.'); |
| 6387 |
} |
| 6388 |
|
| 6389 |
function getThen(promise) { |
| 6390 |
try { |
| 6391 |
return promise.then; |
| 6392 |
} catch (error) { |
| 6393 |
TRY_CATCH_ERROR.error = error; |
| 6394 |
return TRY_CATCH_ERROR; |
| 6395 |
} |
| 6396 |
} |
| 6397 |
|
| 6398 |
function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { |
| 6399 |
try { |
| 6400 |
then$$1.call(value, fulfillmentHandler, rejectionHandler); |
| 6401 |
} catch (e) { |
| 6402 |
return e; |
| 6403 |
} |
| 6404 |
} |
| 6405 |
|
| 6406 |
function handleForeignThenable(promise, thenable, then$$1) { |
| 6407 |
asap(function (promise) { |
| 6408 |
var sealed = false; |
| 6409 |
var error = tryThen(then$$1, thenable, function (value) { |
| 6410 |
if (sealed) { |
| 6411 |
return; |
| 6412 |
} |
| 6413 |
sealed = true; |
| 6414 |
if (thenable !== value) { |
| 6415 |
resolve(promise, value); |
| 6416 |
} else { |
| 6417 |
fulfill(promise, value); |
| 6418 |
} |
| 6419 |
}, function (reason) { |
| 6420 |
if (sealed) { |
| 6421 |
return; |
| 6422 |
} |
| 6423 |
sealed = true; |
| 6424 |
|
| 6425 |
reject(promise, reason); |
| 6426 |
}, 'Settle: ' + (promise._label || ' unknown promise')); |
| 6427 |
|
| 6428 |
if (!sealed && error) { |
| 6429 |
sealed = true; |
| 6430 |
reject(promise, error); |
| 6431 |
} |
| 6432 |
}, promise); |
| 6433 |
} |
| 6434 |
|
| 6435 |
function handleOwnThenable(promise, thenable) { |
| 6436 |
if (thenable._state === FULFILLED) { |
| 6437 |
fulfill(promise, thenable._result); |
| 6438 |
} else if (thenable._state === REJECTED) { |
| 6439 |
reject(promise, thenable._result); |
| 6440 |
} else { |
| 6441 |
subscribe(thenable, undefined, function (value) { |
| 6442 |
return resolve(promise, value); |
| 6443 |
}, function (reason) { |
| 6444 |
return reject(promise, reason); |
| 6445 |
}); |
| 6446 |
} |
| 6447 |
} |
| 6448 |
|
| 6449 |
function handleMaybeThenable(promise, maybeThenable, then$$1) { |
| 6450 |
if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) { |
| 6451 |
handleOwnThenable(promise, maybeThenable); |
| 6452 |
} else { |
| 6453 |
if (then$$1 === TRY_CATCH_ERROR) { |
| 6454 |
reject(promise, TRY_CATCH_ERROR.error); |
| 6455 |
TRY_CATCH_ERROR.error = null; |
| 6456 |
} else if (then$$1 === undefined) { |
| 6457 |
fulfill(promise, maybeThenable); |
| 6458 |
} else if (isFunction(then$$1)) { |
| 6459 |
handleForeignThenable(promise, maybeThenable, then$$1); |
| 6460 |
} else { |
| 6461 |
fulfill(promise, maybeThenable); |
| 6462 |
} |
| 6463 |
} |
| 6464 |
} |
| 6465 |
|
| 6466 |
function resolve(promise, value) { |
| 6467 |
if (promise === value) { |
| 6468 |
reject(promise, selfFulfillment()); |
| 6469 |
} else if (objectOrFunction(value)) { |
| 6470 |
handleMaybeThenable(promise, value, getThen(value)); |
| 6471 |
} else { |
| 6472 |
fulfill(promise, value); |
| 6473 |
} |
| 6474 |
} |
| 6475 |
|
| 6476 |
function publishRejection(promise) { |
| 6477 |
if (promise._onerror) { |
| 6478 |
promise._onerror(promise._result); |
| 6479 |
} |
| 6480 |
|
| 6481 |
publish(promise); |
| 6482 |
} |
| 6483 |
|
| 6484 |
function fulfill(promise, value) { |
| 6485 |
if (promise._state !== PENDING) { |
| 6486 |
return; |
| 6487 |
} |
| 6488 |
|
| 6489 |
promise._result = value; |
| 6490 |
promise._state = FULFILLED; |
| 6491 |
|
| 6492 |
if (promise._subscribers.length !== 0) { |
| 6493 |
asap(publish, promise); |
| 6494 |
} |
| 6495 |
} |
| 6496 |
|
| 6497 |
function reject(promise, reason) { |
| 6498 |
if (promise._state !== PENDING) { |
| 6499 |
return; |
| 6500 |
} |
| 6501 |
promise._state = REJECTED; |
| 6502 |
promise._result = reason; |
| 6503 |
|
| 6504 |
asap(publishRejection, promise); |
| 6505 |
} |
| 6506 |
|
| 6507 |
function subscribe(parent, child, onFulfillment, onRejection) { |
| 6508 |
var _subscribers = parent._subscribers; |
| 6509 |
var length = _subscribers.length; |
| 6510 |
|
| 6511 |
|
| 6512 |
parent._onerror = null; |
| 6513 |
|
| 6514 |
_subscribers[length] = child; |
| 6515 |
_subscribers[length + FULFILLED] = onFulfillment; |
| 6516 |
_subscribers[length + REJECTED] = onRejection; |
| 6517 |
|
| 6518 |
if (length === 0 && parent._state) { |
| 6519 |
asap(publish, parent); |
| 6520 |
} |
| 6521 |
} |
| 6522 |
|
| 6523 |
function publish(promise) { |
| 6524 |
var subscribers = promise._subscribers; |
| 6525 |
var settled = promise._state; |
| 6526 |
|
| 6527 |
if (subscribers.length === 0) { |
| 6528 |
return; |
| 6529 |
} |
| 6530 |
|
| 6531 |
var child = void 0, |
| 6532 |
callback = void 0, |
| 6533 |
detail = promise._result; |
| 6534 |
|
| 6535 |
for (var i = 0; i < subscribers.length; i += 3) { |
| 6536 |
child = subscribers[i]; |
| 6537 |
callback = subscribers[i + settled]; |
| 6538 |
|
| 6539 |
if (child) { |
| 6540 |
invokeCallback(settled, child, callback, detail); |
| 6541 |
} else { |
| 6542 |
callback(detail); |
| 6543 |
} |
| 6544 |
} |
| 6545 |
|
| 6546 |
promise._subscribers.length = 0; |
| 6547 |
} |
| 6548 |
|
| 6549 |
function tryCatch(callback, detail) { |
| 6550 |
try { |
| 6551 |
return callback(detail); |
| 6552 |
} catch (e) { |
| 6553 |
TRY_CATCH_ERROR.error = e; |
| 6554 |
return TRY_CATCH_ERROR; |
| 6555 |
} |
| 6556 |
} |
| 6557 |
|
| 6558 |
function invokeCallback(settled, promise, callback, detail) { |
| 6559 |
var hasCallback = isFunction(callback), |
| 6560 |
value = void 0, |
| 6561 |
error = void 0, |
| 6562 |
succeeded = void 0, |
| 6563 |
failed = void 0; |
| 6564 |
|
| 6565 |
if (hasCallback) { |
| 6566 |
value = tryCatch(callback, detail); |
| 6567 |
|
| 6568 |
if (value === TRY_CATCH_ERROR) { |
| 6569 |
failed = true; |
| 6570 |
error = value.error; |
| 6571 |
value.error = null; |
| 6572 |
} else { |
| 6573 |
succeeded = true; |
| 6574 |
} |
| 6575 |
|
| 6576 |
if (promise === value) { |
| 6577 |
reject(promise, cannotReturnOwn()); |
| 6578 |
return; |
| 6579 |
} |
| 6580 |
} else { |
| 6581 |
value = detail; |
| 6582 |
succeeded = true; |
| 6583 |
} |
| 6584 |
|
| 6585 |
if (promise._state !== PENDING) { |
| 6586 |
// noop |
| 6587 |
} else if (hasCallback && succeeded) { |
| 6588 |
resolve(promise, value); |
| 6589 |
} else if (failed) { |
| 6590 |
reject(promise, error); |
| 6591 |
} else if (settled === FULFILLED) { |
| 6592 |
fulfill(promise, value); |
| 6593 |
} else if (settled === REJECTED) { |
| 6594 |
reject(promise, value); |
| 6595 |
} |
| 6596 |
} |
| 6597 |
|
| 6598 |
function initializePromise(promise, resolver) { |
| 6599 |
try { |
| 6600 |
resolver(function resolvePromise(value) { |
| 6601 |
resolve(promise, value); |
| 6602 |
}, function rejectPromise(reason) { |
| 6603 |
reject(promise, reason); |
| 6604 |
}); |
| 6605 |
} catch (e) { |
| 6606 |
reject(promise, e); |
| 6607 |
} |
| 6608 |
} |
| 6609 |
|
| 6610 |
var id = 0; |
| 6611 |
function nextId() { |
| 6612 |
return id++; |
| 6613 |
} |
| 6614 |
|
| 6615 |
function makePromise(promise) { |
| 6616 |
promise[PROMISE_ID] = id++; |
| 6617 |
promise._state = undefined; |
| 6618 |
promise._result = undefined; |
| 6619 |
promise._subscribers = []; |
| 6620 |
} |
| 6621 |
|
| 6622 |
function validationError() { |
| 6623 |
return new Error('Array Methods must be provided an Array'); |
| 6624 |
} |
| 6625 |
|
| 6626 |
var Enumerator = function () { |
| 6627 |
function Enumerator(Constructor, input) { |
| 6628 |
this._instanceConstructor = Constructor; |
| 6629 |
this.promise = new Constructor(noop); |
| 6630 |
|
| 6631 |
if (!this.promise[PROMISE_ID]) { |
| 6632 |
makePromise(this.promise); |
| 6633 |
} |
| 6634 |
|
| 6635 |
if (isArray(input)) { |
| 6636 |
this.length = input.length; |
| 6637 |
this._remaining = input.length; |
| 6638 |
|
| 6639 |
this._result = new Array(this.length); |
| 6640 |
|
| 6641 |
if (this.length === 0) { |
| 6642 |
fulfill(this.promise, this._result); |
| 6643 |
} else { |
| 6644 |
this.length = this.length || 0; |
| 6645 |
this._enumerate(input); |
| 6646 |
if (this._remaining === 0) { |
| 6647 |
fulfill(this.promise, this._result); |
| 6648 |
} |
| 6649 |
} |
| 6650 |
} else { |
| 6651 |
reject(this.promise, validationError()); |
| 6652 |
} |
| 6653 |
} |
| 6654 |
|
| 6655 |
Enumerator.prototype._enumerate = function _enumerate(input) { |
| 6656 |
for (var i = 0; this._state === PENDING && i < input.length; i++) { |
| 6657 |
this._eachEntry(input[i], i); |
| 6658 |
} |
| 6659 |
}; |
| 6660 |
|
| 6661 |
Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { |
| 6662 |
var c = this._instanceConstructor; |
| 6663 |
var resolve$$1 = c.resolve; |
| 6664 |
|
| 6665 |
|
| 6666 |
if (resolve$$1 === resolve$1) { |
| 6667 |
var _then = getThen(entry); |
| 6668 |
|
| 6669 |
if (_then === then && entry._state !== PENDING) { |
| 6670 |
this._settledAt(entry._state, i, entry._result); |
| 6671 |
} else if (typeof _then !== 'function') { |
| 6672 |
this._remaining--; |
| 6673 |
this._result[i] = entry; |
| 6674 |
} else if (c === Promise$1) { |
| 6675 |
var promise = new c(noop); |
| 6676 |
handleMaybeThenable(promise, entry, _then); |
| 6677 |
this._willSettleAt(promise, i); |
| 6678 |
} else { |
| 6679 |
this._willSettleAt(new c(function (resolve$$1) { |
| 6680 |
return resolve$$1(entry); |
| 6681 |
}), i); |
| 6682 |
} |
| 6683 |
} else { |
| 6684 |
this._willSettleAt(resolve$$1(entry), i); |
| 6685 |
} |
| 6686 |
}; |
| 6687 |
|
| 6688 |
Enumerator.prototype._settledAt = function _settledAt(state, i, value) { |
| 6689 |
var promise = this.promise; |
| 6690 |
|
| 6691 |
|
| 6692 |
if (promise._state === PENDING) { |
| 6693 |
this._remaining--; |
| 6694 |
|
| 6695 |
if (state === REJECTED) { |
| 6696 |
reject(promise, value); |
| 6697 |
} else { |
| 6698 |
this._result[i] = value; |
| 6699 |
} |
| 6700 |
} |
| 6701 |
|
| 6702 |
if (this._remaining === 0) { |
| 6703 |
fulfill(promise, this._result); |
| 6704 |
} |
| 6705 |
}; |
| 6706 |
|
| 6707 |
Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { |
| 6708 |
var enumerator = this; |
| 6709 |
|
| 6710 |
subscribe(promise, undefined, function (value) { |
| 6711 |
return enumerator._settledAt(FULFILLED, i, value); |
| 6712 |
}, function (reason) { |
| 6713 |
return enumerator._settledAt(REJECTED, i, reason); |
| 6714 |
}); |
| 6715 |
}; |
| 6716 |
|
| 6717 |
return Enumerator; |
| 6718 |
}(); |
| 6719 |
|
| 6720 |
/** |
| 6721 |
`Promise.all` accepts an array of promises, and returns a new promise which |
| 6722 |
is fulfilled with an array of fulfillment values for the passed promises, or |
| 6723 |
rejected with the reason of the first passed promise to be rejected. It casts all |
| 6724 |
elements of the passed iterable to promises as it runs this algorithm. |
| 6725 |
|
| 6726 |
Example: |
| 6727 |
|
| 6728 |
```javascript |
| 6729 |
let promise1 = resolve(1); |
| 6730 |
let promise2 = resolve(2); |
| 6731 |
let promise3 = resolve(3); |
| 6732 |
let promises = [ promise1, promise2, promise3 ]; |
| 6733 |
|
| 6734 |
Promise.all(promises).then(function(array){ |
| 6735 |
// The array here would be [ 1, 2, 3 ]; |
| 6736 |
}); |
| 6737 |
``` |
| 6738 |
|
| 6739 |
If any of the `promises` given to `all` are rejected, the first promise |
| 6740 |
that is rejected will be given as an argument to the returned promises's |
| 6741 |
rejection handler. For example: |
| 6742 |
|
| 6743 |
Example: |
| 6744 |
|
| 6745 |
```javascript |
| 6746 |
let promise1 = resolve(1); |
| 6747 |
let promise2 = reject(new Error("2")); |
| 6748 |
let promise3 = reject(new Error("3")); |
| 6749 |
let promises = [ promise1, promise2, promise3 ]; |
| 6750 |
|
| 6751 |
Promise.all(promises).then(function(array){ |
| 6752 |
// Code here never runs because there are rejected promises! |
| 6753 |
}, function(error) { |
| 6754 |
// error.message === "2" |
| 6755 |
}); |
| 6756 |
``` |
| 6757 |
|
| 6758 |
@method all |
| 6759 |
@static |
| 6760 |
@param {Array} entries array of promises |
| 6761 |
@param {String} label optional string for labeling the promise. |
| 6762 |
Useful for tooling. |
| 6763 |
@return {Promise} promise that is fulfilled when all `promises` have been |
| 6764 |
fulfilled, or rejected if any of them become rejected. |
| 6765 |
@static |
| 6766 |
*/ |
| 6767 |
function all(entries) { |
| 6768 |
return new Enumerator(this, entries).promise; |
| 6769 |
} |
| 6770 |
|
| 6771 |
/** |
| 6772 |
`Promise.race` returns a new promise which is settled in the same way as the |
| 6773 |
first passed promise to settle. |
| 6774 |
|
| 6775 |
Example: |
| 6776 |
|
| 6777 |
```javascript |
| 6778 |
let promise1 = new Promise(function(resolve, reject){ |
| 6779 |
setTimeout(function(){ |
| 6780 |
resolve('promise 1'); |
| 6781 |
}, 200); |
| 6782 |
}); |
| 6783 |
|
| 6784 |
let promise2 = new Promise(function(resolve, reject){ |
| 6785 |
setTimeout(function(){ |
| 6786 |
resolve('promise 2'); |
| 6787 |
}, 100); |
| 6788 |
}); |
| 6789 |
|
| 6790 |
Promise.race([promise1, promise2]).then(function(result){ |
| 6791 |
// result === 'promise 2' because it was resolved before promise1 |
| 6792 |
// was resolved. |
| 6793 |
}); |
| 6794 |
``` |
| 6795 |
|
| 6796 |
`Promise.race` is deterministic in that only the state of the first |
| 6797 |
settled promise matters. For example, even if other promises given to the |
| 6798 |
`promises` array argument are resolved, but the first settled promise has |
| 6799 |
become rejected before the other promises became fulfilled, the returned |
| 6800 |
promise will become rejected: |
| 6801 |
|
| 6802 |
```javascript |
| 6803 |
let promise1 = new Promise(function(resolve, reject){ |
| 6804 |
setTimeout(function(){ |
| 6805 |
resolve('promise 1'); |
| 6806 |
}, 200); |
| 6807 |
}); |
| 6808 |
|
| 6809 |
let promise2 = new Promise(function(resolve, reject){ |
| 6810 |
setTimeout(function(){ |
| 6811 |
reject(new Error('promise 2')); |
| 6812 |
}, 100); |
| 6813 |
}); |
| 6814 |
|
| 6815 |
Promise.race([promise1, promise2]).then(function(result){ |
| 6816 |
// Code here never runs |
| 6817 |
}, function(reason){ |
| 6818 |
// reason.message === 'promise 2' because promise 2 became rejected before |
| 6819 |
// promise 1 became fulfilled |
| 6820 |
}); |
| 6821 |
``` |
| 6822 |
|
| 6823 |
An example real-world use case is implementing timeouts: |
| 6824 |
|
| 6825 |
```javascript |
| 6826 |
Promise.race([ajax('foo.json'), timeout(5000)]) |
| 6827 |
``` |
| 6828 |
|
| 6829 |
@method race |
| 6830 |
@static |
| 6831 |
@param {Array} promises array of promises to observe |
| 6832 |
Useful for tooling. |
| 6833 |
@return {Promise} a promise which settles in the same way as the first passed |
| 6834 |
promise to settle. |
| 6835 |
*/ |
| 6836 |
function race(entries) { |
| 6837 |
/*jshint validthis:true */ |
| 6838 |
var Constructor = this; |
| 6839 |
|
| 6840 |
if (!isArray(entries)) { |
| 6841 |
return new Constructor(function (_, reject) { |
| 6842 |
return reject(new TypeError('You must pass an array to race.')); |
| 6843 |
}); |
| 6844 |
} else { |
| 6845 |
return new Constructor(function (resolve, reject) { |
| 6846 |
var length = entries.length; |
| 6847 |
for (var i = 0; i < length; i++) { |
| 6848 |
Constructor.resolve(entries[i]).then(resolve, reject); |
| 6849 |
} |
| 6850 |
}); |
| 6851 |
} |
| 6852 |
} |
| 6853 |
|
| 6854 |
/** |
| 6855 |
`Promise.reject` returns a promise rejected with the passed `reason`. |
| 6856 |
It is shorthand for the following: |
| 6857 |
|
| 6858 |
```javascript |
| 6859 |
let promise = new Promise(function(resolve, reject){ |
| 6860 |
reject(new Error('WHOOPS')); |
| 6861 |
}); |
| 6862 |
|
| 6863 |
promise.then(function(value){ |
| 6864 |
// Code here doesn't run because the promise is rejected! |
| 6865 |
}, function(reason){ |
| 6866 |
// reason.message === 'WHOOPS' |
| 6867 |
}); |
| 6868 |
``` |
| 6869 |
|
| 6870 |
Instead of writing the above, your code now simply becomes the following: |
| 6871 |
|
| 6872 |
```javascript |
| 6873 |
let promise = Promise.reject(new Error('WHOOPS')); |
| 6874 |
|
| 6875 |
promise.then(function(value){ |
| 6876 |
// Code here doesn't run because the promise is rejected! |
| 6877 |
}, function(reason){ |
| 6878 |
// reason.message === 'WHOOPS' |
| 6879 |
}); |
| 6880 |
``` |
| 6881 |
|
| 6882 |
@method reject |
| 6883 |
@static |
| 6884 |
@param {Any} reason value that the returned promise will be rejected with. |
| 6885 |
Useful for tooling. |
| 6886 |
@return {Promise} a promise rejected with the given `reason`. |
| 6887 |
*/ |
| 6888 |
function reject$1(reason) { |
| 6889 |
/*jshint validthis:true */ |
| 6890 |
var Constructor = this; |
| 6891 |
var promise = new Constructor(noop); |
| 6892 |
reject(promise, reason); |
| 6893 |
return promise; |
| 6894 |
} |
| 6895 |
|
| 6896 |
function needsResolver() { |
| 6897 |
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); |
| 6898 |
} |
| 6899 |
|
| 6900 |
function needsNew() { |
| 6901 |
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); |
| 6902 |
} |
| 6903 |
|
| 6904 |
/** |
| 6905 |
Promise objects represent the eventual result of an asynchronous operation. The |
| 6906 |
primary way of interacting with a promise is through its `then` method, which |
| 6907 |
registers callbacks to receive either a promise's eventual value or the reason |
| 6908 |
why the promise cannot be fulfilled. |
| 6909 |
|
| 6910 |
Terminology |
| 6911 |
----------- |
| 6912 |
|
| 6913 |
- `promise` is an object or function with a `then` method whose behavior conforms to this specification. |
| 6914 |
- `thenable` is an object or function that defines a `then` method. |
| 6915 |
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise). |
| 6916 |
- `exception` is a value that is thrown using the throw statement. |
| 6917 |
- `reason` is a value that indicates why a promise was rejected. |
| 6918 |
- `settled` the final resting state of a promise, fulfilled or rejected. |
| 6919 |
|
| 6920 |
A promise can be in one of three states: pending, fulfilled, or rejected. |
| 6921 |
|
| 6922 |
Promises that are fulfilled have a fulfillment value and are in the fulfilled |
| 6923 |
state. Promises that are rejected have a rejection reason and are in the |
| 6924 |
rejected state. A fulfillment value is never a thenable. |
| 6925 |
|
| 6926 |
Promises can also be said to *resolve* a value. If this value is also a |
| 6927 |
promise, then the original promise's settled state will match the value's |
| 6928 |
settled state. So a promise that *resolves* a promise that rejects will |
| 6929 |
itself reject, and a promise that *resolves* a promise that fulfills will |
| 6930 |
itself fulfill. |
| 6931 |
|
| 6932 |
|
| 6933 |
Basic Usage: |
| 6934 |
------------ |
| 6935 |
|
| 6936 |
```js |
| 6937 |
let promise = new Promise(function(resolve, reject) { |
| 6938 |
// on success |
| 6939 |
resolve(value); |
| 6940 |
|
| 6941 |
// on failure |
| 6942 |
reject(reason); |
| 6943 |
}); |
| 6944 |
|
| 6945 |
promise.then(function(value) { |
| 6946 |
// on fulfillment |
| 6947 |
}, function(reason) { |
| 6948 |
// on rejection |
| 6949 |
}); |
| 6950 |
``` |
| 6951 |
|
| 6952 |
Advanced Usage: |
| 6953 |
--------------- |
| 6954 |
|
| 6955 |
Promises shine when abstracting away asynchronous interactions such as |
| 6956 |
`XMLHttpRequest`s. |
| 6957 |
|
| 6958 |
```js |
| 6959 |
function getJSON(url) { |
| 6960 |
return new Promise(function(resolve, reject){ |
| 6961 |
let xhr = new XMLHttpRequest(); |
| 6962 |
|
| 6963 |
xhr.open('GET', url); |
| 6964 |
xhr.onreadystatechange = handler; |
| 6965 |
xhr.responseType = 'json'; |
| 6966 |
xhr.setRequestHeader('Accept', 'application/json'); |
| 6967 |
xhr.send(); |
| 6968 |
|
| 6969 |
function handler() { |
| 6970 |
if (this.readyState === this.DONE) { |
| 6971 |
if (this.status === 200) { |
| 6972 |
resolve(this.response); |
| 6973 |
} else { |
| 6974 |
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); |
| 6975 |
} |
| 6976 |
} |
| 6977 |
}; |
| 6978 |
}); |
| 6979 |
} |
| 6980 |
|
| 6981 |
getJSON('/posts.json').then(function(json) { |
| 6982 |
// on fulfillment |
| 6983 |
}, function(reason) { |
| 6984 |
// on rejection |
| 6985 |
}); |
| 6986 |
``` |
| 6987 |
|
| 6988 |
Unlike callbacks, promises are great composable primitives. |
| 6989 |
|
| 6990 |
```js |
| 6991 |
Promise.all([ |
| 6992 |
getJSON('/posts'), |
| 6993 |
getJSON('/comments') |
| 6994 |
]).then(function(values){ |
| 6995 |
values[0] // => postsJSON |
| 6996 |
values[1] // => commentsJSON |
| 6997 |
|
| 6998 |
return values; |
| 6999 |
}); |
| 7000 |
``` |
| 7001 |
|
| 7002 |
@class Promise |
| 7003 |
@param {Function} resolver |
| 7004 |
Useful for tooling. |
| 7005 |
@constructor |
| 7006 |
*/ |
| 7007 |
|
| 7008 |
var Promise$1 = function () { |
| 7009 |
function Promise(resolver) { |
| 7010 |
this[PROMISE_ID] = nextId(); |
| 7011 |
this._result = this._state = undefined; |
| 7012 |
this._subscribers = []; |
| 7013 |
|
| 7014 |
if (noop !== resolver) { |
| 7015 |
typeof resolver !== 'function' && needsResolver(); |
| 7016 |
this instanceof Promise ? initializePromise(this, resolver) : needsNew(); |
| 7017 |
} |
| 7018 |
} |
| 7019 |
|
| 7020 |
/** |
| 7021 |
The primary way of interacting with a promise is through its `then` method, |
| 7022 |
which registers callbacks to receive either a promise's eventual value or the |
| 7023 |
reason why the promise cannot be fulfilled. |
| 7024 |
```js |
| 7025 |
findUser().then(function(user){ |
| 7026 |
// user is available |
| 7027 |
}, function(reason){ |
| 7028 |
// user is unavailable, and you are given the reason why |
| 7029 |
}); |
| 7030 |
``` |
| 7031 |
Chaining |
| 7032 |
-------- |
| 7033 |
The return value of `then` is itself a promise. This second, 'downstream' |
| 7034 |
promise is resolved with the return value of the first promise's fulfillment |
| 7035 |
or rejection handler, or rejected if the handler throws an exception. |
| 7036 |
```js |
| 7037 |
findUser().then(function (user) { |
| 7038 |
return user.name; |
| 7039 |
}, function (reason) { |
| 7040 |
return 'default name'; |
| 7041 |
}).then(function (userName) { |
| 7042 |
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it |
| 7043 |
// will be `'default name'` |
| 7044 |
}); |
| 7045 |
findUser().then(function (user) { |
| 7046 |
throw new Error('Found user, but still unhappy'); |
| 7047 |
}, function (reason) { |
| 7048 |
throw new Error('`findUser` rejected and we're unhappy'); |
| 7049 |
}).then(function (value) { |
| 7050 |
// never reached |
| 7051 |
}, function (reason) { |
| 7052 |
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. |
| 7053 |
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. |
| 7054 |
}); |
| 7055 |
``` |
| 7056 |
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. |
| 7057 |
```js |
| 7058 |
findUser().then(function (user) { |
| 7059 |
throw new PedagogicalException('Upstream error'); |
| 7060 |
}).then(function (value) { |
| 7061 |
// never reached |
| 7062 |
}).then(function (value) { |
| 7063 |
// never reached |
| 7064 |
}, function (reason) { |
| 7065 |
// The `PedgagocialException` is propagated all the way down to here |
| 7066 |
}); |
| 7067 |
``` |
| 7068 |
Assimilation |
| 7069 |
------------ |
| 7070 |
Sometimes the value you want to propagate to a downstream promise can only be |
| 7071 |
retrieved asynchronously. This can be achieved by returning a promise in the |
| 7072 |
fulfillment or rejection handler. The downstream promise will then be pending |
| 7073 |
until the returned promise is settled. This is called *assimilation*. |
| 7074 |
```js |
| 7075 |
findUser().then(function (user) { |
| 7076 |
return findCommentsByAuthor(user); |
| 7077 |
}).then(function (comments) { |
| 7078 |
// The user's comments are now available |
| 7079 |
}); |
| 7080 |
``` |
| 7081 |
If the assimliated promise rejects, then the downstream promise will also reject. |
| 7082 |
```js |
| 7083 |
findUser().then(function (user) { |
| 7084 |
return findCommentsByAuthor(user); |
| 7085 |
}).then(function (comments) { |
| 7086 |
// If `findCommentsByAuthor` fulfills, we'll have the value here |
| 7087 |
}, function (reason) { |
| 7088 |
// If `findCommentsByAuthor` rejects, we'll have the reason here |
| 7089 |
}); |
| 7090 |
``` |
| 7091 |
Simple Example |
| 7092 |
-------------- |
| 7093 |
Synchronous Example |
| 7094 |
```javascript |
| 7095 |
let result; |
| 7096 |
try { |
| 7097 |
result = findResult(); |
| 7098 |
// success |
| 7099 |
} catch(reason) { |
| 7100 |
// failure |
| 7101 |
} |
| 7102 |
``` |
| 7103 |
Errback Example |
| 7104 |
```js |
| 7105 |
findResult(function(result, err){ |
| 7106 |
if (err) { |
| 7107 |
// failure |
| 7108 |
} else { |
| 7109 |
// success |
| 7110 |
} |
| 7111 |
}); |
| 7112 |
``` |
| 7113 |
Promise Example; |
| 7114 |
```javascript |
| 7115 |
findResult().then(function(result){ |
| 7116 |
// success |
| 7117 |
}, function(reason){ |
| 7118 |
// failure |
| 7119 |
}); |
| 7120 |
``` |
| 7121 |
Advanced Example |
| 7122 |
-------------- |
| 7123 |
Synchronous Example |
| 7124 |
```javascript |
| 7125 |
let author, books; |
| 7126 |
try { |
| 7127 |
author = findAuthor(); |
| 7128 |
books = findBooksByAuthor(author); |
| 7129 |
// success |
| 7130 |
} catch(reason) { |
| 7131 |
// failure |
| 7132 |
} |
| 7133 |
``` |
| 7134 |
Errback Example |
| 7135 |
```js |
| 7136 |
function foundBooks(books) { |
| 7137 |
} |
| 7138 |
function failure(reason) { |
| 7139 |
} |
| 7140 |
findAuthor(function(author, err){ |
| 7141 |
if (err) { |
| 7142 |
failure(err); |
| 7143 |
// failure |
| 7144 |
} else { |
| 7145 |
try { |
| 7146 |
findBoooksByAuthor(author, function(books, err) { |
| 7147 |
if (err) { |
| 7148 |
failure(err); |
| 7149 |
} else { |
| 7150 |
try { |
| 7151 |
foundBooks(books); |
| 7152 |
} catch(reason) { |
| 7153 |
failure(reason); |
| 7154 |
} |
| 7155 |
} |
| 7156 |
}); |
| 7157 |
} catch(error) { |
| 7158 |
failure(err); |
| 7159 |
} |
| 7160 |
// success |
| 7161 |
} |
| 7162 |
}); |
| 7163 |
``` |
| 7164 |
Promise Example; |
| 7165 |
```javascript |
| 7166 |
findAuthor(). |
| 7167 |
then(findBooksByAuthor). |
| 7168 |
then(function(books){ |
| 7169 |
// found books |
| 7170 |
}).catch(function(reason){ |
| 7171 |
// something went wrong |
| 7172 |
}); |
| 7173 |
``` |
| 7174 |
@method then |
| 7175 |
@param {Function} onFulfilled |
| 7176 |
@param {Function} onRejected |
| 7177 |
Useful for tooling. |
| 7178 |
@return {Promise} |
| 7179 |
*/ |
| 7180 |
|
| 7181 |
/** |
| 7182 |
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same |
| 7183 |
as the catch block of a try/catch statement. |
| 7184 |
```js |
| 7185 |
function findAuthor(){ |
| 7186 |
throw new Error('couldn't find that author'); |
| 7187 |
} |
| 7188 |
// synchronous |
| 7189 |
try { |
| 7190 |
findAuthor(); |
| 7191 |
} catch(reason) { |
| 7192 |
// something went wrong |
| 7193 |
} |
| 7194 |
// async with promises |
| 7195 |
findAuthor().catch(function(reason){ |
| 7196 |
// something went wrong |
| 7197 |
}); |
| 7198 |
``` |
| 7199 |
@method catch |
| 7200 |
@param {Function} onRejection |
| 7201 |
Useful for tooling. |
| 7202 |
@return {Promise} |
| 7203 |
*/ |
| 7204 |
|
| 7205 |
|
| 7206 |
Promise.prototype.catch = function _catch(onRejection) { |
| 7207 |
return this.then(null, onRejection); |
| 7208 |
}; |
| 7209 |
|
| 7210 |
/** |
| 7211 |
`finally` will be invoked regardless of the promise's fate just as native |
| 7212 |
try/catch/finally behaves |
| 7213 |
|
| 7214 |
Synchronous example: |
| 7215 |
|
| 7216 |
```js |
| 7217 |
findAuthor() { |
| 7218 |
if (Math.random() > 0.5) { |
| 7219 |
throw new Error(); |
| 7220 |
} |
| 7221 |
return new Author(); |
| 7222 |
} |
| 7223 |
|
| 7224 |
try { |
| 7225 |
return findAuthor(); // succeed or fail |
| 7226 |
} catch(error) { |
| 7227 |
return findOtherAuther(); |
| 7228 |
} finally { |
| 7229 |
// always runs |
| 7230 |
// doesn't affect the return value |
| 7231 |
} |
| 7232 |
``` |
| 7233 |
|
| 7234 |
Asynchronous example: |
| 7235 |
|
| 7236 |
```js |
| 7237 |
findAuthor().catch(function(reason){ |
| 7238 |
return findOtherAuther(); |
| 7239 |
}).finally(function(){ |
| 7240 |
// author was either found, or not |
| 7241 |
}); |
| 7242 |
``` |
| 7243 |
|
| 7244 |
@method finally |
| 7245 |
@param {Function} callback |
| 7246 |
@return {Promise} |
| 7247 |
*/ |
| 7248 |
|
| 7249 |
|
| 7250 |
Promise.prototype.finally = function _finally(callback) { |
| 7251 |
var promise = this; |
| 7252 |
var constructor = promise.constructor; |
| 7253 |
|
| 7254 |
return promise.then(function (value) { |
| 7255 |
return constructor.resolve(callback()).then(function () { |
| 7256 |
return value; |
| 7257 |
}); |
| 7258 |
}, function (reason) { |
| 7259 |
return constructor.resolve(callback()).then(function () { |
| 7260 |
throw reason; |
| 7261 |
}); |
| 7262 |
}); |
| 7263 |
}; |
| 7264 |
|
| 7265 |
return Promise; |
| 7266 |
}(); |
| 7267 |
|
| 7268 |
Promise$1.prototype.then = then; |
| 7269 |
Promise$1.all = all; |
| 7270 |
Promise$1.race = race; |
| 7271 |
Promise$1.resolve = resolve$1; |
| 7272 |
Promise$1.reject = reject$1; |
| 7273 |
Promise$1._setScheduler = setScheduler; |
| 7274 |
Promise$1._setAsap = setAsap; |
| 7275 |
Promise$1._asap = asap; |
| 7276 |
|
| 7277 |
/*global self*/ |
| 7278 |
function polyfill() { |
| 7279 |
var local = void 0; |
| 7280 |
|
| 7281 |
if (typeof global !== 'undefined') { |
| 7282 |
local = global; |
| 7283 |
} else if (typeof self !== 'undefined') { |
| 7284 |
local = self; |
| 7285 |
} else { |
| 7286 |
try { |
| 7287 |
local = Function('return this')(); |
| 7288 |
} catch (e) { |
| 7289 |
throw new Error('polyfill failed because global object is unavailable in this environment'); |
| 7290 |
} |
| 7291 |
} |
| 7292 |
|
| 7293 |
var P = local.Promise; |
| 7294 |
|
| 7295 |
if (P) { |
| 7296 |
var promiseToString = null; |
| 7297 |
try { |
| 7298 |
promiseToString = Object.prototype.toString.call(P.resolve()); |
| 7299 |
} catch (e) { |
| 7300 |
// silently ignored |
| 7301 |
} |
| 7302 |
|
| 7303 |
if (promiseToString === '[object Promise]' && !P.cast) { |
| 7304 |
return; |
| 7305 |
} |
| 7306 |
} |
| 7307 |
|
| 7308 |
local.Promise = Promise$1; |
| 7309 |
} |
| 7310 |
|
| 7311 |
// Strange compat.. |
| 7312 |
Promise$1.polyfill = polyfill; |
| 7313 |
Promise$1.Promise = Promise$1; |
| 7314 |
|
| 7315 |
return Promise$1; |
| 7316 |
|
| 7317 |
}))); |
| 7318 |
|
| 7319 |
|
| 7320 |
|
| 7321 |
//# sourceMappingURL=es6-promise.map |
| 7322 |
|
| 7323 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9), __webpack_require__(4))) |
| 7324 |
|
| 7325 |
/***/ }), |
| 7326 |
/* 44 */ |
| 7327 |
/***/ (function(module, exports, __webpack_require__) { |
| 7328 |
|
| 7329 |
"use strict"; |
| 7330 |
|
| 7331 |
|
| 7332 |
module.exports = inlineHeaders; |
| 7333 |
|
| 7334 |
var encode = __webpack_require__(45); |
| 7335 |
|
| 7336 |
function inlineHeaders(url, headers) { |
| 7337 |
if (/\?/.test(url)) { |
| 7338 |
url += '&'; |
| 7339 |
} else { |
| 7340 |
url += '?'; |
| 7341 |
} |
| 7342 |
|
| 7343 |
return url + encode(headers); |
| 7344 |
} |
| 7345 |
|
| 7346 |
|
| 7347 |
/***/ }), |
| 7348 |
/* 45 */ |
| 7349 |
/***/ (function(module, exports, __webpack_require__) { |
| 7350 |
|
| 7351 |
"use strict"; |
| 7352 |
// Copyright Joyent, Inc. and other Node contributors. |
| 7353 |
// |
| 7354 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 7355 |
// copy of this software and associated documentation files (the |
| 7356 |
// "Software"), to deal in the Software without restriction, including |
| 7357 |
// without limitation the rights to use, copy, modify, merge, publish, |
| 7358 |
// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 7359 |
// persons to whom the Software is furnished to do so, subject to the |
| 7360 |
// following conditions: |
| 7361 |
// |
| 7362 |
// The above copyright notice and this permission notice shall be included |
| 7363 |
// in all copies or substantial portions of the Software. |
| 7364 |
// |
| 7365 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 7366 |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 7367 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 7368 |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 7369 |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 7370 |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 7371 |
// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 7372 |
|
| 7373 |
|
| 7374 |
|
| 7375 |
var stringifyPrimitive = function(v) { |
| 7376 |
switch (typeof v) { |
| 7377 |
case 'string': |
| 7378 |
return v; |
| 7379 |
|
| 7380 |
case 'boolean': |
| 7381 |
return v ? 'true' : 'false'; |
| 7382 |
|
| 7383 |
case 'number': |
| 7384 |
return isFinite(v) ? v : ''; |
| 7385 |
|
| 7386 |
default: |
| 7387 |
return ''; |
| 7388 |
} |
| 7389 |
}; |
| 7390 |
|
| 7391 |
module.exports = function(obj, sep, eq, name) { |
| 7392 |
sep = sep || '&'; |
| 7393 |
eq = eq || '='; |
| 7394 |
if (obj === null) { |
| 7395 |
obj = undefined; |
| 7396 |
} |
| 7397 |
|
| 7398 |
if (typeof obj === 'object') { |
| 7399 |
return map(objectKeys(obj), function(k) { |
| 7400 |
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; |
| 7401 |
if (isArray(obj[k])) { |
| 7402 |
return map(obj[k], function(v) { |
| 7403 |
return ks + encodeURIComponent(stringifyPrimitive(v)); |
| 7404 |
}).join(sep); |
| 7405 |
} else { |
| 7406 |
return ks + encodeURIComponent(stringifyPrimitive(obj[k])); |
| 7407 |
} |
| 7408 |
}).join(sep); |
| 7409 |
|
| 7410 |
} |
| 7411 |
|
| 7412 |
if (!name) return ''; |
| 7413 |
return encodeURIComponent(stringifyPrimitive(name)) + eq + |
| 7414 |
encodeURIComponent(stringifyPrimitive(obj)); |
| 7415 |
}; |
| 7416 |
|
| 7417 |
var isArray = Array.isArray || function (xs) { |
| 7418 |
return Object.prototype.toString.call(xs) === '[object Array]'; |
| 7419 |
}; |
| 7420 |
|
| 7421 |
function map (xs, f) { |
| 7422 |
if (xs.map) return xs.map(f); |
| 7423 |
var res = []; |
| 7424 |
for (var i = 0; i < xs.length; i++) { |
| 7425 |
res.push(f(xs[i], i)); |
| 7426 |
} |
| 7427 |
return res; |
| 7428 |
} |
| 7429 |
|
| 7430 |
var objectKeys = Object.keys || function (obj) { |
| 7431 |
var res = []; |
| 7432 |
for (var key in obj) { |
| 7433 |
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); |
| 7434 |
} |
| 7435 |
return res; |
| 7436 |
}; |
| 7437 |
|
| 7438 |
|
| 7439 |
/***/ }), |
| 7440 |
/* 46 */ |
| 7441 |
/***/ (function(module, exports, __webpack_require__) { |
| 7442 |
|
| 7443 |
"use strict"; |
| 7444 |
|
| 7445 |
|
| 7446 |
module.exports = jsonpRequest; |
| 7447 |
|
| 7448 |
var errors = __webpack_require__(5); |
| 7449 |
|
| 7450 |
var JSONPCounter = 0; |
| 7451 |
|
| 7452 |
function jsonpRequest(url, opts, cb) { |
| 7453 |
if (opts.method !== 'GET') { |
| 7454 |
cb(new Error('Method ' + opts.method + ' ' + url + ' is not supported by JSONP.')); |
| 7455 |
return; |
| 7456 |
} |
| 7457 |
|
| 7458 |
opts.debug('JSONP: start'); |
| 7459 |
|
| 7460 |
var cbCalled = false; |
| 7461 |
var timedOut = false; |
| 7462 |
|
| 7463 |
JSONPCounter += 1; |
| 7464 |
var head = document.getElementsByTagName('head')[0]; |
| 7465 |
var script = document.createElement('script'); |
| 7466 |
var cbName = 'algoliaJSONP_' + JSONPCounter; |
| 7467 |
var done = false; |
| 7468 |
|
| 7469 |
window[cbName] = function(data) { |
| 7470 |
removeGlobals(); |
| 7471 |
|
| 7472 |
if (timedOut) { |
| 7473 |
opts.debug('JSONP: Late answer, ignoring'); |
| 7474 |
return; |
| 7475 |
} |
| 7476 |
|
| 7477 |
cbCalled = true; |
| 7478 |
|
| 7479 |
clean(); |
| 7480 |
|
| 7481 |
cb(null, { |
| 7482 |
body: data, |
| 7483 |
responseText: JSON.stringify(data)/* , |
| 7484 |
// We do not send the statusCode, there's no statusCode in JSONP, it will be |
| 7485 |
// computed using data.status && data.message like with XDR |
| 7486 |
statusCode*/ |
| 7487 |
}); |
| 7488 |
}; |
| 7489 |
|
| 7490 |
// add callback by hand |
| 7491 |
url += '&callback=' + cbName; |
| 7492 |
|
| 7493 |
// add body params manually |
| 7494 |
if (opts.jsonBody && opts.jsonBody.params) { |
| 7495 |
url += '&' + opts.jsonBody.params; |
| 7496 |
} |
| 7497 |
|
| 7498 |
var ontimeout = setTimeout(timeout, opts.timeouts.complete); |
| 7499 |
|
| 7500 |
// script onreadystatechange needed only for |
| 7501 |
// <= IE8 |
| 7502 |
// https://github.com/angular/angular.js/issues/4523 |
| 7503 |
script.onreadystatechange = readystatechange; |
| 7504 |
script.onload = success; |
| 7505 |
script.onerror = error; |
| 7506 |
|
| 7507 |
script.async = true; |
| 7508 |
script.defer = true; |
| 7509 |
script.src = url; |
| 7510 |
head.appendChild(script); |
| 7511 |
|
| 7512 |
function success() { |
| 7513 |
opts.debug('JSONP: success'); |
| 7514 |
|
| 7515 |
if (done || timedOut) { |
| 7516 |
return; |
| 7517 |
} |
| 7518 |
|
| 7519 |
done = true; |
| 7520 |
|
| 7521 |
// script loaded but did not call the fn => script loading error |
| 7522 |
if (!cbCalled) { |
| 7523 |
opts.debug('JSONP: Fail. Script loaded but did not call the callback'); |
| 7524 |
clean(); |
| 7525 |
cb(new errors.JSONPScriptFail()); |
| 7526 |
} |
| 7527 |
} |
| 7528 |
|
| 7529 |
function readystatechange() { |
| 7530 |
if (this.readyState === 'loaded' || this.readyState === 'complete') { |
| 7531 |
success(); |
| 7532 |
} |
| 7533 |
} |
| 7534 |
|
| 7535 |
function clean() { |
| 7536 |
clearTimeout(ontimeout); |
| 7537 |
script.onload = null; |
| 7538 |
script.onreadystatechange = null; |
| 7539 |
script.onerror = null; |
| 7540 |
head.removeChild(script); |
| 7541 |
} |
| 7542 |
|
| 7543 |
function removeGlobals() { |
| 7544 |
try { |
| 7545 |
delete window[cbName]; |
| 7546 |
delete window[cbName + '_loaded']; |
| 7547 |
} catch (e) { |
| 7548 |
window[cbName] = window[cbName + '_loaded'] = undefined; |
| 7549 |
} |
| 7550 |
} |
| 7551 |
|
| 7552 |
function timeout() { |
| 7553 |
opts.debug('JSONP: Script timeout'); |
| 7554 |
timedOut = true; |
| 7555 |
clean(); |
| 7556 |
cb(new errors.RequestTimeout()); |
| 7557 |
} |
| 7558 |
|
| 7559 |
function error() { |
| 7560 |
opts.debug('JSONP: Script error'); |
| 7561 |
|
| 7562 |
if (done || timedOut) { |
| 7563 |
return; |
| 7564 |
} |
| 7565 |
|
| 7566 |
clean(); |
| 7567 |
cb(new errors.JSONPScriptError()); |
| 7568 |
} |
| 7569 |
} |
| 7570 |
|
| 7571 |
|
| 7572 |
/***/ }), |
| 7573 |
/* 47 */ |
| 7574 |
/***/ (function(module, exports, __webpack_require__) { |
| 7575 |
|
| 7576 |
module.exports = createPlacesClient; |
| 7577 |
|
| 7578 |
var buildSearchMethod = __webpack_require__(13); |
| 7579 |
|
| 7580 |
function createPlacesClient(algoliasearch) { |
| 7581 |
return function places(appID, apiKey, opts) { |
| 7582 |
var cloneDeep = __webpack_require__(3); |
| 7583 |
|
| 7584 |
opts = opts && cloneDeep(opts) || {}; |
| 7585 |
opts.hosts = opts.hosts || [ |
| 7586 |
'places-dsn.algolia.net', |
| 7587 |
'places-1.algolianet.com', |
| 7588 |
'places-2.algolianet.com', |
| 7589 |
'places-3.algolianet.com' |
| 7590 |
]; |
| 7591 |
|
| 7592 |
// allow initPlaces() no arguments => community rate limited |
| 7593 |
if (arguments.length === 0 || typeof appID === 'object' || appID === undefined) { |
| 7594 |
appID = ''; |
| 7595 |
apiKey = ''; |
| 7596 |
opts._allowEmptyCredentials = true; |
| 7597 |
} |
| 7598 |
|
| 7599 |
var client = algoliasearch(appID, apiKey, opts); |
| 7600 |
var index = client.initIndex('places'); |
| 7601 |
index.search = buildSearchMethod('query', '/1/places/query'); |
| 7602 |
index.getObject = function(objectID, callback) { |
| 7603 |
return this.as._jsonRequest({ |
| 7604 |
method: 'GET', |
| 7605 |
url: '/1/places/' + encodeURIComponent(objectID), |
| 7606 |
hostType: 'read', |
| 7607 |
callback: callback |
| 7608 |
}); |
| 7609 |
}; |
| 7610 |
return index; |
| 7611 |
}; |
| 7612 |
} |
| 7613 |
|
| 7614 |
|
| 7615 |
/***/ }), |
| 7616 |
/* 48 */ |
| 7617 |
/***/ (function(module, exports, __webpack_require__) { |
| 7618 |
|
| 7619 |
"use strict"; |
| 7620 |
|
| 7621 |
|
| 7622 |
module.exports = '3.30.0'; |
| 7623 |
|
| 7624 |
|
| 7625 |
/***/ }), |
| 7626 |
/* 49 */ |
| 7627 |
/***/ (function(module, exports, __webpack_require__) { |
| 7628 |
|
| 7629 |
"use strict"; |
| 7630 |
|
| 7631 |
|
| 7632 |
module.exports = __webpack_require__(50); |
| 7633 |
|
| 7634 |
|
| 7635 |
/***/ }), |
| 7636 |
/* 50 */ |
| 7637 |
/***/ (function(module, exports, __webpack_require__) { |
| 7638 |
|
| 7639 |
"use strict"; |
| 7640 |
|
| 7641 |
|
| 7642 |
// this will inject Zepto in window, unfortunately no easy commonJS zepto build |
| 7643 |
var zepto = __webpack_require__(15); |
| 7644 |
|
| 7645 |
// setup DOM element |
| 7646 |
var DOM = __webpack_require__(1); |
| 7647 |
DOM.element = zepto; |
| 7648 |
|
| 7649 |
// setup utils functions |
| 7650 |
var _ = __webpack_require__(0); |
| 7651 |
_.isArray = zepto.isArray; |
| 7652 |
_.isFunction = zepto.isFunction; |
| 7653 |
_.isObject = zepto.isPlainObject; |
| 7654 |
_.bind = zepto.proxy; |
| 7655 |
_.each = function(collection, cb) { |
| 7656 |
// stupid argument order for jQuery.each |
| 7657 |
zepto.each(collection, reverseArgs); |
| 7658 |
function reverseArgs(index, value) { |
| 7659 |
return cb(value, index); |
| 7660 |
} |
| 7661 |
}; |
| 7662 |
_.map = zepto.map; |
| 7663 |
_.mixin = zepto.extend; |
| 7664 |
_.Event = zepto.Event; |
| 7665 |
|
| 7666 |
var typeaheadKey = 'aaAutocomplete'; |
| 7667 |
var Typeahead = __webpack_require__(51); |
| 7668 |
var EventBus = __webpack_require__(16); |
| 7669 |
|
| 7670 |
function autocomplete(selector, options, datasets, typeaheadObject) { |
| 7671 |
datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 2); |
| 7672 |
|
| 7673 |
var inputs = zepto(selector).each(function(i, input) { |
| 7674 |
var $input = zepto(input); |
| 7675 |
var eventBus = new EventBus({el: $input}); |
| 7676 |
var typeahead = typeaheadObject || new Typeahead({ |
| 7677 |
input: $input, |
| 7678 |
eventBus: eventBus, |
| 7679 |
dropdownMenuContainer: options.dropdownMenuContainer, |
| 7680 |
hint: options.hint === undefined ? true : !!options.hint, |
| 7681 |
minLength: options.minLength, |
| 7682 |
autoselect: options.autoselect, |
| 7683 |
autoselectOnBlur: options.autoselectOnBlur, |
| 7684 |
tabAutocomplete: options.tabAutocomplete, |
| 7685 |
openOnFocus: options.openOnFocus, |
| 7686 |
templates: options.templates, |
| 7687 |
debug: options.debug, |
| 7688 |
clearOnSelected: options.clearOnSelected, |
| 7689 |
cssClasses: options.cssClasses, |
| 7690 |
datasets: datasets, |
| 7691 |
keyboardShortcuts: options.keyboardShortcuts, |
| 7692 |
appendTo: options.appendTo, |
| 7693 |
autoWidth: options.autoWidth |
| 7694 |
}); |
| 7695 |
$input.data(typeaheadKey, typeahead); |
| 7696 |
}); |
| 7697 |
|
| 7698 |
// expose all methods in the `autocomplete` attribute |
| 7699 |
inputs.autocomplete = {}; |
| 7700 |
_.each(['open', 'close', 'getVal', 'setVal', 'destroy', 'getWrapper'], function(method) { |
| 7701 |
inputs.autocomplete[method] = function() { |
| 7702 |
var methodArguments = arguments; |
| 7703 |
var result; |
| 7704 |
inputs.each(function(j, input) { |
| 7705 |
var typeahead = zepto(input).data(typeaheadKey); |
| 7706 |
result = typeahead[method].apply(typeahead, methodArguments); |
| 7707 |
}); |
| 7708 |
return result; |
| 7709 |
}; |
| 7710 |
}); |
| 7711 |
|
| 7712 |
return inputs; |
| 7713 |
} |
| 7714 |
|
| 7715 |
autocomplete.sources = Typeahead.sources; |
| 7716 |
autocomplete.escapeHighlightedString = _.escapeHighlightedString; |
| 7717 |
|
| 7718 |
var wasAutocompleteSet = 'autocomplete' in window; |
| 7719 |
var oldAutocomplete = window.autocomplete; |
| 7720 |
autocomplete.noConflict = function noConflict() { |
| 7721 |
if (wasAutocompleteSet) { |
| 7722 |
window.autocomplete = oldAutocomplete; |
| 7723 |
} else { |
| 7724 |
delete window.autocomplete; |
| 7725 |
} |
| 7726 |
return autocomplete; |
| 7727 |
}; |
| 7728 |
|
| 7729 |
module.exports = autocomplete; |
| 7730 |
|
| 7731 |
|
| 7732 |
/***/ }), |
| 7733 |
/* 51 */ |
| 7734 |
/***/ (function(module, exports, __webpack_require__) { |
| 7735 |
|
| 7736 |
"use strict"; |
| 7737 |
|
| 7738 |
|
| 7739 |
var attrsKey = 'aaAttrs'; |
| 7740 |
|
| 7741 |
var _ = __webpack_require__(0); |
| 7742 |
var DOM = __webpack_require__(1); |
| 7743 |
var EventBus = __webpack_require__(16); |
| 7744 |
var Input = __webpack_require__(52); |
| 7745 |
var Dropdown = __webpack_require__(59); |
| 7746 |
var html = __webpack_require__(17); |
| 7747 |
var css = __webpack_require__(11); |
| 7748 |
|
| 7749 |
// constructor |
| 7750 |
// ----------- |
| 7751 |
|
| 7752 |
// THOUGHT: what if datasets could dynamically be added/removed? |
| 7753 |
function Typeahead(o) { |
| 7754 |
var $menu; |
| 7755 |
var $hint; |
| 7756 |
|
| 7757 |
o = o || {}; |
| 7758 |
|
| 7759 |
if (!o.input) { |
| 7760 |
_.error('missing input'); |
| 7761 |
} |
| 7762 |
|
| 7763 |
this.isActivated = false; |
| 7764 |
this.debug = !!o.debug; |
| 7765 |
this.autoselect = !!o.autoselect; |
| 7766 |
this.autoselectOnBlur = !!o.autoselectOnBlur; |
| 7767 |
this.openOnFocus = !!o.openOnFocus; |
| 7768 |
this.minLength = _.isNumber(o.minLength) ? o.minLength : 1; |
| 7769 |
this.autoWidth = (o.autoWidth === undefined) ? true : !!o.autoWidth; |
| 7770 |
this.clearOnSelected = !!o.clearOnSelected; |
| 7771 |
this.tabAutocomplete = (o.tabAutocomplete === undefined) ? true : !!o.tabAutocomplete; |
| 7772 |
|
| 7773 |
o.hint = !!o.hint; |
| 7774 |
|
| 7775 |
if (o.hint && o.appendTo) { |
| 7776 |
throw new Error('[autocomplete.js] hint and appendTo options can\'t be used at the same time'); |
| 7777 |
} |
| 7778 |
|
| 7779 |
this.css = o.css = _.mixin({}, css, o.appendTo ? css.appendTo : {}); |
| 7780 |
this.cssClasses = o.cssClasses = _.mixin({}, css.defaultClasses, o.cssClasses || {}); |
| 7781 |
this.cssClasses.prefix = |
| 7782 |
o.cssClasses.formattedPrefix = _.formatPrefix(this.cssClasses.prefix, this.cssClasses.noPrefix); |
| 7783 |
this.listboxId = o.listboxId = [this.cssClasses.root, 'listbox', _.getUniqueId()].join('-'); |
| 7784 |
|
| 7785 |
var domElts = buildDom(o); |
| 7786 |
|
| 7787 |
this.$node = domElts.wrapper; |
| 7788 |
var $input = this.$input = domElts.input; |
| 7789 |
$menu = domElts.menu; |
| 7790 |
$hint = domElts.hint; |
| 7791 |
|
| 7792 |
if (o.dropdownMenuContainer) { |
| 7793 |
DOM.element(o.dropdownMenuContainer) |
| 7794 |
.css('position', 'relative') // ensure the container has a relative position |
| 7795 |
.append($menu.css('top', '0')); // override the top: 100% |
| 7796 |
} |
| 7797 |
|
| 7798 |
// #705: if there's scrollable overflow, ie doesn't support |
| 7799 |
// blur cancellations when the scrollbar is clicked |
| 7800 |
// |
| 7801 |
// #351: preventDefault won't cancel blurs in ie <= 8 |
| 7802 |
$input.on('blur.aa', function($e) { |
| 7803 |
var active = document.activeElement; |
| 7804 |
if (_.isMsie() && ($menu[0] === active || $menu[0].contains(active))) { |
| 7805 |
$e.preventDefault(); |
| 7806 |
// stop immediate in order to prevent Input#_onBlur from |
| 7807 |
// getting exectued |
| 7808 |
$e.stopImmediatePropagation(); |
| 7809 |
_.defer(function() { $input.focus(); }); |
| 7810 |
} |
| 7811 |
}); |
| 7812 |
|
| 7813 |
// #351: prevents input blur due to clicks within dropdown menu |
| 7814 |
$menu.on('mousedown.aa', function($e) { $e.preventDefault(); }); |
| 7815 |
|
| 7816 |
this.eventBus = o.eventBus || new EventBus({el: $input}); |
| 7817 |
|
| 7818 |
this.dropdown = new Typeahead.Dropdown({ |
| 7819 |
appendTo: o.appendTo, |
| 7820 |
wrapper: this.$node, |
| 7821 |
menu: $menu, |
| 7822 |
datasets: o.datasets, |
| 7823 |
templates: o.templates, |
| 7824 |
cssClasses: o.cssClasses, |
| 7825 |
minLength: this.minLength |
| 7826 |
}) |
| 7827 |
.onSync('suggestionClicked', this._onSuggestionClicked, this) |
| 7828 |
.onSync('cursorMoved', this._onCursorMoved, this) |
| 7829 |
.onSync('cursorRemoved', this._onCursorRemoved, this) |
| 7830 |
.onSync('opened', this._onOpened, this) |
| 7831 |
.onSync('closed', this._onClosed, this) |
| 7832 |
.onSync('shown', this._onShown, this) |
| 7833 |
.onSync('empty', this._onEmpty, this) |
| 7834 |
.onSync('redrawn', this._onRedrawn, this) |
| 7835 |
.onAsync('datasetRendered', this._onDatasetRendered, this); |
| 7836 |
|
| 7837 |
this.input = new Typeahead.Input({input: $input, hint: $hint}) |
| 7838 |
.onSync('focused', this._onFocused, this) |
| 7839 |
.onSync('blurred', this._onBlurred, this) |
| 7840 |
.onSync('enterKeyed', this._onEnterKeyed, this) |
| 7841 |
.onSync('tabKeyed', this._onTabKeyed, this) |
| 7842 |
.onSync('escKeyed', this._onEscKeyed, this) |
| 7843 |
.onSync('upKeyed', this._onUpKeyed, this) |
| 7844 |
.onSync('downKeyed', this._onDownKeyed, this) |
| 7845 |
.onSync('leftKeyed', this._onLeftKeyed, this) |
| 7846 |
.onSync('rightKeyed', this._onRightKeyed, this) |
| 7847 |
.onSync('queryChanged', this._onQueryChanged, this) |
| 7848 |
.onSync('whitespaceChanged', this._onWhitespaceChanged, this); |
| 7849 |
|
| 7850 |
this._bindKeyboardShortcuts(o); |
| 7851 |
|
| 7852 |
this._setLanguageDirection(); |
| 7853 |
} |
| 7854 |
|
| 7855 |
// instance methods |
| 7856 |
// ---------------- |
| 7857 |
|
| 7858 |
_.mixin(Typeahead.prototype, { |
| 7859 |
// ### private |
| 7860 |
|
| 7861 |
_bindKeyboardShortcuts: function(options) { |
| 7862 |
if (!options.keyboardShortcuts) { |
| 7863 |
return; |
| 7864 |
} |
| 7865 |
var $input = this.$input; |
| 7866 |
var keyboardShortcuts = []; |
| 7867 |
_.each(options.keyboardShortcuts, function(key) { |
| 7868 |
if (typeof key === 'string') { |
| 7869 |
key = key.toUpperCase().charCodeAt(0); |
| 7870 |
} |
| 7871 |
keyboardShortcuts.push(key); |
| 7872 |
}); |
| 7873 |
DOM.element(document).keydown(function(event) { |
| 7874 |
var elt = (event.target || event.srcElement); |
| 7875 |
var tagName = elt.tagName; |
| 7876 |
if (elt.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA') { |
| 7877 |
// already in an input |
| 7878 |
return; |
| 7879 |
} |
| 7880 |
|
| 7881 |
var which = event.which || event.keyCode; |
| 7882 |
if (keyboardShortcuts.indexOf(which) === -1) { |
| 7883 |
// not the right shortcut |
| 7884 |
return; |
| 7885 |
} |
| 7886 |
|
| 7887 |
$input.focus(); |
| 7888 |
event.stopPropagation(); |
| 7889 |
event.preventDefault(); |
| 7890 |
}); |
| 7891 |
}, |
| 7892 |
|
| 7893 |
_onSuggestionClicked: function onSuggestionClicked(type, $el) { |
| 7894 |
var datum; |
| 7895 |
|
| 7896 |
if (datum = this.dropdown.getDatumForSuggestion($el)) { |
| 7897 |
this._select(datum); |
| 7898 |
} |
| 7899 |
}, |
| 7900 |
|
| 7901 |
_onCursorMoved: function onCursorMoved(event, updateInput) { |
| 7902 |
var datum = this.dropdown.getDatumForCursor(); |
| 7903 |
var currentCursorId = this.dropdown.getCurrentCursor().attr('id'); |
| 7904 |
this.input.setActiveDescendant(currentCursorId); |
| 7905 |
|
| 7906 |
if (datum) { |
| 7907 |
if (updateInput) { |
| 7908 |
this.input.setInputValue(datum.value, true); |
| 7909 |
} |
| 7910 |
|
| 7911 |
this.eventBus.trigger('cursorchanged', datum.raw, datum.datasetName); |
| 7912 |
} |
| 7913 |
}, |
| 7914 |
|
| 7915 |
_onCursorRemoved: function onCursorRemoved() { |
| 7916 |
this.input.resetInputValue(); |
| 7917 |
this._updateHint(); |
| 7918 |
this.eventBus.trigger('cursorremoved'); |
| 7919 |
}, |
| 7920 |
|
| 7921 |
_onDatasetRendered: function onDatasetRendered() { |
| 7922 |
this._updateHint(); |
| 7923 |
|
| 7924 |
this.eventBus.trigger('updated'); |
| 7925 |
}, |
| 7926 |
|
| 7927 |
_onOpened: function onOpened() { |
| 7928 |
this._updateHint(); |
| 7929 |
this.input.expand(); |
| 7930 |
|
| 7931 |
this.eventBus.trigger('opened'); |
| 7932 |
}, |
| 7933 |
|
| 7934 |
_onEmpty: function onEmpty() { |
| 7935 |
this.eventBus.trigger('empty'); |
| 7936 |
}, |
| 7937 |
|
| 7938 |
_onRedrawn: function onRedrawn() { |
| 7939 |
this.$node.css('top', 0 + 'px'); |
| 7940 |
this.$node.css('left', 0 + 'px'); |
| 7941 |
|
| 7942 |
var inputRect = this.$input[0].getBoundingClientRect(); |
| 7943 |
|
| 7944 |
if (this.autoWidth) { |
| 7945 |
this.$node.css('width', inputRect.width + 'px'); |
| 7946 |
} |
| 7947 |
|
| 7948 |
var wrapperRect = this.$node[0].getBoundingClientRect(); |
| 7949 |
|
| 7950 |
var top = inputRect.bottom - wrapperRect.top; |
| 7951 |
this.$node.css('top', top + 'px'); |
| 7952 |
var left = inputRect.left - wrapperRect.left; |
| 7953 |
this.$node.css('left', left + 'px'); |
| 7954 |
|
| 7955 |
this.eventBus.trigger('redrawn'); |
| 7956 |
}, |
| 7957 |
|
| 7958 |
_onShown: function onShown() { |
| 7959 |
this.eventBus.trigger('shown'); |
| 7960 |
if (this.autoselect) { |
| 7961 |
this.dropdown.cursorTopSuggestion(); |
| 7962 |
} |
| 7963 |
}, |
| 7964 |
|
| 7965 |
_onClosed: function onClosed() { |
| 7966 |
this.input.clearHint(); |
| 7967 |
this.input.removeActiveDescendant(); |
| 7968 |
this.input.collapse(); |
| 7969 |
|
| 7970 |
this.eventBus.trigger('closed'); |
| 7971 |
}, |
| 7972 |
|
| 7973 |
_onFocused: function onFocused() { |
| 7974 |
this.isActivated = true; |
| 7975 |
|
| 7976 |
if (this.openOnFocus) { |
| 7977 |
var query = this.input.getQuery(); |
| 7978 |
if (query.length >= this.minLength) { |
| 7979 |
this.dropdown.update(query); |
| 7980 |
} else { |
| 7981 |
this.dropdown.empty(); |
| 7982 |
} |
| 7983 |
|
| 7984 |
this.dropdown.open(); |
| 7985 |
} |
| 7986 |
}, |
| 7987 |
|
| 7988 |
_onBlurred: function onBlurred() { |
| 7989 |
var cursorDatum; |
| 7990 |
var topSuggestionDatum; |
| 7991 |
|
| 7992 |
cursorDatum = this.dropdown.getDatumForCursor(); |
| 7993 |
topSuggestionDatum = this.dropdown.getDatumForTopSuggestion(); |
| 7994 |
|
| 7995 |
if (!this.debug) { |
| 7996 |
if (this.autoselectOnBlur && cursorDatum) { |
| 7997 |
this._select(cursorDatum); |
| 7998 |
} else if (this.autoselectOnBlur && topSuggestionDatum) { |
| 7999 |
this._select(topSuggestionDatum); |
| 8000 |
} else { |
| 8001 |
this.isActivated = false; |
| 8002 |
this.dropdown.empty(); |
| 8003 |
this.dropdown.close(); |
| 8004 |
} |
| 8005 |
} |
| 8006 |
}, |
| 8007 |
|
| 8008 |
_onEnterKeyed: function onEnterKeyed(type, $e) { |
| 8009 |
var cursorDatum; |
| 8010 |
var topSuggestionDatum; |
| 8011 |
|
| 8012 |
cursorDatum = this.dropdown.getDatumForCursor(); |
| 8013 |
topSuggestionDatum = this.dropdown.getDatumForTopSuggestion(); |
| 8014 |
|
| 8015 |
if (cursorDatum) { |
| 8016 |
this._select(cursorDatum); |
| 8017 |
$e.preventDefault(); |
| 8018 |
} else if (this.autoselect && topSuggestionDatum) { |
| 8019 |
this._select(topSuggestionDatum); |
| 8020 |
$e.preventDefault(); |
| 8021 |
} |
| 8022 |
}, |
| 8023 |
|
| 8024 |
_onTabKeyed: function onTabKeyed(type, $e) { |
| 8025 |
if (!this.tabAutocomplete) { |
| 8026 |
// Closing the dropdown enables further tabbing |
| 8027 |
this.dropdown.close(); |
| 8028 |
return; |
| 8029 |
} |
| 8030 |
|
| 8031 |
var datum; |
| 8032 |
|
| 8033 |
if (datum = this.dropdown.getDatumForCursor()) { |
| 8034 |
this._select(datum); |
| 8035 |
$e.preventDefault(); |
| 8036 |
} else { |
| 8037 |
this._autocomplete(true); |
| 8038 |
} |
| 8039 |
}, |
| 8040 |
|
| 8041 |
_onEscKeyed: function onEscKeyed() { |
| 8042 |
this.dropdown.close(); |
| 8043 |
this.input.resetInputValue(); |
| 8044 |
}, |
| 8045 |
|
| 8046 |
_onUpKeyed: function onUpKeyed() { |
| 8047 |
var query = this.input.getQuery(); |
| 8048 |
|
| 8049 |
if (this.dropdown.isEmpty && query.length >= this.minLength) { |
| 8050 |
this.dropdown.update(query); |
| 8051 |
} else { |
| 8052 |
this.dropdown.moveCursorUp(); |
| 8053 |
} |
| 8054 |
|
| 8055 |
this.dropdown.open(); |
| 8056 |
}, |
| 8057 |
|
| 8058 |
_onDownKeyed: function onDownKeyed() { |
| 8059 |
var query = this.input.getQuery(); |
| 8060 |
|
| 8061 |
if (this.dropdown.isEmpty && query.length >= this.minLength) { |
| 8062 |
this.dropdown.update(query); |
| 8063 |
} else { |
| 8064 |
this.dropdown.moveCursorDown(); |
| 8065 |
} |
| 8066 |
|
| 8067 |
this.dropdown.open(); |
| 8068 |
}, |
| 8069 |
|
| 8070 |
_onLeftKeyed: function onLeftKeyed() { |
| 8071 |
if (this.dir === 'rtl') { |
| 8072 |
this._autocomplete(); |
| 8073 |
} |
| 8074 |
}, |
| 8075 |
|
| 8076 |
_onRightKeyed: function onRightKeyed() { |
| 8077 |
if (this.dir === 'ltr') { |
| 8078 |
this._autocomplete(); |
| 8079 |
} |
| 8080 |
}, |
| 8081 |
|
| 8082 |
_onQueryChanged: function onQueryChanged(e, query) { |
| 8083 |
this.input.clearHintIfInvalid(); |
| 8084 |
|
| 8085 |
if (query.length >= this.minLength) { |
| 8086 |
this.dropdown.update(query); |
| 8087 |
} else { |
| 8088 |
this.dropdown.empty(); |
| 8089 |
} |
| 8090 |
|
| 8091 |
this.dropdown.open(); |
| 8092 |
this._setLanguageDirection(); |
| 8093 |
}, |
| 8094 |
|
| 8095 |
_onWhitespaceChanged: function onWhitespaceChanged() { |
| 8096 |
this._updateHint(); |
| 8097 |
this.dropdown.open(); |
| 8098 |
}, |
| 8099 |
|
| 8100 |
_setLanguageDirection: function setLanguageDirection() { |
| 8101 |
var dir = this.input.getLanguageDirection(); |
| 8102 |
|
| 8103 |
if (this.dir !== dir) { |
| 8104 |
this.dir = dir; |
| 8105 |
this.$node.css('direction', dir); |
| 8106 |
this.dropdown.setLanguageDirection(dir); |
| 8107 |
} |
| 8108 |
}, |
| 8109 |
|
| 8110 |
_updateHint: function updateHint() { |
| 8111 |
var datum; |
| 8112 |
var val; |
| 8113 |
var query; |
| 8114 |
var escapedQuery; |
| 8115 |
var frontMatchRegEx; |
| 8116 |
var match; |
| 8117 |
|
| 8118 |
datum = this.dropdown.getDatumForTopSuggestion(); |
| 8119 |
|
| 8120 |
if (datum && this.dropdown.isVisible() && !this.input.hasOverflow()) { |
| 8121 |
val = this.input.getInputValue(); |
| 8122 |
query = Input.normalizeQuery(val); |
| 8123 |
escapedQuery = _.escapeRegExChars(query); |
| 8124 |
|
| 8125 |
// match input value, then capture trailing text |
| 8126 |
frontMatchRegEx = new RegExp('^(?:' + escapedQuery + ')(.+$)', 'i'); |
| 8127 |
match = frontMatchRegEx.exec(datum.value); |
| 8128 |
|
| 8129 |
// clear hint if there's no trailing text |
| 8130 |
if (match) { |
| 8131 |
this.input.setHint(val + match[1]); |
| 8132 |
} else { |
| 8133 |
this.input.clearHint(); |
| 8134 |
} |
| 8135 |
} else { |
| 8136 |
this.input.clearHint(); |
| 8137 |
} |
| 8138 |
}, |
| 8139 |
|
| 8140 |
_autocomplete: function autocomplete(laxCursor) { |
| 8141 |
var hint; |
| 8142 |
var query; |
| 8143 |
var isCursorAtEnd; |
| 8144 |
var datum; |
| 8145 |
|
| 8146 |
hint = this.input.getHint(); |
| 8147 |
query = this.input.getQuery(); |
| 8148 |
isCursorAtEnd = laxCursor || this.input.isCursorAtEnd(); |
| 8149 |
|
| 8150 |
if (hint && query !== hint && isCursorAtEnd) { |
| 8151 |
datum = this.dropdown.getDatumForTopSuggestion(); |
| 8152 |
if (datum) { |
| 8153 |
this.input.setInputValue(datum.value); |
| 8154 |
} |
| 8155 |
|
| 8156 |
this.eventBus.trigger('autocompleted', datum.raw, datum.datasetName); |
| 8157 |
} |
| 8158 |
}, |
| 8159 |
|
| 8160 |
_select: function select(datum) { |
| 8161 |
if (typeof datum.value !== 'undefined') { |
| 8162 |
this.input.setQuery(datum.value); |
| 8163 |
} |
| 8164 |
if (this.clearOnSelected) { |
| 8165 |
this.setVal(''); |
| 8166 |
} else { |
| 8167 |
this.input.setInputValue(datum.value, true); |
| 8168 |
} |
| 8169 |
|
| 8170 |
this._setLanguageDirection(); |
| 8171 |
|
| 8172 |
var event = this.eventBus.trigger('selected', datum.raw, datum.datasetName); |
| 8173 |
if (event.isDefaultPrevented() === false) { |
| 8174 |
this.dropdown.close(); |
| 8175 |
|
| 8176 |
// #118: allow click event to bubble up to the body before removing |
| 8177 |
// the suggestions otherwise we break event delegation |
| 8178 |
_.defer(_.bind(this.dropdown.empty, this.dropdown)); |
| 8179 |
} |
| 8180 |
}, |
| 8181 |
|
| 8182 |
// ### public |
| 8183 |
|
| 8184 |
open: function open() { |
| 8185 |
// if the menu is not activated yet, we need to update |
| 8186 |
// the underlying dropdown menu to trigger the search |
| 8187 |
// otherwise we're not gonna see anything |
| 8188 |
if (!this.isActivated) { |
| 8189 |
var query = this.input.getInputValue(); |
| 8190 |
if (query.length >= this.minLength) { |
| 8191 |
this.dropdown.update(query); |
| 8192 |
} else { |
| 8193 |
this.dropdown.empty(); |
| 8194 |
} |
| 8195 |
} |
| 8196 |
this.dropdown.open(); |
| 8197 |
}, |
| 8198 |
|
| 8199 |
close: function close() { |
| 8200 |
this.dropdown.close(); |
| 8201 |
}, |
| 8202 |
|
| 8203 |
setVal: function setVal(val) { |
| 8204 |
// expect val to be a string, so be safe, and coerce |
| 8205 |
val = _.toStr(val); |
| 8206 |
|
| 8207 |
if (this.isActivated) { |
| 8208 |
this.input.setInputValue(val); |
| 8209 |
} else { |
| 8210 |
this.input.setQuery(val); |
| 8211 |
this.input.setInputValue(val, true); |
| 8212 |
} |
| 8213 |
|
| 8214 |
this._setLanguageDirection(); |
| 8215 |
}, |
| 8216 |
|
| 8217 |
getVal: function getVal() { |
| 8218 |
return this.input.getQuery(); |
| 8219 |
}, |
| 8220 |
|
| 8221 |
destroy: function destroy() { |
| 8222 |
this.input.destroy(); |
| 8223 |
this.dropdown.destroy(); |
| 8224 |
|
| 8225 |
destroyDomStructure(this.$node, this.cssClasses); |
| 8226 |
|
| 8227 |
this.$node = null; |
| 8228 |
}, |
| 8229 |
|
| 8230 |
getWrapper: function getWrapper() { |
| 8231 |
return this.dropdown.$container[0]; |
| 8232 |
} |
| 8233 |
}); |
| 8234 |
|
| 8235 |
function buildDom(options) { |
| 8236 |
var $input; |
| 8237 |
var $wrapper; |
| 8238 |
var $dropdown; |
| 8239 |
var $hint; |
| 8240 |
|
| 8241 |
$input = DOM.element(options.input); |
| 8242 |
$wrapper = DOM |
| 8243 |
.element(html.wrapper.replace('%ROOT%', options.cssClasses.root)) |
| 8244 |
.css(options.css.wrapper); |
| 8245 |
|
| 8246 |
// override the display property with the table-cell value |
| 8247 |
// if the parent element is a table and the original input was a block |
| 8248 |
// -> https://github.com/algolia/autocomplete.js/issues/16 |
| 8249 |
if (!options.appendTo && $input.css('display') === 'block' && $input.parent().css('display') === 'table') { |
| 8250 |
$wrapper.css('display', 'table-cell'); |
| 8251 |
} |
| 8252 |
var dropdownHtml = html.dropdown. |
| 8253 |
replace('%PREFIX%', options.cssClasses.prefix). |
| 8254 |
replace('%DROPDOWN_MENU%', options.cssClasses.dropdownMenu); |
| 8255 |
$dropdown = DOM.element(dropdownHtml) |
| 8256 |
.css(options.css.dropdown) |
| 8257 |
.attr({ |
| 8258 |
role: 'listbox', |
| 8259 |
id: options.listboxId |
| 8260 |
}); |
| 8261 |
if (options.templates && options.templates.dropdownMenu) { |
| 8262 |
$dropdown.html(_.templatify(options.templates.dropdownMenu)()); |
| 8263 |
} |
| 8264 |
$hint = $input.clone().css(options.css.hint).css(getBackgroundStyles($input)); |
| 8265 |
|
| 8266 |
$hint |
| 8267 |
.val('') |
| 8268 |
.addClass(_.className(options.cssClasses.prefix, options.cssClasses.hint, true)) |
| 8269 |
.removeAttr('id name placeholder required') |
| 8270 |
.prop('readonly', true) |
| 8271 |
.attr({ |
| 8272 |
'aria-hidden': 'true', |
| 8273 |
autocomplete: 'off', |
| 8274 |
spellcheck: 'false', |
| 8275 |
tabindex: -1 |
| 8276 |
}); |
| 8277 |
if ($hint.removeData) { |
| 8278 |
$hint.removeData(); |
| 8279 |
} |
| 8280 |
|
| 8281 |
// store the original values of the attrs that get modified |
| 8282 |
// so modifications can be reverted on destroy |
| 8283 |
$input.data(attrsKey, { |
| 8284 |
'aria-autocomplete': $input.attr('aria-autocomplete'), |
| 8285 |
'aria-expanded': $input.attr('aria-expanded'), |
| 8286 |
'aria-owns': $input.attr('aria-owns'), |
| 8287 |
autocomplete: $input.attr('autocomplete'), |
| 8288 |
dir: $input.attr('dir'), |
| 8289 |
role: $input.attr('role'), |
| 8290 |
spellcheck: $input.attr('spellcheck'), |
| 8291 |
style: $input.attr('style'), |
| 8292 |
type: $input.attr('type') |
| 8293 |
}); |
| 8294 |
|
| 8295 |
$input |
| 8296 |
.addClass(_.className(options.cssClasses.prefix, options.cssClasses.input, true)) |
| 8297 |
.attr({ |
| 8298 |
autocomplete: 'off', |
| 8299 |
spellcheck: false, |
| 8300 |
|
| 8301 |
// Accessibility features |
| 8302 |
// Give the field a presentation of a "select". |
| 8303 |
// Combobox is the combined presentation of a single line textfield |
| 8304 |
// with a listbox popup. |
| 8305 |
// https://www.w3.org/WAI/PF/aria/roles#combobox |
| 8306 |
role: 'combobox', |
| 8307 |
// Let the screen reader know the field has an autocomplete |
| 8308 |
// feature to it. |
| 8309 |
'aria-autocomplete': (options.datasets && |
| 8310 |
options.datasets[0] && options.datasets[0].displayKey ? 'both' : 'list'), |
| 8311 |
// Indicates whether the dropdown it controls is currently expanded or collapsed |
| 8312 |
'aria-expanded': 'false', |
| 8313 |
'aria-label': options.ariaLabel, |
| 8314 |
// Explicitly point to the listbox, |
| 8315 |
// which is a list of suggestions (aka options) |
| 8316 |
'aria-owns': options.listboxId |
| 8317 |
}) |
| 8318 |
.css(options.hint ? options.css.input : options.css.inputWithNoHint); |
| 8319 |
|
| 8320 |
// ie7 does not like it when dir is set to auto |
| 8321 |
try { |
| 8322 |
if (!$input.attr('dir')) { |
| 8323 |
$input.attr('dir', 'auto'); |
| 8324 |
} |
| 8325 |
} catch (e) { |
| 8326 |
// ignore |
| 8327 |
} |
| 8328 |
|
| 8329 |
$wrapper = options.appendTo |
| 8330 |
? $wrapper.appendTo(DOM.element(options.appendTo).eq(0)).eq(0) |
| 8331 |
: $input.wrap($wrapper).parent(); |
| 8332 |
|
| 8333 |
$wrapper |
| 8334 |
.prepend(options.hint ? $hint : null) |
| 8335 |
.append($dropdown); |
| 8336 |
|
| 8337 |
return { |
| 8338 |
wrapper: $wrapper, |
| 8339 |
input: $input, |
| 8340 |
hint: $hint, |
| 8341 |
menu: $dropdown |
| 8342 |
}; |
| 8343 |
} |
| 8344 |
|
| 8345 |
function getBackgroundStyles($el) { |
| 8346 |
return { |
| 8347 |
backgroundAttachment: $el.css('background-attachment'), |
| 8348 |
backgroundClip: $el.css('background-clip'), |
| 8349 |
backgroundColor: $el.css('background-color'), |
| 8350 |
backgroundImage: $el.css('background-image'), |
| 8351 |
backgroundOrigin: $el.css('background-origin'), |
| 8352 |
backgroundPosition: $el.css('background-position'), |
| 8353 |
backgroundRepeat: $el.css('background-repeat'), |
| 8354 |
backgroundSize: $el.css('background-size') |
| 8355 |
}; |
| 8356 |
} |
| 8357 |
|
| 8358 |
function destroyDomStructure($node, cssClasses) { |
| 8359 |
var $input = $node.find(_.className(cssClasses.prefix, cssClasses.input)); |
| 8360 |
|
| 8361 |
// need to remove attrs that weren't previously defined and |
| 8362 |
// revert attrs that originally had a value |
| 8363 |
_.each($input.data(attrsKey), function(val, key) { |
| 8364 |
if (val === undefined) { |
| 8365 |
$input.removeAttr(key); |
| 8366 |
} else { |
| 8367 |
$input.attr(key, val); |
| 8368 |
} |
| 8369 |
}); |
| 8370 |
|
| 8371 |
$input |
| 8372 |
.detach() |
| 8373 |
.removeClass(_.className(cssClasses.prefix, cssClasses.input, true)) |
| 8374 |
.insertAfter($node); |
| 8375 |
if ($input.removeData) { |
| 8376 |
$input.removeData(attrsKey); |
| 8377 |
} |
| 8378 |
|
| 8379 |
$node.remove(); |
| 8380 |
} |
| 8381 |
|
| 8382 |
Typeahead.Dropdown = Dropdown; |
| 8383 |
Typeahead.Input = Input; |
| 8384 |
Typeahead.sources = __webpack_require__(61); |
| 8385 |
|
| 8386 |
module.exports = Typeahead; |
| 8387 |
|
| 8388 |
|
| 8389 |
/***/ }), |
| 8390 |
/* 52 */ |
| 8391 |
/***/ (function(module, exports, __webpack_require__) { |
| 8392 |
|
| 8393 |
"use strict"; |
| 8394 |
|
| 8395 |
|
| 8396 |
var specialKeyCodeMap; |
| 8397 |
|
| 8398 |
specialKeyCodeMap = { |
| 8399 |
9: 'tab', |
| 8400 |
27: 'esc', |
| 8401 |
37: 'left', |
| 8402 |
39: 'right', |
| 8403 |
13: 'enter', |
| 8404 |
38: 'up', |
| 8405 |
40: 'down' |
| 8406 |
}; |
| 8407 |
|
| 8408 |
var _ = __webpack_require__(0); |
| 8409 |
var DOM = __webpack_require__(1); |
| 8410 |
var EventEmitter = __webpack_require__(10); |
| 8411 |
|
| 8412 |
// constructor |
| 8413 |
// ----------- |
| 8414 |
|
| 8415 |
function Input(o) { |
| 8416 |
var that = this; |
| 8417 |
var onBlur; |
| 8418 |
var onFocus; |
| 8419 |
var onKeydown; |
| 8420 |
var onInput; |
| 8421 |
|
| 8422 |
o = o || {}; |
| 8423 |
|
| 8424 |
if (!o.input) { |
| 8425 |
_.error('input is missing'); |
| 8426 |
} |
| 8427 |
|
| 8428 |
// bound functions |
| 8429 |
onBlur = _.bind(this._onBlur, this); |
| 8430 |
onFocus = _.bind(this._onFocus, this); |
| 8431 |
onKeydown = _.bind(this._onKeydown, this); |
| 8432 |
onInput = _.bind(this._onInput, this); |
| 8433 |
|
| 8434 |
this.$hint = DOM.element(o.hint); |
| 8435 |
this.$input = DOM.element(o.input) |
| 8436 |
.on('blur.aa', onBlur) |
| 8437 |
.on('focus.aa', onFocus) |
| 8438 |
.on('keydown.aa', onKeydown); |
| 8439 |
|
| 8440 |
// if no hint, noop all the hint related functions |
| 8441 |
if (this.$hint.length === 0) { |
| 8442 |
this.setHint = this.getHint = this.clearHint = this.clearHintIfInvalid = _.noop; |
| 8443 |
} |
| 8444 |
|
| 8445 |
// ie7 and ie8 don't support the input event |
| 8446 |
// ie9 doesn't fire the input event when characters are removed |
| 8447 |
// not sure if ie10 is compatible |
| 8448 |
if (!_.isMsie()) { |
| 8449 |
this.$input.on('input.aa', onInput); |
| 8450 |
} else { |
| 8451 |
this.$input.on('keydown.aa keypress.aa cut.aa paste.aa', function($e) { |
| 8452 |
// if a special key triggered this, ignore it |
| 8453 |
if (specialKeyCodeMap[$e.which || $e.keyCode]) { |
| 8454 |
return; |
| 8455 |
} |
| 8456 |
|
| 8457 |
// give the browser a chance to update the value of the input |
| 8458 |
// before checking to see if the query changed |
| 8459 |
_.defer(_.bind(that._onInput, that, $e)); |
| 8460 |
}); |
| 8461 |
} |
| 8462 |
|
| 8463 |
// the query defaults to whatever the value of the input is |
| 8464 |
// on initialization, it'll most likely be an empty string |
| 8465 |
this.query = this.$input.val(); |
| 8466 |
|
| 8467 |
// helps with calculating the width of the input's value |
| 8468 |
this.$overflowHelper = buildOverflowHelper(this.$input); |
| 8469 |
} |
| 8470 |
|
| 8471 |
// static methods |
| 8472 |
// -------------- |
| 8473 |
|
| 8474 |
Input.normalizeQuery = function(str) { |
| 8475 |
// strips leading whitespace and condenses all whitespace |
| 8476 |
return (str || '').replace(/^\s*/g, '').replace(/\s{2,}/g, ' '); |
| 8477 |
}; |
| 8478 |
|
| 8479 |
// instance methods |
| 8480 |
// ---------------- |
| 8481 |
|
| 8482 |
_.mixin(Input.prototype, EventEmitter, { |
| 8483 |
|
| 8484 |
// ### private |
| 8485 |
|
| 8486 |
_onBlur: function onBlur() { |
| 8487 |
this.resetInputValue(); |
| 8488 |
this.$input.removeAttr('aria-activedescendant'); |
| 8489 |
this.trigger('blurred'); |
| 8490 |
}, |
| 8491 |
|
| 8492 |
_onFocus: function onFocus() { |
| 8493 |
this.trigger('focused'); |
| 8494 |
}, |
| 8495 |
|
| 8496 |
_onKeydown: function onKeydown($e) { |
| 8497 |
// which is normalized and consistent (but not for ie) |
| 8498 |
var keyName = specialKeyCodeMap[$e.which || $e.keyCode]; |
| 8499 |
|
| 8500 |
this._managePreventDefault(keyName, $e); |
| 8501 |
if (keyName && this._shouldTrigger(keyName, $e)) { |
| 8502 |
this.trigger(keyName + 'Keyed', $e); |
| 8503 |
} |
| 8504 |
}, |
| 8505 |
|
| 8506 |
_onInput: function onInput() { |
| 8507 |
this._checkInputValue(); |
| 8508 |
}, |
| 8509 |
|
| 8510 |
_managePreventDefault: function managePreventDefault(keyName, $e) { |
| 8511 |
var preventDefault; |
| 8512 |
var hintValue; |
| 8513 |
var inputValue; |
| 8514 |
|
| 8515 |
switch (keyName) { |
| 8516 |
case 'tab': |
| 8517 |
hintValue = this.getHint(); |
| 8518 |
inputValue = this.getInputValue(); |
| 8519 |
|
| 8520 |
preventDefault = hintValue && |
| 8521 |
hintValue !== inputValue && |
| 8522 |
!withModifier($e); |
| 8523 |
break; |
| 8524 |
|
| 8525 |
case 'up': |
| 8526 |
case 'down': |
| 8527 |
preventDefault = !withModifier($e); |
| 8528 |
break; |
| 8529 |
|
| 8530 |
default: |
| 8531 |
preventDefault = false; |
| 8532 |
} |
| 8533 |
|
| 8534 |
if (preventDefault) { |
| 8535 |
$e.preventDefault(); |
| 8536 |
} |
| 8537 |
}, |
| 8538 |
|
| 8539 |
_shouldTrigger: function shouldTrigger(keyName, $e) { |
| 8540 |
var trigger; |
| 8541 |
|
| 8542 |
switch (keyName) { |
| 8543 |
case 'tab': |
| 8544 |
trigger = !withModifier($e); |
| 8545 |
break; |
| 8546 |
|
| 8547 |
default: |
| 8548 |
trigger = true; |
| 8549 |
} |
| 8550 |
|
| 8551 |
return trigger; |
| 8552 |
}, |
| 8553 |
|
| 8554 |
_checkInputValue: function checkInputValue() { |
| 8555 |
var inputValue; |
| 8556 |
var areEquivalent; |
| 8557 |
var hasDifferentWhitespace; |
| 8558 |
|
| 8559 |
inputValue = this.getInputValue(); |
| 8560 |
areEquivalent = areQueriesEquivalent(inputValue, this.query); |
| 8561 |
hasDifferentWhitespace = areEquivalent && this.query ? |
| 8562 |
this.query.length !== inputValue.length : false; |
| 8563 |
|
| 8564 |
this.query = inputValue; |
| 8565 |
|
| 8566 |
if (!areEquivalent) { |
| 8567 |
this.trigger('queryChanged', this.query); |
| 8568 |
} else if (hasDifferentWhitespace) { |
| 8569 |
this.trigger('whitespaceChanged', this.query); |
| 8570 |
} |
| 8571 |
}, |
| 8572 |
|
| 8573 |
// ### public |
| 8574 |
|
| 8575 |
focus: function focus() { |
| 8576 |
this.$input.focus(); |
| 8577 |
}, |
| 8578 |
|
| 8579 |
blur: function blur() { |
| 8580 |
this.$input.blur(); |
| 8581 |
}, |
| 8582 |
|
| 8583 |
getQuery: function getQuery() { |
| 8584 |
return this.query; |
| 8585 |
}, |
| 8586 |
|
| 8587 |
setQuery: function setQuery(query) { |
| 8588 |
this.query = query; |
| 8589 |
}, |
| 8590 |
|
| 8591 |
getInputValue: function getInputValue() { |
| 8592 |
return this.$input.val(); |
| 8593 |
}, |
| 8594 |
|
| 8595 |
setInputValue: function setInputValue(value, silent) { |
| 8596 |
if (typeof value === 'undefined') { |
| 8597 |
value = this.query; |
| 8598 |
} |
| 8599 |
this.$input.val(value); |
| 8600 |
|
| 8601 |
// silent prevents any additional events from being triggered |
| 8602 |
if (silent) { |
| 8603 |
this.clearHint(); |
| 8604 |
} else { |
| 8605 |
this._checkInputValue(); |
| 8606 |
} |
| 8607 |
}, |
| 8608 |
|
| 8609 |
expand: function expand() { |
| 8610 |
this.$input.attr('aria-expanded', 'true'); |
| 8611 |
}, |
| 8612 |
|
| 8613 |
collapse: function collapse() { |
| 8614 |
this.$input.attr('aria-expanded', 'false'); |
| 8615 |
}, |
| 8616 |
|
| 8617 |
setActiveDescendant: function setActiveDescendant(activedescendantId) { |
| 8618 |
this.$input.attr('aria-activedescendant', activedescendantId); |
| 8619 |
}, |
| 8620 |
|
| 8621 |
removeActiveDescendant: function removeActiveDescendant() { |
| 8622 |
this.$input.removeAttr('aria-activedescendant'); |
| 8623 |
}, |
| 8624 |
|
| 8625 |
resetInputValue: function resetInputValue() { |
| 8626 |
this.setInputValue(this.query, true); |
| 8627 |
}, |
| 8628 |
|
| 8629 |
getHint: function getHint() { |
| 8630 |
return this.$hint.val(); |
| 8631 |
}, |
| 8632 |
|
| 8633 |
setHint: function setHint(value) { |
| 8634 |
this.$hint.val(value); |
| 8635 |
}, |
| 8636 |
|
| 8637 |
clearHint: function clearHint() { |
| 8638 |
this.setHint(''); |
| 8639 |
}, |
| 8640 |
|
| 8641 |
clearHintIfInvalid: function clearHintIfInvalid() { |
| 8642 |
var val; |
| 8643 |
var hint; |
| 8644 |
var valIsPrefixOfHint; |
| 8645 |
var isValid; |
| 8646 |
|
| 8647 |
val = this.getInputValue(); |
| 8648 |
hint = this.getHint(); |
| 8649 |
valIsPrefixOfHint = val !== hint && hint.indexOf(val) === 0; |
| 8650 |
isValid = val !== '' && valIsPrefixOfHint && !this.hasOverflow(); |
| 8651 |
|
| 8652 |
if (!isValid) { |
| 8653 |
this.clearHint(); |
| 8654 |
} |
| 8655 |
}, |
| 8656 |
|
| 8657 |
getLanguageDirection: function getLanguageDirection() { |
| 8658 |
return (this.$input.css('direction') || 'ltr').toLowerCase(); |
| 8659 |
}, |
| 8660 |
|
| 8661 |
hasOverflow: function hasOverflow() { |
| 8662 |
// 2 is arbitrary, just picking a small number to handle edge cases |
| 8663 |
var constraint = this.$input.width() - 2; |
| 8664 |
|
| 8665 |
this.$overflowHelper.text(this.getInputValue()); |
| 8666 |
|
| 8667 |
return this.$overflowHelper.width() >= constraint; |
| 8668 |
}, |
| 8669 |
|
| 8670 |
isCursorAtEnd: function() { |
| 8671 |
var valueLength; |
| 8672 |
var selectionStart; |
| 8673 |
var range; |
| 8674 |
|
| 8675 |
valueLength = this.$input.val().length; |
| 8676 |
selectionStart = this.$input[0].selectionStart; |
| 8677 |
|
| 8678 |
if (_.isNumber(selectionStart)) { |
| 8679 |
return selectionStart === valueLength; |
| 8680 |
} else if (document.selection) { |
| 8681 |
// NOTE: this won't work unless the input has focus, the good news |
| 8682 |
// is this code should only get called when the input has focus |
| 8683 |
range = document.selection.createRange(); |
| 8684 |
range.moveStart('character', -valueLength); |
| 8685 |
|
| 8686 |
return valueLength === range.text.length; |
| 8687 |
} |
| 8688 |
|
| 8689 |
return true; |
| 8690 |
}, |
| 8691 |
|
| 8692 |
destroy: function destroy() { |
| 8693 |
this.$hint.off('.aa'); |
| 8694 |
this.$input.off('.aa'); |
| 8695 |
|
| 8696 |
this.$hint = this.$input = this.$overflowHelper = null; |
| 8697 |
} |
| 8698 |
}); |
| 8699 |
|
| 8700 |
// helper functions |
| 8701 |
// ---------------- |
| 8702 |
|
| 8703 |
function buildOverflowHelper($input) { |
| 8704 |
return DOM.element('<pre aria-hidden="true"></pre>') |
| 8705 |
.css({ |
| 8706 |
// position helper off-screen |
| 8707 |
position: 'absolute', |
| 8708 |
visibility: 'hidden', |
| 8709 |
// avoid line breaks and whitespace collapsing |
| 8710 |
whiteSpace: 'pre', |
| 8711 |
// use same font css as input to calculate accurate width |
| 8712 |
fontFamily: $input.css('font-family'), |
| 8713 |
fontSize: $input.css('font-size'), |
| 8714 |
fontStyle: $input.css('font-style'), |
| 8715 |
fontVariant: $input.css('font-variant'), |
| 8716 |
fontWeight: $input.css('font-weight'), |
| 8717 |
wordSpacing: $input.css('word-spacing'), |
| 8718 |
letterSpacing: $input.css('letter-spacing'), |
| 8719 |
textIndent: $input.css('text-indent'), |
| 8720 |
textRendering: $input.css('text-rendering'), |
| 8721 |
textTransform: $input.css('text-transform') |
| 8722 |
}) |
| 8723 |
.insertAfter($input); |
| 8724 |
} |
| 8725 |
|
| 8726 |
function areQueriesEquivalent(a, b) { |
| 8727 |
return Input.normalizeQuery(a) === Input.normalizeQuery(b); |
| 8728 |
} |
| 8729 |
|
| 8730 |
function withModifier($e) { |
| 8731 |
return $e.altKey || $e.ctrlKey || $e.metaKey || $e.shiftKey; |
| 8732 |
} |
| 8733 |
|
| 8734 |
module.exports = Input; |
| 8735 |
|
| 8736 |
|
| 8737 |
/***/ }), |
| 8738 |
/* 53 */ |
| 8739 |
/***/ (function(module, exports, __webpack_require__) { |
| 8740 |
|
| 8741 |
"use strict"; |
| 8742 |
|
| 8743 |
var types = [ |
| 8744 |
__webpack_require__(54), |
| 8745 |
__webpack_require__(55), |
| 8746 |
__webpack_require__(56), |
| 8747 |
__webpack_require__(57), |
| 8748 |
__webpack_require__(58) |
| 8749 |
]; |
| 8750 |
var draining; |
| 8751 |
var currentQueue; |
| 8752 |
var queueIndex = -1; |
| 8753 |
var queue = []; |
| 8754 |
var scheduled = false; |
| 8755 |
function cleanUpNextTick() { |
| 8756 |
if (!draining || !currentQueue) { |
| 8757 |
return; |
| 8758 |
} |
| 8759 |
draining = false; |
| 8760 |
if (currentQueue.length) { |
| 8761 |
queue = currentQueue.concat(queue); |
| 8762 |
} else { |
| 8763 |
queueIndex = -1; |
| 8764 |
} |
| 8765 |
if (queue.length) { |
| 8766 |
nextTick(); |
| 8767 |
} |
| 8768 |
} |
| 8769 |
|
| 8770 |
//named nextTick for less confusing stack traces |
| 8771 |
function nextTick() { |
| 8772 |
if (draining) { |
| 8773 |
return; |
| 8774 |
} |
| 8775 |
scheduled = false; |
| 8776 |
draining = true; |
| 8777 |
var len = queue.length; |
| 8778 |
var timeout = setTimeout(cleanUpNextTick); |
| 8779 |
while (len) { |
| 8780 |
currentQueue = queue; |
| 8781 |
queue = []; |
| 8782 |
while (currentQueue && ++queueIndex < len) { |
| 8783 |
currentQueue[queueIndex].run(); |
| 8784 |
} |
| 8785 |
queueIndex = -1; |
| 8786 |
len = queue.length; |
| 8787 |
} |
| 8788 |
currentQueue = null; |
| 8789 |
queueIndex = -1; |
| 8790 |
draining = false; |
| 8791 |
clearTimeout(timeout); |
| 8792 |
} |
| 8793 |
var scheduleDrain; |
| 8794 |
var i = -1; |
| 8795 |
var len = types.length; |
| 8796 |
while (++i < len) { |
| 8797 |
if (types[i] && types[i].test && types[i].test()) { |
| 8798 |
scheduleDrain = types[i].install(nextTick); |
| 8799 |
break; |
| 8800 |
} |
| 8801 |
} |
| 8802 |
// v8 likes predictible objects |
| 8803 |
function Item(fun, array) { |
| 8804 |
this.fun = fun; |
| 8805 |
this.array = array; |
| 8806 |
} |
| 8807 |
Item.prototype.run = function () { |
| 8808 |
var fun = this.fun; |
| 8809 |
var array = this.array; |
| 8810 |
switch (array.length) { |
| 8811 |
case 0: |
| 8812 |
return fun(); |
| 8813 |
case 1: |
| 8814 |
return fun(array[0]); |
| 8815 |
case 2: |
| 8816 |
return fun(array[0], array[1]); |
| 8817 |
case 3: |
| 8818 |
return fun(array[0], array[1], array[2]); |
| 8819 |
default: |
| 8820 |
return fun.apply(null, array); |
| 8821 |
} |
| 8822 |
|
| 8823 |
}; |
| 8824 |
module.exports = immediate; |
| 8825 |
function immediate(task) { |
| 8826 |
var args = new Array(arguments.length - 1); |
| 8827 |
if (arguments.length > 1) { |
| 8828 |
for (var i = 1; i < arguments.length; i++) { |
| 8829 |
args[i - 1] = arguments[i]; |
| 8830 |
} |
| 8831 |
} |
| 8832 |
queue.push(new Item(task, args)); |
| 8833 |
if (!scheduled && !draining) { |
| 8834 |
scheduled = true; |
| 8835 |
scheduleDrain(); |
| 8836 |
} |
| 8837 |
} |
| 8838 |
|
| 8839 |
|
| 8840 |
/***/ }), |
| 8841 |
/* 54 */ |
| 8842 |
/***/ (function(module, exports, __webpack_require__) { |
| 8843 |
|
| 8844 |
"use strict"; |
| 8845 |
/* WEBPACK VAR INJECTION */(function(process) { |
| 8846 |
exports.test = function () { |
| 8847 |
// Don't get fooled by e.g. browserify environments. |
| 8848 |
return (typeof process !== 'undefined') && !process.browser; |
| 8849 |
}; |
| 8850 |
|
| 8851 |
exports.install = function (func) { |
| 8852 |
return function () { |
| 8853 |
process.nextTick(func); |
| 8854 |
}; |
| 8855 |
}; |
| 8856 |
|
| 8857 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9))) |
| 8858 |
|
| 8859 |
/***/ }), |
| 8860 |
/* 55 */ |
| 8861 |
/***/ (function(module, exports, __webpack_require__) { |
| 8862 |
|
| 8863 |
"use strict"; |
| 8864 |
/* WEBPACK VAR INJECTION */(function(global) { |
| 8865 |
//based off rsvp https://github.com/tildeio/rsvp.js |
| 8866 |
//license https://github.com/tildeio/rsvp.js/blob/master/LICENSE |
| 8867 |
//https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp/asap.js |
| 8868 |
|
| 8869 |
var Mutation = global.MutationObserver || global.WebKitMutationObserver; |
| 8870 |
|
| 8871 |
exports.test = function () { |
| 8872 |
return Mutation; |
| 8873 |
}; |
| 8874 |
|
| 8875 |
exports.install = function (handle) { |
| 8876 |
var called = 0; |
| 8877 |
var observer = new Mutation(handle); |
| 8878 |
var element = global.document.createTextNode(''); |
| 8879 |
observer.observe(element, { |
| 8880 |
characterData: true |
| 8881 |
}); |
| 8882 |
return function () { |
| 8883 |
element.data = (called = ++called % 2); |
| 8884 |
}; |
| 8885 |
}; |
| 8886 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) |
| 8887 |
|
| 8888 |
/***/ }), |
| 8889 |
/* 56 */ |
| 8890 |
/***/ (function(module, exports, __webpack_require__) { |
| 8891 |
|
| 8892 |
"use strict"; |
| 8893 |
/* WEBPACK VAR INJECTION */(function(global) { |
| 8894 |
|
| 8895 |
exports.test = function () { |
| 8896 |
if (global.setImmediate) { |
| 8897 |
// we can only get here in IE10 |
| 8898 |
// which doesn't handel postMessage well |
| 8899 |
return false; |
| 8900 |
} |
| 8901 |
return typeof global.MessageChannel !== 'undefined'; |
| 8902 |
}; |
| 8903 |
|
| 8904 |
exports.install = function (func) { |
| 8905 |
var channel = new global.MessageChannel(); |
| 8906 |
channel.port1.onmessage = func; |
| 8907 |
return function () { |
| 8908 |
channel.port2.postMessage(0); |
| 8909 |
}; |
| 8910 |
}; |
| 8911 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) |
| 8912 |
|
| 8913 |
/***/ }), |
| 8914 |
/* 57 */ |
| 8915 |
/***/ (function(module, exports, __webpack_require__) { |
| 8916 |
|
| 8917 |
"use strict"; |
| 8918 |
/* WEBPACK VAR INJECTION */(function(global) { |
| 8919 |
|
| 8920 |
exports.test = function () { |
| 8921 |
return 'document' in global && 'onreadystatechange' in global.document.createElement('script'); |
| 8922 |
}; |
| 8923 |
|
| 8924 |
exports.install = function (handle) { |
| 8925 |
return function () { |
| 8926 |
|
| 8927 |
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted |
| 8928 |
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called. |
| 8929 |
var scriptEl = global.document.createElement('script'); |
| 8930 |
scriptEl.onreadystatechange = function () { |
| 8931 |
handle(); |
| 8932 |
|
| 8933 |
scriptEl.onreadystatechange = null; |
| 8934 |
scriptEl.parentNode.removeChild(scriptEl); |
| 8935 |
scriptEl = null; |
| 8936 |
}; |
| 8937 |
global.document.documentElement.appendChild(scriptEl); |
| 8938 |
|
| 8939 |
return handle; |
| 8940 |
}; |
| 8941 |
}; |
| 8942 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) |
| 8943 |
|
| 8944 |
/***/ }), |
| 8945 |
/* 58 */ |
| 8946 |
/***/ (function(module, exports, __webpack_require__) { |
| 8947 |
|
| 8948 |
"use strict"; |
| 8949 |
|
| 8950 |
exports.test = function () { |
| 8951 |
return true; |
| 8952 |
}; |
| 8953 |
|
| 8954 |
exports.install = function (t) { |
| 8955 |
return function () { |
| 8956 |
setTimeout(t, 0); |
| 8957 |
}; |
| 8958 |
}; |
| 8959 |
|
| 8960 |
/***/ }), |
| 8961 |
/* 59 */ |
| 8962 |
/***/ (function(module, exports, __webpack_require__) { |
| 8963 |
|
| 8964 |
"use strict"; |
| 8965 |
|
| 8966 |
|
| 8967 |
var _ = __webpack_require__(0); |
| 8968 |
var DOM = __webpack_require__(1); |
| 8969 |
var EventEmitter = __webpack_require__(10); |
| 8970 |
var Dataset = __webpack_require__(60); |
| 8971 |
var css = __webpack_require__(11); |
| 8972 |
|
| 8973 |
// constructor |
| 8974 |
// ----------- |
| 8975 |
|
| 8976 |
function Dropdown(o) { |
| 8977 |
var that = this; |
| 8978 |
var onSuggestionClick; |
| 8979 |
var onSuggestionMouseEnter; |
| 8980 |
var onSuggestionMouseLeave; |
| 8981 |
|
| 8982 |
o = o || {}; |
| 8983 |
|
| 8984 |
if (!o.menu) { |
| 8985 |
_.error('menu is required'); |
| 8986 |
} |
| 8987 |
|
| 8988 |
if (!_.isArray(o.datasets) && !_.isObject(o.datasets)) { |
| 8989 |
_.error('1 or more datasets required'); |
| 8990 |
} |
| 8991 |
if (!o.datasets) { |
| 8992 |
_.error('datasets is required'); |
| 8993 |
} |
| 8994 |
|
| 8995 |
this.isOpen = false; |
| 8996 |
this.isEmpty = true; |
| 8997 |
this.minLength = o.minLength || 0; |
| 8998 |
this.templates = {}; |
| 8999 |
this.appendTo = o.appendTo || false; |
| 9000 |
this.css = _.mixin({}, css, o.appendTo ? css.appendTo : {}); |
| 9001 |
this.cssClasses = o.cssClasses = _.mixin({}, css.defaultClasses, o.cssClasses || {}); |
| 9002 |
this.cssClasses.prefix = |
| 9003 |
o.cssClasses.formattedPrefix || _.formatPrefix(this.cssClasses.prefix, this.cssClasses.noPrefix); |
| 9004 |
|
| 9005 |
// bound functions |
| 9006 |
onSuggestionClick = _.bind(this._onSuggestionClick, this); |
| 9007 |
onSuggestionMouseEnter = _.bind(this._onSuggestionMouseEnter, this); |
| 9008 |
onSuggestionMouseLeave = _.bind(this._onSuggestionMouseLeave, this); |
| 9009 |
|
| 9010 |
var cssClass = _.className(this.cssClasses.prefix, this.cssClasses.suggestion); |
| 9011 |
this.$menu = DOM.element(o.menu) |
| 9012 |
.on('mouseenter.aa', cssClass, onSuggestionMouseEnter) |
| 9013 |
.on('mouseleave.aa', cssClass, onSuggestionMouseLeave) |
| 9014 |
.on('click.aa', cssClass, onSuggestionClick); |
| 9015 |
|
| 9016 |
this.$container = o.appendTo ? o.wrapper : this.$menu; |
| 9017 |
|
| 9018 |
if (o.templates && o.templates.header) { |
| 9019 |
this.templates.header = _.templatify(o.templates.header); |
| 9020 |
this.$menu.prepend(this.templates.header()); |
| 9021 |
} |
| 9022 |
|
| 9023 |
if (o.templates && o.templates.empty) { |
| 9024 |
this.templates.empty = _.templatify(o.templates.empty); |
| 9025 |
this.$empty = DOM.element('<div class="' + |
| 9026 |
_.className(this.cssClasses.prefix, this.cssClasses.empty, true) + '">' + |
| 9027 |
'</div>'); |
| 9028 |
this.$menu.append(this.$empty); |
| 9029 |
this.$empty.hide(); |
| 9030 |
} |
| 9031 |
|
| 9032 |
this.datasets = _.map(o.datasets, function(oDataset) { |
| 9033 |
return initializeDataset(that.$menu, oDataset, o.cssClasses); |
| 9034 |
}); |
| 9035 |
_.each(this.datasets, function(dataset) { |
| 9036 |
var root = dataset.getRoot(); |
| 9037 |
if (root && root.parent().length === 0) { |
| 9038 |
that.$menu.append(root); |
| 9039 |
} |
| 9040 |
dataset.onSync('rendered', that._onRendered, that); |
| 9041 |
}); |
| 9042 |
|
| 9043 |
if (o.templates && o.templates.footer) { |
| 9044 |
this.templates.footer = _.templatify(o.templates.footer); |
| 9045 |
this.$menu.append(this.templates.footer()); |
| 9046 |
} |
| 9047 |
|
| 9048 |
var self = this; |
| 9049 |
DOM.element(window).resize(function() { |
| 9050 |
self._redraw(); |
| 9051 |
}); |
| 9052 |
} |
| 9053 |
|
| 9054 |
// instance methods |
| 9055 |
// ---------------- |
| 9056 |
|
| 9057 |
_.mixin(Dropdown.prototype, EventEmitter, { |
| 9058 |
|
| 9059 |
// ### private |
| 9060 |
|
| 9061 |
_onSuggestionClick: function onSuggestionClick($e) { |
| 9062 |
this.trigger('suggestionClicked', DOM.element($e.currentTarget)); |
| 9063 |
}, |
| 9064 |
|
| 9065 |
_onSuggestionMouseEnter: function onSuggestionMouseEnter($e) { |
| 9066 |
var elt = DOM.element($e.currentTarget); |
| 9067 |
if (elt.hasClass(_.className(this.cssClasses.prefix, this.cssClasses.cursor, true))) { |
| 9068 |
// we're already on the cursor |
| 9069 |
// => we're probably entering it again after leaving it for a nested div |
| 9070 |
return; |
| 9071 |
} |
| 9072 |
this._removeCursor(); |
| 9073 |
|
| 9074 |
// Fixes iOS double tap behaviour, by modifying the DOM right before the |
| 9075 |
// native href clicks happens, iOS will requires another tap to follow |
| 9076 |
// a suggestion that has an <a href> element inside |
| 9077 |
// https://www.google.com/search?q=ios+double+tap+bug+href |
| 9078 |
var suggestion = this; |
| 9079 |
setTimeout(function() { |
| 9080 |
// this exact line, when inside the main loop, will trigger a double tap bug |
| 9081 |
// on iOS devices |
| 9082 |
suggestion._setCursor(elt, false); |
| 9083 |
}, 0); |
| 9084 |
}, |
| 9085 |
|
| 9086 |
_onSuggestionMouseLeave: function onSuggestionMouseLeave($e) { |
| 9087 |
// $e.relatedTarget is the `EventTarget` the pointing device entered to |
| 9088 |
if ($e.relatedTarget) { |
| 9089 |
var elt = DOM.element($e.relatedTarget); |
| 9090 |
if (elt.closest('.' + _.className(this.cssClasses.prefix, this.cssClasses.cursor, true)).length > 0) { |
| 9091 |
// our father is a cursor |
| 9092 |
// => it means we're just leaving the suggestion for a nested div |
| 9093 |
return; |
| 9094 |
} |
| 9095 |
} |
| 9096 |
this._removeCursor(); |
| 9097 |
this.trigger('cursorRemoved'); |
| 9098 |
}, |
| 9099 |
|
| 9100 |
_onRendered: function onRendered(e, query) { |
| 9101 |
this.isEmpty = _.every(this.datasets, isDatasetEmpty); |
| 9102 |
|
| 9103 |
if (this.isEmpty) { |
| 9104 |
if (query.length >= this.minLength) { |
| 9105 |
this.trigger('empty'); |
| 9106 |
} |
| 9107 |
|
| 9108 |
if (this.$empty) { |
| 9109 |
if (query.length < this.minLength) { |
| 9110 |
this._hide(); |
| 9111 |
} else { |
| 9112 |
var html = this.templates.empty({ |
| 9113 |
query: this.datasets[0] && this.datasets[0].query |
| 9114 |
}); |
| 9115 |
this.$empty.html(html); |
| 9116 |
this.$empty.show(); |
| 9117 |
this._show(); |
| 9118 |
} |
| 9119 |
} else if (_.any(this.datasets, hasEmptyTemplate)) { |
| 9120 |
if (query.length < this.minLength) { |
| 9121 |
this._hide(); |
| 9122 |
} else { |
| 9123 |
this._show(); |
| 9124 |
} |
| 9125 |
} else { |
| 9126 |
this._hide(); |
| 9127 |
} |
| 9128 |
} else if (this.isOpen) { |
| 9129 |
if (this.$empty) { |
| 9130 |
this.$empty.empty(); |
| 9131 |
this.$empty.hide(); |
| 9132 |
} |
| 9133 |
|
| 9134 |
if (query.length >= this.minLength) { |
| 9135 |
this._show(); |
| 9136 |
} else { |
| 9137 |
this._hide(); |
| 9138 |
} |
| 9139 |
} |
| 9140 |
|
| 9141 |
this.trigger('datasetRendered'); |
| 9142 |
|
| 9143 |
function isDatasetEmpty(dataset) { |
| 9144 |
return dataset.isEmpty(); |
| 9145 |
} |
| 9146 |
|
| 9147 |
function hasEmptyTemplate(dataset) { |
| 9148 |
return dataset.templates && dataset.templates.empty; |
| 9149 |
} |
| 9150 |
}, |
| 9151 |
|
| 9152 |
_hide: function() { |
| 9153 |
this.$container.hide(); |
| 9154 |
}, |
| 9155 |
|
| 9156 |
_show: function() { |
| 9157 |
// can't use jQuery#show because $menu is a span element we want |
| 9158 |
// display: block; not dislay: inline; |
| 9159 |
this.$container.css('display', 'block'); |
| 9160 |
|
| 9161 |
this._redraw(); |
| 9162 |
|
| 9163 |
this.trigger('shown'); |
| 9164 |
}, |
| 9165 |
|
| 9166 |
_redraw: function redraw() { |
| 9167 |
if (!this.isOpen || !this.appendTo) return; |
| 9168 |
|
| 9169 |
this.trigger('redrawn'); |
| 9170 |
}, |
| 9171 |
|
| 9172 |
_getSuggestions: function getSuggestions() { |
| 9173 |
return this.$menu.find(_.className(this.cssClasses.prefix, this.cssClasses.suggestion)); |
| 9174 |
}, |
| 9175 |
|
| 9176 |
_getCursor: function getCursor() { |
| 9177 |
return this.$menu.find(_.className(this.cssClasses.prefix, this.cssClasses.cursor)).first(); |
| 9178 |
}, |
| 9179 |
|
| 9180 |
_setCursor: function setCursor($el, updateInput) { |
| 9181 |
$el.first() |
| 9182 |
.addClass(_.className(this.cssClasses.prefix, this.cssClasses.cursor, true)) |
| 9183 |
.attr('aria-selected', 'true'); |
| 9184 |
this.trigger('cursorMoved', updateInput); |
| 9185 |
}, |
| 9186 |
|
| 9187 |
_removeCursor: function removeCursor() { |
| 9188 |
this._getCursor() |
| 9189 |
.removeClass(_.className(this.cssClasses.prefix, this.cssClasses.cursor, true)) |
| 9190 |
.removeAttr('aria-selected'); |
| 9191 |
}, |
| 9192 |
|
| 9193 |
_moveCursor: function moveCursor(increment) { |
| 9194 |
var $suggestions; |
| 9195 |
var $oldCursor; |
| 9196 |
var newCursorIndex; |
| 9197 |
var $newCursor; |
| 9198 |
|
| 9199 |
if (!this.isOpen) { |
| 9200 |
return; |
| 9201 |
} |
| 9202 |
|
| 9203 |
$oldCursor = this._getCursor(); |
| 9204 |
$suggestions = this._getSuggestions(); |
| 9205 |
|
| 9206 |
this._removeCursor(); |
| 9207 |
|
| 9208 |
// shifting before and after modulo to deal with -1 index |
| 9209 |
newCursorIndex = $suggestions.index($oldCursor) + increment; |
| 9210 |
newCursorIndex = (newCursorIndex + 1) % ($suggestions.length + 1) - 1; |
| 9211 |
|
| 9212 |
if (newCursorIndex === -1) { |
| 9213 |
this.trigger('cursorRemoved'); |
| 9214 |
|
| 9215 |
return; |
| 9216 |
} else if (newCursorIndex < -1) { |
| 9217 |
newCursorIndex = $suggestions.length - 1; |
| 9218 |
} |
| 9219 |
|
| 9220 |
this._setCursor($newCursor = $suggestions.eq(newCursorIndex), true); |
| 9221 |
|
| 9222 |
// in the case of scrollable overflow |
| 9223 |
// make sure the cursor is visible in the menu |
| 9224 |
this._ensureVisible($newCursor); |
| 9225 |
}, |
| 9226 |
|
| 9227 |
_ensureVisible: function ensureVisible($el) { |
| 9228 |
var elTop; |
| 9229 |
var elBottom; |
| 9230 |
var menuScrollTop; |
| 9231 |
var menuHeight; |
| 9232 |
|
| 9233 |
elTop = $el.position().top; |
| 9234 |
elBottom = elTop + $el.height() + |
| 9235 |
parseInt($el.css('margin-top'), 10) + |
| 9236 |
parseInt($el.css('margin-bottom'), 10); |
| 9237 |
menuScrollTop = this.$menu.scrollTop(); |
| 9238 |
menuHeight = this.$menu.height() + |
| 9239 |
parseInt(this.$menu.css('padding-top'), 10) + |
| 9240 |
parseInt(this.$menu.css('padding-bottom'), 10); |
| 9241 |
|
| 9242 |
if (elTop < 0) { |
| 9243 |
this.$menu.scrollTop(menuScrollTop + elTop); |
| 9244 |
} else if (menuHeight < elBottom) { |
| 9245 |
this.$menu.scrollTop(menuScrollTop + (elBottom - menuHeight)); |
| 9246 |
} |
| 9247 |
}, |
| 9248 |
|
| 9249 |
// ### public |
| 9250 |
|
| 9251 |
close: function close() { |
| 9252 |
if (this.isOpen) { |
| 9253 |
this.isOpen = false; |
| 9254 |
|
| 9255 |
this._removeCursor(); |
| 9256 |
this._hide(); |
| 9257 |
|
| 9258 |
this.trigger('closed'); |
| 9259 |
} |
| 9260 |
}, |
| 9261 |
|
| 9262 |
open: function open() { |
| 9263 |
if (!this.isOpen) { |
| 9264 |
this.isOpen = true; |
| 9265 |
|
| 9266 |
if (!this.isEmpty) { |
| 9267 |
this._show(); |
| 9268 |
} |
| 9269 |
|
| 9270 |
this.trigger('opened'); |
| 9271 |
} |
| 9272 |
}, |
| 9273 |
|
| 9274 |
setLanguageDirection: function setLanguageDirection(dir) { |
| 9275 |
this.$menu.css(dir === 'ltr' ? this.css.ltr : this.css.rtl); |
| 9276 |
}, |
| 9277 |
|
| 9278 |
moveCursorUp: function moveCursorUp() { |
| 9279 |
this._moveCursor(-1); |
| 9280 |
}, |
| 9281 |
|
| 9282 |
moveCursorDown: function moveCursorDown() { |
| 9283 |
this._moveCursor(+1); |
| 9284 |
}, |
| 9285 |
|
| 9286 |
getDatumForSuggestion: function getDatumForSuggestion($el) { |
| 9287 |
var datum = null; |
| 9288 |
|
| 9289 |
if ($el.length) { |
| 9290 |
datum = { |
| 9291 |
raw: Dataset.extractDatum($el), |
| 9292 |
value: Dataset.extractValue($el), |
| 9293 |
datasetName: Dataset.extractDatasetName($el) |
| 9294 |
}; |
| 9295 |
} |
| 9296 |
|
| 9297 |
return datum; |
| 9298 |
}, |
| 9299 |
|
| 9300 |
getCurrentCursor: function getCurrentCursor() { |
| 9301 |
return this._getCursor().first(); |
| 9302 |
}, |
| 9303 |
|
| 9304 |
getDatumForCursor: function getDatumForCursor() { |
| 9305 |
return this.getDatumForSuggestion(this._getCursor().first()); |
| 9306 |
}, |
| 9307 |
|
| 9308 |
getDatumForTopSuggestion: function getDatumForTopSuggestion() { |
| 9309 |
return this.getDatumForSuggestion(this._getSuggestions().first()); |
| 9310 |
}, |
| 9311 |
|
| 9312 |
cursorTopSuggestion: function cursorTopSuggestion() { |
| 9313 |
this._setCursor(this._getSuggestions().first(), false); |
| 9314 |
}, |
| 9315 |
|
| 9316 |
update: function update(query) { |
| 9317 |
_.each(this.datasets, updateDataset); |
| 9318 |
|
| 9319 |
function updateDataset(dataset) { |
| 9320 |
dataset.update(query); |
| 9321 |
} |
| 9322 |
}, |
| 9323 |
|
| 9324 |
empty: function empty() { |
| 9325 |
_.each(this.datasets, clearDataset); |
| 9326 |
this.isEmpty = true; |
| 9327 |
|
| 9328 |
function clearDataset(dataset) { |
| 9329 |
dataset.clear(); |
| 9330 |
} |
| 9331 |
}, |
| 9332 |
|
| 9333 |
isVisible: function isVisible() { |
| 9334 |
return this.isOpen && !this.isEmpty; |
| 9335 |
}, |
| 9336 |
|
| 9337 |
destroy: function destroy() { |
| 9338 |
this.$menu.off('.aa'); |
| 9339 |
|
| 9340 |
this.$menu = null; |
| 9341 |
|
| 9342 |
_.each(this.datasets, destroyDataset); |
| 9343 |
|
| 9344 |
function destroyDataset(dataset) { |
| 9345 |
dataset.destroy(); |
| 9346 |
} |
| 9347 |
} |
| 9348 |
}); |
| 9349 |
|
| 9350 |
// helper functions |
| 9351 |
// ---------------- |
| 9352 |
Dropdown.Dataset = Dataset; |
| 9353 |
|
| 9354 |
function initializeDataset($menu, oDataset, cssClasses) { |
| 9355 |
return new Dropdown.Dataset(_.mixin({$menu: $menu, cssClasses: cssClasses}, oDataset)); |
| 9356 |
} |
| 9357 |
|
| 9358 |
module.exports = Dropdown; |
| 9359 |
|
| 9360 |
|
| 9361 |
/***/ }), |
| 9362 |
/* 60 */ |
| 9363 |
/***/ (function(module, exports, __webpack_require__) { |
| 9364 |
|
| 9365 |
"use strict"; |
| 9366 |
|
| 9367 |
|
| 9368 |
var datasetKey = 'aaDataset'; |
| 9369 |
var valueKey = 'aaValue'; |
| 9370 |
var datumKey = 'aaDatum'; |
| 9371 |
|
| 9372 |
var _ = __webpack_require__(0); |
| 9373 |
var DOM = __webpack_require__(1); |
| 9374 |
var html = __webpack_require__(17); |
| 9375 |
var css = __webpack_require__(11); |
| 9376 |
var EventEmitter = __webpack_require__(10); |
| 9377 |
|
| 9378 |
// constructor |
| 9379 |
// ----------- |
| 9380 |
|
| 9381 |
function Dataset(o) { |
| 9382 |
o = o || {}; |
| 9383 |
o.templates = o.templates || {}; |
| 9384 |
|
| 9385 |
if (!o.source) { |
| 9386 |
_.error('missing source'); |
| 9387 |
} |
| 9388 |
|
| 9389 |
if (o.name && !isValidName(o.name)) { |
| 9390 |
_.error('invalid dataset name: ' + o.name); |
| 9391 |
} |
| 9392 |
|
| 9393 |
// tracks the last query the dataset was updated for |
| 9394 |
this.query = null; |
| 9395 |
this._isEmpty = true; |
| 9396 |
|
| 9397 |
this.highlight = !!o.highlight; |
| 9398 |
this.name = typeof o.name === 'undefined' || o.name === null ? _.getUniqueId() : o.name; |
| 9399 |
|
| 9400 |
this.source = o.source; |
| 9401 |
this.displayFn = getDisplayFn(o.display || o.displayKey); |
| 9402 |
|
| 9403 |
this.debounce = o.debounce; |
| 9404 |
|
| 9405 |
this.cache = o.cache !== false; |
| 9406 |
|
| 9407 |
this.templates = getTemplates(o.templates, this.displayFn); |
| 9408 |
|
| 9409 |
this.css = _.mixin({}, css, o.appendTo ? css.appendTo : {}); |
| 9410 |
this.cssClasses = o.cssClasses = _.mixin({}, css.defaultClasses, o.cssClasses || {}); |
| 9411 |
this.cssClasses.prefix = |
| 9412 |
o.cssClasses.formattedPrefix || _.formatPrefix(this.cssClasses.prefix, this.cssClasses.noPrefix); |
| 9413 |
|
| 9414 |
var clazz = _.className(this.cssClasses.prefix, this.cssClasses.dataset); |
| 9415 |
this.$el = o.$menu && o.$menu.find(clazz + '-' + this.name).length > 0 ? |
| 9416 |
DOM.element(o.$menu.find(clazz + '-' + this.name)[0]) : |
| 9417 |
DOM.element( |
| 9418 |
html.dataset.replace('%CLASS%', this.name) |
| 9419 |
.replace('%PREFIX%', this.cssClasses.prefix) |
| 9420 |
.replace('%DATASET%', this.cssClasses.dataset) |
| 9421 |
); |
| 9422 |
|
| 9423 |
this.$menu = o.$menu; |
| 9424 |
this.clearCachedSuggestions(); |
| 9425 |
} |
| 9426 |
|
| 9427 |
// static methods |
| 9428 |
// -------------- |
| 9429 |
|
| 9430 |
Dataset.extractDatasetName = function extractDatasetName(el) { |
| 9431 |
return DOM.element(el).data(datasetKey); |
| 9432 |
}; |
| 9433 |
|
| 9434 |
Dataset.extractValue = function extractValue(el) { |
| 9435 |
return DOM.element(el).data(valueKey); |
| 9436 |
}; |
| 9437 |
|
| 9438 |
Dataset.extractDatum = function extractDatum(el) { |
| 9439 |
var datum = DOM.element(el).data(datumKey); |
| 9440 |
if (typeof datum === 'string') { |
| 9441 |
// Zepto has an automatic deserialization of the |
| 9442 |
// JSON encoded data attribute |
| 9443 |
datum = JSON.parse(datum); |
| 9444 |
} |
| 9445 |
return datum; |
| 9446 |
}; |
| 9447 |
|
| 9448 |
// instance methods |
| 9449 |
// ---------------- |
| 9450 |
|
| 9451 |
_.mixin(Dataset.prototype, EventEmitter, { |
| 9452 |
|
| 9453 |
// ### private |
| 9454 |
|
| 9455 |
_render: function render(query, suggestions) { |
| 9456 |
if (!this.$el) { |
| 9457 |
return; |
| 9458 |
} |
| 9459 |
var that = this; |
| 9460 |
|
| 9461 |
var hasSuggestions; |
| 9462 |
var renderArgs = [].slice.call(arguments, 2); |
| 9463 |
this.$el.empty(); |
| 9464 |
|
| 9465 |
hasSuggestions = suggestions && suggestions.length; |
| 9466 |
this._isEmpty = !hasSuggestions; |
| 9467 |
|
| 9468 |
if (!hasSuggestions && this.templates.empty) { |
| 9469 |
this.$el |
| 9470 |
.html(getEmptyHtml.apply(this, renderArgs)) |
| 9471 |
.prepend(that.templates.header ? getHeaderHtml.apply(this, renderArgs) : null) |
| 9472 |
.append(that.templates.footer ? getFooterHtml.apply(this, renderArgs) : null); |
| 9473 |
} else if (hasSuggestions) { |
| 9474 |
this.$el |
| 9475 |
.html(getSuggestionsHtml.apply(this, renderArgs)) |
| 9476 |
.prepend(that.templates.header ? getHeaderHtml.apply(this, renderArgs) : null) |
| 9477 |
.append(that.templates.footer ? getFooterHtml.apply(this, renderArgs) : null); |
| 9478 |
} else if (suggestions && !Array.isArray(suggestions)) { |
| 9479 |
throw new TypeError('suggestions must be an array'); |
| 9480 |
} |
| 9481 |
|
| 9482 |
if (this.$menu) { |
| 9483 |
this.$menu.addClass( |
| 9484 |
this.cssClasses.prefix + (hasSuggestions ? 'with' : 'without') + '-' + this.name |
| 9485 |
).removeClass( |
| 9486 |
this.cssClasses.prefix + (hasSuggestions ? 'without' : 'with') + '-' + this.name |
| 9487 |
); |
| 9488 |
} |
| 9489 |
|
| 9490 |
this.trigger('rendered', query); |
| 9491 |
|
| 9492 |
function getEmptyHtml() { |
| 9493 |
var args = [].slice.call(arguments, 0); |
| 9494 |
args = [{query: query, isEmpty: true}].concat(args); |
| 9495 |
return that.templates.empty.apply(this, args); |
| 9496 |
} |
| 9497 |
|
| 9498 |
function getSuggestionsHtml() { |
| 9499 |
var args = [].slice.call(arguments, 0); |
| 9500 |
var $suggestions; |
| 9501 |
var nodes; |
| 9502 |
var self = this; |
| 9503 |
|
| 9504 |
var suggestionsHtml = html.suggestions. |
| 9505 |
replace('%PREFIX%', this.cssClasses.prefix). |
| 9506 |
replace('%SUGGESTIONS%', this.cssClasses.suggestions); |
| 9507 |
$suggestions = DOM |
| 9508 |
.element(suggestionsHtml) |
| 9509 |
.css(this.css.suggestions); |
| 9510 |
|
| 9511 |
// jQuery#append doesn't support arrays as the first argument |
| 9512 |
// until version 1.8, see http://bugs.jquery.com/ticket/11231 |
| 9513 |
nodes = _.map(suggestions, getSuggestionNode); |
| 9514 |
$suggestions.append.apply($suggestions, nodes); |
| 9515 |
|
| 9516 |
return $suggestions; |
| 9517 |
|
| 9518 |
function getSuggestionNode(suggestion) { |
| 9519 |
var $el; |
| 9520 |
|
| 9521 |
var suggestionHtml = html.suggestion. |
| 9522 |
replace('%PREFIX%', self.cssClasses.prefix). |
| 9523 |
replace('%SUGGESTION%', self.cssClasses.suggestion); |
| 9524 |
$el = DOM.element(suggestionHtml) |
| 9525 |
.attr({ |
| 9526 |
role: 'option', |
| 9527 |
id: ['option', Math.floor(Math.random() * 100000000)].join('-') |
| 9528 |
}) |
| 9529 |
.append(that.templates.suggestion.apply(this, [suggestion].concat(args))); |
| 9530 |
|
| 9531 |
$el.data(datasetKey, that.name); |
| 9532 |
$el.data(valueKey, that.displayFn(suggestion) || undefined); // this led to undefined return value |
| 9533 |
$el.data(datumKey, JSON.stringify(suggestion)); |
| 9534 |
$el.children().each(function() { DOM.element(this).css(self.css.suggestionChild); }); |
| 9535 |
|
| 9536 |
return $el; |
| 9537 |
} |
| 9538 |
} |
| 9539 |
|
| 9540 |
function getHeaderHtml() { |
| 9541 |
var args = [].slice.call(arguments, 0); |
| 9542 |
args = [{query: query, isEmpty: !hasSuggestions}].concat(args); |
| 9543 |
return that.templates.header.apply(this, args); |
| 9544 |
} |
| 9545 |
|
| 9546 |
function getFooterHtml() { |
| 9547 |
var args = [].slice.call(arguments, 0); |
| 9548 |
args = [{query: query, isEmpty: !hasSuggestions}].concat(args); |
| 9549 |
return that.templates.footer.apply(this, args); |
| 9550 |
} |
| 9551 |
}, |
| 9552 |
|
| 9553 |
// ### public |
| 9554 |
|
| 9555 |
getRoot: function getRoot() { |
| 9556 |
return this.$el; |
| 9557 |
}, |
| 9558 |
|
| 9559 |
update: function update(query) { |
| 9560 |
function handleSuggestions(suggestions) { |
| 9561 |
// if the update has been canceled or if the query has changed |
| 9562 |
// do not render the suggestions as they've become outdated |
| 9563 |
if (!this.canceled && query === this.query) { |
| 9564 |
// concat all the other arguments that could have been passed |
| 9565 |
// to the render function, and forward them to _render |
| 9566 |
var extraArgs = [].slice.call(arguments, 1); |
| 9567 |
this.cacheSuggestions(query, suggestions, extraArgs); |
| 9568 |
this._render.apply(this, [query, suggestions].concat(extraArgs)); |
| 9569 |
} |
| 9570 |
} |
| 9571 |
|
| 9572 |
this.query = query; |
| 9573 |
this.canceled = false; |
| 9574 |
|
| 9575 |
if (this.shouldFetchFromCache(query)) { |
| 9576 |
handleSuggestions.apply(this, [this.cachedSuggestions].concat(this.cachedRenderExtraArgs)); |
| 9577 |
} else { |
| 9578 |
var that = this; |
| 9579 |
var execSource = function() { |
| 9580 |
// When the call is debounced the condition avoid to do a useless |
| 9581 |
// request with the last character when the input has been cleared |
| 9582 |
if (!that.canceled) { |
| 9583 |
that.source(query, handleSuggestions.bind(that)); |
| 9584 |
} |
| 9585 |
}; |
| 9586 |
|
| 9587 |
if (this.debounce) { |
| 9588 |
var later = function() { |
| 9589 |
that.debounceTimeout = null; |
| 9590 |
execSource(); |
| 9591 |
}; |
| 9592 |
clearTimeout(this.debounceTimeout); |
| 9593 |
this.debounceTimeout = setTimeout(later, this.debounce); |
| 9594 |
} else { |
| 9595 |
execSource(); |
| 9596 |
} |
| 9597 |
} |
| 9598 |
}, |
| 9599 |
|
| 9600 |
cacheSuggestions: function cacheSuggestions(query, suggestions, extraArgs) { |
| 9601 |
this.cachedQuery = query; |
| 9602 |
this.cachedSuggestions = suggestions; |
| 9603 |
this.cachedRenderExtraArgs = extraArgs; |
| 9604 |
}, |
| 9605 |
|
| 9606 |
shouldFetchFromCache: function shouldFetchFromCache(query) { |
| 9607 |
return this.cache && |
| 9608 |
this.cachedQuery === query && |
| 9609 |
this.cachedSuggestions && |
| 9610 |
this.cachedSuggestions.length; |
| 9611 |
}, |
| 9612 |
|
| 9613 |
clearCachedSuggestions: function clearCachedSuggestions() { |
| 9614 |
delete this.cachedQuery; |
| 9615 |
delete this.cachedSuggestions; |
| 9616 |
delete this.cachedRenderExtraArgs; |
| 9617 |
}, |
| 9618 |
|
| 9619 |
cancel: function cancel() { |
| 9620 |
this.canceled = true; |
| 9621 |
}, |
| 9622 |
|
| 9623 |
clear: function clear() { |
| 9624 |
this.cancel(); |
| 9625 |
this.$el.empty(); |
| 9626 |
this.trigger('rendered', ''); |
| 9627 |
}, |
| 9628 |
|
| 9629 |
isEmpty: function isEmpty() { |
| 9630 |
return this._isEmpty; |
| 9631 |
}, |
| 9632 |
|
| 9633 |
destroy: function destroy() { |
| 9634 |
this.clearCachedSuggestions(); |
| 9635 |
this.$el = null; |
| 9636 |
} |
| 9637 |
}); |
| 9638 |
|
| 9639 |
// helper functions |
| 9640 |
// ---------------- |
| 9641 |
|
| 9642 |
function getDisplayFn(display) { |
| 9643 |
display = display || 'value'; |
| 9644 |
|
| 9645 |
return _.isFunction(display) ? display : displayFn; |
| 9646 |
|
| 9647 |
function displayFn(obj) { |
| 9648 |
return obj[display]; |
| 9649 |
} |
| 9650 |
} |
| 9651 |
|
| 9652 |
function getTemplates(templates, displayFn) { |
| 9653 |
return { |
| 9654 |
empty: templates.empty && _.templatify(templates.empty), |
| 9655 |
header: templates.header && _.templatify(templates.header), |
| 9656 |
footer: templates.footer && _.templatify(templates.footer), |
| 9657 |
suggestion: templates.suggestion || suggestionTemplate |
| 9658 |
}; |
| 9659 |
|
| 9660 |
function suggestionTemplate(context) { |
| 9661 |
return '<p>' + displayFn(context) + '</p>'; |
| 9662 |
} |
| 9663 |
} |
| 9664 |
|
| 9665 |
function isValidName(str) { |
| 9666 |
// dashes, underscores, letters, and numbers |
| 9667 |
return (/^[_a-zA-Z0-9-]+$/).test(str); |
| 9668 |
} |
| 9669 |
|
| 9670 |
module.exports = Dataset; |
| 9671 |
|
| 9672 |
|
| 9673 |
/***/ }), |
| 9674 |
/* 61 */ |
| 9675 |
/***/ (function(module, exports, __webpack_require__) { |
| 9676 |
|
| 9677 |
"use strict"; |
| 9678 |
|
| 9679 |
|
| 9680 |
module.exports = { |
| 9681 |
hits: __webpack_require__(62), |
| 9682 |
popularIn: __webpack_require__(63) |
| 9683 |
}; |
| 9684 |
|
| 9685 |
|
| 9686 |
/***/ }), |
| 9687 |
/* 62 */ |
| 9688 |
/***/ (function(module, exports, __webpack_require__) { |
| 9689 |
|
| 9690 |
"use strict"; |
| 9691 |
|
| 9692 |
|
| 9693 |
var _ = __webpack_require__(0); |
| 9694 |
var version = __webpack_require__(18); |
| 9695 |
var parseAlgoliaClientVersion = __webpack_require__(19); |
| 9696 |
|
| 9697 |
module.exports = function search(index, params) { |
| 9698 |
var algoliaVersion = parseAlgoliaClientVersion(index.as._ua); |
| 9699 |
if (algoliaVersion && algoliaVersion[0] >= 3 && algoliaVersion[1] > 20) { |
| 9700 |
params = params || {}; |
| 9701 |
params.additionalUA = 'autocomplete.js ' + version; |
| 9702 |
} |
| 9703 |
return sourceFn; |
| 9704 |
|
| 9705 |
function sourceFn(query, cb) { |
| 9706 |
index.search(query, params, function(error, content) { |
| 9707 |
if (error) { |
| 9708 |
_.error(error.message); |
| 9709 |
return; |
| 9710 |
} |
| 9711 |
cb(content.hits, content); |
| 9712 |
}); |
| 9713 |
} |
| 9714 |
}; |
| 9715 |
|
| 9716 |
|
| 9717 |
/***/ }), |
| 9718 |
/* 63 */ |
| 9719 |
/***/ (function(module, exports, __webpack_require__) { |
| 9720 |
|
| 9721 |
"use strict"; |
| 9722 |
|
| 9723 |
|
| 9724 |
var _ = __webpack_require__(0); |
| 9725 |
var version = __webpack_require__(18); |
| 9726 |
var parseAlgoliaClientVersion = __webpack_require__(19); |
| 9727 |
|
| 9728 |
module.exports = function popularIn(index, params, details, options) { |
| 9729 |
var algoliaVersion = parseAlgoliaClientVersion(index.as._ua); |
| 9730 |
if (algoliaVersion && algoliaVersion[0] >= 3 && algoliaVersion[1] > 20) { |
| 9731 |
params = params || {}; |
| 9732 |
params.additionalUA = 'autocomplete.js ' + version; |
| 9733 |
} |
| 9734 |
if (!details.source) { |
| 9735 |
return _.error("Missing 'source' key"); |
| 9736 |
} |
| 9737 |
var source = _.isFunction(details.source) ? details.source : function(hit) { return hit[details.source]; }; |
| 9738 |
|
| 9739 |
if (!details.index) { |
| 9740 |
return _.error("Missing 'index' key"); |
| 9741 |
} |
| 9742 |
var detailsIndex = details.index; |
| 9743 |
|
| 9744 |
options = options || {}; |
| 9745 |
|
| 9746 |
return sourceFn; |
| 9747 |
|
| 9748 |
function sourceFn(query, cb) { |
| 9749 |
index.search(query, params, function(error, content) { |
| 9750 |
if (error) { |
| 9751 |
_.error(error.message); |
| 9752 |
return; |
| 9753 |
} |
| 9754 |
|
| 9755 |
if (content.hits.length > 0) { |
| 9756 |
var first = content.hits[0]; |
| 9757 |
|
| 9758 |
var detailsParams = _.mixin({hitsPerPage: 0}, details); |
| 9759 |
delete detailsParams.source; // not a query parameter |
| 9760 |
delete detailsParams.index; // not a query parameter |
| 9761 |
|
| 9762 |
var detailsAlgoliaVersion = parseAlgoliaClientVersion(detailsIndex.as._ua); |
| 9763 |
if (detailsAlgoliaVersion && detailsAlgoliaVersion[0] >= 3 && detailsAlgoliaVersion[1] > 20) { |
| 9764 |
params.additionalUA = 'autocomplete.js ' + version; |
| 9765 |
} |
| 9766 |
|
| 9767 |
detailsIndex.search(source(first), detailsParams, function(error2, content2) { |
| 9768 |
if (error2) { |
| 9769 |
_.error(error2.message); |
| 9770 |
return; |
| 9771 |
} |
| 9772 |
|
| 9773 |
var suggestions = []; |
| 9774 |
|
| 9775 |
// add the 'all department' entry before others |
| 9776 |
if (options.includeAll) { |
| 9777 |
var label = options.allTitle || 'All departments'; |
| 9778 |
suggestions.push(_.mixin({ |
| 9779 |
facet: {value: label, count: content2.nbHits} |
| 9780 |
}, _.cloneDeep(first))); |
| 9781 |
} |
| 9782 |
|
| 9783 |
// enrich the first hit iterating over the facets |
| 9784 |
_.each(content2.facets, function(values, facet) { |
| 9785 |
_.each(values, function(count, value) { |
| 9786 |
suggestions.push(_.mixin({ |
| 9787 |
facet: {facet: facet, value: value, count: count} |
| 9788 |
}, _.cloneDeep(first))); |
| 9789 |
}); |
| 9790 |
}); |
| 9791 |
|
| 9792 |
// append all other hits |
| 9793 |
for (var i = 1; i < content.hits.length; ++i) { |
| 9794 |
suggestions.push(content.hits[i]); |
| 9795 |
} |
| 9796 |
|
| 9797 |
cb(suggestions, content); |
| 9798 |
}); |
| 9799 |
|
| 9800 |
return; |
| 9801 |
} |
| 9802 |
|
| 9803 |
cb([]); |
| 9804 |
}); |
| 9805 |
} |
| 9806 |
}; |
| 9807 |
|
| 9808 |
|
| 9809 |
/***/ }), |
| 9810 |
/* 64 */ |
| 9811 |
/***/ (function(module, exports, __webpack_require__) { |
| 9812 |
|
| 9813 |
"use strict"; |
| 9814 |
|
| 9815 |
|
| 9816 |
Object.defineProperty(exports, "__esModule", { |
| 9817 |
value: true |
| 9818 |
}); |
| 9819 |
var prefix = 'algolia-docsearch'; |
| 9820 |
var suggestionPrefix = prefix + '-suggestion'; |
| 9821 |
var footerPrefix = prefix + '-footer'; |
| 9822 |
|
| 9823 |
/* eslint-disable max-len */ |
| 9824 |
|
| 9825 |
var templates = { |
| 9826 |
suggestion: '\n <a class="' + suggestionPrefix + '\n {{#isCategoryHeader}}' + suggestionPrefix + '__main{{/isCategoryHeader}}\n {{#isSubCategoryHeader}}' + suggestionPrefix + '__secondary{{/isSubCategoryHeader}}\n "\n aria-label="Link to the result"\n href="{{{url}}}"\n >\n <div class="' + suggestionPrefix + '--category-header">\n <span class="' + suggestionPrefix + '--category-header-lvl0">{{{category}}}</span>\n </div>\n <div class="' + suggestionPrefix + '--wrapper">\n <div class="' + suggestionPrefix + '--subcategory-column">\n <span class="' + suggestionPrefix + '--subcategory-column-text">{{{subcategory}}}</span>\n </div>\n {{#isTextOrSubcategoryNonEmpty}}\n <div class="' + suggestionPrefix + '--content">\n <div class="' + suggestionPrefix + '--subcategory-inline">{{{subcategory}}}</div>\n <div class="' + suggestionPrefix + '--title">{{{title}}}</div>\n {{#text}}<div class="' + suggestionPrefix + '--text">{{{text}}}</div>{{/text}}\n </div>\n {{/isTextOrSubcategoryNonEmpty}}\n </div>\n </a>\n ', |
| 9827 |
suggestionSimple: '\n <div class="' + suggestionPrefix + '\n {{#isCategoryHeader}}' + suggestionPrefix + '__main{{/isCategoryHeader}}\n {{#isSubCategoryHeader}}' + suggestionPrefix + '__secondary{{/isSubCategoryHeader}}\n suggestion-layout-simple\n ">\n <div class="' + suggestionPrefix + '--category-header">\n {{^isLvl0}}\n <span class="' + suggestionPrefix + '--category-header-lvl0 ' + suggestionPrefix + '--category-header-item">{{{category}}}</span>\n {{^isLvl1}}\n {{^isLvl1EmptyOrDuplicate}}\n <span class="' + suggestionPrefix + '--category-header-lvl1 ' + suggestionPrefix + '--category-header-item">\n {{{subcategory}}}\n </span>\n {{/isLvl1EmptyOrDuplicate}}\n {{/isLvl1}}\n {{/isLvl0}}\n <div class="' + suggestionPrefix + '--title ' + suggestionPrefix + '--category-header-item">\n {{#isLvl2}}\n {{{title}}}\n {{/isLvl2}}\n {{#isLvl1}}\n {{{subcategory}}}\n {{/isLvl1}}\n {{#isLvl0}}\n {{{category}}}\n {{/isLvl0}}\n </div>\n </div>\n <div class="' + suggestionPrefix + '--wrapper">\n {{#text}}\n <div class="' + suggestionPrefix + '--content">\n <div class="' + suggestionPrefix + '--text">{{{text}}}</div>\n </div>\n {{/text}}\n </div>\n </div>\n ', |
| 9828 |
footer: '\n <div class="' + footerPrefix + '">\n Search by <a class="' + footerPrefix + '--logo" href="https://www.algolia.com/docsearch">Algolia</a>\n </div>\n ', |
| 9829 |
empty: '\n <div class="' + suggestionPrefix + '">\n <div class="' + suggestionPrefix + '--wrapper">\n <div class="' + suggestionPrefix + '--content ' + suggestionPrefix + '--no-results">\n <div class="' + suggestionPrefix + '--title">\n <div class="' + suggestionPrefix + '--text">\n No results found for query <b>"{{query}}"</b>\n </div>\n </div>\n </div>\n </div>\n </div>\n ', |
| 9830 |
searchBox: '\n <form novalidate="novalidate" onsubmit="return false;" class="searchbox">\n <div role="search" class="searchbox__wrapper">\n <input id="docsearch" type="search" name="search" placeholder="Search the docs" autocomplete="off" required="required" class="searchbox__input"/>\n <button type="submit" title="Submit your search query." class="searchbox__submit" >\n <svg width=12 height=12 role="img" aria-label="Search">\n <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#sbx-icon-search-13"></use>\n </svg>\n </button>\n <button type="reset" title="Clear the search query." class="searchbox__reset hide">\n <svg width=12 height=12 role="img" aria-label="Reset">\n <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#sbx-icon-clear-3"></use>\n </svg>\n </button>\n </div>\n</form>\n\n<div class="svg-icons" style="height: 0; width: 0; position: absolute; visibility: hidden">\n <svg xmlns="http://www.w3.org/2000/svg">\n <symbol id="sbx-icon-clear-3" viewBox="0 0 40 40"><path d="M16.228 20L1.886 5.657 0 3.772 3.772 0l1.885 1.886L20 16.228 34.343 1.886 36.228 0 40 3.772l-1.886 1.885L23.772 20l14.342 14.343L40 36.228 36.228 40l-1.885-1.886L20 23.772 5.657 38.114 3.772 40 0 36.228l1.886-1.885L16.228 20z" fill-rule="evenodd"></symbol>\n <symbol id="sbx-icon-search-13" viewBox="0 0 40 40"><path d="M26.806 29.012a16.312 16.312 0 0 1-10.427 3.746C7.332 32.758 0 25.425 0 16.378 0 7.334 7.333 0 16.38 0c9.045 0 16.378 7.333 16.378 16.38 0 3.96-1.406 7.593-3.746 10.426L39.547 37.34c.607.608.61 1.59-.004 2.203a1.56 1.56 0 0 1-2.202.004L26.807 29.012zm-10.427.627c7.322 0 13.26-5.938 13.26-13.26 0-7.324-5.938-13.26-13.26-13.26-7.324 0-13.26 5.936-13.26 13.26 0 7.322 5.936 13.26 13.26 13.26z" fill-rule="evenodd"></symbol>\n </svg>\n</div>\n ' |
| 9831 |
}; |
| 9832 |
|
| 9833 |
exports.default = templates; |
| 9834 |
|
| 9835 |
/***/ }), |
| 9836 |
/* 65 */ |
| 9837 |
/***/ (function(module, exports, __webpack_require__) { |
| 9838 |
|
| 9839 |
"use strict"; |
| 9840 |
|
| 9841 |
|
| 9842 |
Object.defineProperty(exports, "__esModule", { |
| 9843 |
value: true |
| 9844 |
}); |
| 9845 |
|
| 9846 |
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
| 9847 |
|
| 9848 |
var _zepto = __webpack_require__(20); |
| 9849 |
|
| 9850 |
var _zepto2 = _interopRequireDefault(_zepto); |
| 9851 |
|
| 9852 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 9853 |
|
| 9854 |
var utils = { |
| 9855 |
/* |
| 9856 |
* Move the content of an object key one level higher. |
| 9857 |
* eg. |
| 9858 |
* { |
| 9859 |
* name: 'My name', |
| 9860 |
* hierarchy: { |
| 9861 |
* lvl0: 'Foo', |
| 9862 |
* lvl1: 'Bar' |
| 9863 |
* } |
| 9864 |
* } |
| 9865 |
* Will be converted to |
| 9866 |
* { |
| 9867 |
* name: 'My name', |
| 9868 |
* lvl0: 'Foo', |
| 9869 |
* lvl1: 'Bar' |
| 9870 |
* } |
| 9871 |
* @param {Object} object Main object |
| 9872 |
* @param {String} property Main object key to move up |
| 9873 |
* @return {Object} |
| 9874 |
* @throws Error when key is not an attribute of Object or is not an object itself |
| 9875 |
*/ |
| 9876 |
mergeKeyWithParent: function mergeKeyWithParent(object, property) { |
| 9877 |
if (object[property] === undefined) { |
| 9878 |
return object; |
| 9879 |
} |
| 9880 |
if (_typeof(object[property]) !== 'object') { |
| 9881 |
return object; |
| 9882 |
} |
| 9883 |
var newObject = _zepto2.default.extend({}, object, object[property]); |
| 9884 |
delete newObject[property]; |
| 9885 |
return newObject; |
| 9886 |
}, |
| 9887 |
|
| 9888 |
/* |
| 9889 |
* Group all objects of a collection by the value of the specified attribute |
| 9890 |
* If the attribute is a string, use the lowercase form. |
| 9891 |
* |
| 9892 |
* eg. |
| 9893 |
* groupBy([ |
| 9894 |
* {name: 'Tim', category: 'dev'}, |
| 9895 |
* {name: 'Vincent', category: 'dev'}, |
| 9896 |
* {name: 'Ben', category: 'sales'}, |
| 9897 |
* {name: 'Jeremy', category: 'sales'}, |
| 9898 |
* {name: 'AlexS', category: 'dev'}, |
| 9899 |
* {name: 'AlexK', category: 'sales'} |
| 9900 |
* ], 'category'); |
| 9901 |
* => |
| 9902 |
* { |
| 9903 |
* 'devs': [ |
| 9904 |
* {name: 'Tim', category: 'dev'}, |
| 9905 |
* {name: 'Vincent', category: 'dev'}, |
| 9906 |
* {name: 'AlexS', category: 'dev'} |
| 9907 |
* ], |
| 9908 |
* 'sales': [ |
| 9909 |
* {name: 'Ben', category: 'sales'}, |
| 9910 |
* {name: 'Jeremy', category: 'sales'}, |
| 9911 |
* {name: 'AlexK', category: 'sales'} |
| 9912 |
* ] |
| 9913 |
* } |
| 9914 |
* @param {array} collection Array of objects to group |
| 9915 |
* @param {String} property The attribute on which apply the grouping |
| 9916 |
* @return {array} |
| 9917 |
* @throws Error when one of the element does not have the specified property |
| 9918 |
*/ |
| 9919 |
groupBy: function groupBy(collection, property) { |
| 9920 |
var newCollection = {}; |
| 9921 |
_zepto2.default.each(collection, function (index, item) { |
| 9922 |
if (item[property] === undefined) { |
| 9923 |
throw new Error('[groupBy]: Object has no key ' + property); |
| 9924 |
} |
| 9925 |
var key = item[property]; |
| 9926 |
if (typeof key === 'string') { |
| 9927 |
key = key.toLowerCase(); |
| 9928 |
} |
| 9929 |
// fix #171 the given data type of docsearch hits might be conflict with the properties of the native Object, |
| 9930 |
// such as the constructor, so we need to do this check. |
| 9931 |
if (!Object.prototype.hasOwnProperty.call(newCollection, key)) { |
| 9932 |
newCollection[key] = []; |
| 9933 |
} |
| 9934 |
newCollection[key].push(item); |
| 9935 |
}); |
| 9936 |
return newCollection; |
| 9937 |
}, |
| 9938 |
|
| 9939 |
/* |
| 9940 |
* Return an array of all the values of the specified object |
| 9941 |
* eg. |
| 9942 |
* values({ |
| 9943 |
* foo: 42, |
| 9944 |
* bar: true, |
| 9945 |
* baz: 'yep' |
| 9946 |
* }) |
| 9947 |
* => |
| 9948 |
* [42, true, yep] |
| 9949 |
* @param {object} object Object to extract values from |
| 9950 |
* @return {array} |
| 9951 |
*/ |
| 9952 |
values: function values(object) { |
| 9953 |
return Object.keys(object).map(function (key) { |
| 9954 |
return object[key]; |
| 9955 |
}); |
| 9956 |
}, |
| 9957 |
|
| 9958 |
/* |
| 9959 |
* Flattens an array |
| 9960 |
* eg. |
| 9961 |
* flatten([1, 2, [3, 4], [5, 6]]) |
| 9962 |
* => |
| 9963 |
* [1, 2, 3, 4, 5, 6] |
| 9964 |
* @param {array} array Array to flatten |
| 9965 |
* @return {array} |
| 9966 |
*/ |
| 9967 |
flatten: function flatten(array) { |
| 9968 |
var results = []; |
| 9969 |
array.forEach(function (value) { |
| 9970 |
if (!Array.isArray(value)) { |
| 9971 |
results.push(value); |
| 9972 |
return; |
| 9973 |
} |
| 9974 |
value.forEach(function (subvalue) { |
| 9975 |
results.push(subvalue); |
| 9976 |
}); |
| 9977 |
}); |
| 9978 |
return results; |
| 9979 |
}, |
| 9980 |
|
| 9981 |
/* |
| 9982 |
* Flatten all values of an object into an array, marking each first element of |
| 9983 |
* each group with a specific flag |
| 9984 |
* eg. |
| 9985 |
* flattenAndFlagFirst({ |
| 9986 |
* 'devs': [ |
| 9987 |
* {name: 'Tim', category: 'dev'}, |
| 9988 |
* {name: 'Vincent', category: 'dev'}, |
| 9989 |
* {name: 'AlexS', category: 'dev'} |
| 9990 |
* ], |
| 9991 |
* 'sales': [ |
| 9992 |
* {name: 'Ben', category: 'sales'}, |
| 9993 |
* {name: 'Jeremy', category: 'sales'}, |
| 9994 |
* {name: 'AlexK', category: 'sales'} |
| 9995 |
* ] |
| 9996 |
* , 'isTop'); |
| 9997 |
* => |
| 9998 |
* [ |
| 9999 |
* {name: 'Tim', category: 'dev', isTop: true}, |
| 10000 |
* {name: 'Vincent', category: 'dev', isTop: false}, |
| 10001 |
* {name: 'AlexS', category: 'dev', isTop: false}, |
| 10002 |
* {name: 'Ben', category: 'sales', isTop: true}, |
| 10003 |
* {name: 'Jeremy', category: 'sales', isTop: false}, |
| 10004 |
* {name: 'AlexK', category: 'sales', isTop: false} |
| 10005 |
* ] |
| 10006 |
* @param {object} object Object to flatten |
| 10007 |
* @param {string} flag Flag to set to true on first element of each group |
| 10008 |
* @return {array} |
| 10009 |
*/ |
| 10010 |
flattenAndFlagFirst: function flattenAndFlagFirst(object, flag) { |
| 10011 |
var values = this.values(object).map(function (collection) { |
| 10012 |
return collection.map(function (item, index) { |
| 10013 |
// eslint-disable-next-line no-param-reassign |
| 10014 |
item[flag] = index === 0; |
| 10015 |
return item; |
| 10016 |
}); |
| 10017 |
}); |
| 10018 |
return this.flatten(values); |
| 10019 |
}, |
| 10020 |
|
| 10021 |
/* |
| 10022 |
* Removes all empty strings, null, false and undefined elements array |
| 10023 |
* eg. |
| 10024 |
* compact([42, false, null, undefined, '', [], 'foo']); |
| 10025 |
* => |
| 10026 |
* [42, [], 'foo'] |
| 10027 |
* @param {array} array Array to compact |
| 10028 |
* @return {array} |
| 10029 |
*/ |
| 10030 |
compact: function compact(array) { |
| 10031 |
var results = []; |
| 10032 |
array.forEach(function (value) { |
| 10033 |
if (!value) { |
| 10034 |
return; |
| 10035 |
} |
| 10036 |
results.push(value); |
| 10037 |
}); |
| 10038 |
return results; |
| 10039 |
}, |
| 10040 |
|
| 10041 |
/* |
| 10042 |
* Returns the highlighted value of the specified key in the specified object. |
| 10043 |
* If no highlighted value is available, will return the key value directly |
| 10044 |
* eg. |
| 10045 |
* getHighlightedValue({ |
| 10046 |
* _highlightResult: { |
| 10047 |
* text: { |
| 10048 |
* value: '<mark>foo</mark>' |
| 10049 |
* } |
| 10050 |
* }, |
| 10051 |
* text: 'foo' |
| 10052 |
* }, 'text'); |
| 10053 |
* => |
| 10054 |
* '<mark>foo</mark>' |
| 10055 |
* @param {object} object Hit object returned by the Algolia API |
| 10056 |
* @param {string} property Object key to look for |
| 10057 |
* @return {string} |
| 10058 |
**/ |
| 10059 |
getHighlightedValue: function getHighlightedValue(object, property) { |
| 10060 |
if (object._highlightResult && object._highlightResult.hierarchy_camel && object._highlightResult.hierarchy_camel[property] && object._highlightResult.hierarchy_camel[property].matchLevel && object._highlightResult.hierarchy_camel[property].matchLevel !== 'none' && object._highlightResult.hierarchy_camel[property].value) { |
| 10061 |
return object._highlightResult.hierarchy_camel[property].value; |
| 10062 |
} |
| 10063 |
if (object._highlightResult && object._highlightResult && object._highlightResult[property] && object._highlightResult[property].value) { |
| 10064 |
return object._highlightResult[property].value; |
| 10065 |
} |
| 10066 |
return object[property]; |
| 10067 |
}, |
| 10068 |
|
| 10069 |
/* |
| 10070 |
* Returns the snippeted value of the specified key in the specified object. |
| 10071 |
* If no highlighted value is available, will return the key value directly. |
| 10072 |
* Will add starting and ending ellipsis (…) if we detect that a sentence is |
| 10073 |
* incomplete |
| 10074 |
* eg. |
| 10075 |
* getSnippetedValue({ |
| 10076 |
* _snippetResult: { |
| 10077 |
* text: { |
| 10078 |
* value: '<mark>This is an unfinished sentence</mark>' |
| 10079 |
* } |
| 10080 |
* }, |
| 10081 |
* text: 'This is an unfinished sentence' |
| 10082 |
* }, 'text'); |
| 10083 |
* => |
| 10084 |
* '<mark>This is an unfinished sentence</mark>…' |
| 10085 |
* @param {object} object Hit object returned by the Algolia API |
| 10086 |
* @param {string} property Object key to look for |
| 10087 |
* @return {string} |
| 10088 |
**/ |
| 10089 |
getSnippetedValue: function getSnippetedValue(object, property) { |
| 10090 |
if (!object._snippetResult || !object._snippetResult[property] || !object._snippetResult[property].value) { |
| 10091 |
return object[property]; |
| 10092 |
} |
| 10093 |
var snippet = object._snippetResult[property].value; |
| 10094 |
|
| 10095 |
if (snippet[0] !== snippet[0].toUpperCase()) { |
| 10096 |
snippet = '\u2026' + snippet; |
| 10097 |
} |
| 10098 |
if (['.', '!', '?'].indexOf(snippet[snippet.length - 1]) === -1) { |
| 10099 |
snippet = snippet + '\u2026'; |
| 10100 |
} |
| 10101 |
return snippet; |
| 10102 |
}, |
| 10103 |
|
| 10104 |
/* |
| 10105 |
* Deep clone an object. |
| 10106 |
* Note: This will not clone functions and dates |
| 10107 |
* @param {object} object Object to clone |
| 10108 |
* @return {object} |
| 10109 |
*/ |
| 10110 |
deepClone: function deepClone(object) { |
| 10111 |
return JSON.parse(JSON.stringify(object)); |
| 10112 |
} |
| 10113 |
}; |
| 10114 |
|
| 10115 |
exports.default = utils; |
| 10116 |
|
| 10117 |
/***/ }) |
| 10118 |
/******/ ]); |
| 10119 |
}); |
| 10120 |
//# sourceMappingURL=docsearch.js.map |