Browse Source

Merge pull request #222 from Spuds/scBackport

! backport some SCeditor 1.4 fixes to 1.3.7
emanuele45 12 years ago
parent
commit
5e05031a99

+ 8 - 6
Themes/default/scripts/jquery.sceditor.bbcode.js

@@ -233,6 +233,9 @@
 			if("text-align" === property)
 			{
 				$elm = $(element);
+			
+				if(!element.style)
+					return null;
 
 				if($elm.parent().css(property) !== $elm.css(property) &&
 					$elm.css('display') === "block" && !$elm.is('hr') && !$elm.is('th'))
@@ -256,7 +259,7 @@
 			var	childNodes = element.childNodes,
 				i = childNodes.length;
 
-			if(element.nodeValue)
+			if(element.nodeValue && /\S|\u00A0/.test(element.nodeValue))
 				return false;
 
 			if(childNodes.length === 0 || (childNodes.length === 1 && (/br/i.test(childNodes[0].nodeName) || isEmpty(childNodes[0]))))
@@ -411,9 +414,8 @@
 		 * @return string BBCode which has been converted from HTML
 		 * @memberOf jQuery.sceditorBBCodePlugin.prototype
 		 */
-		base.getHtmlHandler = function(html, domBody, filter) {
-			if (typeof filter == 'undefined')
-				$.sceditor.dom.removeWhiteSpace(domBody[0]);
+		base.getHtmlHandler = function(html, domBody) {
+			$.sceditor.dom.removeWhiteSpace(domBody[0]);
 
 			return $.trim(base.elementToBbcode(domBody));
 		};
@@ -632,7 +634,7 @@
 						// If it's an empty DIV and in compatibility mode is below IE8 then
 						// we must add a non-breaking space to the div otherwise the div
 						// will be collapsed. Adding a BR works but when you press enter
-						// to make a newline it suddenly gose back to the normal IE div
+						// to make a newline it suddenly goes back to the normal IE div
 						// behaviour and creates two lines, one for the newline and one
 						// for the BR. I'm sure there must be a better fix but I've yet to
 						// find one.
@@ -1489,7 +1491,7 @@
 	};
 
 	$.fn.sceditorBBCodePlugin = function(options) {
-		if((!options || !options.runWithoutWysiwygSupport) && !$.sceditor.isWysiwygSupported())
+		if((!options || !options.runWithoutWysiwygSupport) && !$.sceditor.isWysiwygSupported)
 			return;
 
 		return this.each(function() {

+ 34 - 28
Themes/default/scripts/jquery.sceditor.js

@@ -242,21 +242,8 @@
 
 			// load any textarea value into the editor
 			base.val($textarea.hide().val());
-/*
-			// Pass the value though the getTextHandler if it is set so that
-			// BBCode, ect. can be converted
-			if(base.options.getTextHandler && base.options.supportedWysiwyg)
-			{
-				val = base.options.getTextHandler(val);
 
-				base.setWysiwygEditorValue(val);
-			}
-			else
-			{
-				base.toggleTextMode();
-				base.setTextareaValue(val);
-			}
-*/
+
 			if(base.options.autofocus)
 				autofocus();
 
@@ -318,7 +305,7 @@
 				$doc.find("html").addClass('ie' + $.sceditor.ie);
 
 			// iframe overflow fix
-			if(/iPhone|iPod|iPad| wosbrowser\//i.test(navigator.userAgent))
+			if(/iPhone|iPod|iPad| wosbrowser\//i.test(navigator.userAgent) || $.sceditor.ie)
 				$body.height('100%');
 
 			// set the key press event
@@ -831,13 +818,14 @@
 				else
 				{
 					// Allow max 25 checks before giving up.
-					// Needed inscase empty input is posted or
-					// something gose wrong.
+					// Needed in case empty input is pasted or
+					// something goes wrong.
 					if(checkCount > 25)
 					{
 						while(prePasteContent.firstChild)
 							elm.appendChild(prePasteContent.firstChild);
 
+						rangeHelper.restoreRange();
 						return;
 					}
 
@@ -999,8 +987,9 @@
 		 * @memberOf jQuery.sceditor.prototype
 		 */
 		base.textEditorInsertText = function (text, endText) {
-			var range, start, end, txtLen;
-
+			var range, start, end, txtLen, scrollTop;
+			
+			scrollTop = textEditor.scrollTop;
 			textEditor.focus();
 
 			if(typeof textEditor.selectionStart !== "undefined")
@@ -1039,6 +1028,7 @@
 			else
 				textEditor.value += text + endText;
 
+			textEditor.scrollTop = scrollTop;
 			textEditor.focus();
 		};
 
@@ -1057,6 +1047,12 @@
 		/**
 		 * Gets the value of the editor
 		 *
+		 * If the editor is in WYSIWYG mode it will return the filtered
+		 * HTML from it (converted to BBCode if using the BBCode plugin).
+		 * It it's in Source Mode it will return the unfiltered contents
+		 * of the source editor (if using the BBCode plugin this will be
+		 * BBCode again).
+		 *
 		 * @since 1.3.5
 		 * @return {string}
 		 * @function
@@ -1153,20 +1149,25 @@
 		 * @memberOf jQuery.sceditor.prototype
 		 */
 		base.getWysiwygEditorValue = function (filter) {
-			// Possible replacement:
-			// if(!$.sceditor.isWysiwygSupported())
-			//if (!base.options.supportedWysiwyg)
-			//	return;
-
 			var	$body = $wysiwygEditor.contents().find("body"),
 				html;
 
+			// save the range before the DOM gets messed with
+			rangeHelper.saveRange();
+			base.focus();
+
 			// fix any invalid nesting
 			$.sceditor.dom.fixNesting($body.get(0));
 			html = $body.html();
 
 			if(filter !== false && base.options.getHtmlHandler)
-				html = base.options.getHtmlHandler(html, $body, filter);
+				html = base.options.getHtmlHandler(html, $body);
+				
+			// restore the range.
+			rangeHelper.restoreRange();
+			
+			// remove the last stored range for IE as it no longer applies
+			lastRange = null;
 
 			return html;
 		};
@@ -2567,7 +2568,11 @@
 				sel = doc.selection;
 
 			if(sel.getRangeAt && sel.rangeCount <= 0)
-				sel.addRange(doc.createRange());
+			{
+				var r = doc.createRange();
+				r.setStart(doc.body, 0)
+				sel.addRange(r);
+			}
 
 			if(!isW3C)
 				return sel.createRange();
@@ -2774,7 +2779,8 @@
 		 * @memberOf jQuery.sceditor.rangeHelper.prototype
 		 */
 		base.restoreRange = function() {
-			var	range	= base.selectedRange(),
+			var	marker,
+				range	= base.selectedRange(),
 				start	= base.getMarker(startMarker),
 				end	= base.getMarker(endMarker);
 
@@ -2784,7 +2790,7 @@
 			if(!isW3C)
 			{
 				range = doc.body.createTextRange();
-				var marker = doc.body.createTextRange();
+				marker = doc.body.createTextRange();
 
 				marker.moveToElementText(start);
 				range.setEndPoint('StartToStart', marker);