added js dep. '/js/_SERVER.js' generated by the router.controller.js.server() method
This commit is contained in:
parent
d043c83ead
commit
2e7291929a
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace router\controller;
|
||||
|
||||
|
||||
class js{
|
||||
|
||||
|
||||
private $pagename;
|
||||
|
||||
/* PRE-CALL
|
||||
*
|
||||
* @url<String> Calling URI
|
||||
*
|
||||
*/
|
||||
public function __construct($url){
|
||||
}
|
||||
|
||||
|
||||
/* Generate _SERVER.js
|
||||
*
|
||||
*/
|
||||
public function server(){
|
||||
header('Content-Type: text/javascript; charset=utf-8');
|
||||
|
||||
echo "window._SERVER = ".json_encode([
|
||||
|
||||
'a' => [1, 2]
|
||||
|
||||
])."\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Manage bundle hash
|
||||
*
|
||||
*/
|
||||
public function bundle(){
|
||||
|
||||
/* (1) Extract /public_html/js/ all .js files */
|
||||
$js_scripts = glob(__PUBLIC__.'/js/*.js');
|
||||
|
||||
/* (2) If match pattern 'bundle@*.js' */
|
||||
foreach($js_scripts as $fname){
|
||||
|
||||
$bname = basename($fname);
|
||||
|
||||
// if match -> load it and exit
|
||||
if( preg_match('/bundle@[\da-f]+\.js/', $bname) )
|
||||
header("Location: /js/$bname");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* POST-CALL
|
||||
*
|
||||
*/
|
||||
public function __destruct(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -14,8 +14,8 @@
|
|||
*
|
||||
*/
|
||||
public function __construct($url){
|
||||
$this->pagename = isset($url['page']) ? $url['page'] : null;
|
||||
|
||||
$this->pagename = $url['page'];
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,28 +30,6 @@
|
|||
echo "page not found";
|
||||
}
|
||||
|
||||
|
||||
/* Manage bundle hash
|
||||
*
|
||||
*/
|
||||
public function bundle(){
|
||||
|
||||
/* (1) Extract /public_html/js/ all .js files */
|
||||
$js_scripts = glob(__PUBLIC__.'/js/*.js');
|
||||
|
||||
/* (2) If match pattern 'bundle@*.js' */
|
||||
foreach($js_scripts as $fname){
|
||||
|
||||
$bname = basename($fname);
|
||||
|
||||
// if match -> load it and exit
|
||||
if( preg_match('/bundle@[\da-f]+\.js/', $bname) )
|
||||
header("Location: /js/$bname");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* POST-CALL
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,13 @@
|
|||
|
||||
"/js/bundle.js": {
|
||||
"methods": ["GET"],
|
||||
"controller": "page:bundle",
|
||||
"controller": "js:bundle",
|
||||
"arguments": {}
|
||||
},
|
||||
|
||||
"/js/_SERVER.js": {
|
||||
"methods": ["GET"],
|
||||
"controller": "js:server",
|
||||
"arguments": {}
|
||||
},
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
<link rel='shortcut icon' href='/favicon.ico'>
|
||||
|
||||
<!-- CSS dependencies -->
|
||||
<link rel='stylesheet' type='text/css' href='/css/layout.css'>
|
||||
|
||||
<!-- JS dependencies -->
|
||||
<script type='text/javascript' src='/js/_SERVER.js'></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
|
Loading…
Reference in New Issue