Commit f8abbbe2 authored by Dan Poltawski's avatar Dan Poltawski
Browse files

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.
parent 0ad39883
...@@ -917,96 +917,53 @@ M.util.add_spinner = function(Y, node) { ...@@ -917,96 +917,53 @@ M.util.add_spinner = function(Y, node) {
return spinner; 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() { function checkall() {
var inputs = document.getElementsByTagName('input'); throw new Error('checkall can not be used any more. Please use jQuery instead.');
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;
}
}
} }
/**
* @deprecated since Moodle 3.3.
*/
function checknone() { function checknone() {
var inputs = document.getElementsByTagName('input'); throw new Error('checknone can not be used any more. Please use jQuery instead.');
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;
}
}
} }
/** /**
* Either check, or uncheck, all checkboxes inside the element with id is * @deprecated since Moodle 3.3.
* @param id the id of the container
* @param checked the new state, either '' or 'checked'.
*/ */
function select_all_in_element_with_id(id, checked) { function select_all_in_element_with_id(id, checked) {
var container = document.getElementById(id); throw new Error('select_all_in_element_with_id can not be used any more. Please use jQuery instead.');
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;
}
}
} }
/**
* @deprecated since Moodle 3.3.
*/
function select_all_in(elTagName, elClass, elId) { function select_all_in(elTagName, elClass, elId) {
var inputs = document.getElementsByTagName('input'); throw new Error('select_all_in can not be used any more. Please use jQuery instead.');
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';
}
}
} }
/**
* @deprecated since Moodle 3.3.
*/
function deselect_all_in(elTagName, elClass, elId) { function deselect_all_in(elTagName, elClass, elId) {
var inputs = document.getElementsByTagName('INPUT'); throw new Error('deselect_all_in can not be used any more. Please use jQuery instead.');
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 = '';
}
}
} }
/**
* @deprecated since Moodle 3.3.
*/
function confirm_if(expr, message) { function confirm_if(expr, message) {
if(!expr) { throw new Error('confirm_if can not be used any more.');
return true;
}
return confirm(message);
} }
/**
/* * @deprecated since Moodle 3.3.
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.
*/
function findParentNode(el, elName, elClass, elId) { function findParentNode(el, elName, elClass, elId) {
while (el.nodeName.toUpperCase() != 'BODY') { throw new Error('findParentNode can not be used any more. Please use jQuery instead.');
if ((!elName || el.nodeName.toUpperCase() == elName) &&
(!elClass || el.className.indexOf(elClass) != -1) &&
(!elId || el.id == elId)) {
break;
}
el = el.parentNode;
}
return el;
} }
function unmaskPassword(id) { function unmaskPassword(id) {
...@@ -1052,15 +1009,11 @@ function unmaskPassword(id) { ...@@ -1052,15 +1009,11 @@ function unmaskPassword(id) {
} }
} }
/**
* @deprecated since Moodle 3.3.
*/
function filterByParent(elCollection, parentFinder) { function filterByParent(elCollection, parentFinder) {
var filteredCollection = []; throw new Error('filterByParent can not be used any more. Please use jQuery instead.');
for (var i = 0; i < elCollection.length; ++i) {
var findParent = parentFinder(elCollection[i]);
if (findParent.nodeName.toUpperCase() != 'BODY') {
filteredCollection.push(elCollection[i]);
}
}
return filteredCollection;
} }
/** /**
...@@ -1274,10 +1227,11 @@ function convert_object_to_string(obj, separator) { ...@@ -1274,10 +1227,11 @@ function convert_object_to_string(obj, separator) {
return list.join(separator); return list.join(separator);
} }
/**
* @deprecated since Moodle 3.3.
*/
function stripHTML(str) { function stripHTML(str) {
var re = /<\S[^><]*>/g; throw new Error('stripHTML can not be used any more. Please use jQuery instead.');
var ret = str.replace(re, "");
return ret;
} }
function updateProgressBar(id, percent, msg, estimate) { function updateProgressBar(id, percent, msg, estimate) {
...@@ -1311,64 +1265,6 @@ function updateProgressBar(id, percent, msg, estimate) { ...@@ -1311,64 +1265,6 @@ function updateProgressBar(id, percent, msg, estimate) {
el.dispatchEvent(event); 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 = { M.util.help_popups = {
setup : function(Y) { setup : function(Y) {
Y.one('body').delegate('click', this.open_popup, 'a.helplinkpopup', this); Y.one('body').delegate('click', this.open_popup, 'a.helplinkpopup', this);
......
...@@ -8,6 +8,9 @@ information provided here is intended especially for developers. ...@@ -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 * $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. 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. * 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 === === 3.2 ===
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment