vendor: 7,835 bytes, lines 1-228
1/*! 2 * typeahead.js 0.11.1 3 * https://github.com/twitter/typeahead.js 4 * Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT 5 */ 6 7(function(root, factory) { 8 if (typeof define === "function" && define.amd) { 9 define("typeahead.js", [ "jquery" ], function(a0) { 10 return factory(a0); 11 }); 12 } else if (typeof exports === "object") { 13 module.exports = factory(require("jquery")); 14 } else { 15 factory(jQuery); 16 } 17})(this, function($) { 18 var _ = function() { 19 "use strict"; 20 return { 21 isMsie: function() { 22 return /(msie|trident)/i.test(navigator.userAgent) ? navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2] : false; 23 }, 24 isBlankString: function(str) { 25 return !str || /^\s*$/.test(str); 26 }, 27 escapeRegExChars: function(str) { 28 return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); 29 }, 30 isString: function(obj) { 31 return typeof obj === "string"; 32 }, 33 isNumber: function(obj) { 34 return typeof obj === "number"; 35 }, 36 isArray: $.isArray, 37 isFunction: $.isFunction, 38 isObject: $.isPlainObject, 39 isUndefined: function(obj) { 40 return typeof obj === "undefined"; 41 }, 42 isElement: function(obj) { 43 return !!(obj && obj.nodeType === 1); 44 }, 45 isJQuery: function(obj) { 46 return obj instanceof $; 47 }, 48 toStr: function toStr(s) { 49 return _.isUndefined(s) || s === null ? "" : s + ""; 50 }, 51 bind: $.proxy, 52 each: function(collection, cb) { 53 $.each(collection, reverseArgs); 54 function reverseArgs(index, value) { 55 return cb(value, index); 56 } 57 }, 58 map: $.map, 59 filter: $.grep, 60 every: function(obj, test) { 61 var result = true; 62 if (!obj) { 63 return result; 64 } 65 $.each(obj, function(key, val) { 66 if (!(result = test.call(null, val, key, obj))) { 67 return false; 68 } 69 }); 70 return !!result; 71 }, 72 some: function(obj, test) { 73 var result = false; 74 if (!obj) { 75 return result; 76 } 77 $.each(obj, function(key, val) { 78 if (result = test.call(null, val, key, obj)) { 79 return false; 80 } 81 }); 82 return !!result; 83 }, 84 mixin: $.extend, 85 identity: function(x) { 86 return x; 87 }, 88 clone: function(obj) { 89 return $.extend(true, {}, obj); 90 }, 91 getIdGenerator: function() { 92 var counter = 0; 93 return function() { 94 return counter++; 95 }; 96 }, 97 templatify: function templatify(obj) { 98 return $.isFunction(obj) ? obj : template; 99 function template() { 100 return String(obj); 101 } 102 }, 103 defer: function(fn) { 104 setTimeout(fn, 0); 105 }, 106 debounce: function(func, wait, immediate) { 107 var timeout, result; 108 return function() { 109 var context = this, args = arguments, later, callNow; 110 later = function() { 111 timeout = null; 112 if (!immediate) { 113 result = func.apply(context, args); 114 } 115 }; 116 callNow = immediate && !timeout; 117 clearTimeout(timeout); 118 timeout = setTimeout(later, wait); 119 if (callNow) { 120 result = func.apply(context, args); 121 } 122 return result; 123 }; 124 }, 125 throttle: function(func, wait) { 126 var context, args, timeout, result, previous, later; 127 previous = 0; 128 later = function() { 129 previous = new Date(); 130 timeout = null; 131 result = func.apply(context, args); 132 }; 133 return function() { 134 var now = new Date(), remaining = wait - (now - previous); 135 context = this; 136 args = arguments; 137 if (remaining <= 0) { 138 clearTimeout(timeout); 139 timeout = null; 140 previous = now; 141 result = func.apply(context, args); 142 } else if (!timeout) { 143 timeout = setTimeout(later, remaining); 144 } 145 return result; 146 }; 147 }, 148 stringify: function(val) { 149 return _.isString(val) ? val : JSON.stringify(val); 150 }, 151 noop: function() {} 152 }; 153 }(); 154 var WWW = function() { 155 "use strict"; 156 var defaultClassNames = { 157 wrapper: "twitter-typeahead", 158 input: "tt-input", 159 hint: "tt-hint", 160 menu: "tt-menu", 161 dataset: "tt-dataset", 162 suggestion: "tt-suggestion", 163 selectable: "tt-selectable", 164 empty: "tt-empty", 165 open: "tt-open", 166 cursor: "tt-cursor", 167 highlight: "tt-highlight" 168 }; 169 return build; 170 function build(o) { 171 var www, classes; 172 classes = _.mixin({}, defaultClassNames, o); 173 www = { 174 css: buildCss(), 175 classes: classes, 176 html: buildHtml(classes), 177 selectors: buildSelectors(classes) 178 }; 179 return { 180 css: www.css, 181 html: www.html, 182 classes: www.classes, 183 selectors: www.selectors, 184 mixin: function(o) { 185 _.mixin(o, www); 186 } 187 }; 188 } 189 function buildHtml(c) { 190 return { 191 wrapper: '<span class="' + c.wrapper + '"></span>', 192 menu: '<div class="' + c.menu + '"></div>' 193 }; 194 } 195 function buildSelectors(classes) { 196 var selectors = {}; 197 _.each(classes, function(v, k) { 198 selectors[k] = "." + v; 199 }); 200 return selectors; 201 } 202 function buildCss() { 203 var css = { 204 wrapper: { 205 position: "relative", 206 display: "inline-block" 207 }, 208 hint: { 209 position: "absolute", 210 top: "0", 211 left: "0", 212 borderColor: "transparent", 213 boxShadow: "none", 214 opacity: "1" 215 }, 216 input: { 217 position: "relative", 218 verticalAlign: "top", 219 backgroundColor: "transparent" 220 }, 221 inputWithNoHint: { 222 position: "relative", 223 verticalAlign: "top" 224 }, 225 menu: { 226 position: "absolute", 227 top: "100%", 228
228//
vendor: 23,877 bytes, lines 228-810
228 left: "0", 229 zIndex: "100", 230 display: "none" 231 }, 232 ltr: { 233 left: "0", 234 right: "auto" 235 }, 236 rtl: { 237 left: "auto", 238 right: " 0" 239 } 240 }; 241 if (_.isMsie()) { 242 _.mixin(css.input, { 243 backgroundImage: "url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)" 244 }); 245 } 246 return css; 247 } 248 }(); 249 var EventBus = function() { 250 "use strict"; 251 var namespace, deprecationMap; 252 namespace = "typeahead:"; 253 deprecationMap = { 254 render: "rendered", 255 cursorchange: "cursorchanged", 256 select: "selected", 257 autocomplete: "autocompleted" 258 }; 259 function EventBus(o) { 260 if (!o || !o.el) { 261 $.error("EventBus initialized without el"); 262 } 263 this.$el = $(o.el); 264 } 265 _.mixin(EventBus.prototype, { 266 _trigger: function(type, args) { 267 var $e; 268 $e = $.Event(namespace + type); 269 (args = args || []).unshift($e); 270 this.$el.trigger.apply(this.$el, args); 271 return $e; 272 }, 273 before: function(type) { 274 var args, $e; 275 args = [].slice.call(arguments, 1); 276 $e = this._trigger("before" + type, args); 277 return $e.isDefaultPrevented(); 278 }, 279 trigger: function(type) { 280 var deprecatedType; 281 this._trigger(type, [].slice.call(arguments, 1)); 282 if (deprecatedType = deprecationMap[type]) { 283 this._trigger(deprecatedType, [].slice.call(arguments, 1)); 284 } 285 } 286 }); 287 return EventBus; 288 }(); 289 var EventEmitter = function() { 290 "use strict"; 291 var splitter = /\s+/, nextTick = getNextTick(); 292 return { 293 onSync: onSync, 294 onAsync: onAsync, 295 off: off, 296 trigger: trigger 297 }; 298 function on(method, types, cb, context) { 299 var type; 300 if (!cb) { 301 return this; 302 } 303 types = types.split(splitter); 304 cb = context ? bindContext(cb, context) : cb; 305 this._callbacks = this._callbacks || {}; 306 while (type = types.shift()) { 307 this._callbacks[type] = this._callbacks[type] || { 308 sync: [], 309 async: [] 310 }; 311 this._callbacks[type][method].push(cb); 312 } 313 return this; 314 } 315 function onAsync(types, cb, context) { 316 return on.call(this, "async", types, cb, context); 317 } 318 function onSync(types, cb, context) { 319 return on.call(this, "sync", types, cb, context); 320 } 321 function off(types) { 322 var type; 323 if (!this._callbacks) { 324 return this; 325 } 326 types = types.split(splitter); 327 while (type = types.shift()) { 328 delete this._callbacks[type]; 329 } 330 return this; 331 } 332 function trigger(types) { 333 var type, callbacks, args, syncFlush, asyncFlush; 334 if (!this._callbacks) { 335 return this; 336 } 337 types = types.split(splitter); 338 args = [].slice.call(arguments, 1); 339 while ((type = types.shift()) && (callbacks = this._callbacks[type])) { 340 syncFlush = getFlush(callbacks.sync, this, [ type ].concat(args)); 341 asyncFlush = getFlush(callbacks.async, this, [ type ].concat(args)); 342 syncFlush() && nextTick(asyncFlush); 343 } 344 return this; 345 } 346 function getFlush(callbacks, context, args) { 347 return flush; 348 function flush() { 349 var cancelled; 350 for (var i = 0, len = callbacks.length; !cancelled && i < len; i += 1) { 351 cancelled = callbacks[i].apply(context, args) === false; 352 } 353 return !cancelled; 354 } 355 } 356 function getNextTick() { 357 var nextTickFn; 358 if (window.setImmediate) { 359 nextTickFn = function nextTickSetImmediate(fn) { 360 setImmediate(function() { 361 fn(); 362 }); 363 }; 364 } else { 365 nextTickFn = function nextTickSetTimeout(fn) { 366 setTimeout(function() { 367 fn(); 368 }, 0); 369 }; 370 } 371 return nextTickFn; 372 } 373 function bindContext(fn, context) { 374 return fn.bind ? fn.bind(context) : function() { 375 fn.apply(context, [].slice.call(arguments, 0)); 376 }; 377 } 378 }(); 379 var highlight = function(doc) { 380 "use strict"; 381 var defaults = { 382 node: null, 383 pattern: null, 384 tagName: "strong", 385 className: null, 386 wordsOnly: false, 387 caseSensitive: false 388 }; 389 return function hightlight(o) { 390 var regex; 391 o = _.mixin({}, defaults, o); 392 if (!o.node || !o.pattern) { 393 return; 394 } 395 o.pattern = _.isArray(o.pattern) ? o.pattern : [ o.pattern ]; 396 regex = getRegex(o.pattern, o.caseSensitive, o.wordsOnly); 397 traverse(o.node, hightlightTextNode); 398 function hightlightTextNode(textNode) { 399 var match, patternNode, wrapperNode; 400 if (match = regex.exec(textNode.data)) { 401 wrapperNode = doc.createElement(o.tagName); 402 o.className && (wrapperNode.className = o.className); 403 patternNode = textNode.splitText(match.index); 404 patternNode.splitText(match[0].length); 405 wrapperNode.appendChild(patternNode.cloneNode(true)); 406 textNode.parentNode.replaceChild(wrapperNode, patternNode); 407 } 408 return !!match; 409 } 410 function traverse(el, hightlightTextNode) { 411 var childNode, TEXT_NODE_TYPE = 3; 412 for (var i = 0; i < el.childNodes.length; i++) { 413 childNode = el.childNodes[i]; 414 if (childNode.nodeType === TEXT_NODE_TYPE) { 415 i += hightlightTextNode(childNode) ? 1 : 0; 416 } else { 417 traverse(childNode, hightlightTextNode); 418 } 419 } 420 } 421 }; 422 function getRegex(patterns, caseSensitive, wordsOnly) { 423 var escapedPatterns = [], regexStr; 424 for (var i = 0, len = patterns.length; i < len; i++) { 425 escapedPatterns.push(_.escapeRegExChars(patterns[i])); 426 } 427 regexStr = wordsOnly ? "\\b(" + escapedPatterns.join("|") + ")\\b" : "(" + escapedPatterns.join("|") + ")"; 428 return caseSensitive ? new RegExp(regexStr) : new RegExp(regexStr, "i"); 429 } 430 }(window.document); 431 var Input = function() { 432 "use strict"; 433 var specialKeyCodeMap; 434 specialKeyCodeMap = { 435 9: "tab", 436 27: "esc", 437 37: "left", 438 39: "right", 439 13: "enter", 440 38: "up", 441 40: "down" 442 }; 443 function Input(o, www) { 444 o = o || {}; 445 if (!o.input) { 446 $.error("input is missing"); 447 } 448 www.mixin(this); 449 this.$hint = $(o.hint); 450 this.$input = $(o.input); 451 this.query = this.$input.val(); 452 this.queryWhenFocused = this.hasFocus() ? this.query : null; 453 this.$overflowHelper = buildOverflowHelper(this.$input); 454 this._checkLanguageDirection(); 455 if (this.$hint.length === 0) { 456 this.setHint = this.getHint = this.clearHint = this.clearHintIfInvalid = _.noop; 457 } 458 } 459 Input.normalizeQuery = function(str) { 460 return _.toStr(str).replace(/^\s*/g, "").replace(/\s{2,}/g, " "); 461 }; 462 _.mixin(Input.prototype, EventEmitter, { 463 _onBlur: function onBlur() { 464 this.resetInputValue(); 465 this.trigger("blurred"); 466 }, 467 _onFocus: function onFocus() { 468 this.queryWhenFocused = this.query; 469 this.trigger("focused"); 470 }, 471 _onKeydown: function onKeydown($e) { 472 var keyName = specialKeyCodeMap[$e.which || $e.keyCode]; 473 this._managePreventDefault(keyName, $e); 474 if (keyName && this._shouldTrigger(keyName, $e)) { 475 this.trigger(keyName + "Keyed", $e); 476 } 477 }, 478 _onInput: function onInput() { 479 this._setQuery(this.getInputValue()); 480 this.clearHintIfInvalid(); 481 this._checkLanguageDirection(); 482 }, 483 _managePreventDefault: function managePreventDefault(keyName, $e) { 484 var preventDefault; 485 switch (keyName) { 486 case "up": 487 case "down": 488 preventDefault = !withModifier($e); 489 break; 490 491 default: 492 preventDefault = false; 493 } 494 preventDefault && $e.preventDefault(); 495 }, 496 _shouldTrigger: function shouldTrigger(keyName, $e) { 497 var trigger; 498 switch (keyName) { 499 case "tab": 500 trigger = !withModifier($e); 501 break; 502 503 default: 504 trigger = true; 505 } 506 return trigger; 507 }, 508 _checkLanguageDirection: function checkLanguageDirection() { 509 var dir = (this.$input.css("direction") || "ltr").toLowerCase(); 510 if (this.dir !== dir) { 511 this.dir = dir; 512 this.$hint.attr("dir", dir); 513 this.trigger("langDirChanged", dir); 514 } 515 }, 516 _setQuery: function setQuery(val, silent) { 517 var areEquivalent, hasDifferentWhitespace; 518 areEquivalent = areQueriesEquivalent(val, this.query); 519 hasDifferentWhitespace = areEquivalent ? this.query.length !== val.length : false; 520 this.query = val; 521 if (!silent && !areEquivalent) { 522 this.trigger("queryChanged", this.query); 523 } else if (!silent && hasDifferentWhitespace) { 524 this.trigger("whitespaceChanged", this.query); 525 } 526 }, 527 bind: function() { 528 var that = this, onBlur, onFocus, onKeydown, onInput; 529 onBlur = _.bind(this._onBlur, this); 530 onFocus = _.bind(this._onFocus, this); 531 onKeydown = _.bind(this._onKeydown, this); 532 onInput = _.bind(this._onInput, this); 533 this.$input.on("blur.tt", onBlur).on("focus.tt", onFocus).on("keydown.tt", onKeydown); 534 if (!_.isMsie() || _.isMsie() > 9) { 535 this.$input.on("input.tt", onInput); 536 } else { 537 this.$input.on("keydown.tt keypress.tt cut.tt paste.tt", function($e) { 538 if (specialKeyCodeMap[$e.which || $e.keyCode]) { 539 return; 540 } 541 _.defer(_.bind(that._onInput, that, $e)); 542 }); 543 } 544 return this; 545 }, 546 focus: function focus() { 547 this.$input.focus(); 548 }, 549 blur: function blur() { 550 this.$input.blur(); 551 }, 552 getLangDir: function getLangDir() { 553 return this.dir; 554 }, 555 getQuery: function getQuery() { 556 return this.query || ""; 557 }, 558 setQuery: function setQuery(val, silent) { 559 this.setInputValue(val); 560 this._setQuery(val, silent); 561 }, 562 hasQueryChangedSinceLastFocus: function hasQueryChangedSinceLastFocus() { 563 return this.query !== this.queryWhenFocused; 564 }, 565 getInputValue: function getInputValue() { 566 return this.$input.val(); 567 }, 568 setInputValue: function setInputValue(value) { 569 this.$input.val(value); 570 this.clearHintIfInvalid(); 571 this._checkLanguageDirection(); 572 }, 573 resetInputValue: function resetInputValue() { 574 this.setInputValue(this.query); 575 }, 576 getHint: function getHint() { 577 return this.$hint.val(); 578 }, 579 setHint: function setHint(value) { 580 this.$hint.val(value); 581 }, 582 clearHint: function clearHint() { 583 this.setHint(""); 584 }, 585 clearHintIfInvalid: function clearHintIfInvalid() { 586 var val, hint, valIsPrefixOfHint, isValid; 587 val = this.getInputValue(); 588 hint = this.getHint(); 589 valIsPrefixOfHint = val !== hint && hint.indexOf(val) === 0; 590 isValid = val !== "" && valIsPrefixOfHint && !this.hasOverflow(); 591 !isValid && this.clearHint(); 592 }, 593 hasFocus: function hasFocus() { 594 return this.$input.is(":focus"); 595 }, 596 hasOverflow: function hasOverflow() { 597 var constraint = this.$input.width() - 2; 598 this.$overflowHelper.text(this.getInputValue()); 599 return this.$overflowHelper.width() >= constraint; 600 }, 601 isCursorAtEnd: function() { 602 var valueLength, selectionStart, range; 603 valueLength = this.$input.val().length; 604 selectionStart = this.$input[0].selectionStart; 605 if (_.isNumber(selectionStart)) { 606 return selectionStart === valueLength; 607 } else if (document.selection) { 608 range = document.selection.createRange(); 609 range.moveStart("character", -valueLength); 610 return valueLength === range.text.length; 611 } 612 return true; 613 }, 614 destroy: function destroy() { 615 this.$hint.off(".tt"); 616 this.$input.off(".tt"); 617 this.$overflowHelper.remove(); 618 this.$hint = this.$input = this.$overflowHelper = $("<div>"); 619 } 620 }); 621 return Input; 622 function buildOverflowHelper($input) { 623 return $('<pre aria-hidden="true"></pre>').css({ 624 position: "absolute", 625 visibility: "hidden", 626 whiteSpace: "pre", 627 fontFamily: $input.css("font-family"), 628 fontSize: $input.css("font-size"), 629 fontStyle: $input.css("font-style"), 630 fontVariant: $input.css("font-variant"), 631 fontWeight: $input.css("font-weight"), 632 wordSpacing: $input.css("word-spacing"), 633 letterSpacing: $input.css("letter-spacing"), 634 textIndent: $input.css("text-indent"), 635 textRendering: $input.css("text-rendering"), 636 textTransform: $input.css("text-transform") 637 }).insertAfter($input); 638 } 639 function areQueriesEquivalent(a, b) { 640 return Input.normalizeQuery(a) === Input.normalizeQuery(b); 641 } 642 function withModifier($e) { 643 return $e.altKey || $e.ctrlKey || $e.metaKey || $e.shiftKey; 644 } 645 }(); 646 var Dataset = function() { 647 "use strict"; 648 var keys, nameGenerator; 649 keys = { 650 val: "tt-selectable-display", 651 obj: "tt-selectable-object" 652 }; 653 nameGenerator = _.getIdGenerator(); 654 function Dataset(o, www) { 655 o = o || {}; 656 o.templates = o.templates || {}; 657 o.templates.notFound = o.templates.notFound || o.templates.empty; 658 if (!o.source) { 659 $.error("missing source"); 660 } 661 if (!o.node) { 662 $.error("missing node"); 663 } 664 if (o.name && !isValidName(o.name)) { 665 $.error("invalid dataset name: " + o.name); 666 } 667 www.mixin(this); 668 this.highlight = !!o.highlight; 669 this.name = o.name || nameGenerator(); 670 this.limit = o.limit || 5; 671 this.displayFn = getDisplayFn(o.display || o.displayKey); 672 this.templates = getTemplates(o.templates, this.displayFn); 673 this.source = o.source.__ttAdapter ? o.source.__ttAdapter() : o.source; 674 this.async = _.isUndefined(o.async) ? this.source.length > 2 : !!o.async; 675 this._resetLastSuggestion(); 676 this.$el = $(o.node).addClass(this.classes.dataset).addClass(this.classes.dataset + "-" + this.name); 677 } 678 Dataset.extractData = function extractData(el) { 679 var $el = $(el); 680 if ($el.data(keys.obj)) { 681 return { 682 val: $el.data(keys.val) || "", 683 obj: $el.data(keys.obj) || null 684 }; 685 } 686 return null; 687 }; 688 _.mixin(Dataset.prototype, EventEmitter, { 689 _overwrite: function overwrite(query, suggestions) { 690 suggestions = suggestions || []; 691 if (suggestions.length) { 692 this._renderSuggestions(query, suggestions); 693 } else if (this.async && this.templates.pending) { 694 this._renderPending(query); 695 } else if (!this.async && this.templates.notFound) { 696 this._renderNotFound(query); 697 } else { 698 this._empty(); 699 } 700 this.trigger("rendered", this.name, suggestions, false); 701 }, 702 _append: function append(query, suggestions) { 703 suggestions = suggestions || []; 704 if (suggestions.length && this.$lastSuggestion.length) { 705 this._appendSuggestions(query, suggestions); 706 } else if (suggestions.length) { 707 this._renderSuggestions(query, suggestions); 708 } else if (!this.$lastSuggestion.length && this.templates.notFound) { 709 this._renderNotFound(query); 710 } 711 this.trigger("rendered", this.name, suggestions, true); 712 }, 713 _renderSuggestions: function renderSuggestions(query, suggestions) { 714 var $fragment; 715 $fragment = this._getSuggestionsFragment(query, suggestions); 716 this.$lastSuggestion = $fragment.children().last(); 717 this.$el.html($fragment).prepend(this._getHeader(query, suggestions)).append(this._getFooter(query, suggestions)); 718 }, 719 _appendSuggestions: function appendSuggestions(query, suggestions) { 720 var $fragment, $lastSuggestion; 721 $fragment = this._getSuggestionsFragment(query, suggestions); 722 $lastSuggestion = $fragment.children().last(); 723 this.$lastSuggestion.after($fragment); 724 this.$lastSuggestion = $lastSuggestion; 725 }, 726 _renderPending: function renderPending(query) { 727 var template = this.templates.pending; 728 this._resetLastSuggestion(); 729 template && this.$el.html(template({ 730 query: query, 731 dataset: this.name 732 })); 733 }, 734 _renderNotFound: function renderNotFound(query) { 735 var template = this.templates.notFound; 736 this._resetLastSuggestion(); 737 template && this.$el.html(template({ 738 query: query, 739 dataset: this.name 740 })); 741 }, 742 _empty: function empty() { 743 this.$el.empty(); 744 this._resetLastSuggestion(); 745 }, 746 _getSuggestionsFragment: function getSuggestionsFragment(query, suggestions) { 747 var that = this, fragment; 748 fragment = document.createDocumentFragment(); 749 _.each(suggestions, function getSuggestionNode(suggestion) { 750 var $el, context; 751 context = that._injectQuery(query, suggestion); 752 $el = $(that.templates.suggestion(context)).data(keys.obj, suggestion).data(keys.val, that.displayFn(suggestion)).addClass(that.classes.suggestion + " " + that.classes.selectable); 753 fragment.appendChild($el[0]); 754 }); 755 this.highlight && highlight({ 756 className: this.classes.highlight, 757 node: fragment, 758 pattern: query 759 }); 760 return $(fragment); 761 }, 762 _getFooter: function getFooter(query, suggestions) { 763 return this.templates.footer ? this.templates.footer({ 764 query: query, 765 suggestions: suggestions, 766 dataset: this.name 767 }) : null; 768 }, 769 _getHeader: function getHeader(query, suggestions) { 770 return this.templates.header ? this.templates.header({ 771 query: query, 772 suggestions: suggestions, 773 dataset: this.name 774 }) : null; 775 }, 776 _resetLastSuggestion: function resetLastSuggestion() { 777 this.$lastSuggestion = $(); 778 }, 779 _injectQuery: function injectQuery(query, obj) { 780 return _.isObject(obj) ? _.mixin({ 781 _query: query 782 }, obj) : obj; 783 }, 784 update: function update(query) { 785 var that = this, canceled = false, syncCalled = false, rendered = 0; 786 this.cancel(); 787 this.cancel = function cancel() { 788 canceled = true; 789 that.cancel = $.noop; 790 that.async && that.trigger("asyncCanceled", query); 791 }; 792 this.source(query, sync, async); 793 !syncCalled && sync([]); 794 function sync(suggestions) { 795 if (syncCalled) { 796 return; 797 } 798 syncCalled = true; 799 suggestions = (suggestions || []).slice(0, that.limit); 800 rendered = suggestions.length; 801 that._overwrite(query, suggestions); 802 if (rendered < that.limit && that.async) { 803 that.trigger("asyncRequested", query); 804 } 805 } 806 function async(suggestions) { 807 suggestions = suggestions || []; 808 if (!canceled && rendered < that.limit) { 809 that.cancel = $.noop; 810
810that._append(query, suggestions.slice(0, that.limit - rendered)); 811 //Update rendered-count _after_ async results have displayed 812 //https://github.com/twitter/typeahead.js/pull/1212/commits/387290b1e70be0052c6dd9be84069f55d54a7ce7# 813 rendered += suggestions.length
vendor: 10,486 bytes, lines 813-1057
813; 814 that.async && that.trigger("asyncReceived", query); 815 } 816 } 817 }, 818 cancel: $.noop, 819 clear: function clear() { 820 this._empty(); 821 this.cancel(); 822 this.trigger("cleared"); 823 }, 824 isEmpty: function isEmpty() { 825 return this.$el.is(":empty"); 826 }, 827 destroy: function destroy() { 828 this.$el = $("<div>"); 829 } 830 }); 831 return Dataset; 832 function getDisplayFn(display) { 833 display = display || _.stringify; 834 return _.isFunction(display) ? display : displayFn; 835 function displayFn(obj) { 836 return obj[display]; 837 } 838 } 839 function getTemplates(templates, displayFn) { 840 return { 841 notFound: templates.notFound && _.templatify(templates.notFound), 842 pending: templates.pending && _.templatify(templates.pending), 843 header: templates.header && _.templatify(templates.header), 844 footer: templates.footer && _.templatify(templates.footer), 845 suggestion: templates.suggestion || suggestionTemplate 846 }; 847 function suggestionTemplate(context) { 848 return $("<div>").text(displayFn(context)); 849 } 850 } 851 function isValidName(str) { 852 return /^[_a-zA-Z0-9-]+$/.test(str); 853 } 854 }(); 855 var Menu = function() { 856 "use strict"; 857 function Menu(o, www) { 858 var that = this; 859 o = o || {}; 860 if (!o.node) { 861 $.error("node is required"); 862 } 863 www.mixin(this); 864 this.$node = $(o.node); 865 this.query = null; 866 this.datasets = _.map(o.datasets, initializeDataset); 867 function initializeDataset(oDataset) { 868 var node = that.$node.find(oDataset.node).first(); 869 oDataset.node = node.length ? node : $("<div>").appendTo(that.$node); 870 return new Dataset(oDataset, www); 871 } 872 } 873 _.mixin(Menu.prototype, EventEmitter, { 874 _onSelectableClick: function onSelectableClick($e) { 875 this.trigger("selectableClicked", $($e.currentTarget)); 876 }, 877 _onRendered: function onRendered(type, dataset, suggestions, async) { 878 this.$node.toggleClass(this.classes.empty, this._allDatasetsEmpty()); 879 this.trigger("datasetRendered", dataset, suggestions, async); 880 }, 881 _onCleared: function onCleared() { 882 this.$node.toggleClass(this.classes.empty, this._allDatasetsEmpty()); 883 this.trigger("datasetCleared"); 884 }, 885 _propagate: function propagate() { 886 this.trigger.apply(this, arguments); 887 }, 888 _allDatasetsEmpty: function allDatasetsEmpty() { 889 return _.every(this.datasets, isDatasetEmpty); 890 function isDatasetEmpty(dataset) { 891 return dataset.isEmpty(); 892 } 893 }, 894 _getSelectables: function getSelectables() { 895 return this.$node.find(this.selectors.selectable); 896 }, 897 _removeCursor: function _removeCursor() { 898 var $selectable = this.getActiveSelectable(); 899 $selectable && $selectable.removeClass(this.classes.cursor); 900 }, 901 _ensureVisible: function ensureVisible($el) { 902 var elTop, elBottom, nodeScrollTop, nodeHeight; 903 elTop = $el.position().top; 904 elBottom = elTop + $el.outerHeight(true); 905 nodeScrollTop = this.$node.scrollTop(); 906 nodeHeight = this.$node.height() + parseInt(this.$node.css("paddingTop"), 10) + parseInt(this.$node.css("paddingBottom"), 10); 907 if (elTop < 0) { 908 this.$node.scrollTop(nodeScrollTop + elTop); 909 } else if (nodeHeight < elBottom) { 910 this.$node.scrollTop(nodeScrollTop + (elBottom - nodeHeight)); 911 } 912 }, 913 bind: function() { 914 var that = this, onSelectableClick; 915 onSelectableClick = _.bind(this._onSelectableClick, this); 916 this.$node.on("click.tt", this.selectors.selectable, onSelectableClick); 917 _.each(this.datasets, function(dataset) { 918 dataset.onSync("asyncRequested", that._propagate, that).onSync("asyncCanceled", that._propagate, that).onSync("asyncReceived", that._propagate, that).onSync("rendered", that._onRendered, that).onSync("cleared", that._onCleared, that); 919 }); 920 return this; 921 }, 922 isOpen: function isOpen() { 923 return this.$node.hasClass(this.classes.open); 924 }, 925 open: function open() { 926 this.$node.addClass(this.classes.open); 927 }, 928 close: function close() { 929 this.$node.removeClass(this.classes.open); 930 this._removeCursor(); 931 }, 932 setLanguageDirection: function setLanguageDirection(dir) { 933 this.$node.attr("dir", dir); 934 }, 935 selectableRelativeToCursor: function selectableRelativeToCursor(delta) { 936 var $selectables, $oldCursor, oldIndex, newIndex; 937 $oldCursor = this.getActiveSelectable(); 938 $selectables = this._getSelectables(); 939 oldIndex = $oldCursor ? $selectables.index($oldCursor) : -1; 940 newIndex = oldIndex + delta; 941 newIndex = (newIndex + 1) % ($selectables.length + 1) - 1; 942 newIndex = newIndex < -1 ? $selectables.length - 1 : newIndex; 943 return newIndex === -1 ? null : $selectables.eq(newIndex); 944 }, 945 setCursor: function setCursor($selectable) { 946 this._removeCursor(); 947 if ($selectable = $selectable && $selectable.first()) { 948 $selectable.addClass(this.classes.cursor); 949 this._ensureVisible($selectable); 950 } 951 }, 952 getSelectableData: function getSelectableData($el) { 953 return $el && $el.length ? Dataset.extractData($el) : null; 954 }, 955 getActiveSelectable: function getActiveSelectable() { 956 var $selectable = this._getSelectables().filter(this.selectors.cursor).first(); 957 return $selectable.length ? $selectable : null; 958 }, 959 getTopSelectable: function getTopSelectable() { 960 var $selectable = this._getSelectables().first(); 961 return $selectable.length ? $selectable : null; 962 }, 963 update: function update(query) { 964 var isValidUpdate = query !== this.query; 965 if (isValidUpdate) { 966 this.query = query; 967 _.each(this.datasets, updateDataset); 968 } 969 return isValidUpdate; 970 function updateDataset(dataset) { 971 dataset.update(query); 972 } 973 }, 974 empty: function empty() { 975 _.each(this.datasets, clearDataset); 976 this.query = null; 977 this.$node.addClass(this.classes.empty); 978 function clearDataset(dataset) { 979 dataset.clear(); 980 } 981 }, 982 destroy: function destroy() { 983 this.$node.off(".tt"); 984 this.$node = $("<div>"); 985 _.each(this.datasets, destroyDataset); 986 function destroyDataset(dataset) { 987 dataset.destroy(); 988 } 989 } 990 }); 991 return Menu; 992 }(); 993 var DefaultMenu = function() { 994 "use strict"; 995 var s = Menu.prototype; 996 function DefaultMenu() { 997 Menu.apply(this, [].slice.call(arguments, 0)); 998 } 999 _.mixin(DefaultMenu.prototype, Menu.prototype, { 1000 open: function open() { 1001 !this._allDatasetsEmpty() && this._show(); 1002 return s.open.apply(this, [].slice.call(arguments, 0)); 1003 }, 1004 close: function close() { 1005 this._hide(); 1006 return s.close.apply(this, [].slice.call(arguments, 0)); 1007 }, 1008 _onRendered: function onRendered() { 1009 if (this._allDatasetsEmpty()) { 1010 this._hide(); 1011 } else { 1012 this.isOpen() && this._show(); 1013 } 1014 return s._onRendered.apply(this, [].slice.call(arguments, 0)); 1015 }, 1016 _onCleared: function onCleared() { 1017 if (this._allDatasetsEmpty()) { 1018 this._hide(); 1019 } else { 1020 this.isOpen() && this._show(); 1021 } 1022 return s._onCleared.apply(this, [].slice.call(arguments, 0)); 1023 }, 1024 setLanguageDirection: function setLanguageDirection(dir) { 1025 this.$node.css(dir === "ltr" ? this.css.ltr : this.css.rtl); 1026 return s.setLanguageDirection.apply(this, [].slice.call(arguments, 0)); 1027 }, 1028 _hide: function hide() { 1029 this.$node.hide(); 1030 }, 1031 _show: function show() { 1032 this.$node.css("display", "block"); 1033 } 1034 }); 1035 return DefaultMenu; 1036 }(); 1037 var Typeahead = function() { 1038 "use strict"; 1039 function Typeahead(o, www) { 1040 var onFocused, onBlurred, onEnterKeyed, onTabKeyed, onEscKeyed, onUpKeyed, onDownKeyed, onLeftKeyed, onRightKeyed, onQueryChanged, onWhitespaceChanged; 1041 o = o || {}; 1042 if (!o.input) { 1043 $.error("missing input"); 1044 } 1045 if (!o.menu) { 1046 $.error("missing menu"); 1047 } 1048 if (!o.eventBus) { 1049 $.error("missing event bus"); 1050 } 1051 www.mixin(this); 1052 this.eventBus = o.eventBus; 1053 this.minLength = _.isNumber(o.minLength) ? o.minLength : 1; 1054 this.input = o.input; 1055 this.menu = o.menu; 1056 this.enabled = true; 1057 this.
vendor: 14,684 bytes, lines 1057-1367
1057tabAutocomplete = o.tabAutocomplete === false ? false : true; 1058 this.active = false; 1059 this.input.hasFocus() && this.activate(); 1060 this.dir = this.input.getLangDir(); 1061 this._hacks(); 1062 this.menu.bind().onSync("selectableClicked", this._onSelectableClicked, this).onSync("asyncRequested", this._onAsyncRequested, this).onSync("asyncCanceled", this._onAsyncCanceled, this).onSync("asyncReceived", this._onAsyncReceived, this).onSync("datasetRendered", this._onDatasetRendered, this).onSync("datasetCleared", this._onDatasetCleared, this); 1063 onFocused = c(this, "activate", "open", "_onFocused"); 1064 onBlurred = c(this, "deactivate", "_onBlurred"); 1065 onEnterKeyed = c(this, "isActive", "isOpen", "_onEnterKeyed"); 1066 onTabKeyed = c(this, "isActive", "isOpen", "_onTabKeyed"); 1067 onEscKeyed = c(this, "isActive", "_onEscKeyed"); 1068 onUpKeyed = c(this, "isActive", "open", "_onUpKeyed"); 1069 onDownKeyed = c(this, "isActive", "open", "_onDownKeyed"); 1070 onLeftKeyed = c(this, "isActive", "isOpen", "_onLeftKeyed"); 1071 onRightKeyed = c(this, "isActive", "isOpen", "_onRightKeyed"); 1072 onQueryChanged = c(this, "_openIfActive", "_onQueryChanged"); 1073 onWhitespaceChanged = c(this, "_openIfActive", "_onWhitespaceChanged"); 1074 this.input.bind().onSync("focused", onFocused, this).onSync("blurred", onBlurred, this).onSync("enterKeyed", onEnterKeyed, this).onSync("tabKeyed", onTabKeyed, this).onSync("escKeyed", onEscKeyed, this).onSync("upKeyed", onUpKeyed, this).onSync("downKeyed", onDownKeyed, this).onSync("leftKeyed", onLeftKeyed, this).onSync("rightKeyed", onRightKeyed, this).onSync("queryChanged", onQueryChanged, this).onSync("whitespaceChanged", onWhitespaceChanged, this).onSync("langDirChanged", this._onLangDirChanged, this); 1075 } 1076 _.mixin(Typeahead.prototype, { 1077 _hacks: function hacks() { 1078 var $input, $menu; 1079 $input = this.input.$input || $("<div>"); 1080 $menu = this.menu.$node || $("<div>"); 1081 $input.on("blur.tt", function($e) { 1082 var active, isActive, hasActive; 1083 active = document.activeElement; 1084 isActive = $menu.is(active); 1085 hasActive = $menu.has(active).length > 0; 1086 if (_.isMsie() && (isActive || hasActive)) { 1087 $e.preventDefault(); 1088 $e.stopImmediatePropagation(); 1089 _.defer(function() { 1090 $input.focus(); 1091 }); 1092 } 1093 }); 1094 $menu.on("mousedown.tt", function($e) { 1095 $e.preventDefault(); 1096 }); 1097 }, 1098 _onSelectableClicked: function onSelectableClicked(type, $el) { 1099 this.select($el); 1100 }, 1101 _onDatasetCleared: function onDatasetCleared() { 1102 this._updateHint(); 1103 }, 1104 _onDatasetRendered: function onDatasetRendered(type, dataset, suggestions, async) { 1105 this._updateHint(); 1106 this.eventBus.trigger("render", suggestions, async, dataset); 1107 }, 1108 _onAsyncRequested: function onAsyncRequested(type, dataset, query) { 1109 this.eventBus.trigger("asyncrequest", query, dataset); 1110 if(dataset) {// make sure a query is really about to be sent 1111 this.eventBus.trigger("asyncsent"); 1112 } 1113 }, 1114 _onAsyncCanceled: function onAsyncCanceled(type, dataset, query) { 1115 this.eventBus.trigger("asynccancel", query, dataset); 1116 }, 1117 _onAsyncReceived: function onAsyncReceived(type, dataset, query) { 1118 this.eventBus.trigger("asyncreceive", query, dataset); 1119 }, 1120 _onFocused: function onFocused() { 1121 this._minLengthMet() && this.menu.update(this.input.getQuery()); 1122 }, 1123 _onBlurred: function onBlurred() { 1124 if (this.input.hasQueryChangedSinceLastFocus()) { 1125 this.eventBus.trigger("change", this.input.getQuery()); 1126 } 1127 }, 1128 _onEnterKeyed: function onEnterKeyed(type, $e) { 1129 var $selectable; 1130 if ($selectable = this.menu.getActiveSelectable()) { 1131 this.select($selectable) && $e.preventDefault(); 1132 } 1133 }, 1134 _onTabKeyed: function onTabKeyed(type, $e) { 1135 var $selectable; 1136 if ($selectable = this.menu.getActiveSelectable()) { 1137 this.select($selectable) && $e.preventDefault(); 1138 } else if (this.tabAutocomplete && ($selectable = this.menu.getTopSelectable())) { 1139 this.autocomplete($selectable) && $e.preventDefault(); 1140 } 1141 }, 1142 _onEscKeyed: function onEscKeyed() { 1143 this.close(); 1144 }, 1145 _onUpKeyed: function onUpKeyed() { 1146 this.moveCursor(-1); 1147 }, 1148 _onDownKeyed: function onDownKeyed() { 1149 this.moveCursor(+1); 1150 }, 1151 _onLeftKeyed: function onLeftKeyed() { 1152 if (this.dir === "rtl" && this.input.isCursorAtEnd()) { 1153 this.autocomplete(this.menu.getTopSelectable()); 1154 } 1155 }, 1156 _onRightKeyed: function onRightKeyed() { 1157 if (this.dir === "ltr" && this.input.isCursorAtEnd()) { 1158 this.autocomplete(this.menu.getTopSelectable()); 1159 } 1160 }, 1161 _onQueryChanged: function onQueryChanged(e, query) { 1162 this._minLengthMet(query) ? this.menu.update(query) : this.menu.empty(); 1163 }, 1164 _onWhitespaceChanged: function onWhitespaceChanged() { 1165 this._updateHint(); 1166 }, 1167 _onLangDirChanged: function onLangDirChanged(e, dir) { 1168 if (this.dir !== dir) { 1169 this.dir = dir; 1170 this.menu.setLanguageDirection(dir); 1171 } 1172 }, 1173 _openIfActive: function openIfActive() { 1174 this.isActive() && this.open(); 1175 }, 1176 _minLengthMet: function minLengthMet(query) { 1177 query = _.isString(query) ? query : this.input.getQuery() || ""; 1178 return query.length >= this.minLength; 1179 }, 1180 _updateHint: function updateHint() { 1181 var $selectable, data, val, query, escapedQuery, frontMatchRegEx, match; 1182 $selectable = this.menu.getTopSelectable(); 1183 data = this.menu.getSelectableData($selectable); 1184 val = this.input.getInputValue(); 1185 if (data && !_.isBlankString(val) && !this.input.hasOverflow()) { 1186 query = Input.normalizeQuery(val); 1187 escapedQuery = _.escapeRegExChars(query); 1188 frontMatchRegEx = new RegExp("^(?:" + escapedQuery + ")(.+$)", "i"); 1189 match = frontMatchRegEx.exec(data.val); 1190 match && this.input.setHint(val + match[1]); 1191 } else { 1192 this.input.clearHint(); 1193 } 1194 }, 1195 isEnabled: function isEnabled() { 1196 return this.enabled; 1197 }, 1198 enable: function enable() { 1199 this.enabled = true; 1200 }, 1201 disable: function disable() { 1202 this.enabled = false; 1203 }, 1204 isActive: function isActive() { 1205 return this.active; 1206 }, 1207 activate: function activate() { 1208 if (this.isActive()) { 1209 return true; 1210 } else if (!this.isEnabled() || this.eventBus.before("active")) { 1211 return false; 1212 } else { 1213 this.active = true; 1214 this.eventBus.trigger("active"); 1215 return true; 1216 } 1217 }, 1218 deactivate: function deactivate() { 1219 if (!this.isActive()) { 1220 return true; 1221 } else if (this.eventBus.before("idle")) { 1222 return false; 1223 } else { 1224 this.active = false; 1225 this.close(); 1226 this.eventBus.trigger("idle"); 1227 return true; 1228 } 1229 }, 1230 isOpen: function isOpen() { 1231 return this.menu.isOpen(); 1232 }, 1233 open: function open() { 1234 if (!this.isOpen() && !this.eventBus.before("open")) { 1235 this.menu.open(); 1236 this._updateHint(); 1237 this.eventBus.trigger("open"); 1238 } 1239 return this.isOpen(); 1240 }, 1241 close: function close() { 1242 if (this.isOpen() && !this.eventBus.before("close")) { 1243 this.menu.close(); 1244 this.input.clearHint(); 1245 this.input.resetInputValue(); 1246 this.eventBus.trigger("close"); 1247 } 1248 return !this.isOpen(); 1249 }, 1250 setVal: function setVal(val) { 1251 this.input.setQuery(_.toStr(val)); 1252 }, 1253 getVal: function getVal() { 1254 return this.input.getQuery(); 1255 }, 1256 select: function select($selectable) { 1257 var data = this.menu.getSelectableData($selectable); 1258 if (data && !this.eventBus.before("select", data.obj)) { 1259 this.input.setQuery(data.val, true); 1260 this.eventBus.trigger("select", data.obj); 1261 this.close(); 1262 return true; 1263 } 1264 return false; 1265 }, 1266 autocomplete: function autocomplete($selectable) { 1267 var query, data, isValid; 1268 query = this.input.getQuery(); 1269 data = this.menu.getSelectableData($selectable); 1270 isValid = data && query !== data.val; 1271 if (isValid && !this.eventBus.before("autocomplete", data.obj)) { 1272 this.input.setQuery(data.val); 1273 this.eventBus.trigger("autocomplete", data.obj); 1274 return true; 1275 } 1276 return false; 1277 }, 1278 moveCursor: function moveCursor(delta) { 1279 var query, $candidate, data, payload, cancelMove; 1280 query = this.input.getQuery(); 1281 $candidate = this.menu.selectableRelativeToCursor(delta); 1282 data = this.menu.getSelectableData($candidate); 1283 payload = data ? data.obj : null; 1284 cancelMove = this._minLengthMet() && this.menu.update(query); 1285 if (!cancelMove && !this.eventBus.before("cursorchange", payload)) { 1286 this.menu.setCursor($candidate); 1287 if (data) { 1288 this.input.setInputValue(data.val); 1289 } else { 1290 this.input.resetInputValue(); 1291 this._updateHint(); 1292 } 1293 this.eventBus.trigger("cursorchange", payload); 1294 return true; 1295 } 1296 return false; 1297 }, 1298 destroy: function destroy() { 1299 this.input.destroy(); 1300 this.menu.destroy(); 1301 } 1302 }); 1303 return Typeahead; 1304 function c(ctx) { 1305 var methods = [].slice.call(arguments, 1); 1306 return function() { 1307 var args = [].slice.call(arguments); 1308 _.each(methods, function(method) { 1309 return ctx[method].apply(ctx, args); 1310 }); 1311 }; 1312 } 1313 }(); 1314 (function() { 1315 "use strict"; 1316 var old, keys, methods; 1317 old = $.fn.typeahead; 1318 keys = { 1319 www: "tt-www", 1320 attrs: "tt-attrs", 1321 typeahead: "tt-typeahead" 1322 }; 1323 methods = { 1324 initialize: function initialize(o, datasets) { 1325 var www; 1326 datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1); 1327 o = o || {}; 1328 www = WWW(o.classNames); 1329 return this.each(attach); 1330 function attach() { 1331 var $input, $wrapper, $hint, $menu, defaultHint, defaultMenu, eventBus, input, menu, typeahead, MenuConstructor; 1332 _.each(datasets, function(d) { 1333 d.highlight = !!o.highlight; 1334 }); 1335 $input = $(this); 1336 $wrapper = $(www.html.wrapper); 1337 $hint = $elOrNull(o.hint); 1338 $menu = $elOrNull(o.menu); 1339 defaultHint = o.hint !== false && !$hint; 1340 defaultMenu = o.menu !== false && !$menu; 1341 defaultHint && ($hint = buildHintFromInput($input, www)); 1342 defaultMenu && ($menu = $(www.html.menu).css(www.css.menu)); 1343 $hint && $hint.val(""); 1344 $input = prepInput($input, www); 1345 if (defaultHint || defaultMenu) { 1346 $wrapper.css(www.css.wrapper); 1347 $input.css(defaultHint ? www.css.input : www.css.inputWithNoHint); 1348 $input.wrap($wrapper).parent().prepend(defaultHint ? $hint : null).append(defaultMenu ? $menu : null); 1349 } 1350 MenuConstructor = defaultMenu ? DefaultMenu : Menu; 1351 eventBus = new EventBus({ 1352 el: $input 1353 }); 1354 input = new Input({ 1355 hint: $hint, 1356 input: $input 1357 }, www); 1358 menu = new MenuConstructor({ 1359 node: $menu, 1360 datasets: datasets 1361 }, www); 1362 typeahead = new Typeahead({ 1363 input: input, 1364 menu: menu, 1365 eventBus: eventBus, 1366 minLength: o.minLength, 1367 tabAutocomplete: typeof o.tabAutocomplete !== "undefined" ? !!o.tabAutocomplete : true
vendor: 6,502 bytes, lines 1367-1545
1367 1368 }, www); 1369 $input.data(keys.www, www); 1370 $input.data(keys.typeahead, typeahead); 1371 } 1372 }, 1373 isEnabled: function isEnabled() { 1374 var enabled; 1375 ttEach(this.first(), function(t) { 1376 enabled = t.isEnabled(); 1377 }); 1378 return enabled; 1379 }, 1380 enable: function enable() { 1381 ttEach(this, function(t) { 1382 t.enable(); 1383 }); 1384 return this; 1385 }, 1386 disable: function disable() { 1387 ttEach(this, function(t) { 1388 t.disable(); 1389 }); 1390 return this; 1391 }, 1392 isActive: function isActive() { 1393 var active; 1394 ttEach(this.first(), function(t) { 1395 active = t.isActive(); 1396 }); 1397 return active; 1398 }, 1399 activate: function activate() { 1400 ttEach(this, function(t) { 1401 t.activate(); 1402 }); 1403 return this; 1404 }, 1405 deactivate: function deactivate() { 1406 ttEach(this, function(t) { 1407 t.deactivate(); 1408 }); 1409 return this; 1410 }, 1411 isOpen: function isOpen() { 1412 var open; 1413 ttEach(this.first(), function(t) { 1414 open = t.isOpen(); 1415 }); 1416 return open; 1417 }, 1418 open: function open() { 1419 ttEach(this, function(t) { 1420 t.open(); 1421 }); 1422 return this; 1423 }, 1424 close: function close() { 1425 ttEach(this, function(t) { 1426 t.close(); 1427 }); 1428 return this; 1429 }, 1430 select: function select(el) { 1431 var success = false, $el = $(el); 1432 ttEach(this.first(), function(t) { 1433 success = t.select($el); 1434 }); 1435 return success; 1436 }, 1437 autocomplete: function autocomplete(el) { 1438 var success = false, $el = $(el); 1439 ttEach(this.first(), function(t) { 1440 success = t.autocomplete($el); 1441 }); 1442 return success; 1443 }, 1444 moveCursor: function moveCursoe(delta) { 1445 var success = false; 1446 ttEach(this.first(), function(t) { 1447 success = t.moveCursor(delta); 1448 }); 1449 return success; 1450 }, 1451 val: function val(newVal) { 1452 var query; 1453 if (!arguments.length) { 1454 ttEach(this.first(), function(t) { 1455 query = t.getVal(); 1456 }); 1457 return query; 1458 } else { 1459 ttEach(this, function(t) { 1460 t.setVal(newVal); 1461 }); 1462 return this; 1463 } 1464 }, 1465 destroy: function destroy() { 1466 ttEach(this, function(typeahead, $input) { 1467 revert($input); 1468 typeahead.destroy(); 1469 }); 1470 return this; 1471 } 1472 }; 1473 $.fn.typeahead = function(method) { 1474 if (methods[method]) { 1475 return methods[method].apply(this, [].slice.call(arguments, 1)); 1476 } else { 1477 return methods.initialize.apply(this, arguments); 1478 } 1479 }; 1480 $.fn.typeahead.noConflict = function noConflict() { 1481 $.fn.typeahead = old; 1482 return this; 1483 }; 1484 function ttEach($els, fn) { 1485 $els.each(function() { 1486 var $input = $(this), typeahead; 1487 (typeahead = $input.data(keys.typeahead)) && fn(typeahead, $input); 1488 }); 1489 } 1490 function buildHintFromInput($input, www) { 1491 return $input.clone().addClass(www.classes.hint).removeData().css(www.css.hint).css(getBackgroundStyles($input)).prop("readonly", true).removeAttr("id name placeholder required").attr({ 1492 autocomplete: "off", 1493 spellcheck: "false", 1494 tabindex: -1 1495 }); 1496 } 1497 function prepInput($input, www) { 1498 $input.data(keys.attrs, { 1499 dir: $input.attr("dir"), 1500 autocomplete: $input.attr("autocomplete"), 1501 spellcheck: $input.attr("spellcheck"), 1502 style: $input.attr("style") 1503 }); 1504 $input.addClass(www.classes.input).attr({ 1505 autocomplete: "off", 1506 spellcheck: false 1507 }); 1508 try { 1509 !$input.attr("dir") && $input.attr("dir", "auto"); 1510 } catch (e) {} 1511 return $input; 1512 } 1513 function getBackgroundStyles($el) { 1514 return { 1515 backgroundAttachment: $el.css("background-attachment"), 1516 backgroundClip: $el.css("background-clip"), 1517 backgroundColor: $el.css("background-color"), 1518 backgroundImage: $el.css("background-image"), 1519 backgroundOrigin: $el.css("background-origin"), 1520 backgroundPosition: $el.css("background-position"), 1521 backgroundRepeat: $el.css("background-repeat"), 1522 backgroundSize: $el.css("background-size") 1523 }; 1524 } 1525 function revert($input) { 1526 var www, $wrapper; 1527 www = $input.data(keys.www); 1528 $wrapper = $input.parent().filter(www.selectors.wrapper); 1529 _.each($input.data(keys.attrs), function(val, key) { 1530 _.isUndefined(val) ? $input.removeAttr(key) : $input.attr(key, val); 1531 }); 1532 $input.removeData(keys.typeahead).removeData(keys.www).removeData(keys.attr).removeClass(www.classes.input); 1533 if ($wrapper.length) { 1534 $input.detach().insertAfter($wrapper); 1535 $wrapper.remove(); 1536 } 1537 } 1538 function $elOrNull(obj) { 1539 var isValid, $el; 1540 isValid = _.isJQuery(obj) || _.isElement(obj); 1541 $el = isValid ? $(obj).first() : []; 1542 return $el.length ? $el : null; 1543 } 1544 })(); 1545});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.