Browse Source

Enabled all the SMF standard buttons (with relative icons) + Fixed (again) the preview

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

+ 80 - 27
Sources/Subs-Editor.php

@@ -1525,28 +1525,28 @@ function create_control_richedit($editorOptions)
 		$context['bbc_tags'][] = array(
 			array(
 				'image' => 'bold',
-				'code' => 'b',
+				'code' => 'bold',
 				'before' => '[b]',
 				'after' => '[/b]',
 				'description' => $txt['bold'],
 			),
 			array(
 				'image' => 'italicize',
-				'code' => 'i',
+				'code' => 'italic',
 				'before' => '[i]',
 				'after' => '[/i]',
 				'description' => $txt['italic'],
 			),
 			array(
 				'image' => 'underline',
-				'code' => 'u',
+				'code' => 'uunderline',
 				'before' => '[u]',
 				'after' => '[/u]',
 				'description' => $txt['underline']
 			),
 			array(
 				'image' => 'strike',
-				'code' => 's',
+				'code' => 'strike',
 				'before' => '[s]',
 				'after' => '[/s]',
 				'description' => $txt['strike']
@@ -1591,14 +1591,14 @@ function create_control_richedit($editorOptions)
 			),
 			array(
 				'image' => 'img',
-				'code' => 'img',
+				'code' => 'image',
 				'before' => '[img]',
 				'after' => '[/img]',
 				'description' => $txt['image']
 			),
 			array(
 				'image' => 'url',
-				'code' => 'url',
+				'code' => 'link',
 				'before' => '[url]',
 				'after' => '[/url]',
 				'description' => $txt['hyperlink']
@@ -1642,14 +1642,14 @@ function create_control_richedit($editorOptions)
 			array(),
 			array(
 				'image' => 'sup',
-				'code' => 'sup',
+				'code' => 'superscript',
 				'before' => '[sup]',
 				'after' => '[/sup]',
 				'description' => $txt['superscript']
 			),
 			array(
 				'image' => 'sub',
-				'code' => 'sub',
+				'code' => 'subscript',
 				'before' => '[sub]',
 				'after' => '[/sub]',
 				'description' => $txt['subscript']
@@ -1686,21 +1686,21 @@ function create_control_richedit($editorOptions)
 			array(),
 			array(
 				'image' => 'list',
-				'code' => 'list',
+				'code' => 'bulletlist',
 				'before' => '[list]\n[li]',
 				'after' => '[/li]\n[li][/li]\n[/list]',
 				'description' => $txt['list_unordered']
 			),
 			array(
 				'image' => 'orderlist',
-				'code' => 'orderlist',
+				'code' => 'orderedlist',
 				'before' => '[list type=decimal]\n[li]',
 				'after' => '[/li]\n[li][/li]\n[/list]',
 				'description' => $txt['list_ordered']
 			),
 			array(
 				'image' => 'hr',
-				'code' => 'hr',
+				'code' => 'horizontalrule',
 				'before' => '[hr]',
 				'description' => $txt['horizontal_rule']
 			),
@@ -1727,8 +1727,76 @@ function create_control_richedit($editorOptions)
 			);
 		}
 
+		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
+		$disabled_tags = array();
+		if (!empty($modSettings['disabledBBC']))
+			$disabled_tags = explode(',', $modSettings['disabledBBC']);
+		if (empty($modSettings['enableEmbeddedFlash']))
+			$disabled_tags[] = 'flash';
+
+		foreach ($disabled_tags as $tag)
+		{
+			if ($tag == 'list')
+				$context['disabled_tags']['orderlist'] = true;
+
+			$context['disabled_tags'][trim($tag)] = true;
+		}
+
+		$context['html_headers'] .= '
+		<style type="text/css">';
+		$context['bbc_toolbar'] = array();
 		foreach ($context['bbc_tags'] as $row => $tagRow)
-			$context['bbc_tags'][$row][count($tagRow) - 1]['isLast'] = true;
+		{
+			if (!isset($context['bbc_toolbar'][$row]))
+				$context['bbc_toolbar'][$row] = array();
+			$tagsRow = array();
+			foreach ($tagRow as $tag)
+			{
+			 if (!empty($tag))
+			 {
+					if (empty($context['disabled_tags'][$tag['code']]))
+					{
+						$tagsRow[] = $tag['code']; 
+						$context['html_headers'] .= '
+			.sceditor-button-' . $tag['code'] . ' div {
+				background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\');
+			}';
+					}
+				}
+				else
+				{
+					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
+					$tagsRow = array();
+				}
+			}
+
+			if ($row == 0)
+			{
+				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
+				$tagsRow = array();
+				if (!isset($context['disabled_tags']['font']))
+					$tagsRow[] = 'font';
+				if (!isset($context['disabled_tags']['size']))
+					$tagsRow[] = 'size';
+				if (!isset($context['disabled_tags']['color']))
+					$tagsRow[] = 'color';
+			}
+			elseif ($row == 1)
+			{
+				$tmp = array();
+				$tagsRow[] = 'removeformat';
+				$tagsRow[] = 'source';
+				if (!empty($tmp))
+				{
+					$tagsRow[] = '|' . implode(',', $tmp);
+				}
+			}
+
+			if (!empty($tagsRow))
+				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
+		}
+		$context['html_headers'] .= '
+		</style>';
 	}
 
 	// Initialize smiley array... if not loaded before.
@@ -1867,21 +1935,6 @@ function create_control_richedit($editorOptions)
 	// Set a flag so the sub template knows what to do...
 	$context['show_bbc'] = !empty($modSettings['enableBBC']) && !empty($settings['show_bbc']);
 
-	// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
-	$disabled_tags = array();
-	if (!empty($modSettings['disabledBBC']))
-		$disabled_tags = explode(',', $modSettings['disabledBBC']);
-	if (empty($modSettings['enableEmbeddedFlash']))
-		$disabled_tags[] = 'flash';
-
-	foreach ($disabled_tags as $tag)
-	{
-		if ($tag == 'list')
-			$context['disabled_tags']['orderlist'] = true;
-
-		$context['disabled_tags'][trim($tag)] = true;
-	}
-
 	// Switch the URLs back... now we're back to whatever the main sub template is.  (like folder in PersonalMessage.)
 	if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template']))
 	{

+ 79 - 222
Themes/default/GenericControls.template.php

@@ -54,6 +54,8 @@ function template_control_richedit($editor_id, $smileyContainer = null, $bbcCont
 							var current_value = this.getTextareaValue(false);
 						else
 							var current_value = this.getWysiwygEditorValue();
+
+						return current_value;
 					},
 					appendEmoticon: function (code, emoticon) {
 						if (code == \'\')
@@ -155,6 +157,69 @@ function template_control_richedit($editor_id, $smileyContainer = null, $bbcCont
 			})(jQuery);
 
 			$(document).ready(function() {
+				$.sceditor.setCommand(
+					\'ftp\',
+					function (caller) {
+						var	editor  = this,
+							content = $(this._(\'<form><div><label for="link">{0}</label> <input type="text" id="link" value="ftp://" /></div>\' +
+									\'<div><label for="des">{1}</label> <input type="text" id="des" value="" /></div></form>\',
+								this._("URL:"),
+								this._("Description (optional):")
+							))
+							.submit(function () {return false;});
+
+						content.append($(
+							this._(\'<div><input type="button" class="button" value="{0}" /></div>\',
+								this._("Insert")
+							)).click(function (e) {
+							var val = $(this).parent("form").find("#link").val(),
+								description = $(this).parent("form").find("#des").val();
+
+							if(val !== "" && val !== "ftp://") {
+								// needed for IE to reset the last range
+								editor.focus();
+
+								if(!editor.getRangeHelper().selectedHtml() || description)
+								{
+									if(!description)
+										description = val;
+									
+									editor.wysiwygEditorInsertHtml(\'<a href="\' + val + \'">\' + description + \'</a>\');
+								}
+								else
+									editor.execCommand("createlink", val);
+							}
+
+							editor.closeDropDown(true);
+							e.preventDefault();
+						}));
+
+						editor.createDropDown(caller, "insertlink", content);
+					},
+					', javaScriptEscape($txt['ftp']), '
+				);
+				$.sceditor.setCommand(
+					\'glow\',
+					function () {
+						this.wysiwygEditorInsertText(\'[glow=red,2,300][/glow]\');
+					},
+					', javaScriptEscape($txt['glow']), '
+				);
+				$.sceditor.setCommand(
+					\'shadow\',
+					function () {
+						this.wysiwygEditorInsertText(\'[shadow=red,left][/shadow]\');
+					},
+					', javaScriptEscape($txt['shadow']), '
+				);
+				$.sceditor.setCommand(
+					\'tt\',
+					function () {
+						this.wysiwygEditorInsertHtml(\'<tt>\', \'</tt>\');
+					},
+					', javaScriptEscape($txt['teletype']), '
+				);
+
 				$("#', $editor_id, '").sceditorBBCodePlugin({
 					style: "', $settings['default_theme_url'], '/css/jquery.sceditor.default.css",
 					emoticonsCompat: true,
@@ -196,232 +261,24 @@ function template_control_richedit($editor_id, $smileyContainer = null, $bbcCont
 			}
 			echo '
 					}';
+		}
 
-/*
-emoticons:
-{
-    // emoticons to be included in the dropdown
-    dropdown: {
-        ":)": "emoticons/smile.png",
-        ":angel:": "emoticons/angel.png"
-    },
-    // emoticons to be included in the more section
-    more: {
-        ":alien:": "emoticons/alien.png",
-        ":blink:": "emoticons/blink.png"
-    },
-    // emoticons that are not shwon in the dropdown but will be converted ATY
-    hidden: {
-        ":aliasforalien:": "emoticons/alien.png",
-        ":aliasforblink:": "emoticons/blink.png"
-    }
-},*/
+		if ($context['show_bbc'] && $bbcContainer !== null)
+		{
+			echo ',
+					toolbar: "';
+			$count_tags = count($context['bbc_tags']);
+			foreach ($context['bbc_toolbar'] as $i => $buttonRow)
+			{
+				echo implode('|', $buttonRow);
+				$count_tags--;
+				if (!empty($count_tags))
+					echo '||';
+			}
 
+			echo '",';
 		}
 /*
-		// Show the smileys.
-// 		if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
-// 		{
-// 			echo '
-// 				var oSmileyBox_', $editor_id, ' = new smc_SmileyBox({
-// 					sUniqueId: ', JavaScriptEscape('smileyBox_' . $editor_id), ',
-// 					sContainerDiv: ', JavaScriptEscape($smileyContainer), ',
-// 					sClickHandler: ', JavaScriptEscape('oEditorHandle_' . $editor_id . '.insertSmiley'), ',
-// 					oSmileyLocations: {';
-// 
-// 			foreach ($context['smileys'] as $location => $smileyRows)
-// 			{
-// 				echo '
-// 						', $location, ': [';
-// 				foreach ($smileyRows as $smileyRow)
-// 				{
-// 					echo '
-// 							[';
-// 					foreach ($smileyRow['smileys'] as $smiley)
-// 						echo '
-// 								{
-// 									sCode: ', JavaScriptEscape($smiley['code']), ',
-// 									sSrc: ', JavaScriptEscape($settings['smileys_url'] . '/' . $smiley['filename']), ',
-// 									sDescription: ', JavaScriptEscape($smiley['description']), '
-// 								}', empty($smiley['isLast']) ? ',' : '';
-// 
-// 				echo '
-// 							]', empty($smileyRow['isLast']) ? ',' : '';
-// 				}
-// 				echo '
-// 						]', $location === 'postform' ? ',' : '';
-// 			}
-// 			echo '
-// 					},
-// 					sSmileyBoxTemplate: ', JavaScriptEscape('
-// 						%smileyRows% %moreSmileys%
-// 					'), ',
-// 					sSmileyRowTemplate: ', JavaScriptEscape('
-// 						<div>%smileyRow%</div>
-// 					'), ',
-// 					sSmileyTemplate: ', JavaScriptEscape('
-// 						<img src="%smileySource%" align="bottom" alt="%smileyDescription%" title="%smileyDescription%" id="%smileyId%" />
-// 					'), ',
-// 					sMoreSmileysTemplate: ', JavaScriptEscape('
-// 						<a href="#" id="%moreSmileysId%">[' . (!empty($context['smileys']['postform']) ? $txt['more_smileys'] : $txt['more_smileys_pick']) . ']</a>
-// 					'), ',
-// 					sMoreSmileysLinkId: ', JavaScriptEscape('moreSmileys_' . $editor_id), ',
-// 					sMoreSmileysPopupTemplate: ', JavaScriptEscape('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-// 						<html>
-// 							<head>
-// 								<title>' . $txt['more_smileys_title'] . '</title>
-// 								<link rel="stylesheet" type="text/css" href="' . $settings['theme_url'] . '/css/index' . $context['theme_variant'] . '.css?alp21" />
-// 							</head>
-// 							<body id="help_popup">
-// 								<div class="padding windowbg">
-// 									<div class="cat_bar">
-// 										<h3 class="catbg">
-// 											' . $txt['more_smileys_pick'] . '
-// 										</h3>
-// 									</div>
-// 									<div class="padding">
-// 										%smileyRows%
-// 									</div>
-// 									<div class="smalltext centertext">
-// 										<a href="#" id="%moreSmileysCloseLinkId%">' . $txt['more_smileys_close_window'] . '</a>
-// 									</div>
-// 								</div>
-// 							</body>
-// 						</html>'), '
-// 				});';
-// 		}
-*/ /*
-// 		if ($context['show_bbc'] && $bbcContainer !== null)
-// 		{
-// 			echo '
-// 				var oBBCBox_', $editor_id, ' = new smc_BBCButtonBox({
-// 					sUniqueId: ', JavaScriptEscape('BBCBox_' . $editor_id), ',
-// 					sContainerDiv: ', JavaScriptEscape($bbcContainer), ',
-// 					sButtonClickHandler: ', JavaScriptEscape('oEditorHandle_' . $editor_id . '.handleButtonClick'), ',
-// 					sSelectChangeHandler: ', JavaScriptEscape('oEditorHandle_' . $editor_id . '.handleSelectChange'), ',
-// 					aButtonRows: [';
-// 
-// 			// Here loop through the array, printing the images/rows/separators!
-// 			foreach ($context['bbc_tags'] as $i => $buttonRow)
-// 			{
-// 				echo '
-// 						[';
-// 				foreach ($buttonRow as $tag)
-// 				{
-// 					// Is there a "before" part for this bbc button? If not, it can't be a button!!
-// 					if (isset($tag['before']))
-// 						echo '
-// 							{
-// 								sType: \'button\',
-// 								bEnabled: ', empty($context['disabled_tags'][$tag['code']]) ? 'true' : 'false', ',
-// 								sImage: ', file_exists($settings['theme_dir'] . '/images/bbc/' . $tag['image'] . '.png') ? JavaScriptEscape($settings['images_url'] . '/bbc/' . $tag['image'] . '.png') : JavaScriptEscape($settings['images_url'] . '/bbc/' . $tag['image'] . '.gif'), ',
-// 								sCode: ', JavaScriptEscape($tag['code']), ',
-// 								sBefore: ', JavaScriptEscape($tag['before']), ',
-// 								sAfter: ', isset($tag['after']) ? JavaScriptEscape($tag['after']) : 'null', ',
-// 								sDescription: ', JavaScriptEscape($tag['description']), '
-// 							}', empty($tag['isLast']) ? ',' : '';
-// 
-// 					// Must be a divider then.
-// 					else
-// 						echo '
-// 							{
-// 								sType: \'divider\'
-// 							}', empty($tag['isLast']) ? ',' : '';
-// 				}
-// 
-// 				// Add the select boxes to the first row.
-// 				if ($i == 0)
-// 				{
-// 					// Show the font drop down...
-// 					if (!isset($context['disabled_tags']['font']))
-// 						echo ',
-// 							{
-// 								sType: \'select\',
-// 								sName: \'sel_face\',
-// 								oOptions: {
-// 									\'\': ', JavaScriptEscape($txt['font_face']), ',
-// 									\'courier\': \'Courier\',
-// 									\'arial\': \'Arial\',
-// 									\'arial black\': \'Arial Black\',
-// 									\'impact\': \'Impact\',
-// 									\'verdana\': \'Verdana\',
-// 									\'times new roman\': \'Times New Roman\',
-// 									\'georgia\': \'Georgia\',
-// 									\'andale mono\': \'Andale Mono\',
-// 									\'trebuchet ms\': \'Trebuchet MS\',
-// 									\'comic sans ms\': \'Comic Sans MS\'
-// 								}
-// 							}';
-// 
-// 					// Font sizes anyone?
-// 					if (!isset($context['disabled_tags']['size']))
-// 						echo ',
-// 							{
-// 								sType: \'select\',
-// 								sName: \'sel_size\',
-// 								oOptions: {
-// 									\'\': ', JavaScriptEscape($txt['font_size']), ',
-// 									\'1\': \'8pt\',
-// 									\'2\': \'10pt\',
-// 									\'3\': \'12pt\',
-// 									\'4\': \'14pt\',
-// 									\'5\': \'18pt\',
-// 									\'6\': \'24pt\',
-// 									\'7\': \'36pt\'
-// 								}
-// 							}';
-// 
-// 					// Print a drop down list for all the colors we allow!
-// 					if (!isset($context['disabled_tags']['color']))
-// 						echo ',
-// 							{
-// 								sType: \'select\',
-// 								sName: \'sel_color\',
-// 								oOptions: {
-// 									\'\': ', JavaScriptEscape($txt['change_color']), ',
-// 									\'black\': ', JavaScriptEscape($txt['black']), ',
-// 									\'red\': ', JavaScriptEscape($txt['red']), ',
-// 									\'yellow\': ', JavaScriptEscape($txt['yellow']), ',
-// 									\'pink\': ', JavaScriptEscape($txt['pink']), ',
-// 									\'green\': ', JavaScriptEscape($txt['green']), ',
-// 									\'orange\': ', JavaScriptEscape($txt['orange']), ',
-// 									\'purple\': ', JavaScriptEscape($txt['purple']), ',
-// 									\'blue\': ', JavaScriptEscape($txt['blue']), ',
-// 									\'beige\': ', JavaScriptEscape($txt['beige']), ',
-// 									\'brown\': ', JavaScriptEscape($txt['brown']), ',
-// 									\'teal\': ', JavaScriptEscape($txt['teal']), ',
-// 									\'navy\': ', JavaScriptEscape($txt['navy']), ',
-// 									\'maroon\': ', JavaScriptEscape($txt['maroon']), ',
-// 									\'limegreen\': ', JavaScriptEscape($txt['lime_green']), ',
-// 									\'white\': ', JavaScriptEscape($txt['white']), '
-// 								}
-// 							}';
-// 				}
-// 				echo '
-// 						]', $i == count($context['bbc_tags']) - 1 ? '' : ',';
-// 			}
-// 			echo '
-// 					],
-// 					sButtonTemplate: ', JavaScriptEscape('
-// 						<img id="%buttonId%" src="%buttonSrc%" align="bottom" width="23" height="22" alt="%buttonDescription%" title="%buttonDescription%" />
-// 					'), ',
-// 					sButtonBackgroundImage: ', JavaScriptEscape($settings['images_url'] . '/bbc/bbc_bg.png'), ',
-// 					sButtonBackgroundImageHover: ', JavaScriptEscape($settings['images_url'] . '/bbc/bbc_hoverbg.png'), ',
-// 					sActiveButtonBackgroundImage: ', JavaScriptEscape($settings['images_url'] . '/bbc/bbc_hoverbg.png'), ',
-// 					sDividerTemplate: ', JavaScriptEscape('
-// 						<img src="' . $settings['images_url'] . '/bbc/divider.png" alt="|" style="margin: 0 3px;" />
-// 					'), ',
-// 					sSelectTemplate: ', JavaScriptEscape('
-// 						<select name="%selectName%" id="%selectId%" style="margin-bottom: 1ex; font-size: x-small;">
-// 							%selectOptions%
-// 						</select>
-// 					'), ',
-// 					sButtonRowTemplate: ', JavaScriptEscape('
-// 						<div>%buttonRow%</div>
-// 					'), '
-// 				});';
-// 		}
-
 // 		// Now it's all drawn out we'll actually setup the box.
 // 		echo '
 // 				var oEditorHandle_', $editor_id, ' = new smc_Editor({

+ 4 - 2
Themes/default/css/jquery.sceditor.css

@@ -172,8 +172,10 @@ div.sceditor-dropdown, div.sceditor-dropdown div {
 		}
 		.sceditor-button div, .sceditor-button {
 			display: block;
-			width: 16px;
-			height: 16px;
+			width: 18px;
+			height: 18px;
+			background-repeat:no-repeat !important;
+			background-position:center center !important;
 		}
 		.sceditor-button div {
 			margin: 0;

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

@@ -98,8 +98,12 @@
 				center: { txtExec: ["[center]", "[/center]"] },
 				right: { txtExec: ["[right]", "[/right]"] },
 				justify: { txtExec: ["[justify]", "[/justify]"] },
-				bulletlist: { txtExec: ["[list]\n[li][/li]\n[li][/li]\n[/list]"] },
-				orderedlist: { txtExec: ["[list type=decimal]\n[li][/li]\n[li][/li]\n[/list]"] },
+				bulletlist: { txtExec: ["[list]\n[li]", "[/li]\n[li][/li]\n[/list]"] },
+				orderedlist: { txtExec: ["[list type=decimal]\n[li]", "[/li]\n[li][/li]\n[/list]"] },
+				ftp: { txtExec: ["[ftp]", "[/ftp]"] },
+				tt: { txtExec: ["[tt]", "[/tt]"] },
+				glow: { txtExec: ["[glow=red,2,300]", "[/glow]"] },
+				shadow: { txtExec: ["[shadow=red,left]", "[/shadow]"] },
 				font: {
 					txtExec: function (caller) {
 						var	editor  = this,
@@ -1081,6 +1085,14 @@
 				return '<a href="' + encodeURI(attrs.defaultAttr) + '">' + content + '</a>';
 			}
 		},
+		ftp: {
+			html: function(element, attrs, content) {
+				if(typeof attrs.defaultAttr === "undefined" || attrs.defaultAttr.length === 0)
+					attrs.defaultAttr = content;
+
+				return '<a trget="_blank" href="' + encodeURI(attrs.defaultAttr) + '">' + content + '</a>';
+			}
+		},
 		// END_COMMAND
 
 		// START_COMMAND: E-mail