File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class Mobile extends Text
1919
2020 public function render ()
2121 {
22- $ options = json_encode ($ this ->options );
22+ $ options = $ this -> json_encode_options ($ this ->options );
2323
2424 $ this ->script = <<<EOT
2525
@@ -31,4 +31,30 @@ public function render()
3131
3232 return parent ::render ();
3333 }
34+
35+ protected function json_encode_options ($ options )
36+ {
37+ $ value_arr = [];
38+ $ replace_keys = [];
39+
40+ foreach ($ options as $ key => &$ value ) {
41+ // Look for values starting with 'function('
42+ if (strpos ($ value , 'function( ' ) === 0 ) {
43+ // Store function string.
44+ $ value_arr [] = $ value ;
45+ // Replace function string in $foo with a 'unique' special key.
46+ $ value = '% ' .$ key .'% ' ;
47+ // Later on, we'll look for the value, and replace it.
48+ $ replace_keys [] = '" ' .$ value .'" ' ;
49+ }
50+ }
51+
52+ // Now encode the array to json format
53+ $ json = json_encode ($ options );
54+
55+ // Replace the special keys with the original string.
56+ $ json = str_replace ($ replace_keys , $ value_arr , $ json );
57+
58+ return $ json ;
59+ }
3460}
You can’t perform that action at this time.
0 commit comments