Javascript:
function require( filename ) { // The require() statement includes and evaluates the specific file.
//
// + original by: Michael White (http://crestidg.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// % note 1: Force Javascript execution to pause until the file is loaded. Usually causes failure if the file never loads. ( Use sparingly! )
var js_code;
var script_block = document.createElement('script');
script_block.type = 'text/javascript';
if(this.is_ie) {
// moved file_get_contents here to avoid double work
js_code = this.file_get_contents(filename);
script_block.text = js_code;
} else {
script_block.appendChild(document.createTextNode(js_code));
}
if(typeof(script_block) != "undefined") {
document.getElementsByTagName("head")[0].appendChild(script_block);
// save include state for reference by include_once
var cur_file = {};
cur_file[window.location.href] = 1;
if (!window.php_js) window.php_js = {};
if (!window.php_js.includes) window.php_js.includes = cur_file;
if (!window.php_js.includes[filename]) {
return window.php_js.includes[filename] = 1;
} else {
return window.php_js.includes[filename]++;
}
}
}
Примеры:
require('/js/imaginary1.js');
1
|
|
|
|
Поиск по сайту
|
|
Содержание
|
|
Последние темы на форуме
|
Forum |
|
11 if(this.is_ie) {
12 // moved file_get_contents here to avoid double work
13 js_code = this.file_get_contents(filename);
А если !this.is_ie, то js_code так и останется неинициализированной. Так зачем же было делать // moved file_get_contents here to avoid double work ?