(function( w, $ ){
  var Dialog = w.componentNamespace.Dialog, doc = document;

  var isValidSelector = function(selector) {
    try {
      var $element = $(selector);
    } catch (error) {
      return false;
    }
    return true;
  };

	$.fn.dialog = function( transbg ){
		return this.each(function(){
			var $el = $( this ), dialog = new Dialog( this );

			$el.data( "instance", dialog );

			$el.addClass( Dialog.classes.content )
				.attr( "role", "dialog" )
				.attr( "tabindex", 0 )
				.bind( Dialog.events.open, $.proxy(dialog, 'open') )
				.bind( Dialog.events.close, $.proxy(dialog, 'close') )
				.bind( "click", function( e ){
					if( $( e.target ).is( "." + Dialog.classes.close ) ){
						w.history.back();
						e.preventDefault();
					}
				});

			dialog.$background.bind( "click", function( e ) {
				w.history.back();
			});

			// close on hashchange if open (supports back button closure)
			$( w ).bind( "hashchange", function( e ){
				var hash = w.location.hash.replace( "#", "" );

				if( hash !== dialog.hash ){
					dialog.close();
				}
			});

			// open on matching a[href=#id] click
			$( doc ).bind( "click", function( e ){
				var $a = $( e.target ).closest( "a" );

				if( !dialog.isOpen && $a.length && $a.attr( "href" ) && isValidSelector($a.attr( "href" )) ){
					var $matchingDialog = $( $a.attr( "href" ) );
					if( $matchingDialog.length && $matchingDialog.is( $el ) ){
						$matchingDialog.trigger( Dialog.events.open );
						e.preventDefault();
					}
				}
			});

			// close on escape key
			$( doc ).bind( "keyup", function( e ){
				if( e.which === 27 ){
					dialog.close();
				}
			});
		});
	};

	// auto-init
	$(function(){
		$( ".dialog" ).dialog();
	});
}( this, jQuery ));

@@ -77,168 +77,8 @@
 t;%0A%0A
-  var isValidSelector = function(selector) %7B%0A    try %7B%0A      var $element = $(selector);%0A    %7D catch (error) %7B%0A      return false;%0A    %7D%0A    return true;%0A  %7D;%0A%0A
 %09$.f
@@ -1105,54 +1105,71 @@
 %22 ) 
-&& isV
+)%7B%0A%0A%09%09%09%09%09// catch inv
 alid
-S
+ s
 elector
-($a.attr( %22href%22 )) )
+ exceptions%0A%09%09%09%09%09try 
 %7B%0A%09%09%09%09%09
+%09
 var 
@@ -1206,24 +1206,201 @@
 %22href%22 ) );%0A
+%09%09%09%09%09%7D catch ( error ) %7B%0A%09%09%09%09%09%09// TODO should check the type of exception, it's not clear how well%0A%09%09%09%09%09%09//      the error name %22SynatxError%22 is supported%0A%09%09%09%09%09%09return;%0A%09%09%09%09%09%7D%0A%0A
 %09%09%09%09%09if( $ma

move the try/catch inline so it selects once, add todo