| Server IP : 165.22.154.248 / Your IP : 216.73.217.0 [ Web Server : Apache/2.4.29 (Ubuntu) System : Linux droplet-integra 4.15.0-197-generic #208-Ubuntu SMP Tue Nov 1 17:23:37 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 7.2.24-0ubuntu0.18.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/avanza-lms.old.bak9874115/lib/amd/src/ |
Upload File : |
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Search box.
*
* @module core/search-input
* @class search-input
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.1
*/
define(['jquery'], function($) {
/**
* This search box div node.
*
* @private
*/
var wrapper = null;
/**
* Toggles the form visibility.
*
* @param {Event} ev
* @method toggleForm
* @private
*/
var toggleForm = function(ev) {
if (wrapper.hasClass('expanded')) {
hideForm();
} else {
showForm(ev);
}
};
/**
* Shows the form or submits it depending on the window size.
*
* @param {Event} ev
* @method showForm
* @private
*/
var showForm = function(ev) {
var windowWidth = $(document).width();
// We are only interested in enter and space keys (accessibility).
if (ev.type === 'keydown' && ev.keyCode !== 13 && ev.keyCode !== 32) {
return;
}
if (windowWidth <= 767 && (ev.type === 'click' || ev.type === 'keydown')) {
// Move to the search page when using small window sizes as the input requires too much space.
submitForm();
return;
} else if (windowWidth <= 767) {
// Ignore mousedown events in while using small window sizes.
return;
}
if (ev.type === 'keydown') {
// We don't want to submit the form unless the user hits enter.
ev.preventDefault();
}
wrapper.addClass('expanded');
wrapper.find('form').addClass('expanded');
wrapper.find('input').focus();
};
/**
* Hides the form.
*
* @method hideForm
* @private
*/
var hideForm = function() {
wrapper.removeClass('expanded');
wrapper.find('form').removeClass('expanded');
};
/**
* Submits the form.
*
* @param {Event} ev
* @method submitForm
* @private
*/
var submitForm = function() {
wrapper.find('form').submit();
};
return /** @alias module:core/search-input */ {
// Public variables and functions.
/**
* Assigns listeners to the requested select box.
*
* @method init
* @param {Number} id The search wrapper div id
*/
init: function(id) {
wrapper = $('#' + id);
wrapper.on('click mouseover keydown', 'div', toggleForm);
}
};
});