From 1f345e4cc5756d55e3e182021f79f3025f8afc95 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Fri, 28 Jun 2013 15:46:31 -0400 Subject: [PATCH] Viewer: refactor message code into showMessage/hideMessage methods This avoids the need to deal with classes, and explicitly makes it reusable for other needs --- src/viewer.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index fb50cbb8..9943c770 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -174,12 +174,7 @@ $.Viewer = function( options ) { this.addHandler( 'open-failed', function (source, args) { var msg = $.getString( "Errors.Open-Failed", args.source, args.message); - - var errorDiv = $.makeNeutralElement( "div" ); - $.addClass( errorDiv, "modal-dialog error" ); - errorDiv.appendChild( document.createTextNode( msg ) ); - - _this.container.appendChild( $.makeCenteredNode( errorDiv ) ); + _this.showMessage( msg ); }); $.ControlDock.call( this, options ); @@ -428,12 +423,7 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, $TileSource, options; - if ( this.container ) { - var dialogs = this.container.querySelectorAll( ".modal-dialog" ); - for ( var i = 0; i < dialogs.length; i++ ) { - dialogs[i].parentNode.remove( dialogs[i] ); - } - } + _this.hideMessage(); //allow plain xml strings or json strings to be parsed here if( $.type( tileSource ) == 'string' ){ @@ -1082,8 +1072,31 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, this.referenceStrip.setFocus( page ); } return this; - } + }, + /** + * Display a message in the viewport + * @function + * @param {String} text message + */ + showMessage: function ( message ) { + var div = this.messageDiv = $.makeNeutralElement( "div" ); + div.appendChild( document.createTextNode( message ) ); + + this.container.appendChild( $.makeCenteredNode( div ) ); + }, + + /** + * Hide any currently displayed viewport message + * @function + */ + hideMessage: function () { + var div = this.messageDiv; + if (div) { + div.parentNode.remove(div); + delete this.messageDiv; + } + } }); /**