3
3
4
4
require ( [
5
5
'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 ) {
8
8
9
9
'use strict' ;
10
10
@@ -18,23 +18,57 @@ require([
18
18
postCreate : function ( ) {
19
19
console . log ( this . id + '.postCreate' ) ;
20
20
21
- switch ( this . contenttype ) {
21
+ var external = this . contentsPath != '' ? true : false ;
22
+
23
+ switch ( this . contenttype ) {
22
24
case 'html' :
23
- domStyle . set ( this . domNode , {
24
- 'height' : 'auto' ,
25
- 'width' : '100%' ,
26
- 'outline' : 0
27
- } ) ;
28
25
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
+
31
48
break ;
32
49
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
+ console . log ( "external js" ) ;
54
+
55
+ var scriptNode = document . createElement ( "script" ) ,
56
+ intDate = + new Date ( ) ;
57
+
58
+ scriptNode . type = "text/javascript" ;
59
+ scriptNode . src = this . contentsPath + "?v=" + intDate . toString ( ) ;
60
+
61
+ domConstruct . place ( scriptNode , this . domNode , "only" ) ;
62
+ }
63
+ else
64
+ {
65
+ console . log ( "inline js" ) ;
66
+ try {
67
+ eval ( this . contents ) ;
68
+ } catch ( e ) {
69
+ domConstruct . place ( "Error while evaluating JavaScript: " + e , this . domNode , "only" ) ;
70
+ }
71
+ }
38
72
break ;
39
73
}
40
74
}
0 commit comments