Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added typeahead library to re-implement search suggestions for bootstrap framework.
Michael Peter Christend87330438165
diff --git a/htroot/env/bootstrap-base.css b/htroot/env/bootstrap-base.cssindex 9c8a540d8..c5bdbdbfc 100644--- a/htroot/env/bootstrap-base.css+++ b/htroot/env/bootstrap-base.css@@ -90,4 +90,34 @@ label {ul.nav li.dropdown:hover ul.dropdown-menu{display: block;margin-top:0px-}\ No newline at end of file+}++/*+ * typeahead+ * sets the following classes:+ * twitter-typeahead, tt-dropdown-menu, tt-dataset-%CLASS%, tt-suggestions, tt-suggestion+ * tt-hint, tt-input, tt-cursor+ */++.tt-dropdown-menu {+ width: 396px;+ margin-top: 4px;+ padding: 4px 0;+ background-color: #f8f8f8;+ border: 1px solid #ccc;+}++.tt-suggestion {+ padding: 3px 10px;+ font-size: 16px;+}++.tt-suggestion.tt-cursor {+ color: #fff;+ background-color: #428bca;+}++.tt-suggestion p {+ margin: 0;+}+\ No newline at end of filediff --git a/htroot/env/bootstrap/js/typeahead.jquery.js b/htroot/env/bootstrap/js/typeahead.jquery.jsnew file mode 100644index 000000000..ab1d5dc7d--- /dev/null+++ b/htroot/env/bootstrap/js/typeahead.jquery.js@@ -0,0 +1,1155 @@+/*!+ * typeahead.js 0.10.2+ * https://github.com/twitter/typeahead.js+ * Copyright 2013-2014 Twitter, Inc. and other contributors; Licensed MIT+ */++(function($) {+ var _ = {+ isMsie: function() {+ return /(msie|trident)/i.test(navigator.userAgent) ? navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2] : false;+ },+ isBlankString: function(str) {+ return !str || /^\s*$/.test(str);+ },+ escapeRegExChars: function(str) {+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");+ },+ isString: function(obj) {+ return typeof obj === "string";+ },+ isNumber: function(obj) {+ return typeof obj === "number";+ },+ isArray: $.isArray,+ isFunction: $.isFunction,+ isObject: $.isPlainObject,+ isUndefined: function(obj) {+ return typeof obj === "undefined";+ },+ bind: $.proxy,+ each: function(collection, cb) {+ $.each(collection, reverseArgs);+ function reverseArgs(index, value) {+ return cb(value, index);+ }+ },+ map: $.map,+ filter: $.grep,+ every: function(obj, test) {+ var result = true;+ if (!obj) {+ return result;+ }+ $.each(obj, function(key, val) {+ if (!(result = test.call(null, val, key, obj))) {+ return false;+ }+ });+ return !!result;+ },+ some: function(obj, test) {+ var result = false;+ if (!obj) {+ return result;+ }+ $.each(obj, function(key, val) {+ if (result = test.call(null, val, key, obj)) {+ return false;+ }+ });+ return !!result;+ },+ mixin: $.extend,+ getUniqueId: function() {+ var counter = 0;+ return function() {+ return counter++;+ };+ }(),+ templatify: function templatify(obj) {+ return $.isFunction(obj) ? obj : template;+ function template() {+ return String(obj);+ }+ },+ defer: function(fn) {+ setTimeout(fn, 0);+ },+ debounce: function(func, wait, immediate) {+ var timeout, result;+ return function() {+ var context = this, args = arguments, later, callNow;+ later = function() {+ timeout = null;+ if (!immediate) {+ result = func.apply(context, args);+ }+ };+ callNow = immediate && !timeout;+ clearTimeout(timeout);+ timeout = setTimeout(later, wait);+ if (callNow) {+ result = func.apply(context, args);+ }+ return result;+ };+ },+ throttle: function(func, wait) {+ var context, args, timeout, result, previous, later;+ previous = 0;+ later = function() {+ previous = new Date();+ timeout = null;+ result = func.apply(context, args);+ };+ return function() {+ var now = new Date(), remaining = wait - (now - previous);+ context = this;+ args = arguments;+ if (remaining <= 0) {+ clearTimeout(timeout);+ timeout = null;+ previous = now;+ result = func.apply(context, args);+ } else if (!timeout) {+ timeout = setTimeout(later, remaining);+ }+ return result;+ };+ },+ noop: function() {}+ };+ var html = {+ wrapper: '<span class="twitter-typeahead"></span>',+ dropdown: '<span class="tt-dropdown-menu"></span>',+ dataset: '<div class="tt-dataset-%CLASS%"></div>',+ suggestions: '<span class="tt-suggestions"></span>',+ suggestion: '<div class="tt-suggestion"></div>'+ };+ var css = {+ wrapper: {+ position: "relative",+ display: "inline-block"+ },+ hint: {+ position: "absolute",+ top: "0",+ left: "0",+ borderColor: "transparent",+ boxShadow: "none"+ },+ input: {+ position: "relative",+ verticalAlign: "top",+ backgroundColor: "transparent"+ },+ inputWithNoHint: {+ position: "relative",+ verticalAlign: "top"+ },+ dropdown: {+ position: "absolute",+ top: "100%",+ left: "0",+ zIndex: "100",+ display: "none"+ },+ suggestions: {+ display: "block"+ },+ suggestion: {+ whiteSpace: "nowrap",+ cursor: "pointer"+ },+ suggestionChild: {+ whiteSpace: "normal"+ },+ ltr: {+ left: "0",+ right: "auto"+ },+ rtl: {+ left: "auto",+ right: " 0"+ }+ };+ if (_.isMsie()) {+ _.mixin(css.input, {+ backgroundImage: "url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"+ });+ }+ if (_.isMsie() && _.isMsie() <= 7) {+ _.mixin(css.input, {+ marginTop: "-1px"+ });+ }+ var EventBus = function() {+ var namespace = "typeahead:";+ function EventBus(o) {+ if (!o || !o.el) {+ $.error("EventBus initialized without el");+ }+ this.$el = $(o.el);+ }+ _.mixin(EventBus.prototype, {+ trigger: function(type) {+ var args = [].slice.call(arguments, 1);+ this.$el.trigger(namespace + type, args);+ }+ });+ return EventBus;+ }();+ var EventEmitter = function() {+ var splitter = /\s+/, nextTick = getNextTick();+ return {+ onSync: onSync,+ onAsync: onAsync,+ off: off,+ trigger: trigger+ };+ function on(method, types, cb, context) {+ var type;+ if (!cb) {+ return this;+ }+ types = types.split(splitter);+ cb = context ? bindContext(cb, context) : cb;+ this._callbacks = this._callbacks || {};+ while (type = types.shift()) {+ this._callbacks[type] = this._callbacks[type] || {+ sync: [],+ async: []+ };+ this._callbacks[type][method].push(cb);+ }+ return this;+ }+ function onAsync(types, cb, context) {+ return on.call(this, "async", types, cb, context);+ }+ function onSync(types, cb, context) {+ return on.call(this, "sync", types, cb, context);+ }+ function off(types) {+ var type;+ if (!this._callbacks) {+ return this;+ }+ types = types.split(splitter);+ while (type = types.shift()) {+ delete this._callbacks[type];+ }+ return this;+ }+ function trigger(types) {+ var type, callbacks, args, syncFlush, asyncFlush;+ if (!this._callbacks) {+ return this;+ }+ types = types.split(splitter);+ args = [].slice.call(arguments, 1);+ while ((type = types.shift()) && (callbacks = this._callbacks[type])) {+ syncFlush = getFlush(callbacks.sync, this, [ type ].concat(args));+ asyncFlush = getFlush(callbacks.async, this, [ type ].concat(args));+ syncFlush() && nextTick(asyncFlush);+ }+ return this;+ }+ function getFlush(callbacks, context, args) {+ return flush;+ function flush() {+ var cancelled;+ for (var i = 0; !cancelled && i < callbacks.length; i += 1) {+ cancelled = callbacks[i].apply(context, args) === false;+ }+ return !cancelled;+ }+ }+ function getNextTick() {+ var nextTickFn;+ if (window.setImmediate) {+ nextTickFn = function nextTickSetImmediate(fn) {+ setImmediate(function() {+ fn();+ });+ };+ } else {+ nextTickFn = function nextTickSetTimeout(fn) {+ setTimeout(function() {+ fn();+ }, 0);+ };+ }+ return nextTickFn;+ }+ function bindContext(fn, context) {+ return fn.bind ? fn.bind(context) : function() {+ fn.apply(context, [].slice.call(arguments, 0));+ };+ }+ }();+ var highlight = function(doc) {+ var defaults = {+ node: null,+ pattern: null,+ tagName: "strong",+ className: null,+ wordsOnly: false,+ caseSensitive: false+ };+ return function hightlight(o) {+ var regex;+ o = _.mixin({}, defaults, o);+ if (!o.node || !o.pattern) {+ return;+ }+ o.pattern = _.isArray(o.pattern) ? o.pattern : [ o.pattern ];+ regex = getRegex(o.pattern, o.caseSensitive, o.wordsOnly);+ traverse(o.node, hightlightTextNode);+ function hightlightTextNode(textNode) {+ var match, patternNode;+ if (match = regex.exec(textNode.data)) {+ wrapperNode = doc.createElement(o.tagName);+ o.className && (wrapperNode.className = o.className);+ patternNode = textNode.splitText(match.index);+ patternNode.splitText(match[0].length);+ wrapperNode.appendChild(patternNode.cloneNode(true));+ textNode.parentNode.replaceChild(wrapperNode, patternNode);+ }+ return !!match;+ }+ function traverse(el, hightlightTextNode) {+ var childNode, TEXT_NODE_TYPE = 3;+ for (var i = 0; i < el.childNodes.length; i++) {+ childNode = el.childNodes[i];+ if (childNode.nodeType === TEXT_NODE_TYPE) {+ i += hightlightTextNode(childNode) ? 1 : 0;+ } else {+ traverse(childNode, hightlightTextNode);+ }+ }+ }+ };+ function getRegex(patterns, caseSensitive, wordsOnly) {+ var escapedPatterns = [], regexStr;+ for (var i = 0; i < patterns.length; i++) {+ escapedPatterns.push(_.escapeRegExChars(patterns[i]));+ }+ regexStr = wordsOnly ? "\\b(" + escapedPatterns.join("|") + ")\\b" : "(" + escapedPatterns.join("|") + ")";+ return caseSensitive ? new RegExp(regexStr) : new RegExp(regexStr, "i");+ }+ }(window.document);+ var Input = function() {+ var specialKeyCodeMap;+ specialKeyCodeMap = {+ 9: "tab",+ 27: "esc",+ 37: "left",+ 39: "right",+ 13: "enter",+ 38: "up",+ 40: "down"+ };+ function Input(o) {+ var that = this, onBlur, onFocus, onKeydown, onInput;+ o = o || {};+ if (!o.input) {+ $.error("input is missing");+ }+ onBlur = _.bind(this._onBlur, this);+ onFocus = _.bind(this._onFocus, this);+ onKeydown = _.bind(this._onKeydown, this);+ onInput = _.bind(this._onInput, this);+ this.$hint = $(o.hint);+ this.$input = $(o.input).on("blur.tt", onBlur).on("focus.tt", onFocus).on("keydown.tt", onKeydown);+ if (this.$hint.length === 0) {+ this.setHint = this.getHint = this.clearHint = this.clearHintIfInvalid = _.noop;+ }+ if (!_.isMsie()) {+ this.$input.on("input.tt", onInput);+ } else {+ this.$input.on("keydown.tt keypress.tt cut.tt paste.tt", function($e) {+ if (specialKeyCodeMap[$e.which || $e.keyCode]) {+ return;+ }+ _.defer(_.bind(that._onInput, that, $e));+ });+ }+ this.query = this.$input.val();+ this.$overflowHelper = buildOverflowHelper(this.$input);+ }+ Input.normalizeQuery = function(str) {+ return (str || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");+ };+ _.mixin(Input.prototype, EventEmitter, {+ _onBlur: function onBlur() {+ this.resetInputValue();+ this.trigger("blurred");+ },+ _onFocus: function onFocus() {+ this.trigger("focused");+ },+ _onKeydown: function onKeydown($e) {+ var keyName = specialKeyCodeMap[$e.which || $e.keyCode];+ this._managePreventDefault(keyName, $e);+ if (keyName && this._shouldTrigger(keyName, $e)) {+ this.trigger(keyName + "Keyed", $e);+ }+ },+ _onInput: function onInput() {+ this._checkInputValue();+ },+ _managePreventDefault: function managePreventDefault(keyName, $e) {+ var preventDefault, hintValue, inputValue;+ switch (keyName) {+ case "tab":+ hintValue = this.getHint();+ inputValue = this.getInputValue();+ preventDefault = hintValue && hintValue !== inputValue && !withModifier($e);+ break;++ case "up":+ case "down":+ preventDefault = !withModifier($e);+ break;++ default:+ preventDefault = false;+ }+ preventDefault && $e.preventDefault();+ },+ _shouldTrigger: function shouldTrigger(keyName, $e) {+ var trigger;+ switch (keyName) {+ case "tab":+ trigger = !withModifier($e);+ break;++ default:+ trigger = true;+ }+ return trigger;+ },+ _checkInputValue: function checkInputValue() {+ var inputValue, areEquivalent, hasDifferentWhitespace;+ inputValue = this.getInputValue();+ areEquivalent = areQueriesEquivalent(inputValue, this.query);+ hasDifferentWhitespace = areEquivalent ? this.query.length !== inputValue.length : false;+ if (!areEquivalent) {+ this.trigger("queryChanged", this.query = inputValue);+ } else if (hasDifferentWhitespace) {+ this.trigger("whitespaceChanged", this.query);+ }+ },+ focus: function focus() {+ this.$input.focus();+ },+ blur: function blur() {+ this.$input.blur();+ },+ getQuery: function getQuery() {+ return this.query;+ },+ setQuery: function setQuery(query) {+ this.query = query;+ },+ getInputValue: function getInputValue() {+ return this.$input.val();+ },+ setInputValue: function setInputValue(value, silent) {+ this.$input.val(value);+ silent ? this.clearHint() : this._checkInputValue();+ },+ resetInputValue: function resetInputValue() {+ this.setInputValue(this.query, true);+ },+ getHint: function getHint() {+ return this.$hint.val();+ },+ setHint: function setHint(value) {+ this.$hint.val(value);+ },+ clearHint: function clearHint() {+ this.setHint("");+ },+ clearHintIfInvalid: function clearHintIfInvalid() {+ var val, hint, valIsPrefixOfHint, isValid;+ val = this.getInputValue();+ hint = this.getHint();+ valIsPrefixOfHint = val !== hint && hint.indexOf(val) === 0;+ isValid = val !== "" && valIsPrefixOfHint && !this.hasOverflow();+ !isValid && this.clearHint();+ },+ getLanguageDirection: function getLanguageDirection() {+ return (this.$input.css("direction") || "ltr").toLowerCase();+ },+ hasOverflow: function hasOverflow() {+ var constraint = this.$input.width() - 2;+ this.$overflowHelper.text(this.getInputValue());+ return this.$overflowHelper.width() >= constraint;+ },+ isCursorAtEnd: function() {+ var valueLength, selectionStart, range;+ valueLength = this.$input.val().length;+ selectionStart = this.$input[0].selectionStart;+ if (_.isNumber(selectionStart)) {+ return selectionStart === valueLength;+ } else if (document.selection) {+ range = document.selection.createRange();+ range.moveStart("character", -valueLength);+ return valueLength === range.text.length;+ }+ return true;+ },+ destroy: function destroy() {+ this.$hint.off(".tt");+ this.$input.off(".tt");+ this.$hint = this.$input = this.$overflowHelper = null;+ }+ });+ return Input;+ function buildOverflowHelper($input) {+ return $('<pre aria-hidden="true"></pre>').css({+ position: "absolute",+ visibility: "hidden",+ whiteSpace: "pre",+ fontFamily: $input.css("font-family"),+ fontSize: $input.css("font-size"),+ fontStyle: $input.css("font-style"),+ fontVariant: $input.css("font-variant"),+ fontWeight: $input.css("font-weight"),+ wordSpacing: $input.css("word-spacing"),+ letterSpacing: $input.css("letter-spacing"),+ textIndent: $input.css("text-indent"),+ textRendering: $input.css("text-rendering"),+ textTransform: $input.css("text-transform")+ }).insertAfter($input);+ }+ function areQueriesEquivalent(a, b) {+ return Input.normalizeQuery(a) === Input.normalizeQuery(b);+ }+ function withModifier($e) {+ return $e.altKey || $e.ctrlKey || $e.metaKey || $e.shiftKey;+ }+ }();+ var Dataset = function() {+ var datasetKey = "ttDataset", valueKey = "ttValue", datumKey = "ttDatum";+ function Dataset(o) {+ o = o || {};+ o.templates = o.templates || {};+ if (!o.source) {+ $.error("missing source");+ }+ if (o.name && !isValidName(o.name)) {+ $.error("invalid dataset name: " + o.name);+ }+ this.query = null;+ this.highlight = !!o.highlight;+ this.name = o.name || _.getUniqueId();+ this.source = o.source;+ this.displayFn = getDisplayFn(o.display || o.displayKey);+ this.templates = getTemplates(o.templates, this.displayFn);+ this.$el = $(html.dataset.replace("%CLASS%", this.name));+ }+ Dataset.extractDatasetName = function extractDatasetName(el) {+ return $(el).data(datasetKey);+ };+ Dataset.extractValue = function extractDatum(el) {+ return $(el).data(valueKey);+ };+ Dataset.extractDatum = function extractDatum(el) {+ return $(el).data(datumKey);+ };+ _.mixin(Dataset.prototype, EventEmitter, {+ _render: function render(query, suggestions) {+ if (!this.$el) {+ return;+ }+ var that = this, hasSuggestions;+ this.$el.empty();+ hasSuggestions = suggestions && suggestions.length;+ if (!hasSuggestions && this.templates.empty) {+ this.$el.html(getEmptyHtml()).prepend(that.templates.header ? getHeaderHtml() : null).append(that.templates.footer ? getFooterHtml() : null);+ } else if (hasSuggestions) {+ this.$el.html(getSuggestionsHtml()).prepend(that.templates.header ? getHeaderHtml() : null).append(that.templates.footer ? getFooterHtml() : null);+ }+ this.trigger("rendered");+ function getEmptyHtml() {+ return that.templates.empty({+ query: query,+ isEmpty: true+ });+ }+ function getSuggestionsHtml() {+ var $suggestions, nodes;+ $suggestions = $(html.suggestions).css(css.suggestions);+ nodes = _.map(suggestions, getSuggestionNode);+ $suggestions.append.apply($suggestions, nodes);+ that.highlight && highlight({+ node: $suggestions[0],+ pattern: query+ });+ return $suggestions;+ function getSuggestionNode(suggestion) {+ var $el;+ $el = $(html.suggestion).append(that.templates.suggestion(suggestion)).data(datasetKey, that.name).data(valueKey, that.displayFn(suggestion)).data(datumKey, suggestion);+ $el.children().each(function() {+ $(this).css(css.suggestionChild);+ });+ return $el;+ }+ }+ function getHeaderHtml() {+ return that.templates.header({+ query: query,+ isEmpty: !hasSuggestions+ });+ }+ function getFooterHtml() {+ return that.templates.footer({+ query: query,+ isEmpty: !hasSuggestions+ });+ }+ },+ getRoot: function getRoot() {+ return this.$el;+ },+ update: function update(query) {+ var that = this;+ this.query = query;+ this.canceled = false;+ this.source(query, render);+ function render(suggestions) {+ if (!that.canceled && query === that.query) {+ that._render(query, suggestions);+ }+ }+ },+ cancel: function cancel() {+ this.canceled = true;+ },+ clear: function clear() {+ this.cancel();+ this.$el.empty();+ this.trigger("rendered");+ },+ isEmpty: function isEmpty() {+ return this.$el.is(":empty");+ },+ destroy: function destroy() {+ this.$el = null;+ }+ });+ return Dataset;+ function getDisplayFn(display) {+ display = display || "value";+ return _.isFunction(display) ? display : displayFn;+ function displayFn(obj) {+ return obj[display];+ }+ }+ function getTemplates(templates, displayFn) {+ return {+ empty: templates.empty && _.templatify(templates.empty),+ header: templates.header && _.templatify(templates.header),+ footer: templates.footer && _.templatify(templates.footer),+ suggestion: templates.suggestion || suggestionTemplate+ };+ function suggestionTemplate(context) {+ return "<p>" + displayFn(context) + "</p>";+ }+ }+ function isValidName(str) {+ return /^[_a-zA-Z0-9-]+$/.test(str);+ }+ }();+ var Dropdown = function() {+ function Dropdown(o) {+ var that = this, onSuggestionClick, onSuggestionMouseEnter, onSuggestionMouseLeave;+ o = o || {};+ if (!o.menu) {+ $.error("menu is required");+ }+ this.isOpen = false;+ this.isEmpty = true;+ this.datasets = _.map(o.datasets, initializeDataset);+ onSuggestionClick = _.bind(this._onSuggestionClick, this);+ onSuggestionMouseEnter = _.bind(this._onSuggestionMouseEnter, this);+ onSuggestionMouseLeave = _.bind(this._onSuggestionMouseLeave, this);+ this.$menu = $(o.menu).on("click.tt", ".tt-suggestion", onSuggestionClick).on("mouseenter.tt", ".tt-suggestion", onSuggestionMouseEnter).on("mouseleave.tt", ".tt-suggestion", onSuggestionMouseLeave);+ _.each(this.datasets, function(dataset) {+ that.$menu.append(dataset.getRoot());+ dataset.onSync("rendered", that._onRendered, that);+ });+ }+ _.mixin(Dropdown.prototype, EventEmitter, {+ _onSuggestionClick: function onSuggestionClick($e) {+ this.trigger("suggestionClicked", $($e.currentTarget));+ },+ _onSuggestionMouseEnter: function onSuggestionMouseEnter($e) {+ this._removeCursor();+ this._setCursor($($e.currentTarget), true);+ },+ _onSuggestionMouseLeave: function onSuggestionMouseLeave() {+ this._removeCursor();+ },+ _onRendered: function onRendered() {+ this.isEmpty = _.every(this.datasets, isDatasetEmpty);+ this.isEmpty ? this._hide() : this.isOpen && this._show();+ this.trigger("datasetRendered");+ function isDatasetEmpty(dataset) {+ return dataset.isEmpty();+ }+ },+ _hide: function() {+ this.$menu.hide();+ },+ _show: function() {+ this.$menu.css("display", "block");+ },+ _getSuggestions: function getSuggestions() {+ return this.$menu.find(".tt-suggestion");+ },+ _getCursor: function getCursor() {+ return this.$menu.find(".tt-cursor").first();+ },+ _setCursor: function setCursor($el, silent) {+ $el.first().addClass("tt-cursor");+ !silent && this.trigger("cursorMoved");+ },+ _removeCursor: function removeCursor() {+ this._getCursor().removeClass("tt-cursor");+ },+ _moveCursor: function moveCursor(increment) {+ var $suggestions, $oldCursor, newCursorIndex, $newCursor;+ if (!this.isOpen) {+ return;+ }+ $oldCursor = this._getCursor();+ $suggestions = this._getSuggestions();+ this._removeCursor();+ newCursorIndex = $suggestions.index($oldCursor) + increment;+ newCursorIndex = (newCursorIndex + 1) % ($suggestions.length + 1) - 1;+ if (newCursorIndex === -1) {+ this.trigger("cursorRemoved");+ return;+ } else if (newCursorIndex < -1) {+ newCursorIndex = $suggestions.length - 1;+ }+ this._setCursor($newCursor = $suggestions.eq(newCursorIndex));+ this._ensureVisible($newCursor);+ },+ _ensureVisible: function ensureVisible($el) {+ var elTop, elBottom, menuScrollTop, menuHeight;+ elTop = $el.position().top;+ elBottom = elTop + $el.outerHeight(true);+ menuScrollTop = this.$menu.scrollTop();+ menuHeight = this.$menu.height() + parseInt(this.$menu.css("paddingTop"), 10) + parseInt(this.$menu.css("paddingBottom"), 10);+ if (elTop < 0) {+ this.$menu.scrollTop(menuScrollTop + elTop);+ } else if (menuHeight < elBottom) {+ this.$menu.scrollTop(menuScrollTop + (elBottom - menuHeight));+ }+ },+ close: function close() {+ if (this.isOpen) {+ this.isOpen = false;+ this._removeCursor();+ this._hide();+ this.trigger("closed");+ }+ },+ open: function open() {+ if (!this.isOpen) {+ this.isOpen = true;+ !this.isEmpty && this._show();+ this.trigger("opened");+ }+ },+ setLanguageDirection: function setLanguageDirection(dir) {+ this.$menu.css(dir === "ltr" ? css.ltr : css.rtl);+ },+ moveCursorUp: function moveCursorUp() {+ this._moveCursor(-1);+ },+ moveCursorDown: function moveCursorDown() {+ this._moveCursor(+1);+ },+ getDatumForSuggestion: function getDatumForSuggestion($el) {+ var datum = null;+ if ($el.length) {+ datum = {+ raw: Dataset.extractDatum($el),+ value: Dataset.extractValue($el),+ datasetName: Dataset.extractDatasetName($el)+ };+ }+ return datum;+ },+ getDatumForCursor: function getDatumForCursor() {+ return this.getDatumForSuggestion(this._getCursor().first());+ },+ getDatumForTopSuggestion: function getDatumForTopSuggestion() {+ return this.getDatumForSuggestion(this._getSuggestions().first());+ },+ update: function update(query) {+ _.each(this.datasets, updateDataset);+ function updateDataset(dataset) {+ dataset.update(query);+ }+ },+ empty: function empty() {+ _.each(this.datasets, clearDataset);+ this.isEmpty = true;+ function clearDataset(dataset) {+ dataset.clear();+ }+ },+ isVisible: function isVisible() {+ return this.isOpen && !this.isEmpty;+ },+ destroy: function destroy() {+ this.$menu.off(".tt");+ this.$menu = null;+ _.each(this.datasets, destroyDataset);+ function destroyDataset(dataset) {+ dataset.destroy();+ }+ }+ });+ return Dropdown;+ function initializeDataset(oDataset) {+ return new Dataset(oDataset);+ }+ }();+ var Typeahead = function() {+ var attrsKey = "ttAttrs";+ function Typeahead(o) {+ var $menu, $input, $hint;+ o = o || {};+ if (!o.input) {+ $.error("missing input");+ }+ this.isActivated = false;+ this.autoselect = !!o.autoselect;+ this.minLength = _.isNumber(o.minLength) ? o.minLength : 1;+ this.$node = buildDomStructure(o.input, o.withHint);+ $menu = this.$node.find(".tt-dropdown-menu");+ $input = this.$node.find(".tt-input");+ $hint = this.$node.find(".tt-hint");+ $input.on("blur.tt", function($e) {+ var active, isActive, hasActive;+ active = document.activeElement;+ isActive = $menu.is(active);+ hasActive = $menu.has(active).length > 0;+ if (_.isMsie() && (isActive || hasActive)) {+ $e.preventDefault();+ $e.stopImmediatePropagation();+ _.defer(function() {+ $input.focus();+ });+ }+ });+ $menu.on("mousedown.tt", function($e) {+ $e.preventDefault();+ });+ this.eventBus = o.eventBus || new EventBus({+ el: $input+ });+ this.dropdown = new Dropdown({+ menu: $menu,+ datasets: o.datasets+ }).onSync("suggestionClicked", this._onSuggestionClicked, this).onSync("cursorMoved", this._onCursorMoved, this).onSync("cursorRemoved", this._onCursorRemoved, this).onSync("opened", this._onOpened, this).onSync("closed", this._onClosed, this).onAsync("datasetRendered", this._onDatasetRendered, this);+ this.input = new Input({+ input: $input,+ hint: $hint+ }).onSync("focused", this._onFocused, this).onSync("blurred", this._onBlurred, this).onSync("enterKeyed", this._onEnterKeyed, this).onSync("tabKeyed", this._onTabKeyed, this).onSync("escKeyed", this._onEscKeyed, this).onSync("upKeyed", this._onUpKeyed, this).onSync("downKeyed", this._onDownKeyed, this).onSync("leftKeyed", this._onLeftKeyed, this).onSync("rightKeyed", this._onRightKeyed, this).onSync("queryChanged", this._onQueryChanged, this).onSync("whitespaceChanged", this._onWhitespaceChanged, this);+ this._setLanguageDirection();+ }+ _.mixin(Typeahead.prototype, {+ _onSuggestionClicked: function onSuggestionClicked(type, $el) {+ var datum;+ if (datum = this.dropdown.getDatumForSuggestion($el)) {+ this._select(datum);+ }+ },+ _onCursorMoved: function onCursorMoved() {+ var datum = this.dropdown.getDatumForCursor();+ this.input.setInputValue(datum.value, true);+ this.eventBus.trigger("cursorchanged", datum.raw, datum.datasetName);+ },+ _onCursorRemoved: function onCursorRemoved() {+ this.input.resetInputValue();+ this._updateHint();+ },+ _onDatasetRendered: function onDatasetRendered() {+ this._updateHint();+ },+ _onOpened: function onOpened() {+ this._updateHint();+ this.eventBus.trigger("opened");+ },+ _onClosed: function onClosed() {+ this.input.clearHint();+ this.eventBus.trigger("closed");+ },+ _onFocused: function onFocused() {+ this.isActivated = true;+ this.dropdown.open();+ },+ _onBlurred: function onBlurred() {+ this.isActivated = false;+ this.dropdown.empty();+ this.dropdown.close();+ },+ _onEnterKeyed: function onEnterKeyed(type, $e) {+ var cursorDatum, topSuggestionDatum;+ cursorDatum = this.dropdown.getDatumForCursor();+ topSuggestionDatum = this.dropdown.getDatumForTopSuggestion();+ if (cursorDatum) {+ this._select(cursorDatum);+ $e.preventDefault();+ } else if (this.autoselect && topSuggestionDatum) {+ this._select(topSuggestionDatum);+ $e.preventDefault();+ }+ },+ _onTabKeyed: function onTabKeyed(type, $e) {+ var datum;+ if (datum = this.dropdown.getDatumForCursor()) {+ this._select(datum);+ $e.preventDefault();+ } else {+ this._autocomplete(true);+ }+ },+ _onEscKeyed: function onEscKeyed() {+ this.dropdown.close();+ this.input.resetInputValue();+ },+ _onUpKeyed: function onUpKeyed() {+ var query = this.input.getQuery();+ this.dropdown.isEmpty && query.length >= this.minLength ? this.dropdown.update(query) : this.dropdown.moveCursorUp();+ this.dropdown.open();+ },+ _onDownKeyed: function onDownKeyed() {+ var query = this.input.getQuery();+ this.dropdown.isEmpty && query.length >= this.minLength ? this.dropdown.update(query) : this.dropdown.moveCursorDown();+ this.dropdown.open();+ },+ _onLeftKeyed: function onLeftKeyed() {+ this.dir === "rtl" && this._autocomplete();+ },+ _onRightKeyed: function onRightKeyed() {+ this.dir === "ltr" && this._autocomplete();+ },+ _onQueryChanged: function onQueryChanged(e, query) {+ this.input.clearHintIfInvalid();+ query.length >= this.minLength ? this.dropdown.update(query) : this.dropdown.empty();+ this.dropdown.open();+ this._setLanguageDirection();+ },+ _onWhitespaceChanged: function onWhitespaceChanged() {+ this._updateHint();+ this.dropdown.open();+ },+ _setLanguageDirection: function setLanguageDirection() {+ var dir;+ if (this.dir !== (dir = this.input.getLanguageDirection())) {+ this.dir = dir;+ this.$node.css("direction", dir);+ this.dropdown.setLanguageDirection(dir);+ }+ },+ _updateHint: function updateHint() {+ var datum, val, query, escapedQuery, frontMatchRegEx, match;+ datum = this.dropdown.getDatumForTopSuggestion();+ if (datum && this.dropdown.isVisible() && !this.input.hasOverflow()) {+ val = this.input.getInputValue();+ query = Input.normalizeQuery(val);+ escapedQuery = _.escapeRegExChars(query);+ frontMatchRegEx = new RegExp("^(?:" + escapedQuery + ")(.+$)", "i");+ match = frontMatchRegEx.exec(datum.value);+ match ? this.input.setHint(val + match[1]) : this.input.clearHint();+ } else {+ this.input.clearHint();+ }+ },+ _autocomplete: function autocomplete(laxCursor) {+ var hint, query, isCursorAtEnd, datum;+ hint = this.input.getHint();+ query = this.input.getQuery();+ isCursorAtEnd = laxCursor || this.input.isCursorAtEnd();+ if (hint && query !== hint && isCursorAtEnd) {+ datum = this.dropdown.getDatumForTopSuggestion();+ datum && this.input.setInputValue(datum.value);+ this.eventBus.trigger("autocompleted", datum.raw, datum.datasetName);+ }+ },+ _select: function select(datum) {+ this.input.setQuery(datum.value);+ this.input.setInputValue(datum.value, true);+ this._setLanguageDirection();+ this.eventBus.trigger("selected", datum.raw, datum.datasetName);+ this.dropdown.close();+ _.defer(_.bind(this.dropdown.empty, this.dropdown));+ },+ open: function open() {+ this.dropdown.open();+ },+ close: function close() {+ this.dropdown.close();+ },+ setVal: function setVal(val) {+ if (this.isActivated) {+ this.input.setInputValue(val);+ } else {+ this.input.setQuery(val);+ this.input.setInputValue(val, true);+ }+ this._setLanguageDirection();+ },+ getVal: function getVal() {+ return this.input.getQuery();+ },+ destroy: function destroy() {+ this.input.destroy();+ this.dropdown.destroy();+ destroyDomStructure(this.$node);+ this.$node = null;+ }+ });+ return Typeahead;+ function buildDomStructure(input, withHint) {+ var $input, $wrapper, $dropdown, $hint;+ $input = $(input);+ $wrapper = $(html.wrapper).css(css.wrapper);+ $dropdown = $(html.dropdown).css(css.dropdown);+ $hint = $input.clone().css(css.hint).css(getBackgroundStyles($input));+ $hint.val("").removeData().addClass("tt-hint").removeAttr("id name placeholder").prop("disabled", true).attr({+ autocomplete: "off",+ spellcheck: "false"+ });+ $input.data(attrsKey, {+ dir: $input.attr("dir"),+ autocomplete: $input.attr("autocomplete"),+ spellcheck: $input.attr("spellcheck"),+ style: $input.attr("style")+ });+ $input.addClass("tt-input").attr({+ autocomplete: "off",+ spellcheck: false+ }).css(withHint ? css.input : css.inputWithNoHint);+ try {+ !$input.attr("dir") && $input.attr("dir", "auto");+ } catch (e) {}+ return $input.wrap($wrapper).parent().prepend(withHint ? $hint : null).append($dropdown);+ }+ function getBackgroundStyles($el) {+ return {+ backgroundAttachment: $el.css("background-attachment"),+ backgroundClip: $el.css("background-clip"),+ backgroundColor: $el.css("background-color"),+ backgroundImage: $el.css("background-image"),+ backgroundOrigin: $el.css("background-origin"),+ backgroundPosition: $el.css("background-position"),+ backgroundRepeat: $el.css("background-repeat"),+ backgroundSize: $el.css("background-size")+ };+ }+ function destroyDomStructure($node) {+ var $input = $node.find(".tt-input");+ _.each($input.data(attrsKey), function(val, key) {+ _.isUndefined(val) ? $input.removeAttr(key) : $input.attr(key, val);+ });+ $input.detach().removeData(attrsKey).removeClass("tt-input").insertAfter($node);+ $node.remove();+ }+ }();+ (function() {+ var old, typeaheadKey, methods;+ old = $.fn.typeahead;+ typeaheadKey = "ttTypeahead";+ methods = {+ initialize: function initialize(o, datasets) {+ datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);+ o = o || {};+ return this.each(attach);+ function attach() {+ var $input = $(this), eventBus, typeahead;+ _.each(datasets, function(d) {+ d.highlight = !!o.highlight;+ });+ typeahead = new Typeahead({+ input: $input,+ eventBus: eventBus = new EventBus({+ el: $input+ }),+ withHint: _.isUndefined(o.hint) ? true : !!o.hint,+ minLength: o.minLength,+ autoselect: o.autoselect,+ datasets: datasets+ });+ $input.data(typeaheadKey, typeahead);+ }+ },+ open: function open() {+ return this.each(openTypeahead);+ function openTypeahead() {+ var $input = $(this), typeahead;+ if (typeahead = $input.data(typeaheadKey)) {+ typeahead.open();+ }+ }+ },+ close: function close() {+ return this.each(closeTypeahead);+ function closeTypeahead() {+ var $input = $(this), typeahead;+ if (typeahead = $input.data(typeaheadKey)) {+ typeahead.close();+ }+ }+ },+ val: function val(newVal) {+ return !arguments.length ? getVal(this.first()) : this.each(setVal);+ function setVal() {+ var $input = $(this), typeahead;+ if (typeahead = $input.data(typeaheadKey)) {+ typeahead.setVal(newVal);+ }+ }+ function getVal($input) {+ var typeahead, query;+ if (typeahead = $input.data(typeaheadKey)) {+ query = typeahead.getVal();+ }+ return query;+ }+ },+ destroy: function destroy() {+ return this.each(unattach);+ function unattach() {+ var $input = $(this), typeahead;+ if (typeahead = $input.data(typeaheadKey)) {+ typeahead.destroy();+ $input.removeData(typeaheadKey);+ }+ }+ }+ };+ $.fn.typeahead = function(method) {+ if (methods[method]) {+ return methods[method].apply(this, [].slice.call(arguments, 1));+ } else {+ return methods.initialize.apply(this, arguments);+ }+ };+ $.fn.typeahead.noConflict = function noConflict() {+ $.fn.typeahead = old;+ return this;+ };+ })();+})(window.jQuery);\ No newline at end of filediff --git a/htroot/env/bootstrap/js/typeahead.jquery.min.js b/htroot/env/bootstrap/js/typeahead.jquery.min.jsnew file mode 100644index 000000000..71c3b214a--- /dev/null+++ b/htroot/env/bootstrap/js/typeahead.jquery.min.js@@ -0,0 +1,7 @@+/*!+ * typeahead.js 0.10.2+ * https://github.com/twitter/typeahead.js+ * Copyright 2013-2014 Twitter, Inc. and other contributors; Licensed MIT+ */++!function(a){var b={isMsie:function(){return/(msie|trident)/i.test(navigator.userAgent)?navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2]:!1},isBlankString:function(a){return!a||/^\s*$/.test(a)},escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(a){return"string"==typeof a},isNumber:function(a){return"number"==typeof a},isArray:a.isArray,isFunction:a.isFunction,isObject:a.isPlainObject,isUndefined:function(a){return"undefined"==typeof a},bind:a.proxy,each:function(b,c){function d(a,b){return c(b,a)}a.each(b,d)},map:a.map,filter:a.grep,every:function(b,c){var d=!0;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?void 0:!1}),!!d):d},some:function(b,c){var d=!1;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?!1:void 0}),!!d):d},mixin:a.extend,getUniqueId:function(){var a=0;return function(){return a++}}(),templatify:function(b){function c(){return String(b)}return a.isFunction(b)?b:c},defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var f,g,h=this,i=arguments;return f=function(){d=null,c||(e=a.apply(h,i))},g=c&&!d,clearTimeout(d),d=setTimeout(f,b),g&&(e=a.apply(h,i)),e}},throttle:function(a,b){var c,d,e,f,g,h;return g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)},function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},noop:function(){}},c={wrapper:'<span class="twitter-typeahead"></span>',dropdown:'<span class="tt-dropdown-menu"></span>',dataset:'<div class="tt-dataset-%CLASS%"></div>',suggestions:'<span class="tt-suggestions"></span>',suggestion:'<div class="tt-suggestion"></div>'},d={wrapper:{position:"relative",display:"inline-block"},hint:{position:"absolute",top:"0",left:"0",borderColor:"transparent",boxShadow:"none"},input:{position:"relative",verticalAlign:"top",backgroundColor:"transparent"},inputWithNoHint:{position:"relative",verticalAlign:"top"},dropdown:{position:"absolute",top:"100%",left:"0",zIndex:"100",display:"none"},suggestions:{display:"block"},suggestion:{whiteSpace:"nowrap",cursor:"pointer"},suggestionChild:{whiteSpace:"normal"},ltr:{left:"0",right:"auto"},rtl:{left:"auto",right:" 0"}};b.isMsie()&&b.mixin(d.input,{backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"}),b.isMsie()&&b.isMsie()<=7&&b.mixin(d.input,{marginTop:"-1px"});var e=function(){function c(b){b&&b.el||a.error("EventBus initialized without el"),this.$el=a(b.el)}var d="typeahead:";return b.mixin(c.prototype,{trigger:function(a){var b=[].slice.call(arguments,1);this.$el.trigger(d+a,b)}}),c}(),f=function(){function a(a,b,c,d){var e;if(!c)return this;for(b=b.split(i),c=d?h(c,d):c,this._callbacks=this._callbacks||{};e=b.shift();)this._callbacks[e]=this._callbacks[e]||{sync:[],async:[]},this._callbacks[e][a].push(c);return this}function b(b,c,d){return a.call(this,"async",b,c,d)}function c(b,c,d){return a.call(this,"sync",b,c,d)}function d(a){var b;if(!this._callbacks)return this;for(a=a.split(i);b=a.shift();)delete this._callbacks[b];return this}function e(a){var b,c,d,e,g;if(!this._callbacks)return this;for(a=a.split(i),d=[].slice.call(arguments,1);(b=a.shift())&&(c=this._callbacks[b]);)e=f(c.sync,this,[b].concat(d)),g=f(c.async,this,[b].concat(d)),e()&&j(g);return this}function f(a,b,c){function d(){for(var d,e=0;!d&&e<a.length;e+=1)d=a[e].apply(b,c)===!1;return!d}return d}function g(){var a;return a=window.setImmediate?function(a){setImmediate(function(){a()})}:function(a){setTimeout(function(){a()},0)}}function h(a,b){return a.bind?a.bind(b):function(){a.apply(b,[].slice.call(arguments,0))}}var i=/\s+/,j=g();return{onSync:c,onAsync:b,off:d,trigger:e}}(),g=function(a){function c(a,c,d){for(var e,f=[],g=0;g<a.length;g++)f.push(b.escapeRegExChars(a[g]));return e=d?"\\b("+f.join("|")+")\\b":"("+f.join("|")+")",c?new RegExp(e):new RegExp(e,"i")}var d={node:null,pattern:null,tagName:"strong",className:null,wordsOnly:!1,caseSensitive:!1};return function(e){function f(b){var c,d;return(c=h.exec(b.data))&&(wrapperNode=a.createElement(e.tagName),e.className&&(wrapperNode.className=e.className),d=b.splitText(c.index),d.splitText(c[0].length),wrapperNode.appendChild(d.cloneNode(!0)),b.parentNode.replaceChild(wrapperNode,d)),!!c}function g(a,b){for(var c,d=3,e=0;e<a.childNodes.length;e++)c=a.childNodes[e],c.nodeType===d?e+=b(c)?1:0:g(c,b)}var h;e=b.mixin({},d,e),e.node&&e.pattern&&(e.pattern=b.isArray(e.pattern)?e.pattern:[e.pattern],h=c(e.pattern,e.caseSensitive,e.wordsOnly),g(e.node,f))}}(window.document),h=function(){function c(c){var e,f,g,i,j=this;c=c||{},c.input||a.error("input is missing"),e=b.bind(this._onBlur,this),f=b.bind(this._onFocus,this),g=b.bind(this._onKeydown,this),i=b.bind(this._onInput,this),this.$hint=a(c.hint),this.$input=a(c.input).on("blur.tt",e).on("focus.tt",f).on("keydown.tt",g),0===this.$hint.length&&(this.setHint=this.getHint=this.clearHint=this.clearHintIfInvalid=b.noop),b.isMsie()?this.$input.on("keydown.tt keypress.tt cut.tt paste.tt",function(a){h[a.which||a.keyCode]||b.defer(b.bind(j._onInput,j,a))}):this.$input.on("input.tt",i),this.query=this.$input.val(),this.$overflowHelper=d(this.$input)}function d(b){return a('<pre aria-hidden="true"></pre>').css({position:"absolute",visibility:"hidden",whiteSpace:"pre",fontFamily:b.css("font-family"),fontSize:b.css("font-size"),fontStyle:b.css("font-style"),fontVariant:b.css("font-variant"),fontWeight:b.css("font-weight"),wordSpacing:b.css("word-spacing"),letterSpacing:b.css("letter-spacing"),textIndent:b.css("text-indent"),textRendering:b.css("text-rendering"),textTransform:b.css("text-transform")}).insertAfter(b)}function e(a,b){return c.normalizeQuery(a)===c.normalizeQuery(b)}function g(a){return a.altKey||a.ctrlKey||a.metaKey||a.shiftKey}var h;return h={9:"tab",27:"esc",37:"left",39:"right",13:"enter",38:"up",40:"down"},c.normalizeQuery=function(a){return(a||"").replace(/^\s*/g,"").replace(/\s{2,}/g," ")},b.mixin(c.prototype,f,{_onBlur:function(){this.resetInputValue(),this.trigger("blurred")},_onFocus:function(){this.trigger("focused")},_onKeydown:function(a){var b=h[a.which||a.keyCode];this._managePreventDefault(b,a),b&&this._shouldTrigger(b,a)&&this.trigger(b+"Keyed",a)},_onInput:function(){this._checkInputValue()},_managePreventDefault:function(a,b){var c,d,e;switch(a){case"tab":d=this.getHint(),e=this.getInputValue(),c=d&&d!==e&&!g(b);break;case"up":case"down":c=!g(b);break;default:c=!1}c&&b.preventDefault()},_shouldTrigger:function(a,b){var c;switch(a){case"tab":c=!g(b);break;default:c=!0}return c},_checkInputValue:function(){var a,b,c;a=this.getInputValue(),b=e(a,this.query),c=b?this.query.length!==a.length:!1,b?c&&this.trigger("whitespaceChanged",this.query):this.trigger("queryChanged",this.query=a)},focus:function(){this.$input.focus()},blur:function(){this.$input.blur()},getQuery:function(){return this.query},setQuery:function(a){this.query=a},getInputValue:function(){return this.$input.val()},setInputValue:function(a,b){this.$input.val(a),b?this.clearHint():this._checkInputValue()},resetInputValue:function(){this.setInputValue(this.query,!0)},getHint:function(){return this.$hint.val()},setHint:function(a){this.$hint.val(a)},clearHint:function(){this.setHint("")},clearHintIfInvalid:function(){var a,b,c,d;a=this.getInputValue(),b=this.getHint(),c=a!==b&&0===b.indexOf(a),d=""!==a&&c&&!this.hasOverflow(),!d&&this.clearHint()},getLanguageDirection:function(){return(this.$input.css("direction")||"ltr").toLowerCase()},hasOverflow:function(){var a=this.$input.width()-2;return this.$overflowHelper.text(this.getInputValue()),this.$overflowHelper.width()>=a},isCursorAtEnd:function(){var a,c,d;return a=this.$input.val().length,c=this.$input[0].selectionStart,b.isNumber(c)?c===a:document.selection?(d=document.selection.createRange(),d.moveStart("character",-a),a===d.text.length):!0},destroy:function(){this.$hint.off(".tt"),this.$input.off(".tt"),this.$hint=this.$input=this.$overflowHelper=null}}),c}(),i=function(){function e(d){d=d||{},d.templates=d.templates||{},d.source||a.error("missing source"),d.name&&!j(d.name)&&a.error("invalid dataset name: "+d.name),this.query=null,this.highlight=!!d.highlight,this.name=d.name||b.getUniqueId(),this.source=d.source,this.displayFn=h(d.display||d.displayKey),this.templates=i(d.templates,this.displayFn),this.$el=a(c.dataset.replace("%CLASS%",this.name))}function h(a){function c(b){return b[a]}return a=a||"value",b.isFunction(a)?a:c}function i(a,c){function d(a){return"<p>"+c(a)+"</p>"}return{empty:a.empty&&b.templatify(a.empty),header:a.header&&b.templatify(a.header),footer:a.footer&&b.templatify(a.footer),suggestion:a.suggestion||d}}function j(a){return/^[_a-zA-Z0-9-]+$/.test(a)}var k="ttDataset",l="ttValue",m="ttDatum";return e.extractDatasetName=function(b){return a(b).data(k)},e.extractValue=function(b){return a(b).data(l)},e.extractDatum=function(b){return a(b).data(m)},b.mixin(e.prototype,f,{_render:function(e,f){function h(){return p.templates.empty({query:e,isEmpty:!0})}function i(){function h(b){var e;return e=a(c.suggestion).append(p.templates.suggestion(b)).data(k,p.name).data(l,p.displayFn(b)).data(m,b),e.children().each(function(){a(this).css(d.suggestionChild)}),e}var i,j;return i=a(c.suggestions).css(d.suggestions),j=b.map(f,h),i.append.apply(i,j),p.highlight&&g({node:i[0],pattern:e}),i}function j(){return p.templates.header({query:e,isEmpty:!o})}function n(){return p.templates.footer({query:e,isEmpty:!o})}if(this.$el){var o,p=this;this.$el.empty(),o=f&&f.length,!o&&this.templates.empty?this.$el.html(h()).prepend(p.templates.header?j():null).append(p.templates.footer?n():null):o&&this.$el.html(i()).prepend(p.templates.header?j():null).append(p.templates.footer?n():null),this.trigger("rendered")}},getRoot:function(){return this.$el},update:function(a){function b(b){c.canceled||a!==c.query||c._render(a,b)}var c=this;this.query=a,this.canceled=!1,this.source(a,b)},cancel:function(){this.canceled=!0},clear:function(){this.cancel(),this.$el.empty(),this.trigger("rendered")},isEmpty:function(){return this.$el.is(":empty")},destroy:function(){this.$el=null}}),e}(),j=function(){function c(c){var d,f,g,h=this;c=c||{},c.menu||a.error("menu is required"),this.isOpen=!1,this.isEmpty=!0,this.datasets=b.map(c.datasets,e),d=b.bind(this._onSuggestionClick,this),f=b.bind(this._onSuggestionMouseEnter,this),g=b.bind(this._onSuggestionMouseLeave,this),this.$menu=a(c.menu).on("click.tt",".tt-suggestion",d).on("mouseenter.tt",".tt-suggestion",f).on("mouseleave.tt",".tt-suggestion",g),b.each(this.datasets,function(a){h.$menu.append(a.getRoot()),a.onSync("rendered",h._onRendered,h)})}function e(a){return new i(a)}return b.mixin(c.prototype,f,{_onSuggestionClick:function(b){this.trigger("suggestionClicked",a(b.currentTarget))},_onSuggestionMouseEnter:function(b){this._removeCursor(),this._setCursor(a(b.currentTarget),!0)},_onSuggestionMouseLeave:function(){this._removeCursor()},_onRendered:function(){function a(a){return a.isEmpty()}this.isEmpty=b.every(this.datasets,a),this.isEmpty?this._hide():this.isOpen&&this._show(),this.trigger("datasetRendered")},_hide:function(){this.$menu.hide()},_show:function(){this.$menu.css("display","block")},_getSuggestions:function(){return this.$menu.find(".tt-suggestion")},_getCursor:function(){return this.$menu.find(".tt-cursor").first()},_setCursor:function(a,b){a.first().addClass("tt-cursor"),!b&&this.trigger("cursorMoved")},_removeCursor:function(){this._getCursor().removeClass("tt-cursor")},_moveCursor:function(a){var b,c,d,e;if(this.isOpen){if(c=this._getCursor(),b=this._getSuggestions(),this._removeCursor(),d=b.index(c)+a,d=(d+1)%(b.length+1)-1,-1===d)return void this.trigger("cursorRemoved");-1>d&&(d=b.length-1),this._setCursor(e=b.eq(d)),this._ensureVisible(e)}},_ensureVisible:function(a){var b,c,d,e;b=a.position().top,c=b+a.outerHeight(!0),d=this.$menu.scrollTop(),e=this.$menu.height()+parseInt(this.$menu.css("paddingTop"),10)+parseInt(this.$menu.css("paddingBottom"),10),0>b?this.$menu.scrollTop(d+b):c>e&&this.$menu.scrollTop(d+(c-e))},close:function(){this.isOpen&&(this.isOpen=!1,this._removeCursor(),this._hide(),this.trigger("closed"))},open:function(){this.isOpen||(this.isOpen=!0,!this.isEmpty&&this._show(),this.trigger("opened"))},setLanguageDirection:function(a){this.$menu.css("ltr"===a?d.ltr:d.rtl)},moveCursorUp:function(){this._moveCursor(-1)},moveCursorDown:function(){this._moveCursor(1)},getDatumForSuggestion:function(a){var b=null;return a.length&&(b={raw:i.extractDatum(a),value:i.extractValue(a),datasetName:i.extractDatasetName(a)}),b},getDatumForCursor:function(){return this.getDatumForSuggestion(this._getCursor().first())},getDatumForTopSuggestion:function(){return this.getDatumForSuggestion(this._getSuggestions().first())},update:function(a){function c(b){b.update(a)}b.each(this.datasets,c)},empty:function(){function a(a){a.clear()}b.each(this.datasets,a),this.isEmpty=!0},isVisible:function(){return this.isOpen&&!this.isEmpty},destroy:function(){function a(a){a.destroy()}this.$menu.off(".tt"),this.$menu=null,b.each(this.datasets,a)}}),c}(),k=function(){function f(c){var d,f,i;c=c||{},c.input||a.error("missing input"),this.isActivated=!1,this.autoselect=!!c.autoselect,this.minLength=b.isNumber(c.minLength)?c.minLength:1,this.$node=g(c.input,c.withHint),d=this.$node.find(".tt-dropdown-menu"),f=this.$node.find(".tt-input"),i=this.$node.find(".tt-hint"),f.on("blur.tt",function(a){var c,e,g;c=document.activeElement,e=d.is(c),g=d.has(c).length>0,b.isMsie()&&(e||g)&&(a.preventDefault(),a.stopImmediatePropagation(),b.defer(function(){f.focus()}))}),d.on("mousedown.tt",function(a){a.preventDefault()}),this.eventBus=c.eventBus||new e({el:f}),this.dropdown=new j({menu:d,datasets:c.datasets}).onSync("suggestionClicked",this._onSuggestionClicked,this).onSync("cursorMoved",this._onCursorMoved,this).onSync("cursorRemoved",this._onCursorRemoved,this).onSync("opened",this._onOpened,this).onSync("closed",this._onClosed,this).onAsync("datasetRendered",this._onDatasetRendered,this),this.input=new h({input:f,hint:i}).onSync("focused",this._onFocused,this).onSync("blurred",this._onBlurred,this).onSync("enterKeyed",this._onEnterKeyed,this).onSync("tabKeyed",this._onTabKeyed,this).onSync("escKeyed",this._onEscKeyed,this).onSync("upKeyed",this._onUpKeyed,this).onSync("downKeyed",this._onDownKeyed,this).onSync("leftKeyed",this._onLeftKeyed,this).onSync("rightKeyed",this._onRightKeyed,this).onSync("queryChanged",this._onQueryChanged,this).onSync("whitespaceChanged",this._onWhitespaceChanged,this),this._setLanguageDirection()}function g(b,e){var f,g,h,j;f=a(b),g=a(c.wrapper).css(d.wrapper),h=a(c.dropdown).css(d.dropdown),j=f.clone().css(d.hint).css(i(f)),j.val("").removeData().addClass("tt-hint").removeAttr("id name placeholder").prop("disabled",!0).attr({autocomplete:"off",spellcheck:"false"}),f.data(l,{dir:f.attr("dir"),autocomplete:f.attr("autocomplete"),spellcheck:f.attr("spellcheck"),style:f.attr("style")}),f.addClass("tt-input").attr({autocomplete:"off",spellcheck:!1}).css(e?d.input:d.inputWithNoHint);try{!f.attr("dir")&&f.attr("dir","auto")}catch(k){}return f.wrap(g).parent().prepend(e?j:null).append(h)}function i(a){return{backgroundAttachment:a.css("background-attachment"),backgroundClip:a.css("background-clip"),backgroundColor:a.css("background-color"),backgroundImage:a.css("background-image"),backgroundOrigin:a.css("background-origin"),backgroundPosition:a.css("background-position"),backgroundRepeat:a.css("background-repeat"),backgroundSize:a.css("background-size")}}function k(a){var c=a.find(".tt-input");b.each(c.data(l),function(a,d){b.isUndefined(a)?c.removeAttr(d):c.attr(d,a)}),c.detach().removeData(l).removeClass("tt-input").insertAfter(a),a.remove()}var l="ttAttrs";return b.mixin(f.prototype,{_onSuggestionClicked:function(a,b){var c;(c=this.dropdown.getDatumForSuggestion(b))&&this._select(c)},_onCursorMoved:function(){var a=this.dropdown.getDatumForCursor();this.input.setInputValue(a.value,!0),this.eventBus.trigger("cursorchanged",a.raw,a.datasetName)},_onCursorRemoved:function(){this.input.resetInputValue(),this._updateHint()},_onDatasetRendered:function(){this._updateHint()},_onOpened:function(){this._updateHint(),this.eventBus.trigger("opened")},_onClosed:function(){this.input.clearHint(),this.eventBus.trigger("closed")},_onFocused:function(){this.isActivated=!0,this.dropdown.open()},_onBlurred:function(){this.isActivated=!1,this.dropdown.empty(),this.dropdown.close()},_onEnterKeyed:function(a,b){var c,d;c=this.dropdown.getDatumForCursor(),d=this.dropdown.getDatumForTopSuggestion(),c?(this._select(c),b.preventDefault()):this.autoselect&&d&&(this._select(d),b.preventDefault())},_onTabKeyed:function(a,b){var c;(c=this.dropdown.getDatumForCursor())?(this._select(c),b.preventDefault()):this._autocomplete(!0)},_onEscKeyed:function(){this.dropdown.close(),this.input.resetInputValue()},_onUpKeyed:function(){var a=this.input.getQuery();this.dropdown.isEmpty&&a.length>=this.minLength?this.dropdown.update(a):this.dropdown.moveCursorUp(),this.dropdown.open()},_onDownKeyed:function(){var a=this.input.getQuery();this.dropdown.isEmpty&&a.length>=this.minLength?this.dropdown.update(a):this.dropdown.moveCursorDown(),this.dropdown.open()},_onLeftKeyed:function(){"rtl"===this.dir&&this._autocomplete()},_onRightKeyed:function(){"ltr"===this.dir&&this._autocomplete()},_onQueryChanged:function(a,b){this.input.clearHintIfInvalid(),b.length>=this.minLength?this.dropdown.update(b):this.dropdown.empty(),this.dropdown.open(),this._setLanguageDirection()},_onWhitespaceChanged:function(){this._updateHint(),this.dropdown.open()},_setLanguageDirection:function(){var a;this.dir!==(a=this.input.getLanguageDirection())&&(this.dir=a,this.$node.css("direction",a),this.dropdown.setLanguageDirection(a))},_updateHint:function(){var a,c,d,e,f,g;a=this.dropdown.getDatumForTopSuggestion(),a&&this.dropdown.isVisible()&&!this.input.hasOverflow()?(c=this.input.getInputValue(),d=h.normalizeQuery(c),e=b.escapeRegExChars(d),f=new RegExp("^(?:"+e+")(.+$)","i"),g=f.exec(a.value),g?this.input.setHint(c+g[1]):this.input.clearHint()):this.input.clearHint()},_autocomplete:function(a){var b,c,d,e;b=this.input.getHint(),c=this.input.getQuery(),d=a||this.input.isCursorAtEnd(),b&&c!==b&&d&&(e=this.dropdown.getDatumForTopSuggestion(),e&&this.input.setInputValue(e.value),this.eventBus.trigger("autocompleted",e.raw,e.datasetName))},_select:function(a){this.input.setQuery(a.value),this.input.setInputValue(a.value,!0),this._setLanguageDirection(),this.eventBus.trigger("selected",a.raw,a.datasetName),this.dropdown.close(),b.defer(b.bind(this.dropdown.empty,this.dropdown))},open:function(){this.dropdown.open()},close:function(){this.dropdown.close()},setVal:function(a){this.isActivated?this.input.setInputValue(a):(this.input.setQuery(a),this.input.setInputValue(a,!0)),this._setLanguageDirection()},getVal:function(){return this.input.getQuery()},destroy:function(){this.input.destroy(),this.dropdown.destroy(),k(this.$node),this.$node=null}}),f}();!function(){var c,d,f;c=a.fn.typeahead,d="ttTypeahead",f={initialize:function(c,f){function g(){var g,h,i=a(this);b.each(f,function(a){a.highlight=!!c.highlight}),h=new k({input:i,eventBus:g=new e({el:i}),withHint:b.isUndefined(c.hint)?!0:!!c.hint,minLength:c.minLength,autoselect:c.autoselect,datasets:f}),i.data(d,h)}return f=b.isArray(f)?f:[].slice.call(arguments,1),c=c||{},this.each(g)},open:function(){function b(){var b,c=a(this);(b=c.data(d))&&b.open()}return this.each(b)},close:function(){function b(){var b,c=a(this);(b=c.data(d))&&b.close()}return this.each(b)},val:function(b){function c(){var c,e=a(this);(c=e.data(d))&&c.setVal(b)}function e(a){var b,c;return(b=a.data(d))&&(c=b.getVal()),c}return arguments.length?this.each(c):e(this.first())},destroy:function(){function b(){var b,c=a(this);(b=c.data(d))&&(b.destroy(),c.removeData(d))}return this.each(b)}},a.fn.typeahead=function(a){return f[a]?f[a].apply(this,[].slice.call(arguments,1)):f.initialize.apply(this,arguments)},a.fn.typeahead.noConflict=function(){return a.fn.typeahead=c,this}}()}(window.jQuery);\ No newline at end of filediff --git a/htroot/index.html b/htroot/index.htmlindex 1806cb068..9480f8db7 100644--- a/htroot/index.html+++ b/htroot/index.html@@ -5,19 +5,16 @@<title>YaCy '#[clientname]#': Search Page</title>#%env/templates/metas.template%#<link rel="alternate" type="application/rss+xml" title="Search for #[former]#" href="yacysearch.rss?query=#[former]#" />- <link rel="search" type="application/opensearchdescription+xml" title="YaCy Search on '#[clientname]#'" href="opensearchdescription.xml" />- <script type="text/javascript" src="yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"></script>- <script type="text/javascript" src="yacy/ui/js/jquery.autocomplete.yacy.js"></script>- <link media="screen" type="text/css" href="yacy/ui/css/autocomplete.css" rel="stylesheet" />+ <link rel="search" type="application/opensearchdescription+xml" title="YaCy Search on '#[clientname]#'" href="opensearchdescription.xml" />+ <script type="text/javascript" src="/env/bootstrap/js/typeahead.jquery.min.js"></script><script type="text/javascript" src="js/html.js"></script><script type="text/javascript">- $(document).ready(function() {- $('#search').autocomplete('suggest.json', {parse: opensearch, delay: 0, selectFirst: false, scroll: false, max: 30});- function opensearch(data) {- var parsed = [];- data = eval('({"suggest":' + data + '})');- for (var i = 0; i < data.suggest[1].length; i++) {- var row = data.suggest[1][i];+ var suggestMatcher = function() {+ return function opensearch(q, cb) {+ $.getJSON("suggest.json?q=" + q, function(data) {+ var parsed = [];+ for (var i = 0; i < data[1].length; i++) {+ var row = data[1][i];if (row) {parsed[parsed.length] = {data: [row],@@ -26,10 +23,19 @@};};};- return parsed;+ cb(parsed);+ });};+ };+ $(document).ready(function() {+ $('#search').typeahead({hint:false,highlight:true,minLength:1}, {+ name: 'states',+ displayKey: 'value',+ source: suggestMatcher()});+ });</script>+ <style type="text/css">.twitter-typeahead {margin: 0px;padding: 0px;top:-8px;}</style> <!-- fix for input window --></head><body id="index" onload="#(focus)#::document.getElementById('search').focus()#(/focus)#">#(topmenu)#diff --git a/htroot/suggest.java b/htroot/suggest.javaindex 5582b0589..2d4929f40 100644--- a/htroot/suggest.java+++ b/htroot/suggest.java@@ -62,7 +62,7 @@ public class suggest {// get queryfinal String originalquerystring = (post == null) ? "" : post.get("query", post.get("q", ""));- final String querystring = originalquerystring.replace('+', ' ');+ final String querystring = originalquerystring.replace('+', ' ').replaceAll("%20", " ");final int timeout = (post == null) ? 300 : post.getInt("timeout", 300);final int count = (post == null) ? 10 : Math.min(20, post.getInt("count", 10));diff --git a/htroot/yacysearch.html b/htroot/yacysearch.htmlindex c4dcf86ee..244beb7fc 100644--- a/htroot/yacysearch.html+++ b/htroot/yacysearch.html@@ -4,10 +4,7 @@<title>#[former]# - YaCy '#[clientname]#': Search Page</title>#%env/templates/metas.template%#<link rel="alternate" type="application/rss+xml" title="Search for #[former]#" href="yacysearch.rss?query=#[former]#" />- <link rel="search" type="application/opensearchdescription+xml" title="YaCy Search on '#[clientname]#'" href="http://#[thisaddress]#/opensearchdescription.xml" />- <script type="text/javascript" src="yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"></script>- <script type="text/javascript" src="yacy/ui/js/jquery.autocomplete.yacy.js"></script>- <link media="screen" type="text/css" href="yacy/ui/css/autocomplete.css" rel="stylesheet" />+ <link rel="search" type="application/opensearchdescription+xml" title="YaCy Search on '#[clientname]#'" href="http://#[thisaddress]#/opensearchdescription.xml" /><link rel="stylesheet" type="text/css" media="screen" href="env/highslide.css" /><script type="text/javascript" src="js/ajax.js"></script><script type="text/javascript" src="js/xml.js"></script>@@ -16,7 +13,6 @@<script type="text/javascript">hs.outlineType = 'rounded-white';</script><script type="text/javascript">- //<![CDATA[function handleArrowKeys(evt) {evt = (evt) ? evt : ((window.event) ? event : null);if (evt) {@@ -33,19 +29,15 @@}}document.onkeydown = handleArrowKeys;- //]]></script>-</head>-<body id="yacysearch">- <script type="text/javascript" src="yacy/ui/js/jquery.autocomplete.yacy.js"></script>- <script type="text/javascript">- $(document).ready(function() {- $('#search').autocomplete('suggest.json', {parse: opensearch, delay: 0, selectFirst: false, scroll: false, max: 30});- function opensearch(data) {- var parsed = [];- data = eval('({"suggest":' + data + '})');- for (var i = 0; i < data.suggest[1].length; i++) {- var row = data.suggest[1][i];+ <script type="text/javascript" src="/env/bootstrap/js/typeahead.jquery.min.js"></script>+ <script type="text/javascript">+ var suggestMatcher = function() {+ return function opensearch(q, cb) {+ $.getJSON("suggest.json?q=" + q, function(data) {+ var parsed = [];+ for (var i = 0; i < data[1].length; i++) {+ var row = data[1][i];if (row) {parsed[parsed.length] = {data: [row],@@ -54,10 +46,22 @@};};};- return parsed;+ cb(parsed);+ });};+ };+ $(document).ready(function() {+ $('#search').typeahead({hint:false,highlight:true,minLength:1}, {+ name: 'states',+ displayKey: 'value',+ source: suggestMatcher()});- </script>+ });+ </script>+ <style type="text/css">.twitter-typeahead {margin: 0px;padding: 0px;top:2px;}</style> <!-- fix for input window -->+</head>+<body id="yacysearch">+#(topmenu)##%env/templates/embeddedheader.template%#::