Browse Source

Improved the recognition of bbcode attributes, now in the bbcode is possible to define what are the expected attributes and the code will be parsed accordingly

Signed-off-by: emanuele <[email protected]>
emanuele 12 years ago
parent
commit
ea7c535612

+ 1 - 1
Themes/default/GenericControls.template.php

@@ -47,7 +47,7 @@ function template_control_richedit($editor_id, $smileyContainer = null, $bbcCont
 
 						if (!bIsSource)
 							this.toggleTextMode();
-					alert(this.this.getWysiwygEditorValue());
+
 					}
 				};
 

+ 31 - 2
Themes/default/scripts/jquery.sceditor.bbcode.js

@@ -448,8 +448,33 @@
 						if(attrs.charAt(0) === "=")
 							attrs = "defaultAttr" + attrs;
 
-						while((matches = atribsRegex.exec(attrs)))
-							attrsMap[matches[1].toLowerCase()] = base.stripQuotes(matches[2]);
+						if (typeof base.bbcodes[bbcode].attrs == 'function')
+						{
+							var declaredAttrs = base.bbcodes[bbcode].attrs();
+							var attrArray = new Array;
+							var compatArray = new Array;
+							for (var i = 0; i < declaredAttrs.length; i++)
+							{
+								var attrPos = attrs.indexOf(declaredAttrs[i]);
+								if (attrPos != -1)
+								{
+									attrArray[attrPos] = [declaredAttrs[i], attrPos + declaredAttrs[i].length + 1];
+								}
+							}
+
+							for (var attrElem in attrArray)
+								compatArray.push(attrArray[attrElem]);
+							for (var i = 0; i < compatArray.length; i++)
+							{
+								if (typeof compatArray[i+1] != 'undefined')
+									attrsMap[compatArray[i][0].toLowerCase()] = attrs.substr(compatArray[i][1], attrs.indexOf(compatArray[i+1][0]) - compatArray[i][1]).trim();
+								else
+									attrsMap[compatArray[i][0].toLowerCase()] = attrs.substr(compatArray[i][1], attrs.length);
+							}
+						}
+						else
+							while((matches = atribsRegex.exec(attrs)))
+								attrsMap[matches[1].toLowerCase()] = base.stripQuotes(matches[2]);
 					}
 				}
 
@@ -983,6 +1008,9 @@
 
 				return '[quote' + author + date + link + ']' + content + '[/quote]';
 			},
+			attrs: function () {
+				return ['author', 'date', 'link'];
+			},
 			html: function(element, attrs, content) {
 				var author = '';
 				var sDate = '';
@@ -991,6 +1019,7 @@
 					author = bbc_quote_from + ': <author>' + attrs.author + '</author>';
 
 				// Links could be in the form: link=topic=71.msg201#msg201 that would fool javascript, so we need a workaround
+				// Probably no more necessary
 				for (var key in attrs)
 				{
 					if (key.substr(0, 4) == 'link' && attrs.hasOwnProperty(key))