@@ -8,9 +8,27 @@ class Window
8
8
private $ content ;
9
9
private $ options = ['width ' => '0.8 ' , 'height ' => '0.8 ' ];
10
10
11
- public function __construct (array $ xhr = ['url ' => '' , 'method ' => 'POST ' ])
11
+ /**
12
+ * Window constructor.
13
+ * @param string|array $content
14
+ */
15
+ public function __construct ($ content )
12
16
{
13
- $ this ->xhr = json_encode (array_merge ($ this ->xhr , $ xhr ));
17
+ $ this ->content = $ content ;
18
+ if (is_string ($ content )){
19
+ $ this ->content = <<<EOF
20
+ function(){
21
+ let window = document.createElement('div');
22
+ let fragment = document.createRange().createContextualFragment(" {$ this ->content }");
23
+ window.appendChild(fragment);
24
+ return window;
25
+ }()
26
+ EOF ;
27
+ return ;
28
+ }
29
+ $ xhr = array_merge (['url ' =>'' ,'method ' =>'' ,'data ' =>[],'callback ' =>'null ' ],$ content );
30
+ $ data = json_encode ($ xhr ['data ' ]);
31
+ $ this ->content = "{url:' {$ xhr ['url ' ]}',method:' {$ xhr ['method ' ]}',data: {$ data },callback: {$ xhr ['callback ' ]}} " ;
14
32
}
15
33
16
34
/**
@@ -38,28 +56,6 @@ public function options(array $options)
38
56
$ this ->options = array_merge ($ this ->options , $ options );
39
57
}
40
58
41
- /**
42
- * @param string|array $data
43
- */
44
- public function content ($ data )
45
- {
46
- $ this ->content = $ data ;
47
- if (is_string ($ data )){
48
- $ this ->content = <<<EOF
49
- function(){
50
- let window = document.createElement('div');
51
- let fragment = document.createRange().createContextualFragment(response);
52
- window.appendChild(fragment);
53
- return window;
54
- }()
55
- EOF ;
56
- return ;
57
- }
58
- $ xhr = array_merge (['url ' =>'' ,'method ' =>'' ,'data ' =>[],'callback ' =>'null ' ],$ data );
59
- $ data = json_encode ($ xhr ['data ' ]);
60
- $ this ->content = "{url:' {$ xhr ['url ' ]}',method:' {$ xhr ['method ' ]}',data: {$ data },callback: {$ xhr ['callback ' ]}} " ;
61
- }
62
-
63
59
public function __toString ()
64
60
{
65
61
$ this ->options = json_encode ($ this ->options );
0 commit comments