MDL-57490 javascript-static: remove legacy functions

1) Some previous deprecations are removed to reduce the amount of
 code sent to the client
2) Other very-old functions are also sent to final deprecation

This is more agressive than our standard deprecation process, but with
the nature of this old js it seems the best way forward to reduce the
amount of obsolete js sent to clients.
This commit is contained in:
Dan Poltawski 2016-12-21 13:38:50 +00:00
parent 0ad39883b7
commit f8abbbe29e
2 changed files with 40 additions and 141 deletions

View File

@ -917,96 +917,53 @@ M.util.add_spinner = function(Y, node) {
return spinner;
}
//=== old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code ===
/**
* @deprecated since Moodle 3.3.
*/
function checkall() {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox') {
if (inputs[i].disabled || inputs[i].readOnly) {
continue;
}
inputs[i].checked = true;
}
}
}
function checknone() {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox') {
if (inputs[i].disabled || inputs[i].readOnly) {
continue;
}
inputs[i].checked = false;
}
}
throw new Error('checkall can not be used any more. Please use jQuery instead.');
}
/**
* Either check, or uncheck, all checkboxes inside the element with id is
* @param id the id of the container
* @param checked the new state, either '' or 'checked'.
* @deprecated since Moodle 3.3.
*/
function checknone() {
throw new Error('checknone can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function select_all_in_element_with_id(id, checked) {
var container = document.getElementById(id);
if (!container) {
return;
}
var inputs = container.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
inputs[i].checked = checked;
}
}
throw new Error('select_all_in_element_with_id can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function select_all_in(elTagName, elClass, elId) {
var inputs = document.getElementsByTagName('input');
inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elClass, elId);});
for(var i = 0; i < inputs.length; ++i) {
if(inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
inputs[i].checked = 'checked';
}
}
throw new Error('select_all_in can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function deselect_all_in(elTagName, elClass, elId) {
var inputs = document.getElementsByTagName('INPUT');
inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elClass, elId);});
for(var i = 0; i < inputs.length; ++i) {
if(inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
inputs[i].checked = '';
}
}
throw new Error('deselect_all_in can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function confirm_if(expr, message) {
if(!expr) {
return true;
}
return confirm(message);
throw new Error('confirm_if can not be used any more.');
}
/*
findParentNode (start, elementName, elementClass, elementID)
Travels up the DOM hierarchy to find a parent element with the
specified tag name, class, and id. All conditions must be met,
but any can be ommitted. Returns the BODY element if no match
found.
*/
/**
* @deprecated since Moodle 3.3.
*/
function findParentNode(el, elName, elClass, elId) {
while (el.nodeName.toUpperCase() != 'BODY') {
if ((!elName || el.nodeName.toUpperCase() == elName) &&
(!elClass || el.className.indexOf(elClass) != -1) &&
(!elId || el.id == elId)) {
break;
}
el = el.parentNode;
}
return el;
throw new Error('findParentNode can not be used any more. Please use jQuery instead.');
}
function unmaskPassword(id) {
@ -1052,15 +1009,11 @@ function unmaskPassword(id) {
}
}
/**
* @deprecated since Moodle 3.3.
*/
function filterByParent(elCollection, parentFinder) {
var filteredCollection = [];
for (var i = 0; i < elCollection.length; ++i) {
var findParent = parentFinder(elCollection[i]);
if (findParent.nodeName.toUpperCase() != 'BODY') {
filteredCollection.push(elCollection[i]);
}
}
return filteredCollection;
throw new Error('filterByParent can not be used any more. Please use jQuery instead.');
}
/**
@ -1274,10 +1227,11 @@ function convert_object_to_string(obj, separator) {
return list.join(separator);
}
/**
* @deprecated since Moodle 3.3.
*/
function stripHTML(str) {
var re = /<\S[^><]*>/g;
var ret = str.replace(re, "");
return ret;
throw new Error('stripHTML can not be used any more. Please use jQuery instead.');
}
function updateProgressBar(id, percent, msg, estimate) {
@ -1311,64 +1265,6 @@ function updateProgressBar(id, percent, msg, estimate) {
el.dispatchEvent(event);
}
// ===== Deprecated core Javascript functions for Moodle ====
// DO NOT USE!!!!!!!
// Do not put this stuff in separate file because it only adds extra load on servers!
/**
* @method show_item
* @deprecated since Moodle 2.7.
* @see Y.Node.show
*/
function show_item() {
throw new Error('show_item can not be used any more. Please use Y.Node.show.');
}
/**
* @method destroy_item
* @deprecated since Moodle 2.7.
* @see Y.Node.destroy
*/
function destroy_item() {
throw new Error('destroy_item can not be used any more. Please use Y.Node.destroy.');
}
/**
* @method hide_item
* @deprecated since Moodle 2.7.
* @see Y.Node.hide
*/
function hide_item() {
throw new Error('hide_item can not be used any more. Please use Y.Node.hide.');
}
/**
* @method addonload
* @deprecated since Moodle 2.7 - please do not use this function any more.
*/
function addonload() {
throw new Error('addonload can not be used any more.');
}
/**
* @method getElementsByClassName
* @deprecated Since Moodle 2.7 - please do not use this function any more.
* @see Y.one
* @see Y.all
*/
function getElementsByClassName() {
throw new Error('getElementsByClassName can not be used any more. Please use Y.one or Y.all.');
}
/**
* @method findChildNodes
* @deprecated since Moodle 2.7 - please do not use this function any more.
* @see Y.all
*/
function findChildNodes() {
throw new Error('findChildNodes can not be used any more. Please use Y.all.');
}
M.util.help_popups = {
setup : function(Y) {
Y.one('body').delegate('click', this.open_popup, 'a.helplinkpopup', this);

View File

@ -8,6 +8,9 @@ information provided here is intended especially for developers.
* $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.
* Return value of the validate_email() is now proper boolean as documented. Previously the function could return 1, 0 or false.
* Some outdated global JS functions have been removed and should be replaced with calls to jquery or alternative approaches:
checkall, checknone, select_all_in_element_with_id, select_all_in, deselect_all_in, confirm_if, findParentNode,
filterByParent, stripHTML
=== 3.2 ===