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.
This commit is contained in:
Dan Poltawski 2016-12-20 15:06:05 +00:00
parent c4cf1c60f5
commit 2fa2ed50eb
6 changed files with 12 additions and 487 deletions

View File

@ -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);
}
/**

View File

@ -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 = '<div id="'+this.id+'_smart_select" class="smartselect">';
content += this.generate_submenu_content(this.structure[0], true);
content += '</ul></div>';
return content;
},
generate_submenu_content : function(item, rootelement) {
this.submenucount++;
var content = '';
if (item.children.length > 0) {
if (rootelement) {
content += '<div class="smartselect_mask" href="#ss_submenu'+this.submenucount+'">&nbsp;</div>';
content += '<div id="ss_submenu'+this.submenucount+'" class="smartselect_menu">';
content += '<div class="smartselect_menu_content">';
} else {
content += '<li class="smartselect_submenuitem">';
var categoryclass = (this.cfg.selectablecategories)?'selectable':'notselectable';
content += '<a class="smartselect_menuitem_label '+categoryclass+'" href="#ss_submenu'+this.submenucount+'" value="'+item.index+'">'+item.text+'</a>';
content += '<div id="ss_submenu'+this.submenucount+'" class="smartselect_submenu">';
content += '<div class="smartselect_submenu_content">';
}
content += '<ul>';
for (var i in item.children) {
content += this.generate_submenu_content(item.children[i],false);
}
content += '</ul>';
content += '</div>';
content += '</div>';
if (rootelement) {
} else {
content += '</li>';
}
} else {
content += '<li class="smartselect_menuitem">';
content += '<a class="smartselect_menuitem_content selectable" href="#" value="'+item.index+'">'+item.text+'</a>';
content += '</li>';
}
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.');
};
/**

View File

@ -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 ===

View File

@ -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

View File

@ -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
*/

View File

@ -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 {