From 2fa2ed50eb6cc2b023fe291a958985ae64ff49d0 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 20 Dec 2016 15:06:05 +0000 Subject: [PATCH] MDL-57471 forms: deprecate init_javascript_enhancement() This was half-finished and only used for the smartselect enhancement. That enhancement doesn't work with theme_boost and is better replaced just using the searchableselector element. --- lib/formslib.php | 22 +-- lib/javascript-static.js | 206 +--------------------- lib/upgrade.txt | 4 + theme/boost/scss/moodle/core.scss | 100 ----------- theme/bootstrapbase/less/moodle/core.less | 84 +-------- theme/bootstrapbase/style/moodle.css | 83 --------- 6 files changed, 12 insertions(+), 487 deletions(-) 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 = '
'; - content += this.generate_submenu_content(this.structure[0], true); - content += '
'; - return content; - }, - generate_submenu_content : function(item, rootelement) { - this.submenucount++; - var content = ''; - if (item.children.length > 0) { - if (rootelement) { - content += '
 
'; - content += '
'; - content += '
'; - } else { - content += '
  • '; - var categoryclass = (this.cfg.selectablecategories)?'selectable':'notselectable'; - content += ''+item.text+''; - content += '
    '; - content += '
    '; - } - content += '
      '; - for (var i in item.children) { - content += this.generate_submenu_content(item.children[i],false); - } - content += '
    '; - content += '
    '; - content += '
    '; - if (rootelement) { - } else { - content += '
  • '; - } - } else { - content += '
  • '; - content += ''+item.text+''; - content += '
  • '; - } - return content; - }, - select : function(e) { - var t = e.target; - e.halt(); - this.currenttext = t.get('innerHTML'); - this.currentvalue = t.getAttribute('value'); - this.nodes.select.set('selectedIndex', this.currentvalue); - this.hide_menu(); - }, - handle_click : function(e) { - var target = e.target; - if (target.hasClass('smartselect_mask')) { - this.show_menu(e); - } else if (target.hasClass('selectable') || target.hasClass('smartselect_menuitem')) { - this.select(e); - } else if (target.hasClass('smartselect_menuitem_label') || target.hasClass('smartselect_submenuitem')) { - this.show_sub_menu(e); - } - }, - show_menu : function(e) { - e.halt(); - var menu = e.target.ancestor().one('.smartselect_menu'); - menu.addClass('visible'); - this.shownevent = Y.one(document.body).on('click', this.hide_menu, this); - }, - show_sub_menu : function(e) { - e.halt(); - var target = e.target; - if (!target.hasClass('smartselect_submenuitem')) { - target = target.ancestor('.smartselect_submenuitem'); - } - if (this.cfg.mode == 'compact' && target.one('.smartselect_submenu').hasClass('visible')) { - target.ancestor('ul').all('.smartselect_submenu.visible').removeClass('visible'); - return; - } - target.ancestor('ul').all('.smartselect_submenu.visible').removeClass('visible'); - target.one('.smartselect_submenu').addClass('visible'); - }, - hide_menu : function() { - this.nodes.menu.all('.visible').removeClass('visible'); - if (this.shownevent) { - this.shownevent.detach(); - } - } - }; - smartselect.init(Y, id, options, {select:select}); - }); +M.form.init_smartselect = function() { + throw new Error('M.form.init_smartselect can not be used any more.'); }; /** diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 2ab171133be..11e29ba9b37 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -4,6 +4,10 @@ information provided here is intended especially for developers. === 3.3 === * YUI module moodle-core-formautosubmit has been removed, use jquery .change() instead (see lib/templates/url_select.mustache for an example) +* $mform->init_javascript_enhancement() is deprecated and no longer does anything. Existing uses of smartselect enhancement + should be switched to the searchableselector form element or other solutions. + +>>>>>>> MDL-57471 forms: deprecate init_javascript_enhancement() === 3.2 === diff --git a/theme/boost/scss/moodle/core.scss b/theme/boost/scss/moodle/core.scss index d97e73d0c9f..c6690751eaa 100644 --- a/theme/boost/scss/moodle/core.scss +++ b/theme/boost/scss/moodle/core.scss @@ -886,106 +886,6 @@ tr.flagged-tag a { text-align: left; border: 0 solid black; } -/** -* Smart Select Element -*/ -.smartselect { - position: absolute; -} - -.smartselect .smartselect_mask { - background-color: #fff; -} - -.smartselect ul { - padding: 0; - margin: 0; -} - -.smartselect ul li { - list-style: none; -} - -.smartselect .smartselect_menu { - margin-right: 5px; -} - -.safari .smartselect .smartselect_menu { - margin-left: 2px; -} - -.smartselect .smartselect_menu, -.smartselect .smartselect_submenu { - border: 1px solid #000; - background-color: #fff; - display: none; -} - -.smartselect .smartselect_menu.visible, -.smartselect .smartselect_submenu.visible { - display: block; -} - -.smartselect .smartselect_menu_content ul li { - position: relative; - padding: 2px 5px; -} - -.smartselect .smartselect_menu_content ul li a { - color: #333; - text-decoration: none; -} - -.smartselect .smartselect_menu_content ul li a.selectable { - color: inherit; -} - -.smartselect .smartselect_submenuitem { - background-image: url([[pix:moodle|t/collapsed]]); - background-repeat: no-repeat; - background-position: 100%; -} -/** Spanning mode */ -.smartselect.spanningmenu .smartselect_submenu { - position: absolute; - top: -1px; - left: 100%; -} - -.smartselect.spanningmenu .smartselect_submenu a { - white-space: nowrap; - padding-right: 16px; -} - -.smartselect.spanningmenu .smartselect_menu_content ul li a.selectable:hover { - text-decoration: underline; -} -/** Compact mode */ -.smartselect.compactmenu .smartselect_submenu { - position: relative; - margin: 2px -3px; - margin-left: 10px; - display: none; - border-width: 0; - z-index: 1010; -} - -.smartselect.compactmenu .smartselect_submenu.visible { - display: block; -} - -.smartselect.compactmenu .smartselect_menu { - z-index: 1000; - overflow: hidden; -} - -.smartselect.compactmenu .smartselect_submenu .smartselect_submenu { - z-index: 1020; -} - -.smartselect.compactmenu .smartselect_submenuitem:hover > .smartselect_menuitem_label { - font-weight: bold; -} /** * Enrol diff --git a/theme/bootstrapbase/less/moodle/core.less b/theme/bootstrapbase/less/moodle/core.less index ea2ac8e9c58..bc20577399b 100644 --- a/theme/bootstrapbase/less/moodle/core.less +++ b/theme/bootstrapbase/less/moodle/core.less @@ -934,89 +934,7 @@ tr.flagged-tag a { text-align: left; border: 0 solid black; } -/** -* Smart Select Element -*/ -.smartselect { - position: absolute; -} -.smartselect .smartselect_mask { - background-color: #fff; -} -.smartselect ul { - padding: 0; - margin: 0; -} -.smartselect ul li { - list-style: none; -} -.smartselect .smartselect_menu { - margin-right: 5px; -} -.safari .smartselect .smartselect_menu { - margin-left: 2px; -} -.smartselect .smartselect_menu, -.smartselect .smartselect_submenu { - border: 1px solid #000; - background-color: #fff; - display: none; -} -.smartselect .smartselect_menu.visible, -.smartselect .smartselect_submenu.visible { - display: block; -} -.smartselect .smartselect_menu_content ul li { - position: relative; - padding: 2px 5px; -} -.smartselect .smartselect_menu_content ul li a { - color: #333; - text-decoration: none; -} -.smartselect .smartselect_menu_content ul li a.selectable { - color: inherit; -} -.smartselect .smartselect_submenuitem { - background-image: url([[pix:moodle|t/collapsed]]); - background-repeat: no-repeat; - background-position: 100%; -} -/** Spanning mode */ -.smartselect.spanningmenu .smartselect_submenu { - position: absolute; - top: -1px; - left: 100%; -} -.smartselect.spanningmenu .smartselect_submenu a { - white-space: nowrap; - padding-right: 16px; -} -.smartselect.spanningmenu .smartselect_menu_content ul li a.selectable:hover { - text-decoration: underline; -} -/** Compact mode */ -.smartselect.compactmenu .smartselect_submenu { - position: relative; - margin: 2px -3px; - margin-left: 10px; - display: none; - border-width: 0; - z-index: 1010; -} -.smartselect.compactmenu .smartselect_submenu.visible { - display: block; -} -.smartselect.compactmenu .smartselect_menu { - z-index: 1000; - overflow: hidden; -} -.smartselect.compactmenu .smartselect_submenu .smartselect_submenu { - z-index: 1020; -} -.smartselect.compactmenu .smartselect_submenuitem:hover > .smartselect_menuitem_label { - font-weight: bold; -} + /** * Registration */ diff --git a/theme/bootstrapbase/style/moodle.css b/theme/bootstrapbase/style/moodle.css index 677e3403027..d09a3c39a31 100644 --- a/theme/bootstrapbase/style/moodle.css +++ b/theme/bootstrapbase/style/moodle.css @@ -895,89 +895,6 @@ tr.flagged-tag a { border: 0 solid black; } /** -* Smart Select Element -*/ -.smartselect { - position: absolute; -} -.smartselect .smartselect_mask { - background-color: #fff; -} -.smartselect ul { - padding: 0; - margin: 0; -} -.smartselect ul li { - list-style: none; -} -.smartselect .smartselect_menu { - margin-right: 5px; -} -.safari .smartselect .smartselect_menu { - margin-left: 2px; -} -.smartselect .smartselect_menu, -.smartselect .smartselect_submenu { - border: 1px solid #000; - background-color: #fff; - display: none; -} -.smartselect .smartselect_menu.visible, -.smartselect .smartselect_submenu.visible { - display: block; -} -.smartselect .smartselect_menu_content ul li { - position: relative; - padding: 2px 5px; -} -.smartselect .smartselect_menu_content ul li a { - color: #333; - text-decoration: none; -} -.smartselect .smartselect_menu_content ul li a.selectable { - color: inherit; -} -.smartselect .smartselect_submenuitem { - background-image: url([[pix:moodle|t/collapsed]]); - background-repeat: no-repeat; - background-position: 100%; -} -/** Spanning mode */ -.smartselect.spanningmenu .smartselect_submenu { - position: absolute; - top: -1px; - left: 100%; -} -.smartselect.spanningmenu .smartselect_submenu a { - white-space: nowrap; - padding-right: 16px; -} -.smartselect.spanningmenu .smartselect_menu_content ul li a.selectable:hover { - text-decoration: underline; -} -/** Compact mode */ -.smartselect.compactmenu .smartselect_submenu { - position: relative; - margin: 2px -3px; - margin-left: 10px; - display: none; - border-width: 0; - z-index: 1010; -} -.smartselect.compactmenu .smartselect_submenu.visible { - display: block; -} -.smartselect.compactmenu .smartselect_menu { - z-index: 1000; - overflow: hidden; -} -.smartselect.compactmenu .smartselect_submenu .smartselect_submenu { - z-index: 1020; -} -.smartselect.compactmenu .smartselect_submenuitem:hover > .smartselect_menuitem_label { - font-weight: bold; -} -/** * Registration */ #page-admin-registration-register .registration_textfield {