r1768 - branches/bxe_2_0/js

[email protected] Fri, 26 Oct 2007 12:00:09 +0200 (CEST)
Newsgroups gmane.editors.bitflux.cvs
Message-ID <[email protected]>
Author: chregu
Date: Fri Oct 26 12:00:09 2007
New Revision: 1768

Log:
add some try/catches

Modified:
   branches/bxe_2_0/js/bxeFunctions.js
   branches/bxe_2_0/js/widget.js

Modified: branches/bxe_2_0/js/bxeFunctions.js
==============================================================================
--- branches/bxe_2_0/js/bxeFunctions.js	(original)
+++ branches/bxe_2_0/js/bxeFunctions.js	Fri Oct 26 12:00:09 2007
@@ -1379,7 +1379,11 @@
 
 function bxe_updateXPath(e) {
 	var sel = window.getSelection();
-	var cssr = sel.getRangeAt(0);
+	try {
+		var cssr = sel.getRangeAt(0);
+	} catch (e) {
+		return false;
+	}
 	if (e && e.localName == "TEXTAREA") {
 		bxe_format_list.removeAllItems();
 		bxe_format_list.appendItem("-Source Mode-","");
@@ -2771,10 +2775,14 @@
 
 function bxe_cursorPositionLoad() {
 	var sel = window.getSelection();
-	sel.collapse(bxe_lastCursorPositionAnchorNode, bxe_lastCursorPositionAnchorOffset);
+	try {
+		sel.collapse(bxe_lastCursorPositionAnchorNode, bxe_lastCursorPositionAnchorOffset);
 	
-	if (bxe_lastCursorPositionFocusNode) {
-		sel.extend(bxe_lastCursorPositionFocusNode, bxe_lastCursorPositionFocusOffset);
+		if (bxe_lastCursorPositionFocusNode) {
+			sel.extend(bxe_lastCursorPositionFocusNode, bxe_lastCursorPositionFocusOffset);
+		}
+	} catch (e) {
+		return false;
 	}
 }
 

Modified: branches/bxe_2_0/js/widget.js
==============================================================================
--- branches/bxe_2_0/js/widget.js	(original)
+++ branches/bxe_2_0/js/widget.js	Fri Oct 26 12:00:09 2007
@@ -347,23 +347,56 @@
 
 
 
-Widget_Globals.prototype.addHideOnClick = function (widget,id) {
+Widget_Globals.prototype.addHideOnClick = function (widget,otherWindowOnly) {
 	if (!this.HideOnClick) {
 		this.HideOnClick = new Array();
 	}
-	/*
-	if (id) {
-		this.HideOnClick.push(id);
+	if (!this.HideOnClickOther) {
+		this.HideOnClickOther = new Array();
+	}
+
+	if (otherWindowOnly) {
+		this.HideOnClickOther.push(widget);
 	} else {
-		this.HideOnClick.push("0");
-	}*/
-	this.HideOnClick.push(widget);
+		this.HideOnClick.push(widget);
+		document.addEventListener("click", Widget_Globals_doHideOnClick , true);
+		document.addEventListener("contextmenu", Widget_Globals_doHideOnClick ,true);
+	}
+	
 	
-	document.addEventListener("click", Widget_Globals_doHideOnClick , true);
-	document.addEventListener("contextmenu", Widget_Globals_doHideOnClick ,true);
 }
 
 
+Widget_Globals_doHideOnClickOther = function(e) {
+	var glob = mozilla.getWidgetGlobals();
+	if( glob.HideOnClickOther && glob.HideOnClickOther.length > 0) {
+		var newHideOnClick = new Array();
+		var widget = null;
+		while (widget = glob.HideOnClickOther.pop()) 
+		{ 
+			if (widget.isElementChooser && e.target.className != 'MenuItem') {
+						
+				while (!bxe_config.xmldoc.XMLNode.validateDocument(true)) {
+					bxe_history_undo();
+				}
+				
+			}
+				
+			if (widget.callbackCancel) {
+				widget.callbackCancel();
+			} else {
+				widget.hide();
+			}
+		}
+		if (typeof BxeTextClipboard_keyhandler == 'function') {
+					document.removeEventListener("keypress", BxeTextClipboard_keyhandler, true);
+			}
+			bxe_registerKeyHandlers();
+			
+		glob.HideOnClickOther = newHideOnClick;
+	}
+}
+
 
 Widget_Globals_doHideOnClick = function(e) {
 	var glob = mozilla.getWidgetGlobals();
@@ -728,6 +761,8 @@
 		}
 		rootNode.Widget = this;
 		rootNode.addEventListener("click", function(e) {
+			Widget_Globals_doHideOnClickOther();
+	
 			this.Widget.buildPopup(this);
 			bxe_cursorPositionLoad();
 			
@@ -1033,6 +1068,16 @@
 
 function Widget_ModalBox (title, callback, callbackCancel) {
 	this.setup(title,callback, callbackCancel);
+
+}
+
+Widget_ModalBox.prototype._draw = Widget.prototype.draw;
+
+Widget_ModalBox.prototype.draw = function (display,noMaxHeight) {
+	var glob = mozilla.getWidgetGlobals();
+	glob.addHideOnClick(this,true);
+	this._draw(display,noMaxHeight);
+
 }
 
 Widget_ModalBox.prototype.setup = function (title, callback, callbackCancel ) {
-- 
Bx-editor-cvs mailing list
[email protected]
http://lists.bitflux.ch/cgi-bin/listinfo/bx-editor-cvs