33
44require ( [
55 'dojo/_base/declare' , 'mxui/widget/_WidgetBase' ,
6- 'mxui/dom' , 'dojo/dom-style' , 'dojo/dom-attr' , 'dojo/html '
7- ] , function ( declare , _WidgetBase , dom , domStyle , domAttr , html ) {
6+ 'mxui/dom' , 'dojo/dom-style' , 'dojo/dom-attr' , 'dojo/dom-construct' , 'dijit/layout/LinkPane '
7+ ] , function ( declare , _WidgetBase , dom , domStyle , domAttr , domConstruct , linkPane ) {
88
99 'use strict' ;
1010
@@ -18,23 +18,54 @@ require([
1818 postCreate : function ( ) {
1919 console . log ( this . id + '.postCreate' ) ;
2020
21- switch ( this . contenttype ) {
21+ var external = this . contentsPath != '' ? true : false ;
22+
23+ switch ( this . contenttype ) {
2224 case 'html' :
23- domStyle . set ( this . domNode , {
24- 'height' : 'auto' ,
25- 'width' : '100%' ,
26- 'outline' : 0
27- } ) ;
2825
29- domAttr . set ( this . domNode , 'style' , this . style ) ; //might override height and width
30- html . set ( this . domNode , this . contents ) ;
26+ if ( external )
27+ {
28+ new linkPane (
29+ {
30+ preload : true ,
31+ loadingMessage : "" ,
32+ href : this . contentsPath ,
33+ onDownloadError : function ( ) { console . log ( "Error loading html path" ) ; }
34+ } ) . placeAt ( this . domNode . id ) . startup ( ) ;
35+ }
36+ else
37+ {
38+ domStyle . set ( this . domNode , {
39+ 'height' : 'auto' ,
40+ 'width' : '100%' ,
41+ 'outline' : 0
42+ } ) ;
43+
44+ domAttr . set ( this . domNode , 'style' , this . style ) ; // might override height and width
45+ domConstruct . place ( this . contents , this . domNode , "only" ) ;
46+ }
47+
3148 break ;
3249 case 'js' :
33- try {
34- eval ( this . contents ) ;
35- } catch ( e ) {
36- html . set ( this . domNode , "Error while evaluating JavaScript: " + e ) ;
37- }
50+
51+ if ( external )
52+ {
53+ var scriptNode = document . createElement ( "script" ) ,
54+ intDate = + new Date ( ) ;
55+
56+ scriptNode . type = "text/javascript" ;
57+ scriptNode . src = this . contentsPath + "?v=" + intDate . toString ( ) ;
58+
59+ domConstruct . place ( scriptNode , this . domNode , "only" ) ;
60+ }
61+ else
62+ {
63+ try {
64+ eval ( this . contents ) ;
65+ } catch ( e ) {
66+ domConstruct . place ( "Error while evaluating JavaScript: " + e , this . domNode , "only" ) ;
67+ }
68+ }
3869 break ;
3970 }
4071 }
0 commit comments