diff --git a/lib/formslib.php b/lib/formslib.php index de7dfca9bd1..2c8a3ea5519 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1240,31 +1240,15 @@ abstract class moodleform { * $enhancement = 'smartselect'; * $options = array('selectablecategories' => true|false) * - * @since Moodle 2.0 * @param string|element $element form element for which Javascript needs to be initalized * @param string $enhancement which init function should be called * @param array $options options passed to javascript * @param array $strings strings for javascript + * @deprecated since Moodle 3.3 MDL-57471 */ function init_javascript_enhancement($element, $enhancement, array $options=array(), array $strings=null) { - global $PAGE; - if (is_string($element)) { - $element = $this->_form->getElement($element); - } - if (is_object($element)) { - $element->_generateId(); - $elementid = $element->getAttribute('id'); - $PAGE->requires->js_init_call('M.form.init_'.$enhancement, array($elementid, $options)); - if (is_array($strings)) { - foreach ($strings as $string) { - if (is_array($string)) { - call_user_func_array(array($PAGE->requires, 'string_for_js'), $string); - } else { - $PAGE->requires->string_for_js($string, 'moodle'); - } - } - } - } + debugging('$mform->init_javascript_enhancement() is deprecated and no longer does anything. '. + 'smartselect uses should be converted to the searchableselector form element.', DEBUG_DEVELOPER); } /** diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 4320ae23c9b..258d52db871 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -1462,209 +1462,11 @@ M.form = M.form || {}; /** * Converts a nbsp indented select box into a multi drop down custom control much - * like the custom menu. It also selectable categories on or off. - * - * $form->init_javascript_enhancement('elementname','smartselect', array('selectablecategories'=>true|false, 'mode'=>'compact'|'spanning')); - * - * @param {YUI} Y - * @param {string} id - * @param {Array} options + * like the custom menu. Can no longer be used. + * @deprecated since Moodle 3.3 */ -M.form.init_smartselect = function(Y, id, options) { - if (!id.match(/^id_/)) { - id = 'id_'+id; - } - var select = Y.one('select#'+id); - if (!select) { - return false; - } - Y.use('event-delegate',function(){ - var smartselect = { - id : id, - structure : [], - options : [], - submenucount : 0, - currentvalue : null, - currenttext : null, - shownevent : null, - cfg : { - selectablecategories : true, - mode : null - }, - nodes : { - select : null, - loading : null, - menu : null - }, - init : function(Y, id, args, nodes) { - if (typeof(args)=='object') { - for (var i in this.cfg) { - if (args[i] || args[i]===false) { - this.cfg[i] = args[i]; - } - } - } - - // Display a loading message first up - this.nodes.select = nodes.select; - - this.currentvalue = this.nodes.select.get('selectedIndex'); - this.currenttext = this.nodes.select.all('option').item(this.currentvalue).get('innerHTML'); - - var options = Array(); - options[''] = {text:this.currenttext,value:'',depth:0,children:[]}; - this.nodes.select.all('option').each(function(option, index) { - var rawtext = option.get('innerHTML'); - var text = rawtext.replace(/^( )*/, ''); - if (rawtext === text) { - text = rawtext.replace(/^(\s)*/, ''); - var depth = (rawtext.length - text.length ) + 1; - } else { - var depth = ((rawtext.length - text.length )/12)+1; - } - option.set('innerHTML', text); - options['i'+index] = {text:text,depth:depth,index:index,children:[]}; - }, this); - - this.structure = []; - var structcount = 0; - for (var i in options) { - var o = options[i]; - if (o.depth == 0) { - this.structure.push(o); - structcount++; - } else { - var d = o.depth; - var current = this.structure[structcount-1]; - for (var j = 0; j < o.depth-1;j++) { - if (current && current.children) { - current = current.children[current.children.length-1]; - } - } - if (current && current.children) { - current.children.push(o); - } - } - } - - this.nodes.menu = Y.Node.create(this.generate_menu_content()); - this.nodes.menu.one('.smartselect_mask').setStyle('opacity', 0.01); - this.nodes.menu.one('.smartselect_mask').setStyle('width', (this.nodes.select.get('offsetWidth')+5)+'px'); - this.nodes.menu.one('.smartselect_mask').setStyle('height', (this.nodes.select.get('offsetHeight'))+'px'); - - if (this.cfg.mode == null) { - var formwidth = this.nodes.select.ancestor('form').get('offsetWidth'); - if (formwidth < 400 || this.nodes.menu.get('offsetWidth') < formwidth*2) { - this.cfg.mode = 'compact'; - } else { - this.cfg.mode = 'spanning'; - } - } - - if (this.cfg.mode == 'compact') { - this.nodes.menu.addClass('compactmenu'); - } else { - this.nodes.menu.addClass('spanningmenu'); - this.nodes.menu.delegate('mouseover', this.show_sub_menu, '.smartselect_submenuitem', this); - } - - Y.one(document.body).append(this.nodes.menu); - var pos = this.nodes.select.getXY(); - pos[0] += 1; - this.nodes.menu.setXY(pos); - this.nodes.menu.on('click', this.handle_click, this); - - Y.one(window).on('resize', function(){ - var pos = this.nodes.select.getXY(); - pos[0] += 1; - this.nodes.menu.setXY(pos); - }, this); - }, - generate_menu_content : function() { - var content = '