Skip to content
This repository
Browse code

Namespace the checkAll() function

  • Loading branch information...
commit d9ec6d3e15344727dc7453c4cce9137b634e8b2c 1 parent f5c536e
Rouven Weßling authored June 13, 2011
41  media/system/js/core-uncompressed.js
... ...
@@ -1,5 +1,5 @@
1 1
 /**
2  
- * @version		$Id: core-uncompressed.js 20196 2011-01-09 02:40:25Z ian $
  2
+ * @version		$Id: core-uncompressed.js 21463 2011-06-06 15:28:10Z dextercowley $
3 3
  * @copyright	Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
4 4
  * @license		GNU General Public License version 2 or later; see LICENSE.txt
5 5
  */
@@ -92,6 +92,39 @@ Joomla.isEmail = function(text) {
92 92
 };
93 93
 
94 94
 /**
  95
+ * USED IN: all list forms.
  96
+ *
  97
+ * Toggles the check state of a group of boxes
  98
+ *
  99
+ * Checkboxes must have an id attribute in the form cb0, cb1...
  100
+ *
  101
+ * @param	mixed	The number of box to 'check', for a checkbox element
  102
+ * @param	string	An alternative field name
  103
+ */
  104
+Joomla.checkAll = function(checkbox, stub) {
  105
+	if (!stub) {
  106
+		stub = 'cb';
  107
+	}
  108
+	if (checkbox.form) {
  109
+		var c = 0;
  110
+		for (var i = 0, n = checkbox.form.elements.length; i < n; i++) {
  111
+			var e = checkbox.form.elements[i];
  112
+			if (e.type == checkbox.type) {
  113
+				if ((stub && e.id.indexOf(stub) == 0) || !stub) {
  114
+					e.checked = checkbox.checked;
  115
+					c += (e.checked == true ? 1 : 0);
  116
+				}
  117
+			}
  118
+		}
  119
+		if (checkbox.form.boxchecked) {
  120
+			checkbox.form.boxchecked.value = c;
  121
+		}
  122
+		return true;
  123
+	}
  124
+	return false;
  125
+}
  126
+
  127
+/**
95 128
  * Render messages send via JSON
96 129
  *
97 130
  * @param	object
@@ -270,6 +303,8 @@ function getSelectedValue(frmName, srcListName) {
270 303
  *
271 304
  * @param	mixed	The number of box to 'check', for a checkbox element
272 305
  * @param	string	An alternative field name
  306
+ *
  307
+ * @deprecated	11.1 This function will be removed in a future version. Use Joomla.checkAll() instead.
273 308
  */
274 309
 function checkAll(checkbox, stub) {
275 310
 	if (!stub) {
@@ -369,6 +404,8 @@ function isChecked(isitchecked) {
369 404
 
370 405
 /**
371 406
  * Default function. Usually would be overriden by the component
  407
+ *
  408
+ * @deprecated	11.1 This function will be removed in a future version. Use Joomla.submitbutton() instead.
372 409
  */
373 410
 function submitbutton(pressbutton) {
374 411
 	submitform(pressbutton);
@@ -376,6 +413,8 @@ function submitbutton(pressbutton) {
376 413
 
377 414
 /**
378 415
  * Submit the admin form
  416
+ *
  417
+ * @deprecated	11.1 This function will be removed in a future version. Use Joomla.submitform() instead.
379 418
  */
380 419
 function submitform(pressbutton) {
381 420
 	if (pressbutton) {
1  media/system/js/core.js
@@ -3,6 +3,7 @@
3 3
 */
4 4
 if(typeof Joomla==="undefined")var Joomla={};Joomla.editors={};Joomla.editors.instances={};Joomla.submitform=function(a,b){if(typeof b==="undefined"&&(b=document.getElementById("adminForm"),!b))b=document.adminForm;if(typeof a!=="undefined")b.task.value=a;if(typeof b.onsubmit=="function")b.onsubmit();typeof b.fireEvent=="function"&&b.fireEvent("submit");b.submit()};Joomla.submitbutton=function(a){Joomla.submitform(a)};
5 5
 Joomla.JText={strings:{},_:function(a,b){return typeof this.strings[a.toUpperCase()]!=="undefined"?this.strings[a.toUpperCase()]:b},load:function(a){for(var b in a)this.strings[b.toUpperCase()]=a[b];return this}};Joomla.replaceTokens=function(a){for(var b=document.getElementsByTagName("input"),c=0;c<b.length;c++)if(b[c].type=="hidden"&&b[c].name.length==32&&b[c].value=="1")b[c].name=a};Joomla.isEmail=function(a){return/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/.test(a)};
  6
+Joomla.checkAll=function(a,b){b||(b="cb");if(a.form){for(var c=0,d=0,f=a.form.elements.length;d<f;d++){var e=a.form.elements[d];if(e.type==a.type&&(b&&e.id.indexOf(b)==0||!b))e.checked=a.checked,c+=e.checked==!0?1:0}if(a.form.boxchecked)a.form.boxchecked.value=c;return!0}return!1};
6 7
 Joomla.renderMessages=function(a){var b=document.id("system-message-container");$$("#system-message-container > *").destroy();var c=new Element("dl",{id:"system-message"});Object.each(a,function(a,b){(new Element("dt",{"class":b,html:b})).inject(c);var e=new Element("dd",{"class":b});e.addClass("message");var g=new Element("ul");Array.each(a,function(a){(new Element("li",{html:a})).inject(g)},this);g.inject(e);e.inject(c)},this);c.inject(b)};
7 8
 function writeDynaList(a,b,c,d,f){var a="\n\t<select "+a+">",e=0;for(x in b){if(b[x][0]==c){var g="";if(d==c&&f==b[x][1]||e==0&&d!=c)g='selected="selected"';a+='\n\t\t<option value="'+b[x][1]+'" '+g+">"+b[x][2]+"</option>"}e++}a+="\n\t</select>";document.writeln(a)}
8 9
 function changeDynaList(a,b,c,d,f){a=document.adminForm[a];for(i in a.options.length)a.options[i]=null;i=0;for(x in b)if(b[x][0]==c){opt=new Option;opt.value=b[x][1];opt.text=b[x][2];if(d==c&&f==opt.value||i==0)opt.selected=!0;a.options[i++]=opt}a.length=i}function radioGetCheckedValue(a){if(!a)return"";var b=a.length;if(b==void 0)return a.checked?a.value:"";for(var c=0;c<b;c++)if(a[c].checked)return a[c].value;return""}

0 notes on commit d9ec6d3

Please sign in to comment.
Something went wrong with that request. Please try again.