Current Path : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/ |
Current File : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/form-autocomplete.min.js.map |
{"version":3,"sources":["../src/form-autocomplete.js"],"names":["define","$","log","str","templates","notification","LoadingIcon","KEYS","DOWN","ENTER","SPACE","ESCAPE","COMMA","UP","uniqueId","Date","now","activateSelection","index","state","selectionElement","document","getElementById","selectionId","length","children","element","get","itemId","attr","Deferred","resolve","updateSelectionList","options","originalSelect","pendingKey","inputId","M","util","js_pending","items","newSelection","activeId","activeValue","each","ele","prop","label","data","html","push","value","context","extend","render","then","js","replaceNodeContents","js_complete","catch","exception","notifyChange","core_formchangechecker","set_form_changed","dispatchEvent","Event","deselectItem","item","selectedItemValue","remove","activateItem","inputElement","suggestionsElement","suggestionsId","globalIndex","scrollPos","offset","top","scrollTop","height","animate","promise","activateNextItem","current","activatePreviousSelection","selectionsElement","activateNextSelection","activatePreviousItem","closeSuggestions","hide","updateSuggestions","query","matchingElements","suggestions","option","innerHTML","searchquery","caseSensitive","toLocaleLowerCase","returnVal","replaceNode","show","node","text","indexOf","tags","get_string","done","nosuggestionsstr","createItem","val","split","found","tagindex","tag","trim","multiple","append","createTextNode","selectCurrentItem","closeSuggestionsOnSelect","focus","updateAjax","e","ajaxHandler","pendingPromise","addPendingJSPromise","parentElement","selectId","parent","addIconToContainerRemoveOnCompletion","currentTarget","transport","selector","results","processedResults","processResults","existingValues","optionIndex","isArray","resultIndex","result","error","reject","addNavigation","on","pendingJsPromise","keyCode","showSuggestions","ajax","require","preventDefault","closest","window","setTimeout","focusElement","activeElement","timeoutPromise","is","arrowElement","downArrowId","off","selectedItem","throttleTimeout","inProgress","handler","arguments","throttledHandler","clearTimeout","bind","last","key","enhance","placeholder","noSelectionString","templateOverrides","input","layout","selection","fail","debug","css","prepend","originalLabel","collectedjs","renderLayout","renderInput","renderDatalist","renderSelection","when","container","find","replaceWith","runTemplateJS"],"mappings":"AA0BAA,OAAM,0BACF,CAAC,Q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AAb,CAAuBkF,CAAvB,CACH,CAjCM,CAkCV,CAtK8C,CAwKtD,CA1kCK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Autocomplete wrapper for select2 library.\n *\n * @module core/form-autocomplete\n * @class autocomplete\n * @package core\n * @copyright 2015 Damyon Wiese <damyon@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.0\n */\n/* globals require: false */\ndefine(\n ['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification', 'core/loadingicon'],\nfunction($, log, str, templates, notification, LoadingIcon) {\n\n // Private functions and variables.\n /** @var {Object} KEYS - List of keycode constants. */\n var KEYS = {\n DOWN: 40,\n ENTER: 13,\n SPACE: 32,\n ESCAPE: 27,\n COMMA: 44,\n UP: 38\n };\n\n var uniqueId = Date.now();\n\n /**\n * Make an item in the selection list \"active\".\n *\n * @method activateSelection\n * @private\n * @param {Number} index The index in the current (visible) list of selection.\n * @param {Object} state State variables for this autocomplete element.\n * @return {Promise}\n */\n var activateSelection = function(index, state) {\n // Find the elements in the DOM.\n var selectionElement = $(document.getElementById(state.selectionId));\n\n // Count the visible items.\n var length = selectionElement.children('[aria-selected=true]').length;\n // Limit the index to the upper/lower bounds of the list (wrap in both directions).\n index = index % length;\n while (index < 0) {\n index += length;\n }\n // Find the specified element.\n var element = $(selectionElement.children('[aria-selected=true]').get(index));\n // Create an id we can assign to this element.\n var itemId = state.selectionId + '-' + index;\n\n // Deselect all the selections.\n selectionElement.children().attr('data-active-selection', false).attr('id', '');\n // Select only this suggestion and assign it the id.\n element.attr('data-active-selection', true).attr('id', itemId);\n // Tell the input field it has a new active descendant so the item is announced.\n selectionElement.attr('aria-activedescendant', itemId);\n\n return $.Deferred().resolve();\n };\n\n /**\n * Update the element that shows the currently selected items.\n *\n * @method updateSelectionList\n * @private\n * @param {Object} options Original options for this autocomplete element.\n * @param {Object} state State variables for this autocomplete element.\n * @param {JQuery} originalSelect The JQuery object matching the hidden select list.\n * @return {Promise}\n */\n var updateSelectionList = function(options, state, originalSelect) {\n var pendingKey = 'form-autocomplete-updateSelectionList-' + state.inputId;\n M.util.js_pending(pendingKey);\n\n // Build up a valid context to re-render the template.\n var items = [];\n var newSelection = $(document.getElementById(state.selectionId));\n var activeId = newSelection.attr('aria-activedescendant');\n var activeValue = false;\n\n if (activeId) {\n activeValue = $(document.getElementById(activeId)).attr('data-value');\n }\n originalSelect.children('option').each(function(index, ele) {\n if ($(ele).prop('selected')) {\n var label;\n if ($(ele).data('html')) {\n label = $(ele).data('html');\n } else {\n label = $(ele).html();\n }\n if (label !== '') {\n items.push({label: label, value: $(ele).attr('value')});\n }\n }\n });\n var context = $.extend({items: items}, options, state);\n // Render the template.\n return templates.render(options.templates.items, context)\n .then(function(html, js) {\n // Add it to the page.\n templates.replaceNodeContents(newSelection, html, js);\n\n if (activeValue !== false) {\n // Reselect any previously selected item.\n newSelection.children('[aria-selected=true]').each(function(index, ele) {\n if ($(ele).attr('data-value') === activeValue) {\n activateSelection(index, state);\n }\n });\n }\n\n return activeValue;\n })\n .then(function() {\n return M.util.js_complete(pendingKey);\n })\n .catch(notification.exception);\n };\n\n /**\n * Notify of a change in the selection.\n *\n * @param {jQuery} originalSelect The jQuery object matching the hidden select list.\n */\n var notifyChange = function(originalSelect) {\n if (typeof M.core_formchangechecker !== 'undefined') {\n M.core_formchangechecker.set_form_changed();\n }\n\n // Note, jQuery .change() was not working here. Better to\n // use plain JavaScript anyway.\n originalSelect[0].dispatchEvent(new Event('change'));\n };\n\n /**\n * Remove the given item from the list of selected things.\n *\n * @method deselectItem\n * @private\n * @param {Object} options Original options for this autocomplete element.\n * @param {Object} state State variables for this autocomplete element.\n * @param {Element} item The item to be deselected.\n * @param {Element} originalSelect The original select list.\n * @return {Promise}\n */\n var deselectItem = function(options, state, item, originalSelect) {\n var selectedItemValue = $(item).attr('data-value');\n\n // Look for a match, and toggle the selected property if there is a match.\n originalSelect.children('option').each(function(index, ele) {\n if ($(ele).attr('value') == selectedItemValue) {\n $(ele).prop('selected', false);\n // We remove newly created custom tags from the suggestions list when they are deselected.\n if ($(ele).attr('data-iscustom')) {\n $(ele).remove();\n }\n }\n });\n // Rerender the selection list.\n return updateSelectionList(options, state, originalSelect)\n .then(function() {\n // Notify that the selection changed.\n notifyChange(originalSelect);\n\n return;\n });\n };\n\n /**\n * Make an item in the suggestions \"active\" (about to be selected).\n *\n * @method activateItem\n * @private\n * @param {Number} index The index in the current (visible) list of suggestions.\n * @param {Object} state State variables for this instance of autocomplete.\n * @return {Promise}\n */\n var activateItem = function(index, state) {\n // Find the elements in the DOM.\n var inputElement = $(document.getElementById(state.inputId));\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n\n // Count the visible items.\n var length = suggestionsElement.children('[aria-hidden=false]').length;\n // Limit the index to the upper/lower bounds of the list (wrap in both directions).\n index = index % length;\n while (index < 0) {\n index += length;\n }\n // Find the specified element.\n var element = $(suggestionsElement.children('[aria-hidden=false]').get(index));\n // Find the index of this item in the full list of suggestions (including hidden).\n var globalIndex = $(suggestionsElement.children('[role=option]')).index(element);\n // Create an id we can assign to this element.\n var itemId = state.suggestionsId + '-' + globalIndex;\n\n // Deselect all the suggestions.\n suggestionsElement.children().attr('aria-selected', false).attr('id', '');\n // Select only this suggestion and assign it the id.\n element.attr('aria-selected', true).attr('id', itemId);\n // Tell the input field it has a new active descendant so the item is announced.\n inputElement.attr('aria-activedescendant', itemId);\n\n // Scroll it into view.\n var scrollPos = element.offset().top\n - suggestionsElement.offset().top\n + suggestionsElement.scrollTop()\n - (suggestionsElement.height() / 2);\n return suggestionsElement.animate({\n scrollTop: scrollPos\n }, 100).promise();\n };\n\n /**\n * Find the index of the current active suggestion, and activate the next one.\n *\n * @method activateNextItem\n * @private\n * @param {Object} state State variable for this auto complete element.\n * @return {Promise}\n */\n var activateNextItem = function(state) {\n // Find the list of suggestions.\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n // Find the active one.\n var element = suggestionsElement.children('[aria-selected=true]');\n // Find it's index.\n var current = suggestionsElement.children('[aria-hidden=false]').index(element);\n // Activate the next one.\n return activateItem(current + 1, state);\n };\n\n /**\n * Find the index of the current active selection, and activate the previous one.\n *\n * @method activatePreviousSelection\n * @private\n * @param {Object} state State variables for this instance of autocomplete.\n * @return {Promise}\n */\n var activatePreviousSelection = function(state) {\n // Find the list of selections.\n var selectionsElement = $(document.getElementById(state.selectionId));\n // Find the active one.\n var element = selectionsElement.children('[data-active-selection=true]');\n if (!element) {\n return activateSelection(0, state);\n }\n // Find it's index.\n var current = selectionsElement.children('[aria-selected=true]').index(element);\n // Activate the next one.\n return activateSelection(current - 1, state);\n };\n\n /**\n * Find the index of the current active selection, and activate the next one.\n *\n * @method activateNextSelection\n * @private\n * @param {Object} state State variables for this instance of autocomplete.\n * @return {Promise}\n */\n var activateNextSelection = function(state) {\n // Find the list of selections.\n var selectionsElement = $(document.getElementById(state.selectionId));\n\n // Find the active one.\n var element = selectionsElement.children('[data-active-selection=true]');\n var current = 0;\n\n if (element) {\n // The element was found. Determine the index and move to the next one.\n current = selectionsElement.children('[aria-selected=true]').index(element);\n current = current + 1;\n } else {\n // No selected item found. Move to the first.\n current = 0;\n }\n\n return activateSelection(current, state);\n };\n\n /**\n * Find the index of the current active suggestion, and activate the previous one.\n *\n * @method activatePreviousItem\n * @private\n * @param {Object} state State variables for this autocomplete element.\n * @return {Promise}\n */\n var activatePreviousItem = function(state) {\n // Find the list of suggestions.\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n\n // Find the active one.\n var element = suggestionsElement.children('[aria-selected=true]');\n\n // Find it's index.\n var current = suggestionsElement.children('[aria-hidden=false]').index(element);\n\n // Activate the previous one.\n return activateItem(current - 1, state);\n };\n\n /**\n * Close the list of suggestions.\n *\n * @method closeSuggestions\n * @private\n * @param {Object} state State variables for this autocomplete element.\n * @return {Promise}\n */\n var closeSuggestions = function(state) {\n // Find the elements in the DOM.\n var inputElement = $(document.getElementById(state.inputId));\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n\n // Announce the list of suggestions was closed, and read the current list of selections.\n inputElement.attr('aria-expanded', false).attr('aria-activedescendant', state.selectionId);\n\n // Hide the suggestions list (from screen readers too).\n suggestionsElement.hide().attr('aria-hidden', true);\n\n return $.Deferred().resolve();\n };\n\n /**\n * Rebuild the list of suggestions based on the current values in the select list, and the query.\n *\n * @method updateSuggestions\n * @private\n * @param {Object} options The original options for this autocomplete.\n * @param {Object} state The state variables for this autocomplete.\n * @param {String} query The current text for the search string.\n * @param {JQuery} originalSelect The JQuery object matching the hidden select list.\n * @return {Promise}\n */\n var updateSuggestions = function(options, state, query, originalSelect) {\n var pendingKey = 'form-autocomplete-updateSuggestions-' + state.inputId;\n M.util.js_pending(pendingKey);\n\n // Find the elements in the DOM.\n var inputElement = $(document.getElementById(state.inputId));\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n\n // Used to track if we found any visible suggestions.\n var matchingElements = false;\n // Options is used by the context when rendering the suggestions from a template.\n var suggestions = [];\n originalSelect.children('option').each(function(index, option) {\n if ($(option).prop('selected') !== true) {\n suggestions[suggestions.length] = {label: option.innerHTML, value: $(option).attr('value')};\n }\n });\n\n // Re-render the list of suggestions.\n var searchquery = state.caseSensitive ? query : query.toLocaleLowerCase();\n var context = $.extend({options: suggestions}, options, state);\n var returnVal = templates.render(\n 'core/form_autocomplete_suggestions',\n context\n )\n .then(function(html, js) {\n // We have the new template, insert it in the page.\n templates.replaceNode(suggestionsElement, html, js);\n\n // Get the element again.\n suggestionsElement = $(document.getElementById(state.suggestionsId));\n // Show it if it is hidden.\n suggestionsElement.show().attr('aria-hidden', false);\n // For each option in the list, hide it if it doesn't match the query.\n suggestionsElement.children().each(function(index, node) {\n node = $(node);\n if ((options.caseSensitive && node.text().indexOf(searchquery) > -1) ||\n (!options.caseSensitive && node.text().toLocaleLowerCase().indexOf(searchquery) > -1)) {\n node.show().attr('aria-hidden', false);\n matchingElements = true;\n } else {\n node.hide().attr('aria-hidden', true);\n }\n });\n // If we found any matches, show the list.\n inputElement.attr('aria-expanded', true);\n if (originalSelect.attr('data-notice')) {\n // Display a notice rather than actual suggestions.\n suggestionsElement.html(originalSelect.attr('data-notice'));\n } else if (matchingElements) {\n // We only activate the first item in the list if tags is false,\n // because otherwise \"Enter\" would select the first item, instead of\n // creating a new tag.\n if (!options.tags) {\n activateItem(0, state);\n }\n } else {\n // Nothing matches. Tell them that.\n str.get_string('nosuggestions', 'form').done(function(nosuggestionsstr) {\n suggestionsElement.html(nosuggestionsstr);\n });\n }\n\n return suggestionsElement;\n })\n .then(function() {\n return M.util.js_complete(pendingKey);\n })\n .catch(notification.exception);\n\n return returnVal;\n };\n\n /**\n * Create a new item for the list (a tag).\n *\n * @method createItem\n * @private\n * @param {Object} options The original options for the autocomplete.\n * @param {Object} state State variables for the autocomplete.\n * @param {JQuery} originalSelect The JQuery object matching the hidden select list.\n * @return {Promise}\n */\n var createItem = function(options, state, originalSelect) {\n // Find the element in the DOM.\n var inputElement = $(document.getElementById(state.inputId));\n // Get the current text in the input field.\n var query = inputElement.val();\n var tags = query.split(',');\n var found = false;\n\n $.each(tags, function(tagindex, tag) {\n // If we can only select one at a time, deselect any current value.\n tag = tag.trim();\n if (tag !== '') {\n if (!options.multiple) {\n originalSelect.children('option').prop('selected', false);\n }\n // Look for an existing option in the select list that matches this new tag.\n originalSelect.children('option').each(function(index, ele) {\n if ($(ele).attr('value') == tag) {\n found = true;\n $(ele).prop('selected', true);\n }\n });\n // Only create the item if it's new.\n if (!found) {\n var option = $('<option>');\n option.append(document.createTextNode(tag));\n option.attr('value', tag);\n originalSelect.append(option);\n option.prop('selected', true);\n // We mark newly created custom options as we handle them differently if they are \"deselected\".\n option.attr('data-iscustom', true);\n }\n }\n });\n\n return updateSelectionList(options, state, originalSelect)\n .then(function() {\n // Notify that the selection changed.\n notifyChange(originalSelect);\n\n return;\n })\n .then(function() {\n // Clear the input field.\n inputElement.val('');\n\n return;\n })\n .then(function() {\n // Close the suggestions list.\n return closeSuggestions(state);\n });\n };\n\n /**\n * Select the currently active item from the suggestions list.\n *\n * @method selectCurrentItem\n * @private\n * @param {Object} options The original options for the autocomplete.\n * @param {Object} state State variables for the autocomplete.\n * @param {JQuery} originalSelect The JQuery object matching the hidden select list.\n * @return {Promise}\n */\n var selectCurrentItem = function(options, state, originalSelect) {\n // Find the elements in the page.\n var inputElement = $(document.getElementById(state.inputId));\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n // Here loop through suggestions and set val to join of all selected items.\n\n var selectedItemValue = suggestionsElement.children('[aria-selected=true]').attr('data-value');\n // The select will either be a single or multi select, so the following will either\n // select one or more items correctly.\n // Take care to use 'prop' and not 'attr' for selected properties.\n // If only one can be selected at a time, start by deselecting everything.\n if (!options.multiple) {\n originalSelect.children('option').prop('selected', false);\n }\n // Look for a match, and toggle the selected property if there is a match.\n originalSelect.children('option').each(function(index, ele) {\n if ($(ele).attr('value') == selectedItemValue) {\n $(ele).prop('selected', true);\n }\n });\n\n return updateSelectionList(options, state, originalSelect)\n .then(function() {\n // Notify that the selection changed.\n notifyChange(originalSelect);\n\n return;\n })\n .then(function() {\n if (options.closeSuggestionsOnSelect) {\n // Clear the input element.\n inputElement.val('');\n // Close the list of suggestions.\n return closeSuggestions(state);\n } else {\n // Focus on the input element so the suggestions does not auto-close.\n inputElement.focus();\n // Remove the last selected item from the suggestions list.\n return updateSuggestions(options, state, inputElement.val(), originalSelect);\n }\n });\n };\n\n /**\n * Fetch a new list of options via ajax.\n *\n * @method updateAjax\n * @private\n * @param {Event} e The event that triggered this update.\n * @param {Object} options The original options for the autocomplete.\n * @param {Object} state The state variables for the autocomplete.\n * @param {JQuery} originalSelect The JQuery object matching the hidden select list.\n * @param {Object} ajaxHandler This is a module that does the ajax fetch and translates the results.\n * @return {Promise}\n */\n var updateAjax = function(e, options, state, originalSelect, ajaxHandler) {\n var pendingPromise = addPendingJSPromise('updateAjax');\n // We need to show the indicator outside of the hidden select list.\n // So we get the parent id of the hidden select list.\n var parentElement = $(document.getElementById(state.selectId)).parent();\n LoadingIcon.addIconToContainerRemoveOnCompletion(parentElement, pendingPromise);\n\n // Get the query to pass to the ajax function.\n var query = $(e.currentTarget).val();\n // Call the transport function to do the ajax (name taken from Select2).\n ajaxHandler.transport(options.selector, query, function(results) {\n // We got a result - pass it through the translator before using it.\n var processedResults = ajaxHandler.processResults(options.selector, results);\n var existingValues = [];\n\n // Now destroy all options that are not currently selected.\n if (!options.multiple) {\n originalSelect.children('option').remove();\n }\n originalSelect.children('option').each(function(optionIndex, option) {\n option = $(option);\n if (!option.prop('selected')) {\n option.remove();\n } else {\n existingValues.push(String(option.attr('value')));\n }\n });\n\n if (!options.multiple && originalSelect.children('option').length === 0) {\n // If this is a single select - and there are no current options\n // the first option added will be selected by the browser. This causes a bug!\n // We need to insert an empty option so that none of the real options are selected.\n var option = $('<option>');\n originalSelect.append(option);\n }\n if ($.isArray(processedResults)) {\n // Add all the new ones returned from ajax.\n $.each(processedResults, function(resultIndex, result) {\n if (existingValues.indexOf(String(result.value)) === -1) {\n var option = $('<option>');\n option.append(result.label);\n option.attr('value', result.value);\n originalSelect.append(option);\n }\n });\n originalSelect.attr('data-notice', '');\n } else {\n // The AJAX handler returned a string instead of the array.\n originalSelect.attr('data-notice', processedResults);\n }\n // Update the list of suggestions now from the new values in the select list.\n pendingPromise.resolve(updateSuggestions(options, state, '', originalSelect));\n }, function(error) {\n pendingPromise.reject(error);\n });\n\n return pendingPromise;\n };\n\n /**\n * Add all the event listeners required for keyboard nav, blur clicks etc.\n *\n * @method addNavigation\n * @private\n * @param {Object} options The options used to create this autocomplete element.\n * @param {Object} state State variables for this autocomplete element.\n * @param {JQuery} originalSelect The JQuery object matching the hidden select list.\n */\n var addNavigation = function(options, state, originalSelect) {\n // Start with the input element.\n var inputElement = $(document.getElementById(state.inputId));\n // Add keyboard nav with keydown.\n inputElement.on('keydown', function(e) {\n var pendingJsPromise = addPendingJSPromise('addNavigation-' + state.inputId + '-' + e.keyCode);\n\n switch (e.keyCode) {\n case KEYS.DOWN:\n // If the suggestion list is open, move to the next item.\n if (!options.showSuggestions) {\n // Do not consume this event.\n pendingJsPromise.resolve();\n return true;\n } else if (inputElement.attr('aria-expanded') === \"true\") {\n pendingJsPromise.resolve(activateNextItem(state));\n } else {\n // Handle ajax population of suggestions.\n if (!inputElement.val() && options.ajax) {\n require([options.ajax], function(ajaxHandler) {\n pendingJsPromise.resolve(updateAjax(e, options, state, originalSelect, ajaxHandler));\n });\n } else {\n // Open the suggestions list.\n pendingJsPromise.resolve(updateSuggestions(options, state, inputElement.val(), originalSelect));\n }\n }\n // We handled this event, so prevent it.\n e.preventDefault();\n return false;\n case KEYS.UP:\n // Choose the previous active item.\n pendingJsPromise.resolve(activatePreviousItem(state));\n\n // We handled this event, so prevent it.\n e.preventDefault();\n return false;\n case KEYS.ENTER:\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n if ((inputElement.attr('aria-expanded') === \"true\") &&\n (suggestionsElement.children('[aria-selected=true]').length > 0)) {\n // If the suggestion list has an active item, select it.\n pendingJsPromise.resolve(selectCurrentItem(options, state, originalSelect));\n } else if (options.tags) {\n // If tags are enabled, create a tag.\n pendingJsPromise.resolve(createItem(options, state, originalSelect));\n } else {\n pendingJsPromise.resolve();\n }\n\n // We handled this event, so prevent it.\n e.preventDefault();\n return false;\n case KEYS.ESCAPE:\n if (inputElement.attr('aria-expanded') === \"true\") {\n // If the suggestion list is open, close it.\n pendingJsPromise.resolve(closeSuggestions(state));\n } else {\n pendingJsPromise.resolve();\n }\n // We handled this event, so prevent it.\n e.preventDefault();\n return false;\n }\n pendingJsPromise.resolve();\n return true;\n });\n // Support multi lingual COMMA keycode (44).\n inputElement.on('keypress', function(e) {\n\n if (e.keyCode === KEYS.COMMA) {\n if (options.tags) {\n // If we are allowing tags, comma should create a tag (or enter).\n addPendingJSPromise('keypress-' + e.keyCode)\n .resolve(createItem(options, state, originalSelect));\n }\n // We handled this event, so prevent it.\n e.preventDefault();\n return false;\n }\n return true;\n });\n // Support submitting the form without leaving the autocomplete element,\n // or submitting too quick before the blur handler action is completed.\n inputElement.closest('form').on('submit', function() {\n if (options.tags) {\n // If tags are enabled, create a tag.\n addPendingJSPromise('form-autocomplete-submit')\n .resolve(createItem(options, state, originalSelect));\n }\n\n return true;\n });\n inputElement.on('blur', function() {\n var pendingPromise = addPendingJSPromise('form-autocomplete-blur');\n window.setTimeout(function() {\n // Get the current element with focus.\n var focusElement = $(document.activeElement);\n var timeoutPromise = $.Deferred();\n\n // Only close the menu if the input hasn't regained focus and if the element still exists,\n // and regain focus if the scrollbar is clicked.\n // Due to the half a second delay, it is possible that the input element no longer exist\n // by the time this code is being executed.\n if (focusElement.is(document.getElementById(state.suggestionsId))) {\n inputElement.focus(); // Probably the scrollbar is clicked. Regain focus.\n } else if (!focusElement.is(inputElement) && $(document.getElementById(state.inputId)).length) {\n if (options.tags) {\n timeoutPromise.then(function() {\n return createItem(options, state, originalSelect);\n })\n .catch();\n }\n timeoutPromise.then(function() {\n return closeSuggestions(state);\n })\n .catch();\n }\n\n timeoutPromise.then(function() {\n return pendingPromise.resolve();\n })\n .catch();\n timeoutPromise.resolve();\n }, 500);\n });\n if (options.showSuggestions) {\n var arrowElement = $(document.getElementById(state.downArrowId));\n arrowElement.on('click', function(e) {\n var pendingPromise = addPendingJSPromise('form-autocomplete-show-suggestions');\n\n // Prevent the close timer, or we will open, then close the suggestions.\n inputElement.focus();\n\n // Handle ajax population of suggestions.\n if (!inputElement.val() && options.ajax) {\n require([options.ajax], function(ajaxHandler) {\n pendingPromise.resolve(updateAjax(e, options, state, originalSelect, ajaxHandler));\n });\n } else {\n // Else - open the suggestions list.\n pendingPromise.resolve(updateSuggestions(options, state, inputElement.val(), originalSelect));\n }\n });\n }\n\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n // Remove any click handler first.\n suggestionsElement.parent().prop(\"onclick\", null).off(\"click\");\n suggestionsElement.parent().on('click', '[role=option]', function(e) {\n var pendingPromise = addPendingJSPromise('form-autocomplete-parent');\n // Handle clicks on suggestions.\n var element = $(e.currentTarget).closest('[role=option]');\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n // Find the index of the clicked on suggestion.\n var current = suggestionsElement.children('[aria-hidden=false]').index(element);\n\n // Activate it.\n activateItem(current, state)\n .then(function() {\n // And select it.\n return selectCurrentItem(options, state, originalSelect);\n })\n .then(function() {\n return pendingPromise.resolve();\n })\n .catch();\n });\n var selectionElement = $(document.getElementById(state.selectionId));\n // Handle clicks on the selected items (will unselect an item).\n selectionElement.on('click', '[role=listitem]', function(e) {\n var pendingPromise = addPendingJSPromise('form-autocomplete-clicks');\n\n // Remove it from the selection.\n pendingPromise.resolve(deselectItem(options, state, $(e.currentTarget), originalSelect));\n });\n // Keyboard navigation for the selection list.\n selectionElement.on('keydown', function(e) {\n var pendingPromise = addPendingJSPromise('form-autocomplete-keydown-' + e.keyCode);\n switch (e.keyCode) {\n case KEYS.DOWN:\n // We handled this event, so prevent it.\n e.preventDefault();\n\n // Choose the next selection item.\n pendingPromise.resolve(activateNextSelection(state));\n return false;\n case KEYS.UP:\n // We handled this event, so prevent it.\n e.preventDefault();\n\n // Choose the previous selection item.\n pendingPromise.resolve(activatePreviousSelection(state));\n return false;\n case KEYS.SPACE:\n case KEYS.ENTER:\n // Get the item that is currently selected.\n var selectedItem = $(document.getElementById(state.selectionId)).children('[data-active-selection=true]');\n if (selectedItem) {\n e.preventDefault();\n\n // Unselect this item.\n pendingPromise.resolve(deselectItem(options, state, selectedItem, originalSelect));\n }\n return false;\n }\n\n // Not handled. Resolve the promise.\n pendingPromise.resolve();\n return true;\n });\n // Whenever the input field changes, update the suggestion list.\n if (options.showSuggestions) {\n // Store the value of the field as its last value, when the field gains focus.\n inputElement.on('focus', function(e) {\n var query = $(e.currentTarget).val();\n $(e.currentTarget).data('last-value', query);\n });\n\n // If this field uses ajax, set it up.\n if (options.ajax) {\n require([options.ajax], function(ajaxHandler) {\n // Creating throttled handlers free of race conditions, and accurate.\n // This code keeps track of a throttleTimeout, which is periodically polled.\n // Once the throttled function is executed, the fact that it is running is noted.\n // If a subsequent request comes in whilst it is running, this request is re-applied.\n var throttleTimeout = null;\n var inProgress = false;\n var pendingKey = 'autocomplete-throttledhandler';\n var handler = function(e) {\n // Empty the current timeout.\n throttleTimeout = null;\n\n // Mark this request as in-progress.\n inProgress = true;\n\n // Process the request.\n updateAjax(e, options, state, originalSelect, ajaxHandler)\n .then(function() {\n // Check if the throttleTimeout is still empty.\n // There's a potential condition whereby the JS request takes long enough to complete that\n // another task has been queued.\n // In this case another task will be kicked off and we must wait for that before marking htis as\n // complete.\n if (null === throttleTimeout) {\n // Mark this task as complete.\n M.util.js_complete(pendingKey);\n }\n inProgress = false;\n\n return arguments[0];\n })\n .catch(notification.exception);\n };\n\n // For input events, we do not want to trigger many, many updates.\n var throttledHandler = function(e) {\n window.clearTimeout(throttleTimeout);\n if (inProgress) {\n // A request is currently ongoing.\n // Delay this request another 100ms.\n throttleTimeout = window.setTimeout(throttledHandler.bind(this, e), 100);\n return;\n }\n\n if (throttleTimeout === null) {\n // There is currently no existing timeout handler, and it has not been recently cleared, so\n // this is the start of a throttling check.\n M.util.js_pending(pendingKey);\n }\n\n // There is currently no existing timeout handler, and it has not been recently cleared, so this\n // is the start of a throttling check.\n // Queue a call to the handler.\n throttleTimeout = window.setTimeout(handler.bind(this, e), 300);\n };\n\n // Trigger an ajax update after the text field value changes.\n inputElement.on('input', function(e) {\n var query = $(e.currentTarget).val();\n var last = $(e.currentTarget).data('last-value');\n // IE11 fires many more input events than required - even when the value has not changed.\n if (last !== query) {\n throttledHandler(e);\n }\n $(e.currentTarget).data('last-value', query);\n });\n });\n } else {\n inputElement.on('input', function(e) {\n var query = $(e.currentTarget).val();\n var last = $(e.currentTarget).data('last-value');\n // IE11 fires many more input events than required - even when the value has not changed.\n // We need to only do this for real value changed events or the suggestions will be\n // unclickable on IE11 (because they will be rebuilt before the click event fires).\n // Note - because of this we cannot close the list when the query is empty or it will break\n // on IE11.\n if (last !== query) {\n updateSuggestions(options, state, query, originalSelect);\n }\n $(e.currentTarget).data('last-value', query);\n });\n }\n }\n };\n\n /**\n * Create and return an unresolved Promise for some pending JS.\n *\n * @param {String} key The unique identifier for this promise\n * @return {Promise}\n */\n var addPendingJSPromise = function(key) {\n var pendingKey = 'form-autocomplete:' + key;\n\n M.util.js_pending(pendingKey);\n\n var pendingPromise = $.Deferred();\n\n pendingPromise\n .then(function() {\n M.util.js_complete(pendingKey);\n\n return arguments[0];\n })\n .catch(notification.exception);\n\n return pendingPromise;\n };\n\n return /** @alias module:core/form-autocomplete */ {\n // Public variables and functions.\n /**\n * Turn a boring select box into an auto-complete beast.\n *\n * @method enhance\n * @param {string} selector The selector that identifies the select box.\n * @param {boolean} tags Whether to allow support for tags (can define new entries).\n * @param {string} ajax Name of an AMD module to handle ajax requests. If specified, the AMD\n * module must expose 2 functions \"transport\" and \"processResults\".\n * These are modeled on Select2 see: https://select2.github.io/options.html#ajax\n * @param {String} placeholder - The text to display before a selection is made.\n * @param {Boolean} caseSensitive - If search has to be made case sensitive.\n * @param {Boolean} showSuggestions - If suggestions should be shown\n * @param {String} noSelectionString - Text to display when there is no selection\n * @param {Boolean} closeSuggestionsOnSelect - Whether to close the suggestions immediately after making a selection.\n * @param {Object} templateOverrides A set of templates to use instead of the standard templates\n * @return {Promise}\n */\n enhance: function(selector, tags, ajax, placeholder, caseSensitive, showSuggestions, noSelectionString,\n closeSuggestionsOnSelect, templateOverrides) {\n // Set some default values.\n var options = {\n selector: selector,\n tags: false,\n ajax: false,\n placeholder: placeholder,\n caseSensitive: false,\n showSuggestions: true,\n noSelectionString: noSelectionString,\n templates: $.extend({\n input: 'core/form_autocomplete_input',\n items: 'core/form_autocomplete_selection_items',\n layout: 'core/form_autocomplete_layout',\n selection: 'core/form_autocomplete_selection',\n suggestions: 'core/form_autocomplete_suggestions',\n }, templateOverrides),\n };\n var pendingKey = 'autocomplete-setup-' + selector;\n M.util.js_pending(pendingKey);\n if (typeof tags !== \"undefined\") {\n options.tags = tags;\n }\n if (typeof ajax !== \"undefined\") {\n options.ajax = ajax;\n }\n if (typeof caseSensitive !== \"undefined\") {\n options.caseSensitive = caseSensitive;\n }\n if (typeof showSuggestions !== \"undefined\") {\n options.showSuggestions = showSuggestions;\n }\n if (typeof noSelectionString === \"undefined\") {\n str.get_string('noselection', 'form').done(function(result) {\n options.noSelectionString = result;\n }).fail(notification.exception);\n }\n\n // Look for the select element.\n var originalSelect = $(selector);\n if (!originalSelect) {\n log.debug('Selector not found: ' + selector);\n M.util.js_complete(pendingKey);\n return false;\n }\n\n originalSelect.css('visibility', 'hidden').attr('aria-hidden', true);\n\n // Hide the original select.\n\n // Find or generate some ids.\n var state = {\n selectId: originalSelect.attr('id'),\n inputId: 'form_autocomplete_input-' + uniqueId,\n suggestionsId: 'form_autocomplete_suggestions-' + uniqueId,\n selectionId: 'form_autocomplete_selection-' + uniqueId,\n downArrowId: 'form_autocomplete_downarrow-' + uniqueId\n };\n\n // Increment the unique counter so we don't get duplicates ever.\n uniqueId++;\n\n options.multiple = originalSelect.attr('multiple');\n if (!options.multiple) {\n // If this is a single select then there is no way to de-select the current value -\n // unless we add a bogus blank option to be selected when nothing else is.\n // This matches similar code in updateAjax above.\n originalSelect.prepend('<option>');\n }\n\n if (typeof closeSuggestionsOnSelect !== \"undefined\") {\n options.closeSuggestionsOnSelect = closeSuggestionsOnSelect;\n } else {\n // If not specified, this will close suggestions by default for single-select elements only.\n options.closeSuggestionsOnSelect = !options.multiple;\n }\n\n var originalLabel = $('[for=' + state.selectId + ']');\n // Create the new markup and insert it after the select.\n var suggestions = [];\n originalSelect.children('option').each(function(index, option) {\n suggestions[index] = {label: option.innerHTML, value: $(option).attr('value')};\n });\n\n // Render all the parts of our UI.\n var context = $.extend({}, options, state);\n context.options = suggestions;\n context.items = [];\n\n // Collect rendered inline JS to be executed once the HTML is shown.\n var collectedjs = '';\n\n var renderLayout = templates.render(options.templates.layout, {})\n .then(function(html) {\n return $(html);\n });\n\n var renderInput = templates.render(options.templates.input, context).then(function(html, js) {\n collectedjs += js;\n return $(html);\n });\n\n var renderDatalist = templates.render(options.templates.suggestions, context).then(function(html, js) {\n collectedjs += js;\n return $(html);\n });\n\n var renderSelection = templates.render(options.templates.selection, context).then(function(html, js) {\n collectedjs += js;\n return $(html);\n });\n\n return $.when(renderLayout, renderInput, renderDatalist, renderSelection)\n .then(function(layout, input, suggestions, selection) {\n originalSelect.hide();\n var container = originalSelect.parent();\n\n container.append(layout);\n container.find('[data-region=\"form_autocomplete-input\"]').replaceWith(input);\n container.find('[data-region=\"form_autocomplete-suggestions\"]').replaceWith(suggestions);\n container.find('[data-region=\"form_autocomplete-selection\"]').replaceWith(selection);\n\n templates.runTemplateJS(collectedjs);\n\n // Update the form label to point to the text input.\n originalLabel.attr('for', state.inputId);\n // Add the event handlers.\n addNavigation(options, state, originalSelect);\n\n var suggestionsElement = $(document.getElementById(state.suggestionsId));\n // Hide the suggestions by default.\n suggestionsElement.hide().attr('aria-hidden', true);\n\n return;\n })\n .then(function() {\n // Show the current values in the selection list.\n return updateSelectionList(options, state, originalSelect);\n })\n .then(function() {\n return M.util.js_complete(pendingKey);\n })\n .catch(function(error) {\n M.util.js_complete(pendingKey);\n notification.exception(error);\n });\n }\n };\n});\n"],"file":"form-autocomplete.min.js"}