Skip to content
This repository
Browse code

Modify JDocumentRendererMessage to always render <div id="system-mess…

…age-container"></div>. This makes it possible to render messages via JavaScript.

Added Joomla.renderMessages() to core.js. This functions enabled rendering messages via JavaScript.
  • Loading branch information...
commit bade3acf0f5ea588be92cb24d4237228c043a3c7 1 parent c323ebe
Rouven Weßling authored May 20, 2011
18  libraries/joomla/document/html/renderer/message.php
@@ -36,8 +36,7 @@ public function render($name, $params = array (), $content = null)
36 36
 		$messages = JFactory::getApplication()->getMessageQueue();
37 37
 
38 38
 		// Build the sorted message list
39  
-		if (is_array($messages) && count($messages))
40  
-		{
  39
+		if (is_array($messages) && !empty($messages)) {
41 40
 			foreach ($messages as $msg)
42 41
 			{
43 42
 				if (isset($msg['type']) && isset($msg['message'])) {
@@ -46,19 +45,20 @@ public function render($name, $params = array (), $content = null)
46 45
 			}
47 46
 		}
48 47
 
  48
+		// Build the return string
  49
+		$buffer .= "\n<div id=\"system-message-container\">";
  50
+
49 51
 		// If messages exist render them
50  
-		if (is_array($lists))
51  
-		{
52  
-			// Build the return string
  52
+		if (is_array($lists)) {
53 53
 			$buffer .= "\n<dl id=\"system-message\">";
54 54
 			foreach ($lists as $type => $msgs)
55 55
 			{
56  
-			if (count($msgs))
57  
-				{
  56
+				if (count($msgs)) {
58 57
 					$buffer .= "\n<dt class=\"".strtolower($type)."\">".JText::_($type)."</dt>";
59 58
 					$buffer .= "\n<dd class=\"".strtolower($type)." message\">";
60 59
 					$buffer .= "\n\t<ul>";
61  
-					foreach ($msgs as $msg) {
  60
+					foreach ($msgs as $msg)
  61
+					{
62 62
 						$buffer .="\n\t\t<li>".$msg."</li>";
63 63
 					}
64 64
 					$buffer .= "\n\t</ul>";
@@ -67,6 +67,8 @@ public function render($name, $params = array (), $content = null)
67 67
 			}
68 68
 			$buffer .= "\n</dl>";
69 69
 		}
  70
+
  71
+		$buffer .= "\n</div>";
70 72
 		return $buffer;
71 73
 	}
72 74
 }
37  media/system/js/core-uncompressed.js
@@ -92,6 +92,43 @@ Joomla.isEmail = function(text) {
92 92
 };
93 93
 
94 94
 /**
  95
+ * Render messages send via JSON
  96
+ *
  97
+ * @param	object
  98
+ * @return	void
  99
+ */
  100
+Joomla.renderMessages = function(messages) {
  101
+	var container = document.id('system-message-container');
  102
+	var children = $$('#system-message-container > *');
  103
+	children.destroy();
  104
+	var dl = new Element('dl', {
  105
+		id: 'system-message'
  106
+	});
  107
+	Object.each(messages, function (item, type) {
  108
+		var dt = new Element('dt', {
  109
+			'class': type,
  110
+			html: type
  111
+		});
  112
+		dt.inject(dl);
  113
+		var dd = new Element('dd', {
  114
+			'class': type
  115
+		});
  116
+		dd.addClass('message');
  117
+		var list = new Element('ul');
  118
+
  119
+		Array.each(item, function (item, index, object) {
  120
+			var li = new Element('li', {
  121
+				html: item
  122
+			});
  123
+			li.inject(list);
  124
+		}, this);
  125
+		list.inject(dd);
  126
+		dd.inject(dl);
  127
+	}, this);
  128
+	dl.inject(container);
  129
+};
  130
+
  131
+/**
95 132
  * USED IN: administrator/components/com_modules/views/module/tmpl/default.php
96 133
  *
97 134
  * Writes a dynamically generated list
14  media/system/js/core.js
... ...
@@ -1 +1,13 @@
1  
-if(typeof(Joomla)==="undefined"){var Joomla={}}Joomla.editors={};Joomla.editors.instances={};Joomla.submitform=function(a,b){if(typeof(b)==="undefined"){b=document.getElementById("adminForm");if(!b){b=document.adminForm}}if(typeof(a)!=="undefined"){b.task.value=a}if(typeof b.onsubmit=="function"){b.onsubmit()}if(typeof b.fireEvent=="function"){b.fireEvent("submit")}b.submit()};Joomla.submitbutton=function(a){Joomla.submitform(a)};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(c){var b=document.getElementsByTagName("input");for(var a=0;a<b.length;a++){if((b[a].type=="hidden")&&(b[a].name.length==32)&&b[a].value=="1"){b[a].name=c}}};Joomla.isEmail=function(b){var a=new RegExp("^[\\w-_.]*[\\w-_.]@[\\w].+[\\w]+[\\w]$");return a.test(b)};function writeDynaList(e,g,d,h,a){var c="\n	<select "+e+">";var b=0;for(x in g){if(g[x][0]==d){var f="";if((h==d&&a==g[x][1])||(b==0&&h!=d)){f='selected="selected"'}c+='\n		<option value="'+g[x][1]+'" '+f+">"+g[x][2]+"</option>"}b++}c+="\n	</select>";document.writeln(c)}function changeDynaList(c,e,b,f,a){var d=document.adminForm[c];for(i in d.options.length){d.options[i]=null}i=0;for(x in e){if(e[x][0]==b){opt=new Option();opt.value=e[x][1];opt.text=e[x][2];if((f==b&&a==opt.value)||i==0){opt.selected=true}d.options[i++]=opt}}d.length=i}function radioGetCheckedValue(b){if(!b){return""}var c=b.length;if(c==undefined){if(b.checked){return b.value}else{return""}}for(var a=0;a<c;a++){if(b[a].checked){return b[a].value}}return""}function getSelectedValue(b,a){var c=document[b];var d=c[a];i=d.selectedIndex;if(i!=null&&i>-1){return d.options[i].value}else{return null}}function checkAll(h,b){if(!b){b="cb"}if(h.form){var m=0;for(var g=0,a=h.form.elements.length;g<a;g++){var l=h.form.elements[g];if(l.type==h.type){if((b&&l.id.indexOf(b)==0)||!b){l.checked=h.checked;m+=(l.checked==true?1:0)}}}if(h.form.boxchecked){h.form.boxchecked.value=m}return true}else{var j=document.adminForm;var m=j.toggle.checked;var a=h;var k=0;for(var g=0;g<a;g++){var d=j[b+""+g];if(d){d.checked=m;k++}}if(m){document.adminForm.boxchecked.value=k}else{document.adminForm.boxchecked.value=0}}}function listItemTask(g,b){var d=document.adminForm;var a=d[g];if(a){for(var c=0;true;c++){var e=d["cb"+c];if(!e){break}e.checked=false}a.checked=true;d.boxchecked.value=1;submitbutton(b)}return false}function isChecked(a){if(a==true){document.adminForm.boxchecked.value++}else{document.adminForm.boxchecked.value--}}function submitbutton(a){submitform(a)}function submitform(a){if(a){document.adminForm.task.value=a}if(typeof document.adminForm.onsubmit=="function"){document.adminForm.onsubmit()}if(typeof document.adminForm.fireEvent=="function"){document.adminForm.fireEvent("submit")}document.adminForm.submit()}function popupWindow(g,e,b,d,a){var c=(screen.width-b)/2;var f=(screen.height-d)/2;winprops="height="+d+",width="+b+",top="+f+",left="+c+",scrollbars="+a+",resizable";win=window.open(g,e,winprops);if(parseInt(navigator.appVersion)>=4){win.window.focus()}}function tableOrdering(a,c,b){var d=document.adminForm;d.filter_order.value=a;d.filter_order_Dir.value=c;submitform(b)}function saveorder(b,a){checkAll_button(b,a)}function checkAll_button(d,a){if(!a){a="saveorder"}for(var b=0;b<=d;b++){var c=document.adminForm["cb"+b];if(c){if(c.checked==false){c.checked=true}}else{alert("You cannot change the order of items, as an item in the list is `Checked Out`");return}}submitform(a)};
  1
+/*
  2
+		GNU General Public License version 2 or later; see LICENSE.txt
  3
+*/
  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
+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.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
+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
+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""}
  9
+function getSelectedValue(a,b){var c=document[a][b];i=c.selectedIndex;return i!=null&&i>-1?c.options[i].value:null}
  10
+function checkAll(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}else{for(var e=document.adminForm,c=e.toggle.checked,f=a,g=0,d=0;d<f;d++){var h=e[b+""+d];if(h)h.checked=c,g++}document.adminForm.boxchecked.value=c?g:0}}
  11
+function listItemTask(a,b){var c=document.adminForm,d=c[a];if(d){for(var f=0;;f++){var e=c["cb"+f];if(!e)break;e.checked=!1}d.checked=!0;c.boxchecked.value=1;submitbutton(b)}return!1}function isChecked(a){a==!0?document.adminForm.boxchecked.value++:document.adminForm.boxchecked.value--}function submitbutton(a){submitform(a)}
  12
+function submitform(a){if(a)document.adminForm.task.value=a;if(typeof document.adminForm.onsubmit=="function")document.adminForm.onsubmit();typeof document.adminForm.fireEvent=="function"&&document.adminForm.fireEvent("submit");document.adminForm.submit()}function popupWindow(a,b,c,d,f){winprops="height="+d+",width="+c+",top="+(screen.height-d)/2+",left="+(screen.width-c)/2+",scrollbars="+f+",resizable";win=window.open(a,b,winprops);parseInt(navigator.appVersion)>=4&&win.window.focus()}
  13
+function tableOrdering(a,b,c){var d=document.adminForm;d.filter_order.value=a;d.filter_order_Dir.value=b;submitform(c)}function saveorder(a,b){checkAll_button(a,b)}function checkAll_button(a,b){b||(b="saveorder");for(var c=0;c<=a;c++){var d=document.adminForm["cb"+c];if(d){if(d.checked==!1)d.checked=!0}else{alert("You cannot change the order of items, as an item in the list is `Checked Out`");return}}submitform(b)};

0 notes on commit bade3ac

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